Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 1 | package org.onlab.onos.sdnip.config; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | |
| 5 | import org.codehaus.jackson.annotate.JsonProperty; |
| 6 | import org.onlab.onos.net.ConnectPoint; |
| 7 | import org.onlab.onos.net.DeviceId; |
| 8 | import org.onlab.onos.net.PortNumber; |
| 9 | import org.onlab.packet.IpAddress; |
| 10 | |
| 11 | /** |
| 12 | * Configuration details for a BGP peer. It contains the peer's IP address and |
| 13 | * an interface name which maps to the interface they are attached at. |
| 14 | */ |
| 15 | public class BgpPeer { |
| 16 | private final ConnectPoint connectPoint; |
| 17 | private final IpAddress ipAddress; |
| 18 | |
| 19 | /** |
| 20 | * Class constructor, taking the interface name and IP address of the peer. |
| 21 | * |
| 22 | * @param interfaceName the String name of the interface which can be used |
| 23 | * to look up the interface this peer is attached at |
| 24 | * @param ipAddress the IP address of the peer as a String |
| 25 | */ |
| 26 | public BgpPeer(@JsonProperty("attachmentDpid") String dpid, |
| 27 | @JsonProperty("attachmentPort") int port, |
| 28 | @JsonProperty("ipAddress") String ipAddress) { |
| 29 | this.connectPoint = new ConnectPoint( |
| 30 | DeviceId.deviceId(SdnIpConfigReader.dpidToUri(dpid)), |
| 31 | PortNumber.portNumber(port)); |
| 32 | this.ipAddress = IpAddress.valueOf(ipAddress); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Gets the connection point of the peer. |
| 37 | * |
| 38 | * @return the connection point |
| 39 | */ |
| 40 | public ConnectPoint getConnectPoint() { |
| 41 | return connectPoint; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Gets the IP address of the peer. |
| 46 | * |
| 47 | * @return the IP address |
| 48 | */ |
| 49 | public IpAddress getIpAddress() { |
| 50 | return ipAddress; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public int hashCode() { |
| 55 | return Objects.hash(connectPoint, ipAddress); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public boolean equals(Object obj) { |
| 60 | if (obj == this) { |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | if (!(obj instanceof BgpPeer)) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | BgpPeer that = (BgpPeer) obj; |
| 69 | return Objects.equals(this.connectPoint, that.connectPoint) |
| 70 | && Objects.equals(this.ipAddress, that.ipAddress); |
| 71 | } |
| 72 | } |