Search in sources :

Example 6 with Instructions

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

Example 7 with Instructions

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

the class TrafficTreatmentCodec method encode.

@Override
public ObjectNode encode(TrafficTreatment treatment, CodecContext context) {
    checkNotNull(treatment, "Traffic treatment cannot be null");
    final ObjectNode result = context.mapper().createObjectNode();
    final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS);
    final JsonCodec<Instruction> instructionCodec = context.codec(Instruction.class);
    for (final Instruction instruction : treatment.immediate()) {
        jsonInstructions.add(instructionCodec.encode(instruction, context));
    }
    if (treatment.metered() != null) {
        for (Instructions.MeterInstruction instruction : treatment.meters()) {
            jsonInstructions.add(instructionCodec.encode(instruction, context));
        }
    }
    if (treatment.tableTransition() != null) {
        jsonInstructions.add(instructionCodec.encode(treatment.tableTransition(), context));
    }
    if (treatment.clearedDeferred()) {
        result.put(CLEAR_DEFERRED, true);
    }
    final ArrayNode jsonDeferred = result.putArray(DEFERRED);
    for (final Instruction instruction : treatment.deferred()) {
        jsonDeferred.add(instructionCodec.encode(instruction, context));
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Instructions(org.onosproject.net.flow.instructions.Instructions) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 8 with Instructions

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

the class OfdpaPipelineTraceable method handleOutputFlows.

// Handles output flows
private List<FlowEntry> handleOutputFlows(TrafficSelector currentPacket, List<FlowEntry> outputFlows, TrafficSelector.Builder egressPacket, List<PortNumber> outputPorts, PipelineTraceableHitChain currentHitChain, PipelineTraceableOutput.Builder outputBuilder, TrafficSelector initialPacket) {
    // TODO optimization
    // outputFlows contains also last rule of device, so we need filtering for OUTPUT instructions.
    List<FlowEntry> outputFlowEntries = outputFlows.stream().filter(flow -> flow.treatment().allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT)).count() > 0).collect(Collectors.toList());
    if (outputFlowEntries.size() > 1) {
        outputBuilder.appendToLog("More than one flow rule with OUTPUT instruction");
        log.warn("There cannot be more than one flow entry with OUTPUT instruction for {}", currentPacket);
    }
    if (outputFlowEntries.size() == 1) {
        OutputInstruction outputInstruction = (OutputInstruction) outputFlowEntries.get(0).treatment().allInstructions().stream().filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT)).findFirst().get();
        buildOutputFromDevice(egressPacket, outputPorts, outputInstruction, currentHitChain, outputBuilder, initialPacket, false);
    }
    return outputFlowEntries;
}
Also used : PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) ConnectPoint(org.onosproject.net.ConnectPoint) DataPlaneEntity(org.onosproject.net.DataPlaneEntity) PipelineTraceable(org.onosproject.net.behaviour.PipelineTraceable) L2_INTERFACE_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_INTERFACE_TYPE) TMAC_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.TMAC_TABLE) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IndexTableId(org.onosproject.net.flow.IndexTableId) VLAN_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.VLAN_TABLE) Set(java.util.Set) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Collectors(java.util.stream.Collectors) L3_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L3_MULTICAST_TYPE) L2_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_MULTICAST_TYPE) EthType(org.onlab.packet.EthType) PipelineTraceableOutput(org.onosproject.net.PipelineTraceableOutput) List(java.util.List) PipelineTraceableInput(org.onosproject.net.PipelineTraceableInput) FlowRule(org.onosproject.net.flow.FlowRule) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) Ofdpa2Pipeline(org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) Pipeliner(org.onosproject.net.behaviour.Pipeliner) PipelineTraceableHitChain(org.onosproject.net.PipelineTraceableHitChain) BRIDGING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.BRIDGING_TABLE) TableId(org.onosproject.net.flow.TableId) ACL_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.ACL_TABLE) GroupBucket(org.onosproject.net.group.GroupBucket) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) OvsOfdpaPipeline(org.onosproject.driver.pipeline.ofdpa.OvsOfdpaPipeline) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) PipelineTraceablePacket(org.onosproject.net.PipelineTraceablePacket) L2_FLOOD_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_FLOOD_TYPE) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) MPLS_L3_TYPE_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MPLS_L3_TYPE_TABLE) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) GroupId(org.onosproject.core.GroupId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MULTICAST_ROUTING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MULTICAST_ROUTING_TABLE) Comparator(java.util.Comparator) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 9 with Instructions

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

