Yuta HIGUCHI

Slice out LinkKey

Change-Id: Ibfcafd07858c5357a2321220e01ddab44f347923
1 +package org.onlab.onos.net;
2 +
3 +import java.util.Objects;
4 +
5 +import com.google.common.base.MoreObjects;
6 +
7 +// TODO Consider renaming.
8 +// it's an identifier for a Link, but it's not ElementId, so not using LinkId.
9 +/**
10 + * Immutable representation of a link identity.
11 + */
12 +public class LinkKey {
13 +
14 + private final ConnectPoint src;
15 + private final ConnectPoint dst;
16 +
17 + /**
18 + * Returns source connection point.
19 + *
20 + * @return source connection point
21 + */
22 + public ConnectPoint src() {
23 + return src;
24 + }
25 +
26 + /**
27 + * Returns destination connection point.
28 + *
29 + * @return destination connection point
30 + */
31 + public ConnectPoint dst() {
32 + return dst;
33 + }
34 +
35 + /**
36 + * Creates a link identifier with source and destination connection point.
37 + *
38 + * @param src source connection point
39 + * @param dst destination connection point
40 + */
41 + public LinkKey(ConnectPoint src, ConnectPoint dst) {
42 + this.src = src;
43 + this.dst = dst;
44 + }
45 +
46 + @Override
47 + public int hashCode() {
48 + return Objects.hash(src(), dst);
49 + }
50 +
51 + @Override
52 + public boolean equals(Object obj) {
53 + if (this == obj) {
54 + return true;
55 + }
56 + if (obj instanceof LinkKey) {
57 + final LinkKey other = (LinkKey) obj;
58 + return Objects.equals(this.src(), other.src()) &&
59 + Objects.equals(this.dst, other.dst);
60 + }
61 + return false;
62 + }
63 +
64 + @Override
65 + public String toString() {
66 + return MoreObjects.toStringHelper(getClass())
67 + .add("src", src())
68 + .add("dst", dst)
69 + .toString();
70 + }
71 +}
...@@ -3,6 +3,7 @@ package org.onlab.onos.net.trivial.impl; ...@@ -3,6 +3,7 @@ package org.onlab.onos.net.trivial.impl;
3 import com.google.common.collect.HashMultimap; 3 import com.google.common.collect.HashMultimap;
4 import com.google.common.collect.ImmutableSet; 4 import com.google.common.collect.ImmutableSet;
5 import com.google.common.collect.Multimap; 5 import com.google.common.collect.Multimap;
6 +
6 import org.apache.felix.scr.annotations.Activate; 7 import org.apache.felix.scr.annotations.Activate;
7 import org.apache.felix.scr.annotations.Component; 8 import org.apache.felix.scr.annotations.Component;
8 import org.apache.felix.scr.annotations.Deactivate; 9 import org.apache.felix.scr.annotations.Deactivate;
...@@ -11,6 +12,7 @@ import org.onlab.onos.net.ConnectPoint; ...@@ -11,6 +12,7 @@ import org.onlab.onos.net.ConnectPoint;
11 import org.onlab.onos.net.DefaultLink; 12 import org.onlab.onos.net.DefaultLink;
12 import org.onlab.onos.net.DeviceId; 13 import org.onlab.onos.net.DeviceId;
13 import org.onlab.onos.net.Link; 14 import org.onlab.onos.net.Link;
15 +import org.onlab.onos.net.LinkKey;
14 import org.onlab.onos.net.link.LinkDescription; 16 import org.onlab.onos.net.link.LinkDescription;
15 import org.onlab.onos.net.link.LinkEvent; 17 import org.onlab.onos.net.link.LinkEvent;
16 import org.onlab.onos.net.link.LinkStore; 18 import org.onlab.onos.net.link.LinkStore;
...@@ -22,7 +24,6 @@ import org.slf4j.Logger; ...@@ -22,7 +24,6 @@ import org.slf4j.Logger;
22 import java.util.Collections; 24 import java.util.Collections;
23 import java.util.HashSet; 25 import java.util.HashSet;
24 import java.util.Map; 26 import java.util.Map;
25 -import java.util.Objects;
26 import java.util.Set; 27 import java.util.Set;
27 import java.util.concurrent.ConcurrentHashMap; 28 import java.util.concurrent.ConcurrentHashMap;
28 29
...@@ -123,7 +124,7 @@ public class SimpleLinkStore ...@@ -123,7 +124,7 @@ public class SimpleLinkStore
123 // Creates and stores the link and returns the appropriate event. 124 // Creates and stores the link and returns the appropriate event.
124 private LinkEvent createLink(ProviderId providerId, LinkKey key, 125 private LinkEvent createLink(ProviderId providerId, LinkKey key,
125 LinkDescription linkDescription) { 126 LinkDescription linkDescription) {
126 - DefaultLink link = new DefaultLink(providerId, key.src, key.dst, 127 + DefaultLink link = new DefaultLink(providerId, key.src(), key.dst(),
127 linkDescription.type()); 128 linkDescription.type());
128 synchronized (this) { 129 synchronized (this) {
129 links.put(key, link); 130 links.put(key, link);
...@@ -165,33 +166,4 @@ public class SimpleLinkStore ...@@ -165,33 +166,4 @@ public class SimpleLinkStore
165 return null; 166 return null;
166 } 167 }
167 } 168 }
168 -
169 - // Auxiliary key to track links.
170 - private class LinkKey {
171 - final ConnectPoint src;
172 - final ConnectPoint dst;
173 -
174 - LinkKey(ConnectPoint src, ConnectPoint dst) {
175 - this.src = src;
176 - this.dst = dst;
177 - }
178 -
179 - @Override
180 - public int hashCode() {
181 - return Objects.hash(src, dst);
182 - }
183 -
184 - @Override
185 - public boolean equals(Object obj) {
186 - if (this == obj) {
187 - return true;
188 - }
189 - if (obj instanceof LinkKey) {
190 - final LinkKey other = (LinkKey) obj;
191 - return Objects.equals(this.src, other.src) &&
192 - Objects.equals(this.dst, other.dst);
193 - }
194 - return false;
195 - }
196 - }
197 } 169 }
......