blob: 0339401f560a329de4cfcade649923f5e5d6e28e [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
Jonathan Hart23701d12014-04-03 10:45:48 -07005import net.onrc.onos.core.util.Dpid;
6import net.onrc.onos.core.util.Port;
7import net.onrc.onos.core.util.SwitchPort;
Jonathan Hart832a7cb2013-06-24 11:25:35 +12008
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 {
Ray Milkey269ffb92014-04-03 14:43:30 -070016 private final String name;
17 private final long dpid;
18 private final short port;
19 private final InetAddress ipAddress;
20 private final int prefixLength;
Jonathan Hart9575cb62013-07-05 13:43:49 +120021
Ray Milkey269ffb92014-04-03 14:43:30 -070022 @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;
33 }
Jonathan Hart832a7cb2013-06-24 11:25:35 +120034
Ray Milkey269ffb92014-04-03 14:43:30 -070035 public String getName() {
36 return name;
37 }
Jonathan Hart832a7cb2013-06-24 11:25:35 +120038
Ray Milkey269ffb92014-04-03 14:43:30 -070039 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));
43 }
Jonathan Hart832a7cb2013-06-24 11:25:35 +120044
Ray Milkey269ffb92014-04-03 14:43:30 -070045 public long getDpid() {
46 return dpid;
47 }
48
49 public short getPort() {
50 return port;
51 }
52
53 public InetAddress getIpAddress() {
54 return ipAddress;
55 }
56
57 public int getPrefixLength() {
58 return prefixLength;
59 }
60
61 @Override
62 public boolean equals(Object other) {
Jonathan Hart738980f2014-04-04 10:11:15 -070063 if (!(other instanceof Interface)) {
Ray Milkey269ffb92014-04-03 14:43:30 -070064 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}