aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/store
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/store')
-rw-r--r--framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java2
-rw-r--r--framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/packet/impl/DistributedPacketStore.java43
-rw-r--r--framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentDeviceResourceStore.java225
-rw-r--r--framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentIntentSetMultimap.java2
-rw-r--r--framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java9
5 files changed, 41 insertions, 240 deletions
diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
index 648119e5..10f79eb0 100644
--- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
+++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
@@ -304,7 +304,7 @@ public class ConsistentResourceStore implements ResourceStore {
}
/**
- * Removes teh values from the existing values associated with the specified key.
+ * Removes the values from the existing values associated with the specified key.
* If the map doesn't contain the given values, removal will not happen.
*
* @param map map holding multiple values for a key
diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/packet/impl/DistributedPacketStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/packet/impl/DistributedPacketStore.java
index f0f3eb5e..3865a779 100644
--- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/packet/impl/DistributedPacketStore.java
+++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/packet/impl/DistributedPacketStore.java
@@ -41,6 +41,7 @@ import org.onosproject.store.cluster.messaging.MessageSubject;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.serializers.KryoSerializer;
import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.ConsistentMapException;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
import org.slf4j.Logger;
@@ -52,6 +53,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.onlab.util.Tools.groupedThreads;
+import static org.onlab.util.Tools.retryable;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -66,6 +68,8 @@ public class DistributedPacketStore
private final Logger log = getLogger(getClass());
+ private static final int MAX_BACKOFF = 10;
+
// TODO: make this configurable.
private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 4;
@@ -159,11 +163,11 @@ public class DistributedPacketStore
return tracker.requests();
}
- private class PacketRequestTracker {
+ private final class PacketRequestTracker {
private ConsistentMap<TrafficSelector, Set<PacketRequest>> requests;
- public PacketRequestTracker() {
+ private PacketRequestTracker() {
requests = storageService.<TrafficSelector, Set<PacketRequest>>consistentMapBuilder()
.withName("onos-packet-requests")
.withPartitionsDisabled()
@@ -171,7 +175,17 @@ public class DistributedPacketStore
.build();
}
- public void add(PacketRequest request) {
+ private void add(PacketRequest request) {
+ AtomicBoolean firstRequest =
+ retryable(this::addInternal, ConsistentMapException.class,
+ 3, MAX_BACKOFF).apply(request);
+ if (firstRequest.get() && delegate != null) {
+ // The instance that makes the first request will push to all devices
+ delegate.requestPackets(request);
+ }
+ }
+
+ private AtomicBoolean addInternal(PacketRequest request) {
AtomicBoolean firstRequest = new AtomicBoolean(false);
requests.compute(request.selector(), (s, existingRequests) -> {
if (existingRequests == null) {
@@ -186,14 +200,20 @@ public class DistributedPacketStore
return existingRequests;
}
});
+ return firstRequest;
+ }
- if (firstRequest.get() && delegate != null) {
- // The instance that makes the first request will push to all devices
- delegate.requestPackets(request);
+ private void remove(PacketRequest request) {
+ AtomicBoolean removedLast =
+ retryable(this::removeInternal, ConsistentMapException.class,
+ 3, MAX_BACKOFF).apply(request);
+ if (removedLast.get() && delegate != null) {
+ // The instance that removes the last request will remove from all devices
+ delegate.cancelPackets(request);
}
}
- public void remove(PacketRequest request) {
+ private AtomicBoolean removeInternal(PacketRequest request) {
AtomicBoolean removedLast = new AtomicBoolean(false);
requests.computeIfPresent(request.selector(), (s, existingRequests) -> {
if (existingRequests.contains(request)) {
@@ -209,15 +229,10 @@ public class DistributedPacketStore
return existingRequests;
}
});
-
- if (removedLast.get() && delegate != null) {
- // The instance that removes the last request will remove from all devices
- delegate.cancelPackets(request);
- }
-
+ return removedLast;
}
- public List<PacketRequest> requests() {
+ private List<PacketRequest> requests() {
List<PacketRequest> list = Lists.newArrayList();
requests.values().forEach(v -> list.addAll(v.value()));
list.sort((o1, o2) -> o1.priority().priorityValue() - o2.priority().priorityValue());
diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentDeviceResourceStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentDeviceResourceStore.java
deleted file mode 100644
index 3266e96c..00000000
--- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentDeviceResourceStore.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.store.resource.impl;
-
-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.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.Service;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Port;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.intent.IntentId;
-import org.onosproject.net.resource.device.DeviceResourceStore;
-import org.onosproject.store.serializers.KryoNamespaces;
-import org.onosproject.store.service.ConsistentMap;
-import org.onosproject.store.service.Serializer;
-import org.onosproject.store.service.StorageService;
-import org.onosproject.store.service.TransactionContext;
-import org.onosproject.store.service.TransactionalMap;
-import org.onosproject.store.service.Versioned;
-import org.slf4j.Logger;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static org.slf4j.LoggerFactory.getLogger;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Store that manages device resources using Copycat-backed TransactionalMaps.
- */
-@Component(immediate = true, enabled = true)
-@Service
-public class ConsistentDeviceResourceStore implements DeviceResourceStore {
- private final Logger log = getLogger(getClass());
-
- private static final String PORT_ALLOCATIONS = "PortAllocations";
- private static final String INTENT_MAPPING = "IntentMapping";
- private static final String INTENT_ALLOCATIONS = "PortIntentAllocations";
-
- private static final Serializer SERIALIZER = Serializer.using(KryoNamespaces.API);
-
- private ConsistentMap<Port, IntentId> portAllocMap;
- private ConsistentMap<IntentId, Set<Port>> intentAllocMap;
- private ConsistentMap<IntentId, Set<IntentId>> intentMapping;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected StorageService storageService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
-
- @Activate
- public void activate() {
- portAllocMap = storageService.<Port, IntentId>consistentMapBuilder()
- .withName(PORT_ALLOCATIONS)
- .withSerializer(SERIALIZER)
- .build();
- intentAllocMap = storageService.<IntentId, Set<Port>>consistentMapBuilder()
- .withName(INTENT_ALLOCATIONS)
- .withSerializer(SERIALIZER)
- .build();
- intentMapping = storageService.<IntentId, Set<IntentId>>consistentMapBuilder()
- .withName(INTENT_MAPPING)
- .withSerializer(SERIALIZER)
- .build();
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- log.info("Stopped");
- }
-
- private TransactionalMap<Port, IntentId> getPortAllocs(TransactionContext tx) {
- return tx.getTransactionalMap(PORT_ALLOCATIONS, SERIALIZER);
- }
-
- private TransactionalMap<IntentId, Set<Port>> getIntentAllocs(TransactionContext tx) {
- return tx.getTransactionalMap(INTENT_ALLOCATIONS, SERIALIZER);
- }
-
- private TransactionContext getTxContext() {
- return storageService.transactionContextBuilder().build();
- }
-
- @Override
- public Set<Port> getFreePorts(DeviceId deviceId) {
- checkNotNull(deviceId);
-
- Set<Port> freePorts = new HashSet<>();
- for (Port port : deviceService.getPorts(deviceId)) {
- if (!portAllocMap.containsKey(port)) {
- freePorts.add(port);
- }
- }
-
- return freePorts;
- }
-
- @Override
- public boolean allocatePorts(Set<Port> ports, IntentId intentId) {
- checkNotNull(ports);
- checkArgument(ports.size() > 0);
- checkNotNull(intentId);
-
- TransactionContext tx = getTxContext();
- tx.begin();
- try {
- TransactionalMap<Port, IntentId> portAllocs = getPortAllocs(tx);
- for (Port port : ports) {
- if (portAllocs.putIfAbsent(port, intentId) != null) {
- throw new Exception("Port already allocated " + port.toString());
- }
- }
-
- TransactionalMap<IntentId, Set<Port>> intentAllocs = getIntentAllocs(tx);
- intentAllocs.put(intentId, ports);
- tx.commit();
- } catch (Exception e) {
- log.error("Exception thrown, rolling back", e);
- tx.abort();
- return false;
- }
-
- return true;
- }
-
- @Override
- public Set<Port> getAllocations(IntentId intentId) {
- if (!intentAllocMap.containsKey(intentId)) {
- Collections.emptySet();
- }
-
- return intentAllocMap.get(intentId).value();
- }
-
- @Override
- public IntentId getAllocations(Port port) {
- if (!portAllocMap.containsKey(port)) {
- return null;
- }
-
- return portAllocMap.get(port).value();
- }
-
- @Override
- public Set<IntentId> getMapping(IntentId intentId) {
- Versioned<Set<IntentId>> result = intentMapping.get(intentId);
-
- if (result != null) {
- return result.value();
- }
-
- return null;
- }
-
- @Override
- public boolean allocateMapping(IntentId keyIntentId, IntentId valIntentId) {
- Versioned<Set<IntentId>> versionedIntents = intentMapping.get(keyIntentId);
-
- if (versionedIntents == null) {
- Set<IntentId> newSet = new HashSet<>();
- newSet.add(valIntentId);
- intentMapping.put(keyIntentId, newSet);
- } else {
- versionedIntents.value().add(valIntentId);
- }
-
- return true;
- }
-
- @Override
- public void releaseMapping(IntentId intentId) {
- for (IntentId intent : intentMapping.keySet()) {
- // TODO: optimize by checking for identical src & dst
- Set<IntentId> mapping = intentMapping.get(intent).value();
- if (mapping.remove(intentId)) {
- return;
- }
- }
- }
-
- @Override
- public boolean releasePorts(IntentId intentId) {
- checkNotNull(intentId);
-
- TransactionContext tx = getTxContext();
- tx.begin();
- try {
- TransactionalMap<IntentId, Set<Port>> intentAllocs = getIntentAllocs(tx);
- Set<Port> ports = intentAllocs.get(intentId);
- intentAllocs.remove(intentId);
-
- TransactionalMap<Port, IntentId> portAllocs = getPortAllocs(tx);
- for (Port port : ports) {
- portAllocs.remove(port);
- }
- tx.commit();
- } catch (Exception e) {
- log.error("Exception thrown, rolling back", e);
- tx.abort();
- return false;
- }
-
- return true;
- }
-}
diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentIntentSetMultimap.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentIntentSetMultimap.java
index 87e67215..8d5a1001 100644
--- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentIntentSetMultimap.java
+++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentIntentSetMultimap.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.store.resource.impl;
+import com.google.common.annotations.Beta;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -42,6 +43,7 @@ import static org.slf4j.LoggerFactory.getLogger;
*/
@Component(immediate = true, enabled = true)
@Service
+@Beta
public class ConsistentIntentSetMultimap implements IntentSetMultimap {
private final Logger log = getLogger(getClass());
diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java
index 11137aa2..c332ada5 100644
--- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java
+++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java
@@ -363,6 +363,15 @@ public class ConsistentLinkResourceStore extends
after.add(allocations);
linkAllocs.putIfAbsent(linkKey, after);
} else {
+ boolean overlapped = before.stream()
+ .flatMap(x -> x.getResourceAllocation(link).stream())
+ .anyMatch(x -> allocations.getResourceAllocation(link).contains(x));
+ if (overlapped) {
+ throw new ResourceAllocationException(
+ String.format("Resource allocations are overlapped between %s and %s",
+ before, allocations)
+ );
+ }
List<LinkResourceAllocations> after = new ArrayList<>(before.size() + 1);
after.addAll(before);
after.add(allocations);