Search in sources :

Example 1 with FlowRuleBatchRequest

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

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

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

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

the class DistributedVirtualFlowRuleStore method storeBatch.

@Override
public void storeBatch(NetworkId networkId, FlowRuleBatchOperation operation) {
    if (operation.getOperations().isEmpty()) {
        notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId())));
        return;
    }
    DeviceId deviceId = operation.deviceId();
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.warn("No master for {}, vnet {} : flows will be marked for removal", deviceId, networkId);
        updateStoreInternal(networkId, operation);
        notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId())));
        return;
    }
    if (Objects.equals(local, master)) {
        storeBatchInternal(networkId, operation);
        return;
    }
    log.trace("Forwarding storeBatch to {}, which is the primary (master) for device {}, vent {}", master, deviceId, networkId);
    clusterCommunicator.unicast(new VirtualFlowRuleBatchOperation(networkId, operation), APPLY_BATCH_FLOWS, serializer::encode, master).whenComplete((result, error) -> {
        if (error != null) {
            log.warn("Failed to storeBatch: {} to {}", operation, master, error);
            Set<FlowRule> allFailures = operation.getOperations().stream().map(BatchOperationEntry::target).collect(Collectors.toSet());
            notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(false, allFailures, deviceId)));
        }
    });
}
Also used : VirtualFlowRuleBatchOperation(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRuleBatchOperation) VirtualDeviceId(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) FlowRule(org.onosproject.net.flow.FlowRule) VirtualFlowRule(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRule) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)

Example 5 with FlowRuleBatchRequest

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

the class ECFlowRuleStore method storeBatch.

@Override
public void storeBatch(FlowRuleBatchOperation operation) {
    if (operation.getOperations().isEmpty()) {
        notifyDelegate(FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId())));
        return;
    }
    DeviceId deviceId = operation.deviceId();
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.warn("Failed to storeBatch: No master for {}", deviceId);
        Set<FlowRule> allFailures = operation.getOperations().stream().map(op -> op.target()).collect(Collectors.toSet());
        notifyDelegate(FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(false, allFailures, deviceId)));
        return;
    }
    if (Objects.equals(local, master)) {
        storeBatchInternal(operation);
        return;
    }
    log.trace("Forwarding storeBatch to {}, which is the primary (master) for device {}", master, deviceId);
    clusterCommunicator.unicast(operation, APPLY_BATCH_FLOWS, serializer::encode, master).whenComplete((result, error) -> {
        if (error != null) {
            log.warn("Failed to storeBatch: {} to {}", operation, master, error);
            Set<FlowRule> allFailures = operation.getOperations().stream().map(op -> op.target()).collect(Collectors.toSet());
            notifyDelegate(FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(false, allFailures, deviceId)));
        }
    });
}
Also used : FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) REMOVE_FLOW_ENTRY(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.REMOVE_FLOW_ENTRY) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) FlowRuleService(org.onosproject.net.flow.FlowRuleService) StorageService(org.onosproject.store.service.StorageService) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Executors(java.util.concurrent.Executors) RULE_REMOVED(org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) FlowRuleOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry.FlowRuleOperation) OrderedExecutor(org.onlab.util.OrderedExecutor) DeviceEvent(org.onosproject.net.device.DeviceEvent) DeviceId(org.onosproject.net.DeviceId) REMOTE_APPLY_COMPLETED(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.REMOTE_APPLY_COMPLETED) Dictionary(java.util.Dictionary) Tools(org.onlab.util.Tools) FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) Component(org.osgi.service.component.annotations.Component) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSupport(java.util.stream.StreamSupport) FlowRuleStore(org.onosproject.net.flow.FlowRuleStore) GET_FLOW_ENTRY(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.GET_FLOW_ENTRY) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) DeviceListener(org.onosproject.net.device.DeviceListener) FLOW_TABLE_BACKUP(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.FLOW_TABLE_BACKUP) OsgiPropertyConstants(org.onosproject.store.OsgiPropertyConstants) APPLY_BATCH_FLOWS(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.APPLY_BATCH_FLOWS) ExecutionException(java.util.concurrent.ExecutionException) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) FlowRuleBatchEvent(org.onosproject.net.flow.oldbatch.FlowRuleBatchEvent) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) PersistenceService(org.onosproject.persistence.PersistenceService) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) TimeoutException(java.util.concurrent.TimeoutException) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) Type(org.onosproject.net.flow.FlowRuleEvent.Type) PURGE_FLOW_RULES(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.PURGE_FLOW_RULES) GET_DEVICE_FLOW_COUNT(org.onosproject.store.flow.impl.ECFlowRuleStoreMessageSubjects.GET_DEVICE_FLOW_COUNT) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest) AsyncConsistentMap(org.onosproject.store.service.AsyncConsistentMap) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) FlowRuleStoreDelegate(org.onosproject.net.flow.FlowRuleStoreDelegate) Tools.get(org.onlab.util.Tools.get) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) ReplicaInfoService(org.onosproject.store.flow.ReplicaInfoService) IdGenerator(org.onosproject.core.IdGenerator) Math.min(java.lang.Math.min) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Math.max(java.lang.Math.max) ClusterService(org.onosproject.cluster.ClusterService) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) ReplicaInfoEventListener(org.onosproject.store.flow.ReplicaInfoEventListener) Function(java.util.function.Function) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Activate(org.osgi.service.component.annotations.Activate) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) EventuallyConsistentMapListener(org.onosproject.store.service.EventuallyConsistentMapListener) ExecutorService(java.util.concurrent.ExecutorService) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ReplicaInfo(org.onosproject.store.flow.ReplicaInfo) ClusterMessageHandler(org.onosproject.store.cluster.messaging.ClusterMessageHandler) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) ReplicaInfoEvent(org.onosproject.store.flow.ReplicaInfoEvent) Maps(com.google.common.collect.Maps) FlowRuleStoreException(org.onosproject.net.flow.FlowRuleStoreException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ClusterMessage(org.onosproject.store.cluster.messaging.ClusterMessage) TimeUnit(java.util.concurrent.TimeUnit) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)

Aggregations

FlowRuleBatchRequest (org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)7 CompletedBatchOperation (org.onosproject.net.flow.CompletedBatchOperation)6 FlowRuleBatchEntry (org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry)6 DeviceId (org.onosproject.net.DeviceId)4 FlowRule (org.onosproject.net.flow.FlowRule)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 NodeId (org.onosproject.cluster.NodeId)2 MastershipService (org.onosproject.mastership.MastershipService)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 Streams (com.google.common.collect.Streams)1 Math.max (java.lang.Math.max)1 Math.min (java.lang.Math.min)1 Collections (java.util.Collections)1 Dictionary (java.util.Dictionary)1 Iterator (java.util.Iterator)1 List (java.util.List)1