Search in sources :

Example 96 with Instruction

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

the class OplinkPowerConfigUtil method findFlow.

/**
 * Find matching flow on device.
 *
 * @param portNum the port number
 * @param och channel signal
 * @return flow entry
 */
private FlowEntry findFlow(PortNumber portNum, OchSignal och) {
    final DriverHandler handler = behaviour.handler();
    FlowRuleService service = handler.get(FlowRuleService.class);
    Iterable<FlowEntry> flowEntries = service.getFlowEntries(handler.data().deviceId());
    // Return first matching flow
    for (FlowEntry entry : flowEntries) {
        TrafficSelector selector = entry.selector();
        OchSignalCriterion entrySigid = (OchSignalCriterion) selector.getCriterion(Criterion.Type.OCH_SIGID);
        // Check channel
        if (entrySigid != null && och.equals(entrySigid.lambda())) {
            // Check input port
            PortCriterion entryPort = (PortCriterion) selector.getCriterion(Criterion.Type.IN_PORT);
            if (entryPort != null && portNum.equals(entryPort.port())) {
                return entry;
            }
            // Check output port
            TrafficTreatment treatment = entry.treatment();
            for (Instruction instruction : treatment.allInstructions()) {
                if (instruction.type() == Instruction.Type.OUTPUT && ((Instructions.OutputInstruction) instruction).port().equals(portNum)) {
                    return entry;
                }
            }
        }
    }
    log.warn("No matching flow found");
    return null;
}
Also used : OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) DriverHandler(org.onosproject.net.driver.DriverHandler) TrafficSelector(org.onosproject.net.flow.TrafficSelector) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) FlowRuleService(org.onosproject.net.flow.FlowRuleService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 97 with Instruction

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

the class DefaultCheckLoop method matchDeviceFlows.

/**
 * Iterate one by one at switch hops.
 * Return whether we discover a Loop now or not.
 *
 * When flows form a loop,
 * pkt is also a return value indicating the loop header.
 *
 * @param deviceId the device needed to be checked
 * @param pkt virtual packet forwarded by switches
 * @return true if a loop is discovered
 */
private boolean matchDeviceFlows(DeviceId deviceId, TsLoopPacket pkt) {
    if (pkt.isPassedDevice(deviceId)) {
        // Attention: pkt should be held outside
        return true;
    }
    List<FlowEntry> availableFlowEntries = new ArrayList<>();
    flowEntryInfo.get(deviceId).forEach(flowEntry -> {
        if (flowEntry.state() == ADDED) {
            availableFlowEntries.add(flowEntry);
        }
    });
    List<FlowEntry> sortedFlowEntries = sortFlowTable(availableFlowEntries);
    for (FlowEntry flowEntry : sortedFlowEntries) {
        TsReturn<Boolean> isBigger = new TsReturn<>();
        TsLoopPacket newPkt = pkt.copyPacketMatch();
        if (!matchAndAddFlowEntry(flowEntry, newPkt, isBigger)) {
            continue;
        }
        newPkt.pushPathFlow(flowEntry);
        for (Instruction instOne : flowEntry.treatment().immediate()) {
            // the relationship of params which are passed in and out.
            if (processOneInstruction(instOne, deviceId, pkt, newPkt, false, null)) {
                return true;
            }
        }
        newPkt.popPathFlow();
        if (!isBigger.getValue()) {
            break;
        }
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) FlowEntry(org.onosproject.net.flow.FlowEntry) TsReturn(org.onosproject.fnl.base.TsReturn) TsLoopPacket(org.onosproject.fnl.base.TsLoopPacket)

Example 98 with Instruction

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

the class PipelineInterpreterImpl method mapTreatment.

@Override
public PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId) throws PiInterpreterException {
    if (piTableId != TABLE_L2_FWD_ID) {
        throw new PiInterpreterException("Can map treatments only for 't_l2_fwd' table");
    }
    if (treatment.allInstructions().size() == 0) {
        // 0 instructions means "NoAction"
        return PiAction.builder().withId(ACT_ID_NOP).build();
    } else if (treatment.allInstructions().size() > 1) {
        // We understand treatments with only 1 instruction.
        throw new PiInterpreterException("Treatment has multiple instructions");
    }
    // Get the first and only instruction.
    Instruction instruction = treatment.allInstructions().get(0);
    if (instruction.type() != OUTPUT) {
        // We can map only instructions of type OUTPUT.
        throw new PiInterpreterException(format("Instruction of type '%s' not supported", instruction.type()));
    }
    OutputInstruction outInstruction = (OutputInstruction) instruction;
    PortNumber port = outInstruction.port();
    if (!port.isLogical()) {
        return PiAction.builder().withId(ACT_ID_SET_EGRESS_PORT).withParameter(new PiActionParam(ACT_PARAM_ID_PORT, copyFrom(port.toLong()))).build();
    } else if (port.equals(CONTROLLER)) {
        return PiAction.builder().withId(ACT_ID_SEND_TO_CPU).build();
    } else {
        throw new PiInterpreterException(format("Output on logical port '%s' not supported", port));
    }
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam)

Example 99 with Instruction

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

the class PipelineInterpreterImpl method mapOutboundPacket.

@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
    TrafficTreatment treatment = packet.treatment();
    // We support only packet-out with OUTPUT instructions.
    if (treatment.allInstructions().size() != 1 && treatment.allInstructions().get(0).type() != OUTPUT) {
        throw new PiInterpreterException("Treatment not supported: " + treatment.toString());
    }
    Instruction instruction = treatment.allInstructions().get(0);
    PortNumber port = ((OutputInstruction) instruction).port();
    List<PiPacketOperation> piPacketOps = Lists.newArrayList();
    if (!port.isLogical()) {
        piPacketOps.add(createPiPacketOp(packet.data(), port.toLong()));
    } else if (port.equals(FLOOD)) {
        // Since mytunnel.p4 does not support flooding, we create a packet
        // operation for each switch port.
        DeviceService deviceService = handler().get(DeviceService.class);
        DeviceId deviceId = packet.sendThrough();
        for (Port p : deviceService.getPorts(deviceId)) {
            piPacketOps.add(createPiPacketOp(packet.data(), p.number().toLong()));
        }
    } else {
        throw new PiInterpreterException(format("Output on logical port '%s' not supported", port));
    }
    return piPacketOps;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DeviceService(org.onosproject.net.device.DeviceService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) PortNumber(org.onosproject.net.PortNumber)

Example 100 with Instruction

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

the class ChannelData method fromFlow.

/**
 * Returns a ChannelData representation from a flow rule. The rule must contain
 * a Criterion.Type.IN_PORT selector, Criterion.Type.OCH_SIGID selector, and
 * Instruction.Type.OUTPUT instruction.
 *
 * @param rule the flow rule representing the connection
 * @return ChannelData representation of the connection
 */
public static ChannelData fromFlow(FlowRule rule) {
    checkNotNull(rule);
    Criterion in = rule.selector().getCriterion(Criterion.Type.IN_PORT);
    checkNotNull(in);
    PortNumber inPort = ((PortCriterion) in).port();
    Criterion och = rule.selector().getCriterion(Criterion.Type.OCH_SIGID);
    OchSignal ochSignal = och == null ? null : ((OchSignalCriterion) och).lambda();
    PortNumber outPort = null;
    List<Instruction> instructions = rule.treatment().allInstructions();
    for (Instruction ins : instructions) {
        if (ins.type() == Instruction.Type.OUTPUT) {
            outPort = ((Instructions.OutputInstruction) ins).port();
        }
    }
    checkNotNull(outPort);
    return new ChannelData(inPort, outPort, ochSignal);
}
Also used : PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) OchSignal(org.onosproject.net.OchSignal) 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)

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