aboutsummaryrefslogtreecommitdiff
path: root/central/src/main/java/moe/yuuta/dn42peering/provision/BGPRequestCommon.java
blob: 8ca9ea2b7a89c15da5da541f8029fb3ef67139ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package moe.yuuta.dn42peering.provision;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import moe.yuuta.dn42peering.agent.proto.BGPRequest;

import javax.annotation.Nonnull;

@DataObject
public class BGPRequestCommon {
    private NodeCommon node;
    private Long id;
    private String asn;
    private Boolean mpbgp;
    private String ipv4;
    private String ipv6;
    private String device;

    public BGPRequestCommon(NodeCommon node,
                            Long id,
                            String asn,
                            Boolean mpbgp,
                            String ipv4,
                            String ipv6,
                            String device) {
        this.node = node;
        this.id = id;
        this.asn = asn;
        this.mpbgp = mpbgp;
        this.ipv4 = ipv4;
        this.ipv6 = ipv6;
        this.device = device;
    }

    public BGPRequestCommon(@Nonnull JsonObject json) {
        if(json.getValue("node") != null) this.node = new NodeCommon(json.getJsonObject("node"));
        if(json.getValue("id") != null) this.id = json.getLong("id");
        this.asn = json.getString("asn");
        if(json.getValue("mpbgp") != null) this.mpbgp = json.getBoolean("mpbgp");
        this.ipv4 = json.getString("ipv4");
        this.ipv6 = json.getString("ipv6");
        this.device = json.getString("device");
    }

    @Nonnull
    public JsonObject toJson() {
        return new JsonObject()
                .put("node", node == null ? null : node.toJson())
                .put("id", id)
                .put("asn", asn)
                .put("mpbgp", mpbgp)
                .put("ipv4", ipv4)
                .put("ipv6", ipv6)
                .put("device", device);
    }

    @Nonnull
    public BGPRequest toGRPC() {
        final BGPRequest.Builder builder = BGPRequest.newBuilder();
        if(node != null) builder.setNode(node.toGRPC());
        if(id != null) builder.setId(id);
        if(asn != null) builder.setAsn(asn);
        if(mpbgp != null) builder.setMpbgp(mpbgp);
        if(ipv4 != null) builder.setIpv4(ipv4);
        if(ipv6 != null) builder.setIpv6(ipv6);
        if(device != null) builder.setDevice(device);
        return builder.build();
    }

    // Getters & Setters

    public NodeCommon getNode() {
        return node;
    }

    public void setNode(NodeCommon node) {
        this.node = node;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAsn() {
        return asn;
    }

    public void setAsn(String asn) {
        this.asn = asn;
    }

    public Boolean getMpbgp() {
        return mpbgp;
    }

    public void setMpbgp(Boolean mpbgp) {
        this.mpbgp = mpbgp;
    }

    public String getIpv4() {
        return ipv4;
    }

    public void setIpv4(String ipv4) {
        this.ipv4 = ipv4;
    }

    public String getIpv6() {
        return ipv6;
    }

    public void setIpv6(String ipv6) {
        this.ipv6 = ipv6;
    }

    public String getDevice() {
        return device;
    }

    public void setDevice(String device) {
        this.device = device;
    }
}