use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry 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.oldbatch.FlowRuleBatchEntry 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.oldbatch.FlowRuleBatchEntry 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.oldbatch.FlowRuleBatchEntry in project onos by opennetworkinglab.
the class SimpleVirtualFlowRuleStore method storeBatch.
@Override
public void storeBatch(NetworkId networkId, FlowRuleBatchOperation batchOperation) {
List<FlowRuleBatchEntry> toAdd = new ArrayList<>();
List<FlowRuleBatchEntry> toRemove = new ArrayList<>();
for (FlowRuleBatchEntry entry : batchOperation.getOperations()) {
final FlowRule flowRule = entry.target();
if (entry.operator().equals(FlowRuleBatchEntry.FlowRuleOperation.ADD)) {
if (!getFlowEntries(networkId, flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
storeFlowRule(networkId, flowRule);
toAdd.add(entry);
}
} else if (entry.operator().equals(FlowRuleBatchEntry.FlowRuleOperation.REMOVE)) {
if (getFlowEntries(networkId, flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
deleteFlowRule(networkId, flowRule);
toRemove.add(entry);
}
} else {
throw new UnsupportedOperationException("Unsupported operation type");
}
}
if (toAdd.isEmpty() && toRemove.isEmpty()) {
notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(batchOperation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), batchOperation.deviceId())));
return;
}
SettableFuture<CompletedBatchOperation> r = SettableFuture.create();
final long futureId = localBatchIdGen.incrementAndGet();
pendingFutures.put(futureId, r);
toAdd.addAll(toRemove);
notifyDelegate(networkId, FlowRuleBatchEvent.requested(new FlowRuleBatchRequest(batchOperation.id(), Sets.newHashSet(toAdd)), batchOperation.deviceId()));
}
Aggregations