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.EchoInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link EchoInputMessageFactory} for correct translation from POJO * @throws Exception /*from w w w . j av a2 s .com*/ */ @Test public void testV13() throws Exception { EchoInputBuilder eib = new EchoInputBuilder(); BufferHelper.setupHeader(eib, EncodeConstants.OF13_VERSION_ID); EchoInput ei = eib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance(); eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, ei); BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link EchoInputMessageFactory} for correct translation from POJO * @throws Exception /*from w ww . j a va 2 s. c om*/ */ @Test public void testV10() throws Exception { EchoInputBuilder eib = new EchoInputBuilder(); BufferHelper.setupHeader(eib, EncodeConstants.OF10_VERSION_ID); EchoInput ei = eib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance(); eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, ei); BufferHelper.checkHeaderV10(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoOutputMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() throws Exception { EchoOutputBuilder builder = new EchoOutputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); byte[] data = ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"); builder.setData(data);// w w w . j a v a2 s . c o m EchoOutput message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 24); 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.EchoReplyInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO * @throws Exception //from ww w .j ava 2s . co m */ @Test public void testV13() throws Exception { EchoReplyInputBuilder erib = new EchoReplyInputBuilder(); BufferHelper.setupHeader(erib, EncodeConstants.OF13_VERSION_ID); EchoReplyInput eri = erib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance(); eimf.messageToBuffer(EncodeConstants.OF13_VERSION_ID, out, eri); BufferHelper.checkHeaderV13(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoReplyInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO * @throws Exception //w w w.jav a 2 s. co m */ @Test public void testV10() throws Exception { EchoReplyInputBuilder erib = new EchoReplyInputBuilder(); BufferHelper.setupHeader(erib, EncodeConstants.OF10_VERSION_ID); EchoReplyInput eri = erib.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance(); eimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, eri); BufferHelper.checkHeaderV10(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.EchoRequestMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() throws Exception { EchoRequestMessageBuilder builder = new EchoRequestMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); byte[] data = ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"); builder.setData(data);/*from ww w. jav a 2s .co m*/ EchoRequestMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 24); 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.ErrorMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() throws Exception { ErrorMessageBuilder builder = new ErrorMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setType(10);/*w ww. j av a2 s. c o m*/ builder.setCode(20); byte[] data = ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"); builder.setData(data); ErrorMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 28); Assert.assertEquals("Wrong Type", message.getType().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong Code", message.getCode().intValue(), serializedBuffer.readShort()); 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.ExperimenterInputMessageFactoryTest.java
License:Open Source License
/** * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO * @throws Exception /*from w w w . ja v a2 s . c o m*/ */ @Test public void test() throws Exception { ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setExperimenter(0x0001020304L); builder.setExpType(0x0001020304L); builder.setData(new byte[] { 0x01, 0x02, 0x03 }); ExperimenterInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); ExperimenterInputMessageFactory factory = ExperimenterInputMessageFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, factory.computeLength(message)); Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt()); Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt()); Assert.assertArrayEquals("Wrong data", message.getData(), readData(out)); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowModInputMessageFactoryTest.java
License:Open Source License
/** * @throws Exception /*from w ww. ja va 2s.c o m*/ * Testing of {@link FlowModInputMessageFactory} for correct translation from POJO */ @Test public void testFlowModInputMessageFactory() throws Exception { FlowModInputBuilder builder = new FlowModInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 }; builder.setCookie(new BigInteger(1, cookie)); byte[] cookieMask = new byte[] { (byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30 }; builder.setCookieMask(new BigInteger(1, cookieMask)); builder.setTableId(new TableId(65L)); builder.setCommand(FlowModCommand.forValue(2)); builder.setIdleTimeout(12); builder.setHardTimeout(0); builder.setPriority(126); builder.setBufferId(2L); builder.setOutPort(new PortNumber(4422L)); builder.setOutGroup(98L); builder.setFlags(new FlowModFlags(true, false, true, false, true)); MatchBuilder matchBuilder = new MatchBuilder(); matchBuilder.setType(OxmMatchType.class); List<MatchEntries> entries = new ArrayList<>(); MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); entriesBuilder.setOxmClass(OpenflowBasicClass.class); entriesBuilder.setOxmMatchField(InPhyPort.class); entriesBuilder.setHasMask(false); PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder(); portNumberBuilder.setPortNumber(new PortNumber(42L)); entriesBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build()); entries.add(entriesBuilder.build()); entriesBuilder.setOxmClass(Nxm0Class.class); entriesBuilder.setOxmMatchField(IpEcn.class); entriesBuilder.setHasMask(false); EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); ecnBuilder.setEcn((short) 4); entriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build()); entries.add(entriesBuilder.build()); matchBuilder.setMatchEntries(entries); builder.setMatch(matchBuilder.build()); List<Instruction> instructions = new ArrayList<>(); InstructionBuilder insBuilder = new InstructionBuilder(); insBuilder.setType(GotoTable.class); TableIdInstructionBuilder idBuilder = new TableIdInstructionBuilder(); idBuilder.setTableId((short) 43); insBuilder.addAugmentation(TableIdInstruction.class, idBuilder.build()); instructions.add(insBuilder.build()); insBuilder.setType(WriteMetadata.class); MetadataInstructionBuilder metaBuilder = new MetadataInstructionBuilder(); metaBuilder.setMetadata(cookie); metaBuilder.setMetadataMask(cookieMask); insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build()); instructions.add(insBuilder.build()); insBuilder = new InstructionBuilder(); insBuilder.setType(ApplyActions.class); insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build()); instructions.add(insBuilder.build()); builder.setInstruction(instructions); FlowModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); FlowModInputMessageFactory factory = FlowModInputMessageFactory.getInstance(); factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message); BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message)); cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(cookie); Assert.assertEquals("Wrong cookie", message.getCookie(), new BigInteger(1, cookie)); cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(cookieMask); Assert.assertEquals("Wrong cookieMask", message.getCookieMask(), new BigInteger(1, cookieMask)); Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readUnsignedByte()); Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedByte()); Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort()); Assert.assertEquals("Wrong hardTimeOut", message.getHardTimeout().intValue(), out.readShort()); Assert.assertEquals("Wrong priority", message.getPriority().intValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong bufferId", message.getBufferId().intValue(), out.readUnsignedInt()); Assert.assertEquals("Wrong outPort", message.getOutPort().getValue().intValue(), out.readUnsignedInt()); Assert.assertEquals("Wrong outGroup", message.getOutGroup().intValue(), out.readUnsignedInt()); Assert.assertEquals("Wrong flags", message.getFlags(), createFlowModFlagsFromBitmap(out.readUnsignedShort())); out.skipBytes(PADDING_IN_FLOW_MOD_MESSAGE); Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort()); out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort()); short fieldAndMask = out.readUnsignedByte(); Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1); out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong oxm value", 42, out.readUnsignedInt()); Assert.assertEquals("Wrong oxm class", 0, out.readUnsignedShort()); fieldAndMask = out.readUnsignedByte(); Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1); out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong oxm value", 4, out.readUnsignedByte()); out.skipBytes(7); Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort()); out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); Assert.assertEquals("Wrong instruction value", 43, out.readUnsignedByte()); out.skipBytes(3); Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort()); out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES); byte[] cookieRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(cookieRead); byte[] cookieMaskRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; out.readBytes(cookieMaskRead); Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead); Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead); Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort()); out.skipBytes(4); Assert.assertTrue("Unread data", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowRemovedMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() throws Exception { FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setCookie(BigInteger.valueOf(1234L)); builder.setPriority(1234);//from w w w . j a va2s . c om builder.setReason(FlowRemovedReason.forValue(2)); builder.setTableId(new TableId(65L)); builder.setDurationSec(1234L); builder.setDurationNsec(1234L); builder.setIdleTimeout(1234); builder.setHardTimeout(1234); builder.setPacketCount(BigInteger.valueOf(1234L)); builder.setByteCount(BigInteger.valueOf(1234L)); 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()); FlowRemovedMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 72); Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong priority", message.getPriority().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readByte()); Assert.assertEquals("Wrong Table ID", message.getTableId().getValue().intValue(), serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong duration sec", message.getDurationSec().intValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong duration nsec", message.getDurationNsec().intValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong Idle timeout", message.getIdleTimeout().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong Hard timeout", message.getIdleTimeout().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong Packet count", message.getPacketCount().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong Byte count", message.getByteCount().longValue(), serializedBuffer.readLong()); 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); }