Search in sources :

Example 31 with TrafficTreatment

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

the class LinkCollectionIntentCompiler method compactActions.

/**
 * This method tries to optimize the chain of actions.
 *
 * @param oldTreatment the list of instructions to optimize
 * @return the optimized set of actions
 */
private TrafficTreatment compactActions(TrafficTreatment oldTreatment) {
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    Instruction instruction;
    Instruction newInstruction;
    for (int index = 0; index < oldTreatment.allInstructions().size(); index++) {
        instruction = oldTreatment.allInstructions().get(index);
        /*
             * if the action is not optimizable. We simply add
             * to the builder.
             */
        if (checkInstruction(instruction)) {
            treatmentBuilder.add(instruction);
            continue;
        }
        /*
             * We try to run an optimization;
             */
        newInstruction = optimizeInstruction(index, instruction, oldTreatment.allInstructions());
        if (!newInstruction.type().equals(NOACTION)) {
            treatmentBuilder.add(newInstruction);
        }
    }
    return treatmentBuilder.build();
}
Also used : DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint)

Example 32 with TrafficTreatment

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

the class FlowObjectiveCompositionUtil method composeSequential.

public static ForwardingObjective composeSequential(ForwardingObjective fo1, ForwardingObjective fo2, int priorityMultiplier) {
    TrafficSelector revertTrafficSelector = revertTreatmentSelector(fo1.treatment(), fo2.selector());
    if (revertTrafficSelector == null) {
        return null;
    }
    TrafficSelector trafficSelector = intersectTrafficSelector(fo1.selector(), revertTrafficSelector);
    if (trafficSelector == null) {
        return null;
    }
    TrafficTreatment trafficTreatment = unionTrafficTreatment(fo1.treatment(), fo2.treatment());
    return DefaultForwardingObjective.builder().fromApp(fo1.appId()).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).withPriority(fo1.priority() * priorityMultiplier + fo2.priority()).withSelector(trafficSelector).withTreatment(trafficTreatment).add();
}
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 33 with TrafficTreatment

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

the class OplinkOpticalPowerConfig method setChannelTargetPower.

private boolean setChannelTargetPower(PortNumber port, OchSignal channel, long power) {
    log.debug("Set port{} channel{} attenuation.", port, channel.channelSpacing());
    FlowRuleService service = handler().get(FlowRuleService.class);
    Iterable<FlowEntry> entries = service.getFlowEntries(data().deviceId());
    for (FlowEntry entry : entries) {
        OplinkCrossConnect crossConnect = OplinkOpticalUtility.fromFlowRule(this, entry);
        // The channel port might be input port or output port.
        if ((port.equals(crossConnect.getInPort()) || port.equals(crossConnect.getOutPort())) && channel.spacingMultiplier() == crossConnect.getChannel()) {
            log.debug("Flow is found, modify the flow with attenuation.");
            // Modify attenuation in treatment
            TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(crossConnect.getOutPort()).extension(new OplinkAttenuation((int) power), data().deviceId()).build();
            // Apply the new flow rule
            service.applyFlowRules(DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(entry.selector()).withTreatment(treatment).withPriority(entry.priority()).withCookie(entry.id().value()).build());
            return true;
        }
    }
    return false;
}
Also used : OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 34 with TrafficTreatment

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

the class OplinkOpticalUtility method fromFlowRule.

/**
 * Transforms a flow FlowRule object to an OplinkCrossConnect object.
 * @param behaviour the parent driver handler
 * @param rule FlowRule object
 * @return cross connect object
 */
public static OplinkCrossConnect fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
    // TrafficSelector
    Set<Criterion> criterions = rule.selector().criteria();
    int channel = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
    PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
    // TrafficTreatment
    List<Instruction> instructions = rule.treatment().immediate();
    PortNumber outPort = instructions.stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
    int attenuation = instructions.stream().filter(c -> c instanceof Instructions.ExtensionInstructionWrapper).map(c -> ((Instructions.ExtensionInstructionWrapper) c).extensionInstruction()).filter(c -> c instanceof OplinkAttenuation).map(c -> ((OplinkAttenuation) c).getAttenuation()).findAny().orElse(DEFAULT_ATT);
    return new OplinkCrossConnect(inPort, outPort, channel, attenuation);
}
Also used : GridType(org.onosproject.net.GridType) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HandlerBehaviour(org.onosproject.net.driver.HandlerBehaviour) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) Frequency(org.onlab.util.Frequency) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) Instructions(org.onosproject.net.flow.instructions.Instructions) Instruction(org.onosproject.net.flow.instructions.Instruction) Range(com.google.common.collect.Range) Set(java.util.Set) Lambda(org.onosproject.net.Lambda) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) ChannelSpacing(org.onosproject.net.ChannelSpacing) Instructions(org.onosproject.net.flow.instructions.Instructions) OplinkAttenuation(org.onosproject.driver.extensions.OplinkAttenuation) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PortNumber(org.onosproject.net.PortNumber)

