Search in sources :

Example 91 with Instruction

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

the class PolatisOpticalUtility method fromFlowRule.

/**
 * Transforms a flow FlowRule object to a cross-connect object.
 * @param behaviour the parent driver handler
 * @param rule FlowRule object
 * @return cross connect object
 */
public static CrossConnects fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
    // TrafficSelector
    Set<Criterion> criterions = rule.selector().criteria();
    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);
    DefaultCrossConnects crossConnects = new DefaultCrossConnects();
    DefaultPair p = new DefaultPair();
    p.ingress(new PortFormat(inPort.toLong()));
    p.egress(new PortFormat(outPort.toLong()));
    crossConnects.addToPair(p);
    return crossConnects;
}
Also used : TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) PortFormat(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.PortFormat) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) Instruction(org.onosproject.net.flow.instructions.Instruction) Range(com.google.common.collect.Range) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) Pair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.Pair) Set(java.util.Set) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HandlerBehaviour(org.onosproject.net.driver.HandlerBehaviour) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) List(java.util.List) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) CrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.CrossConnects) DefaultPair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.DefaultPair) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultCrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.DefaultCrossConnects) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultCrossConnects(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.DefaultCrossConnects) PortFormat(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.PortFormat) DefaultPair(org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.DefaultPair) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) PortNumber(org.onosproject.net.PortNumber) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 92 with Instruction

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

the class DefaultNicFlowRule method populate.

/**
 * Parses FlowRule's traffic selector and treatment
 * and keeps relevant information for this NIC rule.
 */
private void populate() {
    this.ethTypeCriterion = (EthTypeCriterion) this.selector().getCriterion(ETH_TYPE);
    this.ethSrcAddrCriterion = (EthCriterion) this.selector().getCriterion(ETH_SRC);
    this.ethDstAddrCriterion = (EthCriterion) this.selector().getCriterion(ETH_DST);
    this.ipv4ProtoCriterion = (IPProtocolCriterion) this.selector().getCriterion(IP_PROTO);
    this.ipv4SrcAddrCriterion = (IPCriterion) this.selector().getCriterion(IPV4_SRC);
    this.ipv4DstAddrCriterion = (IPCriterion) this.selector().getCriterion(IPV4_DST);
    this.ipv4SrcMaskCriterion = (IPCriterion) this.selector().getCriterion(IPV4_SRC);
    this.ipv4DstMaskCriterion = (IPCriterion) this.selector().getCriterion(IPV4_DST);
    this.udpSrcPortCriterion = (UdpPortCriterion) this.selector().getCriterion(UDP_SRC);
    this.udpDstPortCriterion = (UdpPortCriterion) this.selector().getCriterion(UDP_DST);
    this.tcpSrcPortCriterion = (TcpPortCriterion) this.selector().getCriterion(TCP_SRC);
    this.tcpDstPortCriterion = (TcpPortCriterion) this.selector().getCriterion(TCP_DST);
    this.actions = new HashSet<NicRuleAction>();
    // TODO: Expand this translator with more actions
    for (Instruction instr : this.treatment().allInstructions()) {
        if (instr.type() == NOACTION) {
            this.actions.add(new NicRuleAction(NicRuleAction.Action.DROP));
        } else if (instr.type() == QUEUE) {
            SetQueueInstruction queueInstruction = (SetQueueInstruction) instr;
            this.actions.add(new NicRuleAction(NicRuleAction.Action.QUEUE, queueInstruction.queueId()));
            this.interfaceNumber = queueInstruction.port().toLong();
        } else if (instr.type() == METER) {
            MeterInstruction meterInstruction = (MeterInstruction) instr;
            this.actions.add(new NicRuleAction(NicRuleAction.Action.METER, meterInstruction.meterId().id()));
        }
    }
    // This action provides basic rule match counters
    this.actions.add(new NicRuleAction(NicRuleAction.Action.COUNT));
}
Also used : SetQueueInstruction(org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction) MeterInstruction(org.onosproject.net.flow.instructions.Instructions.MeterInstruction) MeterInstruction(org.onosproject.net.flow.instructions.Instructions.MeterInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) SetQueueInstruction(org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction)

