Search in sources :

Example 66 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata in project openflowplugin by opendaylight.

the class WriteMetadataInstructionSerializerTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    final long metadata = 10L;
    final long metadataMask = 10L;
    final Instruction instruction = new WriteMetadataCaseBuilder().setWriteMetadata(new WriteMetadataBuilder().setMetadata(BigInteger.valueOf(metadata)).setMetadataMask(BigInteger.valueOf(metadataMask)).build()).build();
    assertInstruction(instruction, out -> {
        out.skipBytes(InstructionConstants.PADDING_IN_WRITE_METADATA);
        assertEquals(out.readLong(), metadata);
        assertEquals(out.readLong(), metadataMask);
    });
}
Also used : WriteMetadataCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) WriteMetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder) Test(org.junit.Test)

Example 67 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata in project openflowplugin by opendaylight.

the class MetadataEntryDeserializerTest method deserializeEntry.

@Test
public void deserializeEntry() throws Exception {
    final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
    final BigInteger metadata = BigInteger.valueOf(20);
    final BigInteger metadataMask = BigInteger.valueOf(30);
    writeHeader(in, false);
    in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadata, getValueLength()));
    assertEquals(metadata, deserialize(in).getMetadata().getMetadata());
    assertEquals(0, in.readableBytes());
    writeHeader(in, true);
    in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadata, getValueLength()));
    in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadataMask, getValueLength()));
    final Metadata desMetadata = deserialize(in).getMetadata();
    assertEquals(metadata, desMetadata.getMetadata());
    assertEquals(metadataMask, desMetadata.getMetadataMask());
    assertEquals(0, in.readableBytes());
}
Also used : Metadata(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata) BigInteger(java.math.BigInteger) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 68 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata in project openflowplugin by opendaylight.

the class WriteMetadataInstructionDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
    final BigInteger metadata = BigInteger.valueOf(1234L);
    final BigInteger metadataMask = BigInteger.valueOf(9876L);
    writeHeader(in);
    in.writeZero(InstructionConstants.PADDING_IN_WRITE_METADATA);
    in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadata, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
    in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadataMask, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
    final Instruction instruction = deserializeInstruction(in);
    assertEquals(WriteMetadataCase.class, instruction.getImplementedInterface());
    assertArrayEquals(ByteUtil.convertBigIntegerToNBytes(metadata, EncodeConstants.SIZE_OF_LONG_IN_BYTES), ByteUtil.convertBigIntegerToNBytes(WriteMetadataCase.class.cast(instruction).getWriteMetadata().getMetadata(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
    assertArrayEquals(ByteUtil.convertBigIntegerToNBytes(metadataMask, EncodeConstants.SIZE_OF_LONG_IN_BYTES), ByteUtil.convertBigIntegerToNBytes(WriteMetadataCase.class.cast(instruction).getWriteMetadata().getMetadataMask(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
    assertEquals(0, in.readableBytes());
}
Also used : BigInteger(java.math.BigInteger) ByteBuf(io.netty.buffer.ByteBuf) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) Test(org.junit.Test)

Example 69 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata 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 70 with Metadata

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Metadata in project openflowplugin by opendaylight.

the class FlowModInputMessageFactoryTest method createInstructions.

private List<Instruction> createInstructions() {
    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();
    byte[] metadata = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
    metadataBuilder.setMetadata(metadata);
    byte[] metadataMask = new byte[] { (byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30 };
    metadataBuilder.setMetadataMask(metadataMask);
    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());
    return instructions;
}
Also used : 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) 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) WriteMetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.metadata._case.WriteMetadataBuilder) 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) GotoTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice._goto.table._case.GotoTableBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) ApplyActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.apply.actions._case.ApplyActionsBuilder)

Aggregations

BigInteger (java.math.BigInteger)44 ArrayList (java.util.ArrayList)36 Test (org.junit.Test)25 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)14 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)13 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)13 ByteBuf (io.netty.buffer.ByteBuf)10 MetadataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder)10 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)8 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)7 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)7 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)7 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)7 MatchTunnelId (org.opendaylight.genius.mdsalutil.matches.MatchTunnelId)6 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)6 Metadata (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata)6 WriteMetadataCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCaseBuilder)6 InstructionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder)6 List (java.util.List)5