Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Jonathan Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 16 | package org.onosproject.routing.config; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 43ae293 | 2015-01-20 11:08:20 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.annotation.JsonCreator; |
| 19 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 20 | import com.google.common.base.MoreObjects; |
Pavlin Radoslavov | 2020eac | 2015-01-06 17:26:10 -0800 | [diff] [blame] | 21 | import org.onlab.packet.MacAddress; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.DeviceId; |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 24 | import org.onosproject.net.NetTools; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.PortNumber; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 26 | |
Jonathan Hart | 43ae293 | 2015-01-20 11:08:20 -0800 | [diff] [blame] | 27 | import java.util.List; |
| 28 | import java.util.Objects; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 29 | |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Represents a BGP daemon in SDN network. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 32 | * <p> |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 38 | * </p> |
| 39 | * <p> |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 40 | * Each BGP speaker has a name, which is a unique identifying String that is |
| 41 | * used to reference this speaker in the configuration. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 42 | * </p> |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 43 | */ |
| 44 | public class BgpSpeaker { |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 45 | private final String name; |
| 46 | private final ConnectPoint connectPoint; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 47 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 53 | * @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 Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 57 | */ |
| 58 | @JsonCreator |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 59 | public BgpSpeaker(@JsonProperty("name") String name, |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 60 | @JsonProperty("attachmentDpid") String attachmentDpid, |
Jonathan Hart | 43ae293 | 2015-01-20 11:08:20 -0800 | [diff] [blame] | 61 | @JsonProperty("attachmentPort") long attachmentPort, |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 62 | @JsonProperty("macAddress") String macAddress) { |
| 63 | |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 64 | this.name = name; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 65 | this.macAddress = MacAddress.valueOf(macAddress); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 66 | this.connectPoint = new ConnectPoint( |
Jonathan Hart | 90a02c2 | 2015-02-13 11:52:07 -0800 | [diff] [blame] | 67 | DeviceId.deviceId(NetTools.dpidToUri(attachmentDpid)), |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 89 | public String name() { |
| 90 | return name; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 94 | * Gets the connect point where the BGP speaker is attached. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 95 | * |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 96 | * @return the connect point |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 97 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 98 | public ConnectPoint connectPoint() { |
| 99 | return connectPoint; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Gets the MAC address of the BGP speaker. |
| 104 | * |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 105 | * @return the MAC address |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 106 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 107 | public MacAddress macAddress() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 108 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 118 | public List<InterfaceAddress> interfaceAddresses() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 119 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 130 | return name.equals(otherBgpSpeaker.name) && |
| 131 | connectPoint.equals( |
| 132 | otherBgpSpeaker.connectPoint) && |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 133 | macAddress.equals(otherBgpSpeaker.macAddress) && |
| 134 | interfaceAddresses.equals(otherBgpSpeaker.interfaceAddresses); |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public int hashCode() { |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 139 | return Objects.hash(name, connectPoint, macAddress, |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 140 | interfaceAddresses); |
| 141 | |
| 142 | } |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 143 | |
| 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 Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 153 | } |