Search in sources :

Example 1 with L0ModificationInstruction

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

the class EncodeInstructionCodecHelper method encodeL0.

/**
 * Encode an L0 modification instruction.
 *
 * @param result json node that the instruction attributes are added to
 */
private void encodeL0(ObjectNode result) {
    L0ModificationInstruction l0Instruction = (L0ModificationInstruction) instruction;
    result.put(InstructionCodec.SUBTYPE, l0Instruction.subtype().name());
    switch(l0Instruction.subtype()) {
        case OCH:
            L0ModificationInstruction.ModOchSignalInstruction ochSignalInstruction = (L0ModificationInstruction.ModOchSignalInstruction) l0Instruction;
            OchSignal ochSignal = ochSignalInstruction.lambda();
            result.put(InstructionCodec.GRID_TYPE, ochSignal.gridType().name());
            result.put(InstructionCodec.CHANNEL_SPACING, ochSignal.channelSpacing().name());
            result.put(InstructionCodec.SPACING_MULTIPLIER, ochSignal.spacingMultiplier());
            result.put(InstructionCodec.SLOT_GRANULARITY, ochSignal.slotGranularity());
            break;
        default:
            log.info("Cannot convert L0 subtype of {}", l0Instruction.subtype());
    }
}
Also used : OchSignal(org.onosproject.net.OchSignal) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction)

Example 2 with L0ModificationInstruction

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

the class FlowRuleCodecTest method decodeInstructionsFlowTest.

/**
 * Checks that a rule with one of each instruction type decodes properly.
 *
 * @throws IOException if the resource cannot be processed
 */
@Test
public void decodeInstructionsFlowTest() throws Exception {
    FlowRule rule = getRule("instructions-flow.json");
    checkCommonData(rule);
    rule.treatment().allInstructions().forEach(instruction -> {
        String subType;
        if (instruction.type() == Instruction.Type.L0MODIFICATION) {
            subType = ((L0ModificationInstruction) instruction).subtype().name();
        } else if (instruction.type() == Instruction.Type.L2MODIFICATION) {
            subType = ((L2ModificationInstruction) instruction).subtype().name();
        } else if (instruction.type() == Instruction.Type.L3MODIFICATION) {
            subType = ((L3ModificationInstruction) instruction).subtype().name();
        } else if (instruction.type() == Instruction.Type.L4MODIFICATION) {
            subType = ((L4ModificationInstruction) instruction).subtype().name();
        } else {
            subType = "";
        }
        instructions.put(instruction.type().name() + "/" + subType, instruction);
    });
    assertThat(rule.treatment().allInstructions().size(), is(23));
    Instruction instruction;
    instruction = getInstruction(Instruction.Type.OUTPUT, "");
    assertThat(instruction.type(), is(Instruction.Type.OUTPUT));
    assertThat(((Instructions.OutputInstruction) instruction).port(), is(PortNumber.CONTROLLER));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.ETH_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(), is(MacAddress.valueOf("12:34:56:78:90:12")));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.ETH_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(), is(MacAddress.valueOf("98:76:54:32:01:00")));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_ID.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModVlanIdInstruction) instruction).vlanId().toShort(), is((short) 22));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_PCP.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModVlanPcpInstruction) instruction).vlanPcp(), is((byte) 1));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.MPLS_LABEL.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModMplsLabelInstruction) instruction).label().toInt(), is(MplsLabel.MAX_MPLS));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.MPLS_PUSH.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModMplsHeaderInstruction) instruction).ethernetType().toShort(), is(Ethernet.MPLS_UNICAST));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.MPLS_POP.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModMplsHeaderInstruction) instruction).ethernetType().toShort(), is(Ethernet.MPLS_UNICAST));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.DEC_MPLS_TTL.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(instruction, instanceOf(L2ModificationInstruction.ModMplsTtlInstruction.class));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_POP.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(instruction, instanceOf(L2ModificationInstruction.ModVlanHeaderInstruction.class));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_PUSH.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(instruction, instanceOf(L2ModificationInstruction.ModVlanHeaderInstruction.class));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.TUNNEL_ID.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModTunnelIdInstruction) instruction).tunnelId(), is(100L));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV4_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.4")));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV4_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.3")));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV6_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.2")));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV6_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.1")));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV6_FLABEL.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPv6FlowLabelInstruction) instruction).flowLabel(), is(8));
    instruction = getInstruction(Instruction.Type.L0MODIFICATION, L0ModificationInstruction.L0SubType.OCH.name());
    assertThat(instruction.type(), is(Instruction.Type.L0MODIFICATION));
    L0ModificationInstruction.ModOchSignalInstruction och = (L0ModificationInstruction.ModOchSignalInstruction) instruction;
    assertThat(och.lambda().spacingMultiplier(), is(4));
    assertThat(och.lambda().slotGranularity(), is(8));
    assertThat(och.lambda().gridType(), is(GridType.DWDM));
    assertThat(och.lambda().channelSpacing(), is(ChannelSpacing.CHL_100GHZ));
    instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.TCP_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
    assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40001));
    instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.TCP_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
    assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40002));
    instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.UDP_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
    assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40003));
    instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.UDP_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
    assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40004));
}
Also used : L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instructions(org.onosproject.net.flow.instructions.Instructions) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Test(org.junit.Test)

