blob: 6c99c8ccff8ae5b7c2942f94302927d23183e4ab [file] [log] [blame]
Jonathan Hart8f6dc092014-04-18 15:56:43 -07001package net.onrc.onos.apps.sdnip;
Jonathan Hart832a7cb2013-06-24 11:25:35 +12002
3import java.net.InetAddress;
Sho SHIMIZU84ce03e2014-07-08 10:45:22 -07004import java.util.Objects;
Jonathan Hart832a7cb2013-06-24 11:25:35 +12005
Jonathan Hart832a7cb2013-06-24 11:25:35 +12006import org.codehaus.jackson.annotate.JsonProperty;
7
8import com.google.common.net.InetAddresses;
9
Jonathan Hart4e7c22e2014-04-09 10:59:34 -070010/**
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 Hart832a7cb2013-06-24 11:25:35 +120014public class BgpPeer {
Ray Milkey269ffb92014-04-03 14:43:30 -070015 private final String interfaceName;
16 private final InetAddress ipAddress;
Jonathan Hart4aa2b4e2013-09-24 14:50:23 +120017
Jonathan Hart4e7c22e2014-04-09 10:59:34 -070018 /**
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 Milkey269ffb92014-04-03 14:43:30 -070025 public BgpPeer(@JsonProperty("interface") String interfaceName,
26 @JsonProperty("ipAddress") String ipAddress) {
27 this.interfaceName = interfaceName;
28 this.ipAddress = InetAddresses.forString(ipAddress);
29 }
30
Jonathan Hart4e7c22e2014-04-09 10:59:34 -070031 /**
32 * Gets the interface name.
33 *
34 * @return the interface name as a String
35 */
Ray Milkey269ffb92014-04-03 14:43:30 -070036 public String getInterfaceName() {
37 return interfaceName;
38 }
39
Jonathan Hart4e7c22e2014-04-09 10:59:34 -070040 /**
41 * Gets the IP address of the peer.
42 *
43 * @return the IP address as an {@link InetAddress} object
44 */
Ray Milkey269ffb92014-04-03 14:43:30 -070045 public InetAddress getIpAddress() {
46 return ipAddress;
47 }
Sho SHIMIZU84ce03e2014-07-08 10:45:22 -070048
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 Hart832a7cb2013-06-24 11:25:35 +120068}