Search in sources :

Example 11 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags in project openflowplugin by opendaylight.

the class FlowModInputMessageFactoryTest method testFlowModInputMessageFactory.

/**
 * Testing of {@link FlowModInputMessageFactory} for correct translation from POJO.
 */
@Test
public void testFlowModInputMessageFactory() throws Exception {
    FlowModInputBuilder builder = new FlowModInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
    builder.setCookie(new BigInteger(1, cookie));
    byte[] cookieMask = new byte[] { (byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30 };
    builder.setCookieMask(new BigInteger(1, cookieMask));
    builder.setTableId(new TableId(65L));
    builder.setCommand(FlowModCommand.forValue(2));
    builder.setIdleTimeout(12);
    builder.setHardTimeout(0);
    builder.setPriority(126);
    builder.setBufferId(2L);
    builder.setOutPort(new PortNumber(4422L));
    builder.setOutGroup(98L);
    builder.setFlags(new FlowModFlags(true, false, true, false, true));
    MatchBuilder matchBuilder = new MatchBuilder();
    matchBuilder.setType(OxmMatchType.class);
    final List<MatchEntry> entries = new ArrayList<>();
    MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(InPhyPort.class);
    entriesBuilder.setHasMask(false);
    InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
    InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
    inPhyPortBuilder.setPortNumber(new PortNumber(42L));
    inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
    entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
    entries.add(entriesBuilder.build());
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(IpEcn.class);
    entriesBuilder.setHasMask(false);
    IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
    IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
    ipEcnBuilder.setEcn((short) 4);
    ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
    entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
    entries.add(entriesBuilder.build());
    matchBuilder.setMatchEntry(entries);
    builder.setMatch(matchBuilder.build());
    final List<Instruction> instructions = new ArrayList<>();
    InstructionBuilder insBuilder = new InstructionBuilder();
    GotoTableCaseBuilder goToCaseBuilder = new GotoTableCaseBuilder();
    GotoTableBuilder instructionBuilder = new GotoTableBuilder();
    instructionBuilder.setTableId((short) 43);
    goToCaseBuilder.setGotoTable(instructionBuilder.build());
    insBuilder.setInstructionChoice(goToCaseBuilder.build());
    instructions.add(insBuilder.build());
    WriteMetadataCaseBuilder metadataCaseBuilder = new WriteMetadataCaseBuilder();
    WriteMetadataBuilder metadataBuilder = new WriteMetadataBuilder();
    metadataBuilder.setMetadata(cookie);
    metadataBuilder.setMetadataMask(cookieMask);
    metadataCaseBuilder.setWriteMetadata(metadataBuilder.build());
    insBuilder.setInstructionChoice(metadataCaseBuilder.build());
    instructions.add(insBuilder.build());
    insBuilder = new InstructionBuilder();
    final ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
    final ApplyActionsBuilder actionsBuilder = new ApplyActionsBuilder();
    final List<Action> actions = new ArrayList<>();
    final ActionBuilder actionBuilder = new ActionBuilder();
    OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
    OutputActionBuilder outputBuilder = new OutputActionBuilder();
    outputBuilder.setPort(new PortNumber(42L));
    outputBuilder.setMaxLength(52);
    caseBuilder.setOutputAction(outputBuilder.build());
    actionBuilder.setActionChoice(caseBuilder.build());
    actions.add(actionBuilder.build());
    actionsBuilder.setAction(actions);
    applyActionsCaseBuilder.setApplyActions(actionsBuilder.build());
    insBuilder.setInstructionChoice(applyActionsCaseBuilder.build());
    instructions.add(insBuilder.build());
    builder.setInstruction(instructions);
    final FlowModInput message = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    // simulate parent message
    out.writeInt(1);
    out.writeZero(2);
    out.writeShort(3);
    flowModFactory.serialize(message, out);
    // read parent message
    out.readInt();
    out.skipBytes(2);
    out.readShort();
    BufferHelper.checkHeaderV13(out, (byte) 14, 128);
    cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(cookie);
    Assert.assertEquals("Wrong cookie", message.getCookie(), new BigInteger(1, cookie));
    cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(cookieMask);
    Assert.assertEquals("Wrong cookieMask", message.getCookieMask(), new BigInteger(1, cookieMask));
    Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readUnsignedByte());
    Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedByte());
    Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort());
    Assert.assertEquals("Wrong hardTimeOut", message.getHardTimeout().intValue(), out.readShort());
    Assert.assertEquals("Wrong priority", message.getPriority().intValue(), out.readUnsignedShort());
    Assert.assertEquals("Wrong bufferId", message.getBufferId().intValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong outPort", message.getOutPort().getValue().intValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong outGroup", message.getOutGroup().intValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong flags", message.getFlags(), createFlowModFlagsFromBitmap(out.readUnsignedShort()));
    out.skipBytes(PADDING_IN_FLOW_MOD_MESSAGE);
    Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort());
    short fieldAndMask = out.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
    out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 42, out.readUnsignedInt());
    Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort());
    fieldAndMask = out.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
    out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 4, out.readUnsignedByte());
    out.skipBytes(7);
    Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong instruction value", 43, out.readUnsignedByte());
    out.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    out.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES);
    byte[] cookieRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(cookieRead);
    byte[] cookieMaskRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(cookieMaskRead);
    Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead);
    Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead);
    Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
    Assert.assertEquals("Wrong port", 42, out.readUnsignedInt());
    Assert.assertEquals("Wrong max-length", 52, out.readUnsignedShort());
    out.skipBytes(6);
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId) InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder) OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) WriteMetadataCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCaseBuilder) ArrayList(java.util.ArrayList) GotoTableCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCaseBuilder) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction) ByteBuf(io.netty.buffer.ByteBuf) WriteMetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.metadata._case.WriteMetadataBuilder) InPhyPortBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.in.phy.port._case.InPhyPortBuilder) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) InPhyPortCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPhyPortCaseBuilder) ApplyActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCaseBuilder) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) IpEcnCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpEcnCaseBuilder) ApplyActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.apply.actions._case.ApplyActionsBuilder) IpEcnBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.ecn._case.IpEcnBuilder) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) FlowModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput) GotoTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice._goto.table._case.GotoTableBuilder) BigInteger(java.math.BigInteger) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder) Test(org.junit.Test)