Example 35 with TrafficTreatment

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

the class ReactiveForwarding method installRule.

// Install a rule forwarding the packet to the specified port.
private void installRule(PacketContext context, PortNumber portNumber, ReactiveForwardMetrics macMetrics) {
    // 
    // We don't support (yet) buffer IDs in the Flow Service so
    // packet out first.
    // 
    Ethernet inPkt = context.inPacket().parsed();
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    // If PacketOutOnly or ARP packet than forward directly to output port
    if (packetOutOnly || inPkt.getEtherType() == Ethernet.TYPE_ARP) {
        packetOut(context, portNumber, macMetrics);
        return;
    }
    // 
    if (matchDstMacOnly) {
        selectorBuilder.matchEthDst(inPkt.getDestinationMAC());
    } else {
        selectorBuilder.matchInPort(context.inPacket().receivedFrom().port()).matchEthSrc(inPkt.getSourceMAC()).matchEthDst(inPkt.getDestinationMAC());
        // If configured Match Vlan ID
        if (matchVlanId && inPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) {
            selectorBuilder.matchVlanId(VlanId.vlanId(inPkt.getVlanID()));
        }
        // 
        if (matchIpv4Address && inPkt.getEtherType() == Ethernet.TYPE_IPV4) {
            IPv4 ipv4Packet = (IPv4) inPkt.getPayload();
            byte ipv4Protocol = ipv4Packet.getProtocol();
            Ip4Prefix matchIp4SrcPrefix = Ip4Prefix.valueOf(ipv4Packet.getSourceAddress(), Ip4Prefix.MAX_MASK_LENGTH);
            Ip4Prefix matchIp4DstPrefix = Ip4Prefix.valueOf(ipv4Packet.getDestinationAddress(), Ip4Prefix.MAX_MASK_LENGTH);
            selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(matchIp4SrcPrefix).matchIPDst(matchIp4DstPrefix);
            if (matchIpv4Dscp) {
                byte dscp = ipv4Packet.getDscp();
                byte ecn = ipv4Packet.getEcn();
                selectorBuilder.matchIPDscp(dscp).matchIPEcn(ecn);
            }
            if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) {
                TCP tcpPacket = (TCP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())).matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
            }
            if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) {
                UDP udpPacket = (UDP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())).matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
            }
            if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) {
                ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchIcmpType(icmpPacket.getIcmpType()).matchIcmpCode(icmpPacket.getIcmpCode());
            }
        }
        // 
        if (matchIpv6Address && inPkt.getEtherType() == Ethernet.TYPE_IPV6) {
            IPv6 ipv6Packet = (IPv6) inPkt.getPayload();
            byte ipv6NextHeader = ipv6Packet.getNextHeader();
            Ip6Prefix matchIp6SrcPrefix = Ip6Prefix.valueOf(ipv6Packet.getSourceAddress(), Ip6Prefix.MAX_MASK_LENGTH);
            Ip6Prefix matchIp6DstPrefix = Ip6Prefix.valueOf(ipv6Packet.getDestinationAddress(), Ip6Prefix.MAX_MASK_LENGTH);
            selectorBuilder.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Src(matchIp6SrcPrefix).matchIPv6Dst(matchIp6DstPrefix);
            if (matchIpv6FlowLabel) {
                selectorBuilder.matchIPv6FlowLabel(ipv6Packet.getFlowLabel());
            }
            if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) {
                TCP tcpPacket = (TCP) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())).matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
            }
            if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) {
                UDP udpPacket = (UDP) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())).matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
            }
            if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) {
                ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchIcmpv6Type(icmp6Packet.getIcmpType()).matchIcmpv6Code(icmp6Packet.getIcmpCode());
            }
        }
    }
    TrafficTreatment treatment;
    if (inheritFlowTreatment) {
        treatment = context.treatmentBuilder().setOutput(portNumber).build();
    } else {
        treatment = DefaultTrafficTreatment.builder().setOutput(portNumber).build();
    }
    ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder().withSelector(selectorBuilder.build()).withTreatment(treatment).withPriority(flowPriority).withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makeTemporary(flowTimeout).add();
    flowObjectiveService.forward(context.inPacket().receivedFrom().deviceId(), forwardingObjective);
    forwardPacket(macMetrics);
    // 
    if (packetOutOfppTable) {
        packetOut(context, PortNumber.TABLE, macMetrics);
    } else {
        packetOut(context, portNumber, macMetrics);
    }
}
Also used : TCP(org.onlab.packet.TCP) UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Ip6Prefix(org.onlab.packet.Ip6Prefix) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Ip4Prefix(org.onlab.packet.Ip4Prefix) ICMP6(org.onlab.packet.ICMP6) ICMP(org.onlab.packet.ICMP)

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