Search in sources :

Example 11 with WriteActionsCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder in project genius by opendaylight.

the class MDSALUtil method buildWriteActionsInstruction.

/**
 * Build write actions instruction with the given actions and key.
 *
 * @param actions the actions.
 * @param instructionKey the instruction key.
 * @return the instruction.
 */
public static Instruction buildWriteActionsInstruction(List<Action> actions, int instructionKey) {
    WriteActions writeActions = new WriteActionsBuilder().setAction(actions).build();
    WriteActionsCase writeActionsCase = new WriteActionsCaseBuilder().setWriteActions(writeActions).build();
    InstructionBuilder instructionBuilder = new InstructionBuilder();
    instructionBuilder.setInstruction(writeActionsCase);
    instructionBuilder.setKey(new InstructionKey(instructionKey));
    return instructionBuilder.build();
}
Also used : InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder) WriteActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder) WriteActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder) WriteActions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase) InstructionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey)

Example 12 with WriteActionsCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder in project openflowplugin by opendaylight.

the class FlowStatsResponseConvertorTest method testToSALInstruction.

/**
 * Test method for {@link FlowInstructionResponseConvertor#convert(List, VersionConvertorData)} }.
 */
@Test
public void testToSALInstruction() {
    List<Instruction> instructionsList = new ArrayList<>();
    InstructionBuilder instructionBuilder = new InstructionBuilder();
    for (int i = 0; i < PRESET_COUNT; i++) {
        ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
        ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder();
        ActionBuilder actionBuilder = new ActionBuilder();
        List<Action> actions = new ArrayList<>();
        for (int j = 0; j < PRESET_COUNT; j++) {
            actions.add(actionBuilder.build());
        }
        applyActionsBuilder.setAction(actions);
        applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build());
        instructionBuilder.setInstructionChoice(applyActionsCaseBuilder.build());
        instructionsList.add(instructionBuilder.build());
    }
    Instructions instructions;
    VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
    instructions = convert(instructionsList, data);
    assertNotNull(instructions);
    assertEquals(PRESET_COUNT, instructions.getInstruction().size());
    instructionsList = new ArrayList<>();
    for (int i = 0; i < PRESET_COUNT; i++) {
        GotoTableCaseBuilder gotoTableCaseBuilder = new GotoTableCaseBuilder();
        GotoTableBuilder gotoTableBuilder = new GotoTableBuilder();
        gotoTableBuilder.setTableId((short) i);
        gotoTableCaseBuilder.setGotoTable(gotoTableBuilder.build());
        instructionBuilder.setInstructionChoice(gotoTableCaseBuilder.build());
        instructionsList.add(instructionBuilder.build());
    }
    instructions = convert(instructionsList, data);
    assertNotNull(instructions);
    assertEquals(PRESET_COUNT, instructions.getInstruction().size());
    instructionsList = new ArrayList<>();
    for (int i = 0; i < PRESET_COUNT; i++) {
        MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
        MeterBuilder meterBuilder = new MeterBuilder();
        meterBuilder.setMeterId((long) i);
        meterCaseBuilder.setMeter(meterBuilder.build());
        instructionBuilder.setInstructionChoice(meterCaseBuilder.build());
        instructionsList.add(instructionBuilder.build());
    }
    instructions = convert(instructionsList, data);
    assertNotNull(instructions);
    assertEquals(PRESET_COUNT, instructions.getInstruction().size());
    instructionsList = new ArrayList<>();
    for (int i = 0; i < PRESET_COUNT; i++) {
        WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder();
        WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder();
        ActionBuilder actionBuilder = new ActionBuilder();
        List<Action> actions = new ArrayList<>();
        for (int j = 0; j < PRESET_COUNT; j++) {
            actions.add(actionBuilder.build());
        }
        writeActionsBuilder.setAction(actions);
        writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build());
        instructionBuilder.setInstructionChoice(writeActionsCaseBuilder.build());
        instructionsList.add(instructionBuilder.build());
    }
    instructions = convert(instructionsList, data);
    assertNotNull(instructions);
    assertEquals(PRESET_COUNT, instructions.getInstruction().size());
    instructionsList = new ArrayList<>();
    for (int i = 0; i < PRESET_COUNT; i++) {
        ClearActionsCaseBuilder clearActionsCaseBuilder = new ClearActionsCaseBuilder();
        instructionBuilder.setInstructionChoice(clearActionsCaseBuilder.build());
        instructionsList.add(instructionBuilder.build());
    }
    instructions = convert(instructionsList, data);
    assertNotNull(instructions);
    int instructionSize = instructions.getInstruction().size();
    assertEquals(PRESET_COUNT, instructionSize);
    instructionsList = new ArrayList<>();
    for (int i = 0; i < PRESET_COUNT; i++) {
        WriteMetadataCaseBuilder metadataCaseBuilder = new WriteMetadataCaseBuilder();
        WriteMetadataBuilder metadataBuilder = new WriteMetadataBuilder();
        metadataBuilder.setMetadata(BigInteger.TEN.setBit(i).toByteArray());
        metadataBuilder.setMetadataMask(BigInteger.ONE.setBit(i).toByteArray());
        metadataCaseBuilder.setWriteMetadata(metadataBuilder.build());
        instructionBuilder.setInstructionChoice(metadataCaseBuilder.build());
        instructionsList.add(instructionBuilder.build());
    }
    instructions = convert(instructionsList, data);
    assertNotNull(instructions);
    assertEquals(PRESET_COUNT, instructions.getInstruction().size());
}
Also used : MeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.meter._case.MeterBuilder) InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) WriteActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.actions._case.WriteActionsBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) WriteActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder) 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) Instructions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction) WriteMetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.metadata._case.WriteMetadataBuilder) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) ApplyActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCaseBuilder) GotoTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice._goto.table._case.GotoTableBuilder) ClearActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCaseBuilder) ApplyActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.apply.actions._case.ApplyActionsBuilder) MeterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCaseBuilder) Test(org.junit.Test)

