Search in sources :

Example 6 with WriteMetadataCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase in project genius by opendaylight.

the class FlowBasedServicesUtils method installLPortDispatcherFlow.

public static void installLPortDispatcherFlow(BigInteger dpId, BoundServices boundService, String interfaceName, WriteTransaction writeTransaction, int interfaceTag, short currentServiceIndex, short nextServiceIndex) {
    String serviceRef = boundService.getServiceName();
    List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForDispatcherTable(interfaceTag, currentServiceIndex);
    // Get the metadata and mask from the service's write metadata
    // instruction
    StypeOpenflow stypeOpenFlow = boundService.getAugmentation(StypeOpenflow.class);
    List<Instruction> serviceInstructions = stypeOpenFlow.getInstruction();
    int instructionSize = serviceInstructions != null ? serviceInstructions.size() : 0;
    BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(serviceInstructions);
    BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(interfaceTag, nextServiceIndex, metadataValues[0]);
    BigInteger metadataMask = MetaDataUtil.getWriteMetaDataMaskForDispatcherTable();
    // build the final instruction for LPort Dispatcher table flow entry
    List<Instruction> instructions = new ArrayList<>();
    instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadata, metadataMask, ++instructionSize));
    if (serviceInstructions != null && !serviceInstructions.isEmpty()) {
        for (Instruction info : serviceInstructions) {
            // Skip meta data write as that is handled already
            if (info.getInstruction() instanceof WriteMetadataCase) {
                continue;
            } else if (info.getInstruction() instanceof WriteActionsCase) {
                info = MDSALUtil.buildWriteActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction(((WriteActionsCase) info.getInstruction()).getWriteActions().getAction()));
            } else if (info.getInstruction() instanceof ApplyActionsCase) {
                info = MDSALUtil.buildApplyActionsInstruction(ActionConverterUtil.convertServiceActionToFlowAction(((ApplyActionsCase) info.getInstruction()).getApplyActions().getAction()));
            }
            instructions.add(info);
        }
    }
    // build the flow and install it
    String flowRef = getFlowRef(dpId, NwConstants.LPORT_DISPATCHER_TABLE, interfaceName, currentServiceIndex);
    Flow ingressFlow = MDSALUtil.buildFlowNew(NwConstants.LPORT_DISPATCHER_TABLE, flowRef, DEFAULT_DISPATCHER_PRIORITY, serviceRef, 0, 0, stypeOpenFlow.getFlowCookie(), matches, instructions);
    LOG.debug("Installing LPort Dispatcher Flow on DPN {}, for interface {}, with flowRef {}", dpId, interfaceName, flowRef);
    installFlow(dpId, ingressFlow, writeTransaction);
}
Also used : WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase) StypeOpenflow(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.StypeOpenflow) ArrayList(java.util.ArrayList) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) BigInteger(java.math.BigInteger) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)

Example 7 with WriteMetadataCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase in project genius by opendaylight.

the class IfmUtil method mergeOpenflowMetadataWriteInstructions.

public static BigInteger[] mergeOpenflowMetadataWriteInstructions(List<Instruction> instructions) {
    BigInteger metadata = new BigInteger("0", 16);
    BigInteger metadataMask = new BigInteger("0", 16);
    if (instructions != null && !instructions.isEmpty()) {
        // check if metadata write instruction is present
        for (Instruction instruction : instructions) {
            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction actualInstruction = instruction.getInstruction();
            if (actualInstruction instanceof WriteMetadataCase) {
                WriteMetadataCase writeMetaDataInstruction = (WriteMetadataCase) actualInstruction;
                WriteMetadata availableMetaData = writeMetaDataInstruction.getWriteMetadata();
                metadata = metadata.or(availableMetaData.getMetadata());
                metadataMask = metadataMask.or(availableMetaData.getMetadataMask());
            }
        }
    }
    return new BigInteger[] { metadata, metadataMask };
}
Also used : WriteMetadata(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata) WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase) BigInteger(java.math.BigInteger) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)

Example 8 with WriteMetadataCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase in project genius by opendaylight.

the class InstructionWriteMetadataTest method verifyInstructionInfo.

private void verifyInstructionInfo(InstructionInfo instructionInfo) {
    Instruction instruction = instructionInfo.buildInstruction(2);
    assertEquals(2, instruction.getKey().getOrder().intValue());
    assertTrue(instruction.getInstruction() instanceof WriteMetadataCase);
    WriteMetadataCase writeMetadataCase = (WriteMetadataCase) instruction.getInstruction();
    WriteMetadata writeMetadata = writeMetadataCase.getWriteMetadata();
    assertEquals(BigInteger.ONE, writeMetadata.getMetadata());
    assertEquals(BigInteger.TEN, writeMetadata.getMetadataMask());
}
Also used : WriteMetadata(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata) WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)

Example 9 with WriteMetadataCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase in project openflowplugin by opendaylight.

the class WriteMetadataInstructionSerializer method serialize.

@Override
public void serialize(Instruction instruction, ByteBuf outBuffer) {
    outBuffer.writeShort(getType());
    outBuffer.writeShort(InstructionConstants.WRITE_METADATA_LENGTH);
    outBuffer.writeZero(InstructionConstants.PADDING_IN_WRITE_METADATA);
    WriteMetadata metadata = ((WriteMetadataCase) instruction.getInstructionChoice()).getWriteMetadata();
    outBuffer.writeBytes(metadata.getMetadata());
    outBuffer.writeBytes(metadata.getMetadataMask());
}
Also used : WriteMetadata(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.metadata._case.WriteMetadata) WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase)

