Search in sources :

Example 76 with TrafficTreatment

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

the class ConnectivityIntentCommand method buildTrafficTreatment.

/**
 * Generates a traffic treatment for this intent based on command line
 * arguments presented to the command.
 *
 * @return traffic treatment
 */
protected TrafficTreatment buildTrafficTreatment() {
    final TrafficTreatment.Builder treatmentBuilder = builder();
    boolean emptyTreatment = true;
    if (!isNullOrEmpty(setEthSrcString)) {
        treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setEthDstString)) {
        treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setIpSrcString)) {
        treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setIpDstString)) {
        treatmentBuilder.setIpDst(IpAddress.valueOf(setIpDstString));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setVlan)) {
        treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
        emptyTreatment = false;
    }
    if (popVlan) {
        treatmentBuilder.popVlan();
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(pushVlan)) {
        treatmentBuilder.pushVlan();
        treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
        emptyTreatment = false;
    }
    if (!isNullOrEmpty(setQueue)) {
        // OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
        if (setQueue.contains("/")) {
            String[] queueConfig = setQueue.split("/");
            PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
            long queueId = Long.parseLong(queueConfig[1]);
            treatmentBuilder.setQueue(queueId, port);
        } else {
            treatmentBuilder.setQueue(Long.parseLong(setQueue));
        }
        emptyTreatment = false;
    }
    if (emptyTreatment) {
        return DefaultTrafficTreatment.emptyTreatment();
    } else {
        return treatmentBuilder.build();
    }
}
Also used : DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber)

Example 77 with TrafficTreatment

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

the class IntentCycleCommand method generateIntents.

private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) {
    TrafficSelector.Builder selectorBldr = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4);
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    List<Intent> intents = Lists.newArrayList();
    for (long i = 0; i < count; i++) {
        TrafficSelector selector = selectorBldr.matchEthSrc(MacAddress.valueOf(i + keyOffset)).build();
        intents.add(PointToPointIntent.builder().appId(appId()).key(Key.of(i + keyOffset, appId())).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).build());
    }
    return intents;
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Intent(org.onosproject.net.intent.Intent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 78 with TrafficTreatment

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

the class PortWaveLengthCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    if (operation.equals("edit-config") || operation.equals("delete-config")) {
        FlowRuleService flowService = get(FlowRuleService.class);
        DeviceService deviceService = get(DeviceService.class);
        CoreService coreService = get(CoreService.class);
        TrafficSelector.Builder trafficSelectorBuilder = DefaultTrafficSelector.builder();
        TrafficTreatment.Builder trafficTreatmentBuilder = DefaultTrafficTreatment.builder();
        FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
        ConnectPoint inCp, outCp = null;
        Device inDevice, outDevice = null;
        inCp = ConnectPoint.deviceConnectPoint(inConnectPointString);
        inDevice = deviceService.getDevice(inCp.deviceId());
        if (outConnectPointString != null) {
            outCp = ConnectPoint.deviceConnectPoint(outConnectPointString);
            outDevice = deviceService.getDevice(outCp.deviceId());
        }
        if (inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
            // Parsing the ochSignal
            OchSignal ochSignal;
            if (parameter.contains("/")) {
                ochSignal = createOchSignal();
            } else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
                ochSignal = createOchSignalFromWavelength(deviceService, inCp);
            } else {
                print("[ERROR] signal or wavelength %s are in uncorrect format");
                return;
            }
            if (ochSignal == null) {
                print("[ERROR] problem while creating OchSignal");
                return;
            }
            // Traffic selector
            TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).build();
            // Traffic treatment including ochSignal
            TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(inCp).number())).build();
            int priority = 100;
            ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
            // Flow rule using selector and treatment
            FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
            // Print output on CLI
            if (operation.equals("edit-config")) {
                flowService.applyFlowRules(addFlow);
                print("[INFO] Setting ochSignal on TERMINAL_DEVICE %s", ochSignal);
                print("--- device: %s", inDevice.id());
                print("--- port: %s", inCp.port());
                print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
            } else {
                // This is delete-config
                flowService.removeFlowRules(addFlow);
                print("[INFO] Deleting ochSignal on TERMINAL_DEVICE %s", ochSignal);
                print("--- device: %s", inDevice.id());
                print("--- port: %s", inCp.port());
                print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
            }
        }
        if (inDevice.type().equals(Device.Type.ROADM)) {
            if (outConnectPointString == null) {
                print("[ERROR] output port is required for ROADM devices");
                return;
            }
            if (!inDevice.equals(outDevice)) {
                print("[ERROR] input and output ports must be on the same device");
                return;
            }
            // Parsing the ochSignal
            OchSignal ochSignal;
            if (parameter.contains("/")) {
                ochSignal = createOchSignal();
            } else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
                ochSignal = createOchSignalFromWavelength(deviceService, inCp);
            } else {
                print("[ERROR] signal or wavelength %s are in uncorrect format");
                return;
            }
            if (ochSignal == null) {
                print("[ERROR] problem while creating OchSignal");
                return;
            }
            // Traffic selector
            TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).build();
            // Traffic treatment
            TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(outCp).number())).build();
            int priority = 100;
            ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
            // Flow rule using selector and treatment
            FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
            // Print output on CLI
            if (operation.equals("edit-config")) {
                flowService.applyFlowRules(addFlow);
                print("[INFO] Setting ochSignal on ROADM %s", ochSignal);
                print("--- device: %s", inDevice.id());
                print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
                print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
                print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
            } else {
                // This is delete-config
                flowService.removeFlowRules(addFlow);
                print("[INFO] Deleting ochSignal on ROADM %s", ochSignal);
                print("--- device: %s", inDevice.id());
                print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
                print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
                print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
            }
        }
        if (!inDevice.type().equals(Device.Type.ROADM) && !inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
            print("[ERROR] wrong device type: %s", inDevice.type());
        }
    } else {
        print("[ERROR] operation %s is not yet supported", operation);
    }
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) OchSignal(org.onosproject.net.OchSignal) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) 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)

