use of org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation in project onos by opennetworkinglab.
the class FlowRuleBatchOperationTest method testEquals.
/**
* Tests the equals(), hashCode() and toString() methods.
*/
@Test
public void testEquals() {
final FlowRule rule = new IntentTestsMocks.MockFlowRule(1);
final FlowRuleBatchEntry entry1 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule);
final FlowRuleBatchEntry entry2 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.MODIFY, rule);
final FlowRuleBatchEntry entry3 = new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.REMOVE, rule);
final LinkedList<FlowRuleBatchEntry> ops1 = new LinkedList<>();
ops1.add(entry1);
final LinkedList<FlowRuleBatchEntry> ops2 = new LinkedList<>();
ops1.add(entry2);
final LinkedList<FlowRuleBatchEntry> ops3 = new LinkedList<>();
ops3.add(entry3);
final FlowRuleBatchOperation operation1 = new FlowRuleBatchOperation(ops1, null, 0);
final FlowRuleBatchOperation sameAsOperation1 = new FlowRuleBatchOperation(ops1, null, 0);
final FlowRuleBatchOperation operation2 = new FlowRuleBatchOperation(ops2, null, 0);
final FlowRuleBatchOperation operation3 = new FlowRuleBatchOperation(ops3, null, 0);
new EqualsTester().addEqualityGroup(operation1, sameAsOperation1).addEqualityGroup(operation2).addEqualityGroup(operation3).testEquals();
}
use of org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation 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.FlowRuleBatchOperation in project onos by opennetworkinglab.
the class ECFlowRuleStoreTest method testStoreBatch.
/**
* Tests initial state of flowrule.
*/
@Test
public void testStoreBatch() {
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());
}
use of org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation 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.oldbatch.FlowRuleBatchOperation 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