blob: 9dc8ff268a98a9b8dbb1d6d92003951d7f1eb9bc [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/**
14 * Represents an address of a {@link BgpSpeaker} configured on an
15 * {@link Interface}.
16 * <p/>
17 * Each InterfaceAddress includes the interface name and an IP address.
18 */
19public class InterfaceAddress {
20 private final ConnectPoint connectPoint;
21 private final IpAddress ipAddress;
22
23 /**
Jonathan Hartdc711bd2014-10-15 11:24:23 -070024 * Creates an InterfaceAddress object.
Jonathan Hartbac07a02014-10-13 21:29:54 -070025 *
Jonathan Hartdc711bd2014-10-15 11:24:23 -070026 * @param dpid the DPID of the interface as a String
27 * @param port the port of the interface
Jonathan Hartbac07a02014-10-13 21:29:54 -070028 * @param ipAddress the IP address of a {@link BgpSpeaker} configured on
29 * the interface
30 */
31 public InterfaceAddress(@JsonProperty("interfaceDpid") String dpid,
32 @JsonProperty("interfacePort") int port,
33 @JsonProperty("ipAddress") String ipAddress) {
34 this.connectPoint = new ConnectPoint(
35 DeviceId.deviceId(SdnIpConfigReader.dpidToUri(dpid)),
36 PortNumber.portNumber(port));
37 this.ipAddress = IpAddress.valueOf(ipAddress);
38 }
39
40 /**
41 * Gets the connection point of the peer.
42 *
43 * @return the connection point
44 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070045 public ConnectPoint connectPoint() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070046 return connectPoint;
47 }
48
49 /**
50 * Gets the IP address of a BGP speaker configured on an {@link Interface}.
51 *
52 * @return the IP address
53 */
Jonathan Hartdc711bd2014-10-15 11:24:23 -070054 public IpAddress ipAddress() {
Jonathan Hartbac07a02014-10-13 21:29:54 -070055 return ipAddress;
56 }
57
58 @Override
59 public int hashCode() {
60 return Objects.hash(connectPoint, ipAddress);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (obj == this) {
66 return true;
67 }
68
69 if (!(obj instanceof InterfaceAddress)) {
70 return false;
71 }
72
73 InterfaceAddress that = (InterfaceAddress) obj;
74 return Objects.equals(this.connectPoint, that.connectPoint)
75 && Objects.equals(this.ipAddress, that.ipAddress);
76 }
Jonathan Hartdc711bd2014-10-15 11:24:23 -070077
78 @Override
79 public String toString() {
80 return MoreObjects.toStringHelper(getClass())
81 .add("connectPoint", connectPoint)
82 .add("ipAddress", ipAddress)
83 .toString();
84 }
Jonathan Hartbac07a02014-10-13 21:29:54 -070085}