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));
}
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()));
}
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()));
}
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)));
}
});
}
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)));
}
});
}
Aggregations