blob: 6e89b1f1415930536b63c03ae5ebeecc7f00a1c0 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.sdnip.config;
Jonathan Hartbac07a02014-10-13 21:29:54 -070017
Jonathan Hartd7bd9822014-10-20 18:18:02 -070018import com.fasterxml.jackson.annotation.JsonCreator;
19import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070020import com.google.common.base.MoreObjects;
Jonathan Hart2339a8d2015-01-20 11:08:20 -080021import org.onlab.packet.MacAddress;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.PortNumber;
25
26import java.util.List;
27import java.util.Objects;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070028
Jonathan Hartbac07a02014-10-13 21:29:54 -070029/**
30 * Represents a BGP daemon in SDN network.
Thomas Vachuska4b420772014-10-30 16:46:17 -070031 * <p>
Jonathan Hartbac07a02014-10-13 21:29:54 -070032 * Each BGP speaker has a attachment point, which includes a switch DPID and a
33 * switch port. Each BGP speaker has one MAC address and several IP addresses,
34 * which are used to peer with BGP peers outside the SDN network. For each
35 * peer outside the SDN network, we configure a different IP address to BGP
36 * speaker inside the SDN network.
Thomas Vachuska4b420772014-10-30 16:46:17 -070037 * </p>
38 * <p>
Jonathan Hartbac07a02014-10-13 21:29:54 -070039 * Each BGP speaker has a name, which is a unique identifying String that is
40 * used to reference this speaker in the configuration.
Thomas Vachuska4b420772014-10-30 16:46:17 -070041 * </p>
Jonathan Hartbac07a02014-10-13 21:29:54 -070042 */
43public class BgpSpeaker {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070044 private final String name;
45 private final ConnectPoint connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070046 private final MacAddress macAddress;
47 private List<InterfaceAddress> interfaceAddresses;
48
49 /**
50 * Class constructor used by the JSON library to create an object.
51 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070052 * @param name the name of the BGP speaker inside SDN network
53 * @param attachmentDpid the DPID where the BGP speaker is attached to
54 * @param attachmentPort the port where the BGP speaker is attached to
55 * @param macAddress the MAC address of the BGP speaker
Jonathan Hartbac07a02014-10-13 21:29:54 -070056 */
57 @JsonCreator
Jonathan Hartdc711bd2014-10-15 11:24:23 -070058 public BgpSpeaker(@JsonProperty("name") String name,
Jonathan Hartbac07a02014-10-13 21:29:54 -070059 @JsonProperty("attachmentDpid") String attachmentDpid,
Jonathan Hart2339a8d2015-01-20 11:08:20 -080060 @JsonProperty("attachmentPort") long attachmentPort,
Jonathan Hartbac07a02014-10-13 21:29:54 -070061 @JsonProperty("macAddress") String macAddress) {
62
Jonathan Hartdc711bd2014-10-15 11:24:23 -070063 this.name = name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070064 this.macAddress = MacAddress.valueOf(macAddress);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070065 this.connectPoint = new ConnectPoint(
Jonathan Hart9965d772014-12-02 10:28:34 -080066 DeviceId.deviceId(SdnIpConfigurationReader.dpidToUri(attachmentDpid)),
Jonathan Hartbac07a02014-10-13 21:29:54 -070067 PortNumber.portNumber(attachmentPort));
68 }
69
70 /**
71 * Sets the addresses we configured for the BGP speaker on all virtual
72 * {@link Interface}s.
73 *
74 * @param interfaceAddresses a list of IP addresses of the BGP speaker
75 * configured on all virtual interfaces
76 */
77 @JsonProperty("interfaceAddresses")
78 public void setInterfaceAddresses(
79 List<InterfaceAddress> interfaceAddresses) {
80 this.interfaceAddresses = interfaceAddresses;
81 }
82
83 /**
84 * Gets the BGP speaker name.
85 *
86 * @return the BGP speaker name
87 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070088 public String name() {
89 return name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070090 }
91
92 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070093 * Gets the connect point where the BGP speaker is attached.
Jonathan Hartbac07a02014-10-13 21:29:54 -070094 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070095 * @return the connect point
Jonathan Hartbac07a02014-10-13 21:29:54 -070096 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070097 public ConnectPoint connectPoint() {
98 return connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070099 }
100
101 /**
102 * Gets the MAC address of the BGP speaker.
103 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700104 * @return the MAC address
Jonathan Hartbac07a02014-10-13 21:29:54 -0700105 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700106 public MacAddress macAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -0700107 return macAddress;
108 }
109
110 /**
111 * Gets all IP addresses configured on all {@link Interface}s of the
112 * BGP speaker.
113 *
114 * @return a list of IP addresses of the BGP speaker configured on all
115 * virtual interfaces
116 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700117 public List<InterfaceAddress> interfaceAddresses() {
Jonathan Hartbac07a02014-10-13 21:29:54 -0700118 return interfaceAddresses;
119 }
120
121 @Override
122 public boolean equals(Object other) {
123 if (!(other instanceof BgpSpeaker)) {
124 return false;
125 }
126
127 BgpSpeaker otherBgpSpeaker = (BgpSpeaker) other;
128
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700129 return name.equals(otherBgpSpeaker.name) &&
130 connectPoint.equals(
131 otherBgpSpeaker.connectPoint) &&
Jonathan Hartbac07a02014-10-13 21:29:54 -0700132 macAddress.equals(otherBgpSpeaker.macAddress) &&
133 interfaceAddresses.equals(otherBgpSpeaker.interfaceAddresses);
134 }
135
136 @Override
137 public int hashCode() {
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700138 return Objects.hash(name, connectPoint, macAddress,
Jonathan Hartbac07a02014-10-13 21:29:54 -0700139 interfaceAddresses);
140
141 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700142
143 @Override
144 public String toString() {
145 return MoreObjects.toStringHelper(getClass())
146 .add("speakerName", name)
147 .add("connectPoint", connectPoint)
148 .add("macAddress", macAddress)
149 .add("interfaceAddresses", interfaceAddresses)
150 .toString();
151 }
Jonathan Hartbac07a02014-10-13 21:29:54 -0700152}