use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry in project onos by opennetworkinglab.
the class KryoSerializerTest method testFlowRuleBatchEntry.
@Test
public void testFlowRuleBatchEntry() {
final FlowRule rule1 = DefaultFlowRule.builder().forDevice(DID1).withSelector(DefaultTrafficSelector.emptySelector()).withTreatment(DefaultTrafficTreatment.emptyTreatment()).withPriority(0).fromApp(new DefaultApplicationId(1, "1")).makeTemporary(1).build();
final FlowRuleBatchEntry entry1 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
final FlowRuleBatchEntry entry2 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
testSerializedEquals(entry1);
testSerializedEquals(entry2);
}
use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry 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.FlowRuleBatchEntry in project onos by opennetworkinglab.
the class DefaultVirtualFlowRuleProvider method executeBatch.
@Override
public void executeBatch(NetworkId networkId, FlowRuleBatchOperation batch) {
checkNotNull(batch);
for (FlowRuleBatchEntry fop : batch.getOperations()) {
FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
switch(fop.operator()) {
case ADD:
devirtualize(networkId, fop.target()).forEach(builder::add);
break;
case REMOVE:
devirtualize(networkId, fop.target()).forEach(builder::remove);
break;
case MODIFY:
devirtualize(networkId, fop.target()).forEach(builder::modify);
break;
default:
break;
}
flowRuleService.apply(builder.build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
CompletedBatchOperation status = new CompletedBatchOperation(true, Sets.newConcurrentHashSet(), batch.deviceId());
VirtualFlowRuleProviderService providerService = (VirtualFlowRuleProviderService) providerRegistryService.getProviderService(networkId, VirtualFlowRuleProvider.class);
providerService.batchOperationCompleted(batch.id(), status);
}
@Override
public void onError(FlowRuleOperations ops) {
Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), BatchOperationEntry::target));
CompletedBatchOperation status = new CompletedBatchOperation(false, failures, batch.deviceId());
VirtualFlowRuleProviderService providerService = (VirtualFlowRuleProviderService) providerRegistryService.getProviderService(networkId, VirtualFlowRuleProvider.class);
providerService.batchOperationCompleted(batch.id(), status);
}
}));
}
}
use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry 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.FlowRuleBatchEntry in project onos by opennetworkinglab.
the class ECFlowRuleStoreTest method testAddFlow.
/**
* Tests adding a flowrule.
*/
@Test
public void testAddFlow() {
FlowEntry flowEntry = new DefaultFlowEntry(flowRule);
FlowRuleOperation op = new FlowRuleOperation(flowRule, FlowRuleOperation.Type.ADD);
Multimap<DeviceId, FlowRuleBatchEntry> perDeviceBatches = ArrayListMultimap.create();
perDeviceBatches.put(op.rule().deviceId(), new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, op.rule()));
FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId), deviceId, 1);
flowStoreImpl.storeBatch(b);
FlowEntry flowEntry1 = flowStoreImpl.getFlowEntry(flowRule);
assertEquals("PENDING_ADD", flowEntry1.state().toString());
flowStoreImpl.addOrUpdateFlowRule(flowEntry);
assertFlowsOnDevice(deviceId, 1);
FlowEntry flowEntry2 = flowStoreImpl.getFlowEntry(flowRule);
assertEquals("ADDED", flowEntry2.state().toString());
assertThat(flowStoreImpl.getTableStatistics(deviceId), notNullValue());
}
Aggregations