Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.topology; |
| 2 | |
| 3 | import net.floodlightcontroller.core.web.serializers.DPIDSerializer; |
| 4 | import net.floodlightcontroller.core.web.serializers.UShortSerializer; |
| 5 | |
| 6 | import org.codehaus.jackson.annotate.JsonProperty; |
| 7 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
| 8 | import org.openflow.util.HexString; |
| 9 | |
| 10 | /** |
| 11 | * A NodePortTuple is similar to a SwitchPortTuple |
| 12 | * but it only stores IDs instead of references |
| 13 | * to the actual objects. |
| 14 | * @author srini |
| 15 | */ |
| 16 | public class NodePortTuple { |
| 17 | protected long nodeId; // switch DPID |
| 18 | protected short portId; // switch port id |
| 19 | |
| 20 | /** |
Pavlin Radoslavov | d46b749 | 2013-02-13 11:26:32 -0800 | [diff] [blame] | 21 | * A copy constructor for NodePortTuple. |
| 22 | * |
| 23 | * @param other the object to copy the state from. |
| 24 | */ |
| 25 | public NodePortTuple(NodePortTuple other) { |
| 26 | this.nodeId = other.nodeId; |
| 27 | this.portId = other.portId; |
| 28 | } |
| 29 | |
| 30 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 31 | * Creates a NodePortTuple |
| 32 | * @param nodeId The DPID of the switch |
| 33 | * @param portId The port of the switch |
| 34 | */ |
| 35 | public NodePortTuple(long nodeId, short portId) { |
| 36 | this.nodeId = nodeId; |
| 37 | this.portId = portId; |
| 38 | } |
| 39 | |
| 40 | public NodePortTuple(long nodeId, int portId) { |
| 41 | this.nodeId = nodeId; |
| 42 | this.portId = (short) portId; |
| 43 | } |
| 44 | |
| 45 | @JsonProperty("switch") |
| 46 | @JsonSerialize(using=DPIDSerializer.class) |
| 47 | public long getNodeId() { |
| 48 | return nodeId; |
| 49 | } |
| 50 | public void setNodeId(long nodeId) { |
| 51 | this.nodeId = nodeId; |
| 52 | } |
| 53 | @JsonProperty("port") |
| 54 | @JsonSerialize(using=UShortSerializer.class) |
| 55 | public short getPortId() { |
| 56 | return portId; |
| 57 | } |
| 58 | public void setPortId(short portId) { |
| 59 | this.portId = portId; |
| 60 | } |
| 61 | |
| 62 | public String toString() { |
| 63 | return "[id=" + HexString.toHexString(nodeId) + ", port=" + new Short(portId) + "]"; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public int hashCode() { |
| 68 | final int prime = 31; |
| 69 | int result = 1; |
| 70 | result = prime * result + (int) (nodeId ^ (nodeId >>> 32)); |
| 71 | result = prime * result + portId; |
| 72 | return result; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean equals(Object obj) { |
| 77 | if (this == obj) |
| 78 | return true; |
| 79 | if (obj == null) |
| 80 | return false; |
| 81 | if (getClass() != obj.getClass()) |
| 82 | return false; |
| 83 | NodePortTuple other = (NodePortTuple) obj; |
| 84 | if (nodeId != other.nodeId) |
| 85 | return false; |
| 86 | if (portId != other.portId) |
| 87 | return false; |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * API to return a String value formed wtih NodeID and PortID |
| 93 | * The portID is a 16-bit field, so mask it as an integer to get full |
| 94 | * positive value |
| 95 | * @return |
| 96 | */ |
| 97 | public String toKeyString() { |
| 98 | return (HexString.toHexString(nodeId)+ "|" + (portId & 0xffff)); |
| 99 | } |
| 100 | } |