Example 13 with WriteActionsCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder in project openflowplugin by opendaylight.

the class WriteActionsInstructionDeserializer method deserializeHeader.

@Override
public Instruction deserializeHeader(ByteBuf input) {
    InstructionBuilder builder = new InstructionBuilder();
    input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    builder.setInstructionChoice(new WriteActionsCaseBuilder().build());
    return builder.build();
}
Also used : InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder) WriteActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder)

Example 14 with WriteActionsCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder in project openflowplugin by opendaylight.

the class TableFeaturesResponseConvertor method setInstructionTableFeatureProperty.

private static List<Instruction> setInstructionTableFeatureProperty(final TableFeatureProperties properties) {
    List<Instruction> instructionList = new ArrayList<>();
    org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder();
    int index = 0;
    for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction currInstruction : properties.getAugmentation(InstructionRelatedTableFeatureProperty.class).getInstruction()) {
        InstructionChoice currInstructionType = currInstruction.getInstructionChoice();
        if (currInstructionType instanceof GotoTableCase) {
            builder.setInstruction(new GoToTableCaseBuilder().setGoToTable(new GoToTableBuilder().build()).build());
        } else if (currInstructionType instanceof WriteMetadataCase) {
            builder.setInstruction(new WriteMetadataCaseBuilder().setWriteMetadata(new WriteMetadataBuilder().build()).build());
        } else if (currInstructionType instanceof WriteActionsCase) {
            builder.setInstruction(new WriteActionsCaseBuilder().setWriteActions(new WriteActionsBuilder().build()).build());
        } else if (currInstructionType instanceof ApplyActionsCase) {
            builder.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(new ApplyActionsBuilder().build()).build());
        } else if (currInstructionType instanceof ClearActionsCase) {
            builder.setInstruction(new ClearActionsCaseBuilder().setClearActions(new ClearActionsBuilder().build()).build());
        } else if (currInstructionType instanceof MeterCase) {
            builder.setInstruction(new MeterCaseBuilder().setMeter(new MeterBuilder().build()).build());
        }
        // TODO: Experimenter instructions are unhandled
        builder.setOrder(index);
        index += 1;
        instructionList.add(builder.build());
    }
    return instructionList;
}
Also used : MeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder) WriteMetadataCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder) WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase) MeterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCase) ArrayList(java.util.ArrayList) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) WriteMetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder) ApplyActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder) ClearActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCaseBuilder) ApplyActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder) GoToTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder) MeterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder) GotoTableCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase) InstructionRelatedTableFeatureProperty(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeatureProperty) WriteActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder) WriteActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder) ClearActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.clear.actions._case.ClearActionsBuilder) GoToTableCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder) ClearActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase) InstructionChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.InstructionChoice) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase)

Example 15 with WriteActionsCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder in project openflowplugin by opendaylight.

the class WriteActionsCase method process.

@Override
public Optional<Instruction> process(@Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
    WriteActions writeActions = source.getWriteActions();
    WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder();
    WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder();
    final Optional<List<Action>> actions = convertorExecutor.convert(writeActions.getAction(), data);
    writeActionsBuilder.setAction(actions.orElse(Collections.emptyList()));
    writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build());
    InstructionBuilder instructionBuilder = new InstructionBuilder();
    instructionBuilder.setInstructionChoice(writeActionsCaseBuilder.build());
    return Optional.of(instructionBuilder.build());
}
Also used : InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder) WriteActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.actions._case.WriteActionsBuilder) WriteActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder) WriteActions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)10 WriteActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder)10 InstructionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder)10 Test (org.junit.Test)7 ApplyActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCaseBuilder)7 ClearActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCaseBuilder)7 GotoTableCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCaseBuilder)7 MeterCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCaseBuilder)7 WriteMetadataCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCaseBuilder)7 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)6 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder)6 WriteActionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.actions._case.WriteActionsBuilder)6 WriteActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder)5 WriteActionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder)5 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction)5 BigInteger (java.math.BigInteger)4 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)4 InstructionRelatedTableFeaturePropertyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.InstructionRelatedTableFeaturePropertyBuilder)4 OutputActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder)4 PushVlanActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder)4