Search in sources :

Example 11 with Instructions

use of org.onosproject.net.flow.instructions.Instructions 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)

Example 12 with Instructions

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

the class FlowAnalyzer method analyzeInstruction.

private boolean analyzeInstruction(Instruction i, FlowEntry flow) {
    boolean pointsToLiveEntry = false;
    Instructions.OutputInstruction output = (Instructions.OutputInstruction) i;
    PortNumber port = output.port();
    PortNumber outPort = null;
    DeviceId egress = null;
    boolean hasHost = false;
    ConnectPoint portPt = new ConnectPoint(flow.deviceId(), port);
    for (Link l : linkService.getEgressLinks(portPt)) {
        if (l.dst().elementId() instanceof DeviceId) {
            egress = l.dst().deviceId();
            outPort = l.dst().port();
        } else if (l.dst().elementId() instanceof HostId) {
            // the port leads to a host: therefore it is not a dead link
            pointsToLiveEntry = true;
            hasHost = true;
        }
    }
    if (!topologyService.isInfrastructure(topologyService.currentTopology(), portPt) && egress == null) {
        pointsToLiveEntry = true;
        hasHost = true;
    }
    if (hasHost) {
        return pointsToLiveEntry;
    }
    if (egress == null) {
        // the port that the flow instructions tells you to send the packet
        // to doesn't exist or is a controller port
        label.put(flow, "NA");
        return pointsToLiveEntry;
    }
    Iterable<FlowEntry> dstFlowTable = flowRuleService.getFlowEntries(egress);
    Set<Criterion> flowCriteria = flow.selector().criteria();
    // filter the criteria in order to remove port dependency
    Set<Criterion> filteredCriteria = new HashSet<>();
    for (Criterion criterion : flowCriteria) {
        if (!(criterion instanceof PortCriterion)) {
            filteredCriteria.add(criterion);
        }
    }
    // ensure that the in port is equal to the port that it is coming in from
    filteredCriteria.add(Criteria.matchInPort(outPort));
    for (FlowEntry entry : dstFlowTable) {
        if (ignoredFlows.contains(entry)) {
            continue;
        }
        if (filteredCriteria.containsAll(entry.selector().criteria())) {
            dfs(entry);
            if (!"Black Hole".equals(label.get(entry))) {
                // this entry is "live" i.e not a black hole
                pointsToLiveEntry = true;
            }
        }
    }
    return pointsToLiveEntry;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) Link(org.onosproject.net.Link) HashSet(java.util.HashSet)

Example 13 with Instructions

use of org.onosproject.net.flow.instructions.Instructions in project fabric-tna by stratum.

the class FabricInterpreter method mapOutboundPacket.

@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
    TrafficTreatment treatment = packet.treatment();
    // We support only OUTPUT instructions.
    List<Instructions.OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (Instructions.OutputInstruction) i).collect(toList());
    if (treatment.allInstructions().size() != outInstructions.size()) {
        // There are other instructions that are not of type OUTPUT.
        throw new PiInterpreterException("Treatment not supported: " + treatment);
    }
    ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
    for (Instructions.OutputInstruction outInst : outInstructions) {
        if (outInst.port().equals(TABLE)) {
            // Logical port. Forward using the switch tables like a regular packet.
            builder.add(createPiPacketOperation(packet.data(), 0, true));
        } else if (outInst.port().equals(FLOOD)) {
            // Logical port. Create a packet operation for each switch port.
            final DeviceService deviceService = handler().get(DeviceService.class);
            for (Port port : deviceService.getPorts(packet.sendThrough())) {
                builder.add(createPiPacketOperation(packet.data(), port.number().toLong(), false));
            }
        } else if (outInst.port().isLogical()) {
            throw new PiInterpreterException(format("Output on logical port '%s' not supported", outInst.port()));
        } else {
            // Send as-is to given port bypassing all switch tables.
            builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong(), false));
        }
    }
    return builder.build();
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) PACKET_OUT(org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT) ZERO(org.stratumproject.fabric.tna.Constants.ZERO) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) FabricTreatmentInterpreter.mapNextTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapNextTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) ImmutableList(com.google.common.collect.ImmutableList) DeserializationException(org.onlab.packet.DeserializationException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ImmutableByteSequence.copyFrom(org.onlab.util.ImmutableByteSequence.copyFrom) UnsignedInteger(com.google.common.primitives.UnsignedInteger) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FLOOD(org.onosproject.net.PortNumber.FLOOD) Instructions(org.onosproject.net.flow.instructions.Instructions) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Collection(java.util.Collection) FabricTreatmentInterpreter.mapForwardingTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapForwardingTreatment) Set(java.util.Set) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) SlicingService(org.stratumproject.fabric.tna.slicing.api.SlicingService) FabricTreatmentInterpreter.mapAclTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapAclTreatment) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) TABLE(org.onosproject.net.PortNumber.TABLE) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DriverHandler(org.onosproject.net.driver.DriverHandler) InboundPacket(org.onosproject.net.packet.InboundPacket) FabricTreatmentInterpreter.mapEgressNextTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapEgressNextTreatment) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) ONE(org.stratumproject.fabric.tna.Constants.ONE) FabricTreatmentInterpreter.mapPreNextTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapPreNextTreatment) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DeviceService(org.onosproject.net.device.DeviceService) Instructions(org.onosproject.net.flow.instructions.Instructions) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

Instructions (org.onosproject.net.flow.instructions.Instructions)13 PortNumber (org.onosproject.net.PortNumber)8 Criterion (org.onosproject.net.flow.criteria.Criterion)8 Instruction (org.onosproject.net.flow.instructions.Instruction)8 List (java.util.List)6 Set (java.util.Set)6 DeviceId (org.onosproject.net.DeviceId)5 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)5 FlowEntry (org.onosproject.net.flow.FlowEntry)5 FlowRule (org.onosproject.net.flow.FlowRule)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)5 ConnectPoint (org.onosproject.net.ConnectPoint)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ImmutableList (com.google.common.collect.ImmutableList)3 Range (com.google.common.collect.Range)3 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2