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

License:Open Source License

/**
 * Testing OF10StatsRequestInputFactory (Aggregate) for correct serialization
 * @throws Exception//  w  w w .  ja v  a  2  s  . co  m
 */
@Test
public void testAggregate() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
    builder.setType(MultipartType.OFPMPAGGREGATE);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestFlowCaseBuilder caseBuilder = new MultipartRequestFlowCaseBuilder();
    MultipartRequestFlowBuilder flowBuilder = new MultipartRequestFlowBuilder();
    MatchV10Builder matchBuilder = new MatchV10Builder();
    matchBuilder.setWildcards(
            new FlowWildcardsV10(false, false, false, false, false, false, false, false, false, false));
    matchBuilder.setNwSrcMask((short) 32);
    matchBuilder.setNwDstMask((short) 32);
    matchBuilder.setInPort(51);
    matchBuilder.setDlSrc(new MacAddress("00:01:02:03:04:05"));
    matchBuilder.setDlDst(new MacAddress("05:04:03:02:01:00"));
    matchBuilder.setDlVlan(52);
    matchBuilder.setDlVlanPcp((short) 53);
    matchBuilder.setDlType(54);
    matchBuilder.setNwTos((short) 55);
    matchBuilder.setNwProto((short) 56);
    matchBuilder.setNwSrc(new Ipv4Address("10.0.0.1"));
    matchBuilder.setNwDst(new Ipv4Address("10.0.0.2"));
    matchBuilder.setTpSrc(57);
    matchBuilder.setTpDst(58);
    flowBuilder.setMatchV10(matchBuilder.build());
    flowBuilder.setTableId((short) 42);
    flowBuilder.setOutPort(6653L);
    caseBuilder.setMultipartRequestFlow(flowBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();
    factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);

    BufferHelper.checkHeaderV10(out, factory.getMessageType(), 56);
    Assert.assertEquals("Wrong type", 2, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong wildcards", 0, out.readUnsignedInt());
    Assert.assertEquals("Wrong in-port", 51, out.readUnsignedShort());
    byte[] dlSrc = new byte[6];
    out.readBytes(dlSrc);
    Assert.assertEquals("Wrong dl-src", "00:01:02:03:04:05", ByteBufUtils.macAddressToString(dlSrc));
    byte[] dlDst = new byte[6];
    out.readBytes(dlDst);
    Assert.assertEquals("Wrong dl-dst", "05:04:03:02:01:00", ByteBufUtils.macAddressToString(dlDst));
    Assert.assertEquals("Wrong dl-vlan", 52, out.readUnsignedShort());
    Assert.assertEquals("Wrong dl-vlan-pcp", 53, out.readUnsignedByte());
    out.skipBytes(1);
    Assert.assertEquals("Wrong dl-type", 54, out.readUnsignedShort());
    Assert.assertEquals("Wrong nw-tos", 55, out.readUnsignedByte());
    Assert.assertEquals("Wrong nw-proto", 56, out.readUnsignedByte());
    out.skipBytes(2);
    Assert.assertEquals("Wrong nw-src", 167772161, out.readUnsignedInt());
    Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt());
    Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort());
    Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort());
    Assert.assertEquals("Wrong table-id", 42, out.readUnsignedByte());
    out.skipBytes(1);
    Assert.assertEquals("Wrong out-port", 6653, out.readUnsignedShort());
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}

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

License:Open Source License

/**
 * Testing OF10StatsRequestInputFactory (Port) for correct serialization
 * @throws Exception// w  w  w. j av a  2 s  .c o m
 */
@Test
public void testPort() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
    builder.setType(MultipartType.OFPMPPORTSTATS);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
    MultipartRequestPortStatsBuilder portBuilder = new MultipartRequestPortStatsBuilder();
    portBuilder.setPortNo(15L);
    caseBuilder.setMultipartRequestPortStats(portBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();
    factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);

    BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20);
    Assert.assertEquals("Wrong type", 4, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort());
    out.skipBytes(6);
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}

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

License:Open Source License

/**
 * Testing OF10StatsRequestInputFactory (Queue) for correct serialization
 * @throws Exception/*w  w w. j  av  a2s .c  o  m*/
 */
