Jonathan Hart | 382623d | 2014-04-03 09:48:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.bgproute; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 2 | |
| 3 | import java.net.InetAddress; |
| 4 | |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.util.Dpid; |
| 6 | import net.onrc.onos.core.util.Port; |
| 7 | import net.onrc.onos.core.util.SwitchPort; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 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 { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 16 | 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 Hart | 9575cb6 | 2013-07-05 13:43:49 +1200 | [diff] [blame] | 21 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 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; |
| 33 | } |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 34 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 35 | public String getName() { |
| 36 | return name; |
| 37 | } |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 38 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [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)); |
| 43 | } |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 44 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 45 | 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) { |
| 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 | } |