Search in sources :

Example 86 with TrafficSelector

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

the class Dhcp6HandlerImpl method cancelClientDhcpPacket.

private void cancelClientDhcpPacket(Ip6Address serverIp) {
    // Packet comes from relay
    TrafficSelector indirectClientSelector = DefaultTrafficSelector.builder(SERVER_RELAY_SELECTOR).matchIPv6Dst(serverIp.toIpPrefix()).build();
    packetService.cancelPackets(indirectClientSelector, PacketPriority.CONTROL, appId);
    indirectClientSelector = DefaultTrafficSelector.builder(SERVER_RELAY_SELECTOR).matchIPv6Dst(Ip6Address.ALL_DHCP_RELAY_AGENTS_AND_SERVERS.toIpPrefix()).build();
    packetService.cancelPackets(indirectClientSelector, PacketPriority.CONTROL, appId);
    indirectClientSelector = DefaultTrafficSelector.builder(SERVER_RELAY_SELECTOR).matchIPv6Dst(Ip6Address.ALL_DHCP_SERVERS.toIpPrefix()).build();
    packetService.cancelPackets(indirectClientSelector, PacketPriority.CONTROL, appId);
    // Packet comes from client
    packetService.cancelPackets(CLIENT_SERVER_SELECTOR, PacketPriority.CONTROL, appId);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector)

Example 87 with TrafficSelector

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

the class Dhcp6HandlerImpl method cancelServerDhcpPacket.

private void cancelServerDhcpPacket(Ip6Address serverIp) {
    TrafficSelector serverSelector = DefaultTrafficSelector.builder(SERVER_RELAY_SELECTOR).matchIPv6Src(serverIp.toIpPrefix()).build();
    packetService.cancelPackets(serverSelector, PacketPriority.CONTROL, appId);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector)

Example 88 with TrafficSelector

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

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

the class OpenstackTroubleshootManager method setVidTagRule.

/**
 * Installs/uninstalls a flow rule to match ingress fake ICMP request packets,
 * and tags VNI/VID, direct the tagged packet to ACL table.
 *
 * @param port      instance port
 * @param install   installation flag
 */
private void setVidTagRule(InstancePort port, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(port.ipAddress(), PREFIX_LENGTH)).build();
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder().setTunnelId(getSegId(osNetworkService, port)).transition(ACL_EGRESS_TABLE);
    osFlowRuleService.setRule(appId, port.deviceId(), selector, tb.build(), PRIORITY_ICMP_PROBE_RULE, VTAG_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 90 with TrafficSelector

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

the class OpenstackTroubleshootManager method checkFlowRule.

/**
 * Checks whether flow rules with the given IP and criterion are added or not.
 *
 * @param ip        IP address
 * @param ipType    IP criterion type (IPV4_DST or IPV4_SRC)
 * @return true if the flow rule is added, false otherwise
 */
private boolean checkFlowRule(String ip, Criterion.Type ipType) {
    for (FlowEntry entry : flowRuleService.getFlowEntriesById(appId)) {
        TrafficSelector selector = entry.selector();
        IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(ipType);
        if (ipCriterion != null && ip.equals(ipCriterion.ip().address().toString()) && entry.state() == ADDED) {
            return true;
        }
    }
    return false;
}
Also used : IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowEntry(org.onosproject.net.flow.FlowEntry)

Aggregations

TrafficSelector (org.onosproject.net.flow.TrafficSelector)396 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)354 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)249 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)235 FlowRule (org.onosproject.net.flow.FlowRule)94 Test (org.junit.Test)85 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)84 PiAction (org.onosproject.net.pi.runtime.PiAction)54 ConnectPoint (org.onosproject.net.ConnectPoint)51 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)48 DeviceId (org.onosproject.net.DeviceId)43 PortNumber (org.onosproject.net.PortNumber)43 List (java.util.List)42 NextObjective (org.onosproject.net.flowobjective.NextObjective)41 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)39 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)38 Instruction (org.onosproject.net.flow.instructions.Instruction)37 Criterion (org.onosproject.net.flow.criteria.Criterion)36 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)36 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)35