use of org.onosproject.net.flow.CompletedBatchOperation in project onos by opennetworkinglab.
the class OpenFlowRuleProvider method executeBatch.
@Override
public void executeBatch(FlowRuleBatchOperation batch) {
checkNotNull(batch);
Dpid dpid = Dpid.dpid(batch.deviceId().uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
// If switch no longer exists, simply return.
if (sw == null) {
Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), e -> e.target()));
providerService.batchOperationCompleted(batch.id(), new CompletedBatchOperation(false, failures, batch.deviceId()));
return;
}
pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
// Build a batch of flow mods - to reduce the number i/o asked to the SO
Set<OFFlowMod> mods = Sets.newHashSet();
OFFlowMod mod;
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
FlowModBuilder builder = FlowModBuilder.builder(fbe.target(), sw.factory(), Optional.of(batch.id()), Optional.of(driverService));
switch(fbe.operator()) {
case ADD:
mod = builder.buildFlowAdd();
break;
case REMOVE:
mod = builder.buildFlowDel();
break;
case MODIFY:
mod = builder.buildFlowMod();
break;
default:
log.error("Unsupported batch operation {}; skipping flowmod {}", fbe.operator(), fbe);
continue;
}
mods.add(mod);
}
// Build a list to mantain the order
List<OFMessage> modsTosend = Lists.newArrayList(mods);
OFBarrierRequest.Builder builder = sw.factory().buildBarrierRequest().setXid(batch.id());
// Adds finally the barrier request
modsTosend.add(builder.build());
sw.sendMsg(modsTosend);
// Take into account also the barrier request
recordEvents(dpid, (batch.getOperations().size() + 1));
}
use of org.onosproject.net.flow.CompletedBatchOperation 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)));
}
});
}
use of org.onosproject.net.flow.CompletedBatchOperation in project onos by opennetworkinglab.
the class ECFlowRuleStore method storeBatchInternal.
private void storeBatchInternal(FlowRuleBatchOperation operation) {
final DeviceId did = operation.deviceId();
// final Collection<FlowEntry> ft = flowTable.getFlowEntries(did);
Set<FlowRuleBatchEntry> currentOps = updateStoreInternal(operation);
if (currentOps.isEmpty()) {
batchOperationComplete(FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), did)));
return;
}
notifyDelegate(FlowRuleBatchEvent.requested(new FlowRuleBatchRequest(operation.id(), currentOps), operation.deviceId()));
}
use of org.onosproject.net.flow.CompletedBatchOperation in project onos by opennetworkinglab.
the class NullFlowRuleProvider method executeBatch.
@Override
public void executeBatch(FlowRuleBatchOperation batch) {
// TODO: consider checking mastership
Set<FlowEntry> entries = flowTable.getOrDefault(batch.deviceId(), Sets.newConcurrentHashSet());
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
switch(fbe.operator()) {
case ADD:
entries.add(new DefaultFlowEntry(fbe.target()));
break;
case REMOVE:
entries.remove(new DefaultFlowEntry(fbe.target()));
break;
case MODIFY:
FlowEntry entry = new DefaultFlowEntry(fbe.target());
entries.remove(entry);
entries.add(entry);
break;
default:
log.error("Unknown flow operation: {}", fbe);
}
}
flowTable.put(batch.deviceId(), entries);
CompletedBatchOperation op = new CompletedBatchOperation(true, Collections.emptySet(), batch.deviceId());
providerService.batchOperationCompleted(batch.id(), op);
}
use of org.onosproject.net.flow.CompletedBatchOperation 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)));
}
});
}
Aggregations