Search in sources :

Example 41 with Instruction

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

the class TrafficMonitor method getEgressFlows.

// Counts all entries that egress on the link source port.
private int getEgressFlows(Link link, List<FlowEntry> entries) {
    int count = 0;
    PortNumber out = link.src().port();
    for (FlowEntry entry : entries) {
        TrafficTreatment treatment = entry.treatment();
        for (Instruction instruction : treatment.allInstructions()) {
            if (instruction.type() == Instruction.Type.OUTPUT && ((OutputInstruction) instruction).port().equals(out)) {
                count++;
            }
        }
    }
    return count;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PortNumber(org.onosproject.net.PortNumber) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 42 with Instruction

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

the class FlowModBuilderVer15 method buildActions.

private List<OFAction> buildActions(List<Instruction> treatments, Boolean immediateActions) {
    if (treatment == null) {
        return Collections.emptyList();
    }
    boolean tableFound = false;
    List<OFAction> actions = new LinkedList<>();
    // Meter action handling
    if (null != treatment.meters() && immediateActions) {
        treatment.meters().forEach(meterInstruction -> {
            OFAction meterAction = buildMeterAction(meterInstruction);
            actions.add(meterAction);
        });
    }
    for (Instruction i : treatments) {
        switch(i.type()) {
            case NOACTION:
                return Collections.emptyList();
            case L0MODIFICATION:
                actions.add(buildL0Modification(i));
                break;
            case L1MODIFICATION:
                actions.add(buildL1Modification(i));
                break;
            case L2MODIFICATION:
                actions.add(buildL2Modification(i));
                break;
            case L3MODIFICATION:
                actions.add(buildL3Modification(i));
                break;
            case L4MODIFICATION:
                actions.add(buildL4Modification(i));
                break;
            case OUTPUT:
                Instructions.OutputInstruction out = (Instructions.OutputInstruction) i;
                OFActionOutput.Builder action = factory().actions().buildOutput().setPort(OFPort.of((int) out.port().toLong()));
                if (out.port().equals(PortNumber.CONTROLLER)) {
                    action.setMaxLen(OFPCML_NO_BUFFER);
                }
                actions.add(action.build());
                break;
            case GROUP:
                Instructions.GroupInstruction group = (Instructions.GroupInstruction) i;
                OFActionGroup.Builder groupBuilder = factory().actions().buildGroup().setGroup(OFGroup.of(group.groupId().id()));
                actions.add(groupBuilder.build());
                break;
            case QUEUE:
                Instructions.SetQueueInstruction queue = (Instructions.SetQueueInstruction) i;
                OFActionSetQueue.Builder queueBuilder = factory().actions().buildSetQueue().setQueueId(queue.queueId());
                actions.add(queueBuilder.build());
                break;
            case TABLE:
                // FIXME: should not occur here.
                tableFound = true;
                break;
            case EXTENSION:
                actions.add(buildExtensionAction(((Instructions.ExtensionInstructionWrapper) i).extensionInstruction()));
                break;
            default:
                log.warn("Instruction type {} not yet implemented.", i.type());
        }
    }
    if (tableFound && actions.isEmpty()) {
        // a goto instruction for the next table
        return Collections.emptyList();
    }
    return actions;
}
Also used : OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFActionSetQueue(org.projectfloodlight.openflow.protocol.action.OFActionSetQueue) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) Instructions(org.onosproject.net.flow.instructions.Instructions) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) OFActionGroup(org.projectfloodlight.openflow.protocol.action.OFActionGroup) LinkedList(java.util.LinkedList)

Example 43 with Instruction

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

the class OpenFlowCorePacketContext method sendPacket.

private void sendPacket(Ethernet eth) {
    List<Instruction> ins = treatmentBuilder().build().allInstructions();
    OFPort p = null;
    // TODO: support arbitrary list of treatments must be supported in ofPacketContext
    for (Instruction i : ins) {
        if (i.type() == Type.OUTPUT) {
            p = buildPort(((OutputInstruction) i).port());
            // for now...
            break;
        }
    }
    if (eth == null) {
        ofPktCtx.build(p);
    } else {
        ofPktCtx.build(eth, p);
    }
    ofPktCtx.send();
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OFPort(org.projectfloodlight.openflow.types.OFPort) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 44 with Instruction

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

the class OpenFlowPacketProvider method emit.

@Override
public void emit(OutboundPacket packet) {
    DeviceId devId = packet.sendThrough();
    String scheme = devId.toString().split(":")[0];
    if (!scheme.equals(this.id().scheme())) {
        throw new IllegalArgumentException("Don't know how to handle Device with scheme " + scheme);
    }
    Dpid dpid = Dpid.dpid(devId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null) {
        log.warn("Device {} isn't available?", devId);
        return;
    }
    OFPort inPort;
    if (packet.inPort() != null) {
        inPort = portDesc(packet.inPort()).getPortNo();
    } else {
        inPort = OFPort.CONTROLLER;
    }
    // Ethernet eth = new Ethernet();
    // eth.deserialize(packet.data().array(), 0, packet.data().array().length);
    OFPortDesc p = null;
    for (Instruction inst : packet.treatment().allInstructions()) {
        if (inst.type().equals(Instruction.Type.OUTPUT)) {
            p = portDesc(((OutputInstruction) inst).port());
            OFPacketOut po = packetOut(sw, packet.data().array(), p.getPortNo(), inPort);
            sw.sendMsg(po);
        }
    }
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) DeviceId(org.onosproject.net.DeviceId) Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFPort(org.projectfloodlight.openflow.types.OFPort) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut)

Example 45 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 variable binding.
 * @param rule FlowRule object
 * @param delete whether it is a delete or edit request
 * @return variable binding
 */
public static VariableBinding fromFlowRule(FlowRule rule, boolean delete) {
    Set<Criterion> criterions = rule.selector().criteria();
    PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
    long input = inPort.toLong();
    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);
    long output = outPort.toLong();
    OID oid = new OID(PORT_PATCH_OID + "." + input);
    Variable var = new UnsignedInteger32(delete ? 0 : output);
    return new VariableBinding(oid, var);
}
Also used : TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) 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) Set(java.util.Set) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HandlerBehaviour(org.onosproject.net.driver.HandlerBehaviour) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) UnsignedInteger32(org.snmp4j.smi.UnsignedInteger32) List(java.util.List) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) FlowRule(org.onosproject.net.flow.FlowRule) VariableBinding(org.snmp4j.smi.VariableBinding) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) Variable(org.snmp4j.smi.Variable) OID(org.snmp4j.smi.OID) Variable(org.snmp4j.smi.Variable) UnsignedInteger32(org.snmp4j.smi.UnsignedInteger32) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) OID(org.snmp4j.smi.OID) Instruction(org.onosproject.net.flow.instructions.Instruction) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PortNumber(org.onosproject.net.PortNumber) VariableBinding(org.snmp4j.smi.VariableBinding)

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