Search in sources :

Example 16 with FlowRuleOperations

use of org.onosproject.net.flow.FlowRuleOperations in project fabric-tna by stratum.

the class FabricIntProgrammableTest method testWithoutValidSrConfig.

/**
 * Test with no segment routing config.
 */
@Test
public void testWithoutValidSrConfig() {
    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(LEAF_DEVICE_ID)).build();
    // Expected steps of method calls, captures, and results.
    reset(netcfgService, flowRuleService);
    expect(netcfgService.getConfig(LEAF_DEVICE_ID, SegmentRoutingDeviceConfig.class)).andReturn(null).anyTimes();
    expect(flowRuleService.getFlowEntriesById(APP_ID)).andReturn(ImmutableList.of()).times(3);
    flowRuleService.apply(capture(capturedOpsForCollector));
    flowRuleService.apply(capture(capturedOpsForSubnet));
    flowRuleService.apply(capture(capturedOpsForQueueThresholds));
    replay(netcfgService, flowRuleService);
    // Verify values.
    assertFalse(intProgrammable.setUpIntConfig(intConfig));
    assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
    assertFlowRuleOperationsEquals(EMPTY_FLOW_RULE_OPS, capturedOpsForSubnet.getValue());
    verify(netcfgService, 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)

Example 17 with FlowRuleOperations

use of org.onosproject.net.flow.FlowRuleOperations in project fabric-tna by stratum.

the class FabricIntProgrammableTest method testSetUpSpineButInvalidLeafConfig.

/**
 * Test installing report rules on spine but the config
 * of leaf is invalid.
 */
@Test
public void testSetUpSpineButInvalidLeafConfig() {
    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(getSrConfig(SPINE_DEVICE_ID, "/sr-invalid.json")).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)

Example 18 with FlowRuleOperations

use of org.onosproject.net.flow.FlowRuleOperations in project fabric-tna by stratum.

the class FabricIntProgrammableTest method testSetupIntConfigWithQueueReportThreshold.

/**
 * Test "setUpIntConfig" function of IntProgrammable with a config that contains
 * queue report threshold config.
 */
@Test
public void testSetupIntConfigWithQueueReportThreshold() {
    final IntReportConfig intConfig = getIntReportConfig(APP_ID, "/int-report-queue-report-threshold.json");
    final List<FlowRule> expectRules = Lists.newArrayList();
    final Capture<FlowRuleOperations> capturedOpsForCollector = newCapture();
    final Capture<FlowRuleOperations> capturedOpsForSubnet = newCapture();
    final Capture<FlowRuleOperations> capturedOpsForQueueThresholds = newCapture();
    final Capture<FlowRule> capturedReportRules = newCapture(CaptureType.ALL);
    final FlowRuleOperations expectedOpsForCollector = FlowRuleOperations.builder().add(buildCollectorWatchlistRule(LEAF_DEVICE_ID)).build();
    // Queue threshold rules.
    // Queue 0 has some old rules which must be removed before adding the new ones.
    final List<FlowRule> queueThresholdRulesToRemove = queueReportFlows(LEAF_DEVICE_ID, 0, 0, (byte) 0);
    final FlowRuleOperations.Builder opsBuilder = FlowRuleOperations.builder();
    queueThresholdRulesToRemove.forEach(opsBuilder::remove);
    opsBuilder.newStage();
    // Add new entries for all queues.
    for (byte queueId = 0; queueId < MAX_QUEUES; queueId++) {
        // threshold config.
        if (queueId == 0) {
            queueReportFlows(LEAF_DEVICE_ID, 1888, 388, queueId).forEach(opsBuilder::add);
        } else if (queueId == 7) {
            // Queue 7 contains the "triggerNs" config only, the value of "resetNs"
            // will be half of "triggerNs".
            queueReportFlows(LEAF_DEVICE_ID, 500, 250, queueId).forEach(opsBuilder::add);
        } else {
            // The rest of the queues use the default queue latency threshold.
            queueReportFlows(LEAF_DEVICE_ID, DEFAULT_QUEUE_REPORT_TRIGGER_LATENCY_THRESHOLD, DEFAULT_QUEUE_REPORT_RESET_LATENCY_THRESHOLD, queueId).forEach(opsBuilder::add);
        }
    }
    final FlowRuleOperations expectedOpsForQueueThresholds = opsBuilder.build();
    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));
    List<Capture<FlowRule>> captures = Lists.newArrayList();
    for (int i = 0; i < expectRules.size(); i++) {
        Capture<FlowRule> flowRuleCapture = newCapture();
        flowRuleService.applyFlowRules(capture(flowRuleCapture));
        captures.add(flowRuleCapture);
    }
    // Expected steps of method calls, captures, and results.
    reset(flowRuleService);
    final List<FlowEntry> existingFlowEntries = queueThresholdRulesToRemove.stream().map(f -> buildFlowEntry(f)).collect(Collectors.toList());
    expect(flowRuleService.getFlowEntriesById(APP_ID)).andReturn(existingFlowEntries).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());
    assertFlowRuleOperationsEquals(expectedOpsForQueueThresholds, capturedOpsForQueueThresholds.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 : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Arrays(java.util.Arrays) HostLocation(org.onosproject.net.HostLocation) EasyMock.capture(org.easymock.EasyMock.capture) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) IntReportConfig(org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) FlowRuleService(org.onosproject.net.flow.FlowRuleService) EasyMock.reset(org.easymock.EasyMock.reset) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) After(org.junit.After) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) Parameterized(org.junit.runners.Parameterized) TestUtils.getIntReportConfig(org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig) V1MODEL_RECIRC_PORT(org.stratumproject.fabric.tna.Constants.V1MODEL_RECIRC_PORT) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) EasyMock.newCapture(org.easymock.EasyMock.newCapture) FabricUtils.doCareRangeMatch(org.stratumproject.fabric.tna.behaviour.FabricUtils.doCareRangeMatch) Collection(java.util.Collection) Range(com.google.common.collect.Range) Set(java.util.Set) Constants(org.stratumproject.fabric.tna.Constants) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) TestUtils.getSrConfig(org.stratumproject.fabric.tna.utils.TestUtils.getSrConfig) EasyMock.partialMockBuilder(org.easymock.EasyMock.partialMockBuilder) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) IpPrefix(org.onlab.packet.IpPrefix) Host(org.onosproject.net.Host) RunWith(org.junit.runner.RunWith) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) GroupBucket(org.onosproject.net.group.GroupBucket) HostService(org.onosproject.net.host.HostService) DefaultHost(org.onosproject.net.DefaultHost) DriverData(org.onosproject.net.driver.DriverData) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultGroupBucket.createCloneGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createCloneGroupBucket) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) TestUtils(org.onlab.junit.TestUtils) EasyMock.replay(org.easymock.EasyMock.replay) EasyMock.createMock(org.easymock.EasyMock.createMock) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRuleOperation(org.onosproject.net.flow.FlowRuleOperation) Criterion(org.onosproject.net.flow.criteria.Criterion) Before(org.junit.Before) IpAddress(org.onlab.packet.IpAddress) TpPort(org.onlab.packet.TpPort) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Capture(org.easymock.Capture) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EasyMock.anyString(org.easymock.EasyMock.anyString) GroupService(org.onosproject.net.group.GroupService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) V1MODEL_INT_REPORT_MIRROR_ID(org.stratumproject.fabric.tna.Constants.V1MODEL_INT_REPORT_MIRROR_ID) EasyMock.expect(org.easymock.EasyMock.expect) TimeUnit(java.util.concurrent.TimeUnit) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) PiAction(org.onosproject.net.pi.runtime.PiAction) IPv4(org.onlab.packet.IPv4) CaptureType(org.easymock.CaptureType) DriverHandler(org.onosproject.net.driver.DriverHandler) HexString(org.onlab.util.HexString) KRYO(org.stratumproject.fabric.tna.behaviour.FabricUtils.KRYO) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) EasyMock.verify(org.easymock.EasyMock.verify) Collections(java.util.Collections) PiActionId(org.onosproject.net.pi.model.PiActionId) Assert.assertEquals(org.junit.Assert.assertEquals) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) IntReportConfig(org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig) TestUtils.getIntReportConfig(org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig) EasyMock.newCapture(org.easymock.EasyMock.newCapture) Capture(org.easymock.Capture) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 19 with FlowRuleOperations

