blob: fa5d56875072ccf562e94137b6af652f93432856 [file] [log] [blame]
Jonathan Hart382623d2014-04-03 09:48:11 -07001package net.onrc.onos.apps.bgproute;
Jonathan Hart832a7cb2013-06-24 11:25:35 +12002
3import java.net.InetAddress;
4
5import net.onrc.onos.ofcontroller.util.Dpid;
6import net.onrc.onos.ofcontroller.util.Port;
7import net.onrc.onos.ofcontroller.util.SwitchPort;
8
Jonathan Hart4aa2b4e2013-09-24 14:50:23 +12009import org.codehaus.jackson.annotate.JsonCreator;
Jonathan Hart832a7cb2013-06-24 11:25:35 +120010import org.codehaus.jackson.annotate.JsonProperty;
11import org.openflow.util.HexString;
12
13import com.google.common.net.InetAddresses;
14
15public class Interface {
Jonathan Hart4aa2b4e2013-09-24 14:50:23 +120016 private final String name;
Jonathan Hart4aa2b4e2013-09-24 14:50:23 +120017 private final long dpid;
18 private final short port;
19 private final InetAddress ipAddress;
20 private final int prefixLength;
21
22 @JsonCreator
23 public Interface (@JsonProperty("name") String name,
24 @JsonProperty("dpid") String dpid,
25 @JsonProperty("port") short port,
26 @JsonProperty("ipAddress") String ipAddress,
27 @JsonProperty("prefixLength") int prefixLength) {
28 this.name = name;
29 this.dpid = HexString.toLong(dpid);
30 this.port = port;
31 this.ipAddress = InetAddresses.forString(ipAddress);
32 this.prefixLength = prefixLength;
Jonathan Hart4aa2b4e2013-09-24 14:50:23 +120033 }
Jonathan Hart832a7cb2013-06-24 11:25:35 +120034
Jonathan Hart9575cb62013-07-05 13:43:49 +120035 public String getName() {
36 return name;
37 }
38
Jonathan Hart4aa2b4e2013-09-24 14:50:23 +120039 public SwitchPort getSwitchPort() {
40 //TODO SwitchPort, Dpid and Port are mutable, but they could probably
41 //be made immutable which would prevent the need to copy
42 return new SwitchPort(new Dpid(dpid), new Port(port));
Jonathan Hart832a7cb2013-06-24 11:25:35 +120043 }
44
45 public long getDpid() {
46 return dpid;
47 }
48
Jonathan Hart832a7cb2013-06-24 11:25:35 +120049 public short getPort() {
50 return port;
51 }
52
Jonathan Hart832a7cb2013-06-24 11:25:35 +120053 public InetAddress getIpAddress() {
54 return ipAddress;
55 }
56
Jonathan Hart832a7cb2013-06-24 11:25:35 +120057 public int getPrefixLength() {
58 return prefixLength;
59 }
Jonathan Hart45107222013-10-22 17:35:04 -070060
61 @Override
62 public boolean equals(Object other) {
63 if (other == null || !(other instanceof Interface)) {
64 return false;
65 }
66
67 Interface otherInterface = (Interface)other;
68
69 //Don't check switchPort as it's comprised of dpid and port
70 return (name.equals(otherInterface.name)) &&
71 (dpid == otherInterface.dpid) &&
72 (port == otherInterface.port) &&
73 (ipAddress.equals(otherInterface.ipAddress)) &&
74 (prefixLength == otherInterface.prefixLength);
75 }
76
77 @Override
78 public int hashCode() {
79 int hash = 17;
80 hash = 31 * hash + name.hashCode();
81 hash = 31 * hash + (int)(dpid ^ dpid >>> 32);
82 hash = 31 * hash + (int)port;
83 hash = 31 * hash + ipAddress.hashCode();
84 hash = 31 * hash + prefixLength;
85 return hash;
86 }
Jonathan Hart832a7cb2013-06-24 11:25:35 +120087}