@Test public void testSerialize() { FlowRemovedMessageFactory serializer = new FlowRemovedMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init(); serializer.injectSerializerRegistry(registry); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 72); Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong priority", message.getPriority().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readByte()); Assert.assertEquals("Wrong Table ID", message.getTableId().getValue().intValue(), serializedBuffer.readUnsignedByte()); Assert.assertEquals("Wrong duration sec", message.getDurationSec().intValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong duration nsec", message.getDurationNsec().intValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong Idle timeout", message.getIdleTimeout().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong Hard timeout", message.getIdleTimeout().intValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong Packet count", message.getPacketCount().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong Byte count", message.getByteCount().longValue(), serializedBuffer.readLong()); 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); }
@Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeShort(message.getHardTimeout()); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); ByteBufUtils.updateOFHeaderLength(outBuffer); }
FlowRemovedMessageFactory implements OFSerializer<FlowRemovedMessage>, SerializerRegistryInjector { @Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeShort(message.getHardTimeout()); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); ByteBufUtils.updateOFHeaderLength(outBuffer); } }
FlowRemovedMessageFactory implements OFSerializer<FlowRemovedMessage>, SerializerRegistryInjector { @Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeShort(message.getHardTimeout()); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); ByteBufUtils.updateOFHeaderLength(outBuffer); }  }
FlowRemovedMessageFactory implements OFSerializer<FlowRemovedMessage>, SerializerRegistryInjector { @Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeShort(message.getHardTimeout()); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void injectSerializerRegistry(SerializerRegistry serializerRegistry); @Override void serialize(FlowRemovedMessage message, ByteBuf outBuffer); }
FlowRemovedMessageFactory implements OFSerializer<FlowRemovedMessage>, SerializerRegistryInjector { @Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeShort(message.getHardTimeout()); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void injectSerializerRegistry(SerializerRegistry serializerRegistry); @Override void serialize(FlowRemovedMessage message, ByteBuf outBuffer);  }