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.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.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());

    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((short) 3);
    dscpCaseBuilder.setMeterBandDscpRemark(dscpRemarkBand.build());
    bandsList.add(bandsBuilder.setMeterBand(dscpCaseBuilder.build()).build());
    return bandsList;
}

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

License:Open Source License

@Test
public void testDescSerialize() {
    builder.setType(MultipartType.forValue(0));
    MultipartReplyDescCaseBuilder descCase = new MultipartReplyDescCaseBuilder();
    MultipartReplyDescBuilder desc = new MultipartReplyDescBuilder();
    desc.setMfrDesc("Test");
    desc.setHwDesc("Test");
    desc.setSwDesc("Test");
    desc.setSerialNum("12345");
    desc.setDpDesc("Test");
    descCase.setMultipartReplyDesc(desc.build());
    builder.setMultipartReplyBody(descCase.build());
    message = builder.build();//from  ww w.j  a  v  a 2s  .c  o  m
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 1072);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPDESC.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    serializedBuffer.skipBytes(PADDING);
    Assert.assertEquals("Wrong desc body", message.getMultipartReplyBody(), decodeDescBody(serializedBuffer));
}

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

License:Open Source License

@Test
public void testSerialize() {
    OF10FeaturesReplyMessageFactory serializer = new OF10FeaturesReplyMessageFactory();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 80);
    Assert.assertEquals("Wrong datapath id", message.getDatapathId().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong n buffers", message.getBuffers().longValue(),
            serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong n tables", message.getTables().shortValue(),
            serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(3);
    Assert.assertEquals("Wrong capabilities", message.getCapabilitiesV10(),
            createCapabilities(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong actions", message.getActionsV10(), createActionsV10(serializedBuffer.readInt()));
    PhyPort port = message.getPhyPort().get(0);
    Assert.assertEquals("Wrong port No", port.getPortNo().intValue(), serializedBuffer.readShort());
    byte[] address = new byte[6];
    serializedBuffer.readBytes(address);
    Assert.assertEquals("Wrong MacAddress", port.getHwAddr().getValue().toLowerCase(),
            new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase());
    byte[] name = new byte[16];
    serializedBuffer.readBytes(name);//ww  w .j a  va2  s.  c  o  m
    Assert.assertEquals("Wrong name", port.getName(), new String(name).trim());
    Assert.assertEquals("Wrong config", port.getConfigV10(), createPortConfig(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong state", port.getStateV10(), createPortState(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong current", port.getCurrentFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong advertised", port.getAdvertisedFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong supported", port.getSupportedFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong peer", port.getPeerFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));

}

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

License:Open Source License

@Test
public void testSerialize() {
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();//from   ww  w . ja v  a2s  . c o m
    OF10FlowRemovedMessageFactory serializer = new OF10FlowRemovedMessageFactory();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 88);
    Assert.assertEquals("Wrong wildcards", 3678463, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong inPort", 58, serializedBuffer.readUnsignedShort());
    byte[] dlSrc = new byte[6];
    serializedBuffer.readBytes(dlSrc);
    Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
    byte[] dlDst = new byte[6];
    serializedBuffer.readBytes(dlDst);
    Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));
    Assert.assertEquals("Wrong dlVlan", 18, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong dlVlanPcp", 5, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertEquals("Wrong dlType", 42, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong nwTos", 4, serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong nwProto", 7, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(2);
    Assert.assertEquals("Wrong nwSrc", 134744072, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong nwDst", 269488144, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong tpSrc", 6653, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong tpDst", 6633, serializedBuffer.readUnsignedShort());
    byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x01, 0x01, 0x04, 0x01 };
    byte[] cookieRead = new byte[8];
    serializedBuffer.readBytes(cookieRead);
    Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead);
    Assert.assertEquals("Wrong priority", 1, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong reason", 1, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertEquals("Wrong duration", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong duration nsec", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong idle timeout", 12, serializedBuffer.readUnsignedShort());
    serializedBuffer.skipBytes(2);
    Assert.assertEquals("Wrong packet count", 1L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong byte count", 2L, serializedBuffer.readLong());
}

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

License:Open Source License

@Test
public void testSerialize() {
    OF10PacketInMessageFactory serializer = new OF10PacketInMessageFactory();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 34);
    Assert.assertEquals("Wrong buffer id", message.getBufferId().longValue(),
            serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong total len", message.getTotalLen().intValue(),
            serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong port in", message.getInPort().intValue(), serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertArrayEquals("Wrong data", message.getData(),
            serializedBuffer.readBytes(serializedBuffer.readableBytes()).array());
}

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

License:Open Source License

@Test
public void testSerialize() {
    OF10PortStatusMessageFactory serializer = new OF10PortStatusMessageFactory();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 64);
    Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(7);
    Assert.assertEquals("Wrong port No", message.getPortNo().intValue(), serializedBuffer.readShort());
    byte[] address = new byte[6];
    serializedBuffer.readBytes(address);
    Assert.assertEquals("Wrong MacAddress", message.getHwAddr().getValue().toLowerCase(),
            new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase());
    byte[] name = new byte[16];
    serializedBuffer.readBytes(name);//from ww w .  j a va2  s.c  om
    Assert.assertEquals("Wrong name", message.getName(), new String(name).trim());
    Assert.assertEquals("Wrong config", message.getConfigV10(), createPortConfig(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong state", message.getStateV10(), createPortState(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong current", message.getCurrentFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong advertised", message.getAdvertisedFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong supported", message.getSupportedFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong peer", message.getPeerFeaturesV10(),
            createPortFeatures(serializedBuffer.readInt()));
}

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

License:Open Source License

@Test
public void testSerialize() {
    OF10QueueGetConfigReplyMessageFactory serializer = new OF10QueueGetConfigReplyMessageFactory();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 40);
    Assert.assertEquals("Wrong port", message.getPort().getValue().longValue(), serializedBuffer.readShort());
    serializedBuffer.skipBytes(6);
    Assert.assertEquals("Wrong queue Id", message.getQueues().get(0).getQueueId().getValue().longValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong length", 24, serializedBuffer.readShort());
    serializedBuffer.skipBytes(2);//from   w  w w  .j a  va2s.co m
    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(4);
    RateQueueProperty rateQueueProperty = properties.get(0).getAugmentation(RateQueueProperty.class);
    Assert.assertEquals("Wrong rate", rateQueueProperty.getRate().intValue(), serializedBuffer.readShort());
    serializedBuffer.skipBytes(6);
}

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

License:Open Source License

@Test
public void testFlowBodySerialize() {
    builder.setType(MultipartType.forValue(1));
    MultipartReplyFlowCaseBuilder flowCase = new MultipartReplyFlowCaseBuilder();
    MultipartReplyFlowBuilder flow = new MultipartReplyFlowBuilder();
    flow.setFlowStats(createFlowStats());
    flowCase.setMultipartReplyFlow(flow.build());
    builder.setMultipartReplyBody(flowCase.build());
    message = builder.build();/*w  w w. j a va 2s.  c om*/
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 108);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPFLOW.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    FlowStats flowStats = flow.getFlowStats().get(0);
    Assert.assertEquals("Wrong length", 96, serializedBuffer.readShort());
    Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(),
            serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertEquals("Wrong wildcards", 3678463, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong inPort", 58, serializedBuffer.readUnsignedShort());
    byte[] dlSrc = new byte[6];
    serializedBuffer.readBytes(dlSrc);
    Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
    byte[] dlDst = new byte[6];
    serializedBuffer.readBytes(dlDst);
    Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));
    Assert.assertEquals("Wrong dlVlan", 18, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong dlVlanPcp", 5, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertEquals("Wrong dlType", 42, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong nwTos", 4, serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong nwProto", 7, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(2);
    Assert.assertEquals("Wrong nwSrc", 134744072, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong nwDst", 269488144, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong tpSrc", 6653, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong tpDst", 6633, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(),
            serializedBuffer.readShort());
    serializedBuffer.skipBytes(6);
    Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong port", 42, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong maxlength", 50, serializedBuffer.readUnsignedShort());
}

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

License:Open Source License

@Test
public void testAggregateBodySerialize() {
    builder.setType(MultipartType.forValue(2));
    MultipartReplyAggregateCaseBuilder aggregateCase = new MultipartReplyAggregateCaseBuilder();
    MultipartReplyAggregateBuilder aggregate = new MultipartReplyAggregateBuilder();
    aggregate.setPacketCount(BigInteger.valueOf(1234L));
    aggregate.setByteCount(BigInteger.valueOf(1234L));
    aggregate.setFlowCount(1L);/*ww  w  .  j a v a2  s  . c  om*/
    aggregateCase.setMultipartReplyAggregate(aggregate.build());
    builder.setMultipartReplyBody(aggregateCase.build());
    message = builder.build();
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 36);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPAGGREGATE.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong Packet count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong Byte count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong flow count", 1L, serializedBuffer.readInt());
    serializedBuffer.skipBytes(4);
}

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

License:Open Source License

@Test
public void testTableBodySerialize() {
    builder.setType(MultipartType.forValue(3));
    MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder();
    MultipartReplyTableBuilder table = new MultipartReplyTableBuilder();
    table.setTableStats(createTableStats());
    tableCase.setMultipartReplyTable(table.build());
    builder.setMultipartReplyBody(tableCase.build());
    message = builder.build();//  ww  w .ja  v a2 s .com
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 60);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLE.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong table id", 1, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(3);
    Assert.assertEquals("Wrong name", "Table name",
            ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 16));
    Assert.assertEquals("Wrong wildcards", 3145983, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong max entries", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong active count", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong lookup count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong matched count", 1234L, serializedBuffer.readLong());
}