Example 93 with Instruction

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

the class CorsaPipelineV39 method processNextTreatment.

@Override
protected CorsaTrafficTreatment processNextTreatment(TrafficTreatment treatment) {
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    treatment.immediate().stream().filter(i -> {
        switch(i.type()) {
            case L2MODIFICATION:
                L2ModificationInstruction l2i = (L2ModificationInstruction) i;
                return l2i.subtype() == VLAN_ID || l2i.subtype() == VLAN_POP || l2i.subtype() == ETH_DST || l2i.subtype() == ETH_SRC;
            case OUTPUT:
                return true;
            default:
                return false;
        }
    }).forEach(i -> tb.add(i));
    TrafficTreatment t = tb.build();
    boolean isPresentModVlanId = false;
    boolean isPresentModEthSrc = false;
    boolean isPresentModEthDst = false;
    boolean isPresentOutpuPort = false;
    for (Instruction instruction : t.immediate()) {
        switch(instruction.type()) {
            case L2MODIFICATION:
                L2ModificationInstruction l2i = (L2ModificationInstruction) instruction;
                if (l2i instanceof L2ModificationInstruction.ModVlanIdInstruction) {
                    isPresentModVlanId = true;
                }
                if (l2i instanceof L2ModificationInstruction.ModEtherInstruction) {
                    L2ModificationInstruction.L2SubType subType = l2i.subtype();
                    if (subType.equals(L2ModificationInstruction.L2SubType.ETH_SRC)) {
                        isPresentModEthSrc = true;
                    } else if (subType.equals(L2ModificationInstruction.L2SubType.ETH_DST)) {
                        isPresentModEthDst = true;
                    }
                }
                break;
            case OUTPUT:
                isPresentOutpuPort = true;
                break;
            default:
        }
    }
    CorsaTrafficTreatmentType type = CorsaTrafficTreatmentType.ACTIONS;
    /**
     * These are the allowed groups for CorsaPipelinev39
     */
    if (isPresentModVlanId && isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) {
        type = CorsaTrafficTreatmentType.GROUP;
    } else if ((!isPresentModVlanId && isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) || (!isPresentModVlanId && !isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) || (!isPresentModVlanId && !isPresentModEthSrc && !isPresentModEthDst && isPresentOutpuPort)) {
        type = CorsaTrafficTreatmentType.GROUP;
        TrafficTreatment.Builder tb2 = DefaultTrafficTreatment.builder(t);
        tb2.add(Instructions.popVlan());
        t = tb2.build();
    }
    CorsaTrafficTreatment corsaTreatment = new CorsaTrafficTreatment(type, t);
    return corsaTreatment;
}
Also used : VLAN_POP(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_POP) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) ETH_DST(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.ETH_DST) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) VLAN_ID(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_ID) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Instruction(org.onosproject.net.flow.instructions.Instruction) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) ETH_SRC(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.ETH_SRC) IPv4(org.onlab.packet.IPv4) Builder(org.onosproject.net.flow.FlowRule.Builder) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Collections(java.util.Collections) Builder(org.onosproject.net.flow.FlowRule.Builder) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 94 with Instruction

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

the class CorsaPipelineV3 method processNextTreatment.