Example 12 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags in project openflowplugin by opendaylight.

the class FlowCreatorUtilTest method testCanModifyFlow.

/**
 * Test method for
 * {@link FlowCreatorUtil#canModifyFlow(OriginalFlow, UpdatedFlow, Short)}.
 */
@Test
public void testCanModifyFlow() {
    final Short of10 = Short.valueOf(OFConstants.OFP_VERSION_1_0);
    final Short of13 = Short.valueOf(OFConstants.OFP_VERSION_1_3);
    final Short[] versions = { null, of10, of13 };
    final Boolean[] bools = { null, Boolean.TRUE, Boolean.FALSE };
    final Integer defPri = Integer.valueOf(0x8000);
    final Integer defIdle = Integer.valueOf(0);
    final Integer defHard = Integer.valueOf(0);
    final FlowModFlags defFlags = FlowModFlags.getDefaultInstance("sENDFLOWREM");
    final FlowModFlags flags = new FlowModFlags(false, true, false, true, false);
    final FlowCookie defCookie = new FlowCookie(BigInteger.ZERO);
    final FlowCookie cookie = new FlowCookie(BigInteger.valueOf(0x12345L));
    final FlowCookie cookie1 = new FlowCookie(BigInteger.valueOf(0x67890L));
    final FlowCookie cookieMask = new FlowCookie(BigInteger.valueOf(0xffff00L));
    for (final Short ver : versions) {
        final OriginalFlowBuilder originalBuilder = new OriginalFlowBuilder();
        final UpdatedFlowBuilder updatedBuilder = new UpdatedFlowBuilder();
        canModifyFlowTest(true, originalBuilder, updatedBuilder, ver);
        // Default value tests.
        canModifyFlowTest(true, new OriginalFlowBuilder().setPriority(defPri), updatedBuilder, ver);
        canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setPriority(defPri), ver);
        canModifyFlowTest(true, new OriginalFlowBuilder().setIdleTimeout(defIdle), updatedBuilder, ver);
        canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setIdleTimeout(defIdle), ver);
        canModifyFlowTest(true, new OriginalFlowBuilder().setHardTimeout(defHard), updatedBuilder, ver);
        canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setHardTimeout(defHard), ver);
        canModifyFlowTest(false, new OriginalFlowBuilder().setFlags(defFlags), updatedBuilder, ver);
        canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder().setFlags(defFlags), ver);
        canModifyFlowTest(true, new OriginalFlowBuilder().setCookie(defCookie), updatedBuilder, ver);
        canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setCookie(defCookie), ver);
        // Set non-default values.
        canModifyFlowTest(true, originalBuilder.setMatch(createMatch(0x800L)), updatedBuilder.setMatch(createMatch(0x800L)), ver);
        canModifyFlowTest(true, originalBuilder.setIdleTimeout(600), updatedBuilder.setIdleTimeout(600), ver);
        canModifyFlowTest(true, originalBuilder.setHardTimeout(1200), updatedBuilder.setHardTimeout(1200), ver);
        canModifyFlowTest(true, originalBuilder.setPriority(100), updatedBuilder.setPriority(100), ver);
        canModifyFlowTest(true, originalBuilder.setFlags(flags), updatedBuilder.setFlags(flags), ver);
        canModifyFlowTest(true, originalBuilder.setCookie(cookie), updatedBuilder.setCookie(cookie), ver);
        final OriginalFlow org = originalBuilder.build();
        final UpdatedFlow upd = updatedBuilder.build();
        // Set different match.
        final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match[] matches = { null, createMatch(0x86ddL) };
        for (final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match m : matches) {
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setMatch(m), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setMatch(m), updatedBuilder, ver);
        }
        // Set different idle-timeout, hard-timeout, priority.
        final Integer[] integers = { null, Integer.valueOf(3600) };
        for (final Integer i : integers) {
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setIdleTimeout(i), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setIdleTimeout(i), updatedBuilder, ver);
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setHardTimeout(i), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setHardTimeout(i), updatedBuilder, ver);
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setPriority(i), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setPriority(i), updatedBuilder, ver);
        }
        // Set different FLOW_MOD flags.
        final FlowModFlags[] flowModFlags = { null, defFlags, new FlowModFlags(true, true, true, true, true) };
        for (final FlowModFlags f : flowModFlags) {
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setFlags(f), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setFlags(f), updatedBuilder, ver);
        }
        // Set different cookie.
        final FlowCookie[] cookies = { null, defCookie, new FlowCookie(BigInteger.valueOf(0x123456L)) };
        for (final FlowCookie c : cookies) {
            canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setCookie(c), ver);
            canModifyFlowTest(false, new OriginalFlowBuilder(org).setCookie(c), updatedBuilder, ver);
        }
        // Cookie mask test.
        // Cookie mask is used by OF13 non-strict MODIFY command.
        updatedBuilder.setCookie(cookie1);
        for (final Boolean strict : bools) {
            updatedBuilder.setCookieMask(null).setStrict(strict);
            canModifyFlowTest(false, originalBuilder, updatedBuilder, ver);
            updatedBuilder.setCookieMask(defCookie);
            canModifyFlowTest(false, originalBuilder, updatedBuilder, ver);
            updatedBuilder.setCookieMask(cookieMask);
            final boolean expected = (of13.equals(ver) && !Boolean.TRUE.equals(strict));
            canModifyFlowTest(expected, originalBuilder, updatedBuilder, ver);
        }
    }
}
Also used : UpdatedFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow) OriginalFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) BigInteger(java.math.BigInteger) OriginalFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder) UpdatedFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder) Test(org.junit.Test)

