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.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testTableBodySerialize() { builder.setType(MultipartType.forValue(3)); MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder(); MultipartReplyTableBuilder table = new MultipartReplyTableBuilder(); table.setTableStats(createTableStats()); tableCase.setMultipartReplyTable(table.build()); builder.setMultipartReplyBody(tableCase.build()); message = builder.build();// w w w.j a v a 2 s . 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, 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); 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.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();/* w w w . ja va 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();//w ww . j a va 2 s . 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, 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.QueueGetConfigReplyMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { QueueGetConfigReplyMessageFactory serializer = new QueueGetConfigReplyMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init();/* w w w . jav a 2 s . 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.openflowjava.nx.codec.action.LearnCodecUtil.java
License:Open Source License
static short deserializeHeader(ByteBuf message) { // size of experimenter type message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // size of length short length = message.readShort(); // vendor id/*from w ww .j a v a 2 s . c o m*/ message.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES); // subtype message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); return length; }
From source file:org.opendaylight.openflowjava.nx.codec.action.LearnCodecUtil.java
License:Open Source License
private static FlowMods readFlowMod(ByteBuf message) { short header = message.readShort(); length -= EncodeConstants.SIZE_OF_SHORT_IN_BYTES; if (header == 0) { return null; }/* w w w. j a v a2 s .c o m*/ short src = (short) ((header & SRC_MASK) >> SRC_POS); short dst = (short) ((header & DST_MASK) >> DST_POS); short numBits = (short) (header & NUM_BITS_MASK); if (src == 0 && dst == 0 && numBits != 0) { return readFlowModAddMatchFromField(message, numBits); } else if (src == 0 && dst == 0) { message.skipBytes(EMPTY_FLOW_MOD_LENGTH); length -= EMPTY_FLOW_MOD_LENGTH; } else if (src == 1 && dst == 0) { return readFlowModAddMatchFromValue(message, numBits); } else if (src == 0 && dst == 1) { return readFlowModCopyFromField(message, numBits); } else if (src == 1 && dst == 1) { return readFlowModCopyFromValue(message, numBits); } else if (src == 0 && dst == 2) { return readFlowToPort(message, numBits); } return null; }
From source file:org.opendaylight.openflowjava.nx.codec.action.LearnCodecUtil.java
License:Open Source License
private static FlowMods readFlowModAddMatchFromField(ByteBuf message, short numBits) { FlowModAddMatchFromFieldBuilder builder = new FlowModAddMatchFromFieldBuilder(); builder.setSrcField((long) message.readInt()); builder.setSrcOfs((int) message.readShort()); builder.setDstField((long) message.readInt()); builder.setDstOfs((int) message.readShort()); builder.setFlowModNumBits((int) numBits); length -= FROM_FIELD_LENGTH - EncodeConstants.SIZE_OF_SHORT_IN_BYTES; FlowModsBuilder flowModsBuilder = new FlowModsBuilder(); FlowModAddMatchFromFieldCaseBuilder caseBuilder = new FlowModAddMatchFromFieldCaseBuilder(); caseBuilder.setFlowModAddMatchFromField(builder.build()); flowModsBuilder.setFlowModSpec(caseBuilder.build()); return flowModsBuilder.build(); }
From source file:org.opendaylight.openflowjava.nx.codec.action.LearnCodecUtil.java
License:Open Source License
private static FlowMods readFlowModAddMatchFromValue(ByteBuf message, short numBits) { FlowModAddMatchFromValueBuilder builder = new FlowModAddMatchFromValueBuilder(); builder.setValue((int) message.readUnsignedShort()); builder.setSrcField((long) message.readInt()); builder.setSrcOfs((int) message.readShort()); builder.setFlowModNumBits((int) numBits); length -= FROM_VALUE_LENGTH - EncodeConstants.SIZE_OF_SHORT_IN_BYTES; FlowModsBuilder flowModsBuilder = new FlowModsBuilder(); FlowModAddMatchFromValueCaseBuilder caseBuilder = new FlowModAddMatchFromValueCaseBuilder(); caseBuilder.setFlowModAddMatchFromValue(builder.build()); flowModsBuilder.setFlowModSpec(caseBuilder.build()); return flowModsBuilder.build(); }
From source file:org.opendaylight.openflowjava.nx.codec.action.LearnCodecUtil.java
License:Open Source License
private static FlowMods readFlowModCopyFromField(ByteBuf message, short numBits) { FlowModCopyFieldIntoFieldBuilder builder = new FlowModCopyFieldIntoFieldBuilder(); builder.setSrcField((long) message.readInt()); builder.setSrcOfs((int) message.readShort()); builder.setDstField((long) message.readInt()); builder.setDstOfs((int) message.readShort()); builder.setFlowModNumBits((int) numBits); length -= FROM_FIELD_LENGTH - EncodeConstants.SIZE_OF_SHORT_IN_BYTES; FlowModsBuilder flowModsBuilder = new FlowModsBuilder(); FlowModCopyFieldIntoFieldCaseBuilder caseBuilder = new FlowModCopyFieldIntoFieldCaseBuilder(); caseBuilder.setFlowModCopyFieldIntoField(builder.build()); flowModsBuilder.setFlowModSpec(caseBuilder.build()); return flowModsBuilder.build(); }
From source file:org.opendaylight.openflowjava.nx.codec.action.LearnCodecUtil.java
License:Open Source License
private static FlowMods readFlowModCopyFromValue(ByteBuf message, short numBits) { FlowModCopyValueIntoFieldBuilder builder = new FlowModCopyValueIntoFieldBuilder(); builder.setValue((int) message.readUnsignedShort()); builder.setDstField((long) message.readInt()); builder.setDstOfs((int) message.readShort()); builder.setFlowModNumBits((int) numBits); length -= FROM_VALUE_LENGTH - EncodeConstants.SIZE_OF_SHORT_IN_BYTES; FlowModsBuilder flowModsBuilder = new FlowModsBuilder(); FlowModCopyValueIntoFieldCaseBuilder caseBuilder = new FlowModCopyValueIntoFieldCaseBuilder(); caseBuilder.setFlowModCopyValueIntoField(builder.build()); flowModsBuilder.setFlowModSpec(caseBuilder.build()); return flowModsBuilder.build(); }