the class OfdpaPipelineTraceable method getGroupsFromInstructions.

// Gets group information from instructions.
private void getGroupsFromInstructions(Map<GroupId, Group> groups, List<Instruction> instructions, TrafficSelector.Builder egressPacket, List<PortNumber> outputPorts, PipelineTraceableHitChain currentHitChain, PipelineTraceableOutput.Builder outputBuilder, PipelineTraceableInput input, boolean dropped) {
    List<Instruction> groupInstructionlist = new ArrayList<>();
    // sort instructions according to priority (larger Instruction.Type ENUM constant first)
    // which enables to treat other actions before the OUTPUT action
    // TODO improve the priority scheme according to the OpenFlow ActionSet spec
    List<Instruction> instructionsSorted = new ArrayList<>();
    instructionsSorted.addAll(instructions);
    instructionsSorted.sort((instr1, instr2) -> Integer.compare(instr2.type().ordinal(), instr1.type().ordinal()));
    // Handles first all non-group instructions
    for (Instruction instruction : instructionsSorted) {
        log.debug("Considering Instruction {}", instruction);
        // to the possible outputs for this packet
        if (!instruction.type().equals(Instruction.Type.GROUP)) {
            // or add the output to the possible outputs for this packet
            if (instruction.type().equals(Instruction.Type.OUTPUT)) {
                buildOutputFromDevice(egressPacket, outputPorts, (OutputInstruction) instruction, currentHitChain, outputBuilder, input.ingressPacket().packet(), dropped);
            } else {
                egressPacket = translateInstruction(egressPacket, instruction);
            }
        } else {
            // Store for later if the instruction is pointing to a group
            groupInstructionlist.add(instruction);
        }
    }
    // handle all the internal instructions pointing to a group.
    for (Instruction instr : groupInstructionlist) {
        Instructions.GroupInstruction groupInstruction = (Instructions.GroupInstruction) instr;
        Group group = groups.get(groupInstruction.groupId());
        // group does not exist in the dataplane
        if (group == null) {
            currentHitChain.setEgressPacket(new PipelineTraceablePacket(egressPacket.build()));
            currentHitChain.dropped();
            outputBuilder.appendToLog("Null group for Instruction " + instr).noGroups().addHitChain(currentHitChain);
            break;
        }
        log.debug("Analyzing group {}", group.id());
        // group is there but there are no members/buckets
        if (group.buckets().buckets().size() == 0) {
            // add the group to the traversed groups
            currentHitChain.addDataPlaneEntity(new DataPlaneEntity(group));
            currentHitChain.setEgressPacket(new PipelineTraceablePacket(egressPacket.build()));
            currentHitChain.dropped();
            outputBuilder.appendToLog("Group " + group.id() + " has no buckets").noMembers().addHitChain(currentHitChain);
            break;
        }
        PipelineTraceableHitChain newHitChain;
        TrafficSelector.Builder newEgressPacket;
        // Cycle in each of the group's buckets and add them to the groups for this Device.
        for (GroupBucket bucket : group.buckets().buckets()) {
            // add the group to the traversed groups
            currentHitChain.addDataPlaneEntity(new DataPlaneEntity(group));
            // Go to the next step - using a copy of the egress packet and of the hit chain
            newHitChain = PipelineTraceableHitChain.emptyHitChain();
            currentHitChain.hitChain().forEach(newHitChain::addDataPlaneEntity);
            newEgressPacket = DefaultTrafficSelector.builder(egressPacket.build());
            getGroupsFromInstructions(groups, bucket.treatment().allInstructions(), newEgressPacket, outputPorts, newHitChain, outputBuilder, input, dropped | isDropped(group.id(), bucket, input.ingressPort()));
        }
    }
}
Also used : Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) Instructions(org.onosproject.net.flow.instructions.Instructions) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) DataPlaneEntity(org.onosproject.net.DataPlaneEntity) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) GroupBucket(org.onosproject.net.group.GroupBucket) PipelineTraceableHitChain(org.onosproject.net.PipelineTraceableHitChain) PipelineTraceablePacket(org.onosproject.net.PipelineTraceablePacket)

Example 10 with Instructions

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

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