blob: cff66335ca14db9a46672ac82333b9cff1f2609e [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;
Jonathan Hartc78b8f62014-08-07 22:31:09 -07008import org.projectfloodlight.openflow.util.HexString;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08009
10/**
11 * A NodePortTuple is similar to a SwitchPortTuple
12 * but it only stores IDs instead of references
13 * to the actual objects.
Yuta HIGUCHIaa132f52014-06-26 10:18:39 -070014 * <!-- CHECKSTYLE IGNORE WriteTag FOR NEXT 1 LINES -->
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 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070022 * 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
Yuta HIGUCHIaa132f52014-06-26 10:18:39 -070057 @Override
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080058 public String toString() {
Pavlin Radoslavovdf826c92014-04-10 14:51:12 -070059 return "[id=" + HexString.toHexString(nodeId) + ", port=" + portId + "]";
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080060 }
61
62 @Override
63 public int hashCode() {
64 final int prime = 31;
65 int result = 1;
66 result = prime * result + (int) (nodeId ^ (nodeId >>> 32));
67 result = prime * result + portId;
68 return result;
69 }
70
71 @Override
72 public boolean equals(Object obj) {
Ray Milkeyb29e6262014-04-09 16:02:14 -070073 if (this == obj) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080074 return true;
Ray Milkeyb29e6262014-04-09 16:02:14 -070075 }
76 if (obj == null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080077 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070078 }
79 if (getClass() != obj.getClass()) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080080 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070081 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080082 NodePortTuple other = (NodePortTuple) obj;
Ray Milkeyb29e6262014-04-09 16:02:14 -070083 if (nodeId != other.nodeId) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080084 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070085 }
86 if (portId != other.portId) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080087 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070088 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080089 return true;
90 }
Ray Milkey269ffb92014-04-03 14:43:30 -070091
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080092 /**
93 * API to return a String value formed wtih NodeID and PortID
94 * The portID is a 16-bit field, so mask it as an integer to get full
Ray Milkeyb41100a2014-04-10 10:42:15 -070095 * positive value.
Ray Milkey269ffb92014-04-03 14:43:30 -070096 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -070097 * @return a String that uniquely identifies this NodePortTuple
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080098 */
99 public String toKeyString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700100 return (HexString.toHexString(nodeId) + "|" + (portId & 0xffff));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800101 }
102}