blob: f44698f1d87191410f5bf4abf45cb88c5ac3270c [file] [log] [blame]
Yuta HIGUCHIa16a8232014-07-03 19:45:40 -07001package net.onrc.onos.core.util;
2
Yuta HIGUCHIa860dff2014-08-20 21:16:30 -07003import static com.google.common.base.Preconditions.checkNotNull;
Yuta HIGUCHIa16a8232014-07-03 19:45:40 -07004
Yuta HIGUCHIa860dff2014-08-20 21:16:30 -07005import java.util.Objects;
Yuta HIGUCHIa16a8232014-07-03 19:45:40 -07006
Yuta HIGUCHI6d7ee9f2014-08-22 09:56:50 -07007import javax.annotation.concurrent.Immutable;
8
Yuta HIGUCHIa16a8232014-07-03 19:45:40 -07009
10/**
11 * Immutable class to identify a Link between 2 ports.
12 */
Yuta HIGUCHI6d7ee9f2014-08-22 09:56:50 -070013@Immutable
Yuta HIGUCHIa16a8232014-07-03 19:45:40 -070014public final class LinkTuple {
15
16 private final SwitchPort src;
17 private final SwitchPort dst;
18
19 /**
20 * Default constructor for Serializer.
21 */
22 protected LinkTuple() {
23 src = null;
24 dst = null;
25 }
26
27 /**
28 * Constructor.
29 *
30 * @param src source port
31 * @param dst destination port
32 */
33 public LinkTuple(SwitchPort src, SwitchPort dst) {
Yuta HIGUCHIa860dff2014-08-20 21:16:30 -070034 this.src = checkNotNull(src);
35 this.dst = checkNotNull(dst);
Yuta HIGUCHIa16a8232014-07-03 19:45:40 -070036 }
37
38 /**
39 * Creates the Link object.
40 *
41 * @param srcDpid source switch DPID
42 * @param srcPortNo source port number
43 * @param dstDpid destination switch DPID
44 * @param dstPortNo destination port number
45 */
46 public LinkTuple(Dpid srcDpid, PortNumber srcPortNo,
47 Dpid dstDpid, PortNumber dstPortNo) {
48 this(new SwitchPort(srcDpid, srcPortNo),
49 new SwitchPort(dstDpid, dstPortNo));
50 }
51
52 /**
53 * Gets the source port.
54 *
55 * @return source port
56 */
57 public SwitchPort getSrc() {
58 return src;
59 }
60
61 /**
62 * Gets the destination port.
63 *
64 * @return destination port
65 */
66 public SwitchPort getDst() {
67 return dst;
68 }
69
70 @Override
71 public int hashCode() {
Yuta HIGUCHI6d7ee9f2014-08-22 09:56:50 -070072 return Objects.hash(src, dst);
Yuta HIGUCHIa16a8232014-07-03 19:45:40 -070073 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (this == obj) {
78 return true;
79 }
80 if (obj == null) {
81 return false;
82 }
83 if (getClass() != obj.getClass()) {
84 return false;
85 }
86 LinkTuple other = (LinkTuple) obj;
87 return Objects.equals(src, other.src) &&
88 Objects.equals(dst, other.dst);
89 }
90
91 @Override
92 public String toString() {
93 return "(" + src + "=>" + dst + ")";
94 }
95}