blob: 4e79672006b8d26210d98e8f6139d84ef7bf2c3a [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.
Thomas Vachuska4b420772014-10-30 16:46:17 -070032 * <p>
Jonathan Hartbac07a02014-10-13 21:29:54 -070033 * 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.
Thomas Vachuska4b420772014-10-30 16:46:17 -070038 * </p>
39 * <p>
Jonathan Hartbac07a02014-10-13 21:29:54 -070040 * Each BGP speaker has a name, which is a unique identifying String that is
41 * used to reference this speaker in the configuration.
Thomas Vachuska4b420772014-10-30 16:46:17 -070042 * </p>
Jonathan Hartbac07a02014-10-13 21:29:54 -070043 */
44public class BgpSpeaker {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070045 private final String name;
46 private final ConnectPoint connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070047 private final MacAddress macAddress;
48 private List<InterfaceAddress> interfaceAddresses;
49
50 /**
51 * Class constructor used by the JSON library to create an object.
52 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070053 * @param name the name of the BGP speaker inside SDN network
54 * @param attachmentDpid the DPID where the BGP speaker is attached to
55 * @param attachmentPort the port where the BGP speaker is attached to
56 * @param macAddress the MAC address of the BGP speaker
Jonathan Hartbac07a02014-10-13 21:29:54 -070057 */
58 @JsonCreator
Jonathan Hartdc711bd2014-10-15 11:24:23 -070059 public BgpSpeaker(@JsonProperty("name") String name,
Jonathan Hartbac07a02014-10-13 21:29:54 -070060 @JsonProperty("attachmentDpid") String attachmentDpid,
61 @JsonProperty("attachmentPort") int attachmentPort,
62 @JsonProperty("macAddress") String macAddress) {
63
Jonathan Hartdc711bd2014-10-15 11:24:23 -070064 this.name = name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070065 this.macAddress = MacAddress.valueOf(macAddress);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070066 this.connectPoint = new ConnectPoint(
Jonathan Hartbac07a02014-10-13 21:29:54 -070067 DeviceId.deviceId(SdnIpConfigReader.dpidToUri(attachmentDpid)),
68 PortNumber.portNumber(attachmentPort));
69 }
70
71 /**
72 * Sets the addresses we configured for the BGP speaker on all virtual
73 * {@link Interface}s.
74 *
75 * @param interfaceAddresses a list of IP addresses of the BGP speaker
76 * configured on all virtual interfaces
77 */
78 @JsonProperty("interfaceAddresses")
79 public void setInterfaceAddresses(
80 List<InterfaceAddress> interfaceAddresses) {
81 this.interfaceAddresses = interfaceAddresses;
82 }
83
84 /**
85 * Gets the BGP speaker name.
86 *
87 * @return the BGP speaker name
88 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070089 public String name() {
90 return name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070091 }
92
93 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070094 * Gets the connect point where the BGP speaker is attached.
Jonathan Hartbac07a02014-10-13 21:29:54 -070095 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070096 * @return the connect point
Jonathan Hartbac07a02014-10-13 21:29:54 -070097 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070098 public ConnectPoint connectPoint() {
99 return connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -0700100 }
101
102 /**
103 * Gets the MAC address of the BGP speaker.
104 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700105 * @return the MAC address
Jonathan Hartbac07a02014-10-13 21:29:54 -0700106 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700107 public MacAddress macAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -0700108 return macAddress;
109 }
110
111 /**
112 * Gets all IP addresses configured on all {@link Interface}s of the
113 * BGP speaker.
114 *
115 * @return a list of IP addresses of the BGP speaker configured on all
116 * virtual interfaces
117 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700118 public List<InterfaceAddress> interfaceAddresses() {
Jonathan Hartbac07a02014-10-13 21:29:54 -0700119 return interfaceAddresses;
120 }
121
122 @Override
123 public boolean equals(Object other) {
124 if (!(other instanceof BgpSpeaker)) {
125 return false;
126 }
127
128 BgpSpeaker otherBgpSpeaker = (BgpSpeaker) other;
129
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700130 return name.equals(otherBgpSpeaker.name) &&
131 connectPoint.equals(
132 otherBgpSpeaker.connectPoint) &&
Jonathan Hartbac07a02014-10-13 21:29:54 -0700133 macAddress.equals(otherBgpSpeaker.macAddress) &&
134 interfaceAddresses.equals(otherBgpSpeaker.interfaceAddresses);
135 }
136
137 @Override
138 public int hashCode() {
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700139 return Objects.hash(name, connectPoint, macAddress,
Jonathan Hartbac07a02014-10-13 21:29:54 -0700140 interfaceAddresses);
141
142 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700143
144 @Override
145 public String toString() {
146 return MoreObjects.toStringHelper(getClass())
147 .add("speakerName", name)
148 .add("connectPoint", connectPoint)
149 .add("macAddress", macAddress)
150 .add("interfaceAddresses", interfaceAddresses)
151 .toString();
152 }
Jonathan Hartbac07a02014-10-13 21:29:54 -0700153}