Search in sources :

Example 1 with L4ModificationInstruction

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

the class EncodeInstructionCodecHelper method encodeL4.

/**
 * Encode a L4 modification instruction.
 *
 * @param result json node that the instruction attributes are added to
 */
private void encodeL4(ObjectNode result) {
    L4ModificationInstruction l4Instruction = (L4ModificationInstruction) instruction;
    result.put(InstructionCodec.SUBTYPE, l4Instruction.subtype().name());
    switch(l4Instruction.subtype()) {
        case TCP_DST:
        case TCP_SRC:
            final L4ModificationInstruction.ModTransportPortInstruction modTcpPortInstruction = (L4ModificationInstruction.ModTransportPortInstruction) l4Instruction;
            result.put(InstructionCodec.TCP_PORT, modTcpPortInstruction.port().toInt());
            break;
        case UDP_DST:
        case UDP_SRC:
            final L4ModificationInstruction.ModTransportPortInstruction modUdpPortInstruction = (L4ModificationInstruction.ModTransportPortInstruction) l4Instruction;
            result.put(InstructionCodec.UDP_PORT, modUdpPortInstruction.port().toInt());
            break;
        default:
            log.info("Cannot convert L4 subtype of {}", l4Instruction.subtype());
            break;
    }
}
Also used : L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction)

Example 2 with L4ModificationInstruction

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

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

the class GroupModBuilder method buildL4Modification.

protected OFAction buildL4Modification(Instruction i) {
    L4ModificationInstruction l4m = (L4ModificationInstruction) i;
    L4ModificationInstruction.ModTransportPortInstruction tp;
    OFOxm<?> oxm = null;
    switch(l4m.subtype()) {
        case TCP_SRC:
            tp = (L4ModificationInstruction.ModTransportPortInstruction) l4m;
            oxm = factory.oxms().tcpSrc(TransportPort.of(tp.port().toInt()));
            break;
        case TCP_DST:
            tp = (L4ModificationInstruction.ModTransportPortInstruction) l4m;
            oxm = factory.oxms().tcpDst(TransportPort.of(tp.port().toInt()));
            break;
        case UDP_SRC:
            tp = (L4ModificationInstruction.ModTransportPortInstruction) l4m;
            oxm = factory.oxms().udpSrc(TransportPort.of(tp.port().toInt()));
            break;
        case UDP_DST:
            tp = (L4ModificationInstruction.ModTransportPortInstruction) l4m;
            oxm = factory.oxms().udpDst(TransportPort.of(tp.port().toInt()));
            break;
        default:
            log.warn("Unimplemented action type {}.", l4m.subtype());
            break;
    }
    if (oxm != null) {
        return factory.actions().buildSetField().setField(oxm).build();
    }
    return null;
}
Also used : L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction)

Example 4 with L4ModificationInstruction

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

the class HPPipelineV3 method tableIdForForwardingObjective.

