Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.bgproute; |
| 2 | |
| 3 | import java.net.InetAddress; |
| 4 | |
| 5 | import net.onrc.onos.ofcontroller.util.Dpid; |
| 6 | import net.onrc.onos.ofcontroller.util.Port; |
| 7 | import net.onrc.onos.ofcontroller.util.SwitchPort; |
| 8 | |
Jonathan Hart | 4aa2b4e | 2013-09-24 14:50:23 +1200 | [diff] [blame] | 9 | import org.codehaus.jackson.annotate.JsonCreator; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 10 | import org.codehaus.jackson.annotate.JsonProperty; |
| 11 | import org.openflow.util.HexString; |
| 12 | |
| 13 | import com.google.common.net.InetAddresses; |
| 14 | |
| 15 | public class Interface { |
Jonathan Hart | 4aa2b4e | 2013-09-24 14:50:23 +1200 | [diff] [blame] | 16 | private final String name; |
Jonathan Hart | 4aa2b4e | 2013-09-24 14:50:23 +1200 | [diff] [blame] | 17 | 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 Hart | 4aa2b4e | 2013-09-24 14:50:23 +1200 | [diff] [blame] | 33 | } |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 34 | |
Jonathan Hart | 9575cb6 | 2013-07-05 13:43:49 +1200 | [diff] [blame] | 35 | public String getName() { |
| 36 | return name; |
| 37 | } |
| 38 | |
Jonathan Hart | 4aa2b4e | 2013-09-24 14:50:23 +1200 | [diff] [blame] | 39 | 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 Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | public long getDpid() { |
| 46 | return dpid; |
| 47 | } |
| 48 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 49 | public short getPort() { |
| 50 | return port; |
| 51 | } |
| 52 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 53 | public InetAddress getIpAddress() { |
| 54 | return ipAddress; |
| 55 | } |
| 56 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 57 | public int getPrefixLength() { |
| 58 | return prefixLength; |
| 59 | } |
Jonathan Hart | 4510722 | 2013-10-22 17:35:04 -0700 | [diff] [blame] | 60 | |
| 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 Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 87 | } |