Search in sources :

Example 1 with FlowRuleOperationsContext

use of org.onosproject.net.flow.FlowRuleOperationsContext 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 2 with FlowRuleOperationsContext

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

the class AddTestFlowsCommand method doExecute.

@Override
protected void doExecute() {
    FlowRuleService flowService = get(FlowRuleService.class);
    DeviceService deviceService = get(DeviceService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.registerApplication("onos.test.flow.installer");
    int flowsPerDevice = Integer.parseInt(flows);
    int num = Integer.parseInt(numOfRuns);
    ArrayList<Long> results = Lists.newArrayList();
    Iterable<Device> devices = deviceService.getDevices();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(RandomUtils.nextInt(MAX_OUT_PORT))).build();
    TrafficSelector.Builder sbuilder;
    FlowRuleOperations.Builder rules = FlowRuleOperations.builder();
    FlowRuleOperations.Builder remove = FlowRuleOperations.builder();
    for (Device d : devices) {
        for (long i = 0; i < flowsPerDevice; i++) {
            sbuilder = DefaultTrafficSelector.builder();
            sbuilder.matchEthSrc(MacAddress.valueOf(RandomUtils.nextInt() * i)).matchEthDst(MacAddress.valueOf((Integer.MAX_VALUE - i) * RandomUtils.nextInt()));
            int randomPriority = RandomUtils.nextInt(FlowRule.MAX_PRIORITY - FlowRule.MIN_PRIORITY + 1) + FlowRule.MIN_PRIORITY;
            FlowRule addRule = DefaultFlowRule.builder().forDevice(d.id()).withSelector(sbuilder.build()).withTreatment(treatment).withPriority(randomPriority).fromApp(appId).makeTemporary(10).build();
            FlowRule removeRule = DefaultFlowRule.builder().forDevice(d.id()).withSelector(sbuilder.build()).withTreatment(treatment).withPriority(randomPriority).fromApp(appId).makeTemporary(10).build();
            rules.add(addRule);
            remove.remove(removeRule);
        }
    }
    // close stages
    rules.newStage();
    remove.newStage();
    for (int i = 0; i < num; i++) {
        printProgress("Run %d:", i);
        latch = new CountDownLatch(2);
        final CountDownLatch addSuccess = new CountDownLatch(1);
        printProgress("..batch add request");
        Stopwatch add = Stopwatch.createStarted();
        flowService.apply(rules.build(new FlowRuleOperationsContext() {

            private final Stopwatch timer = Stopwatch.createStarted();

            @Override
            public void onSuccess(FlowRuleOperations ops) {
                timer.stop();
                printProgress("..add success");
                results.add(timer.elapsed(TimeUnit.MILLISECONDS));
                if (results.size() == num) {
                    if (outputJson()) {
                        print("%s", json(new ObjectMapper(), true, results));
                    } else {
                        printTime(true, results);
                    }
                }
                latch.countDown();
                addSuccess.countDown();
            }
        }));
        try {
            addSuccess.await();
            // wait until all flows reaches ADDED state
            while (!Streams.stream(flowService.getFlowEntriesById(appId)).allMatch(fr -> fr.state() == FlowEntryState.ADDED)) {
                Thread.sleep(100);
            }
            add.stop();
            printProgress("..completed %d ± 100 ms", add.elapsed(TimeUnit.MILLISECONDS));
        } catch (InterruptedException e1) {
            printProgress("Interrupted");
            Thread.currentThread().interrupt();
        }
        printProgress("..cleaning up");
        flowService.apply(remove.build(new FlowRuleOperationsContext() {

            @Override
            public void onSuccess(FlowRuleOperations ops) {
                latch.countDown();
            }
        }));
        try {
            latch.await();
            while (!Iterables.isEmpty(flowService.getFlowEntriesById(appId))) {
                Thread.sleep(500);
            }
        } catch (InterruptedException e) {
            printProgress("Interrupted.");
            Thread.currentThread().interrupt();
        }
    }
    if (outputJson()) {
        print("%s", json(new ObjectMapper(), true, results));
    } else {
        printTime(true, results);
    }
}
Also used : FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) Iterables(com.google.common.collect.Iterables) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) Stopwatch(com.google.common.base.Stopwatch) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Command(org.apache.karaf.shell.api.action.Command) RandomUtils(org.apache.commons.lang.math.RandomUtils) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Lists(com.google.common.collect.Lists) ApplicationId(org.onosproject.core.ApplicationId) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Device(org.onosproject.net.Device) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Argument(org.apache.karaf.shell.api.action.Argument) Streams(com.google.common.collect.Streams) TimeUnit(java.util.concurrent.TimeUnit) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) FlowRule(org.onosproject.net.flow.FlowRule) Service(org.apache.karaf.shell.api.action.lifecycle.Service) MacAddress(org.onlab.packet.MacAddress) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) Stopwatch(com.google.common.base.Stopwatch) CoreService(org.onosproject.core.CoreService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) CountDownLatch(java.util.concurrent.CountDownLatch) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with FlowRuleOperationsContext

use of org.onosproject.net.flow.FlowRuleOperationsContext 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 4 with FlowRuleOperationsContext

use of org.onosproject.net.flow.FlowRuleOperationsContext 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 5 with FlowRuleOperationsContext

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

the class SoftRouterPipeline method initializePipeline.

private void initializePipeline() {
    // Drop rules for both tables
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    treatment.drop();
    FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(DROP_PRIORITY).fromApp(driverId).makePermanent().forTable(FILTER_TABLE).build();
    ops = ops.add(rule);
    rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(DROP_PRIORITY).fromApp(driverId).makePermanent().forTable(FIB_TABLE).build();
    ops = ops.add(rule);
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            log.info("Provisioned drop rules in both tables");
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            log.info("Failed to provision drop rules");
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) 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)

Aggregations

DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)22 FlowRule (org.onosproject.net.flow.FlowRule)22 FlowRuleOperations (org.onosproject.net.flow.FlowRuleOperations)22 FlowRuleOperationsContext (org.onosproject.net.flow.FlowRuleOperationsContext)22 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 Criterion (org.onosproject.net.flow.criteria.Criterion)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 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)8 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)7 ArrayList (java.util.ArrayList)4 MacAddress (org.onlab.packet.MacAddress)4 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)4 CacheBuilder (com.google.common.cache.CacheBuilder)3 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3