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.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactoryTest.java
License:Open Source License
/** * Testing OF10StatsRequestInputFactory (Queue) for correct serialization * @throws Exception//from w w w . ja v a 2 s . c om */ @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.OF10VendorInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO * @throws Exception /*from w ww .j a va 2s .c o m*/ */ @Test public void test() throws Exception { ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setExperimenter(0x0001020304L); builder.setData(new byte[] { 0x01, 0x02, 0x03, 0x04 }); ExperimenterInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); OF10VendorInputMessageFactory factory = OF10VendorInputMessageFactory.getInstance(); factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message); BufferHelper.checkHeaderV10(out, (byte) 4, factory.computeLength(message)); Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); byte[] data = new byte[4]; out.readBytes(data); Assert.assertArrayEquals("Wrong data", message.getData(), data); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF13ExperimenterInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO * @throws Exception /*from w w w . j av a2s .c om*/ */ @Test public void test() throws Exception { ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setExperimenter(0x0001020304L); builder.setExpType(0x0001020304L); byte[] expData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; builder.setData(expData); ExperimenterInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); expFactory.serialize(message, out); BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, 24); Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt()); byte[] tmp = new byte[8]; out.readBytes(tmp); Assert.assertArrayEquals("Wrong data", expData, tmp); }
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 w ww . ja va 2 s .com 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 ww .j av a2s .c o 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 // w w w . j a v a 2 s. c o m */ @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 w w . j a v a 2 s . c o m*/ 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 .j a va2 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 /*from www .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)); }