List of usage examples for io.netty.buffer ByteBuf readShort
public abstract short readShort();
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
@Test public void testAggregateSerialize() { builder.setType(MultipartType.forValue(2)); MultipartReplyAggregateCaseBuilder aggregateCase = new MultipartReplyAggregateCaseBuilder(); MultipartReplyAggregateBuilder aggregate = new MultipartReplyAggregateBuilder(); aggregate.setPacketCount(BigInteger.valueOf(1L)); aggregate.setByteCount(BigInteger.valueOf(1L)); aggregate.setFlowCount(1L);/*from w w w. j a v a2 s . c om*/ aggregateCase.setMultipartReplyAggregate(aggregate.build()); builder.setMultipartReplyBody(aggregateCase.build()); message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 40); Assert.assertEquals("Wrong type", MultipartType.OFPMPAGGREGATE.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); serializedBuffer.skipBytes(PADDING); MultipartReplyAggregateCase body = (MultipartReplyAggregateCase) message.getMultipartReplyBody(); MultipartReplyAggregate messageOutput = body.getMultipartReplyAggregate(); Assert.assertEquals("Wrong Packet count", messageOutput.getPacketCount().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong Byte count", messageOutput.getByteCount().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong Flow count", messageOutput.getFlowCount().longValue(), serializedBuffer.readInt()); serializedBuffer.skipBytes(4); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
@Test public void testFlowSerialize() { builder.setType(MultipartType.forValue(1)); MultipartReplyFlowCaseBuilder flowCase = new MultipartReplyFlowCaseBuilder(); MultipartReplyFlowBuilder flow = new MultipartReplyFlowBuilder(); flow.setFlowStats(createFlowStats()); flowCase.setMultipartReplyFlow(flow.build()); builder.setMultipartReplyBody(flowCase.build()); message = builder.build();// w ww.ja va 2s . c o m ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 192); Assert.assertEquals("Wrong type", MultipartType.OFPMPFLOW.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); serializedBuffer.skipBytes(PADDING); testFlowBody(message.getMultipartReplyBody(), serializedBuffer); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
private static void testFlowBody(MultipartReplyBody body, ByteBuf output) { MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body; MultipartReplyFlow flow = flowCase.getMultipartReplyFlow(); FlowStats flowStats = flow.getFlowStats().get(0); Assert.assertEquals("Wrong length", 176, output.readShort()); Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(), output.readUnsignedByte()); output.skipBytes(1);/*from w ww . j a v a2 s. c o m*/ Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(), output.readInt()); Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(), output.readInt()); Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), output.readShort()); Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(), output.readShort()); Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(), output.readShort()); output.skipBytes(6); Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), output.readLong()); Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(), output.readLong()); Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), output.readLong()); Assert.assertEquals("Wrong match type", 1, output.readUnsignedShort()); output.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort()); short fieldAndMask = output.readUnsignedByte(); Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1); output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong oxm value", 42, output.readUnsignedInt()); Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort()); fieldAndMask = output.readUnsignedByte(); Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1); Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1); output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES); Assert.assertEquals("Wrong oxm value", 4, output.readUnsignedByte()); output.skipBytes(7); Assert.assertEquals("Wrong instruction type", 1, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction table-id", 5, output.readUnsignedByte()); output.skipBytes(3); Assert.assertEquals("Wrong instruction type", 2, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort()); output.skipBytes(4); byte[] actual = new byte[8]; output.readBytes(actual); Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07", ByteBufUtils.bytesToHexString(actual)); actual = new byte[8]; output.readBytes(actual); Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00", ByteBufUtils.bytesToHexString(actual)); Assert.assertEquals("Wrong instruction type", 5, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort()); output.skipBytes(4); Assert.assertEquals("Wrong instruction type", 6, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction meter-id", 42, output.readUnsignedInt()); Assert.assertEquals("Wrong instruction type", 3, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 32, output.readUnsignedShort()); output.skipBytes(4); Assert.assertEquals("Wrong action type", 0, output.readUnsignedShort()); Assert.assertEquals("Wrong action length", 16, output.readUnsignedShort()); Assert.assertEquals("Wrong action type", 45, output.readUnsignedInt()); Assert.assertEquals("Wrong action type", 55, output.readUnsignedShort()); output.skipBytes(6); Assert.assertEquals("Wrong action type", 23, output.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort()); Assert.assertEquals("Wrong action type", 64, output.readUnsignedByte()); output.skipBytes(3); Assert.assertEquals("Wrong instruction type", 4, output.readUnsignedShort()); Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort()); output.skipBytes(4); Assert.assertEquals("Wrong action type", 17, output.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort()); Assert.assertEquals("Wrong action ethertype", 14, output.readUnsignedShort()); output.skipBytes(2); Assert.assertEquals("Wrong action type", 27, output.readUnsignedShort()); Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort()); output.skipBytes(4); Assert.assertTrue("Not all data were read", output.readableBytes() == 0); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactoryTest.java
License:Open Source License
@Test public void testDescSerialize() { builder.setType(MultipartType.forValue(0)); MultipartReplyDescCaseBuilder descCase = new MultipartReplyDescCaseBuilder(); MultipartReplyDescBuilder desc = new MultipartReplyDescBuilder(); desc.setMfrDesc("Test"); desc.setHwDesc("Test"); desc.setSwDesc("Test"); desc.setSerialNum("12345"); desc.setDpDesc("Test"); descCase.setMultipartReplyDesc(desc.build()); builder.setMultipartReplyBody(descCase.build()); message = builder.build();/* w w w . j a v a 2 s . c om*/ ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 1072); Assert.assertEquals("Wrong type", MultipartType.OFPMPDESC.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); serializedBuffer.skipBytes(PADDING); Assert.assertEquals("Wrong desc body", message.getMultipartReplyBody(), decodeDescBody(serializedBuffer)); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10FeaturesReplyMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { OF10FeaturesReplyMessageFactory serializer = new OF10FeaturesReplyMessageFactory(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 80); Assert.assertEquals("Wrong datapath id", message.getDatapathId().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong n buffers", message.getBuffers().longValue(), serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong n tables", message.getTables().shortValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(3);//from w w w.j av a2s. c om Assert.assertEquals("Wrong capabilities", message.getCapabilitiesV10(), createCapabilities(serializedBuffer.readInt())); Assert.assertEquals("Wrong actions", message.getActionsV10(), createActionsV10(serializedBuffer.readInt())); PhyPort port = message.getPhyPort().get(0); Assert.assertEquals("Wrong port No", port.getPortNo().intValue(), serializedBuffer.readShort()); byte[] address = new byte[6]; serializedBuffer.readBytes(address); Assert.assertEquals("Wrong MacAddress", port.getHwAddr().getValue().toLowerCase(), new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase()); byte[] name = new byte[16]; serializedBuffer.readBytes(name); Assert.assertEquals("Wrong name", port.getName(), new String(name).trim()); Assert.assertEquals("Wrong config", port.getConfigV10(), createPortConfig(serializedBuffer.readInt())); Assert.assertEquals("Wrong state", port.getStateV10(), createPortState(serializedBuffer.readInt())); Assert.assertEquals("Wrong current", port.getCurrentFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong advertised", port.getAdvertisedFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong supported", port.getSupportedFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong peer", port.getPeerFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10PortStatusMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { OF10PortStatusMessageFactory serializer = new OF10PortStatusMessageFactory(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 64); Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(7);//from w w w . ja v a 2 s. c om Assert.assertEquals("Wrong port No", message.getPortNo().intValue(), serializedBuffer.readShort()); byte[] address = new byte[6]; serializedBuffer.readBytes(address); Assert.assertEquals("Wrong MacAddress", message.getHwAddr().getValue().toLowerCase(), new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase()); byte[] name = new byte[16]; serializedBuffer.readBytes(name); Assert.assertEquals("Wrong name", message.getName(), new String(name).trim()); Assert.assertEquals("Wrong config", message.getConfigV10(), createPortConfig(serializedBuffer.readInt())); Assert.assertEquals("Wrong state", message.getStateV10(), createPortState(serializedBuffer.readInt())); Assert.assertEquals("Wrong current", message.getCurrentFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong advertised", message.getAdvertisedFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong supported", message.getSupportedFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong peer", message.getPeerFeaturesV10(), createPortFeatures(serializedBuffer.readInt())); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10QueueGetConfigReplyMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { OF10QueueGetConfigReplyMessageFactory serializer = new OF10QueueGetConfigReplyMessageFactory(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 40); Assert.assertEquals("Wrong port", message.getPort().getValue().longValue(), serializedBuffer.readShort()); serializedBuffer.skipBytes(6);// w w w . j a v a2 s . c o m Assert.assertEquals("Wrong queue Id", message.getQueues().get(0).getQueueId().getValue().longValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong length", 24, serializedBuffer.readShort()); serializedBuffer.skipBytes(2); 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(4); RateQueueProperty rateQueueProperty = properties.get(0).getAugmentation(RateQueueProperty.class); Assert.assertEquals("Wrong rate", rateQueueProperty.getRate().intValue(), serializedBuffer.readShort()); serializedBuffer.skipBytes(6); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testDescBodySerialize() { builder.setType(MultipartType.forValue(0)); MultipartReplyDescCaseBuilder descCase = new MultipartReplyDescCaseBuilder(); MultipartReplyDescBuilder desc = new MultipartReplyDescBuilder(); desc.setMfrDesc("Test"); desc.setHwDesc("Test"); desc.setSwDesc("Test"); desc.setSerialNum("12345"); desc.setDpDesc("Test"); descCase.setMultipartReplyDesc(desc.build()); builder.setMultipartReplyBody(descCase.build()); message = builder.build();/* w w w . 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, 1068); Assert.assertEquals("Wrong type", MultipartType.OFPMPDESC.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); Assert.assertEquals("Wrong desc body", message.getMultipartReplyBody(), decodeDescBody(serializedBuffer)); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testFlowBodySerialize() { builder.setType(MultipartType.forValue(1)); MultipartReplyFlowCaseBuilder flowCase = new MultipartReplyFlowCaseBuilder(); MultipartReplyFlowBuilder flow = new MultipartReplyFlowBuilder(); flow.setFlowStats(createFlowStats()); flowCase.setMultipartReplyFlow(flow.build()); builder.setMultipartReplyBody(flowCase.build()); message = builder.build();/*from w ww. j a v a2s . c o 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, 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); 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.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testAggregateBodySerialize() { 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);// w w w. ja va 2 s .c o m aggregateCase.setMultipartReplyAggregate(aggregate.build()); builder.setMultipartReplyBody(aggregateCase.build()); message = builder.build(); 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, 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); }