Example 13 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags in project netvirt by opendaylight.

the class OpenFlow13Utils method createFlowBuilder.

public static FlowBuilder createFlowBuilder(final short table, final int priority, final BigInteger cookieValue, final String flowName, final String flowIdStr, MatchBuilder match, InstructionsBuilder isb) {
    FlowBuilder flow = new FlowBuilder();
    flow.setId(new FlowId(flowIdStr));
    flow.setKey(new FlowKey(new FlowId(flowIdStr)));
    flow.setTableId(table);
    flow.setFlowName(flowName);
    flow.setCookie(new FlowCookie(cookieValue));
    flow.setCookieMask(new FlowCookie(cookieValue));
    flow.setContainerName(null);
    flow.setStrict(false);
    flow.setMatch(match.build());
    flow.setInstructions(isb.build());
    flow.setPriority(priority);
    flow.setHardTimeout(0);
    flow.setIdleTimeout(0);
    flow.setFlags(new FlowModFlags(false, false, false, false, false));
    if (null == flow.isBarrier()) {
        flow.setBarrier(Boolean.FALSE);
    }
    return flow;
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) NxAugMatchNodesNodeTableFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) GeneralAugMatchNodesNodeTableFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags)

Example 14 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags in project openflowplugin by opendaylight.

