@Test public void testSerialize() { PacketInMessageFactory packetInSerializationFactory = new PacketInMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init(); 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()); }
@Override public void serialize(PacketInMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeInt(message.getBufferId().intValue()); outBuffer.writeShort(message.getTotalLen().intValue()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeLong(message.getCookie().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); outBuffer.writeZero(PADDING); byte[] data = message.getData(); if (data != null) { outBuffer.writeBytes(data); } ByteBufUtils.updateOFHeaderLength(outBuffer); }
PacketInMessageFactory implements OFSerializer<PacketInMessage>, SerializerRegistryInjector { @Override public void serialize(PacketInMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeInt(message.getBufferId().intValue()); outBuffer.writeShort(message.getTotalLen().intValue()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeLong(message.getCookie().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); outBuffer.writeZero(PADDING); byte[] data = message.getData(); if (data != null) { outBuffer.writeBytes(data); } ByteBufUtils.updateOFHeaderLength(outBuffer); } }
PacketInMessageFactory implements OFSerializer<PacketInMessage>, SerializerRegistryInjector { @Override public void serialize(PacketInMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeInt(message.getBufferId().intValue()); outBuffer.writeShort(message.getTotalLen().intValue()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeLong(message.getCookie().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); outBuffer.writeZero(PADDING); byte[] data = message.getData(); if (data != null) { outBuffer.writeBytes(data); } ByteBufUtils.updateOFHeaderLength(outBuffer); }  }
PacketInMessageFactory implements OFSerializer<PacketInMessage>, SerializerRegistryInjector { @Override public void serialize(PacketInMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeInt(message.getBufferId().intValue()); outBuffer.writeShort(message.getTotalLen().intValue()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeLong(message.getCookie().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); outBuffer.writeZero(PADDING); byte[] data = message.getData(); if (data != null) { outBuffer.writeBytes(data); } ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void serialize(PacketInMessage message, ByteBuf outBuffer); @Override void injectSerializerRegistry(final SerializerRegistry serializerRegistry); }
PacketInMessageFactory implements OFSerializer<PacketInMessage>, SerializerRegistryInjector { @Override public void serialize(PacketInMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeInt(message.getBufferId().intValue()); outBuffer.writeShort(message.getTotalLen().intValue()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeLong(message.getCookie().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>> getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); outBuffer.writeZero(PADDING); byte[] data = message.getData(); if (data != null) { outBuffer.writeBytes(data); } ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void serialize(PacketInMessage message, ByteBuf outBuffer); @Override void injectSerializerRegistry(final SerializerRegistry serializerRegistry);  }