blob: 7831925b2da5eef35b7623af29940bac0a585044 [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
7
8/**
9 * Immutable class to identify a Link between 2 ports.
10 */
11public final class LinkTuple {
12
13 private final SwitchPort src;
14 private final SwitchPort dst;
15
16 /**
17 * Default constructor for Serializer.
18 */
19 protected LinkTuple() {
20 src = null;
21 dst = null;
22 }
23
24 /**
25 * Constructor.
26 *
27 * @param src source port
28 * @param dst destination port
29 */
30 public LinkTuple(SwitchPort src, SwitchPort dst) {
Yuta HIGUCHIa860dff2014-08-20 21:16:30 -070031 this.src = checkNotNull(src);
32 this.dst = checkNotNull(dst);
Yuta HIGUCHIa16a8232014-07-03 19:45:40 -070033 }
34
35 /**
36 * Creates the Link object.
37 *
38 * @param srcDpid source switch DPID
39 * @param srcPortNo source port number
40 * @param dstDpid destination switch DPID
41 * @param dstPortNo destination port number
42 */
43 public LinkTuple(Dpid srcDpid, PortNumber srcPortNo,
44 Dpid dstDpid, PortNumber dstPortNo) {
45 this(new SwitchPort(srcDpid, srcPortNo),
46 new SwitchPort(dstDpid, dstPortNo));
47 }
48
49 /**
50 * Gets the source port.
51 *
52 * @return source port
53 */
54 public SwitchPort getSrc() {
55 return src;
56 }
57
58 /**
59 * Gets the destination port.
60 *
61 * @return destination port
62 */
63 public SwitchPort getDst() {
64 return dst;
65 }
66
67 @Override
68 public int hashCode() {
69 final int prime = 31;
70 int result = 1;
71 result = prime * result + ((src == null) ? 0 : src.hashCode());
72 result = prime * result + ((dst == null) ? 0 : dst.hashCode());
73 return result;
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (obj == null) {
82 return false;
83 }
84 if (getClass() != obj.getClass()) {
85 return false;
86 }
87 LinkTuple other = (LinkTuple) obj;
88 return Objects.equals(src, other.src) &&
89 Objects.equals(dst, other.dst);
90 }
91
92 @Override
93 public String toString() {
94 return "(" + src + "=>" + dst + ")";
95 }
96}