Example 79 with TrafficTreatment

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

the class OpenstackTroubleshootManager method setNorthSouthIcmpReplyRule.

/**
 * Installs/uninstalls a flow rule to match north-south ICMP reply packets,
 * direct all ICMP reply packets to the controller.
 *
 * @param port      instance port
 * @param gw        gateway node
 * @param install   installation flag
 */
private void setNorthSouthIcmpReplyRule(InstancePort port, OpenstackNode gw, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(port.ipAddress(), PREFIX_LENGTH)).matchIPProtocol(IPv4.PROTOCOL_ICMP).matchIcmpType(ICMP.TYPE_ECHO_REPLY).matchTunnelId(getSegId(osNetworkService, port)).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setIpSrc(instancePortService.floatingIp(port.portId())).setEthSrc(port.macAddress()).setEthDst(DEFAULT_EXTERNAL_ROUTER_MAC).punt().build();
    osFlowRuleService.setRule(appId, gw.intgBridge(), selector, treatment, PRIORITY_ICMP_PROBE_RULE, GW_COMMON_TABLE, install);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 80 with TrafficTreatment

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

the class SelectGroupHandler method generateBucketsForSelectGroup.

private List<GroupBucket> generateBucketsForSelectGroup(DeviceId deviceId, List<GatewayNode> nodeList) {
    List<GroupBucket> bucketList = Lists.newArrayList();
    nodeList.forEach(node -> {
        TrafficTreatment tBuilder = DefaultTrafficTreatment.builder().extension(buildNiciraExtenstion(deviceId, node.getDataIpAddress()), deviceId).setOutput(getTunnelPort(deviceId)).build();
        bucketList.add(createSelectGroupBucket(tBuilder));
    });
    return bucketList;
}
Also used : GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket.createSelectGroupBucket(org.onosproject.net.group.DefaultGroupBucket.createSelectGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

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