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.deserialization.instruction.WriteMetadataInstructionDeserializer.java

License:Open Source License

@Override
public Instruction deserializeHeader(ByteBuf input) {
    InstructionBuilder builder = new InstructionBuilder();
    input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    builder.setInstructionChoice(new WriteMetadataCaseBuilder().build());
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.AbstractOxmMatchEntryDeserializer.java

License:Open Source License

/**
 * Prepares match entry header - sets oxm_class, oxm_field, hasMask
 *  + sets the buffer.readerIndex() to the end of match entry
 *  - where augmentation starts//from  www  .  j a  v a 2s . c  om
 * @param oxmClass oxm class type
 * @param oxmField oxm field type
 * @param input input bytebuf
 * @return MatchEntriesBuilder which can be filled with MatchEntry augmentation
 */
protected MatchEntryBuilder processHeader(Class<? extends OxmClassBase> oxmClass,
        Class<? extends MatchField> oxmField, ByteBuf input) {
    MatchEntryBuilder builder = new MatchEntryBuilder();
    builder.setOxmClass(oxmClass);
    // skip oxm_class (provided)
    input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    builder.setOxmMatchField(oxmField);
    boolean hasMask = (input.readUnsignedByte() & 1) != 0;
    builder.setHasMask(hasMask);
    // skip match entry length - not needed
    input.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    return builder;
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6ExtHdrDeserializerTest.java

License:Open Source License

/**
 * Tests {@link OxmIpv6ExtHdrDeserializer#deserialize(ByteBuf)}
 */// www.  ja va 2 s  . c  o  m
@Test
public void test() {
    ByteBuf buffer = BufferHelper.buildBuffer("80 00 4E 02 01 FF");

    buffer.skipBytes(4); // skip XID
    OxmIpv6ExtHdrDeserializer deserializer = new OxmIpv6ExtHdrDeserializer();
    MatchEntry entry = deserializer.deserialize(buffer);

    Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
    Assert.assertEquals("Wrong entry field", Ipv6Exthdr.class, entry.getOxmMatchField());
    Assert.assertEquals("Wrong entry hasMask", false, entry.isHasMask());
    Assert.assertEquals("Wrong entry value",
            new Ipv6ExthdrFlags(true, true, true, true, true, true, true, true, true),
            ((Ipv6ExthdrCase) entry.getMatchEntryValue()).getIpv6Exthdr().getPseudoField());
    Assert.assertEquals("Wrong entry mask", null,
            ((Ipv6ExthdrCase) entry.getMatchEntryValue()).getIpv6Exthdr().getMask());
    Assert.assertTrue("Unread data", buffer.readableBytes() == 0);
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6FlabelDeserializerTest.java

License:Open Source License

/**
 * Tests {@link OxmIpv6FlabelDeserializer#deserialize(ByteBuf)}
 */// w w  w  .  j a va  2  s.  c o m
@Test
public void test() {
    ByteBuf buffer = BufferHelper.buildBuffer("80 00 38 04 00 00 00 02");

    buffer.skipBytes(4); // skip XID
    OxmIpv6FlabelDeserializer deserializer = new OxmIpv6FlabelDeserializer();
    MatchEntry entry = deserializer.deserialize(buffer);

    Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
    Assert.assertEquals("Wrong entry field", Ipv6Flabel.class, entry.getOxmMatchField());
    Assert.assertEquals("Wrong entry hasMask", false, entry.isHasMask());
    Assert.assertEquals("Wrong entry value", 2, ((Ipv6FlabelCase) entry.getMatchEntryValue()).getIpv6Flabel()
            .getIpv6Flabel().getValue().intValue());
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmIpv6FlabelDeserializerTest.java

License:Open Source License

/**
 * Tests {@link OxmIpv6FlabelDeserializer#deserialize(ByteBuf)}
 *//*from   ww w  .j a v a2 s . c o  m*/
@Test
public void testWithMask() {
    ByteBuf buffer = BufferHelper.buildBuffer("80 00 39 08 00 00 00 02 00 00 00 05");

    buffer.skipBytes(4); // skip XID
    OxmIpv6FlabelDeserializer deserializer = new OxmIpv6FlabelDeserializer();
    MatchEntry entry = deserializer.deserialize(buffer);

    Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
    Assert.assertEquals("Wrong entry field", Ipv6Flabel.class, entry.getOxmMatchField());
    Assert.assertEquals("Wrong entry hasMask", true, entry.isHasMask());
    Assert.assertEquals("Wrong entry value", 2, ((Ipv6FlabelCase) entry.getMatchEntryValue()).getIpv6Flabel()
            .getIpv6Flabel().getValue().intValue());
    Assert.assertArrayEquals("Wrong entry mask", new byte[] { 0, 0, 0, 5 },
            ((Ipv6FlabelCase) entry.getMatchEntryValue()).getIpv6Flabel().getMask());
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmMetadataDeserializerTest.java

License:Open Source License

/**
 * Tests {@link OxmMetadataDeserializer#deserialize(ByteBuf)}
 *//* w  ww  . j a v  a 2 s.co m*/
@Test
public void test() {
    ByteBuf buffer = BufferHelper.buildBuffer("80 00 04 08 00 00 00 00 00 00 00 03");

    buffer.skipBytes(4); // skip XID
    OxmMetadataDeserializer deserializer = new OxmMetadataDeserializer();
    MatchEntry entry = deserializer.deserialize(buffer);

    Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
    Assert.assertEquals("Wrong entry field", Metadata.class, entry.getOxmMatchField());
    Assert.assertEquals("Wrong entry hasMask", false, entry.isHasMask());
    Assert.assertArrayEquals("Wrong entry value", ByteBufUtils.hexStringToBytes("00 00 00 00 00 00 00 03"),
            ((MetadataCase) entry.getMatchEntryValue()).getMetadata().getMetadata());
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmMplsBosDeserializerTest.java

License:Open Source License

/**
 * Tests {@link OxmMplsBosDeserializer#deserialize(ByteBuf)}
 *//*w  w w  .  jav  a 2  s. c o  m*/
@Test
public void test() {
    ByteBuf buffer = BufferHelper.buildBuffer("80 00 48 01 00");

    buffer.skipBytes(4); // skip XID
    OxmMplsBosDeserializer deserializer = new OxmMplsBosDeserializer();
    MatchEntry entry = deserializer.deserialize(buffer);

    Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
    Assert.assertEquals("Wrong entry field", MplsBos.class, entry.getOxmMatchField());
    Assert.assertEquals("Wrong entry hasMask", false, entry.isHasMask());
    Assert.assertEquals("Wrong entry value", false,
            ((MplsBosCase) entry.getMatchEntryValue()).getMplsBos().isBos());
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmPbbIsidDeserializerTest.java

License:Open Source License

/**
 * Tests {@link OxmPbbIsidDeserializer#deserialize(ByteBuf)}
 *//* w  w  w  .j av  a 2  s  . c  o m*/
@Test
public void test() {
    ByteBuf buffer = BufferHelper.buildBuffer("80 00 4A 03 00 00 02");

    buffer.skipBytes(4); // skip XID
    OxmPbbIsidDeserializer deserializer = new OxmPbbIsidDeserializer();
    MatchEntry entry = deserializer.deserialize(buffer);

    Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
    Assert.assertEquals("Wrong entry field", PbbIsid.class, entry.getOxmMatchField());
    Assert.assertEquals("Wrong entry hasMask", false, entry.isHasMask());
    Assert.assertEquals("Wrong entry value", 2,
            ((PbbIsidCase) entry.getMatchEntryValue()).getPbbIsid().getIsid().intValue());
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.OxmVlanVidDeserializerTest.java

License:Open Source License

/**
 * Tests {@link OxmVlanVidDeserializer#deserialize(ByteBuf)}
 *//*  w w  w .jav a2  s. com*/
@Test
public void test() {
    ByteBuf buffer = BufferHelper.buildBuffer("80 00 0C 02 20 0A");

    buffer.skipBytes(4); // skip XID
    OxmVlanVidDeserializer deserializer = new OxmVlanVidDeserializer();
    MatchEntry entry = deserializer.deserialize(buffer);

    Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
    Assert.assertEquals("Wrong entry field", VlanVid.class, entry.getOxmMatchField());
    Assert.assertEquals("Wrong entry hasMask", false, entry.isHasMask());
    Assert.assertEquals("Wrong entry value", 10,
            ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().getVlanVid().intValue());
    Assert.assertEquals("Wrong entry value", false,
            ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().isCfiBit());
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowModInputMessageFactoryTest.java

License:Open Source License

/**
 * @throws Exception //from ww w.  j  av  a  2 s . c om
 * 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);
    List<MatchEntries> entries = new ArrayList<>();
    MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(InPhyPort.class);
    entriesBuilder.setHasMask(false);
    PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder();
    portNumberBuilder.setPortNumber(new PortNumber(42L));
    entriesBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build());
    entries.add(entriesBuilder.build());
    entriesBuilder.setOxmClass(Nxm0Class.class);
    entriesBuilder.setOxmMatchField(IpEcn.class);
    entriesBuilder.setHasMask(false);
    EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
    ecnBuilder.setEcn((short) 4);
    entriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
    entries.add(entriesBuilder.build());
    matchBuilder.setMatchEntries(entries);
    builder.setMatch(matchBuilder.build());
    List<Instruction> instructions = new ArrayList<>();
    InstructionBuilder insBuilder = new InstructionBuilder();
    insBuilder.setType(GotoTable.class);
    TableIdInstructionBuilder idBuilder = new TableIdInstructionBuilder();
    idBuilder.setTableId((short) 43);
    insBuilder.addAugmentation(TableIdInstruction.class, idBuilder.build());
    instructions.add(insBuilder.build());
    insBuilder.setType(WriteMetadata.class);
    MetadataInstructionBuilder metaBuilder = new MetadataInstructionBuilder();
    metaBuilder.setMetadata(cookie);
    metaBuilder.setMetadataMask(cookieMask);
    insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
    instructions.add(insBuilder.build());
    insBuilder = new InstructionBuilder();
    insBuilder.setType(ApplyActions.class);
    insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
    instructions.add(insBuilder.build());
    builder.setInstruction(instructions);
    FlowModInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    FlowModInputMessageFactory factory = FlowModInputMessageFactory.getInstance();
    factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    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", 0, 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", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}