Jonathan Hart | 8f6dc09 | 2014-04-18 15:56:43 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.sdnip; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 2 | |
| 3 | import java.net.InetAddress; |
Sho SHIMIZU | 84ce03e | 2014-07-08 10:45:22 -0700 | [diff] [blame] | 4 | import java.util.Objects; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 5 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 6 | import org.codehaus.jackson.annotate.JsonProperty; |
| 7 | |
| 8 | import com.google.common.net.InetAddresses; |
| 9 | |
Jonathan Hart | 4e7c22e | 2014-04-09 10:59:34 -0700 | [diff] [blame] | 10 | /** |
| 11 | * Configuration details for a BGP peer. It contains the peer's IP address and |
| 12 | * an interface name which maps to the interface they are attached at. |
| 13 | */ |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 14 | public class BgpPeer { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 15 | private final String interfaceName; |
| 16 | private final InetAddress ipAddress; |
Jonathan Hart | 4aa2b4e | 2013-09-24 14:50:23 +1200 | [diff] [blame] | 17 | |
Jonathan Hart | 4e7c22e | 2014-04-09 10:59:34 -0700 | [diff] [blame] | 18 | /** |
| 19 | * Class constructor, taking the interface name and IP address of the peer. |
| 20 | * |
| 21 | * @param interfaceName the String name of the interface which can be used |
| 22 | * to look up the interface this peer is attached at |
| 23 | * @param ipAddress the IP address of the peer as a String |
| 24 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | public BgpPeer(@JsonProperty("interface") String interfaceName, |
| 26 | @JsonProperty("ipAddress") String ipAddress) { |
| 27 | this.interfaceName = interfaceName; |
| 28 | this.ipAddress = InetAddresses.forString(ipAddress); |
| 29 | } |
| 30 | |
Jonathan Hart | 4e7c22e | 2014-04-09 10:59:34 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Gets the interface name. |
| 33 | * |
| 34 | * @return the interface name as a String |
| 35 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 36 | public String getInterfaceName() { |
| 37 | return interfaceName; |
| 38 | } |
| 39 | |
Jonathan Hart | 4e7c22e | 2014-04-09 10:59:34 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Gets the IP address of the peer. |
| 42 | * |
| 43 | * @return the IP address as an {@link InetAddress} object |
| 44 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | public InetAddress getIpAddress() { |
| 46 | return ipAddress; |
| 47 | } |
Sho SHIMIZU | 84ce03e | 2014-07-08 10:45:22 -0700 | [diff] [blame] | 48 | |
| 49 | @Override |
| 50 | public int hashCode() { |
| 51 | return Objects.hash(interfaceName, ipAddress); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public boolean equals(Object obj) { |
| 56 | if (obj == this) { |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | if (!(obj instanceof BgpPeer)) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | BgpPeer that = (BgpPeer) obj; |
| 65 | return Objects.equals(this.interfaceName, that.interfaceName) |
| 66 | && Objects.equals(this.ipAddress, that.ipAddress); |
| 67 | } |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 68 | } |