List of usage examples for io.netty.buffer UnpooledByteBufAllocator DEFAULT
UnpooledByteBufAllocator DEFAULT
To view the source code for io.netty.buffer UnpooledByteBufAllocator DEFAULT.
Click Source Link
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 www .j a v a 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. ja v a2s . 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, 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 . ja v a2 s. c o m*/ 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 ww w .ja v a 2 s . 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.QueueGetConfigReplyMessageFactory.java
License:Open Source License
@Override public void serialize(GetQueueConfigOutput message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeInt(message.getPort().getValue().intValue()); outBuffer.writeZero(PADDING);//from w w w .jav a2s . c om for (Queues queue : message.getQueues()) { ByteBuf queueBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); queueBuff.writeInt(queue.getQueueId().getValue().intValue()); queueBuff.writeInt(queue.getPort().getValue().intValue()); queueBuff.writeShort(EncodeConstants.EMPTY_LENGTH); queueBuff.writeZero(QUEUE_PADDING); for (QueueProperty property : queue.getQueueProperty()) { ByteBuf propertyBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); propertyBuff.writeShort(property.getProperty().getIntValue()); propertyBuff.writeShort(EncodeConstants.EMPTY_LENGTH); propertyBuff.writeZero(PROPERTY_HEADER_PADDING); switch (property.getProperty()) { case OFPQTMINRATE: serializeRateBody(property.getAugmentation(RateQueueProperty.class), propertyBuff); break; case OFPQTMAXRATE: serializeRateBody(property.getAugmentation(RateQueueProperty.class), propertyBuff); break; case OFPQTEXPERIMENTER: serializeExperimenterBody(property.getAugmentation(ExperimenterIdQueueProperty.class), propertyBuff); break; default: break; } propertyBuff.setShort(PROPERTY_LENGTH_INDEX, propertyBuff.readableBytes()); queueBuff.writeBytes(propertyBuff); } queueBuff.setShort(QUEUE_LENGTH_INDEX, queueBuff.readableBytes()); outBuffer.writeBytes(queueBuff); } ByteBufUtils.updateOFHeaderLength(outBuffer); }
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();/*from www . j av a 2s . c om*/ 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 .ja v a 2 s . c om 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.netide.openflowjava.protocol.impl.util.BufferHelper.java
License:Open Source License
/** * @param payload//w w w .j a v a 2 s.c o m * @return ByteBuf filled with OpenFlow protocol message without first 4 * bytes */ public static ByteBuf buildBuffer(byte[] payload) { ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer(); bb.writeBytes(XID); bb.writeBytes(payload); return bb; }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.util.BufferHelper.java
License:Open Source License
/** * @return ByteBuf filled with OpenFlow protocol header message without * first 4 bytes//from ww w .jav a 2s .c om */ public static ByteBuf buildBuffer() { ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer(); bb.writeBytes(XID); bb.writeBytes(new byte[0]); return bb; }
From source file:org.opendaylight.netide.shim.ShimRelay.java
License:Open Source License
public void sendOpenFlowMessageToCore(ZeroMQBaseConnector coreConnector, DataObject msg, short ofVersion, long xId, long datapathId, int moduleId) { SerializationFactory factory = createSerializationFactory(); SerializerRegistry registry = new SerializerRegistryImpl(); registry.init();/* w ww. ja v a 2s . co m*/ ByteBuf output = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.setSerializerTable(registry); factory.messageToBuffer(ofVersion, output, msg); byte[] bytes = new byte[output.readableBytes()]; output.readBytes(bytes); Message message = new Message(NetIPUtils.StubHeaderFromPayload(bytes), bytes); message.getHeader().setMessageType(MessageType.OPENFLOW); message.getHeader().setDatapathId(datapathId); message.getHeader().setModuleId(moduleId); message.getHeader().setTransactionId((int) xId); coreConnector.SendData(message.toByteRepresentation()); }