Search in sources :

Example 1 with FlowRuleBatchEntry

use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry 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 FlowRuleBatchEntry

use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry 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 FlowRuleBatchEntry

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

the class FlowRuleBatchOperationTest method testEquals.

/**
 * Tests the equals(), hashCode() and toString() methods.
 */
@Test
public void testEquals() {
    final FlowRule rule = new IntentTestsMocks.MockFlowRule(1);
    final FlowRuleBatchEntry entry1 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule);
    final FlowRuleBatchEntry entry2 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.MODIFY, rule);
    final FlowRuleBatchEntry entry3 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.REMOVE, rule);
    final LinkedList<FlowRuleBatchEntry> ops1 = new LinkedList<>();
    ops1.add(entry1);
    final LinkedList<FlowRuleBatchEntry> ops2 = new LinkedList<>();
    ops1.add(entry2);
    final LinkedList<FlowRuleBatchEntry> ops3 = new LinkedList<>();
    ops3.add(entry3);
    final FlowRuleBatchOperation operation1 = new FlowRuleBatchOperation(ops1, null, 0);
    final FlowRuleBatchOperation sameAsOperation1 = new FlowRuleBatchOperation(ops1, null, 0);
    final FlowRuleBatchOperation operation2 = new FlowRuleBatchOperation(ops2, null, 0);
    final FlowRuleBatchOperation operation3 = new FlowRuleBatchOperation(ops3, null, 0);
    new EqualsTester().addEqualityGroup(operation1, sameAsOperation1).addEqualityGroup(operation2).addEqualityGroup(operation3).testEquals();
}
Also used : FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) EqualsTester(com.google.common.testing.EqualsTester) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with FlowRuleBatchEntry

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

the class FlowRuleBatchRequestTest method testConstruction.

/**
 * Tests that construction of FlowRuleBatchRequest objects returns the
 * correct objects.
 */
@Test
public void testConstruction() {
    final FlowRule rule1 = new IntentTestsMocks.MockFlowRule(1);
    final FlowRule rule2 = new IntentTestsMocks.MockFlowRule(2);
    final Set<FlowRuleBatchEntry> batch = new HashSet<>();
    batch.add(new FlowRuleBatchEntry(ADD, rule1));
    batch.add(new FlowRuleBatchEntry(REMOVE, rule2));
    final FlowRuleBatchRequest request = new FlowRuleBatchRequest(1, batch);
    assertThat(request.ops(), hasSize(2));
    assertThat(request.batchId(), is(1L));
    final FlowRuleBatchOperation op = request.asBatchOperation(rule1.deviceId());
    assertThat(op.size(), is(2));
    final List<FlowRuleBatchEntry> ops = op.getOperations();
    assertThat(ops, hasSize(2));
}
Also used : FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) HashSet(java.util.HashSet) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest) Test(org.junit.Test)

Example 5 with FlowRuleBatchEntry

use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry 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)

Aggregations

FlowRuleBatchEntry (org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry)14 CompletedBatchOperation (org.onosproject.net.flow.CompletedBatchOperation)8 FlowRule (org.onosproject.net.flow.FlowRule)6 Test (org.junit.Test)5 DeviceId (org.onosproject.net.DeviceId)5 FlowRuleBatchOperation (org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation)5 FlowRuleBatchRequest (org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)5 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)4 FlowEntry (org.onosproject.net.flow.FlowEntry)4 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)3 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 RemovalCause (com.google.common.cache.RemovalCause)1 RemovalNotification (com.google.common.cache.RemovalNotification)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1