blob: 8aad97f97c93578a3e9ea45058b19d4d59ea584a [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Jonathan Hartbac07a02014-10-13 21:29:54 -070019package org.onlab.onos.sdnip.config;
20
21import java.util.List;
22import java.util.Objects;
23
Jonathan Hartbac07a02014-10-13 21:29:54 -070024import org.onlab.onos.net.ConnectPoint;
25import org.onlab.onos.net.DeviceId;
26import org.onlab.onos.net.PortNumber;
27import org.onlab.packet.MacAddress;
28
Jonathan Hartd7bd9822014-10-20 18:18:02 -070029import com.fasterxml.jackson.annotation.JsonCreator;
30import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070031import com.google.common.base.MoreObjects;
32
Jonathan Hartbac07a02014-10-13 21:29:54 -070033/**
34 * Represents a BGP daemon in SDN network.
35 * <p/>
36 * Each BGP speaker has a attachment point, which includes a switch DPID and a
37 * switch port. Each BGP speaker has one MAC address and several IP addresses,
38 * which are used to peer with BGP peers outside the SDN network. For each
39 * peer outside the SDN network, we configure a different IP address to BGP
40 * speaker inside the SDN network.
41 * <p/>
42 * Each BGP speaker has a name, which is a unique identifying String that is
43 * used to reference this speaker in the configuration.
44 */
45public class BgpSpeaker {
Jonathan Hartdc711bd2014-10-15 11:24:23 -070046 private final String name;
47 private final ConnectPoint connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -070048 private final MacAddress macAddress;
49 private List<InterfaceAddress> interfaceAddresses;
50
51 /**
52 * Class constructor used by the JSON library to create an object.
53 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070054 * @param name the name of the BGP speaker inside SDN network
55 * @param attachmentDpid the DPID where the BGP speaker is attached to
56 * @param attachmentPort the port where the BGP speaker is attached to
57 * @param macAddress the MAC address of the BGP speaker
Jonathan Hartbac07a02014-10-13 21:29:54 -070058 */
59 @JsonCreator
Jonathan Hartdc711bd2014-10-15 11:24:23 -070060 public BgpSpeaker(@JsonProperty("name") String name,
Jonathan Hartbac07a02014-10-13 21:29:54 -070061 @JsonProperty("attachmentDpid") String attachmentDpid,
62 @JsonProperty("attachmentPort") int attachmentPort,
63 @JsonProperty("macAddress") String macAddress) {
64
Jonathan Hartdc711bd2014-10-15 11:24:23 -070065 this.name = name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070066 this.macAddress = MacAddress.valueOf(macAddress);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070067 this.connectPoint = new ConnectPoint(
Jonathan Hartbac07a02014-10-13 21:29:54 -070068 DeviceId.deviceId(SdnIpConfigReader.dpidToUri(attachmentDpid)),
69 PortNumber.portNumber(attachmentPort));
70 }
71
72 /**
73 * Sets the addresses we configured for the BGP speaker on all virtual
74 * {@link Interface}s.
75 *
76 * @param interfaceAddresses a list of IP addresses of the BGP speaker
77 * configured on all virtual interfaces
78 */
79 @JsonProperty("interfaceAddresses")
80 public void setInterfaceAddresses(
81 List<InterfaceAddress> interfaceAddresses) {
82 this.interfaceAddresses = interfaceAddresses;
83 }
84
85 /**
86 * Gets the BGP speaker name.
87 *
88 * @return the BGP speaker name
89 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070090 public String name() {
91 return name;
Jonathan Hartbac07a02014-10-13 21:29:54 -070092 }
93
94 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070095 * Gets the connect point where the BGP speaker is attached.
Jonathan Hartbac07a02014-10-13 21:29:54 -070096 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070097 * @return the connect point
Jonathan Hartbac07a02014-10-13 21:29:54 -070098 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070099 public ConnectPoint connectPoint() {
100 return connectPoint;
Jonathan Hartbac07a02014-10-13 21:29:54 -0700101 }
102
103 /**
104 * Gets the MAC address of the BGP speaker.
105 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700106 * @return the MAC address
Jonathan Hartbac07a02014-10-13 21:29:54 -0700107 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700108 public MacAddress macAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -0700109 return macAddress;
110 }
111
112 /**
113 * Gets all IP addresses configured on all {@link Interface}s of the
114 * BGP speaker.
115 *
116 * @return a list of IP addresses of the BGP speaker configured on all
117 * virtual interfaces
118 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700119 public List<InterfaceAddress> interfaceAddresses() {
Jonathan Hartbac07a02014-10-13 21:29:54 -0700120 return interfaceAddresses;
121 }
122
123 @Override
124 public boolean equals(Object other) {
125 if (!(other instanceof BgpSpeaker)) {
126 return false;
127 }
128
129 BgpSpeaker otherBgpSpeaker = (BgpSpeaker) other;
130
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700131 return name.equals(otherBgpSpeaker.name) &&
132 connectPoint.equals(
133 otherBgpSpeaker.connectPoint) &&
Jonathan Hartbac07a02014-10-13 21:29:54 -0700134 macAddress.equals(otherBgpSpeaker.macAddress) &&
135 interfaceAddresses.equals(otherBgpSpeaker.interfaceAddresses);
136 }
137
138 @Override
139 public int hashCode() {
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700140 return Objects.hash(name, connectPoint, macAddress,
Jonathan Hartbac07a02014-10-13 21:29:54 -0700141 interfaceAddresses);
142
143 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -0700144
145 @Override
146 public String toString() {
147 return MoreObjects.toStringHelper(getClass())
148 .add("speakerName", name)
149 .add("connectPoint", connectPoint)
150 .add("macAddress", macAddress)
151 .add("interfaceAddresses", interfaceAddresses)
152 .toString();
153 }
Jonathan Hartbac07a02014-10-13 21:29:54 -0700154}