blob: 5db8f0ad3732392d4c6fc6687f237ecbf8e62dc8 [file] [log] [blame]
Jonathan Hart832a7cb2013-06-24 11:25:35 +12001package net.onrc.onos.ofcontroller.bgproute;
2
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;
17 private final SwitchPort switchPort;
18 private final long dpid;
19 private final short port;
20 private final InetAddress ipAddress;
21 private final int prefixLength;
22
23 @JsonCreator
24 public Interface (@JsonProperty("name") String name,
25 @JsonProperty("dpid") String dpid,
26 @JsonProperty("port") short port,
27 @JsonProperty("ipAddress") String ipAddress,
28 @JsonProperty("prefixLength") int prefixLength) {
29 this.name = name;
30 this.dpid = HexString.toLong(dpid);
31 this.port = port;
32 this.ipAddress = InetAddresses.forString(ipAddress);
33 this.prefixLength = prefixLength;
34 this.switchPort = new SwitchPort(new Dpid(this.dpid), new Port(this.port));
35 }
Jonathan Hart832a7cb2013-06-24 11:25:35 +120036
Jonathan Hart9575cb62013-07-05 13:43:49 +120037 public String getName() {
38 return name;
39 }
40
Jonathan Hart4aa2b4e2013-09-24 14:50:23 +120041 public SwitchPort getSwitchPort() {
42 //TODO SwitchPort, Dpid and Port are mutable, but they could probably
43 //be made immutable which would prevent the need to copy
44 return new SwitchPort(new Dpid(dpid), new Port(port));
Jonathan Hart832a7cb2013-06-24 11:25:35 +120045 }
46
47 public long getDpid() {
48 return dpid;
49 }
50
Jonathan Hart832a7cb2013-06-24 11:25:35 +120051 public short getPort() {
52 return port;
53 }
54
Jonathan Hart832a7cb2013-06-24 11:25:35 +120055 public InetAddress getIpAddress() {
56 return ipAddress;
57 }
58
Jonathan Hart832a7cb2013-06-24 11:25:35 +120059 public int getPrefixLength() {
60 return prefixLength;
61 }
Jonathan Hart45107222013-10-22 17:35:04 -070062
63 @Override
64 public boolean equals(Object other) {
65 if (other == null || !(other instanceof Interface)) {
66 return false;
67 }
68
69 Interface otherInterface = (Interface)other;
70
71 //Don't check switchPort as it's comprised of dpid and port
72 return (name.equals(otherInterface.name)) &&
73 (dpid == otherInterface.dpid) &&
74 (port == otherInterface.port) &&
75 (ipAddress.equals(otherInterface.ipAddress)) &&
76 (prefixLength == otherInterface.prefixLength);
77 }
78
79 @Override
80 public int hashCode() {
81 int hash = 17;
82 hash = 31 * hash + name.hashCode();
83 hash = 31 * hash + (int)(dpid ^ dpid >>> 32);
84 hash = 31 * hash + (int)port;
85 hash = 31 * hash + ipAddress.hashCode();
86 hash = 31 * hash + prefixLength;
87 return hash;
88 }
Jonathan Hart832a7cb2013-06-24 11:25:35 +120089}