blob: 224ca3ae8c345fd8b2e7e746a44a337f479fb811 [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) {
Ray Milkeyb29e6262014-04-09 16:02:14 -070072 if (this == obj) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080073 return true;
Ray Milkeyb29e6262014-04-09 16:02:14 -070074 }
75 if (obj == null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080076 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070077 }
78 if (getClass() != obj.getClass()) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080079 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070080 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080081 NodePortTuple other = (NodePortTuple) obj;
Ray Milkeyb29e6262014-04-09 16:02:14 -070082 if (nodeId != other.nodeId) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080083 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070084 }
85 if (portId != other.portId) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080086 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070087 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080088 return true;
89 }
Ray Milkey269ffb92014-04-03 14:43:30 -070090
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080091 /**
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
Ray Milkey269ffb92014-04-03 14:43:30 -070095 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080096 * @return
97 */
98 public String toKeyString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070099 return (HexString.toHexString(nodeId) + "|" + (portId & 0xffff));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800100 }
101}