List of usage examples for io.netty.buffer ByteBuf skipBytes
public abstract ByteBuf skipBytes(int length);
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testPortStatsBodySerialize() { builder.setType(MultipartType.forValue(4)); MultipartReplyPortStatsCaseBuilder portStatsCase = new MultipartReplyPortStatsCaseBuilder(); MultipartReplyPortStatsBuilder portStats = new MultipartReplyPortStatsBuilder(); portStats.setPortStats(createPortStats()); portStatsCase.setMultipartReplyPortStats(portStats.build()); builder.setMultipartReplyBody(portStatsCase.build()); message = builder.build();/*from w w w .j ava 2 s . 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, 118); Assert.assertEquals("Wrong type", MultipartType.OFPMPPORTSTATS.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); MultipartReplyPortStatsCase body = (MultipartReplyPortStatsCase) message.getMultipartReplyBody(); MultipartReplyPortStats messageOutput = body.getMultipartReplyPortStats(); PortStats portStatsOutput = messageOutput.getPortStats().get(0); Assert.assertEquals("Wrong port no", portStatsOutput.getPortNo().intValue(), serializedBuffer.readInt()); serializedBuffer.skipBytes(6); Assert.assertEquals("Wrong rx packets", portStatsOutput.getRxPackets().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx packets", portStatsOutput.getTxPackets().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx bytes", portStatsOutput.getRxBytes().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx bytes", portStatsOutput.getTxBytes().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx dropped", portStatsOutput.getRxDropped().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx dropped", portStatsOutput.getTxDropped().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx errors", portStatsOutput.getRxErrors().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx errors", portStatsOutput.getTxErrors().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx frame err", portStatsOutput.getRxFrameErr().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx over err", portStatsOutput.getRxOverErr().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx crc err", portStatsOutput.getRxCrcErr().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong collisions", portStatsOutput.getCollisions().longValue(), serializedBuffer.readLong()); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testQueueBodySerialize() { builder.setType(MultipartType.forValue(5)); MultipartReplyQueueCaseBuilder queueCase = new MultipartReplyQueueCaseBuilder(); MultipartReplyQueueBuilder queue = new MultipartReplyQueueBuilder(); queue.setQueueStats(createQueueStats()); queueCase.setMultipartReplyQueue(queue.build()); builder.setMultipartReplyBody(queueCase.build()); message = builder.build();/*from w w w . j a va2s .co m*/ 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, 44); Assert.assertEquals("Wrong type", MultipartType.OFPMPQUEUE.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); MultipartReplyQueueCase body = (MultipartReplyQueueCase) message.getMultipartReplyBody(); MultipartReplyQueue messageOutput = body.getMultipartReplyQueue(); QueueStats queueStats = messageOutput.getQueueStats().get(0); Assert.assertEquals("Wrong length", 32, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(2); Assert.assertEquals("Wrong queue id", queueStats.getQueueId().intValue(), serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong tx bytes", queueStats.getTxBytes().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx packets", queueStats.getTxPackets().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx errors", queueStats.getTxErrors().longValue(), serializedBuffer.readLong()); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.PacketInMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { PacketInMessageFactory packetInSerializationFactory = new PacketInMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init();// w w w . java 2 s .com MatchEntriesInitializer.registerMatchEntrySerializers(registry); packetInSerializationFactory.injectSerializerRegistry(registry); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); packetInSerializationFactory.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()); byte[] 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); Assert.assertArrayEquals("Wrong data", message.getData(), serializedBuffer.readBytes(serializedBuffer.readableBytes()).array()); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.PortStatusMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { PortStatusMessageFactory serializer = new PortStatusMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init();//from www .j a va2s . c o m ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.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.netide.openflowjava.protocol.impl.serialization.factories.QueueGetConfigReplyMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { QueueGetConfigReplyMessageFactory serializer = new QueueGetConfigReplyMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init();/* w w w . ja v a2 s.co m*/ ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.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.netide.openflowjava.protocol.impl.serialization.factories.RoleReplyMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { RoleReplyMessageFactory serializer = new RoleReplyMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init();/*from w w w.j av a2s.c o m*/ ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.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); Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId)); }
From source file:org.opendaylight.openflowjava.nx.api.impl.ActionDeserializer.java
License:Open Source License
@Override public Action deserialize(ByteBuf message) { int startPossition = message.readerIndex(); // size of experimenter type message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // size of length message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); long experimenterId = message.readUnsignedInt(); if (NiciraConstants.NX_VENDOR_ID != experimenterId) { throw new IllegalStateException("Experimenter ID is not Nicira vendor id but is " + experimenterId); }/*from w w w . jav a 2 s. c o m*/ int subtype = message.readUnsignedShort(); NiciraActionDeserializerKey key = new NiciraActionDeserializerKey(version, subtype); OFDeserializer<Action> actionDeserializer = NiciraExtensionCodecRegistratorImpl.getActionDeserializer(key); if (actionDeserializer == null) { LOG.info("No deserializer was found for key {}", key); return null; } message.readerIndex(startPossition); return actionDeserializer.deserialize(message); }
From source file:org.opendaylight.openflowjava.nx.codec.action.AbstractActionCodec.java
License:Open Source License
protected static final ActionBuilder deserializeHeader(final ByteBuf message) { // size of experimenter type message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // size of length message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // vendor id/*from w ww.j av a2 s . co m*/ message.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES); // subtype message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setExperimenterId(getExperimenterId()); return actionBuilder; }
From source file:org.opendaylight.openflowjava.nx.codec.action.ConntrackCodec.java
License:Open Source License
@Override public Action deserialize(final ByteBuf message) { ActionBuilder actionBuilder = deserializeHeader(message); ActionConntrackBuilder actionConntrackBuilder = new ActionConntrackBuilder(); NxActionConntrackBuilder nxActionConntrackBuilder = new NxActionConntrackBuilder(); nxActionConntrackBuilder.setFlags(message.readUnsignedShort()); nxActionConntrackBuilder.setZoneSrc(message.readUnsignedInt()); nxActionConntrackBuilder.setConntrackZone(message.readUnsignedShort()); nxActionConntrackBuilder.setRecircTable(message.readUnsignedByte()); message.skipBytes(5); actionConntrackBuilder.setNxActionConntrack(nxActionConntrackBuilder.build()); actionBuilder.setActionChoice(actionConntrackBuilder.build()); return actionBuilder.build(); }
From source file:org.opendaylight.openflowjava.nx.codec.action.LearnCodecUtil.java
License:Open Source License
static short deserializeHeader(ByteBuf message) { // size of experimenter type message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // size of length short length = message.readShort(); // vendor id//from w w w.j av a 2 s.c o m message.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES); // subtype message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); return length; }