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 | * Represents an address of a {@link BgpSpeaker} configured on an |
| 13 | * {@link Interface}. |
| 14 | * <p/> |
| 15 | * Each InterfaceAddress includes the interface name and an IP address. |
| 16 | */ |
| 17 | public class InterfaceAddress { |
| 18 | private final ConnectPoint connectPoint; |
| 19 | private final IpAddress ipAddress; |
| 20 | |
| 21 | /** |
| 22 | * Class constructor used by the JSON library to create an object. |
| 23 | * |
| 24 | * @param interfaceName the interface name for which an IP address of a BGP |
| 25 | * router is configured |
| 26 | * @param ipAddress the IP address of a {@link BgpSpeaker} configured on |
| 27 | * the interface |
| 28 | */ |
| 29 | public InterfaceAddress(@JsonProperty("interfaceDpid") String dpid, |
| 30 | @JsonProperty("interfacePort") int port, |
| 31 | @JsonProperty("ipAddress") String ipAddress) { |
| 32 | this.connectPoint = new ConnectPoint( |
| 33 | DeviceId.deviceId(SdnIpConfigReader.dpidToUri(dpid)), |
| 34 | PortNumber.portNumber(port)); |
| 35 | this.ipAddress = IpAddress.valueOf(ipAddress); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Gets the connection point of the peer. |
| 40 | * |
| 41 | * @return the connection point |
| 42 | */ |
| 43 | public ConnectPoint getConnectPoint() { |
| 44 | return connectPoint; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Gets the IP address of a BGP speaker configured on an {@link Interface}. |
| 49 | * |
| 50 | * @return the IP address |
| 51 | */ |
| 52 | public IpAddress getIpAddress() { |
| 53 | return ipAddress; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public int hashCode() { |
| 58 | return Objects.hash(connectPoint, ipAddress); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean equals(Object obj) { |
| 63 | if (obj == this) { |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | if (!(obj instanceof InterfaceAddress)) { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | InterfaceAddress that = (InterfaceAddress) obj; |
| 72 | return Objects.equals(this.connectPoint, that.connectPoint) |
| 73 | && Objects.equals(this.ipAddress, that.ipAddress); |
| 74 | } |
| 75 | } |