Search in sources :

Example 11 with FlowRuleOperations

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

the class SoftRouterPipeline method processFilter.

private void processFilter(FilteringObjective filt, boolean install, ApplicationId applicationId) {
    // This driver only processes filtering criteria defined with switch
    // ports as the key
    PortCriterion p;
    EthCriterion e = null;
    VlanIdCriterion v = null;
    if (!filt.key().equals(Criteria.dummy()) && filt.key().type() == Criterion.Type.IN_PORT) {
        p = (PortCriterion) filt.key();
    } else {
        log.warn("No key defined in filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
        fail(filt, ObjectiveError.UNKNOWN);
        return;
    }
    // convert filtering conditions for switch-intfs into flowrules
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (Criterion c : filt.conditions()) {
        if (c.type() == Criterion.Type.ETH_DST || c.type() == Criterion.Type.ETH_DST_MASKED) {
            e = (EthCriterion) c;
        } else if (c.type() == Criterion.Type.VLAN_VID) {
            v = (VlanIdCriterion) c;
        } else {
            log.error("Unsupported filter {}", c);
            fail(filt, ObjectiveError.UNSUPPORTED);
            return;
        }
    }
    if (v == null || e == null) {
        log.warn("Soft Router Pipeline ETH_DST and/or VLAN_ID not specified");
        fail(filt, ObjectiveError.BADPARAMS);
        return;
    }
    log.debug("Modifying Port/VLAN/MAC filtering rules in filter table: {}/{}/{}", p.port(), v.vlanId(), e.mac());
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    selector.matchInPort(p.port());
    // Multicast MAC
    if (e.mask() != null) {
        selector.matchEthDstMasked(e.mac(), e.mask());
    } else {
        selector.matchEthDst(e.mac());
    }
    selector.matchVlanId(v.vlanId());
    if (!v.vlanId().equals(VlanId.NONE)) {
        treatment.popVlan();
    }
    treatment.transition(FIB_TABLE);
    FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(FILTER_TABLE).build();
    ops = install ? ops.add(rule) : ops.remove(rule);
    // apply filtering flow rules
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            log.info("Applied filtering rules");
            pass(filt);
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            log.info("Failed to apply filtering rules");
            fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 12 with FlowRuleOperations

use of org.onosproject.net.flow.FlowRuleOperations 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);
            }
        }));
    }
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) VirtualFlowRuleProvider(org.onosproject.incubator.net.virtual.provider.VirtualFlowRuleProvider) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) VirtualFlowRuleProviderService(org.onosproject.incubator.net.virtual.provider.VirtualFlowRuleProviderService) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext)

Example 13 with FlowRuleOperations

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

the class AbstractCorsaPipeline method processFilter.

private void processFilter(FilteringObjective filt, boolean install, ApplicationId applicationId) {
    // This driver only processes filtering criteria defined with switch
    // ports as the key
    PortCriterion port;
    if (!filt.key().equals(Criteria.dummy()) && filt.key().type() == Criterion.Type.IN_PORT) {
        port = (PortCriterion) filt.key();
    } else {
        log.warn("No key defined in filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
        fail(filt, ObjectiveError.UNKNOWN);
        return;
    }
    // convert filtering conditions for switch-intfs into flowrules
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (Criterion c : filt.conditions()) {
        if (c.type() == Criterion.Type.ETH_DST) {
            EthCriterion eth = (EthCriterion) c;
            FlowRule.Builder rule = processEthFiler(filt, eth, port);
            rule.forDevice(deviceId).fromApp(applicationId);
            ops = install ? ops.add(rule.build()) : ops.remove(rule.build());
        } else if (c.type() == Criterion.Type.VLAN_VID) {
            VlanIdCriterion vlan = (VlanIdCriterion) c;
            FlowRule.Builder rule = processVlanFiler(filt, vlan, port);
            rule.forDevice(deviceId).fromApp(applicationId);
            ops = install ? ops.add(rule.build()) : ops.remove(rule.build());
        } else if (c.type() == Criterion.Type.IPV4_DST) {
            IPCriterion ip = (IPCriterion) c;
            FlowRule.Builder rule = processIpFilter(filt, ip, port);
            rule.forDevice(deviceId).fromApp(applicationId);
            ops = install ? ops.add(rule.build()) : ops.remove(rule.build());
        } else {
            log.warn("Driver does not currently process filtering condition" + " of type: {}", c.type());
            fail(filt, ObjectiveError.UNSUPPORTED);
        }
    }
    // apply filtering flow rules
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            pass(filt);
            log.info("Applied filtering rules");
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
            log.info("Failed to apply filtering rules");
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Builder(org.onosproject.net.flow.FlowRule.Builder) Builder(org.onosproject.net.flow.FlowRule.Builder) CacheBuilder(com.google.common.cache.CacheBuilder) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 14 with FlowRuleOperations

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

the class FabricIntProgrammableTest method testSetUpSpineButCollectorHostNotFound.

/**
 * Test installing report rules on spine but collector host not found.
 */
@Test
public void testSetUpSpineButCollectorHostNotFound() {
    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, hostService);
    expect(driverData.deviceId()).andReturn(SPINE_DEVICE_ID).anyTimes();
    expect(hostService.getHostsByIp(anyObject())).andReturn(Collections.emptySet()).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, hostService, flowRuleService);
    // Verify values.
    assertFalse(intProgrammable.setUpIntConfig(intConfig));
    assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
    assertFlowRuleOperationsEquals(EMPTY_FLOW_RULE_OPS, capturedOpsForSubnet.getValue());
    verify(flowRuleService);
}
Also used : 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 15 with FlowRuleOperations

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

the class FabricIntProgrammableTest method testSetUpSpineButNoCollectorHostLocation.

/**
 * Test installing report rules on spine but cannot find
 * the location of the collector host.
 */
@Test
public void testSetUpSpineButNoCollectorHostLocation() {
    final IntReportConfig intConfig = getIntReportConfig(APP_ID, "/int-report.json");
    final Host collectorHost = new DefaultHost(null, null, null, null, Sets.newHashSet(), Sets.newHashSet(), true);
    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, hostService);
    expect(driverData.deviceId()).andReturn(SPINE_DEVICE_ID).anyTimes();
    expect(hostService.getHostsByIp(COLLECTOR_IP)).andReturn(ImmutableSet.of(collectorHost)).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, hostService, flowRuleService);
    // Verify values.
    assertFalse(intProgrammable.setUpIntConfig(intConfig));
    assertFlowRuleOperationsEquals(expectedOpsForCollector, capturedOpsForCollector.getValue());
    assertFlowRuleOperationsEquals(EMPTY_FLOW_RULE_OPS, capturedOpsForSubnet.getValue());
    verify(flowRuleService);
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) 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