Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
| 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 Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 19 | package org.onlab.onos.sdnip.config; |
| 20 | |
| 21 | import java.util.List; |
| 22 | import java.util.Objects; |
| 23 | |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 24 | import org.onlab.onos.net.ConnectPoint; |
| 25 | import org.onlab.onos.net.DeviceId; |
| 26 | import org.onlab.onos.net.PortNumber; |
| 27 | import org.onlab.packet.MacAddress; |
| 28 | |
Jonathan Hart | d7bd982 | 2014-10-20 18:18:02 -0700 | [diff] [blame] | 29 | import com.fasterxml.jackson.annotation.JsonCreator; |
| 30 | import com.fasterxml.jackson.annotation.JsonProperty; |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 31 | import com.google.common.base.MoreObjects; |
| 32 | |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 33 | /** |
| 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 | */ |
| 45 | public class BgpSpeaker { |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 46 | private final String name; |
| 47 | private final ConnectPoint connectPoint; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 48 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 54 | * @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 Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 58 | */ |
| 59 | @JsonCreator |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 60 | public BgpSpeaker(@JsonProperty("name") String name, |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 61 | @JsonProperty("attachmentDpid") String attachmentDpid, |
| 62 | @JsonProperty("attachmentPort") int attachmentPort, |
| 63 | @JsonProperty("macAddress") String macAddress) { |
| 64 | |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 65 | this.name = name; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 66 | this.macAddress = MacAddress.valueOf(macAddress); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 67 | this.connectPoint = new ConnectPoint( |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 68 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 90 | public String name() { |
| 91 | return name; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 95 | * Gets the connect point where the BGP speaker is attached. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 96 | * |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 97 | * @return the connect point |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 98 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 99 | public ConnectPoint connectPoint() { |
| 100 | return connectPoint; |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Gets the MAC address of the BGP speaker. |
| 105 | * |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 106 | * @return the MAC address |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 107 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 108 | public MacAddress macAddress() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 109 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 119 | public List<InterfaceAddress> interfaceAddresses() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 120 | 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 Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 131 | return name.equals(otherBgpSpeaker.name) && |
| 132 | connectPoint.equals( |
| 133 | otherBgpSpeaker.connectPoint) && |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 134 | macAddress.equals(otherBgpSpeaker.macAddress) && |
| 135 | interfaceAddresses.equals(otherBgpSpeaker.interfaceAddresses); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public int hashCode() { |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 140 | return Objects.hash(name, connectPoint, macAddress, |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 141 | interfaceAddresses); |
| 142 | |
| 143 | } |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 144 | |
| 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 Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 154 | } |