blob: eb433044c8c4331ad1896c82d02e00063e4416d7 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
Jonathan Hart23701d12014-04-03 10:45:48 -070018package net.onrc.onos.core.linkdiscovery;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019
20import net.floodlightcontroller.core.web.serializers.DPIDSerializer;
21import net.floodlightcontroller.core.web.serializers.UShortSerializer;
22
23import org.codehaus.jackson.annotate.JsonProperty;
24import org.codehaus.jackson.map.annotate.JsonSerialize;
25import org.openflow.util.HexString;
26
27public class Link {
28 private long src;
29 private short srcPort;
30 private long dst;
31 private short dstPort;
32
33
34 public Link(long srcId, short srcPort, long dstId, short dstPort) {
35 this.src = srcId;
36 this.srcPort = srcPort;
37 this.dst = dstId;
38 this.dstPort = dstPort;
39 }
40
41 // Convenience method
42 public Link(long srcId, int srcPort, long dstId, int dstPort) {
43 this.src = srcId;
44 this.srcPort = (short) srcPort;
45 this.dst = dstId;
46 this.dstPort = (short) dstPort;
47 }
48
49 @JsonProperty("src-switch")
50 @JsonSerialize(using=DPIDSerializer.class)
51 public long getSrc() {
52 return src;
53 }
54
55 @JsonProperty("src-port")
56 @JsonSerialize(using=UShortSerializer.class)
57 public short getSrcPort() {
58 return srcPort;
59 }
60
61 @JsonProperty("dst-switch")
62 @JsonSerialize(using=DPIDSerializer.class)
63 public long getDst() {
64 return dst;
65 }
66 @JsonProperty("dst-port")
67 @JsonSerialize(using=UShortSerializer.class)
68 public short getDstPort() {
69 return dstPort;
70 }
71
72 @Override
73 public int hashCode() {
74 final int prime = 31;
75 int result = 1;
76 result = prime * result + (int) (dst ^ (dst >>> 32));
77 result = prime * result + dstPort;
78 result = prime * result + (int) (src ^ (src >>> 32));
79 result = prime * result + srcPort;
80 return result;
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj)
86 return true;
87 if (obj == null)
88 return false;
89 if (getClass() != obj.getClass())
90 return false;
91 Link other = (Link) obj;
92 if (dst != other.dst)
93 return false;
94 if (dstPort != other.dstPort)
95 return false;
96 if (src != other.src)
97 return false;
98 if (srcPort != other.srcPort)
99 return false;
100 return true;
101 }
102
103
104 @Override
105 public String toString() {
106 return "Link [src=" + HexString.toHexString(this.src)
107 + " outPort="
108 + (srcPort & 0xffff)
109 + ", dst=" + HexString.toHexString(this.dst)
110 + ", inPort="
111 + (dstPort & 0xffff)
112 + "]";
113 }
114
115 public String toKeyString() {
116 return (HexString.toHexString(this.src) + "|" +
117 (this.srcPort & 0xffff) + "|" +
118 HexString.toHexString(this.dst) + "|" +
119 (this.dstPort & 0xffff) );
120 }
121}
122