Example usage for io.netty.buffer ByteBuf skipBytes

List of usage examples for io.netty.buffer ByteBuf skipBytes

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf skipBytes.

Prototype

public abstract ByteBuf skipBytes(int length);

Source Link

Document

Increases the current readerIndex by the specified length in this buffer.

Usage

From source file:org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactoryTest.java

License:Open Source License

/**
 * Tests {@link CodeKeyMakerFactory#createMatchEntriesKeyMaker(short)}
 *///ww  w .j av a2s  .c o m
@Test
public void testExperimenterMatchEntriesKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);

    ByteBuf buffer = BufferHelper.buildBuffer("FF FF 00 04 00 00 00 01");
    buffer.skipBytes(4); // skip XID
    MessageCodeKey codeKey = keyMaker.make(buffer);

    Assert.assertNotNull("Null key", codeKey);
    MatchEntryDeserializerKey comparationKey = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
            65535, 0);
    comparationKey.setExperimenterId(1L);
    Assert.assertEquals("Wrong key", comparationKey, codeKey);
    Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactoryTest.java

License:Open Source License

/**
 * Tests {@link CodeKeyMakerFactory#createActionsKeyMaker(short)}
 *//*from   w ww. j a  v a2  s. co  m*/
@Test
public void testActionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);

    ByteBuf buffer = BufferHelper.buildBuffer("00 00 00 10 00 00 00 01 00 02 00 00 00 00 00 00");
    buffer.skipBytes(4); // skip XID
    MessageCodeKey codeKey = keyMaker.make(buffer);

    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 0, null),
            codeKey);
    Assert.assertEquals("Buffer index modified", 16, buffer.readableBytes());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactoryTest.java

License:Open Source License

/**
 * Tests {@link CodeKeyMakerFactory#createActionsKeyMaker(short)}
 *///from w  w  w  .  j a  va  2s. c o m
@Test
public void testExperimenterActionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);

    ByteBuf buffer = BufferHelper.buildBuffer("FF FF 00 08 00 00 00 01");
    buffer.skipBytes(4); // skip XID
    MessageCodeKey codeKey = keyMaker.make(buffer);

    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 65535, 1L),
            codeKey);
    Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactoryTest.java

License:Open Source License

/**
 * Tests {@link CodeKeyMakerFactory#createInstructionsKeyMaker(short)}
 *///w  w  w  .j av a 2s. c  o m
@Test
public void testInstructionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);

    ByteBuf buffer = BufferHelper.buildBuffer("00 00 00 08");
    buffer.skipBytes(4); // skip XID
    MessageCodeKey codeKey = keyMaker.make(buffer);

    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new InstructionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 0, null),
            codeKey);
    Assert.assertEquals("Buffer index modified", 4, buffer.readableBytes());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactoryTest.java

License:Open Source License

/**
 * Tests {@link CodeKeyMakerFactory#createInstructionsKeyMaker(short)}
 *///from   ww w. j  a v a 2  s.co  m
@Test
public void testExperimenterInstructionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);

    ByteBuf buffer = BufferHelper.buildBuffer("FF FF 00 08 00 00 00 01");
    buffer.skipBytes(4); // skip XID
    MessageCodeKey codeKey = keyMaker.make(buffer);

    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new InstructionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 65535, 1L),
            codeKey);
    Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.InstructionsDeserializer.java

License:Open Source License

