blob: c7c2edd0dec729fb51108d8b83c1c36080378ed1 [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
6import org.codehaus.jackson.annotate.JsonCreator;
7import org.codehaus.jackson.annotate.JsonProperty;
8import org.onlab.onos.net.ConnectPoint;
9import org.onlab.onos.net.DeviceId;
10import org.onlab.onos.net.PortNumber;
11import org.onlab.packet.MacAddress;
12
13/**
14 * Represents a BGP daemon in SDN network.
15 * <p/>
16 * Each BGP speaker has a attachment point, which includes a switch DPID and a
17 * switch port. Each BGP speaker has one MAC address and several IP addresses,
18 * which are used to peer with BGP peers outside the SDN network. For each
19 * peer outside the SDN network, we configure a different IP address to BGP
20 * speaker inside the SDN network.
21 * <p/>
22 * Each BGP speaker has a name, which is a unique identifying String that is
23 * used to reference this speaker in the configuration.
24 */
25public class BgpSpeaker {
26 private final String speakerName;
27 private final ConnectPoint attachmentSwitchPort;
28 private final MacAddress macAddress;
29 private List<InterfaceAddress> interfaceAddresses;
30
31 /**
32 * Class constructor used by the JSON library to create an object.
33 *
34 * @param speakerName the name of the BGP router inside SDN network
35 * @param attachmentDpid the DPID where the BGP router is attached to
36 * @param attachmentPort the port where the BGP router is attached to
37 * @param macAddress the MAC address of the BGP router
38 */
39 @JsonCreator
40 public BgpSpeaker(@JsonProperty("name") String speakerName,
41 @JsonProperty("attachmentDpid") String attachmentDpid,
42 @JsonProperty("attachmentPort") int attachmentPort,
43 @JsonProperty("macAddress") String macAddress) {
44
45 this.speakerName = speakerName;
46 this.macAddress = MacAddress.valueOf(macAddress);
47 this.attachmentSwitchPort = new ConnectPoint(
48 DeviceId.deviceId(SdnIpConfigReader.dpidToUri(attachmentDpid)),
49 PortNumber.portNumber(attachmentPort));
50 }
51
52 /**
53 * Sets the addresses we configured for the BGP speaker on all virtual
54 * {@link Interface}s.
55 *
56 * @param interfaceAddresses a list of IP addresses of the BGP speaker
57 * configured on all virtual interfaces
58 */
59 @JsonProperty("interfaceAddresses")
60 public void setInterfaceAddresses(
61 List<InterfaceAddress> interfaceAddresses) {
62 this.interfaceAddresses = interfaceAddresses;
63 }
64
65 /**
66 * Gets the BGP speaker name.
67 *
68 * @return the BGP speaker name
69 */
70 public String getSpeakerName() {
71 return speakerName;
72 }
73
74 /**
75 * Gets the switch port where the BGP speaker is attached.
76 *
77 * @return the switch port where the BGP speaker is attached
78 */
79 public ConnectPoint getAttachmentSwitchPort() {
80 return attachmentSwitchPort;
81 }
82
83 /**
84 * Gets the MAC address of the BGP speaker.
85 *
86 * @return the MAC address of the BGP speaker
87 */
88 public MacAddress getMacAddress() {
89 return macAddress;
90 }
91
92 /**
93 * Gets all IP addresses configured on all {@link Interface}s of the
94 * BGP speaker.
95 *
96 * @return a list of IP addresses of the BGP speaker configured on all
97 * virtual interfaces
98 */
99 public List<InterfaceAddress> getInterfaceAddresses() {
100 return interfaceAddresses;
101 }
102
103 @Override
104 public boolean equals(Object other) {
105 if (!(other instanceof BgpSpeaker)) {
106 return false;
107 }
108
109 BgpSpeaker otherBgpSpeaker = (BgpSpeaker) other;
110
111 return speakerName.equals(otherBgpSpeaker.speakerName) &&
112 attachmentSwitchPort.equals(
113 otherBgpSpeaker.attachmentSwitchPort) &&
114 macAddress.equals(otherBgpSpeaker.macAddress) &&
115 interfaceAddresses.equals(otherBgpSpeaker.interfaceAddresses);
116 }
117
118 @Override
119 public int hashCode() {
120 return Objects.hash(speakerName, attachmentSwitchPort, macAddress,
121 interfaceAddresses);
122
123 }
124}