Search in sources :

Example 11 with CompletedBatchOperation

use of org.onosproject.net.flow.CompletedBatchOperation in project onos by opennetworkinglab.

the class SimpleVirtualFlowRuleStore method storeBatch.

@Override
public void storeBatch(NetworkId networkId, FlowRuleBatchOperation batchOperation) {
    List<FlowRuleBatchEntry> toAdd = new ArrayList<>();
    List<FlowRuleBatchEntry> toRemove = new ArrayList<>();
    for (FlowRuleBatchEntry entry : batchOperation.getOperations()) {
        final FlowRule flowRule = entry.target();
        if (entry.operator().equals(FlowRuleBatchEntry.FlowRuleOperation.ADD)) {
            if (!getFlowEntries(networkId, flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
                storeFlowRule(networkId, flowRule);
                toAdd.add(entry);
            }
        } else if (entry.operator().equals(FlowRuleBatchEntry.FlowRuleOperation.REMOVE)) {
            if (getFlowEntries(networkId, flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
                deleteFlowRule(networkId, flowRule);
                toRemove.add(entry);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported operation type");
        }
    }
    if (toAdd.isEmpty() && toRemove.isEmpty()) {
        notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(batchOperation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), batchOperation.deviceId())));
        return;
    }
    SettableFuture<CompletedBatchOperation> r = SettableFuture.create();
    final long futureId = localBatchIdGen.incrementAndGet();
    pendingFutures.put(futureId, r);
    toAdd.addAll(toRemove);
    notifyDelegate(networkId, FlowRuleBatchEvent.requested(new FlowRuleBatchRequest(batchOperation.id(), Sets.newHashSet(toAdd)), batchOperation.deviceId()));
}
Also used : FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) FlowRule(org.onosproject.net.flow.FlowRule) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)

Aggregations

CompletedBatchOperation (org.onosproject.net.flow.CompletedBatchOperation)11 FlowRuleBatchEntry (org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry)9 FlowRule (org.onosproject.net.flow.FlowRule)7 FlowRuleBatchRequest (org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)6 DeviceId (org.onosproject.net.DeviceId)5 FlowEntry (org.onosproject.net.flow.FlowEntry)3 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)2 ImmutableList (com.google.common.collect.ImmutableList)2 Maps (com.google.common.collect.Maps)2 Collections (java.util.Collections)2 Dictionary (java.util.Dictionary)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Set (java.util.Set)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2 Tools.get (org.onlab.util.Tools.get)2 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)2