the class OpenflowpluginTestCommandProvider method createTestFlow.

private FlowBuilder createTestFlow(final NodeBuilder nodeBuilder, final String flowTypeArg, final String tableId) {
    final long TEST_ID = 123;
    final FlowBuilder flow = new FlowBuilder();
    long id = TEST_ID;
    String flowType = flowTypeArg;
    if (flowType == null) {
        flowType = "f1";
    }
    flow.setPriority(2);
    switch(flowType) {
        case "f1":
            id += 1;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createDecNwTtlInstructions().build());
            break;
        case "f2":
            id += 2;
            flow.setMatch(createMatch2().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f3":
            id += 3;
            flow.setMatch(createMatch3().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f4":
            id += 4;
            flow.setMatch(createEthernetMatch().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f5":
            id += 5;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction().build());
            break;
        case "f6":
            id += 6;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createGotoTableInstructions().build());
            break;
        case "f7":
            id += 7;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createMeterInstructions().build());
            break;
        case "f8":
            id += 8;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction1().build());
            break;
        case "f9":
            id += 9;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction2().build());
            break;
        case "f10":
            id += 10;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction3().build());
            break;
        case "f11":
            id += 11;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction4().build());
            break;
        case "f12":
            id += 12;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction5().build());
            break;
        case "f13":
            id += 13;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction6().build());
            break;
        case "f14":
            id += 14;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction7().build());
            break;
        case "f15":
            id += 15;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction8().build());
            break;
        case "f16":
            id += 16;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction9().build());
            break;
        case "f17":
            id += 17;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction10().build());
            break;
        case "f18":
            id += 18;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction11().build());
            break;
        case "f19":
            id += 19;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction12().build());
            break;
        case "f20":
            id += 20;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction13().build());
            break;
        case "f21":
            id += 21;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction14().build());
            break;
        case "f22":
            id += 22;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction15().build());
            break;
        case "f23":
            id += 23;
            // f23 can be used as test-case for generating error notification
            // if the particular group is not configured - tested
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction16().build());
            break;
        case "f24":
            id += 24;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction17().build());
            break;
        case "f25":
            id += 25;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction18().build());
            break;
        case "f26":
            id += 26;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction19().build());
            break;
        case "f27":
            id += 27;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createMetadataInstructions().build());
            break;
        case "f28":
            id += 28;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction20().build());
            break;
        case "f29":
            id += 29;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction21().build());
            break;
        case "f30":
            id += 30;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction22().build());
            break;
        case "f31":
            id += 31;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction23(nodeBuilder.getId()).build());
            break;
        case "f32":
            id += 32;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction24().build());
            break;
        case "f33":
            id += 33;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction25().build());
            break;
        case "f34":
            id += 34;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction26().build());
            break;
        case "f35":
            id += 35;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction27().build());
            break;
        case "f36":
            id += 36;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction28().build());
            break;
        case "f37":
            id += 37;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction29().build());
            break;
        case "f38":
            id += 38;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction30().build());
            break;
        case "f39":
            id += 39;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction31().build());
            break;
        case "f40":
            id += 40;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction32().build());
            break;
        case "f41":
            id += 41;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction33().build());
            break;
        case "f42":
            id += 42;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction34().build());
            break;
        case "f43":
            id += 43;
            flow.setMatch(createICMPv6Match().build());
            flow.setInstructions(createDecNwTtlInstructions().build());
            break;
        case "f44":
            id += 44;
            flow.setMatch(createInphyportMatch(nodeBuilder.getId()).build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f45":
            id += 45;
            flow.setMatch(createMetadataMatch().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f46":
            id += 46;
            flow.setMatch(createL3IPv6Match().build());
            flow.setInstructions(createDecNwTtlInstructions().build());
            break;
        case "f47":
            id += 47;
            flow.setMatch(createL4SCTPMatch().build());
            flow.setInstructions(createAppyActionInstruction().build());
            break;
        case "f48":
            id += 48;
            flow.setMatch(createTunnelIDMatch().build());
            flow.setInstructions(createGotoTableInstructions().build());
            break;
        case "f49":
            id += 49;
            flow.setMatch(createVlanMatch().build());
            flow.setInstructions(createMeterInstructions().build());
            break;
        case "f50":
            id += 50;
            flow.setMatch(createPbbMatch().build());
            flow.setInstructions(createMeterInstructions().build());
            break;
        case "f51":
            id += 51;
            flow.setMatch(createVlanMatch().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f52":
            id += 52;
            flow.setMatch(createL4TCPMatch().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f53":
            id += 53;
            flow.setMatch(createL4UDPMatch().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f54":
            id += 54;
            flow.setMatch(new MatchBuilder().build());
            flow.setInstructions(createSentToControllerInstructions().build());
            flow.setPriority(0);
            break;
        case "f55":
            id += 55;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f56":
            id += 56;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createOutputInstructions("INPORT", 10).build());
            break;
        case "f57":
            id += 57;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createOutputInstructions("FLOOD", 20).build());
            break;
        case "f58":
            id += 58;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createOutputInstructions("ALL", 30).build());
            break;
        case "f59":
            id += 59;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createOutputInstructions("NORMAL", 40).build());
            break;
        case "f60":
            id += 60;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createOutputInstructions("LOCAL", 50).build());
            break;
        case "f61":
            id += 61;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createOutputInstructions("TABLE", 60).build());
            break;
        case "f62":
            id += 62;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createOutputInstructions("NONE", 70).build());
            break;
        case "f63":
            id += 63;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createStripVlanInstructions().build());
            flow.setBarrier(Boolean.TRUE);
            break;
        case "f64":
            id += 64;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction35().build());
            break;
        case "f65":
            id += 65;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction36().build());
            break;
        case "f66":
            id += 66;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction37().build());
            break;
        case "f67":
            id += 67;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createAppyActionInstruction38().build());
            break;
        case "f68":
            id += 68;
            flow.setMatch(createL4TCPMatch().build());
            flow.setInstructions(createAppyActionInstruction39().build());
            break;
        case "f69":
            id += 69;
            flow.setMatch(createL4UDPMatch().build());
            flow.setInstructions(createAppyActionInstruction40().build());
            break;
        case "f70":
            id += 70;
            flow.setMatch(createL4SCTPMatch().build());
            flow.setInstructions(createAppyActionInstruction41().build());
            break;
        case "f71":
            id += 71;
            flow.setMatch(createICMPv4Match().build());
            flow.setInstructions(createAppyActionInstruction42().build());
            break;
        case "f72":
            id += 72;
            flow.setMatch(createArpMatch().build());
            flow.setInstructions(createAppyActionInstruction43().build());
            break;
        case "f73":
            id += 73;
            flow.setMatch(createL3IPv6Match().build());
            flow.setInstructions(createAppyActionInstruction44().build());
            break;
        case "f74":
            id += 74;
            flow.setMatch(createICMPv6Match().build());
            flow.setInstructions(createAppyActionInstruction45().build());
            break;
        case "f75":
            id += 75;
            flow.setMatch(createMplsMatch().build());
            flow.setInstructions(createAppyActionInstruction46().build());
            break;
        case "f76":
            id += 76;
            flow.setMatch(createPbbMatch().build());
            flow.setInstructions(createAppyActionInstruction47().build());
            break;
        case "f77":
            id += 77;
            flow.setMatch(createTunnelIDMatch().build());
            flow.setInstructions(createAppyActionInstruction48().build());
            break;
        case "f78":
            id += 78;
            flow.setMatch(createMatch33().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f79":
            id += 79;
            flow.setMatch(createICMPv6Match1().build());
            flow.setInstructions(createDecNwTtlInstructions().build());
            break;
        case "f80":
            id += 80;
            flow.setMatch(createVlanMatch().build());
            flow.setInstructions(createAppyActionInstruction88().build());
            break;
        case "f81":
            id += 81;
            flow.setMatch(createLLDPMatch().build());
            flow.setInstructions(createSentToControllerInstructions().build());
            break;
        case "f82":
            id += 82;
            flow.setMatch(createToSMatch().build());
            flow.setInstructions(createOutputInstructions().build());
            break;
        case "f83":
            // Test TCP_Flag Match
            id += 83;
            flow.setMatch(createTcpFlagMatch().build());
            flow.setInstructions(createDropInstructions().build());
            break;
        case "f84":
            id += 84;
            // match vlan=10,dl_vlan_pcp=3
            flow.setMatch(createVlanMatch().build());
            // vlan_pcp=4
            flow.setInstructions(createAppyActionInstruction88().build());
            break;
        case "f85":
            // Test Tunnel IPv4 Src (e.g. set_field:172.16.100.200->tun_src)
            id += 85;
            flow.setMatch(createMatch3().build());
            flow.setInstructions(createTunnelIpv4SrcInstructions().build());
            break;
        case "f86":
            // Test Tunnel IPv4 Dst (e.g. set_field:172.16.100.100->tun_dst)
            id += 86;
            flow.setMatch(createMatch1().build());
            flow.setInstructions(createTunnelIpv4DstInstructions().build());
            break;
        default:
            LOG.warn("flow type not understood: {}", flowType);
    }
    final FlowKey key = new FlowKey(new FlowId(Long.toString(id)));
    if (null == flow.isBarrier()) {
        flow.setBarrier(Boolean.FALSE);
    }
    final BigInteger value = BigInteger.valueOf(10);
    flow.setCookie(new FlowCookie(value));
    flow.setCookieMask(new FlowCookie(value));
    flow.setHardTimeout(0);
    flow.setIdleTimeout(0);
    flow.setInstallHw(false);
    flow.setStrict(false);
    flow.setContainerName(null);
    flow.setFlags(new FlowModFlags(false, false, false, false, true));
    flow.setId(new FlowId("12"));
    flow.setTableId(getTableId(tableId));
    flow.setKey(key);
    flow.setFlowName(ORIGINAL_FLOW_NAME + "X" + flowType);
    return flow;
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) BigInteger(java.math.BigInteger) ArpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder) Icmpv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder) TunnelIpv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) TcpFlagsMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Ipv6MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder) IpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder) Icmpv6MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder) SctpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder) UdpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)

