blob: 254cc248a62495e45a936f372e55cadd621c03de [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * 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 **/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
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")
Ray Milkey269ffb92014-04-03 14:43:30 -070050 @JsonSerialize(using = DPIDSerializer.class)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080051 public long getSrc() {
52 return src;
53 }
54
55 @JsonProperty("src-port")
Ray Milkey269ffb92014-04-03 14:43:30 -070056 @JsonSerialize(using = UShortSerializer.class)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080057 public short getSrcPort() {
58 return srcPort;
59 }
60
61 @JsonProperty("dst-switch")
Ray Milkey269ffb92014-04-03 14:43:30 -070062 @JsonSerialize(using = DPIDSerializer.class)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080063 public long getDst() {
64 return dst;
65 }
Ray Milkey269ffb92014-04-03 14:43:30 -070066
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080067 @JsonProperty("dst-port")
Ray Milkey269ffb92014-04-03 14:43:30 -070068 @JsonSerialize(using = UShortSerializer.class)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080069 public short getDstPort() {
70 return dstPort;
71 }
72
73 @Override
74 public int hashCode() {
75 final int prime = 31;
76 int result = 1;
77 result = prime * result + (int) (dst ^ (dst >>> 32));
78 result = prime * result + dstPort;
79 result = prime * result + (int) (src ^ (src >>> 32));
80 result = prime * result + srcPort;
81 return result;
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj)
87 return true;
88 if (obj == null)
89 return false;
90 if (getClass() != obj.getClass())
91 return false;
92 Link other = (Link) obj;
93 if (dst != other.dst)
94 return false;
95 if (dstPort != other.dstPort)
96 return false;
97 if (src != other.src)
98 return false;
99 if (srcPort != other.srcPort)
100 return false;
101 return true;
102 }
103
104
105 @Override
106 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700107 return "Link [src=" + HexString.toHexString(this.src)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800108 + " outPort="
109 + (srcPort & 0xffff)
110 + ", dst=" + HexString.toHexString(this.dst)
111 + ", inPort="
112 + (dstPort & 0xffff)
113 + "]";
114 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700115
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800116 public String toKeyString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700117 return (HexString.toHexString(this.src) + "|" +
118 (this.srcPort & 0xffff) + "|" +
119 HexString.toHexString(this.dst) + "|" +
120 (this.dstPort & 0xffff));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800121 }
122}
123