Search in sources :

Example 71 with TrafficTreatment

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

the class K8sFlowRuleManager method setAnyRoutingRule.

private void setAnyRoutingRule(IpPrefix srcIpPrefix, MacAddress mac, K8sNetwork k8sNetwork) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(srcIpPrefix).matchIPDst(IpPrefix.valueOf(k8sNetwork.cidr()));
    for (K8sNode node : k8sNodeService.completeNodes()) {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.valueOf(k8sNetwork.segmentId()));
        if (node.hostname().equals(k8sNetwork.name())) {
            if (mac != null) {
                tBuilder.setEthSrc(mac);
            }
            tBuilder.transition(STAT_EGRESS_TABLE);
        } else {
            K8sNode localNode = k8sNodeService.node(k8sNetwork.name());
            tBuilder.setOutput(node.intgToTunPortNum());
            // install flows into tunnel bridge
            PortNumber portNum = tunnelPortNumByNetId(k8sNetwork.networkId(), k8sNetworkService, node);
            TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().extension(buildExtension(deviceService, node.tunBridge(), localNode.dataIp().getIp4Address()), node.tunBridge()).setTunnelId(Long.valueOf(k8sNetwork.segmentId())).setOutput(portNum).build();
            FlowRule remoteFlowRule = DefaultFlowRule.builder().forDevice(node.tunBridge()).withSelector(sBuilder.build()).withTreatment(treatmentToRemote).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(TUN_ENTRY_TABLE).build();
            applyRule(remoteFlowRule, true);
        }
        FlowRule flowRule = DefaultFlowRule.builder().forDevice(node.intgBridge()).withSelector(sBuilder.build()).withTreatment(tBuilder.build()).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(ROUTING_TABLE).build();
        applyRule(flowRule, true);
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) 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) PortNumber(org.onosproject.net.PortNumber)

Example 72 with TrafficTreatment

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

the class SdnIpReactiveRouting method forwardPacketToDst.

/**
 * Emits the specified packet onto the network.
 *
 * @param context      the packet context
 * @param connectPoint the connect point where the packet should be
 *                     sent out
 */
private void forwardPacketToDst(PacketContext context, ConnectPoint connectPoint) {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
    OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, context.inPacket().unparsed());
    packetService.emit(packet);
    log.trace("sending packet: {}", packet);
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 73 with TrafficTreatment

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

the class RoadmManager method createConnection.

@Override
public FlowId createConnection(DeviceId deviceId, int priority, boolean isPermanent, int timeout, PortNumber inPort, PortNumber outPort, OchSignal ochSignal) {
    checkNotNull(deviceId);
    checkNotNull(inPort);
    checkNotNull(outPort);
    // Creation of selector.
    TrafficSelector selector = DefaultTrafficSelector.builder().add(Criteria.matchInPort(inPort)).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).build();
    // Creation of treatment
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(outPort)).build();
    FlowRule.Builder flowBuilder = DefaultFlowRule.builder().forDevice(deviceId).fromApp(appId).withPriority(priority).withSelector(selector).withTreatment(treatment);
    if (isPermanent) {
        flowBuilder.makePermanent();
    } else {
        flowBuilder.makeTemporary(timeout);
    }
    FlowRule flowRule = flowBuilder.build();
    flowRuleService.applyFlowRules(flowRule);
    log.info("Created connection from input port {} to output port {}", inPort.toLong(), outPort.toLong());
    return flowRule.id();
}
Also used : 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)

Example 74 with TrafficTreatment

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

the class AddMultiPointToSinglePointIntentCommand method doExecute.

@Override
protected void doExecute() {
    IntentService service = get(IntentService.class);
    if (deviceStrings.length < 2) {
        return;
    }
    String egressDeviceString = deviceStrings[deviceStrings.length - 1];
    FilteredConnectPoint egress = new FilteredConnectPoint(ConnectPoint.deviceConnectPoint(egressDeviceString));
    Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
    for (int index = 0; index < deviceStrings.length - 1; index++) {
        String ingressDeviceString = deviceStrings[index];
        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
        ingressPoints.add(new FilteredConnectPoint(ingress));
    }
    TrafficSelector selector = buildTrafficSelector();
    TrafficTreatment treatment = buildTrafficTreatment();
    List<Constraint> constraints = buildConstraints();
    Intent intent = MultiPointToSinglePointIntent.builder().appId(appId()).key(key()).selector(selector).treatment(treatment).filteredIngressPoints(ingressPoints).filteredEgressPoint(egress).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
    service.submit(intent);
    print("Multipoint to single point intent submitted:\n%s", intent.toString());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) Constraint(org.onosproject.net.intent.Constraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Constraint(org.onosproject.net.intent.Constraint) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

Example 75 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment 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)

Aggregations

TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)395 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)369 TrafficSelector (org.onosproject.net.flow.TrafficSelector)257 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)236 FlowRule (org.onosproject.net.flow.FlowRule)93 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)86 PiAction (org.onosproject.net.pi.runtime.PiAction)79 Test (org.junit.Test)78 PortNumber (org.onosproject.net.PortNumber)70 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)56 Instruction (org.onosproject.net.flow.instructions.Instruction)52 DeviceId (org.onosproject.net.DeviceId)46 NextObjective (org.onosproject.net.flowobjective.NextObjective)45 ConnectPoint (org.onosproject.net.ConnectPoint)44 List (java.util.List)43 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)43 Ethernet (org.onlab.packet.Ethernet)40 Criterion (org.onosproject.net.flow.criteria.Criterion)39 GroupBucket (org.onosproject.net.group.GroupBucket)39 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)37