Yuta HIGUCHI

modified LinkKey creation to follow other id objects

Change-Id: Ie70444f9069486d0251482464595f5835cf12539
1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 +import static com.google.common.base.Preconditions.checkNotNull;
4 +
3 import java.util.Objects; 5 import java.util.Objects;
4 6
7 +import org.onlab.onos.net.link.LinkDescription;
8 +
5 import com.google.common.base.MoreObjects; 9 import com.google.common.base.MoreObjects;
6 10
7 // TODO Consider renaming. 11 // TODO Consider renaming.
...@@ -10,7 +14,7 @@ import com.google.common.base.MoreObjects; ...@@ -10,7 +14,7 @@ import com.google.common.base.MoreObjects;
10 /** 14 /**
11 * Immutable representation of a link identity. 15 * Immutable representation of a link identity.
12 */ 16 */
13 -public class LinkKey { 17 +public final class LinkKey {
14 18
15 private final ConnectPoint src; 19 private final ConnectPoint src;
16 private final ConnectPoint dst; 20 private final ConnectPoint dst;
...@@ -39,18 +43,40 @@ public class LinkKey { ...@@ -39,18 +43,40 @@ public class LinkKey {
39 * @param src source connection point 43 * @param src source connection point
40 * @param dst destination connection point 44 * @param dst destination connection point
41 */ 45 */
42 - public LinkKey(ConnectPoint src, ConnectPoint dst) { 46 + private LinkKey(ConnectPoint src, ConnectPoint dst) {
43 - this.src = src; 47 + this.src = checkNotNull(src);
44 - this.dst = dst; 48 + this.dst = checkNotNull(dst);
49 + }
50 +
51 + /**
52 + * Creates a link identifier with source and destination connection point.
53 + *
54 + * @param src source connection point
55 + * @param dst destination connection point
56 + * @return a link identifier
57 + */
58 + public static LinkKey linkKey(ConnectPoint src, ConnectPoint dst) {
59 + return new LinkKey(src, dst);
45 } 60 }
46 61
47 /** 62 /**
48 * Creates a link identifier for the specified link. 63 * Creates a link identifier for the specified link.
49 * 64 *
50 * @param link link descriptor 65 * @param link link descriptor
66 + * @return a link identifier
67 + */
68 + public static LinkKey linkKey(Link link) {
69 + return new LinkKey(link.src(), link.dst());
70 + }
71 +
72 + /**
73 + * Creates a link identifier for the specified link.
74 + *
75 + * @param desc link description
76 + * @return a link identifier
51 */ 77 */
52 - public LinkKey(Link link) { 78 + public static LinkKey linkKey(LinkDescription desc) {
53 - this(link.src(), link.dst()); 79 + return new LinkKey(desc.src(), desc.dst());
54 } 80 }
55 81
56 @Override 82 @Override
...@@ -65,7 +91,7 @@ public class LinkKey { ...@@ -65,7 +91,7 @@ public class LinkKey {
65 } 91 }
66 if (obj instanceof LinkKey) { 92 if (obj instanceof LinkKey) {
67 final LinkKey other = (LinkKey) obj; 93 final LinkKey other = (LinkKey) obj;
68 - return Objects.equals(this.src(), other.src()) && 94 + return Objects.equals(this.src, other.src) &&
69 Objects.equals(this.dst, other.dst); 95 Objects.equals(this.dst, other.dst);
70 } 96 }
71 return false; 97 return false;
...@@ -74,7 +100,7 @@ public class LinkKey { ...@@ -74,7 +100,7 @@ public class LinkKey {
74 @Override 100 @Override
75 public String toString() { 101 public String toString() {
76 return MoreObjects.toStringHelper(getClass()) 102 return MoreObjects.toStringHelper(getClass())
77 - .add("src", src()) 103 + .add("src", src)
78 .add("dst", dst) 104 .add("dst", dst)
79 .toString(); 105 .toString();
80 } 106 }
......
...@@ -28,6 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -28,6 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
28 import static com.google.common.collect.Multimaps.synchronizedSetMultimap; 28 import static com.google.common.collect.Multimaps.synchronizedSetMultimap;
29 import static java.util.concurrent.Executors.newSingleThreadExecutor; 29 import static java.util.concurrent.Executors.newSingleThreadExecutor;
30 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED; 30 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED;
31 +import static org.onlab.onos.net.LinkKey.linkKey;
31 import static org.onlab.util.Tools.namedThreads; 32 import static org.onlab.util.Tools.namedThreads;
32 import static org.slf4j.LoggerFactory.getLogger; 33 import static org.slf4j.LoggerFactory.getLogger;
33 34
...@@ -82,14 +83,14 @@ public class ObjectiveTracker implements ObjectiveTrackerService { ...@@ -82,14 +83,14 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
82 @Override 83 @Override
83 public void addTrackedResources(IntentId intentId, Collection<Link> resources) { 84 public void addTrackedResources(IntentId intentId, Collection<Link> resources) {
84 for (Link link : resources) { 85 for (Link link : resources) {
85 - intentsByLink.put(new LinkKey(link), intentId); 86 + intentsByLink.put(linkKey(link), intentId);
86 } 87 }
87 } 88 }
88 89
89 @Override 90 @Override
90 public void removeTrackedResources(IntentId intentId, Collection<Link> resources) { 91 public void removeTrackedResources(IntentId intentId, Collection<Link> resources) {
91 for (Link link : resources) { 92 for (Link link : resources) {
92 - intentsByLink.remove(new LinkKey(link), intentId); 93 + intentsByLink.remove(linkKey(link), intentId);
93 } 94 }
94 } 95 }
95 96
...@@ -125,7 +126,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { ...@@ -125,7 +126,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
125 if (reason instanceof LinkEvent) { 126 if (reason instanceof LinkEvent) {
126 LinkEvent linkEvent = (LinkEvent) reason; 127 LinkEvent linkEvent = (LinkEvent) reason;
127 if (linkEvent.type() == LINK_REMOVED) { 128 if (linkEvent.type() == LINK_REMOVED) {
128 - Set<IntentId> intentIds = intentsByLink.get(new LinkKey(linkEvent.subject())); 129 + Set<IntentId> intentIds = intentsByLink.get(linkKey(linkEvent.subject()));
129 toBeRecompiled.addAll(intentIds); 130 toBeRecompiled.addAll(intentIds);
130 } 131 }
131 recompileOnly = recompileOnly && linkEvent.type() == LINK_REMOVED; 132 recompileOnly = recompileOnly && linkEvent.type() == LINK_REMOVED;
......
...@@ -67,6 +67,7 @@ import static org.onlab.onos.net.DefaultAnnotations.union; ...@@ -67,6 +67,7 @@ import static org.onlab.onos.net.DefaultAnnotations.union;
67 import static org.onlab.onos.net.DefaultAnnotations.merge; 67 import static org.onlab.onos.net.DefaultAnnotations.merge;
68 import static org.onlab.onos.net.Link.Type.DIRECT; 68 import static org.onlab.onos.net.Link.Type.DIRECT;
69 import static org.onlab.onos.net.Link.Type.INDIRECT; 69 import static org.onlab.onos.net.Link.Type.INDIRECT;
70 +import static org.onlab.onos.net.LinkKey.linkKey;
70 import static org.onlab.onos.net.link.LinkEvent.Type.*; 71 import static org.onlab.onos.net.link.LinkEvent.Type.*;
71 import static org.onlab.util.Tools.namedThreads; 72 import static org.onlab.util.Tools.namedThreads;
72 import static org.slf4j.LoggerFactory.getLogger; 73 import static org.slf4j.LoggerFactory.getLogger;
...@@ -203,7 +204,7 @@ public class GossipLinkStore ...@@ -203,7 +204,7 @@ public class GossipLinkStore
203 204
204 @Override 205 @Override
205 public Link getLink(ConnectPoint src, ConnectPoint dst) { 206 public Link getLink(ConnectPoint src, ConnectPoint dst) {
206 - return links.get(new LinkKey(src, dst)); 207 + return links.get(linkKey(src, dst));
207 } 208 }
208 209
209 @Override 210 @Override
...@@ -237,7 +238,7 @@ public class GossipLinkStore ...@@ -237,7 +238,7 @@ public class GossipLinkStore
237 238
238 final Timestamped<LinkDescription> deltaDesc = new Timestamped<>(linkDescription, newTimestamp); 239 final Timestamped<LinkDescription> deltaDesc = new Timestamped<>(linkDescription, newTimestamp);
239 240
240 - LinkKey key = new LinkKey(linkDescription.src(), linkDescription.dst()); 241 + LinkKey key = linkKey(linkDescription);
241 final LinkEvent event; 242 final LinkEvent event;
242 final Timestamped<LinkDescription> mergedDesc; 243 final Timestamped<LinkDescription> mergedDesc;
243 synchronized (getLinkDescriptions(key)) { 244 synchronized (getLinkDescriptions(key)) {
...@@ -264,7 +265,7 @@ public class GossipLinkStore ...@@ -264,7 +265,7 @@ public class GossipLinkStore
264 ProviderId providerId, 265 ProviderId providerId,
265 Timestamped<LinkDescription> linkDescription) { 266 Timestamped<LinkDescription> linkDescription) {
266 267
267 - LinkKey key = new LinkKey(linkDescription.value().src(), linkDescription.value().dst()); 268 + LinkKey key = linkKey(linkDescription.value());
268 ConcurrentMap<ProviderId, Timestamped<LinkDescription>> descs = getLinkDescriptions(key); 269 ConcurrentMap<ProviderId, Timestamped<LinkDescription>> descs = getLinkDescriptions(key);
269 270
270 synchronized (descs) { 271 synchronized (descs) {
...@@ -357,7 +358,7 @@ public class GossipLinkStore ...@@ -357,7 +358,7 @@ public class GossipLinkStore
357 358
358 @Override 359 @Override
359 public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { 360 public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) {
360 - final LinkKey key = new LinkKey(src, dst); 361 + final LinkKey key = linkKey(src, dst);
361 362
362 DeviceId dstDeviceId = dst.deviceId(); 363 DeviceId dstDeviceId = dst.deviceId();
363 Timestamp timestamp = deviceClockService.getTimestamp(dstDeviceId); 364 Timestamp timestamp = deviceClockService.getTimestamp(dstDeviceId);
......
...@@ -3,6 +3,7 @@ package org.onlab.onos.store.link.impl; ...@@ -3,6 +3,7 @@ package org.onlab.onos.store.link.impl;
3 import static com.google.common.cache.CacheBuilder.newBuilder; 3 import static com.google.common.cache.CacheBuilder.newBuilder;
4 import static org.onlab.onos.net.Link.Type.DIRECT; 4 import static org.onlab.onos.net.Link.Type.DIRECT;
5 import static org.onlab.onos.net.Link.Type.INDIRECT; 5 import static org.onlab.onos.net.Link.Type.INDIRECT;
6 +import static org.onlab.onos.net.LinkKey.linkKey;
6 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_ADDED; 7 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_ADDED;
7 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED; 8 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED;
8 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_UPDATED; 9 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_UPDATED;
...@@ -122,7 +123,7 @@ public class DistributedLinkStore ...@@ -122,7 +123,7 @@ public class DistributedLinkStore
122 123
123 @Override 124 @Override
124 public Link getLink(ConnectPoint src, ConnectPoint dst) { 125 public Link getLink(ConnectPoint src, ConnectPoint dst) {
125 - return links.getUnchecked(new LinkKey(src, dst)).orNull(); 126 + return links.getUnchecked(linkKey(src, dst)).orNull();
126 } 127 }
127 128
128 @Override 129 @Override
...@@ -150,7 +151,7 @@ public class DistributedLinkStore ...@@ -150,7 +151,7 @@ public class DistributedLinkStore
150 @Override 151 @Override
151 public LinkEvent createOrUpdateLink(ProviderId providerId, 152 public LinkEvent createOrUpdateLink(ProviderId providerId,
152 LinkDescription linkDescription) { 153 LinkDescription linkDescription) {
153 - LinkKey key = new LinkKey(linkDescription.src(), linkDescription.dst()); 154 + LinkKey key = linkKey(linkDescription);
154 Optional<DefaultLink> link = links.getUnchecked(key); 155 Optional<DefaultLink> link = links.getUnchecked(key);
155 if (!link.isPresent()) { 156 if (!link.isPresent()) {
156 return createLink(providerId, key, linkDescription); 157 return createLink(providerId, key, linkDescription);
...@@ -216,7 +217,7 @@ public class DistributedLinkStore ...@@ -216,7 +217,7 @@ public class DistributedLinkStore
216 @Override 217 @Override
217 public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { 218 public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) {
218 synchronized (this) { 219 synchronized (this) {
219 - LinkKey key = new LinkKey(src, dst); 220 + LinkKey key = linkKey(src, dst);
220 byte[] keyBytes = serialize(key); 221 byte[] keyBytes = serialize(key);
221 Link link = deserialize(rawLinks.remove(keyBytes)); 222 Link link = deserialize(rawLinks.remove(keyBytes));
222 links.invalidate(key); 223 links.invalidate(key);
......
...@@ -3,6 +3,7 @@ package org.onlab.onos.store.link.impl; ...@@ -3,6 +3,7 @@ package org.onlab.onos.store.link.impl;
3 import static org.junit.Assert.*; 3 import static org.junit.Assert.*;
4 import static org.onlab.onos.net.DeviceId.deviceId; 4 import static org.onlab.onos.net.DeviceId.deviceId;
5 import static org.onlab.onos.net.Link.Type.*; 5 import static org.onlab.onos.net.Link.Type.*;
6 +import static org.onlab.onos.net.LinkKey.linkKey;
6 import static org.onlab.onos.net.link.LinkEvent.Type.*; 7 import static org.onlab.onos.net.link.LinkEvent.Type.*;
7 8
8 import java.util.HashMap; 9 import java.util.HashMap;
...@@ -122,8 +123,8 @@ public class DistributedLinkStoreTest { ...@@ -122,8 +123,8 @@ public class DistributedLinkStoreTest {
122 assertEquals("initialy empty", 0, 123 assertEquals("initialy empty", 0,
123 Iterables.size(linkStore.getLinks())); 124 Iterables.size(linkStore.getLinks()));
124 125
125 - LinkKey linkId1 = new LinkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2)); 126 + LinkKey linkId1 = linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
126 - LinkKey linkId2 = new LinkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1)); 127 + LinkKey linkId2 = linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
127 128
128 putLink(linkId1, DIRECT); 129 putLink(linkId1, DIRECT);
129 putLink(linkId2, DIRECT); 130 putLink(linkId2, DIRECT);
...@@ -134,7 +135,7 @@ public class DistributedLinkStoreTest { ...@@ -134,7 +135,7 @@ public class DistributedLinkStoreTest {
134 135
135 Map<LinkKey, Link> links = new HashMap<>(); 136 Map<LinkKey, Link> links = new HashMap<>();
136 for (Link link : linkStore.getLinks()) { 137 for (Link link : linkStore.getLinks()) {
137 - links.put(new LinkKey(link.src(), link.dst()), link); 138 + links.put(linkKey(link), link);
138 } 139 }
139 140
140 assertLink(linkId1, DIRECT, links.get(linkId1)); 141 assertLink(linkId1, DIRECT, links.get(linkId1));
...@@ -143,9 +144,9 @@ public class DistributedLinkStoreTest { ...@@ -143,9 +144,9 @@ public class DistributedLinkStoreTest {
143 144
144 @Test 145 @Test
145 public final void testGetDeviceEgressLinks() { 146 public final void testGetDeviceEgressLinks() {
146 - LinkKey linkId1 = new LinkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2)); 147 + LinkKey linkId1 = linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
147 - LinkKey linkId2 = new LinkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1)); 148 + LinkKey linkId2 = linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
148 - LinkKey linkId3 = new LinkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3)); 149 + LinkKey linkId3 = linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
149 150
150 putLink(linkId1, DIRECT); 151 putLink(linkId1, DIRECT);
151 putLink(linkId2, DIRECT); 152 putLink(linkId2, DIRECT);
...@@ -166,9 +167,9 @@ public class DistributedLinkStoreTest { ...@@ -166,9 +167,9 @@ public class DistributedLinkStoreTest {
166 167
167 @Test 168 @Test
168 public final void testGetDeviceIngressLinks() { 169 public final void testGetDeviceIngressLinks() {
169 - LinkKey linkId1 = new LinkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2)); 170 + LinkKey linkId1 = linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
170 - LinkKey linkId2 = new LinkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1)); 171 + LinkKey linkId2 = linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
171 - LinkKey linkId3 = new LinkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3)); 172 + LinkKey linkId3 = linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
172 173
173 putLink(linkId1, DIRECT); 174 putLink(linkId1, DIRECT);
174 putLink(linkId2, DIRECT); 175 putLink(linkId2, DIRECT);
...@@ -191,7 +192,7 @@ public class DistributedLinkStoreTest { ...@@ -191,7 +192,7 @@ public class DistributedLinkStoreTest {
191 public final void testGetLink() { 192 public final void testGetLink() {
192 ConnectPoint src = new ConnectPoint(DID1, P1); 193 ConnectPoint src = new ConnectPoint(DID1, P1);
193 ConnectPoint dst = new ConnectPoint(DID2, P2); 194 ConnectPoint dst = new ConnectPoint(DID2, P2);
194 - LinkKey linkId1 = new LinkKey(src, dst); 195 + LinkKey linkId1 = linkKey(src, dst);
195 196
196 putLink(linkId1, DIRECT); 197 putLink(linkId1, DIRECT);
197 198
...@@ -206,9 +207,9 @@ public class DistributedLinkStoreTest { ...@@ -206,9 +207,9 @@ public class DistributedLinkStoreTest {
206 public final void testGetEgressLinks() { 207 public final void testGetEgressLinks() {
207 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1); 208 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
208 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2); 209 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
209 - LinkKey linkId1 = new LinkKey(d1P1, d2P2); 210 + LinkKey linkId1 = linkKey(d1P1, d2P2);
210 - LinkKey linkId2 = new LinkKey(d2P2, d1P1); 211 + LinkKey linkId2 = linkKey(d2P2, d1P1);
211 - LinkKey linkId3 = new LinkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3)); 212 + LinkKey linkId3 = linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
212 213
213 putLink(linkId1, DIRECT); 214 putLink(linkId1, DIRECT);
214 putLink(linkId2, DIRECT); 215 putLink(linkId2, DIRECT);
...@@ -231,9 +232,9 @@ public class DistributedLinkStoreTest { ...@@ -231,9 +232,9 @@ public class DistributedLinkStoreTest {
231 public final void testGetIngressLinks() { 232 public final void testGetIngressLinks() {
232 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1); 233 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
233 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2); 234 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
234 - LinkKey linkId1 = new LinkKey(d1P1, d2P2); 235 + LinkKey linkId1 = linkKey(d1P1, d2P2);
235 - LinkKey linkId2 = new LinkKey(d2P2, d1P1); 236 + LinkKey linkId2 = linkKey(d2P2, d1P1);
236 - LinkKey linkId3 = new LinkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3)); 237 + LinkKey linkId3 = linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
237 238
238 putLink(linkId1, DIRECT); 239 putLink(linkId1, DIRECT);
239 putLink(linkId2, DIRECT); 240 putLink(linkId2, DIRECT);
...@@ -282,8 +283,8 @@ public class DistributedLinkStoreTest { ...@@ -282,8 +283,8 @@ public class DistributedLinkStoreTest {
282 public final void testRemoveLink() { 283 public final void testRemoveLink() {
283 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1); 284 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
284 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2); 285 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
285 - LinkKey linkId1 = new LinkKey(d1P1, d2P2); 286 + LinkKey linkId1 = linkKey(d1P1, d2P2);
286 - LinkKey linkId2 = new LinkKey(d2P2, d1P1); 287 + LinkKey linkId2 = linkKey(d2P2, d1P1);
287 288
288 putLink(linkId1, DIRECT); 289 putLink(linkId1, DIRECT);
289 putLink(linkId2, DIRECT); 290 putLink(linkId2, DIRECT);
...@@ -306,7 +307,7 @@ public class DistributedLinkStoreTest { ...@@ -306,7 +307,7 @@ public class DistributedLinkStoreTest {
306 307
307 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1); 308 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
308 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2); 309 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
309 - final LinkKey linkId1 = new LinkKey(d1P1, d2P2); 310 + final LinkKey linkId1 = linkKey(d1P1, d2P2);
310 311
311 final CountDownLatch addLatch = new CountDownLatch(1); 312 final CountDownLatch addLatch = new CountDownLatch(1);
312 LinkStoreDelegate checkAdd = new LinkStoreDelegate() { 313 LinkStoreDelegate checkAdd = new LinkStoreDelegate() {
......
...@@ -31,6 +31,6 @@ public class LinkKeySerializer extends Serializer<LinkKey> { ...@@ -31,6 +31,6 @@ public class LinkKeySerializer extends Serializer<LinkKey> {
31 public LinkKey read(Kryo kryo, Input input, Class<LinkKey> type) { 31 public LinkKey read(Kryo kryo, Input input, Class<LinkKey> type) {
32 ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input); 32 ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input);
33 ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input); 33 ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input);
34 - return new LinkKey(src, dst); 34 + return LinkKey.linkKey(src, dst);
35 } 35 }
36 } 36 }
......
...@@ -108,7 +108,7 @@ public class KryoSerializerTest { ...@@ -108,7 +108,7 @@ public class KryoSerializerTest {
108 testSerialized(ImmutableSet.of()); 108 testSerialized(ImmutableSet.of());
109 testSerialized(IpPrefix.valueOf("192.168.0.1/24")); 109 testSerialized(IpPrefix.valueOf("192.168.0.1/24"));
110 testSerialized(IpAddress.valueOf("192.168.0.1")); 110 testSerialized(IpAddress.valueOf("192.168.0.1"));
111 - testSerialized(new LinkKey(CP1, CP2)); 111 + testSerialized(LinkKey.linkKey(CP1, CP2));
112 testSerialized(new NodeId("SomeNodeIdentifier")); 112 testSerialized(new NodeId("SomeNodeIdentifier"));
113 testSerialized(P1); 113 testSerialized(P1);
114 testSerialized(PID); 114 testSerialized(PID);
......
...@@ -42,6 +42,7 @@ import static org.onlab.onos.net.DefaultAnnotations.union; ...@@ -42,6 +42,7 @@ import static org.onlab.onos.net.DefaultAnnotations.union;
42 import static org.onlab.onos.net.DefaultAnnotations.merge; 42 import static org.onlab.onos.net.DefaultAnnotations.merge;
43 import static org.onlab.onos.net.Link.Type.DIRECT; 43 import static org.onlab.onos.net.Link.Type.DIRECT;
44 import static org.onlab.onos.net.Link.Type.INDIRECT; 44 import static org.onlab.onos.net.Link.Type.INDIRECT;
45 +import static org.onlab.onos.net.LinkKey.linkKey;
45 import static org.onlab.onos.net.link.LinkEvent.Type.*; 46 import static org.onlab.onos.net.link.LinkEvent.Type.*;
46 import static org.slf4j.LoggerFactory.getLogger; 47 import static org.slf4j.LoggerFactory.getLogger;
47 import static com.google.common.collect.Multimaps.synchronizedSetMultimap; 48 import static com.google.common.collect.Multimaps.synchronizedSetMultimap;
...@@ -120,7 +121,7 @@ public class SimpleLinkStore ...@@ -120,7 +121,7 @@ public class SimpleLinkStore
120 121
121 @Override 122 @Override
122 public Link getLink(ConnectPoint src, ConnectPoint dst) { 123 public Link getLink(ConnectPoint src, ConnectPoint dst) {
123 - return links.get(new LinkKey(src, dst)); 124 + return links.get(linkKey(src, dst));
124 } 125 }
125 126
126 @Override 127 @Override
...@@ -148,7 +149,7 @@ public class SimpleLinkStore ...@@ -148,7 +149,7 @@ public class SimpleLinkStore
148 @Override 149 @Override
149 public LinkEvent createOrUpdateLink(ProviderId providerId, 150 public LinkEvent createOrUpdateLink(ProviderId providerId,
150 LinkDescription linkDescription) { 151 LinkDescription linkDescription) {
151 - LinkKey key = new LinkKey(linkDescription.src(), linkDescription.dst()); 152 + LinkKey key = linkKey(linkDescription);
152 153
153 ConcurrentMap<ProviderId, LinkDescription> descs = getLinkDescriptions(key); 154 ConcurrentMap<ProviderId, LinkDescription> descs = getLinkDescriptions(key);
154 synchronized (descs) { 155 synchronized (descs) {
...@@ -225,7 +226,7 @@ public class SimpleLinkStore ...@@ -225,7 +226,7 @@ public class SimpleLinkStore
225 226
226 @Override 227 @Override
227 public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { 228 public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) {
228 - final LinkKey key = new LinkKey(src, dst); 229 + final LinkKey key = linkKey(src, dst);
229 ConcurrentMap<ProviderId, LinkDescription> descs = getLinkDescriptions(key); 230 ConcurrentMap<ProviderId, LinkDescription> descs = getLinkDescriptions(key);
230 synchronized (descs) { 231 synchronized (descs) {
231 Link link = links.remove(key); 232 Link link = links.remove(key);
......
...@@ -136,8 +136,8 @@ public class SimpleLinkStoreTest { ...@@ -136,8 +136,8 @@ public class SimpleLinkStoreTest {
136 assertEquals("initialy empty", 0, 136 assertEquals("initialy empty", 0,
137 Iterables.size(linkStore.getLinks())); 137 Iterables.size(linkStore.getLinks()));
138 138
139 - LinkKey linkId1 = new LinkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2)); 139 + LinkKey linkId1 = LinkKey.linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
140 - LinkKey linkId2 = new LinkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1)); 140 + LinkKey linkId2 = LinkKey.linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
141 141
142 putLink(linkId1, DIRECT); 142 putLink(linkId1, DIRECT);
143 putLink(linkId2, DIRECT); 143 putLink(linkId2, DIRECT);
...@@ -148,7 +148,7 @@ public class SimpleLinkStoreTest { ...@@ -148,7 +148,7 @@ public class SimpleLinkStoreTest {
148 148
149 Map<LinkKey, Link> links = new HashMap<>(); 149 Map<LinkKey, Link> links = new HashMap<>();
150 for (Link link : linkStore.getLinks()) { 150 for (Link link : linkStore.getLinks()) {
151 - links.put(new LinkKey(link.src(), link.dst()), link); 151 + links.put(LinkKey.linkKey(link), link);
152 } 152 }
153 153
154 assertLink(linkId1, DIRECT, links.get(linkId1)); 154 assertLink(linkId1, DIRECT, links.get(linkId1));
...@@ -157,9 +157,9 @@ public class SimpleLinkStoreTest { ...@@ -157,9 +157,9 @@ public class SimpleLinkStoreTest {
157 157
158 @Test 158 @Test
159 public final void testGetDeviceEgressLinks() { 159 public final void testGetDeviceEgressLinks() {
160 - LinkKey linkId1 = new LinkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2)); 160 + LinkKey linkId1 = LinkKey.linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
161 - LinkKey linkId2 = new LinkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1)); 161 + LinkKey linkId2 = LinkKey.linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
162 - LinkKey linkId3 = new LinkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3)); 162 + LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
163 163
164 putLink(linkId1, DIRECT); 164 putLink(linkId1, DIRECT);
165 putLink(linkId2, DIRECT); 165 putLink(linkId2, DIRECT);
...@@ -180,9 +180,9 @@ public class SimpleLinkStoreTest { ...@@ -180,9 +180,9 @@ public class SimpleLinkStoreTest {
180 180
181 @Test 181 @Test
182 public final void testGetDeviceIngressLinks() { 182 public final void testGetDeviceIngressLinks() {
183 - LinkKey linkId1 = new LinkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2)); 183 + LinkKey linkId1 = LinkKey.linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
184 - LinkKey linkId2 = new LinkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1)); 184 + LinkKey linkId2 = LinkKey.linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
185 - LinkKey linkId3 = new LinkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3)); 185 + LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
186 186
187 putLink(linkId1, DIRECT); 187 putLink(linkId1, DIRECT);
188 putLink(linkId2, DIRECT); 188 putLink(linkId2, DIRECT);
...@@ -205,7 +205,7 @@ public class SimpleLinkStoreTest { ...@@ -205,7 +205,7 @@ public class SimpleLinkStoreTest {
205 public final void testGetLink() { 205 public final void testGetLink() {
206 ConnectPoint src = new ConnectPoint(DID1, P1); 206 ConnectPoint src = new ConnectPoint(DID1, P1);
207 ConnectPoint dst = new ConnectPoint(DID2, P2); 207 ConnectPoint dst = new ConnectPoint(DID2, P2);
208 - LinkKey linkId1 = new LinkKey(src, dst); 208 + LinkKey linkId1 = LinkKey.linkKey(src, dst);
209 209
210 putLink(linkId1, DIRECT); 210 putLink(linkId1, DIRECT);
211 211
...@@ -220,9 +220,9 @@ public class SimpleLinkStoreTest { ...@@ -220,9 +220,9 @@ public class SimpleLinkStoreTest {
220 public final void testGetEgressLinks() { 220 public final void testGetEgressLinks() {
221 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1); 221 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
222 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2); 222 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
223 - LinkKey linkId1 = new LinkKey(d1P1, d2P2); 223 + LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
224 - LinkKey linkId2 = new LinkKey(d2P2, d1P1); 224 + LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1);
225 - LinkKey linkId3 = new LinkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3)); 225 + LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
226 226
227 putLink(linkId1, DIRECT); 227 putLink(linkId1, DIRECT);
228 putLink(linkId2, DIRECT); 228 putLink(linkId2, DIRECT);
...@@ -245,9 +245,9 @@ public class SimpleLinkStoreTest { ...@@ -245,9 +245,9 @@ public class SimpleLinkStoreTest {
245 public final void testGetIngressLinks() { 245 public final void testGetIngressLinks() {
246 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1); 246 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
247 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2); 247 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
248 - LinkKey linkId1 = new LinkKey(d1P1, d2P2); 248 + LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
249 - LinkKey linkId2 = new LinkKey(d2P2, d1P1); 249 + LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1);
250 - LinkKey linkId3 = new LinkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3)); 250 + LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
251 251
252 putLink(linkId1, DIRECT); 252 putLink(linkId1, DIRECT);
253 putLink(linkId2, DIRECT); 253 putLink(linkId2, DIRECT);
...@@ -349,8 +349,8 @@ public class SimpleLinkStoreTest { ...@@ -349,8 +349,8 @@ public class SimpleLinkStoreTest {
349 public final void testRemoveLink() { 349 public final void testRemoveLink() {
350 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1); 350 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
351 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2); 351 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
352 - LinkKey linkId1 = new LinkKey(d1P1, d2P2); 352 + LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
353 - LinkKey linkId2 = new LinkKey(d2P2, d1P1); 353 + LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1);
354 354
355 putLink(linkId1, DIRECT, A1); 355 putLink(linkId1, DIRECT, A1);
356 putLink(linkId2, DIRECT, A2); 356 putLink(linkId2, DIRECT, A2);
...@@ -406,7 +406,7 @@ public class SimpleLinkStoreTest { ...@@ -406,7 +406,7 @@ public class SimpleLinkStoreTest {
406 406
407 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1); 407 final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
408 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2); 408 final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
409 - final LinkKey linkId1 = new LinkKey(d1P1, d2P2); 409 + final LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
410 410
411 final CountDownLatch addLatch = new CountDownLatch(1); 411 final CountDownLatch addLatch = new CountDownLatch(1);
412 LinkStoreDelegate checkAdd = new LinkStoreDelegate() { 412 LinkStoreDelegate checkAdd = new LinkStoreDelegate() {
......