@Test public void testSerialize() { SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init(); 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()); }
@Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); OFSerializer<MatchV10> matchSerializer = registry .getSerializer(new MessageTypeKey<>(message.getVersion(), MatchV10.class)); matchSerializer.serialize(message.getMatchV10(), outBuffer); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeZero(PADDING); outBuffer.writeZero(PADDING); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }
OF10FlowRemovedMessageFactory implements OFSerializer<FlowRemovedMessage>, SerializerRegistryInjector { @Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); OFSerializer<MatchV10> matchSerializer = registry .getSerializer(new MessageTypeKey<>(message.getVersion(), MatchV10.class)); matchSerializer.serialize(message.getMatchV10(), outBuffer); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeZero(PADDING); outBuffer.writeZero(PADDING); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); } }
OF10FlowRemovedMessageFactory implements OFSerializer<FlowRemovedMessage>, SerializerRegistryInjector { @Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); OFSerializer<MatchV10> matchSerializer = registry .getSerializer(new MessageTypeKey<>(message.getVersion(), MatchV10.class)); matchSerializer.serialize(message.getMatchV10(), outBuffer); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeZero(PADDING); outBuffer.writeZero(PADDING); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }  }
OF10FlowRemovedMessageFactory implements OFSerializer<FlowRemovedMessage>, SerializerRegistryInjector { @Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); OFSerializer<MatchV10> matchSerializer = registry .getSerializer(new MessageTypeKey<>(message.getVersion(), MatchV10.class)); matchSerializer.serialize(message.getMatchV10(), outBuffer); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeZero(PADDING); outBuffer.writeZero(PADDING); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void injectSerializerRegistry(SerializerRegistry serializerRegistry); @Override void serialize(FlowRemovedMessage message, ByteBuf outBuffer); }
OF10FlowRemovedMessageFactory implements OFSerializer<FlowRemovedMessage>, SerializerRegistryInjector { @Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); OFSerializer<MatchV10> matchSerializer = registry .getSerializer(new MessageTypeKey<>(message.getVersion(), MatchV10.class)); matchSerializer.serialize(message.getMatchV10(), outBuffer); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeZero(PADDING); outBuffer.writeZero(PADDING); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void injectSerializerRegistry(SerializerRegistry serializerRegistry); @Override void serialize(FlowRemovedMessage message, ByteBuf outBuffer);  }