@Override
protected CorsaTrafficTreatment processNextTreatment(TrafficTreatment treatment) {
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    treatment.immediate().stream().filter(i -> {
        switch(i.type()) {
            case L2MODIFICATION:
                L2ModificationInstruction l2i = (L2ModificationInstruction) i;
                return l2i instanceof L2ModificationInstruction.ModVlanIdInstruction || l2i instanceof L2ModificationInstruction.ModEtherInstruction;
            case OUTPUT:
                return true;
            default:
                return false;
        }
    }).forEach(i -> tb.add(i));
    TrafficTreatment t = tb.build();
    boolean isPresentModVlanId = false;
    boolean isPresentModEthSrc = false;
    boolean isPresentModEthDst = false;
    boolean isPresentOutpuPort = false;
    for (Instruction instruction : t.immediate()) {
        switch(instruction.type()) {
            case L2MODIFICATION:
                L2ModificationInstruction l2i = (L2ModificationInstruction) instruction;
                if (l2i instanceof L2ModificationInstruction.ModVlanIdInstruction) {
                    isPresentModVlanId = true;
                }
                if (l2i instanceof L2ModificationInstruction.ModEtherInstruction) {
                    L2ModificationInstruction.L2SubType subType = l2i.subtype();
                    if (subType.equals(L2ModificationInstruction.L2SubType.ETH_SRC)) {
                        isPresentModEthSrc = true;
                    } else if (subType.equals(L2ModificationInstruction.L2SubType.ETH_DST)) {
                        isPresentModEthDst = true;
                    }
                }
                break;
            case OUTPUT:
                isPresentOutpuPort = true;
                break;
            default:
        }
    }
    CorsaTrafficTreatmentType type = CorsaTrafficTreatmentType.ACTIONS;
    /**
     * This represents the allowed group for CorsaPipelinev3
     */
    if (isPresentModVlanId && isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) {
        type = CorsaTrafficTreatmentType.GROUP;
    }
    CorsaTrafficTreatment corsaTreatment = new CorsaTrafficTreatment(type, t);
    return corsaTreatment;
}
Also used : MeterRequest(org.onosproject.net.meter.MeterRequest) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) MeterId(org.onosproject.net.meter.MeterId) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) NextObjective(org.onosproject.net.flowobjective.NextObjective) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) Band(org.onosproject.net.meter.Band) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ImmutableSet(com.google.common.collect.ImmutableSet) Meter(org.onosproject.net.meter.Meter) Logger(org.slf4j.Logger) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Instruction(org.onosproject.net.flow.instructions.Instruction) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) DefaultBand(org.onosproject.net.meter.DefaultBand) DefaultMeterRequest(org.onosproject.net.meter.DefaultMeterRequest) Builder(org.onosproject.net.flow.FlowRule.Builder) FlowRule(org.onosproject.net.flow.FlowRule) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Collections(java.util.Collections) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 95 with Instruction

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

the class OplinkPowerConfigUtil method getChannelAttenuation.

/**
 * Gets specified channel attenuation.
 *
 * @param portNum the port number
 * @param och channel signal
 * @return atteuation in 0.01 dB
 */
private Long getChannelAttenuation(PortNumber portNum, OchSignal och) {
    FlowEntry flowEntry = findFlow(portNum, och);
    if (flowEntry == null) {
        return null;
    }
    List<Instruction> instructions = flowEntry.treatment().allInstructions();
    for (Instruction ins : instructions) {
        if (ins.type() != Instruction.Type.EXTENSION) {
            continue;
        }
        ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction();
        if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) {
            return (long) ((OplinkAttenuation) ext).getAttenuation();
        }
    }
    return null;
}
Also used : Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Aggregations

Instruction (org.onosproject.net.flow.instructions.Instruction)104 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)59 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)44 Criterion (org.onosproject.net.flow.criteria.Criterion)42 TrafficSelector (org.onosproject.net.flow.TrafficSelector)34 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)33 Instructions (org.onosproject.net.flow.instructions.Instructions)33 OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)32 L3ModificationInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction)32 PortNumber (org.onosproject.net.PortNumber)30 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)28 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)27 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)26 VlanId (org.onlab.packet.VlanId)25 DeviceId (org.onosproject.net.DeviceId)25 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)25 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)25 FlowRule (org.onosproject.net.flow.FlowRule)24 Group (org.onosproject.net.group.Group)23