Example 15 with FlowModFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags in project openflowplugin by opendaylight.

the class Test method testFlow.

@Override
public Future<RpcResult<Void>> testFlow(TestFlowInput input) {
    AddFlowInputBuilder flow = new AddFlowInputBuilder();
    flow.setPriority(2);
    flow.setMatch(createMatchBld().build());
    flow.setInstructions(createDecNwTtlInstructionsBld().build());
    flow.setBarrier(Boolean.FALSE);
    BigInteger value = BigInteger.valueOf(10L);
    flow.setCookie(new FlowCookie(value));
    flow.setCookieMask(new FlowCookie(value));
    flow.setHardTimeout(0);
    flow.setIdleTimeout(0);
    flow.setInstallHw(false);
    flow.setStrict(false);
    flow.setContainerName(null);
    flow.setFlags(new FlowModFlags(false, false, false, false, true));
    flow.setTableId((short) 0);
    flow.setFlowName("NiciraFLOW");
    // Construct the flow instance id
    final InstanceIdentifier<Node> flowInstanceId = InstanceIdentifier.builder(// File under nodes
    Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:1"))).build();
    flow.setNode(new NodeRef(flowInstanceId));
    pushFlowViaRpc(flow.build());
    return Futures.immediateFuture(RpcResultBuilder.<Void>status(true).build());
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) BigInteger(java.math.BigInteger) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Aggregations

FlowModFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags)16 BigInteger (java.math.BigInteger)12 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)12 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)11 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)10 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)9 Test (org.junit.Test)8 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)7 FlowModFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags)7 ByteBuf (io.netty.buffer.ByteBuf)3 ArrayList (java.util.ArrayList)3 InstructionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder)3 FlowModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder)3 Optional (com.google.common.base.Optional)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)2 Counter32 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32)2 Counter64 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64)2 OutputActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder)2 OutputActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder)2