Example 3 with L0ModificationInstruction

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

the class FlowObjectiveCompositionUtil method revertTreatmentSelector.

public static TrafficSelector revertTreatmentSelector(TrafficTreatment trafficTreatment, TrafficSelector trafficSelector) {
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    Map<Criterion.Type, Criterion> criterionMap = new HashMap<>();
    for (Criterion criterion : trafficSelector.criteria()) {
        criterionMap.put(criterion.type(), criterion);
    }
    for (Instruction instruction : trafficTreatment.allInstructions()) {
        switch(instruction.type()) {
            case OUTPUT:
                break;
            case GROUP:
                break;
            case L0MODIFICATION:
                {
                    L0ModificationInstruction l0 = (L0ModificationInstruction) instruction;
                    switch(l0.subtype()) {
                        case OCH:
                            if (criterionMap.containsKey(Criterion.Type.OCH_SIGID)) {
                                if (((OchSignalCriterion) criterionMap.get((Criterion.Type.OCH_SIGID))).lambda().equals(((L0ModificationInstruction.ModOchSignalInstruction) l0).lambda())) {
                                    criterionMap.remove(Criterion.Type.OCH_SIGID);
                                } else {
                                    return null;
                                }
                            }
                        default:
                            break;
                    }
                    break;
                }
            case L1MODIFICATION:
                {
                    L1ModificationInstruction l1 = (L1ModificationInstruction) instruction;
                    switch(l1.subtype()) {
                        case ODU_SIGID:
                            if (criterionMap.containsKey(Criterion.Type.ODU_SIGID)) {
                                if (((OduSignalIdCriterion) criterionMap.get((Criterion.Type.ODU_SIGID))).oduSignalId().equals(((L1ModificationInstruction.ModOduSignalIdInstruction) l1).oduSignalId())) {
                                    criterionMap.remove(Criterion.Type.ODU_SIGID);
                                } else {
                                    return null;
                                }
                            }
                        default:
                            break;
                    }
                    break;
                }
            case L2MODIFICATION:
                {
                    L2ModificationInstruction l2 = (L2ModificationInstruction) instruction;
                    switch(l2.subtype()) {
                        case ETH_SRC:
                            if (criterionMap.containsKey(Criterion.Type.ETH_SRC)) {
                                if (((EthCriterion) criterionMap.get((Criterion.Type.ETH_SRC))).mac().equals(((L2ModificationInstruction.ModEtherInstruction) l2).mac())) {
                                    criterionMap.remove(Criterion.Type.ETH_SRC);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case ETH_DST:
                            if (criterionMap.containsKey(Criterion.Type.ETH_DST)) {
                                if (((EthCriterion) criterionMap.get((Criterion.Type.ETH_DST))).mac().equals(((L2ModificationInstruction.ModEtherInstruction) l2).mac())) {
                                    criterionMap.remove(Criterion.Type.ETH_DST);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case VLAN_ID:
                            if (criterionMap.containsKey(Criterion.Type.VLAN_VID)) {
                                if (((VlanIdCriterion) criterionMap.get((Criterion.Type.VLAN_VID))).vlanId().equals(((L2ModificationInstruction.ModVlanIdInstruction) l2).vlanId())) {
                                    criterionMap.remove(Criterion.Type.VLAN_VID);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case VLAN_PCP:
                            if (criterionMap.containsKey(Criterion.Type.VLAN_PCP)) {
                                if (((VlanPcpCriterion) criterionMap.get((Criterion.Type.VLAN_PCP))).priority() == ((L2ModificationInstruction.ModVlanPcpInstruction) l2).vlanPcp()) {
                                    criterionMap.remove(Criterion.Type.VLAN_PCP);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case MPLS_LABEL:
                            if (criterionMap.containsKey(Criterion.Type.MPLS_LABEL)) {
                                if (((MplsCriterion) criterionMap.get((Criterion.Type.MPLS_LABEL))).label().equals(((L2ModificationInstruction.ModMplsLabelInstruction) l2).label())) {
                                    criterionMap.remove(Criterion.Type.ETH_DST);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        default:
                            break;
                    }
                    break;
                }
            case TABLE:
                break;
            case L3MODIFICATION:
                {
                    L3ModificationInstruction l3 = (L3ModificationInstruction) instruction;
                    switch(l3.subtype()) {
                        case IPV4_SRC:
                            if (criterionMap.containsKey(Criterion.Type.IPV4_SRC)) {
                                if (((IPCriterion) criterionMap.get(Criterion.Type.IPV4_SRC)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
                                    criterionMap.remove(Criterion.Type.IPV4_SRC);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case IPV4_DST:
                            if (criterionMap.containsKey(Criterion.Type.IPV4_DST)) {
                                if (((IPCriterion) criterionMap.get(Criterion.Type.IPV4_DST)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
                                    criterionMap.remove(Criterion.Type.IPV4_DST);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case IPV6_SRC:
                            if (criterionMap.containsKey(Criterion.Type.IPV6_SRC)) {
                                if (((IPCriterion) criterionMap.get(Criterion.Type.IPV6_SRC)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
                                    criterionMap.remove(Criterion.Type.IPV6_SRC);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case IPV6_DST:
                            if (criterionMap.containsKey(Criterion.Type.IPV6_DST)) {
                                if (((IPCriterion) criterionMap.get(Criterion.Type.IPV6_DST)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
                                    criterionMap.remove(Criterion.Type.IPV6_DST);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case IPV6_FLABEL:
                            if (criterionMap.containsKey(Criterion.Type.IPV6_FLABEL)) {
                                if (((IPv6FlowLabelCriterion) criterionMap.get(Criterion.Type.IPV6_FLABEL)).flowLabel() == (((L3ModificationInstruction.ModIPv6FlowLabelInstruction) l3).flowLabel())) {
                                    criterionMap.remove(Criterion.Type.IPV4_SRC);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        default:
                            break;
                    }
                    break;
                }
            case METADATA:
                break;
            default:
                break;
        }
    }
    for (Criterion criterion : criterionMap.values()) {
        selectorBuilder.add(criterion);
    }
    return selectorBuilder.build();
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) HashMap(java.util.HashMap) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 4 with L0ModificationInstruction

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

the class FlowModBuilderVer13 method buildL0Modification.

protected OFAction buildL0Modification(Instruction i) {
    L0ModificationInstruction l0m = (L0ModificationInstruction) i;
    OFOxm<?> oxm = null;
    switch(l0m.subtype()) {
        case OCH:
            try {
                ModOchSignalInstruction modOchSignalInstruction = (ModOchSignalInstruction) l0m;
                OchSignal signal = modOchSignalInstruction.lambda();
                byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
                byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
                oxm = factory().oxms().expOchSigId(new CircuitSignalID(gridType, channelSpacing, (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
            } catch (NoMappingFoundException e) {
                log.warn(e.getMessage());
                break;
            }
            break;
        default:
            log.warn("Unimplemented action type {}.", l0m.subtype());
            break;
    }
    if (oxm != null) {
        return factory().actions().buildSetField().setField(oxm).build();
    }
    return null;
}
Also used : ModOchSignalInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction) OchSignal(org.onosproject.net.OchSignal) CircuitSignalID(org.projectfloodlight.openflow.types.CircuitSignalID) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) NoMappingFoundException(org.onosproject.provider.of.flow.util.NoMappingFoundException)

Aggregations

L0ModificationInstruction (org.onosproject.net.flow.instructions.L0ModificationInstruction)4 OchSignal (org.onosproject.net.OchSignal)2 Instruction (org.onosproject.net.flow.instructions.Instruction)2 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)2 L3ModificationInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)1 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)1 FlowRule (org.onosproject.net.flow.FlowRule)1 TrafficSelector (org.onosproject.net.flow.TrafficSelector)1 Criterion (org.onosproject.net.flow.criteria.Criterion)1 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)1 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)1 IPv6FlowLabelCriterion (org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion)1 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)1 OchSignalCriterion (org.onosproject.net.flow.criteria.OchSignalCriterion)1 OduSignalIdCriterion (org.onosproject.net.flow.criteria.OduSignalIdCriterion)1 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)1 VlanPcpCriterion (org.onosproject.net.flow.criteria.VlanPcpCriterion)1