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.serialization.factories.FlowRemovedMessageFactoryTest.java

License:Open Source License

@Test
public void testSerialize() throws Exception {
    FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setCookie(BigInteger.valueOf(1234L));
    builder.setPriority(1234);/*from w w w  . jav a  2s  . c  o  m*/
    builder.setReason(FlowRemovedReason.forValue(2));
    builder.setTableId(new TableId(65L));
    builder.setDurationSec(1234L);
    builder.setDurationNsec(1234L);
    builder.setIdleTimeout(1234);
    builder.setHardTimeout(1234);
    builder.setPacketCount(BigInteger.valueOf(1234L));
    builder.setByteCount(BigInteger.valueOf(1234L));
    MatchBuilder matchBuilder = new MatchBuilder();
    matchBuilder.setType(OxmMatchType.class);
    List<MatchEntry> entries = new ArrayList<>();
    MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(InPhyPort.class);
    entriesBuilder.setHasMask(false);
    InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
    InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
    inPhyPortBuilder.setPortNumber(new PortNumber(42L));
    inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
    entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
    entries.add(entriesBuilder.build());
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(IpEcn.class);
    entriesBuilder.setHasMask(false);
    IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
    IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
    ipEcnBuilder.setEcn((short) 4);
    ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
    entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
    entries.add(entriesBuilder.build());
    matchBuilder.setMatchEntry(entries);
    builder.setMatch(matchBuilder.build());
    FlowRemovedMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);

    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 72);
    Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong priority", message.getPriority().intValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readByte());
    Assert.assertEquals("Wrong Table ID", message.getTableId().getValue().intValue(),
            serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong duration sec", message.getDurationSec().intValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong duration nsec", message.getDurationNsec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong Idle timeout", message.getIdleTimeout().intValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong Hard timeout", message.getIdleTimeout().intValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong Packet count", message.getPacketCount().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong Byte count", message.getByteCount().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong match type", 1, serializedBuffer.readUnsignedShort());
    serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort());
    short fieldAndMask = serializedBuffer.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
    serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 42, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort());
    fieldAndMask = serializedBuffer.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
    serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 4, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(7);
}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setDatapathId(BigInteger.valueOf(1234L));
    builder.setBuffers(1234L);//from   ww  w  .  j a v a  2s  . c  o m
    builder.setTables((short) 12);
    builder.setAuxiliaryId((short) 12);
    builder.setCapabilities(new Capabilities(true, false, true, false, true, false, true));
    builder.setReserved(1234L);
    GetFeaturesOutput message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);

    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 32);
    Assert.assertEquals("Wrong DatapathId", message.getDatapathId().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong Buffer ID", message.getBuffers().longValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong tables", message.getTables().shortValue(), serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong auxiliary ID", message.getAuxiliaryId().shortValue(),
            serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(PADDING);
    Assert.assertEquals("Wrong Capabilities", message.getCapabilities(),
            createCapabilities(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong reserved", message.getReserved().longValue(), serializedBuffer.readInt());
}

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

License:Open Source License

/**
 * Testing of {@link GetQueueConfigInputMessageFactory} for correct translation from POJO
 * @throws Exception //from  w ww  .j a  v a 2  s  . c o m
 */
@Test
public void testGetQueueConfigInputMessage() throws Exception {
    GetQueueConfigInputBuilder builder = new GetQueueConfigInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setPort(new PortNumber(0x00010203L));
    GetQueueConfigInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, GET_QUEUE_CONFIG_INPUT_MESSAGE_CODE_TYPE, 16);
    Assert.assertEquals("Wrong port", 0x00010203, out.readUnsignedInt());
    out.skipBytes(PADDING_IN_QUEUE_CONFIG_INPUT_MESSAGE);
}

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

License:Open Source License

/**
 * @throws Exception//from w  w w .  j a  va 2 s  .  co  m
 * Testing of {@link GroupModInputMessageFactory} for correct translation from POJO
 */
@Test
public void testGroupModInputMessage() throws Exception {
    GroupModInputBuilder builder = new GroupModInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setCommand(GroupModCommand.forValue(2));
    builder.setType(GroupType.forValue(3));
    builder.setGroupId(new GroupId(256L));
    List<BucketsList> exp = createBucketsList();
    builder.setBucketsList(exp);
    GroupModInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedShort());
    Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedByte());
    out.skipBytes(PADDING_IN_GROUP_MOD_MESSAGE);
    Assert.assertEquals("Wrong groupId", message.getGroupId().getValue().intValue(), out.readUnsignedInt());
    List<BucketsList> rec = createBucketsListFromBufer(out);
    Assert.assertArrayEquals("Wrong bucketList", exp.toArray(), rec.toArray());
}

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

License:Open Source License

private static List<BucketsList> createBucketsListFromBufer(ByteBuf out) {
    List<BucketsList> bucketsList = new ArrayList<>();
    BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
    BucketsList bucket;//  w w w  .  java 2 s . c om
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    bucketsBuilder.setWeight(out.readUnsignedShort());
    bucketsBuilder.setWatchPort(new PortNumber(out.readUnsignedInt()));
    bucketsBuilder.setWatchGroup(out.readUnsignedInt());
    out.skipBytes(4);
    bucket = bucketsBuilder.build();
    bucketsList.add(bucket);
    return bucketsList;
}

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

License:Open Source License