@Test
public void testQueue() throws Exception {
    MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
    builder.setType(MultipartType.OFPMPQUEUE);
    builder.setFlags(new MultipartRequestFlags(false));
    MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
    MultipartRequestQueueBuilder queueBuilder = new MultipartRequestQueueBuilder();
    queueBuilder.setPortNo(15L);
    queueBuilder.setQueueId(16L);
    caseBuilder.setMultipartRequestQueue(queueBuilder.build());
    builder.setMultipartRequestBody(caseBuilder.build());
    MultipartRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    OF10StatsRequestInputFactory factory = OF10StatsRequestInputFactory.getInstance();
    factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);

    BufferHelper.checkHeaderV10(out, factory.getMessageType(), 20);
    Assert.assertEquals("Wrong type", 5, out.readUnsignedShort());
    Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort());
    out.skipBytes(2);
    Assert.assertEquals("Wrong queue-id", 16, out.readUnsignedInt());
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    PacketInMessageBuilder builder = new PacketInMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setBufferId(256L);/*from  ww  w  .j a va  2s  .  c o  m*/
    builder.setTotalLen(10);
    builder.setReason(PacketInReason.forValue(0));
    builder.setTableId(new TableId(1L));
    byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
    builder.setCookie(new BigInteger(1, cookie));
    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());
    byte[] data = ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14");
    builder.setData(data);
    PacketInMessage message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 66);
    Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(),
            serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong actions length", message.getTotalLen().intValue(),
            serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(),
            serializedBuffer.readUnsignedByte());
    cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    serializedBuffer.readBytes(cookie);
    Assert.assertEquals("Wrong cookie", message.getCookie(), new BigInteger(1, cookie));
    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);
    serializedBuffer.skipBytes(PADDING);
    byte[] readData = new byte[serializedBuffer.readableBytes()];
    serializedBuffer.readBytes(readData);
    Assert.assertArrayEquals("Wrong data", message.getData(), readData);
}

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

License:Open Source License

/**
 * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO
 * @throws Exception /*from  w w w. ja  v  a 2  s .  co  m*/
 */
@Test
public void testPacketOutInputMessage() throws Exception {
    PacketOutInputBuilder builder = new PacketOutInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setBufferId(256L);
    builder.setInPort(new PortNumber(256L));
    List<Action> actions = new ArrayList<>();
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setType(PushVlan.class);
    EthertypeActionBuilder ethertypeBuilder = new EthertypeActionBuilder();
    ethertypeBuilder.setEthertype(new EtherType(25));
    actionBuilder.addAugmentation(EthertypeAction.class, ethertypeBuilder.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PopVlan.class);
    actions.add(actionBuilder.build());
    builder.setAction(actions);
    builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"));
    PacketOutInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 56);
    Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong PortNumber", message.getInPort().getValue().longValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong ActionsLength", 16, out.readUnsignedShort());
    out.skipBytes(PADDING_IN_PACKET_OUT_MESSAGE);
    Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong ethertype", 25, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(PADDING_IN_ACTION_HEADER);
    Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array());
}

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

License:Open Source License

/**
 * Testing of {@link PortModInputMessageFactory} for correct translation from POJO
 * @throws Exception /*from w ww  . j a  va  2 s.com*/
 */
