blob: dc44db3bfa24c59b6bb06c2528b364b3415b0140 [file] [log] [blame]
Jonathan Hartbac07a02014-10-13 21:29:54 -07001package org.onlab.onos.sdnip.config;
2
3import java.util.Objects;
4
Jonathan Hartbac07a02014-10-13 21:29:54 -07005import org.onlab.onos.net.ConnectPoint;
6import org.onlab.onos.net.DeviceId;
7import org.onlab.onos.net.PortNumber;
8import org.onlab.packet.IpAddress;
9
Jonathan Hartd7bd9822014-10-20 18:18:02 -070010import com.fasterxml.jackson.annotation.JsonProperty;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070011import com.google.common.base.MoreObjects;
12
Jonathan Hartbac07a02014-10-13 21:29:54 -070013/**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070014 * Configuration details for a BGP peer.
Jonathan Hartbac07a02014-10-13 21:29:54 -070015 */
16public class BgpPeer {
17 private final ConnectPoint connectPoint;
18 private final IpAddress ipAddress;
19
20 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070021 * Creates a new BgpPeer.
Jonathan Hartbac07a02014-10-13 21:29:54 -070022 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070023 * @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 Hartbac07a02014-10-13 21:29:54 -070025 * @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 Hartdc711bd2014-10-15 11:24:23 -070041 public ConnectPoint connectPoint() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070042 return connectPoint;
43 }
44
45 /**
46 * Gets the IP address of the peer.
47 *
48 * @return the IP address
49 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070050 public IpAddress ipAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070051 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 Hartdc711bd2014-10-15 11:24:23 -070073
74 @Override
75 public String toString() {
76 return MoreObjects.toStringHelper(getClass())
77 .add("connectPoint", connectPoint)
78 .add("ipAddress", ipAddress)
79 .toString();
80 }
Jonathan Hartbac07a02014-10-13 21:29:54 -070081}