blob: 6e5e0c3b60439238512895890162b103ef612625 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.linkdiscovery;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08002
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.
Ray Milkey269ffb92014-04-03 14:43:30 -070014 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080015 * @author srini
16 */
17public class NodePortTuple {
18 protected long nodeId; // switch DPID
19 protected short portId; // switch port id
20
21 /**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080022 * Creates a NodePortTuple
Ray Milkey269ffb92014-04-03 14:43:30 -070023 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080024 * @param nodeId The DPID of the switch
25 * @param portId The port of the switch
26 */
27 public NodePortTuple(long nodeId, short portId) {
28 this.nodeId = nodeId;
29 this.portId = portId;
30 }
31
32 public NodePortTuple(long nodeId, int portId) {
33 this.nodeId = nodeId;
34 this.portId = (short) portId;
35 }
36
37 @JsonProperty("switch")
Ray Milkey269ffb92014-04-03 14:43:30 -070038 @JsonSerialize(using = DPIDSerializer.class)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080039 public long getNodeId() {
40 return nodeId;
41 }
Ray Milkey269ffb92014-04-03 14:43:30 -070042
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080043 public void setNodeId(long nodeId) {
44 this.nodeId = nodeId;
45 }
Ray Milkey269ffb92014-04-03 14:43:30 -070046
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080047 @JsonProperty("port")
Ray Milkey269ffb92014-04-03 14:43:30 -070048 @JsonSerialize(using = UShortSerializer.class)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080049 public short getPortId() {
50 return portId;
51 }
Ray Milkey269ffb92014-04-03 14:43:30 -070052
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080053 public void setPortId(short portId) {
54 this.portId = portId;
55 }
Ray Milkey269ffb92014-04-03 14:43:30 -070056
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080057 public String toString() {
58 return "[id=" + HexString.toHexString(nodeId) + ", port=" + new Short(portId) + "]";
59 }
60
61 @Override
62 public int hashCode() {
63 final int prime = 31;
64 int result = 1;
65 result = prime * result + (int) (nodeId ^ (nodeId >>> 32));
66 result = prime * result + portId;
67 return result;
68 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (this == obj)
73 return true;
74 if (obj == null)
75 return false;
76 if (getClass() != obj.getClass())
77 return false;
78 NodePortTuple other = (NodePortTuple) obj;
79 if (nodeId != other.nodeId)
80 return false;
81 if (portId != other.portId)
82 return false;
83 return true;
84 }
Ray Milkey269ffb92014-04-03 14:43:30 -070085
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080086 /**
87 * API to return a String value formed wtih NodeID and PortID
88 * The portID is a 16-bit field, so mask it as an integer to get full
89 * positive value
Ray Milkey269ffb92014-04-03 14:43:30 -070090 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080091 * @return
92 */
93 public String toKeyString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070094 return (HexString.toHexString(nodeId) + "|" + (portId & 0xffff));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080095 }
96}