List of usage examples for io.netty.buffer ByteBuf readUnsignedShort
public abstract int readUnsignedShort();
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10FlowRemovedMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init();/*from w w w .j av a 2s .co m*/ OF10FlowRemovedMessageFactory serializer = new OF10FlowRemovedMessageFactory(); serializer.injectSerializerRegistry(registry); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 88); 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()); byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x01, 0x01, 0x04, 0x01 }; byte[] cookieRead = new byte[8]; serializedBuffer.readBytes(cookieRead); Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead); Assert.assertEquals("Wrong priority", 1, serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong reason", 1, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(1); Assert.assertEquals("Wrong duration", 1L, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong duration nsec", 1L, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong idle timeout", 12, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(2); Assert.assertEquals("Wrong packet count", 1L, serializedBuffer.readLong()); Assert.assertEquals("Wrong byte count", 2L, serializedBuffer.readLong()); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10PacketInMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { OF10PacketInMessageFactory serializer = new OF10PacketInMessageFactory(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 34); Assert.assertEquals("Wrong buffer id", message.getBufferId().longValue(), serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong total len", message.getTotalLen().intValue(), serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong port in", message.getInPort().intValue(), serializedBuffer.readUnsignedShort()); Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(1);/*w ww . j ava 2 s .c om*/ Assert.assertArrayEquals("Wrong data", message.getData(), serializedBuffer.readBytes(serializedBuffer.readableBytes()).array()); }
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();// w w w. ja va 2 s . com 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 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();/*from w w w . j a v a 2 s . co 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.PacketInMessageFactoryTest.java
License:Open Source License
@Test public void testSerialize() { PacketInMessageFactory packetInSerializationFactory = new PacketInMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init();//from w ww. j a va 2 s .c o m MatchEntriesInitializer.registerMatchEntrySerializers(registry); packetInSerializationFactory.injectSerializerRegistry(registry); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); packetInSerializationFactory.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()); byte[] 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); Assert.assertArrayEquals("Wrong data", message.getData(), serializedBuffer.readBytes(serializedBuffer.readableBytes()).array()); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.util.BufferHelper.java
License:Open Source License
private static void checkHeader(ByteBuf input, byte msgType, int length, Short version) { Assert.assertEquals("Wrong version", version, Short.valueOf(input.readByte())); Assert.assertEquals("Wrong type", msgType, input.readByte()); Assert.assertEquals("Wrong length", length, input.readUnsignedShort()); Assert.assertEquals("Wrong Xid", DEFAULT_XID, Long.valueOf(input.readUnsignedInt())); }
From source file:org.opendaylight.openflowjava.nx.api.impl.ActionDeserializer.java
License:Open Source License
@Override public Action deserialize(ByteBuf message) { int startPossition = message.readerIndex(); // size of experimenter type message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // size of length message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); long experimenterId = message.readUnsignedInt(); if (NiciraConstants.NX_VENDOR_ID != experimenterId) { throw new IllegalStateException("Experimenter ID is not Nicira vendor id but is " + experimenterId); }//w w w . j a v a 2s .c om int subtype = message.readUnsignedShort(); NiciraActionDeserializerKey key = new NiciraActionDeserializerKey(version, subtype); OFDeserializer<Action> actionDeserializer = NiciraExtensionCodecRegistratorImpl.getActionDeserializer(key); if (actionDeserializer == null) { LOG.info("No deserializer was found for key {}", key); return null; } message.readerIndex(startPossition); return actionDeserializer.deserialize(message); }
From source file:org.opendaylight.openflowjava.nx.codec.action.ConntrackCodec.java
License:Open Source License
@Override public Action deserialize(final ByteBuf message) { ActionBuilder actionBuilder = deserializeHeader(message); ActionConntrackBuilder actionConntrackBuilder = new ActionConntrackBuilder(); NxActionConntrackBuilder nxActionConntrackBuilder = new NxActionConntrackBuilder(); nxActionConntrackBuilder.setFlags(message.readUnsignedShort()); nxActionConntrackBuilder.setZoneSrc(message.readUnsignedInt()); nxActionConntrackBuilder.setConntrackZone(message.readUnsignedShort()); nxActionConntrackBuilder.setRecircTable(message.readUnsignedByte()); message.skipBytes(5);// w w w . j ava2s . c om actionConntrackBuilder.setNxActionConntrack(nxActionConntrackBuilder.build()); actionBuilder.setActionChoice(actionConntrackBuilder.build()); return actionBuilder.build(); }
From source file:org.opendaylight.openflowjava.nx.codec.action.LearnCodecUtil.java
License:Open Source License
static void deserializeLearnHeader(final ByteBuf message, NxActionLearnBuilder nxActionLearnBuilder) { nxActionLearnBuilder.setIdleTimeout(message.readUnsignedShort()); nxActionLearnBuilder.setHardTimeout(message.readUnsignedShort()); nxActionLearnBuilder.setPriority(message.readUnsignedShort()); nxActionLearnBuilder.setCookie(BigInteger.valueOf(message.readLong())); nxActionLearnBuilder.setFlags(message.readUnsignedShort()); nxActionLearnBuilder.setTableId(message.readUnsignedByte()); message.skipBytes(1);/*from w w w .ja v a 2s.co m*/ nxActionLearnBuilder.setFinIdleTimeout(message.readUnsignedShort()); nxActionLearnBuilder.setFinHardTimeout(message.readUnsignedShort()); }
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(); }