Search in sources :

Example 31 with FlowRuleOperations

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);
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) IntReportConfig(org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig) TestUtils.getIntReportConfig(org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 32 with FlowRuleOperations

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);
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) IntReportConfig(org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig) TestUtils.getIntReportConfig(org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig) Test(org.junit.Test)

Example 33 with FlowRuleOperations

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);
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) IntReportConfig(org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig) TestUtils.getIntReportConfig(org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 34 with FlowRuleOperations

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);
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) IntReportConfig(org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig) TestUtils.getIntReportConfig(org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig) Test(org.junit.Test)

Example 35 with FlowRuleOperations

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);
}
Also used : SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) IntReportConfig(org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig) TestUtils.getIntReportConfig(org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig) Test(org.junit.Test)

Aggregations

FlowRuleOperations (org.onosproject.net.flow.FlowRuleOperations)35 FlowRule (org.onosproject.net.flow.FlowRule)30 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)27 FlowRuleOperationsContext (org.onosproject.net.flow.FlowRuleOperationsContext)22 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)11 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 Criterion (org.onosproject.net.flow.criteria.Criterion)11 Test (org.junit.Test)10 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)10 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)10 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)10 IntReportConfig (org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig)10 TestUtils.getIntReportConfig (org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig)10 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)8 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)7 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)6 FlowEntry (org.onosproject.net.flow.FlowEntry)6 Set (java.util.Set)5