use of org.onosproject.net.flow.FlowRuleOperations in project fabric-tna by stratum.
the class FabricIntProgrammableTest method testSetupIntConfigWithOldEntry.
/**
* Test "setUpIntConfig" function of IntProgrammable, but there is an old
* flow rule in the store for collector.
*/
@Test
public void testSetupIntConfigWithOldEntry() {
final List<FlowEntry> existsEntries = ImmutableList.of(buildFlowEntry(buildCollectorWatchlistRule(LEAF_DEVICE_ID)));
final FlowRuleOperations expectedOpsForCollector = FlowRuleOperations.builder().remove(buildCollectorWatchlistRule(LEAF_DEVICE_ID)).newStage().add(buildCollectorWatchlistRule(LEAF_DEVICE_ID)).build();
final IntReportConfig intConfig = getIntReportConfig(APP_ID, "/int-report.json");
final Capture<FlowRuleOperations> capturedOpsForCollector = newCapture();
final Capture<FlowRuleOperations> capturedOpsForSubnet = newCapture();
final Capture<FlowRuleOperations> capturedOpsForQueueThresholds = newCapture();
final Capture<FlowRule> capturedReportRules = newCapture(CaptureType.ALL);
final List<FlowRule> expectRules = Lists.newArrayList();
expectRules.addAll(queueReportFlows(LEAF_DEVICE_ID, DEFAULT_QUEUE_REPORT_TRIGGER_LATENCY_THRESHOLD, DEFAULT_QUEUE_REPORT_RESET_LATENCY_THRESHOLD));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_INT_INGRESS_DROP, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_FLOW, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_DEFLECTED, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_QUEUE, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, (short) (INT_REPORT_TYPE_QUEUE | INT_REPORT_TYPE_FLOW), MIRROR_TYPE_INT_REPORT));
expectRules.add(buildFilterConfigFlow(LEAF_DEVICE_ID));
// Expected steps of method calls, captures, and results.
reset(flowRuleService);
expect(flowRuleService.getFlowEntriesById(APP_ID)).andReturn(existsEntries).times(3);
flowRuleService.apply(capture(capturedOpsForCollector));
flowRuleService.apply(capture(capturedOpsForSubnet));
flowRuleService.apply(capture(capturedOpsForQueueThresholds));
flowRuleService.applyFlowRules(capture(capturedReportRules));
expectLastCall().times(expectRules.size());
replay(flowRuleService);
// Verify values.
assertTrue(intProgrammable.setUpIntConfig(intConfig));
assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
assertFlowRuleOperationsEquals(EMPTY_FLOW_RULE_OPS, capturedOpsForSubnet.getValue());
for (int i = 0; i < expectRules.size(); i++) {
FlowRule expectRule = expectRules.get(i);
FlowRule actualRule = capturedReportRules.getValues().get(i);
assertTrue(expectRule.exactMatch(actualRule));
}
verify(flowRuleService);
}
use of org.onosproject.net.flow.FlowRuleOperations in project fabric-tna by stratum.
the class FabricIntProgrammableTest method testSetupIntConfigOnSpine.
/**
* Test "setUpIntConfig" function of IntProgrammable for spine device.
* We should expected to get a table entry for report table
* with do_report_encap_mpls action.
*/
@Test
public void testSetupIntConfigOnSpine() {
final IntReportConfig intConfig = getIntReportConfig(APP_ID, "/int-report.json");
final FlowRuleOperations expectedOpsForCollector = FlowRuleOperations.builder().add(buildCollectorWatchlistRule(SPINE_DEVICE_ID)).build();
final Capture<FlowRuleOperations> capturedOpsForCollector = newCapture();
final Capture<FlowRuleOperations> capturedOpsForSubnet = newCapture();
final Capture<FlowRuleOperations> capturedOpsForQueueThresholds = newCapture();
final Capture<FlowRule> capturedReportRules = newCapture(CaptureType.ALL);
final List<FlowRule> expectRules = Lists.newArrayList();
expectRules.addAll(queueReportFlows(SPINE_DEVICE_ID, DEFAULT_QUEUE_REPORT_TRIGGER_LATENCY_THRESHOLD, DEFAULT_QUEUE_REPORT_RESET_LATENCY_THRESHOLD));
expectRules.add(buildReportTableRule(SPINE_DEVICE_ID, true, BMD_TYPE_INT_INGRESS_DROP, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(SPINE_DEVICE_ID, true, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(SPINE_DEVICE_ID, true, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_FLOW, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(SPINE_DEVICE_ID, true, BMD_TYPE_DEFLECTED, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(SPINE_DEVICE_ID, true, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_QUEUE, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(SPINE_DEVICE_ID, true, BMD_TYPE_EGRESS_MIRROR, (short) (INT_REPORT_TYPE_QUEUE | INT_REPORT_TYPE_FLOW), MIRROR_TYPE_INT_REPORT));
expectRules.add(buildFilterConfigFlow(SPINE_DEVICE_ID));
// Expected steps of method calls, captures, and results.
reset(flowRuleService, driverData);
expect(driverData.deviceId()).andReturn(SPINE_DEVICE_ID).anyTimes();
expect(flowRuleService.getFlowEntriesById(APP_ID)).andReturn(ImmutableList.of()).times(3);
flowRuleService.apply(capture(capturedOpsForCollector));
flowRuleService.apply(capture(capturedOpsForSubnet));
flowRuleService.apply(capture(capturedOpsForQueueThresholds));
flowRuleService.applyFlowRules(capture(capturedReportRules));
expectLastCall().times(expectRules.size());
replay(flowRuleService, driverData);
// Verify values.
assertTrue(intProgrammable.setUpIntConfig(intConfig));
assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
assertFlowRuleOperationsEquals(EMPTY_FLOW_RULE_OPS, capturedOpsForSubnet.getValue());
for (int i = 0; i < expectRules.size(); i++) {
FlowRule expectRule = expectRules.get(i);
FlowRule actualRule = capturedReportRules.getValues().get(i);
assertTrue(expectRule.exactMatch(actualRule));
}
verify(flowRuleService);
}
use of org.onosproject.net.flow.FlowRuleOperations in project fabric-tna by stratum.
the class FabricIntProgrammableTest method testSetupIntConfigWithWatchedSubnet.
/**
* Test "setUpIntConfig" function of IntProgrammable and the config contains
* subnets to be watched.
* And there exists some entries in the watchlist table.
*/
@Test
public void testSetupIntConfigWithWatchedSubnet() {
final List<FlowEntry> existsEntries = ImmutableList.of(buildFlowEntry(buildWatchlistRule(SUBNET_1, Criterion.Type.IPV4_SRC)), buildFlowEntry(buildWatchlistRule(SUBNET_1, Criterion.Type.IPV4_DST)));
final FlowRuleOperations expectedOpsForCollector = FlowRuleOperations.builder().add(buildCollectorWatchlistRule(LEAF_DEVICE_ID)).build();
final FlowRuleOperations expectedOpsForSubnet = FlowRuleOperations.builder().remove(buildWatchlistRule(SUBNET_1, Criterion.Type.IPV4_SRC)).remove(buildWatchlistRule(SUBNET_1, Criterion.Type.IPV4_DST)).newStage().add(buildWatchlistRule(null, Criterion.Type.IPV4_SRC)).add(buildWatchlistRule(SUBNET_1, Criterion.Type.IPV4_SRC)).add(buildWatchlistRule(SUBNET_1, Criterion.Type.IPV4_DST)).add(buildWatchlistRule(SUBNET_2, Criterion.Type.IPV4_SRC)).add(buildWatchlistRule(SUBNET_2, Criterion.Type.IPV4_DST)).build();
final IntReportConfig intConfig = getIntReportConfig(APP_ID, "/int-report-with-subnets.json");
final Capture<FlowRuleOperations> capturedOpsForCollector = newCapture();
final Capture<FlowRuleOperations> capturedOpsForSubnet = newCapture();
final Capture<FlowRuleOperations> capturedOpsForQueueThresholds = newCapture();
final Capture<FlowRule> capturedReportRules = newCapture(CaptureType.ALL);
final List<FlowRule> expectRules = Lists.newArrayList();
expectRules.addAll(queueReportFlows(LEAF_DEVICE_ID, DEFAULT_QUEUE_REPORT_TRIGGER_LATENCY_THRESHOLD, DEFAULT_QUEUE_REPORT_RESET_LATENCY_THRESHOLD));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_INT_INGRESS_DROP, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_FLOW, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_DEFLECTED, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_QUEUE, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, (short) (INT_REPORT_TYPE_QUEUE | INT_REPORT_TYPE_FLOW), MIRROR_TYPE_INT_REPORT));
expectRules.add(buildFilterConfigFlow(LEAF_DEVICE_ID));
// Expected steps of method calls, captures, and results.
reset(flowRuleService);
expect(flowRuleService.getFlowEntriesById(APP_ID)).andReturn(existsEntries).times(3);
flowRuleService.apply(capture(capturedOpsForCollector));
flowRuleService.apply(capture(capturedOpsForSubnet));
flowRuleService.apply(capture(capturedOpsForQueueThresholds));
flowRuleService.applyFlowRules(capture(capturedReportRules));
expectLastCall().times(expectRules.size());
replay(flowRuleService);
// Verify values.
assertTrue(intProgrammable.setUpIntConfig(intConfig));
assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
assertFlowRuleOperationsEquals(expectedOpsForSubnet, capturedOpsForSubnet.getValue());
for (int i = 0; i < expectRules.size(); i++) {
FlowRule expectRule = expectRules.get(i);
FlowRule actualRule = capturedReportRules.getValues().get(i);
assertTrue(expectRule.exactMatch(actualRule));
}
verify(flowRuleService);
}
use of org.onosproject.net.flow.FlowRuleOperations in project fabric-tna by stratum.
the class FabricIntProgrammableTest method testSetupIntConfigWithNoWatchedSubnet.
/**
* Test "setUpIntConfig" function of IntProgrammable and the config does not contain
* subnets to be watched.
*/
@Test
public void testSetupIntConfigWithNoWatchedSubnet() {
final IntReportConfig intConfig = getIntReportConfig(APP_ID, "/int-report.json");
final FlowRuleOperations expectedOpsForCollector = FlowRuleOperations.builder().add(buildCollectorWatchlistRule(LEAF_DEVICE_ID)).build();
final Capture<FlowRuleOperations> capturedOpsForCollector = newCapture();
final Capture<FlowRuleOperations> capturedOpsForSubnet = newCapture();
final Capture<FlowRuleOperations> capturedOpsForQueueThresholds = newCapture();
final Capture<FlowRule> capturedReportRules = newCapture(CaptureType.ALL);
final List<FlowRule> expectRules = Lists.newArrayList();
expectRules.addAll(queueReportFlows(LEAF_DEVICE_ID, DEFAULT_QUEUE_REPORT_TRIGGER_LATENCY_THRESHOLD, DEFAULT_QUEUE_REPORT_RESET_LATENCY_THRESHOLD));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_INT_INGRESS_DROP, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_FLOW, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_DEFLECTED, INT_REPORT_TYPE_DROP, MIRROR_TYPE_INVALID));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, INT_REPORT_TYPE_QUEUE, MIRROR_TYPE_INT_REPORT));
expectRules.add(buildReportTableRule(LEAF_DEVICE_ID, false, BMD_TYPE_EGRESS_MIRROR, (short) (INT_REPORT_TYPE_QUEUE | INT_REPORT_TYPE_FLOW), MIRROR_TYPE_INT_REPORT));
expectRules.add(buildFilterConfigFlow(LEAF_DEVICE_ID));
// Expected steps of method calls, captures, and results.
reset(flowRuleService);
expect(flowRuleService.getFlowEntriesById(APP_ID)).andReturn(ImmutableList.of()).times(3);
flowRuleService.apply(capture(capturedOpsForCollector));
flowRuleService.apply(capture(capturedOpsForSubnet));
flowRuleService.apply(capture(capturedOpsForQueueThresholds));
flowRuleService.applyFlowRules(capture(capturedReportRules));
expectLastCall().times(expectRules.size());
replay(flowRuleService);
// Verify values.
assertTrue(intProgrammable.setUpIntConfig(intConfig));
assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
assertFlowRuleOperationsEquals(EMPTY_FLOW_RULE_OPS, capturedOpsForSubnet.getValue());
for (int i = 0; i < expectRules.size(); i++) {
FlowRule expectRule = expectRules.get(i);
FlowRule actualRule = capturedReportRules.getValues().get(i);
assertTrue(expectRule.exactMatch(actualRule));
}
verify(flowRuleService);
}
use of org.onosproject.net.flow.FlowRuleOperations in project fabric-tna by stratum.
the class FabricIntProgrammableTest method testSetUpSpineButNoLeafConfig.
/**
* Test installing report rules on spine but cannot find
* the segment routing config of the leaf.
*/
@Test
public void testSetUpSpineButNoLeafConfig() {
final IntReportConfig intConfig = getIntReportConfig(APP_ID, "/int-report.json");
final Capture<FlowRuleOperations> capturedOpsForCollector = newCapture();
final Capture<FlowRuleOperations> capturedOpsForSubnet = newCapture();
final Capture<FlowRuleOperations> capturedOpsForQueueThresholds = newCapture();
final FlowRuleOperations expectedOpsForCollector = FlowRuleOperations.builder().add(buildCollectorWatchlistRule(SPINE_DEVICE_ID)).build();
// Expected steps of method calls, captures, and results.
reset(driverData, netcfgService);
expect(driverData.deviceId()).andReturn(SPINE_DEVICE_ID).anyTimes();
expect(netcfgService.getConfig(LEAF_DEVICE_ID, SegmentRoutingDeviceConfig.class)).andReturn(null).anyTimes();
expect(netcfgService.getConfig(SPINE_DEVICE_ID, SegmentRoutingDeviceConfig.class)).andReturn(getSrConfig(SPINE_DEVICE_ID, "/sr-spine.json")).anyTimes();
expect(flowRuleService.getFlowEntriesById(APP_ID)).andReturn(ImmutableList.of()).times(3);
flowRuleService.apply(capture(capturedOpsForCollector));
flowRuleService.apply(capture(capturedOpsForSubnet));
flowRuleService.apply(capture(capturedOpsForQueueThresholds));
replay(driverData, flowRuleService, netcfgService);
// Verify values.
assertFalse(intProgrammable.setUpIntConfig(intConfig));
assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
assertFlowRuleOperationsEquals(EMPTY_FLOW_RULE_OPS, capturedOpsForSubnet.getValue());
verify(flowRuleService);
}
Aggregations