blob: 4983529d6b6c76e07b8ca1b90e740c3f67c09655 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.topology;
2
3import net.floodlightcontroller.core.web.serializers.DPIDSerializer;
4import net.floodlightcontroller.core.web.serializers.UShortSerializer;
5
6import org.codehaus.jackson.annotate.JsonProperty;
7import org.codehaus.jackson.map.annotate.JsonSerialize;
8import 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 */
16public class NodePortTuple {
17 protected long nodeId; // switch DPID
18 protected short portId; // switch port id
19
20 /**
21 * Creates a NodePortTuple
22 * @param nodeId The DPID of the switch
23 * @param portId The port of the switch
24 */
25 public NodePortTuple(long nodeId, short portId) {
26 this.nodeId = nodeId;
27 this.portId = portId;
28 }
29
30 public NodePortTuple(long nodeId, int portId) {
31 this.nodeId = nodeId;
32 this.portId = (short) portId;
33 }
34
35 @JsonProperty("switch")
36 @JsonSerialize(using=DPIDSerializer.class)
37 public long getNodeId() {
38 return nodeId;
39 }
40 public void setNodeId(long nodeId) {
41 this.nodeId = nodeId;
42 }
43 @JsonProperty("port")
44 @JsonSerialize(using=UShortSerializer.class)
45 public short getPortId() {
46 return portId;
47 }
48 public void setPortId(short portId) {
49 this.portId = portId;
50 }
51
52 public String toString() {
53 return "[id=" + HexString.toHexString(nodeId) + ", port=" + new Short(portId) + "]";
54 }
55
56 @Override
57 public int hashCode() {
58 final int prime = 31;
59 int result = 1;
60 result = prime * result + (int) (nodeId ^ (nodeId >>> 32));
61 result = prime * result + portId;
62 return result;
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj)
68 return true;
69 if (obj == null)
70 return false;
71 if (getClass() != obj.getClass())
72 return false;
73 NodePortTuple other = (NodePortTuple) obj;
74 if (nodeId != other.nodeId)
75 return false;
76 if (portId != other.portId)
77 return false;
78 return true;
79 }
80
81 /**
82 * API to return a String value formed wtih NodeID and PortID
83 * The portID is a 16-bit field, so mask it as an integer to get full
84 * positive value
85 * @return
86 */
87 public String toKeyString() {
88 return (HexString.toHexString(nodeId)+ "|" + (portId & 0xffff));
89 }
90}