@Override
protected int tableIdForForwardingObjective(TrafficSelector selector, TrafficTreatment treatment) {
    boolean hardwareProcess = true;
    log.debug("HP V3 Driver - Evaluating the ForwardingObjective for proper TableID");
    // Check criteria supported in hardware
    for (Criterion criterion : selector.criteria()) {
        if (!this.hardwareCriteria.contains(criterion.type())) {
            log.warn("HP V3 Driver - criterion {} only supported in SOFTWARE", criterion.type());
            hardwareProcess = false;
            break;
        }
        // HP3800 does not support hardware match on ETH_TYPE of value TYPE_VLAN
        if (criterion.type() == Criterion.Type.ETH_TYPE) {
            if (((EthTypeCriterion) criterion).ethType().toShort() == Ethernet.TYPE_VLAN) {
                log.warn("HP V3 Driver -  ETH_TYPE == VLAN (0x8100) is only supported in software");
                hardwareProcess = false;
                break;
            }
        }
    }
    // If criteria can be processed in hardware, then check treatment
    if (hardwareProcess) {
        for (Instruction instruction : treatment.allInstructions()) {
            // Check if the instruction type is contained in the hardware instruction
            if (!this.hardwareInstructions.contains(instruction.type())) {
                log.warn("HP V3 Driver - instruction {} only supported in SOFTWARE", instruction.type());
                hardwareProcess = false;
                break;
            }
            /**
             * If output is CONTROLLER_PORT the flow entry could be installed in hardware
             * but is anyway processed in software because OPENFLOW header has to be added
             */
            if (instruction.type() == Instruction.Type.OUTPUT) {
                if (((Instructions.OutputInstruction) instruction).port() == PortNumber.CONTROLLER) {
                    log.warn("HP V3 Driver - Forwarding to CONTROLLER only supported in software");
                    hardwareProcess = false;
                    break;
                }
            }
            // Check if the specific L2MODIFICATION.subtype is supported in hardware
            if (instruction.type() == Instruction.Type.L2MODIFICATION) {
                if (!this.hardwareInstructionsL2mod.contains(((L2ModificationInstruction) instruction).subtype())) {
                    log.warn("HP V3 Driver - L2MODIFICATION.subtype {} only supported in SOFTWARE", ((L2ModificationInstruction) instruction).subtype());
                    hardwareProcess = false;
                    break;
                }
            }
            // Check if the specific L3MODIFICATION.subtype is supported in hardware
            if (instruction.type() == Instruction.Type.L3MODIFICATION) {
                if (!this.hardwareInstructionsL3mod.contains(((L3ModificationInstruction) instruction).subtype())) {
                    log.warn("HP V3 Driver - L3MODIFICATION.subtype {} only supported in SOFTWARE", ((L3ModificationInstruction) instruction).subtype());
                    hardwareProcess = false;
                    break;
                }
            }
            // Check if the specific L4MODIFICATION.subtype is supported in hardware
            if (instruction.type() == Instruction.Type.L4MODIFICATION) {
                if (!this.hardwareInstructionsL4mod.contains(((L4ModificationInstruction) instruction).subtype())) {
                    log.warn("HP V3 Driver - L4MODIFICATION.subtype {} only supported in SOFTWARE", ((L4ModificationInstruction) instruction).subtype());
                    hardwareProcess = false;
                    break;
                }
            }
            // TODO --- check if all the buckets contains one and only one output action
            if (instruction.type() == Instruction.Type.GROUP) {
                boolean groupInstalled = false;
                GroupId groupId = ((Instructions.GroupInstruction) instruction).groupId();
                Iterable<Group> groupsOnDevice = groupService.getGroups(deviceId);
                for (Group group : groupsOnDevice) {
                    if ((group.state() == Group.GroupState.ADDED) && (group.id().equals(groupId))) {
                        groupInstalled = true;
                        if (group.type() != Group.Type.ALL) {
                            log.warn("HP V3 Driver - group type {} only supported in SOFTWARE", group.type().toString());
                            hardwareProcess = false;
                        }
                        break;
                    }
                }
                if (!groupInstalled) {
                    log.warn("HP V3 Driver - referenced group is not installed on the device.");
                    hardwareProcess = false;
                }
            }
        }
    }
    if (hardwareProcess) {
        log.warn("HP V3 Driver - This flow rule is supported in HARDWARE");
        return HP_HARDWARE_TABLE;
    } else {
        // TODO: create a specific flow in table 100 to redirect selected traffic on table 200
        log.warn("HP V3 Driver - This flow rule is only supported in SOFTWARE");
        return HP_SOFTWARE_TABLE;
    }
}
Also used : Group(org.onosproject.net.group.Group) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instructions(org.onosproject.net.flow.instructions.Instructions) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) GroupId(org.onosproject.core.GroupId)

Example 5 with L4ModificationInstruction

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

the class FlowModBuilderVer13 method buildL4Modification.

protected OFAction buildL4Modification(Instruction i) {
    L4ModificationInstruction l4m = (L4ModificationInstruction) i;
    ModTransportPortInstruction tp;
    OFOxm<?> oxm = null;
    switch(l4m.subtype()) {
        case TCP_SRC:
            tp = (ModTransportPortInstruction) l4m;
            oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port().toInt()));
            break;
        case TCP_DST:
            tp = (ModTransportPortInstruction) l4m;
            oxm = factory().oxms().tcpDst(TransportPort.of(tp.port().toInt()));
            break;
        case UDP_SRC:
            tp = (ModTransportPortInstruction) l4m;
            oxm = factory().oxms().udpSrc(TransportPort.of(tp.port().toInt()));
            break;
        case UDP_DST:
            tp = (ModTransportPortInstruction) l4m;
            oxm = factory().oxms().udpDst(TransportPort.of(tp.port().toInt()));
            break;
        default:
            log.warn("Unimplemented action type {}.", l4m.subtype());
            break;
    }
    if (oxm != null) {
        return factory().actions().buildSetField().setField(oxm).build();
    }
    return null;
}
Also used : L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction) ModTransportPortInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction)

Aggregations

L4ModificationInstruction (org.onosproject.net.flow.instructions.L4ModificationInstruction)5 Instruction (org.onosproject.net.flow.instructions.Instruction)2 Instructions (org.onosproject.net.flow.instructions.Instructions)2 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)2 L3ModificationInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction)2 Test (org.junit.Test)1 GroupId (org.onosproject.core.GroupId)1 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)1 FlowRule (org.onosproject.net.flow.FlowRule)1 Criterion (org.onosproject.net.flow.criteria.Criterion)1 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)1 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)1 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)1 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)1 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)1 L0ModificationInstruction (org.onosproject.net.flow.instructions.L0ModificationInstruction)1 ModTransportPortInstruction (org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction)1 Group (org.onosproject.net.group.Group)1