blob: 38356002f8a10b243c07f79a159f3768a518b845 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Jonathan Hartbac07a02014-10-13 21:29:54 -070016package org.onlab.onos.sdnip.config;
17
18import java.util.List;
19import java.util.Objects;
20
Jonathan Hartbac07a02014-10-13 21:29:54 -070021import org.onlab.onos.net.ConnectPoint;
22import org.onlab.onos.net.DeviceId;
23import org.onlab.onos.net.PortNumber;
24import org.onlab.packet.MacAddress;
25
Jonathan Hartd7bd9822014-10-20 18:18:02 -070026import com.fasterxml.jackson.annotation.JsonCreator;
27import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070028import com.google.common.base.MoreObjects;
29
Jonathan Hartbac07a02014-10-13 21:29:54 -070030/**
31 * Represents a BGP daemon in SDN network.
32 * <p/>
33 * Each BGP speaker has a attachment point, which includes a switch DPID and a
34 * switch port. Each BGP speaker has one MAC address and several IP addresses,
35 * which are used to peer with BGP peers outside the SDN network. For each
36 * peer outside the SDN network, we configure a different IP address to BGP
37 * speaker inside the SDN network.
38 * <p/>
39 * Each BGP speaker has a name, which is a unique identifying String that is
40 * used to reference this speaker in the configuration.
41 */
42public class BgpSpeaker {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070043 private final String name;
44 private final ConnectPoint connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070045 private final MacAddress macAddress;
46 private List<InterfaceAddress> interfaceAddresses;
47
48 /**
49 * Class constructor used by the JSON library to create an object.
50 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070051 * @param name the name of the BGP speaker inside SDN network
52 * @param attachmentDpid the DPID where the BGP speaker is attached to
53 * @param attachmentPort the port where the BGP speaker is attached to
54 * @param macAddress the MAC address of the BGP speaker
Jonathan Hartbac07a02014-10-13 21:29:54 -070055 */
56 @JsonCreator
Jonathan Hartdc711bd2014-10-15 11:24:23 -070057 public BgpSpeaker(@JsonProperty("name") String name,
Jonathan Hartbac07a02014-10-13 21:29:54 -070058 @JsonProperty("attachmentDpid") String attachmentDpid,
59 @JsonProperty("attachmentPort") int attachmentPort,
60 @JsonProperty("macAddress") String macAddress) {
61
Jonathan Hartdc711bd2014-10-15 11:24:23 -070062 this.name = name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070063 this.macAddress = MacAddress.valueOf(macAddress);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070064 this.connectPoint = new ConnectPoint(
Jonathan Hartbac07a02014-10-13 21:29:54 -070065 DeviceId.deviceId(SdnIpConfigReader.dpidToUri(attachmentDpid)),
66 PortNumber.portNumber(attachmentPort));
67 }
68
69 /**
70 * Sets the addresses we configured for the BGP speaker on all virtual
71 * {@link Interface}s.
72 *
73 * @param interfaceAddresses a list of IP addresses of the BGP speaker
74 * configured on all virtual interfaces
75 */
76 @JsonProperty("interfaceAddresses")
77 public void setInterfaceAddresses(
78 List<InterfaceAddress> interfaceAddresses) {
79 this.interfaceAddresses = interfaceAddresses;
80 }
81
82 /**
83 * Gets the BGP speaker name.
84 *
85 * @return the BGP speaker name
86 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070087 public String name() {
88 return name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070089 }
90
91 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070092 * Gets the connect point where the BGP speaker is attached.
Jonathan Hartbac07a02014-10-13 21:29:54 -070093 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070094 * @return the connect point
Jonathan Hartbac07a02014-10-13 21:29:54 -070095 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070096 public ConnectPoint connectPoint() {
97 return connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070098 }
99
100 /**
101 * Gets the MAC address of the BGP speaker.
102 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700103 * @return the MAC address
Jonathan Hartbac07a02014-10-13 21:29:54 -0700104 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700105 public MacAddress macAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -0700106 return macAddress;
107 }
108
109 /**
110 * Gets all IP addresses configured on all {@link Interface}s of the
111 * BGP speaker.
112 *
113 * @return a list of IP addresses of the BGP speaker configured on all
114 * virtual interfaces
115 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700116 public List<InterfaceAddress> interfaceAddresses() {
Jonathan Hartbac07a02014-10-13 21:29:54 -0700117 return interfaceAddresses;
118 }
119
120 @Override
121 public boolean equals(Object other) {
122 if (!(other instanceof BgpSpeaker)) {
123 return false;
124 }
125
126 BgpSpeaker otherBgpSpeaker = (BgpSpeaker) other;
127
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700128 return name.equals(otherBgpSpeaker.name) &&
129 connectPoint.equals(
130 otherBgpSpeaker.connectPoint) &&
Jonathan Hartbac07a02014-10-13 21:29:54 -0700131 macAddress.equals(otherBgpSpeaker.macAddress) &&
132 interfaceAddresses.equals(otherBgpSpeaker.interfaceAddresses);
133 }
134
135 @Override
136 public int hashCode() {
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700137 return Objects.hash(name, connectPoint, macAddress,
Jonathan Hartbac07a02014-10-13 21:29:54 -0700138 interfaceAddresses);
139
140 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700141
142 @Override
143 public String toString() {
144 return MoreObjects.toStringHelper(getClass())
145 .add("speakerName", name)
146 .add("connectPoint", connectPoint)
147 .add("macAddress", macAddress)
148 .add("interfaceAddresses", interfaceAddresses)
149 .toString();
150 }
Jonathan Hartbac07a02014-10-13 21:29:54 -0700151}