blob: 187e8b70f3ae3c169cae09d288b0cd3598d8e38e [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) {
Ray Milkeyb29e6262014-04-09 16:02:14 -070086 if (this == obj) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080087 return true;
Ray Milkeyb29e6262014-04-09 16:02:14 -070088 }
89 if (obj == null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080090 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070091 }
92 if (getClass() != obj.getClass()) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080093 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070094 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080095 Link other = (Link) obj;
Ray Milkeyb29e6262014-04-09 16:02:14 -070096 if (dst != other.dst) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080097 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070098 }
99 if (dstPort != other.dstPort) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800100 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700101 }
102 if (src != other.src) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800103 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700104 }
105 if (srcPort != other.srcPort) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800106 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700107 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800108 return true;
109 }
110
111
112 @Override
113 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700114 return "Link [src=" + HexString.toHexString(this.src)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800115 + " outPort="
116 + (srcPort & 0xffff)
117 + ", dst=" + HexString.toHexString(this.dst)
118 + ", inPort="
119 + (dstPort & 0xffff)
120 + "]";
121 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700122
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800123 public String toKeyString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700124 return (HexString.toHexString(this.src) + "|" +
125 (this.srcPort & 0xffff) + "|" +
126 HexString.toHexString(this.dst) + "|" +
127 (this.dstPort & 0xffff));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800128 }
129}
130