Example 10 with WriteMetadataCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase in project openflowplugin by opendaylight.

the class InstructionsDeserializerTest method test.

/**
 * Testing instructions translation.
 */
@Test
public void test() {
    ByteBuf message = BufferHelper.buildBuffer("00 01 00 08 0A 00 00 00 00 02 00 18 00 00 00 00 " + "00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 30 00 05 00 08 00 00 00 00 00 06 00 08 " + "00 01 02 03 00 03 00 20 00 00 00 00 00 00 00 10 00 00 00 25 00 35 00 00 00 00 00 00 " + "00 16 00 08 00 00 00 50 00 04 00 18 00 00 00 00 00 15 00 08 00 00 00 25 00 0F 00 08 05 00 00 00");
    // skip XID
    message.skipBytes(4);
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, message.readableBytes(), message, keyMaker, registry);
    Instruction i1 = instructions.get(0);
    Assert.assertTrue("Wrong type - i1", i1.getInstructionChoice() instanceof GotoTableCase);
    Assert.assertEquals("Wrong table-id - i1", 10, ((GotoTableCase) i1.getInstructionChoice()).getGotoTable().getTableId().intValue());
    Instruction i2 = instructions.get(1);
    Assert.assertTrue("Wrong type - i2", i2.getInstructionChoice() instanceof WriteMetadataCase);
    Assert.assertArrayEquals("Wrong metadata - i2", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 20"), ((WriteMetadataCase) i2.getInstructionChoice()).getWriteMetadata().getMetadata());
    Assert.assertArrayEquals("Wrong metadata-mask - i2", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 30"), ((WriteMetadataCase) i2.getInstructionChoice()).getWriteMetadata().getMetadataMask());
    Instruction i3 = instructions.get(2);
    Assert.assertTrue("Wrong type - i3", i3.getInstructionChoice() instanceof ClearActionsCase);
    Instruction i4 = instructions.get(3);
    Assert.assertTrue("Wrong type - i4", i4.getInstructionChoice() instanceof MeterCase);
    Assert.assertEquals("Wrong meterId - i4", 66051, ((MeterCase) i4.getInstructionChoice()).getMeter().getMeterId().intValue());
    Instruction i5 = instructions.get(4);
    Assert.assertTrue("Wrong type - i5", i5.getInstructionChoice() instanceof WriteActionsCase);
    Assert.assertEquals("Wrong instructions - i5", 2, ((WriteActionsCase) i5.getInstructionChoice()).getWriteActions().getAction().size());
    Action action1 = ((WriteActionsCase) i5.getInstructionChoice()).getWriteActions().getAction().get(0);
    Assert.assertTrue("Wrong action", action1.getActionChoice() instanceof OutputActionCase);
    Assert.assertEquals("Wrong action", 37, ((OutputActionCase) action1.getActionChoice()).getOutputAction().getPort().getValue().intValue());
    Assert.assertEquals("Wrong action", 53, ((OutputActionCase) action1.getActionChoice()).getOutputAction().getMaxLength().intValue());
    Action action2 = ((WriteActionsCase) i5.getInstructionChoice()).getWriteActions().getAction().get(1);
    Assert.assertTrue("Wrong action", action2.getActionChoice() instanceof GroupCase);
    Assert.assertEquals("Wrong action", 80, ((GroupCase) action2.getActionChoice()).getGroupAction().getGroupId().intValue());
    Instruction i6 = instructions.get(5);
    Assert.assertTrue("Wrong type - i6", i6.getInstructionChoice() instanceof ApplyActionsCase);
    Assert.assertEquals("Wrong instructions - i6", 2, ((ApplyActionsCase) i6.getInstructionChoice()).getApplyActions().getAction().size());
    action1 = ((ApplyActionsCase) i6.getInstructionChoice()).getApplyActions().getAction().get(0);
    Assert.assertTrue("Wrong action", action1.getActionChoice() instanceof SetQueueCase);
    Assert.assertEquals("Wrong action", 37, ((SetQueueCase) action1.getActionChoice()).getSetQueueAction().getQueueId().intValue());
    action2 = ((ApplyActionsCase) i6.getInstructionChoice()).getApplyActions().getAction().get(1);
    Assert.assertTrue("Wrong action", action2.getActionChoice() instanceof SetMplsTtlCase);
    Assert.assertEquals("Wrong action", 5, ((SetMplsTtlCase) action2.getActionChoice()).getSetMplsTtlAction().getMplsTtl().shortValue());
}
Also used : GotoTableCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) 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) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase) SetQueueCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase) SetMplsTtlCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCase) GroupCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCase) ByteBuf(io.netty.buffer.ByteBuf) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction) ClearActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase) OutputActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase) Test(org.junit.Test)

Aggregations

Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)9 ArrayList (java.util.ArrayList)7 BigInteger (java.math.BigInteger)6 WriteMetadataCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase)6 ApplyActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase)5 GotoTableCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase)5 MeterCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCase)5 WriteActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase)5 WriteMetadataCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase)5 ApplyActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)4 WriteActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase)4 Test (org.junit.Test)3 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)3 ApplyActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder)3 ClearActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCaseBuilder)3 GoToTableCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder)3 MeterCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder)3 WriteActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder)3 WriteMetadataCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder)3 ApplyActionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder)3