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.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testFlowBodySerialize() throws Exception { MultipartReplyMessageBuilder builder; builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(1)); MultipartReplyFlowCaseBuilder flowCase = new MultipartReplyFlowCaseBuilder(); MultipartReplyFlowBuilder flow = new MultipartReplyFlowBuilder(); flow.setFlowStats(createFlowStats()); flowCase.setMultipartReplyFlow(flow.build()); builder.setMultipartReplyBody(flowCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.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);/*from w w w . jav a 2 s . c o m*/ 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.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testAggregateBodySerialize() throws Exception { MultipartReplyMessageBuilder builder; builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); 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);/*from w w w. java2 s. c om*/ aggregateCase.setMultipartReplyAggregate(aggregate.build()); builder.setMultipartReplyBody(aggregateCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.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.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testTableBodySerialize() throws Exception { MultipartReplyMessageBuilder builder; builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(3)); MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder(); MultipartReplyTableBuilder table = new MultipartReplyTableBuilder(); table.setTableStats(createTableStats()); tableCase.setMultipartReplyTable(table.build()); builder.setMultipartReplyBody(tableCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.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);/*from w ww . j a v a 2 s. c o m*/ 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()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testPortStatsBodySerialize() throws Exception { MultipartReplyMessageBuilder builder; builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(4)); MultipartReplyPortStatsCaseBuilder portStatsCase = new MultipartReplyPortStatsCaseBuilder(); MultipartReplyPortStatsBuilder portStats = new MultipartReplyPortStatsBuilder(); portStats.setPortStats(createPortStats()); portStatsCase.setMultipartReplyPortStats(portStats.build()); builder.setMultipartReplyBody(portStatsCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.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);//from w w w .jav a2s .co m 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.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testQueueBodySerialize() throws Exception { MultipartReplyMessageBuilder builder; builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(5)); MultipartReplyQueueCaseBuilder queueCase = new MultipartReplyQueueCaseBuilder(); MultipartReplyQueueBuilder queue = new MultipartReplyQueueBuilder(); queue.setQueueStats(createQueueStats()); queueCase.setMultipartReplyQueue(queue.build()); builder.setMultipartReplyBody(queueCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.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);//from w w w. ja v a2s . c o m 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.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactoryTest.java
License:Open Source License
/** * Testing OF10StatsRequestInputFactory (Desc) for correct serialization * @throws Exception/*from ww w .java2 s. c o m*/ */ @Test public void testDesc() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setType(MultipartType.OFPMPDESC); builder.setFlags(new MultipartRequestFlags(false)); MultipartRequestDescCaseBuilder caseBuilder = new MultipartRequestDescCaseBuilder(); MultipartRequestDescBuilder descBuilder = new MultipartRequestDescBuilder(); caseBuilder.setMultipartRequestDesc(descBuilder.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(), 12); Assert.assertEquals("Wrong type", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertTrue("Unread data", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactoryTest.java
License:Open Source License
/** * Testing OF10StatsRequestInputFactory (Flow) for correct serialization * @throws Exception/*from w w w .j a v a 2 s .c o m*/ */ @Test public void testFlow() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setType(MultipartType.OFPMPFLOW); builder.setFlags(new MultipartRequestFlags(false)); MultipartRequestFlowCaseBuilder caseBuilder = new MultipartRequestFlowCaseBuilder(); MultipartRequestFlowBuilder flowBuilder = new MultipartRequestFlowBuilder(); MatchV10Builder matchBuilder = new MatchV10Builder(); matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true)); matchBuilder.setNwSrcMask((short) 8); matchBuilder.setNwDstMask((short) 16); matchBuilder.setInPort(51); matchBuilder.setDlSrc(new MacAddress("00:01:02:03:04:05")); matchBuilder.setDlDst(new MacAddress("05:04:03:02:01:00")); matchBuilder.setDlVlan(52); matchBuilder.setDlVlanPcp((short) 53); matchBuilder.setDlType(54); matchBuilder.setNwTos((short) 55); matchBuilder.setNwProto((short) 56); matchBuilder.setNwSrc(new Ipv4Address("10.0.0.1")); matchBuilder.setNwDst(new Ipv4Address("10.0.0.2")); matchBuilder.setTpSrc(57); matchBuilder.setTpDst(58); flowBuilder.setMatchV10(matchBuilder.build()); flowBuilder.setTableId((short) 1); flowBuilder.setOutPort(42L); caseBuilder.setMultipartRequestFlow(flowBuilder.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(), 56); Assert.assertEquals("Wrong type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong wildcards", 3414271, out.readUnsignedInt()); Assert.assertEquals("Wrong in-port", 51, out.readUnsignedShort()); byte[] dlSrc = new byte[6]; out.readBytes(dlSrc); Assert.assertEquals("Wrong dl-src", "00:01:02:03:04:05", ByteBufUtils.macAddressToString(dlSrc)); byte[] dlDst = new byte[6]; out.readBytes(dlDst); Assert.assertEquals("Wrong dl-dst", "05:04:03:02:01:00", ByteBufUtils.macAddressToString(dlDst)); Assert.assertEquals("Wrong dl-vlan", 52, out.readUnsignedShort()); Assert.assertEquals("Wrong dl-vlan-pcp", 53, out.readUnsignedByte()); out.skipBytes(1); Assert.assertEquals("Wrong dl-type", 54, out.readUnsignedShort()); Assert.assertEquals("Wrong nw-tos", 55, out.readUnsignedByte()); Assert.assertEquals("Wrong nw-proto", 56, out.readUnsignedByte()); out.skipBytes(2); Assert.assertEquals("Wrong nw-src", 167772161, out.readUnsignedInt()); Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt()); Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort()); Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort()); Assert.assertEquals("Wrong table-id", 1, out.readUnsignedByte()); out.skipBytes(1); Assert.assertEquals("Wrong out-port", 42, out.readUnsignedShort()); Assert.assertTrue("Unread data", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactoryTest.java
License:Open Source License
/** * Testing OF10StatsRequestInputFactory (Aggregate) for correct serialization * @throws Exception//from ww w . j a v a2 s . c o m */ @Test public void testAggregate() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setType(MultipartType.OFPMPAGGREGATE); builder.setFlags(new MultipartRequestFlags(false)); MultipartRequestFlowCaseBuilder caseBuilder = new MultipartRequestFlowCaseBuilder(); MultipartRequestFlowBuilder flowBuilder = new MultipartRequestFlowBuilder(); MatchV10Builder matchBuilder = new MatchV10Builder(); matchBuilder.setWildcards( new FlowWildcardsV10(false, false, false, false, false, false, false, false, false, false)); matchBuilder.setNwSrcMask((short) 32); matchBuilder.setNwDstMask((short) 32); matchBuilder.setInPort(51); matchBuilder.setDlSrc(new MacAddress("00:01:02:03:04:05")); matchBuilder.setDlDst(new MacAddress("05:04:03:02:01:00")); matchBuilder.setDlVlan(52); matchBuilder.setDlVlanPcp((short) 53); matchBuilder.setDlType(54); matchBuilder.setNwTos((short) 55); matchBuilder.setNwProto((short) 56); matchBuilder.setNwSrc(new Ipv4Address("10.0.0.1")); matchBuilder.setNwDst(new Ipv4Address("10.0.0.2")); matchBuilder.setTpSrc(57); matchBuilder.setTpDst(58); flowBuilder.setMatchV10(matchBuilder.build()); flowBuilder.setTableId((short) 42); flowBuilder.setOutPort(6653L); caseBuilder.setMultipartRequestFlow(flowBuilder.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(), 56); Assert.assertEquals("Wrong type", 2, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong wildcards", 0, out.readUnsignedInt()); Assert.assertEquals("Wrong in-port", 51, out.readUnsignedShort()); byte[] dlSrc = new byte[6]; out.readBytes(dlSrc); Assert.assertEquals("Wrong dl-src", "00:01:02:03:04:05", ByteBufUtils.macAddressToString(dlSrc)); byte[] dlDst = new byte[6]; out.readBytes(dlDst); Assert.assertEquals("Wrong dl-dst", "05:04:03:02:01:00", ByteBufUtils.macAddressToString(dlDst)); Assert.assertEquals("Wrong dl-vlan", 52, out.readUnsignedShort()); Assert.assertEquals("Wrong dl-vlan-pcp", 53, out.readUnsignedByte()); out.skipBytes(1); Assert.assertEquals("Wrong dl-type", 54, out.readUnsignedShort()); Assert.assertEquals("Wrong nw-tos", 55, out.readUnsignedByte()); Assert.assertEquals("Wrong nw-proto", 56, out.readUnsignedByte()); out.skipBytes(2); Assert.assertEquals("Wrong nw-src", 167772161, out.readUnsignedInt()); Assert.assertEquals("Wrong nw-dst", 167772162, out.readUnsignedInt()); Assert.assertEquals("Wrong tp-src", 57, out.readUnsignedShort()); Assert.assertEquals("Wrong tp-dst", 58, out.readUnsignedShort()); Assert.assertEquals("Wrong table-id", 42, out.readUnsignedByte()); out.skipBytes(1); Assert.assertEquals("Wrong out-port", 6653, out.readUnsignedShort()); Assert.assertTrue("Unread data", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactoryTest.java
License:Open Source License
/** * Testing OF10StatsRequestInputFactory (Table) for correct serialization * @throws Exception//ww w . jav a2 s.c om */ @Test public void testTable() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setType(MultipartType.OFPMPTABLE); builder.setFlags(new MultipartRequestFlags(false)); MultipartRequestTableCaseBuilder caseBuilder = new MultipartRequestTableCaseBuilder(); MultipartRequestTableBuilder tableBuilder = new MultipartRequestTableBuilder(); caseBuilder.setMultipartRequestTable(tableBuilder.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(), 12); Assert.assertEquals("Wrong type", 3, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertTrue("Unread data", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsRequestInputFactoryTest.java
License:Open Source License
/** * Testing OF10StatsRequestInputFactory (Port) for correct serialization * @throws Exception//from w w w .j a v a 2s . c o m */ @Test public void testPort() throws Exception { MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setType(MultipartType.OFPMPPORTSTATS); builder.setFlags(new MultipartRequestFlags(false)); MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder(); MultipartRequestPortStatsBuilder portBuilder = new MultipartRequestPortStatsBuilder(); portBuilder.setPortNo(15L); caseBuilder.setMultipartRequestPortStats(portBuilder.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", 4, out.readUnsignedShort()); Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong port-no", 15, out.readUnsignedShort()); out.skipBytes(6); Assert.assertTrue("Unread data", out.readableBytes() == 0); }