blob: caa44eb1823991b0d297eda92c3c318d14333a40 [file] [log] [blame]
Jonathan Hartbac07a02014-10-13 21:29:54 -07001package org.onlab.onos.sdnip.config;
2
3import java.util.List;
4import java.util.Objects;
5
Jonathan Hartbac07a02014-10-13 21:29:54 -07006import org.onlab.onos.net.ConnectPoint;
7import org.onlab.onos.net.DeviceId;
8import org.onlab.onos.net.PortNumber;
9import org.onlab.packet.MacAddress;
10
Jonathan Hartd7bd9822014-10-20 18:18:02 -070011import com.fasterxml.jackson.annotation.JsonCreator;
12import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070013import com.google.common.base.MoreObjects;
14
Jonathan Hartbac07a02014-10-13 21:29:54 -070015/**
16 * Represents a BGP daemon in SDN network.
17 * <p/>
18 * Each BGP speaker has a attachment point, which includes a switch DPID and a
19 * switch port. Each BGP speaker has one MAC address and several IP addresses,
20 * which are used to peer with BGP peers outside the SDN network. For each
21 * peer outside the SDN network, we configure a different IP address to BGP
22 * speaker inside the SDN network.
23 * <p/>
24 * Each BGP speaker has a name, which is a unique identifying String that is
25 * used to reference this speaker in the configuration.
26 */
27public class BgpSpeaker {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070028 private final String name;
29 private final ConnectPoint connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070030 private final MacAddress macAddress;
31 private List<InterfaceAddress> interfaceAddresses;
32
33 /**
34 * Class constructor used by the JSON library to create an object.
35 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070036 * @param name the name of the BGP speaker inside SDN network
37 * @param attachmentDpid the DPID where the BGP speaker is attached to
38 * @param attachmentPort the port where the BGP speaker is attached to
39 * @param macAddress the MAC address of the BGP speaker
Jonathan Hartbac07a02014-10-13 21:29:54 -070040 */
41 @JsonCreator
Jonathan Hartdc711bd2014-10-15 11:24:23 -070042 public BgpSpeaker(@JsonProperty("name") String name,
Jonathan Hartbac07a02014-10-13 21:29:54 -070043 @JsonProperty("attachmentDpid") String attachmentDpid,
44 @JsonProperty("attachmentPort") int attachmentPort,
45 @JsonProperty("macAddress") String macAddress) {
46
Jonathan Hartdc711bd2014-10-15 11:24:23 -070047 this.name = name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070048 this.macAddress = MacAddress.valueOf(macAddress);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070049 this.connectPoint = new ConnectPoint(
Jonathan Hartbac07a02014-10-13 21:29:54 -070050 DeviceId.deviceId(SdnIpConfigReader.dpidToUri(attachmentDpid)),
51 PortNumber.portNumber(attachmentPort));
52 }
53
54 /**
55 * Sets the addresses we configured for the BGP speaker on all virtual
56 * {@link Interface}s.
57 *
58 * @param interfaceAddresses a list of IP addresses of the BGP speaker
59 * configured on all virtual interfaces
60 */
61 @JsonProperty("interfaceAddresses")
62 public void setInterfaceAddresses(
63 List<InterfaceAddress> interfaceAddresses) {
64 this.interfaceAddresses = interfaceAddresses;
65 }
66
67 /**
68 * Gets the BGP speaker name.
69 *
70 * @return the BGP speaker name
71 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070072 public String name() {
73 return name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070074 }
75
76 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070077 * Gets the connect point where the BGP speaker is attached.
Jonathan Hartbac07a02014-10-13 21:29:54 -070078 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070079 * @return the connect point
Jonathan Hartbac07a02014-10-13 21:29:54 -070080 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070081 public ConnectPoint connectPoint() {
82 return connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070083 }
84
85 /**
86 * Gets the MAC address of the BGP speaker.
87 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070088 * @return the MAC address
Jonathan Hartbac07a02014-10-13 21:29:54 -070089 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070090 public MacAddress macAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070091 return macAddress;
92 }
93
94 /**
95 * Gets all IP addresses configured on all {@link Interface}s of the
96 * BGP speaker.
97 *
98 * @return a list of IP addresses of the BGP speaker configured on all
99 * virtual interfaces
100 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700101 public List<InterfaceAddress> interfaceAddresses() {
Jonathan Hartbac07a02014-10-13 21:29:54 -0700102 return interfaceAddresses;
103 }
104
105 @Override
106 public boolean equals(Object other) {
107 if (!(other instanceof BgpSpeaker)) {
108 return false;
109 }
110
111 BgpSpeaker otherBgpSpeaker = (BgpSpeaker) other;
112
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700113 return name.equals(otherBgpSpeaker.name) &&
114 connectPoint.equals(
115 otherBgpSpeaker.connectPoint) &&
Jonathan Hartbac07a02014-10-13 21:29:54 -0700116 macAddress.equals(otherBgpSpeaker.macAddress) &&
117 interfaceAddresses.equals(otherBgpSpeaker.interfaceAddresses);
118 }
119
120 @Override
121 public int hashCode() {
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700122 return Objects.hash(name, connectPoint, macAddress,
Jonathan Hartbac07a02014-10-13 21:29:54 -0700123 interfaceAddresses);
124
125 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700126
127 @Override
128 public String toString() {
129 return MoreObjects.toStringHelper(getClass())
130 .add("speakerName", name)
131 .add("connectPoint", connectPoint)
132 .add("macAddress", macAddress)
133 .add("interfaceAddresses", interfaceAddresses)
134 .toString();
135 }
Jonathan Hartbac07a02014-10-13 21:29:54 -0700136}