private static void createGotoTableInstruction(InstructionBuilder builder, ByteBuf input) {
    builder.setType(GotoTable.class);
    TableIdInstructionBuilder tableBuilder = new TableIdInstructionBuilder();
    tableBuilder.setTableId(input.readUnsignedByte());
    builder.addAugmentation(TableIdInstruction.class, tableBuilder.build());
    input.skipBytes(GOTO_TABLE_PADDING);
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.InstructionsDeserializer.java

License:Open Source License

private static void createMetadataInstruction(InstructionBuilder builder, ByteBuf input) {
    input.skipBytes(WRITE_METADATA_PADDING);
    builder.setType(WriteMetadata.class);
    MetadataInstructionBuilder metadataBuilder = new MetadataInstructionBuilder();
    byte[] metadata = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    input.readBytes(metadata);//from www  . ja va2 s .  com
    metadataBuilder.setMetadata(metadata);
    byte[] metadata_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    input.readBytes(metadata_mask);
    metadataBuilder.setMetadataMask(metadata_mask);
    builder.addAugmentation(MetadataInstruction.class, metadataBuilder.build());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.InstructionsDeserializer.java

License:Open Source License

private static void createActionRelatedInstruction(ByteBuf input, InstructionBuilder builder,
        int actionsLength) {
    input.skipBytes(ACTIONS_RELATED_INSTRUCTION_PADDING);
    ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder();
    actionsBuilder.setAction(ActionsDeserializer.createActions(input, actionsLength));
    builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.InstructionsDeserializerTest.java

License:Open Source License

/**
 * Testing instructions translation//w  w w .j  ava  2 s.  c o  m
 */
@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");

    message.skipBytes(4); // skip XID
    List<Instruction> instructions = InstructionsDeserializer.createInstructions(message,
            message.readableBytes());
    Instruction i1 = instructions.get(0);
    Assert.assertEquals("Wrong type - i1", "org.opendaylight.yang.gen.v1.urn."
            + "opendaylight.openflow.common.instruction.rev130731.GotoTable", i1.getType().getName());
    Assert.assertEquals("Wrong table-id - i1", 10,
            i1.getAugmentation(TableIdInstruction.class).getTableId().intValue());
    Instruction i2 = instructions.get(1);
    Assert.assertEquals("Wrong type - i2",
            "org.opendaylight.yang.gen.v1.urn."
                    + "opendaylight.openflow.common.instruction.rev130731.WriteMetadata",
            i2.getType().getName());
    Assert.assertArrayEquals("Wrong metadata - i2", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 20"),
            i2.getAugmentation(MetadataInstruction.class).getMetadata());
    Assert.assertArrayEquals("Wrong metadata-mask - i2",
            ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 30"),
            i2.getAugmentation(MetadataInstruction.class).getMetadataMask());
    Instruction i3 = instructions.get(2);
    Assert.assertEquals("Wrong type - i3",
            "org.opendaylight.yang.gen.v1.urn."
                    + "opendaylight.openflow.common.instruction.rev130731.ClearActions",
            i3.getType().getName());
    Assert.assertEquals("Wrong instructions - i3", 0,
            i3.getAugmentation(ActionsInstruction.class).getAction().size());
    Instruction i4 = instructions.get(3);
    Assert.assertEquals("Wrong type - i4",
            "org.opendaylight.yang.gen.v1.urn." + "opendaylight.openflow.common.instruction.rev130731.Meter",
            i4.getType().getName());
    Assert.assertEquals("Wrong meterId - i4", 66051,
            i4.getAugmentation(MeterIdInstruction.class).getMeterId().intValue());
    Instruction i5 = instructions.get(4);
    Assert.assertEquals("Wrong type - i5",
            "org.opendaylight.yang.gen.v1.urn."
                    + "opendaylight.openflow.common.instruction.rev130731.WriteActions",
            i5.getType().getName());
    Assert.assertEquals("Wrong instructions - i5", 2,
            i5.getAugmentation(ActionsInstruction.class).getAction().size());
    Action action1 = i5.getAugmentation(ActionsInstruction.class).getAction().get(0);
    Assert.assertEquals("Wrong action",
            "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output",
            action1.getType().getName());
    Assert.assertEquals("Wrong action", 37,
            action1.getAugmentation(PortAction.class).getPort().getValue().intValue());
    Assert.assertEquals("Wrong action", 53,
            action1.getAugmentation(MaxLengthAction.class).getMaxLength().intValue());
    Action action2 = i5.getAugmentation(ActionsInstruction.class).getAction().get(1);
    Assert.assertEquals("Wrong action",
            "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group",
            action2.getType().getName());
    Assert.assertEquals("Wrong action", 80,
            action2.getAugmentation(GroupIdAction.class).getGroupId().intValue());
    Instruction i6 = instructions.get(5);
    Assert.assertEquals("Wrong type - i6",
            "org.opendaylight.yang.gen.v1.urn."
                    + "opendaylight.openflow.common.instruction.rev130731.ApplyActions",
            i6.getType().getName());
    Assert.assertEquals("Wrong instructions - i6", 2,
            i6.getAugmentation(ActionsInstruction.class).getAction().size());
    action1 = i6.getAugmentation(ActionsInstruction.class).getAction().get(0);
    Assert.assertEquals("Wrong action",
            "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue",
            action1.getType().getName());
    Assert.assertEquals("Wrong action", 37,
            action1.getAugmentation(QueueIdAction.class).getQueueId().intValue());
    action2 = i6.getAugmentation(ActionsInstruction.class).getAction().get(1);
    Assert.assertEquals("Wrong action",
            "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl",
            action2.getType().getName());
    Assert.assertEquals("Wrong action", 5,
            action2.getAugmentation(MplsTtlAction.class).getMplsTtl().intValue());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializerTest.java

License:Open Source License

/**
 * Testing instructions translation// w  ww  .  j  a  v  a 2 s .c  o  m
 */
@Test
public void test() {
    List<Instruction> instructions = new ArrayList<>();
    // Goto_table instruction
    InstructionBuilder builder = new InstructionBuilder();
    builder.setType(GotoTable.class);
    TableIdInstructionBuilder tableIdBuilder = new TableIdInstructionBuilder();
    tableIdBuilder.setTableId((short) 5);
    builder.addAugmentation(TableIdInstruction.class, tableIdBuilder.build());
    instructions.add(builder.build());
    builder = new InstructionBuilder();
    // Write_metadata instruction
    builder.setType(WriteMetadata.class);
    MetadataInstructionBuilder metaBuilder = new MetadataInstructionBuilder();
    metaBuilder.setMetadata(ByteBufUtils.hexStringToBytes("00 01 02 03 04 05 06 07"));
    metaBuilder.setMetadataMask(ByteBufUtils.hexStringToBytes("07 06 05 04 03 02 01 00"));
    builder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
    instructions.add(builder.build());
    // Clear_actions instruction
    builder = new InstructionBuilder();
    builder.setType(ClearActions.class);
    instructions.add(builder.build());
    // Meter instruction
    builder = new InstructionBuilder();
    builder.setType(Meter.class);
    MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder();
    meterBuilder.setMeterId(42L);
    builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build());
    instructions.add(builder.build());
    // Write_actions instruction
    builder = new InstructionBuilder();
    builder.setType(WriteActions.class);
    ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder();
    List<Action> actions = new ArrayList<>();
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setType(Output.class);
    PortActionBuilder portBuilder = new PortActionBuilder();
    portBuilder.setPort(new PortNumber(45L));
    actionBuilder.addAugmentation(PortAction.class, portBuilder.build());
    MaxLengthActionBuilder maxBuilder = new MaxLengthActionBuilder();
    maxBuilder.setMaxLength(55);
    actionBuilder.addAugmentation(MaxLengthAction.class, maxBuilder.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(SetNwTtl.class);
    NwTtlActionBuilder nwTtl = new NwTtlActionBuilder();
    nwTtl.setNwTtl((short) 64);
    actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build());
    actions.add(actionBuilder.build());
    actionsBuilder.setAction(actions);
    builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());
    instructions.add(builder.build());
    // Apply_actions instruction
    builder = new InstructionBuilder();
    builder.setType(ApplyActions.class);
    actionsBuilder = new ActionsInstructionBuilder();
    actions = new ArrayList<>();
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PushVlan.class);
    EthertypeActionBuilder ethertypeBuilder = new EthertypeActionBuilder();
    ethertypeBuilder.setEthertype(new EtherType(14));
    actionBuilder.addAugmentation(EthertypeAction.class, ethertypeBuilder.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PopPbb.class);
    actions.add(actionBuilder.build());
    actionsBuilder.setAction(actions);
    builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());
    instructions.add(builder.build());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    InstructionsSerializer.encodeInstructions(instructions, out);

    Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction table-id", 5, out.readUnsignedByte());
    out.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
    out.skipBytes(4);
    byte[] actual = new byte[8];
    out.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07",
            ByteBufUtils.bytesToHexString(actual));
    actual = new byte[8];
    out.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00",
            ByteBufUtils.bytesToHexString(actual));
    Assert.assertEquals("Wrong instruction type", 5, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong instruction type", 6, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction meter-id", 42, out.readUnsignedInt());
    Assert.assertEquals("Wrong instruction type", 3, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 32, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 45, out.readUnsignedInt());
    Assert.assertEquals("Wrong action type", 55, out.readUnsignedShort());
    out.skipBytes(6);
    Assert.assertEquals("Wrong action type", 23, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 64, out.readUnsignedByte());
    out.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action ethertype", 14, out.readUnsignedShort());
    out.skipBytes(2);
    Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertTrue("Not all data were read", out.readableBytes() == 0);
}