use of org.onosproject.net.flow.FlowRuleOperations in project fabric-tna by stratum.

the class MockFlowRuleService method apply.

@Override
public void apply(FlowRuleOperations ops) {
    AtomicBoolean thisSuccess = new AtomicBoolean(success);
    ops.stages().forEach(stage -> stage.forEach(flow -> {
        if (errorFlow == flow.rule().id().value()) {
            thisSuccess.set(false);
        } else {
            switch(flow.type()) {
                case ADD:
                case // TODO is this the right behavior for modify?
                MODIFY:
                    ((DefaultFlowEntry) flow.rule()).setState(FlowEntry.FlowEntryState.ADDED);
                    flows.add(flow.rule());
                    break;
                case REMOVE:
                    // Remove and add in REMOVED state
                    flows.remove(flow.rule());
                    ((DefaultFlowEntry) flow.rule()).setState(FlowEntry.FlowEntryState.REMOVED);
                    flows.add(flow.rule());
                    break;
                default:
                    break;
            }
        }
    }));
    if (thisSuccess.get()) {
        ops.callback().onSuccess(ops);
    } else {
        ops.callback().onError(ops);
    }
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) FlowRule(org.onosproject.net.flow.FlowRule) ApplicationId(org.onosproject.core.ApplicationId) FlowEntry(org.onosproject.net.flow.FlowEntry) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FlowRuleServiceAdapter(org.onosproject.net.flow.FlowRuleServiceAdapter) DeviceId(org.onosproject.net.DeviceId) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 20 with FlowRuleOperations

use of org.onosproject.net.flow.FlowRuleOperations in project onos by opennetworkinglab.

the class MockFlowRuleService method apply.

@Override
public void apply(FlowRuleOperations ops) {
    AtomicBoolean thisSuccess = new AtomicBoolean(success);
    ops.stages().forEach(stage -> stage.forEach(flow -> {
        if (errorFlow == flow.rule().id().value()) {
            thisSuccess.set(false);
        } else {
            switch(flow.type()) {
                case ADD:
                case // TODO is this the right behavior for modify?
                MODIFY:
                    flows.add(flow.rule());
                    break;
                case REMOVE:
                    flows.remove(flow.rule());
                    break;
                default:
                    break;
            }
        }
    }));
    if (thisSuccess.get()) {
        ops.callback().onSuccess(ops);
    } else {
        ops.callback().onError(ops);
    }
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) FlowRule(org.onosproject.net.flow.FlowRule) ApplicationId(org.onosproject.core.ApplicationId) FlowEntry(org.onosproject.net.flow.FlowEntry) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FlowRuleServiceAdapter(org.onosproject.net.flow.FlowRuleServiceAdapter) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

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