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.MultipartRequestInputFactoryTest.java

License:Open Source License

/**
 * @throws Exception// w w  w.j  a v  a2s. c  om
 * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO
 */
@Test
public void testMultipartRequestInputFactory() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.forValue(1));
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setMultipartRequestBody(createRequestFlow());
    MultipartRequestInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort()));
    out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE);
    Assert.assertEquals("Wrong flow", message.getMultipartRequestBody(), decodeRequestFlow(out));
}

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

License:Open Source License

private static MultipartRequestFlowCase decodeRequestFlow(ByteBuf output) {
    final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01 = 3;
    final byte PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02 = 4;
    MultipartRequestFlowCaseBuilder caseBuilder = new MultipartRequestFlowCaseBuilder();
    MultipartRequestFlowBuilder builder = new MultipartRequestFlowBuilder();
    builder.setTableId(output.readUnsignedByte());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_01);
    builder.setOutPort(output.readUnsignedInt());
    builder.setOutGroup(output.readUnsignedInt());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_FLOW_BODY_02);
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    output.readBytes(cookie);/*from w ww .jav  a 2 s. co  m*/
    builder.setCookie(new BigInteger(1, cookie));
    byte[] cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    output.readBytes(cookieMask);
    builder.setCookieMask(new BigInteger(1, cookieMask));
    caseBuilder.setMultipartRequestFlow(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

/**
 * @throws Exception//w  ww . j ava  2 s  . com
 * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO
 */
@Test
public void testMultipartRequestInputAggregateBodyFactory() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.forValue(2));
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setMultipartRequestBody(createRequestAggregate());
    MultipartRequestInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort()));
    out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE);
    Assert.assertEquals("Wrong aggregate", message.getMultipartRequestBody(), decodeRequestAggregate(out));
}

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

License:Open Source License

private static MultipartRequestAggregateCase decodeRequestAggregate(ByteBuf output) {
    final byte PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_01 = 3;
    final byte PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_02 = 4;
    MultipartRequestAggregateCaseBuilder caseBuilder = new MultipartRequestAggregateCaseBuilder();
    MultipartRequestAggregateBuilder builder = new MultipartRequestAggregateBuilder();
    builder.setTableId(output.readUnsignedByte());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_01);
    builder.setOutPort(output.readUnsignedInt());
    builder.setOutGroup(output.readUnsignedInt());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_AGGREGATE_BODY_02);
    byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    output.readBytes(cookie);//from   www  .j a  va 2 s . com
    builder.setCookie(new BigInteger(1, cookie));
    byte[] cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    output.readBytes(cookieMask);
    builder.setCookieMask(new BigInteger(1, cookieMask));
    caseBuilder.setMultipartRequestAggregate(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

/**
 * @throws Exception//  w  ww  .j a v a2s.  c o m
 * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO
 */
@Test
public void testMultipartRequestInputTableFactory() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.forValue(3));
    builder.setFlags(new MultipartRequestFlags(true));
    //multipart request for table does not have body
    MultipartRequestInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort()));
    out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE);
}

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

License:Open Source License

/**
 * @throws Exception/*  w ww.j  a va 2s  . com*/
 * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO
 */
@Test
public void testMultipartRequestPortStatsMessageFactory() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.forValue(4));
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setMultipartRequestBody(createRequestPortStats());
    MultipartRequestInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort()));
    out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE);
    Assert.assertEquals("Wrong portStatsBody", message.getMultipartRequestBody(), decodeRequestPortStats(out));
}

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

License:Open Source License

private static MultipartRequestPortStatsCase decodeRequestPortStats(ByteBuf output) {
    final byte PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY = 4;
    MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
    MultipartRequestPortStatsBuilder builder = new MultipartRequestPortStatsBuilder();
    builder.setPortNo(output.readUnsignedInt());
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_PORTSTATS_BODY);
    caseBuilder.setMultipartRequestPortStats(builder.build());
    return caseBuilder.build();
}

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

License:Open Source License

/**
 * @throws Exception/*from   w  ww.ja v a 2  s. c  o m*/
 * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO
 */
@Test
public void testMultipartRequestQueueMessageFactory() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.forValue(5));
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setMultipartRequestBody(createRequestQueue());
    MultipartRequestInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort()));
    out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE);
    Assert.assertEquals("Wrong queueBody", message.getMultipartRequestBody(), decodeRequestQueue(out));
}

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

License:Open Source License

/**
 * @throws Exception//  w w w  .  j  ava2s  .co m
 * Testing of {@link MultipartRequestInputFactory} for correct translation from POJO
 */
@Test
public void testMultipartRequestGroupMessageFactory() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setType(MultipartType.forValue(6));
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setMultipartRequestBody(createRequestGroup());
    MultipartRequestInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), decodeMultipartRequestFlags(out.readShort()));
    out.skipBytes(PADDING_IN_MULTIPART_REQUEST_MESSAGE);
    Assert.assertEquals("Wrong groupBody", message.getMultipartRequestBody(), decodeRequestGroup(out));
}

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

License:Open Source License

private static MultipartRequestGroupCase decodeRequestGroup(ByteBuf output) {
    final byte PADDING_IN_MULTIPART_REQUEST_GROUP_BODY = 4;
    MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
    MultipartRequestGroupBuilder builder = new MultipartRequestGroupBuilder();
    builder.setGroupId(new GroupId(output.readUnsignedInt()));
    output.skipBytes(PADDING_IN_MULTIPART_REQUEST_GROUP_BODY);
    caseBuilder.setMultipartRequestGroup(builder.build());
    return caseBuilder.build();
}