private static List<Bands> decodeBandsList(ByteBuf input) {
    List<Bands> bandsList = new ArrayList<>();
    BandsBuilder bandsBuilder = new BandsBuilder();
    MeterBandDropCaseBuilder dropCaseBuilder = new MeterBandDropCaseBuilder();
    MeterBandDropBuilder dropBand = new MeterBandDropBuilder();
    dropBand.setType(MeterBandType.forValue(input.readUnsignedShort()));
    input.skipBytes(Short.SIZE / Byte.SIZE);
    dropBand.setRate(input.readUnsignedInt());
    dropBand.setBurstSize(input.readUnsignedInt());
    input.skipBytes(4);/*from   www  .ja va  2  s  . c  o m*/
    dropCaseBuilder.setMeterBandDrop(dropBand.build());
    bandsList.add(bandsBuilder.setMeterBand(dropCaseBuilder.build()).build());
    MeterBandDscpRemarkCaseBuilder dscpCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
    MeterBandDscpRemarkBuilder dscpRemarkBand = new MeterBandDscpRemarkBuilder();
    dscpRemarkBand.setType(MeterBandType.forValue(input.readUnsignedShort()));
    input.skipBytes(Short.SIZE / Byte.SIZE);
    dscpRemarkBand.setRate(input.readUnsignedInt());
    dscpRemarkBand.setBurstSize(input.readUnsignedInt());
    dscpRemarkBand.setPrecLevel(input.readUnsignedByte());
    input.skipBytes(3);
    dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build());
    bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build());
    MeterBandExperimenterCaseBuilder expCaseBuilder = new MeterBandExperimenterCaseBuilder();
    MeterBandExperimenterBuilder experimenterBand = new MeterBandExperimenterBuilder();
    experimenterBand.setType(MeterBandType.forValue(input.readUnsignedShort()));
    input.skipBytes(Short.SIZE / Byte.SIZE);
    experimenterBand.setRate(input.readUnsignedInt());
    experimenterBand.setBurstSize(input.readUnsignedInt());
    experimenterBand.setExperimenter(input.readUnsignedInt());
    expCaseBuilder.setMeterBandExperimenter(experimenterBand.build());
    bandsList.add(bandsBuilder.setMeterBand(expCaseBuilder.build()).build());
    return bandsList;
}

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

License:Open Source License

/**
 * Tests {@link MultipartRequestInputFactory} - GroupDesc case
 * @throws Exception// w  ww.ja v a 2 s. c  o  m
 */
@Test
public void test() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.OFPMPGROUPDESC);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestGroupDescCaseBuilder caseBuilder = new MultipartRequestGroupDescCaseBuilder();
    MultipartRequestGroupDescBuilder descBuilder = new MultipartRequestGroupDescBuilder();
    descBuilder.setEmpty(true);
    caseBuilder.setMultipartRequestGroupDesc(descBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);

    BufferHelper.checkHeaderV13(out, (byte) 18, 16);
    Assert.assertEquals("Wrong type", 7, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    out.skipBytes(4); // skip padding
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}

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

License:Open Source License

/**
 * Tests {@link MultipartRequestInputFactory} - GroupFeatures case
 * @throws Exception/*  w  w w. ja  v a 2 s. c  om*/
 */
@Test
public void test() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.OFPMPGROUPFEATURES);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestGroupFeaturesCaseBuilder caseBuilder = new MultipartRequestGroupFeaturesCaseBuilder();
    MultipartRequestGroupFeaturesBuilder featuresBuilder = new MultipartRequestGroupFeaturesBuilder();
    featuresBuilder.setEmpty(true);
    caseBuilder.setMultipartRequestGroupFeatures(featuresBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);

    BufferHelper.checkHeaderV13(out, (byte) 18, 16);
    Assert.assertEquals("Wrong type", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    out.skipBytes(4); // skip padding
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}

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

License:Open Source License

/**
 * Tests {@link MultipartRequestInputFactory} - MeterFeatures case
 * @throws Exception//from w w  w . j av a 2s .c  om
 */
@Test
public void test() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.OFPMPMETERFEATURES);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestMeterFeaturesCaseBuilder caseBuilder = new MultipartRequestMeterFeaturesCaseBuilder();
    MultipartRequestMeterFeaturesBuilder featuresBuilder = new MultipartRequestMeterFeaturesBuilder();
    featuresBuilder.setEmpty(true);
    caseBuilder.setMultipartRequestMeterFeatures(featuresBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);

    BufferHelper.checkHeaderV13(out, (byte) 18, 16);
    Assert.assertEquals("Wrong type", 11, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    out.skipBytes(4); // skip padding
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}

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

License:Open Source License

/**
 * Tests {@link MultipartRequestInputFactory} - PortDesc case
 * @throws Exception/*from w w  w.  j a v a  2  s  . co m*/
 */
@Test
public void test() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.OFPMPPORTDESC);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestPortDescCaseBuilder caseBuilder = new MultipartRequestPortDescCaseBuilder();
    MultipartRequestPortDescBuilder descBuilder = new MultipartRequestPortDescBuilder();
    descBuilder.setEmpty(true);
    caseBuilder.setMultipartRequestPortDesc(descBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    multipartFactory.serialize(message, out);

    BufferHelper.checkHeaderV13(out, (byte) 18, 16);
    Assert.assertEquals("Wrong type", 13, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    out.skipBytes(4); // skip padding
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}