Search in sources :

Example 1 with VirtualFlowRuleBatchOperation

use of org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRuleBatchOperation 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)

Aggregations

NodeId (org.onosproject.cluster.NodeId)1 VirtualDeviceId (org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId)1 VirtualFlowRule (org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRule)1 VirtualFlowRuleBatchOperation (org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRuleBatchOperation)1 MastershipService (org.onosproject.mastership.MastershipService)1 DeviceId (org.onosproject.net.DeviceId)1 CompletedBatchOperation (org.onosproject.net.flow.CompletedBatchOperation)1 FlowRule (org.onosproject.net.flow.FlowRule)1 FlowRuleBatchRequest (org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)1