Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
16 changed files
with
885 additions
and
66 deletions
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 | } | ... | ... |
1 | +package org.onlab.onos.net.host; | ||
2 | + | ||
3 | +import org.onlab.onos.store.Timestamp; | ||
4 | +import org.onlab.packet.MacAddress; | ||
5 | + | ||
6 | +/** | ||
7 | + * Interface for a logical clock service that issues per host timestamps. | ||
8 | + */ | ||
9 | +public interface HostClockService { | ||
10 | + | ||
11 | + /** | ||
12 | + * Returns a new timestamp for the specified host mac address. | ||
13 | + * @param hostMac host MAC address. | ||
14 | + * @return timestamp. | ||
15 | + */ | ||
16 | + public Timestamp getTimestamp(MacAddress hostMac); | ||
17 | +} |
... | @@ -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; | ... | ... |
... | @@ -1090,7 +1090,7 @@ public class GossipDeviceStore | ... | @@ -1090,7 +1090,7 @@ public class GossipDeviceStore |
1090 | .toList(); | 1090 | .toList(); |
1091 | 1091 | ||
1092 | if (nodeIds.size() == 1 && nodeIds.get(0).equals(self)) { | 1092 | if (nodeIds.size() == 1 && nodeIds.get(0).equals(self)) { |
1093 | - log.info("No other peers in the cluster."); | 1093 | + log.debug("No other peers in the cluster."); |
1094 | return; | 1094 | return; |
1095 | } | 1095 | } |
1096 | 1096 | ... | ... |
1 | +package org.onlab.onos.store.host.impl; | ||
2 | + | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
5 | +import org.apache.felix.scr.annotations.Activate; | ||
6 | +import org.apache.felix.scr.annotations.Component; | ||
7 | +import org.apache.felix.scr.annotations.Deactivate; | ||
8 | +import org.apache.felix.scr.annotations.Service; | ||
9 | +import org.onlab.onos.net.host.HostClockService; | ||
10 | +import org.onlab.onos.store.Timestamp; | ||
11 | +import org.onlab.onos.store.impl.WallClockTimestamp; | ||
12 | +import org.onlab.packet.MacAddress; | ||
13 | +import org.slf4j.Logger; | ||
14 | + | ||
15 | +/** | ||
16 | + * HostClockService to issue Timestamps based on local wallclock time. | ||
17 | + */ | ||
18 | +@Component(immediate = true) | ||
19 | +@Service | ||
20 | +public class HostClockManager implements HostClockService { | ||
21 | + | ||
22 | + private final Logger log = getLogger(getClass()); | ||
23 | + | ||
24 | + @Activate | ||
25 | + public void activate() { | ||
26 | + log.info("Started"); | ||
27 | + } | ||
28 | + | ||
29 | + @Deactivate | ||
30 | + public void deactivate() { | ||
31 | + log.info("Stopped"); | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + public Timestamp getTimestamp(MacAddress hostMac) { | ||
36 | + return new WallClockTimestamp(); | ||
37 | + } | ||
38 | +} |
... | @@ -10,8 +10,12 @@ import com.google.common.base.MoreObjects; | ... | @@ -10,8 +10,12 @@ import com.google.common.base.MoreObjects; |
10 | import com.google.common.collect.ComparisonChain; | 10 | import com.google.common.collect.ComparisonChain; |
11 | 11 | ||
12 | /** | 12 | /** |
13 | - * Default implementation of Timestamp. | 13 | + * A logical timestamp that derives its value from two things: |
14 | - * TODO: Better documentation. | 14 | + * <ul> |
15 | + * <li> The current mastership term of the device.</li> | ||
16 | + * <li> The value of the counter used for tracking topology events observed from | ||
17 | + * the device during that current time of a device. </li> | ||
18 | + * </ul> | ||
15 | */ | 19 | */ |
16 | public final class MastershipBasedTimestamp implements Timestamp { | 20 | public final class MastershipBasedTimestamp implements Timestamp { |
17 | 21 | ... | ... |
1 | +package org.onlab.onos.store.impl; | ||
2 | + | ||
3 | +import static com.google.common.base.Preconditions.checkArgument; | ||
4 | + | ||
5 | +import java.util.Objects; | ||
6 | + | ||
7 | +import org.onlab.onos.store.Timestamp; | ||
8 | + | ||
9 | +import com.google.common.base.MoreObjects; | ||
10 | +import com.google.common.collect.ComparisonChain; | ||
11 | + | ||
12 | +/** | ||
13 | + * A Timestamp that derives its value from the prevailing | ||
14 | + * wallclock time on the controller where it is generated. | ||
15 | + */ | ||
16 | +public class WallClockTimestamp implements Timestamp { | ||
17 | + | ||
18 | + private final long unixTimestamp; | ||
19 | + | ||
20 | + public WallClockTimestamp() { | ||
21 | + unixTimestamp = System.currentTimeMillis(); | ||
22 | + } | ||
23 | + | ||
24 | + @Override | ||
25 | + public int compareTo(Timestamp o) { | ||
26 | + checkArgument(o instanceof WallClockTimestamp, | ||
27 | + "Must be WallClockTimestamp", o); | ||
28 | + WallClockTimestamp that = (WallClockTimestamp) o; | ||
29 | + | ||
30 | + return ComparisonChain.start() | ||
31 | + .compare(this.unixTimestamp, that.unixTimestamp) | ||
32 | + .result(); | ||
33 | + } | ||
34 | + @Override | ||
35 | + public int hashCode() { | ||
36 | + return Objects.hash(unixTimestamp); | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + public boolean equals(Object obj) { | ||
41 | + if (this == obj) { | ||
42 | + return true; | ||
43 | + } | ||
44 | + if (!(obj instanceof WallClockTimestamp)) { | ||
45 | + return false; | ||
46 | + } | ||
47 | + WallClockTimestamp that = (WallClockTimestamp) obj; | ||
48 | + return Objects.equals(this.unixTimestamp, that.unixTimestamp); | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public String toString() { | ||
53 | + return MoreObjects.toStringHelper(getClass()) | ||
54 | + .add("unixTimestamp", unixTimestamp) | ||
55 | + .toString(); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Returns the unixTimestamp. | ||
60 | + * | ||
61 | + * @return unix timestamp | ||
62 | + */ | ||
63 | + public long unixTimestamp() { | ||
64 | + return unixTimestamp; | ||
65 | + } | ||
66 | +} |
... | @@ -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,14 +238,20 @@ public class GossipLinkStore | ... | @@ -237,14 +238,20 @@ 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 | - LinkEvent event = createOrUpdateLinkInternal(providerId, deltaDesc); | 241 | + LinkKey key = linkKey(linkDescription); |
242 | + final LinkEvent event; | ||
243 | + final Timestamped<LinkDescription> mergedDesc; | ||
244 | + synchronized (getLinkDescriptions(key)) { | ||
245 | + event = createOrUpdateLinkInternal(providerId, deltaDesc); | ||
246 | + mergedDesc = getLinkDescriptions(key).get(providerId); | ||
247 | + } | ||
241 | 248 | ||
242 | if (event != null) { | 249 | if (event != null) { |
243 | log.info("Notifying peers of a link update topology event from providerId: " | 250 | log.info("Notifying peers of a link update topology event from providerId: " |
244 | + "{} between src: {} and dst: {}", | 251 | + "{} between src: {} and dst: {}", |
245 | providerId, linkDescription.src(), linkDescription.dst()); | 252 | providerId, linkDescription.src(), linkDescription.dst()); |
246 | try { | 253 | try { |
247 | - notifyPeers(new InternalLinkEvent(providerId, deltaDesc)); | 254 | + notifyPeers(new InternalLinkEvent(providerId, mergedDesc)); |
248 | } catch (IOException e) { | 255 | } catch (IOException e) { |
249 | log.info("Failed to notify peers of a link update topology event from providerId: " | 256 | log.info("Failed to notify peers of a link update topology event from providerId: " |
250 | + "{} between src: {} and dst: {}", | 257 | + "{} between src: {} and dst: {}", |
... | @@ -258,7 +265,7 @@ public class GossipLinkStore | ... | @@ -258,7 +265,7 @@ public class GossipLinkStore |
258 | ProviderId providerId, | 265 | ProviderId providerId, |
259 | Timestamped<LinkDescription> linkDescription) { | 266 | Timestamped<LinkDescription> linkDescription) { |
260 | 267 | ||
261 | - LinkKey key = new LinkKey(linkDescription.value().src(), linkDescription.value().dst()); | 268 | + LinkKey key = linkKey(linkDescription.value()); |
262 | ConcurrentMap<ProviderId, Timestamped<LinkDescription>> descs = getLinkDescriptions(key); | 269 | ConcurrentMap<ProviderId, Timestamped<LinkDescription>> descs = getLinkDescriptions(key); |
263 | 270 | ||
264 | synchronized (descs) { | 271 | synchronized (descs) { |
... | @@ -351,7 +358,7 @@ public class GossipLinkStore | ... | @@ -351,7 +358,7 @@ public class GossipLinkStore |
351 | 358 | ||
352 | @Override | 359 | @Override |
353 | public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { | 360 | public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { |
354 | - final LinkKey key = new LinkKey(src, dst); | 361 | + final LinkKey key = linkKey(src, dst); |
355 | 362 | ||
356 | DeviceId dstDeviceId = dst.deviceId(); | 363 | DeviceId dstDeviceId = dst.deviceId(); |
357 | Timestamp timestamp = deviceClockService.getTimestamp(dstDeviceId); | 364 | Timestamp timestamp = deviceClockService.getTimestamp(dstDeviceId); |
... | @@ -538,7 +545,7 @@ public class GossipLinkStore | ... | @@ -538,7 +545,7 @@ public class GossipLinkStore |
538 | .toList(); | 545 | .toList(); |
539 | 546 | ||
540 | if (nodeIds.size() == 1 && nodeIds.get(0).equals(self)) { | 547 | if (nodeIds.size() == 1 && nodeIds.get(0).equals(self)) { |
541 | - log.info("No other peers in the cluster."); | 548 | + log.debug("No other peers in the cluster."); |
542 | return; | 549 | return; |
543 | } | 550 | } |
544 | 551 | ... | ... |
1 | +package org.onlab.onos.store.impl; | ||
2 | + | ||
3 | +import static org.junit.Assert.assertTrue; | ||
4 | + | ||
5 | +import java.nio.ByteBuffer; | ||
6 | + | ||
7 | +import org.junit.Test; | ||
8 | +import org.onlab.onos.store.Timestamp; | ||
9 | +import org.onlab.util.KryoPool; | ||
10 | + | ||
11 | +import com.google.common.testing.EqualsTester; | ||
12 | + | ||
13 | +/** | ||
14 | + * Tests for {@link WallClockTimestamp}. | ||
15 | + */ | ||
16 | +public class WallClockTimestampTest { | ||
17 | + | ||
18 | + @Test | ||
19 | + public final void testBasic() throws InterruptedException { | ||
20 | + WallClockTimestamp ts1 = new WallClockTimestamp(); | ||
21 | + Thread.sleep(50); | ||
22 | + WallClockTimestamp ts2 = new WallClockTimestamp(); | ||
23 | + | ||
24 | + assertTrue(ts1.compareTo(ts1) == 0); | ||
25 | + assertTrue(ts2.compareTo(ts1) > 0); | ||
26 | + assertTrue(ts1.compareTo(ts2) < 0); | ||
27 | + } | ||
28 | + | ||
29 | + @Test | ||
30 | + public final void testKryoSerializable() { | ||
31 | + WallClockTimestamp ts1 = new WallClockTimestamp(); | ||
32 | + final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); | ||
33 | + final KryoPool kryos = KryoPool.newBuilder() | ||
34 | + .register(WallClockTimestamp.class) | ||
35 | + .build(); | ||
36 | + | ||
37 | + kryos.serialize(ts1, buffer); | ||
38 | + buffer.flip(); | ||
39 | + Timestamp copy = kryos.deserialize(buffer); | ||
40 | + | ||
41 | + new EqualsTester() | ||
42 | + .addEqualityGroup(ts1, copy) | ||
43 | + .testEquals(); | ||
44 | + } | ||
45 | +} |
1 | +package org.onlab.onos.store.common; | ||
2 | + | ||
3 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
4 | + | ||
5 | +import java.util.ArrayList; | ||
6 | +import java.util.Collection; | ||
7 | +import java.util.Collections; | ||
8 | +import java.util.HashMap; | ||
9 | +import java.util.HashSet; | ||
10 | +import java.util.IdentityHashMap; | ||
11 | +import java.util.Map; | ||
12 | +import java.util.Set; | ||
13 | +import java.util.concurrent.Future; | ||
14 | +import java.util.concurrent.TimeUnit; | ||
15 | + | ||
16 | +import org.apache.commons.lang3.tuple.Pair; | ||
17 | +import org.onlab.onos.store.serializers.StoreSerializer; | ||
18 | + | ||
19 | +import com.google.common.base.Function; | ||
20 | +import com.google.common.util.concurrent.Futures; | ||
21 | +import com.hazelcast.core.EntryEvent; | ||
22 | +import com.hazelcast.core.EntryListener; | ||
23 | +import com.hazelcast.core.EntryView; | ||
24 | +import com.hazelcast.core.ExecutionCallback; | ||
25 | +import com.hazelcast.core.IMap; | ||
26 | +import com.hazelcast.core.MapEvent; | ||
27 | +import com.hazelcast.map.EntryProcessor; | ||
28 | +import com.hazelcast.map.MapInterceptor; | ||
29 | +import com.hazelcast.mapreduce.JobTracker; | ||
30 | +import com.hazelcast.mapreduce.aggregation.Aggregation; | ||
31 | +import com.hazelcast.mapreduce.aggregation.Supplier; | ||
32 | +import com.hazelcast.monitor.LocalMapStats; | ||
33 | +import com.hazelcast.query.Predicate; | ||
34 | + | ||
35 | +// TODO: implement Predicate, etc. if we need them. | ||
36 | +/** | ||
37 | + * Wrapper around IMap<byte[], byte[]> which serializes/deserializes | ||
38 | + * Key and Value using StoreSerializer. | ||
39 | + * | ||
40 | + * @param <K> key type | ||
41 | + * @param <V> value type | ||
42 | + */ | ||
43 | +public class SMap<K, V> implements IMap<K, V> { | ||
44 | + | ||
45 | + private final IMap<byte[], byte[]> m; | ||
46 | + private final StoreSerializer serializer; | ||
47 | + | ||
48 | + /** | ||
49 | + * Creates a SMap instance. | ||
50 | + * | ||
51 | + * @param baseMap base IMap to use | ||
52 | + * @param serializer serializer to use for both key and value | ||
53 | + */ | ||
54 | + public SMap(IMap<byte[], byte[]> baseMap, StoreSerializer serializer) { | ||
55 | + this.m = checkNotNull(baseMap); | ||
56 | + this.serializer = checkNotNull(serializer); | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public int size() { | ||
61 | + return m.size(); | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public boolean isEmpty() { | ||
66 | + return m.isEmpty(); | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public void putAll(Map<? extends K, ? extends V> map) { | ||
71 | + Map<byte[], byte[]> sm = new IdentityHashMap<>(map.size()); | ||
72 | + for (java.util.Map.Entry<? extends K, ? extends V> e : map.entrySet()) { | ||
73 | + sm.put(serializeKey(e.getKey()), serializeVal(e.getValue())); | ||
74 | + } | ||
75 | + m.putAll(sm); | ||
76 | + } | ||
77 | + | ||
78 | + @Deprecated | ||
79 | + @Override | ||
80 | + public Object getId() { | ||
81 | + return m.getId(); | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public String getPartitionKey() { | ||
86 | + return m.getPartitionKey(); | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public String getName() { | ||
91 | + return m.getName(); | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public String getServiceName() { | ||
96 | + return m.getServiceName(); | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public void destroy() { | ||
101 | + m.destroy(); | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public boolean containsKey(Object key) { | ||
106 | + return m.containsKey(serializeKey(key)); | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public boolean containsValue(Object value) { | ||
111 | + return m.containsValue(serializeVal(value)); | ||
112 | + } | ||
113 | + | ||
114 | + @Override | ||
115 | + public V get(Object key) { | ||
116 | + return deserializeVal(m.get(serializeKey(key))); | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
120 | + public V put(K key, V value) { | ||
121 | + return deserializeVal(m.put(serializeKey(key), serializeVal(value))); | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public V remove(Object key) { | ||
126 | + return deserializeVal(m.remove(serializeKey(key))); | ||
127 | + } | ||
128 | + | ||
129 | + @Override | ||
130 | + public boolean remove(Object key, Object value) { | ||
131 | + return m.remove(serializeKey(key), serializeVal(value)); | ||
132 | + } | ||
133 | + | ||
134 | + @Override | ||
135 | + public void delete(Object key) { | ||
136 | + m.delete(serializeKey(key)); | ||
137 | + } | ||
138 | + | ||
139 | + @Override | ||
140 | + public void flush() { | ||
141 | + m.flush(); | ||
142 | + } | ||
143 | + | ||
144 | + @Override | ||
145 | + public Map<K, V> getAll(Set<K> keys) { | ||
146 | + Set<byte[]> sk = serializeKeySet(keys); | ||
147 | + Map<byte[], byte[]> bm = m.getAll(sk); | ||
148 | + Map<K, V> dsm = new HashMap<>(bm.size()); | ||
149 | + for (java.util.Map.Entry<byte[], byte[]> e : bm.entrySet()) { | ||
150 | + dsm.put(deserializeKey(e.getKey()), deserializeVal(e.getValue())); | ||
151 | + } | ||
152 | + return dsm; | ||
153 | + } | ||
154 | + | ||
155 | + @Override | ||
156 | + public void loadAll(boolean replaceExistingValues) { | ||
157 | + m.loadAll(replaceExistingValues); | ||
158 | + } | ||
159 | + | ||
160 | + @Override | ||
161 | + public void loadAll(Set<K> keys, boolean replaceExistingValues) { | ||
162 | + Set<byte[]> sk = serializeKeySet(keys); | ||
163 | + m.loadAll(sk, replaceExistingValues); | ||
164 | + } | ||
165 | + | ||
166 | + @Override | ||
167 | + public void clear() { | ||
168 | + m.clear(); | ||
169 | + } | ||
170 | + | ||
171 | + @Override | ||
172 | + public Future<V> getAsync(K key) { | ||
173 | + Future<byte[]> f = m.getAsync(serializeKey(key)); | ||
174 | + return Futures.lazyTransform(f, new DeserializeVal()); | ||
175 | + } | ||
176 | + | ||
177 | + @Override | ||
178 | + public Future<V> putAsync(K key, V value) { | ||
179 | + Future<byte[]> f = m.putAsync(serializeKey(key), serializeVal(value)); | ||
180 | + return Futures.lazyTransform(f, new DeserializeVal()); | ||
181 | + } | ||
182 | + | ||
183 | + @Override | ||
184 | + public Future<V> putAsync(K key, V value, long ttl, TimeUnit timeunit) { | ||
185 | + Future<byte[]> f = m.putAsync(serializeKey(key), serializeVal(value), ttl, timeunit); | ||
186 | + return Futures.lazyTransform(f, new DeserializeVal()); | ||
187 | + } | ||
188 | + | ||
189 | + @Override | ||
190 | + public Future<V> removeAsync(K key) { | ||
191 | + Future<byte[]> f = m.removeAsync(serializeKey(key)); | ||
192 | + return Futures.lazyTransform(f, new DeserializeVal()); | ||
193 | + } | ||
194 | + | ||
195 | + @Override | ||
196 | + public boolean tryRemove(K key, long timeout, TimeUnit timeunit) { | ||
197 | + return m.tryRemove(serializeKey(key), timeout, timeunit); | ||
198 | + } | ||
199 | + | ||
200 | + @Override | ||
201 | + public boolean tryPut(K key, V value, long timeout, TimeUnit timeunit) { | ||
202 | + return m.tryPut(serializeKey(key), serializeVal(value), timeout, timeunit); | ||
203 | + } | ||
204 | + | ||
205 | + @Override | ||
206 | + public V put(K key, V value, long ttl, TimeUnit timeunit) { | ||
207 | + return deserializeVal(m.put(serializeKey(key), serializeVal(value), ttl, timeunit)); | ||
208 | + } | ||
209 | + | ||
210 | + @Override | ||
211 | + public void putTransient(K key, V value, long ttl, TimeUnit timeunit) { | ||
212 | + m.putTransient(serializeKey(key), serializeVal(value), ttl, timeunit); | ||
213 | + } | ||
214 | + | ||
215 | + @Override | ||
216 | + public V putIfAbsent(K key, V value) { | ||
217 | + return deserializeVal(m.putIfAbsent(serializeKey(key), serializeVal(value))); | ||
218 | + } | ||
219 | + | ||
220 | + @Override | ||
221 | + public V putIfAbsent(K key, V value, long ttl, TimeUnit timeunit) { | ||
222 | + return deserializeVal(m.putIfAbsent(serializeKey(key), serializeVal(value), ttl, timeunit)); | ||
223 | + } | ||
224 | + | ||
225 | + @Override | ||
226 | + public boolean replace(K key, V oldValue, V newValue) { | ||
227 | + return m.replace(serializeKey(key), serializeVal(oldValue), serializeVal(newValue)); | ||
228 | + } | ||
229 | + | ||
230 | + @Override | ||
231 | + public V replace(K key, V value) { | ||
232 | + return deserializeVal(m.replace(serializeKey(key), serializeVal(value))); | ||
233 | + } | ||
234 | + | ||
235 | + @Override | ||
236 | + public void set(K key, V value) { | ||
237 | + m.set(serializeKey(key), serializeVal(value)); | ||
238 | + } | ||
239 | + | ||
240 | + @Override | ||
241 | + public void set(K key, V value, long ttl, TimeUnit timeunit) { | ||
242 | + m.set(serializeKey(key), serializeVal(value), ttl, timeunit); | ||
243 | + } | ||
244 | + | ||
245 | + @Override | ||
246 | + public void lock(K key) { | ||
247 | + m.lock(serializeKey(key)); | ||
248 | + } | ||
249 | + | ||
250 | + @Override | ||
251 | + public void lock(K key, long leaseTime, TimeUnit timeUnit) { | ||
252 | + m.lock(serializeKey(key), leaseTime, timeUnit); | ||
253 | + } | ||
254 | + | ||
255 | + @Override | ||
256 | + public boolean isLocked(K key) { | ||
257 | + return m.isLocked(serializeKey(key)); | ||
258 | + } | ||
259 | + | ||
260 | + @Override | ||
261 | + public boolean tryLock(K key) { | ||
262 | + return m.tryLock(serializeKey(key)); | ||
263 | + } | ||
264 | + | ||
265 | + @Override | ||
266 | + public boolean tryLock(K key, long time, TimeUnit timeunit) | ||
267 | + throws InterruptedException { | ||
268 | + return m.tryLock(serializeKey(key), time, timeunit); | ||
269 | + } | ||
270 | + | ||
271 | + @Override | ||
272 | + public void unlock(K key) { | ||
273 | + m.unlock(serializeKey(key)); | ||
274 | + } | ||
275 | + | ||
276 | + @Override | ||
277 | + public void forceUnlock(K key) { | ||
278 | + m.forceUnlock(serializeKey(key)); | ||
279 | + } | ||
280 | + | ||
281 | + @Override | ||
282 | + public String addLocalEntryListener(EntryListener<K, V> listener) { | ||
283 | + return m.addLocalEntryListener(new BaseEntryListener(listener)); | ||
284 | + } | ||
285 | + | ||
286 | + @Deprecated // marking method not implemented | ||
287 | + @Override | ||
288 | + public String addLocalEntryListener(EntryListener<K, V> listener, | ||
289 | + Predicate<K, V> predicate, boolean includeValue) { | ||
290 | + throw new UnsupportedOperationException(); | ||
291 | + } | ||
292 | + | ||
293 | + @Deprecated // marking method not implemented | ||
294 | + @Override | ||
295 | + public String addLocalEntryListener(EntryListener<K, V> listener, | ||
296 | + Predicate<K, V> predicate, K key, boolean includeValue) { | ||
297 | + throw new UnsupportedOperationException(); | ||
298 | + } | ||
299 | + | ||
300 | + @Deprecated // marking method not implemented | ||
301 | + @Override | ||
302 | + public String addInterceptor(MapInterceptor interceptor) { | ||
303 | + throw new UnsupportedOperationException(); | ||
304 | + } | ||
305 | + | ||
306 | + @Override | ||
307 | + public void removeInterceptor(String id) { | ||
308 | + m.removeInterceptor(id); | ||
309 | + } | ||
310 | + | ||
311 | + @Override | ||
312 | + public String addEntryListener(EntryListener<K, V> listener, | ||
313 | + boolean includeValue) { | ||
314 | + return m.addEntryListener(new BaseEntryListener(listener), includeValue); | ||
315 | + } | ||
316 | + | ||
317 | + @Override | ||
318 | + public boolean removeEntryListener(String id) { | ||
319 | + return m.removeEntryListener(id); | ||
320 | + } | ||
321 | + | ||
322 | + @Override | ||
323 | + public String addEntryListener(EntryListener<K, V> listener, K key, | ||
324 | + boolean includeValue) { | ||
325 | + return m.addEntryListener(new BaseEntryListener(listener), | ||
326 | + serializeKey(key), includeValue); | ||
327 | + } | ||
328 | + | ||
329 | + @Deprecated // marking method not implemented | ||
330 | + @Override | ||
331 | + public String addEntryListener(EntryListener<K, V> listener, | ||
332 | + Predicate<K, V> predicate, boolean includeValue) { | ||
333 | + throw new UnsupportedOperationException(); | ||
334 | + } | ||
335 | + | ||
336 | + @Deprecated // marking method not implemented | ||
337 | + @Override | ||
338 | + public String addEntryListener(EntryListener<K, V> listener, | ||
339 | + Predicate<K, V> predicate, K key, boolean includeValue) { | ||
340 | + throw new UnsupportedOperationException(); | ||
341 | + } | ||
342 | + | ||
343 | + @Deprecated // marking method not implemented | ||
344 | + @Override | ||
345 | + public EntryView<K, V> getEntryView(K key) { | ||
346 | + throw new UnsupportedOperationException(); | ||
347 | + } | ||
348 | + | ||
349 | + @Override | ||
350 | + public boolean evict(K key) { | ||
351 | + return m.evict(serializeKey(key)); | ||
352 | + } | ||
353 | + | ||
354 | + @Override | ||
355 | + public void evictAll() { | ||
356 | + m.evictAll(); | ||
357 | + } | ||
358 | + | ||
359 | + @Override | ||
360 | + public Set<K> keySet() { | ||
361 | + return deserializeKeySet(m.keySet()); | ||
362 | + } | ||
363 | + | ||
364 | + @Override | ||
365 | + public Collection<V> values() { | ||
366 | + return deserializeVal(m.values()); | ||
367 | + } | ||
368 | + | ||
369 | + @Override | ||
370 | + public Set<java.util.Map.Entry<K, V>> entrySet() { | ||
371 | + return deserializeEntrySet(m.entrySet()); | ||
372 | + } | ||
373 | + | ||
374 | + @Deprecated // marking method not implemented | ||
375 | + @SuppressWarnings("rawtypes") | ||
376 | + @Override | ||
377 | + public Set<K> keySet(Predicate predicate) { | ||
378 | + throw new UnsupportedOperationException(); | ||
379 | + } | ||
380 | + | ||
381 | + @Deprecated // marking method not implemented | ||
382 | + @SuppressWarnings("rawtypes") | ||
383 | + @Override | ||
384 | + public Set<java.util.Map.Entry<K, V>> entrySet(Predicate predicate) { | ||
385 | + throw new UnsupportedOperationException(); | ||
386 | + } | ||
387 | + | ||
388 | + @Deprecated // marking method not implemented | ||
389 | + @SuppressWarnings("rawtypes") | ||
390 | + @Override | ||
391 | + public Collection<V> values(Predicate predicate) { | ||
392 | + throw new UnsupportedOperationException(); | ||
393 | + } | ||
394 | + | ||
395 | + @Override | ||
396 | + public Set<K> localKeySet() { | ||
397 | + return deserializeKeySet(m.localKeySet()); | ||
398 | + } | ||
399 | + | ||
400 | + @Deprecated // marking method not implemented | ||
401 | + @SuppressWarnings("rawtypes") | ||
402 | + @Override | ||
403 | + public Set<K> localKeySet(Predicate predicate) { | ||
404 | + throw new UnsupportedOperationException(); | ||
405 | + } | ||
406 | + | ||
407 | + @Deprecated // marking method not implemented | ||
408 | + @Override | ||
409 | + public void addIndex(String attribute, boolean ordered) { | ||
410 | + throw new UnsupportedOperationException(); | ||
411 | + } | ||
412 | + | ||
413 | + @Override | ||
414 | + public LocalMapStats getLocalMapStats() { | ||
415 | + return m.getLocalMapStats(); | ||
416 | + } | ||
417 | + | ||
418 | + @Deprecated // marking method not implemented | ||
419 | + @SuppressWarnings("rawtypes") | ||
420 | + @Override | ||
421 | + public Object executeOnKey(K key, EntryProcessor entryProcessor) { | ||
422 | + throw new UnsupportedOperationException(); | ||
423 | + } | ||
424 | + | ||
425 | + @Deprecated // marking method not implemented | ||
426 | + @SuppressWarnings("rawtypes") | ||
427 | + @Override | ||
428 | + public Map<K, Object> executeOnKeys(Set<K> keys, | ||
429 | + EntryProcessor entryProcessor) { | ||
430 | + throw new UnsupportedOperationException(); | ||
431 | + } | ||
432 | + | ||
433 | + @Deprecated // marking method not implemented | ||
434 | + @SuppressWarnings("rawtypes") | ||
435 | + @Override | ||
436 | + public void submitToKey(K key, EntryProcessor entryProcessor, | ||
437 | + ExecutionCallback callback) { | ||
438 | + throw new UnsupportedOperationException(); | ||
439 | + } | ||
440 | + | ||
441 | + @Deprecated // marking method not implemented | ||
442 | + @SuppressWarnings("rawtypes") | ||
443 | + @Override | ||
444 | + public Future submitToKey(K key, EntryProcessor entryProcessor) { | ||
445 | + throw new UnsupportedOperationException(); | ||
446 | + } | ||
447 | + | ||
448 | + @Deprecated // marking method not implemented | ||
449 | + @SuppressWarnings("rawtypes") | ||
450 | + @Override | ||
451 | + public Map<K, Object> executeOnEntries(EntryProcessor entryProcessor) { | ||
452 | + throw new UnsupportedOperationException(); | ||
453 | + } | ||
454 | + | ||
455 | + @Deprecated // marking method not implemented | ||
456 | + @SuppressWarnings("rawtypes") | ||
457 | + @Override | ||
458 | + public Map<K, Object> executeOnEntries(EntryProcessor entryProcessor, | ||
459 | + Predicate predicate) { | ||
460 | + throw new UnsupportedOperationException(); | ||
461 | + } | ||
462 | + | ||
463 | + @Deprecated // marking method not implemented | ||
464 | + @Override | ||
465 | + public <SuppliedValue, Result> Result aggregate( | ||
466 | + Supplier<K, V, SuppliedValue> supplier, | ||
467 | + Aggregation<K, SuppliedValue, Result> aggregation) { | ||
468 | + | ||
469 | + throw new UnsupportedOperationException(); | ||
470 | + } | ||
471 | + | ||
472 | + @Deprecated // marking method not implemented | ||
473 | + @Override | ||
474 | + public <SuppliedValue, Result> Result aggregate( | ||
475 | + Supplier<K, V, SuppliedValue> supplier, | ||
476 | + Aggregation<K, SuppliedValue, Result> aggregation, | ||
477 | + JobTracker jobTracker) { | ||
478 | + | ||
479 | + throw new UnsupportedOperationException(); | ||
480 | + } | ||
481 | + | ||
482 | + private byte[] serializeKey(Object key) { | ||
483 | + return serializer.encode(key); | ||
484 | + } | ||
485 | + | ||
486 | + private K deserializeKey(byte[] key) { | ||
487 | + return serializer.decode(key); | ||
488 | + } | ||
489 | + | ||
490 | + private byte[] serializeVal(Object val) { | ||
491 | + return serializer.encode(val); | ||
492 | + } | ||
493 | + | ||
494 | + private V deserializeVal(byte[] val) { | ||
495 | + return serializer.decode(val); | ||
496 | + } | ||
497 | + | ||
498 | + private Set<byte[]> serializeKeySet(Set<K> keys) { | ||
499 | + Set<byte[]> sk = Collections.newSetFromMap(new IdentityHashMap<byte[], Boolean>(keys.size())); | ||
500 | + for (K key : keys) { | ||
501 | + sk.add(serializeKey(key)); | ||
502 | + } | ||
503 | + return sk; | ||
504 | + } | ||
505 | + | ||
506 | + private Set<K> deserializeKeySet(Set<byte[]> keys) { | ||
507 | + Set<K> dsk = new HashSet<>(keys.size()); | ||
508 | + for (byte[] key : keys) { | ||
509 | + dsk.add(deserializeKey(key)); | ||
510 | + } | ||
511 | + return dsk; | ||
512 | + } | ||
513 | + | ||
514 | + private Collection<V> deserializeVal(Collection<byte[]> vals) { | ||
515 | + Collection<V> dsl = new ArrayList<>(vals.size()); | ||
516 | + for (byte[] val : vals) { | ||
517 | + dsl.add(deserializeVal(val)); | ||
518 | + } | ||
519 | + return dsl; | ||
520 | + } | ||
521 | + | ||
522 | + private Set<java.util.Map.Entry<K, V>> deserializeEntrySet( | ||
523 | + Set<java.util.Map.Entry<byte[], byte[]>> entries) { | ||
524 | + | ||
525 | + Set<java.util.Map.Entry<K, V>> dse = new HashSet<>(entries.size()); | ||
526 | + for (java.util.Map.Entry<byte[], byte[]> entry : entries) { | ||
527 | + dse.add(Pair.of(deserializeKey(entry.getKey()), | ||
528 | + deserializeVal(entry.getValue()))); | ||
529 | + } | ||
530 | + return dse; | ||
531 | + } | ||
532 | + | ||
533 | + private final class BaseEntryListener | ||
534 | + implements EntryListener<byte[], byte[]> { | ||
535 | + | ||
536 | + private final EntryListener<K, V> listener; | ||
537 | + | ||
538 | + public BaseEntryListener(EntryListener<K, V> listener) { | ||
539 | + this.listener = listener; | ||
540 | + } | ||
541 | + | ||
542 | + @Override | ||
543 | + public void mapEvicted(MapEvent event) { | ||
544 | + listener.mapEvicted(event); | ||
545 | + } | ||
546 | + | ||
547 | + @Override | ||
548 | + public void mapCleared(MapEvent event) { | ||
549 | + listener.mapCleared(event); | ||
550 | + } | ||
551 | + | ||
552 | + @Override | ||
553 | + public void entryUpdated(EntryEvent<byte[], byte[]> event) { | ||
554 | + EntryEvent<K, V> evt = new EntryEvent<K, V>( | ||
555 | + event.getSource(), | ||
556 | + event.getMember(), | ||
557 | + event.getEventType().getType(), | ||
558 | + deserializeKey(event.getKey()), | ||
559 | + deserializeVal(event.getOldValue()), | ||
560 | + deserializeVal(event.getValue())); | ||
561 | + | ||
562 | + listener.entryUpdated(evt); | ||
563 | + } | ||
564 | + | ||
565 | + @Override | ||
566 | + public void entryRemoved(EntryEvent<byte[], byte[]> event) { | ||
567 | + EntryEvent<K, V> evt = new EntryEvent<K, V>( | ||
568 | + event.getSource(), | ||
569 | + event.getMember(), | ||
570 | + event.getEventType().getType(), | ||
571 | + deserializeKey(event.getKey()), | ||
572 | + deserializeVal(event.getOldValue()), | ||
573 | + null); | ||
574 | + | ||
575 | + listener.entryRemoved(evt); | ||
576 | + } | ||
577 | + | ||
578 | + @Override | ||
579 | + public void entryEvicted(EntryEvent<byte[], byte[]> event) { | ||
580 | + EntryEvent<K, V> evt = new EntryEvent<K, V>( | ||
581 | + event.getSource(), | ||
582 | + event.getMember(), | ||
583 | + event.getEventType().getType(), | ||
584 | + deserializeKey(event.getKey()), | ||
585 | + deserializeVal(event.getOldValue()), | ||
586 | + deserializeVal(event.getValue())); | ||
587 | + | ||
588 | + listener.entryEvicted(evt); | ||
589 | + } | ||
590 | + | ||
591 | + @Override | ||
592 | + public void entryAdded(EntryEvent<byte[], byte[]> event) { | ||
593 | + EntryEvent<K, V> evt = new EntryEvent<K, V>( | ||
594 | + event.getSource(), | ||
595 | + event.getMember(), | ||
596 | + event.getEventType().getType(), | ||
597 | + deserializeKey(event.getKey()), | ||
598 | + null, | ||
599 | + deserializeVal(event.getValue())); | ||
600 | + | ||
601 | + listener.entryAdded(evt); | ||
602 | + } | ||
603 | + } | ||
604 | + | ||
605 | + private final class DeserializeVal implements Function<byte[], V> { | ||
606 | + @Override | ||
607 | + public V apply(byte[] input) { | ||
608 | + return deserializeVal(input); | ||
609 | + } | ||
610 | + } | ||
611 | + | ||
612 | +} |
... | @@ -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() { | ... | ... |
-
Please register or login to post a comment