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