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 | |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 11 | import com.google.common.base.MoreObjects; |
| 12 | |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 13 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 14 | * Configuration details for a BGP peer. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 15 | */ |
| 16 | public class BgpPeer { |
| 17 | private final ConnectPoint connectPoint; |
| 18 | private final IpAddress ipAddress; |
| 19 | |
| 20 | /** |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 21 | * Creates a new BgpPeer. |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 22 | * |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 23 | * @param dpid the DPID of the switch the peer is attached at, as a String |
| 24 | * @param port the port the peer is attached at |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 25 | * @param ipAddress the IP address of the peer as a String |
| 26 | */ |
| 27 | public BgpPeer(@JsonProperty("attachmentDpid") String dpid, |
| 28 | @JsonProperty("attachmentPort") int port, |
| 29 | @JsonProperty("ipAddress") String ipAddress) { |
| 30 | this.connectPoint = new ConnectPoint( |
| 31 | DeviceId.deviceId(SdnIpConfigReader.dpidToUri(dpid)), |
| 32 | PortNumber.portNumber(port)); |
| 33 | this.ipAddress = IpAddress.valueOf(ipAddress); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Gets the connection point of the peer. |
| 38 | * |
| 39 | * @return the connection point |
| 40 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 41 | public ConnectPoint connectPoint() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 42 | return connectPoint; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Gets the IP address of the peer. |
| 47 | * |
| 48 | * @return the IP address |
| 49 | */ |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 50 | public IpAddress ipAddress() { |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 51 | return ipAddress; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public int hashCode() { |
| 56 | return Objects.hash(connectPoint, ipAddress); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public boolean equals(Object obj) { |
| 61 | if (obj == this) { |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | if (!(obj instanceof BgpPeer)) { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | BgpPeer that = (BgpPeer) obj; |
| 70 | return Objects.equals(this.connectPoint, that.connectPoint) |
| 71 | && Objects.equals(this.ipAddress, that.ipAddress); |
| 72 | } |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 73 | |
| 74 | @Override |
| 75 | public String toString() { |
| 76 | return MoreObjects.toStringHelper(getClass()) |
| 77 | .add("connectPoint", connectPoint) |
| 78 | .add("ipAddress", ipAddress) |
| 79 | .toString(); |
| 80 | } |
Jonathan Hart | bac07a0 | 2014-10-13 21:29:54 -0700 | [diff] [blame] | 81 | } |