@Test
public void testPortModInput() throws Exception {
    PortModInputBuilder builder = new PortModInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setPortNo(new PortNumber(9L));
    builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB"));
    builder.setConfig(new PortConfig(true, false, true, false));
    builder.setMask(new PortConfig(false, true, false, true));
    builder.setAdvertise(new PortFeatures(true, false, false, false, false, false, false, true, false, false,
            false, false, false, false, false, false));
    PortModInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
    Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedInt());
    out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_01);
    byte[] address = new byte[6];
    out.readBytes(address);
    Assert.assertEquals("Wrong MacAddress", message.getHwAddress().getValue(),
            new MacAddress(ByteBufUtils.macAddressToString(address)).getValue());
    out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_02);
    Assert.assertEquals("Wrong config", message.getConfig(), createPortConfig(out.readInt()));
    Assert.assertEquals("Wrong mask", message.getMask(), createPortConfig(out.readInt()));
    Assert.assertEquals("Wrong advertise", message.getAdvertise(), createPortFeatures(out.readInt()));
    out.skipBytes(PADDING_IN_PORT_MOD_MESSAGE_03);
}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    PortStatusMessageBuilder builder = new PortStatusMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setReason(PortReason.forValue(1));
    builder.setPortNo(1L);//w  ww.j  ava 2 s .  c  om
    builder.setHwAddr(new MacAddress("94:de:80:a6:61:40"));
    builder.setName("Port name");
    builder.setConfig(new PortConfig(true, false, true, false));
    builder.setState(new PortState(true, false, true));
    builder.setCurrentFeatures(new PortFeatures(true, false, true, false, true, false, true, false, true, false,
            true, false, true, false, true, false));
    builder.setAdvertisedFeatures(new PortFeatures(true, false, true, false, true, false, true, false, true,
            false, true, false, true, false, true, false));
    builder.setSupportedFeatures(new PortFeatures(true, false, true, false, true, false, true, false, true,
            false, true, false, true, false, true, false));
    builder.setPeerFeatures(new PortFeatures(true, false, true, false, true, false, true, false, true, false,
            true, false, true, false, true, false));
    builder.setCurrSpeed(1234L);
    builder.setMaxSpeed(1234L);
    PortStatusMessage message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 80);
    Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(PADDING);
    Assert.assertEquals("Wrong PortNo", message.getPortNo().intValue(), serializedBuffer.readUnsignedInt());
    serializedBuffer.skipBytes(PORT_PADDING_1);
    byte[] address = new byte[6];
    serializedBuffer.readBytes(address);
    Assert.assertEquals("Wrong MacAddress", message.getHwAddr().getValue().toLowerCase(),
            new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase());
    serializedBuffer.skipBytes(PORT_PADDING_2);
    byte[] name = new byte[16];
    serializedBuffer.readBytes(name);
    Assert.assertEquals("Wrong name", message.getName(), new String(name).trim());
    Assert.assertEquals("Wrong config", message.getConfig(), createPortConfig(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong state", message.getState(), createPortState(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong current", message.getCurrentFeatures(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong advertised", message.getAdvertisedFeatures(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong supported", message.getSupportedFeatures(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong peer", message.getPeerFeatures(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong Current speed", message.getCurrSpeed().longValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong Max speed", message.getMaxSpeed().longValue(), serializedBuffer.readInt());
}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setPort(new PortNumber(0x00010203L));
    builder.setQueues(createQueuesList());
    GetQueueConfigOutput message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 80);
    Assert.assertEquals("Wrong port", message.getPort().getValue().longValue(), serializedBuffer.readInt());
    serializedBuffer.skipBytes(PADDING);

    Assert.assertEquals("Wrong queue Id", message.getQueues().get(0).getQueueId().getValue().longValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong port", message.getQueues().get(0).getPort().getValue().longValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong length", 32, serializedBuffer.readShort());
    serializedBuffer.skipBytes(QUEUE_PADDING);
    List<QueueProperty> properties = message.getQueues().get(0).getQueueProperty();
    Assert.assertEquals("Wrong property", properties.get(0).getProperty().getIntValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong property length", 16, serializedBuffer.readShort());
    serializedBuffer.skipBytes(PROPERTY_HEADER_PADDING);
    RateQueueProperty rateQueueProperty = properties.get(0).getAugmentation(RateQueueProperty.class);
    Assert.assertEquals("Wrong rate", rateQueueProperty.getRate().intValue(), serializedBuffer.readShort());
    serializedBuffer.skipBytes(PROPERTY_RATE_PADDING);

    Assert.assertEquals("Wrong queue Id", message.getQueues().get(1).getQueueId().getValue().longValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong queue Id", message.getQueues().get(1).getPort().getValue().longValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong length", 32, serializedBuffer.readShort());
    serializedBuffer.skipBytes(QUEUE_PADDING);
    List<QueueProperty> propertiesTwo = message.getQueues().get(1).getQueueProperty();
    Assert.assertEquals("Wrong property", propertiesTwo.get(0).getProperty().getIntValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong property length", 16, serializedBuffer.readShort());
    serializedBuffer.skipBytes(PROPERTY_HEADER_PADDING);
    RateQueueProperty rateQueuePropertyTwo = propertiesTwo.get(0).getAugmentation(RateQueueProperty.class);
    Assert.assertEquals("Wrong rate", rateQueuePropertyTwo.getRate().intValue(), serializedBuffer.readShort());
    serializedBuffer.skipBytes(PROPERTY_RATE_PADDING);

}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setRole(ControllerRole.forValue(0));
    builder.setGenerationId(BigInteger.valueOf(1L));
    RoleRequestOutput message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 24);
    Assert.assertEquals("Wrong role", message.getRole().getIntValue(),
            ControllerRole.forValue((int) serializedBuffer.readUnsignedInt()).getIntValue());
    serializedBuffer.skipBytes(PADDING);
    byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    serializedBuffer.readBytes(genId);//from   w w  w.jav  a2  s  .  c  o  m
    Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId));
}

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

License:Open Source License

/**
 * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO
 * @throws Exception // ww  w  . j av  a2  s .  co  m
 */
@Test
public void testRoleRequestInputMessage() throws Exception {
    RoleRequestInputBuilder builder = new RoleRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setRole(ControllerRole.forValue(2));
    byte[] generationId = new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 };
    builder.setGenerationId(new BigInteger(1, generationId));
    RoleRequestInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
    Assert.assertEquals("Wrong role", message.getRole().getIntValue(),
            ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue());
    out.skipBytes(PADDING_IN_ROLE_REQUEST_MESSAGE);
    byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(genId);
    Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId));
}