Search in sources :

Example 1 with CompletedBatchOperation

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

the class DefaultVirtualFlowRuleProvider method executeBatch.

@Override
public void executeBatch(NetworkId networkId, FlowRuleBatchOperation batch) {
    checkNotNull(batch);
    for (FlowRuleBatchEntry fop : batch.getOperations()) {
        FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
        switch(fop.operator()) {
            case ADD:
                devirtualize(networkId, fop.target()).forEach(builder::add);
                break;
            case REMOVE:
                devirtualize(networkId, fop.target()).forEach(builder::remove);
                break;
            case MODIFY:
                devirtualize(networkId, fop.target()).forEach(builder::modify);
                break;
            default:
                break;
        }
        flowRuleService.apply(builder.build(new FlowRuleOperationsContext() {

            @Override
            public void onSuccess(FlowRuleOperations ops) {
                CompletedBatchOperation status = new CompletedBatchOperation(true, Sets.newConcurrentHashSet(), batch.deviceId());
                VirtualFlowRuleProviderService providerService = (VirtualFlowRuleProviderService) providerRegistryService.getProviderService(networkId, VirtualFlowRuleProvider.class);
                providerService.batchOperationCompleted(batch.id(), status);
            }

            @Override
            public void onError(FlowRuleOperations ops) {
                Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), BatchOperationEntry::target));
                CompletedBatchOperation status = new CompletedBatchOperation(false, failures, batch.deviceId());
                VirtualFlowRuleProviderService providerService = (VirtualFlowRuleProviderService) providerRegistryService.getProviderService(networkId, VirtualFlowRuleProvider.class);
                providerService.batchOperationCompleted(batch.id(), status);
            }
        }));
    }
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) VirtualFlowRuleProvider(org.onosproject.incubator.net.virtual.provider.VirtualFlowRuleProvider) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) VirtualFlowRuleProviderService(org.onosproject.incubator.net.virtual.provider.VirtualFlowRuleProviderService) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext)

Example 2 with CompletedBatchOperation

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

the class DistributedVirtualFlowRuleStore method storeBatchInternal.

private void storeBatchInternal(NetworkId networkId, FlowRuleBatchOperation operation) {
    final DeviceId did = operation.deviceId();
    // final Collection<FlowEntry> ft = flowTable.getFlowEntries(did);
    Set<FlowRuleBatchEntry> currentOps = updateStoreInternal(networkId, operation);
    if (currentOps.isEmpty()) {
        batchOperationComplete(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), did)));
        return;
    }
    // Confirm that flowrule service is created
    vnaService.get(networkId, FlowRuleService.class);
    notifyDelegate(networkId, FlowRuleBatchEvent.requested(new FlowRuleBatchRequest(operation.id(), currentOps), operation.deviceId()));
}
Also used : VirtualDeviceId(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId) DeviceId(org.onosproject.net.DeviceId) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)

Example 3 with CompletedBatchOperation

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

the class SimpleVirtualFlowRuleStore method batchOperationComplete.

@Override
public void batchOperationComplete(NetworkId networkId, FlowRuleBatchEvent event) {
    final Long batchId = event.subject().batchId();
    SettableFuture<CompletedBatchOperation> future = pendingFutures.getIfPresent(batchId);
    if (future != null) {
        future.set(event.result());
        pendingFutures.invalidate(batchId);
    }
    notifyDelegate(networkId, event);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation)

Example 4 with CompletedBatchOperation

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

the class SimpleFlowRuleStore method storeBatch.

@Override
public void storeBatch(FlowRuleBatchOperation operation) {
    List<FlowRuleBatchEntry> toAdd = new ArrayList<>();
    List<FlowRuleBatchEntry> toRemove = new ArrayList<>();
    for (FlowRuleBatchEntry entry : operation.getOperations()) {
        final FlowRule flowRule = entry.target();
        if (entry.operator().equals(FlowRuleOperation.ADD)) {
            if (!getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
                storeFlowRule(flowRule);
                toAdd.add(entry);
            }
        } else if (entry.operator().equals(FlowRuleOperation.REMOVE)) {
            if (getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
                deleteFlowRule(flowRule);
                toRemove.add(entry);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported operation type");
        }
    }
    if (toAdd.isEmpty() && toRemove.isEmpty()) {
        notifyDelegate(FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId())));
        return;
    }
    SettableFuture<CompletedBatchOperation> r = SettableFuture.create();
    final int batchId = localBatchIdGen.incrementAndGet();
    pendingFutures.put(batchId, r);
    toAdd.addAll(toRemove);
    notifyDelegate(FlowRuleBatchEvent.requested(new FlowRuleBatchRequest(batchId, Sets.newHashSet(toAdd)), operation.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)

Example 5 with CompletedBatchOperation

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

the class FlowRuleDriverProvider method executeBatch.

@Override
public void executeBatch(FlowRuleBatchOperation batch) {
    ImmutableList.Builder<FlowRule> toAdd = ImmutableList.builder();
    ImmutableList.Builder<FlowRule> toRemove = ImmutableList.builder();
    for (FlowRuleBatchEntry fbe : batch.getOperations()) {
        if (fbe.operator() == ADD || fbe.operator() == MODIFY) {
            toAdd.add(fbe.target());
        } else if (fbe.operator() == REMOVE) {
            toRemove.add(fbe.target());
        }
    }
    ImmutableList<FlowRule> rulesToAdd = toAdd.build();
    ImmutableList<FlowRule> rulesToRemove = toRemove.build();
    Collection<FlowRule> added = ImmutableList.of();
    if (!rulesToAdd.isEmpty()) {
        added = applyFlowRules(batch.deviceId(), rulesToAdd);
    }
    Collection<FlowRule> removed = ImmutableList.of();
    if (!rulesToRemove.isEmpty()) {
        removed = removeFlowRules(batch.deviceId(), rulesToRemove);
    }
    Set<FlowRule> failedRules = Sets.union(Sets.difference(copyOf(rulesToAdd), copyOf(added)), Sets.difference(copyOf(rulesToRemove), copyOf(removed)));
    CompletedBatchOperation status = new CompletedBatchOperation(failedRules.isEmpty(), failedRules, batch.deviceId());
    providerService.batchOperationCompleted(batch.id(), status);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) FlowRule(org.onosproject.net.flow.FlowRule) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation)

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