From 81391595dca425ae58e2294898f09f11d9a32dbc Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Tue, 22 Sep 2015 12:49:09 -0700 Subject: bringing src to commit tag 65d551b50e782b0c1ea76c1a9ed1c5a801a5a7e4 Change-Id: Ib2da78962eaef856f418636c31b0f5c84286244f --- framework/src/onos/core/common/pom.xml | 2 +- .../onosproject/codec/impl/MockCodecContext.java | 2 +- .../store/trivial/SimpleDeviceStore.java | 9 +- .../store/trivial/SimpleDeviceStoreTest.java | 33 +++----- .../store/trivial/SimpleFlowRuleStore.java | 11 +-- .../store/trivial/SimpleGroupStore.java | 17 +--- .../store/trivial/SimpleGroupStoreTest.java | 20 ++--- .../onosproject/store/trivial/SimpleHostStore.java | 96 +++++++--------------- .../onosproject/store/trivial/SimpleLinkStore.java | 3 +- .../store/trivial/SimpleLinkStoreTest.java | 33 +++----- .../store/trivial/SimpleMastershipStore.java | 8 +- .../store/trivial/SimplePacketStore.java | 8 +- 12 files changed, 78 insertions(+), 164 deletions(-) (limited to 'framework/src/onos/core/common') diff --git a/framework/src/onos/core/common/pom.xml b/framework/src/onos/core/common/pom.xml index 71c0fe40..e4d25eed 100644 --- a/framework/src/onos/core/common/pom.xml +++ b/framework/src/onos/core/common/pom.xml @@ -22,7 +22,7 @@ org.onosproject onos-core - 1.3.0-SNAPSHOT + 1.4.0-SNAPSHOT ../pom.xml diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/MockCodecContext.java b/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/MockCodecContext.java index 6a9b6708..c3b6d821 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/MockCodecContext.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/MockCodecContext.java @@ -30,7 +30,7 @@ public class MockCodecContext implements CodecContext { private final ObjectMapper mapper = new ObjectMapper(); private final CodecManager manager = new CodecManager(); - private final Map, Object> services = new HashMap<>(); + private final Map, Object> services = new HashMap<>(); /** * Constructs a new mock codec context. diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java index fc90dfad..72fc1b05 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java @@ -15,7 +15,6 @@ */ package org.onosproject.store.trivial; -import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; @@ -134,13 +133,7 @@ public class SimpleDeviceStore @Override public Iterable getAvailableDevices() { return FluentIterable.from(getDevices()) - .filter(new Predicate() { - - @Override - public boolean apply(Device input) { - return isAvailable(input.id()); - } - }); + .filter(input -> isAvailable(input.id())); } @Override diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStoreTest.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStoreTest.java index 562e6f3c..c9e135d9 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStoreTest.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStoreTest.java @@ -479,31 +479,22 @@ public class SimpleDeviceStoreTest { @Test public final void testEvents() throws InterruptedException { final CountDownLatch addLatch = new CountDownLatch(1); - DeviceStoreDelegate checkAdd = new DeviceStoreDelegate() { - @Override - public void notify(DeviceEvent event) { - assertEquals(DEVICE_ADDED, event.type()); - assertDevice(DID1, SW1, event.subject()); - addLatch.countDown(); - } + DeviceStoreDelegate checkAdd = event -> { + assertEquals(DEVICE_ADDED, event.type()); + assertDevice(DID1, SW1, event.subject()); + addLatch.countDown(); }; final CountDownLatch updateLatch = new CountDownLatch(1); - DeviceStoreDelegate checkUpdate = new DeviceStoreDelegate() { - @Override - public void notify(DeviceEvent event) { - assertEquals(DEVICE_UPDATED, event.type()); - assertDevice(DID1, SW2, event.subject()); - updateLatch.countDown(); - } + DeviceStoreDelegate checkUpdate = event -> { + assertEquals(DEVICE_UPDATED, event.type()); + assertDevice(DID1, SW2, event.subject()); + updateLatch.countDown(); }; final CountDownLatch removeLatch = new CountDownLatch(1); - DeviceStoreDelegate checkRemove = new DeviceStoreDelegate() { - @Override - public void notify(DeviceEvent event) { - assertEquals(DEVICE_REMOVED, event.type()); - assertDevice(DID1, SW2, event.subject()); - removeLatch.countDown(); - } + DeviceStoreDelegate checkRemove = event -> { + assertEquals(DEVICE_REMOVED, event.type()); + assertDevice(DID1, SW2, event.subject()); + removeLatch.countDown(); }; DeviceDescription description = diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleFlowRuleStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleFlowRuleStore.java index 3b8f1d35..c8c92aa5 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleFlowRuleStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleFlowRuleStore.java @@ -15,7 +15,6 @@ */ package org.onosproject.store.trivial; -import com.google.common.base.Function; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.RemovalListener; @@ -162,15 +161,7 @@ public class SimpleFlowRuleStore public Iterable getFlowEntries(DeviceId deviceId) { // flatten and make iterator unmodifiable return FluentIterable.from(getFlowTable(deviceId).values()) - .transformAndConcat( - new Function, Iterable>() { - - @Override - public Iterable apply( - List input) { - return Collections.unmodifiableList(input); - } - }); + .transformAndConcat(Collections::unmodifiableList); } @Override diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleGroupStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleGroupStore.java index 71de3e13..230fa339 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleGroupStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleGroupStore.java @@ -55,7 +55,6 @@ import org.onosproject.net.group.StoredGroupEntry; import org.onosproject.store.AbstractStore; import org.slf4j.Logger; -import com.google.common.base.Function; import com.google.common.collect.FluentIterable; import com.google.common.collect.Sets; @@ -83,8 +82,7 @@ public class SimpleGroupStore private final ConcurrentMap> extraneousGroupEntriesById = new ConcurrentHashMap<>(); - private final HashMap deviceAuditStatus = - new HashMap(); + private final HashMap deviceAuditStatus = new HashMap<>(); private final AtomicInteger groupIdGen = new AtomicInteger(); @@ -189,15 +187,7 @@ public class SimpleGroupStore public Iterable getGroups(DeviceId deviceId) { // flatten and make iterator unmodifiable return FluentIterable.from(getGroupKeyTable(deviceId).values()) - .transform( - new Function() { - - @Override - public Group apply( - StoredGroupEntry input) { - return input; - } - }); + .transform(input -> input); } /** @@ -358,8 +348,7 @@ public class SimpleGroupStore UpdateType type, GroupBuckets buckets) { GroupBuckets oldBuckets = oldGroup.buckets(); - List newBucketList = new ArrayList( - oldBuckets.buckets()); + List newBucketList = new ArrayList<>(oldBuckets.buckets()); boolean groupDescUpdated = false; if (type == UpdateType.ADD) { diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleGroupStoreTest.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleGroupStoreTest.java index dd6c8a58..b10fca5c 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleGroupStoreTest.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleGroupStoreTest.java @@ -205,10 +205,10 @@ public class SimpleGroupStoreTest { private void testStoreAndGetGroup(GroupKey key) { PortNumber[] ports = {PortNumber.portNumber(31), PortNumber.portNumber(32)}; - List outPorts = new ArrayList(); + List outPorts = new ArrayList<>(); outPorts.addAll(Arrays.asList(ports)); - List buckets = new ArrayList(); + List buckets = new ArrayList<>(); for (PortNumber portNumber: outPorts) { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(portNumber) @@ -271,7 +271,7 @@ public class SimpleGroupStoreTest { Group existingGroup = simpleGroupStore.getGroup(D1, currKey); int totalPkts = 0; int totalBytes = 0; - List newBucketList = new ArrayList(); + List newBucketList = new ArrayList<>(); for (GroupBucket bucket:existingGroup.buckets().buckets()) { StoredGroupBucketEntry newBucket = (StoredGroupBucketEntry) @@ -302,15 +302,15 @@ public class SimpleGroupStoreTest { // Testing updateGroupDescription for ADD operation from northbound private void testAddBuckets(GroupKey currKey, GroupKey addKey) { Group existingGroup = simpleGroupStore.getGroup(D1, currKey); - List buckets = new ArrayList(); + List buckets = new ArrayList<>(); buckets.addAll(existingGroup.buckets().buckets()); PortNumber[] newNeighborPorts = {PortNumber.portNumber(41), PortNumber.portNumber(42)}; - List newOutPorts = new ArrayList(); + List newOutPorts = new ArrayList<>(); newOutPorts.addAll(Collections.singletonList(newNeighborPorts[0])); - List toAddBuckets = new ArrayList(); + List toAddBuckets = new ArrayList<>(); for (PortNumber portNumber: newOutPorts) { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(portNumber) @@ -340,10 +340,10 @@ public class SimpleGroupStoreTest { // Testing updateGroupDescription for REMOVE operation from northbound private void testRemoveBuckets(GroupKey currKey, GroupKey removeKey) { Group existingGroup = simpleGroupStore.getGroup(D1, currKey); - List buckets = new ArrayList(); + List buckets = new ArrayList<>(); buckets.addAll(existingGroup.buckets().buckets()); - List toRemoveBuckets = new ArrayList(); + List toRemoveBuckets = new ArrayList<>(); // There should be 4 buckets in the current group toRemoveBuckets.add(buckets.remove(0)); @@ -405,11 +405,11 @@ public class SimpleGroupStoreTest { GroupKey key = new DefaultGroupKey("group1".getBytes()); PortNumber[] ports = {PortNumber.portNumber(31), PortNumber.portNumber(32)}; - List outPorts = new ArrayList(); + List outPorts = new ArrayList<>(); outPorts.add(ports[0]); outPorts.add(ports[1]); - List buckets = new ArrayList(); + List buckets = new ArrayList<>(); for (PortNumber portNumber: outPorts) { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(portNumber) diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java index f5604f68..264d0493 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java @@ -15,23 +15,16 @@ */ package org.onosproject.store.trivial; -import static org.onosproject.net.DefaultAnnotations.merge; -import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; -import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED; -import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; -import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED; -import static org.slf4j.LoggerFactory.getLogger; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - +import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Service; +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; +import org.onlab.packet.VlanId; import org.onosproject.net.Annotations; import org.onosproject.net.ConnectPoint; import org.onosproject.net.DefaultAnnotations; @@ -44,19 +37,21 @@ import org.onosproject.net.host.HostDescription; import org.onosproject.net.host.HostEvent; import org.onosproject.net.host.HostStore; import org.onosproject.net.host.HostStoreDelegate; -import org.onosproject.net.host.PortAddresses; import org.onosproject.net.provider.ProviderId; import org.onosproject.store.AbstractStore; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onlab.packet.VlanId; import org.slf4j.Logger; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; -import com.google.common.collect.SetMultimap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import static org.onosproject.net.DefaultAnnotations.merge; +import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; +import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED; +import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; +import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED; +import static org.slf4j.LoggerFactory.getLogger; // TODO: multi-provider, annotation not supported. /** @@ -77,10 +72,6 @@ public class SimpleHostStore // Hosts tracked by their location private final Multimap locations = HashMultimap.create(); - private final SetMultimap portAddresses = - Multimaps.synchronizedSetMultimap( - HashMultimap.create()); - @Activate public void activate() { log.info("Started"); @@ -93,12 +84,14 @@ public class SimpleHostStore @Override public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, - HostDescription hostDescription) { + HostDescription hostDescription, + boolean replaceIps) { + //TODO We need a way to detect conflicting changes and abort update. StoredHost host = hosts.get(hostId); if (host == null) { return createHost(providerId, hostId, hostDescription); } - return updateHost(providerId, host, hostDescription); + return updateHost(providerId, host, hostDescription, replaceIps); } // creates a new host and sends HOST_ADDED @@ -119,7 +112,7 @@ public class SimpleHostStore // checks for type of update to host, sends appropriate event private HostEvent updateHost(ProviderId providerId, StoredHost host, - HostDescription descr) { + HostDescription descr, boolean replaceIps) { HostEvent event; if (!host.location().equals(descr.location())) { host.setLocation(descr.location()); @@ -131,8 +124,14 @@ public class SimpleHostStore return null; } - Set addresses = new HashSet<>(host.ipAddresses()); - addresses.addAll(descr.ipAddress()); + final Set addresses; + if (replaceIps) { + addresses = ImmutableSet.copyOf(descr.ipAddress()); + } else { + addresses = new HashSet<>(host.ipAddresses()); + addresses.addAll(descr.ipAddress()); + } + Annotations annotations = merge((DefaultAnnotations) host.annotations(), descr.annotations()); StoredHost updated = new StoredHost(providerId, host.id(), @@ -224,41 +223,6 @@ public class SimpleHostStore return hostset; } - @Override - public void updateAddressBindings(PortAddresses addresses) { - portAddresses.put(addresses.connectPoint(), addresses); - } - - @Override - public void removeAddressBindings(PortAddresses addresses) { - portAddresses.remove(addresses.connectPoint(), addresses); - } - - @Override - public void clearAddressBindings(ConnectPoint connectPoint) { - portAddresses.removeAll(connectPoint); - } - - @Override - public Set getAddressBindings() { - synchronized (portAddresses) { - return ImmutableSet.copyOf(portAddresses.values()); - } - } - - @Override - public Set getAddressBindingsForPort(ConnectPoint connectPoint) { - synchronized (portAddresses) { - Set addresses = portAddresses.get(connectPoint); - - if (addresses == null) { - return Collections.emptySet(); - } else { - return ImmutableSet.copyOf(addresses); - } - } - } - // Auxiliary extension to allow location to mutate. private static final class StoredHost extends DefaultHost { private HostLocation location; diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStore.java index d0be2b1f..92b882a6 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStore.java @@ -44,7 +44,6 @@ import org.onosproject.net.provider.ProviderId; import org.onosproject.store.AbstractStore; import org.slf4j.Logger; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -280,7 +279,7 @@ public class SimpleLinkStore */ private static SetMultimap createSynchronizedHashMultiMap() { return synchronizedSetMultimap( - Multimaps.newSetMultimap(new ConcurrentHashMap>(), + Multimaps.newSetMultimap(new ConcurrentHashMap<>(), () -> Sets.newConcurrentHashSet())); } diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStoreTest.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStoreTest.java index 2d2b2759..40649aa5 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStoreTest.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStoreTest.java @@ -498,31 +498,22 @@ public class SimpleLinkStoreTest { final LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2); final CountDownLatch addLatch = new CountDownLatch(1); - LinkStoreDelegate checkAdd = new LinkStoreDelegate() { - @Override - public void notify(LinkEvent event) { - assertEquals(LINK_ADDED, event.type()); - assertLink(linkId1, INDIRECT, event.subject()); - addLatch.countDown(); - } + LinkStoreDelegate checkAdd = event -> { + assertEquals(LINK_ADDED, event.type()); + assertLink(linkId1, INDIRECT, event.subject()); + addLatch.countDown(); }; final CountDownLatch updateLatch = new CountDownLatch(1); - LinkStoreDelegate checkUpdate = new LinkStoreDelegate() { - @Override - public void notify(LinkEvent event) { - assertEquals(LINK_UPDATED, event.type()); - assertLink(linkId1, DIRECT, event.subject()); - updateLatch.countDown(); - } + LinkStoreDelegate checkUpdate = event -> { + assertEquals(LINK_UPDATED, event.type()); + assertLink(linkId1, DIRECT, event.subject()); + updateLatch.countDown(); }; final CountDownLatch removeLatch = new CountDownLatch(1); - LinkStoreDelegate checkRemove = new LinkStoreDelegate() { - @Override - public void notify(LinkEvent event) { - assertEquals(LINK_REMOVED, event.type()); - assertLink(linkId1, DIRECT, event.subject()); - removeLatch.countDown(); - } + LinkStoreDelegate checkRemove = event -> { + assertEquals(LINK_REMOVED, event.type()); + assertLink(linkId1, DIRECT, event.subject()); + removeLatch.countDown(); }; linkStore.setDelegate(checkAdd); diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleMastershipStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleMastershipStore.java index ef92ded2..61db2e66 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleMastershipStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleMastershipStore.java @@ -375,14 +375,10 @@ public class SimpleMastershipStore .filter(entry -> entry.getValue().contains(nodeId)) .forEach(entry -> toRelinquish.add(entry.getKey())); - toRelinquish.forEach(deviceId -> { - eventFutures.add(relinquishRole(nodeId, deviceId)); - }); + toRelinquish.forEach(deviceId -> eventFutures.add(relinquishRole(nodeId, deviceId))); eventFutures.forEach(future -> { - future.whenComplete((event, error) -> { - notifyDelegate(event); - }); + future.whenComplete((event, error) -> notifyDelegate(event)); }); } } diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimplePacketStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimplePacketStore.java index 4345abaf..f8359262 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimplePacketStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimplePacketStore.java @@ -15,6 +15,7 @@ */ package org.onosproject.store.trivial; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Service; @@ -26,8 +27,7 @@ import org.onosproject.net.packet.PacketStore; import org.onosproject.net.packet.PacketStoreDelegate; import org.onosproject.store.AbstractStore; - -import java.util.Collections; +import java.util.List; import java.util.Set; /** @@ -57,8 +57,8 @@ public class SimplePacketStore } @Override - public Set existingRequests() { - return Collections.unmodifiableSet(requests); + public List existingRequests() { + return ImmutableList.copyOf(requests); } } -- cgit 1.2.3-korg