@Test public void test() throws Exception { FlowModInput expectedMessage = createMessage(); SerializerRegistry registry = new SerializerRegistryImpl(); registry.init(); OFSerializer<FlowModInput> serializer = registry .getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, FlowModInput.class)); ByteBuf originalBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(expectedMessage, originalBuffer); originalBuffer.skipBytes(4); FlowModInput deserializedMessage = BufferHelper.deserialize(flowFactory, originalBuffer); Assert.assertEquals("Wrong version", expectedMessage.getVersion(), deserializedMessage.getVersion()); Assert.assertEquals("Wrong XId", expectedMessage.getXid(), deserializedMessage.getXid()); Assert.assertEquals("Wrong cookie", expectedMessage.getCookie(), deserializedMessage.getCookie()); Assert.assertEquals("Wrong cookie mask", expectedMessage.getCookieMask(), deserializedMessage.getCookieMask()); Assert.assertEquals("Wrong table id", expectedMessage.getTableId().getValue(), deserializedMessage.getTableId().getValue()); Assert.assertEquals("Wrong command", expectedMessage.getCommand().getIntValue(), deserializedMessage.getCommand().getIntValue()); Assert.assertEquals("Wrong idle timeout", expectedMessage.getIdleTimeout(), deserializedMessage.getIdleTimeout()); Assert.assertEquals("Wrong hard timeout", expectedMessage.getHardTimeout(), deserializedMessage.getHardTimeout()); Assert.assertEquals("Wrong priority", expectedMessage.getPriority(), deserializedMessage.getPriority()); Assert.assertEquals("Wrong buffer id ", expectedMessage.getBufferId(), deserializedMessage.getBufferId()); Assert.assertEquals("Wrong out port", expectedMessage.getOutPort().getValue(), deserializedMessage.getOutPort().getValue()); Assert.assertEquals("Wrong out group", expectedMessage.getOutGroup(), deserializedMessage.getOutGroup()); Assert.assertEquals("Wrong number of flags", expectedMessage.getFlags().getValue().length, deserializedMessage.getFlags().getValue().length); for (int i = 0; i < expectedMessage.getFlags().getValue().length; i++) { Assert.assertEquals("Wrong flag", expectedMessage.getFlags().getValue()[i], deserializedMessage.getFlags().getValue()[i]); } Assert.assertEquals("Wrong match", expectedMessage.getMatch(), deserializedMessage.getMatch()); Assert.assertEquals("Wrong number of instructions", expectedMessage.getInstruction().size(), deserializedMessage.getInstruction().size()); int i = 0; for (Instruction ins : expectedMessage.getInstruction()) { Assert.assertEquals("Wrong instruction", ins, deserializedMessage.getInstruction().get(i)); i++; } }
@Override public FlowModInput deserialize(ByteBuf rawMessage) { FlowModInputBuilder builder = new FlowModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); builder.setCookie(new BigInteger(1, cookie)); byte[] cookie_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie_mask); builder.setCookieMask(new BigInteger(1, cookie_mask)); builder.setTableId(new TableId((long) rawMessage.readUnsignedByte())); builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedByte())); builder.setIdleTimeout(rawMessage.readUnsignedShort()); builder.setHardTimeout(rawMessage.readUnsignedShort()); builder.setPriority(rawMessage.readUnsignedShort()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setOutPort(new PortNumber(rawMessage.readUnsignedInt())); builder.setOutGroup(rawMessage.readUnsignedInt()); builder.setFlags(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort())); rawMessage.skipBytes(PADDING); OFDeserializer<Match> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); builder.setMatch(matchDeserializer.deserialize(rawMessage)); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry); builder.setInstruction(instructions); return builder.build(); }
FlowModInputMessageFactory implements OFDeserializer<FlowModInput>, DeserializerRegistryInjector { @Override public FlowModInput deserialize(ByteBuf rawMessage) { FlowModInputBuilder builder = new FlowModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); builder.setCookie(new BigInteger(1, cookie)); byte[] cookie_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie_mask); builder.setCookieMask(new BigInteger(1, cookie_mask)); builder.setTableId(new TableId((long) rawMessage.readUnsignedByte())); builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedByte())); builder.setIdleTimeout(rawMessage.readUnsignedShort()); builder.setHardTimeout(rawMessage.readUnsignedShort()); builder.setPriority(rawMessage.readUnsignedShort()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setOutPort(new PortNumber(rawMessage.readUnsignedInt())); builder.setOutGroup(rawMessage.readUnsignedInt()); builder.setFlags(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort())); rawMessage.skipBytes(PADDING); OFDeserializer<Match> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); builder.setMatch(matchDeserializer.deserialize(rawMessage)); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry); builder.setInstruction(instructions); return builder.build(); } }
FlowModInputMessageFactory implements OFDeserializer<FlowModInput>, DeserializerRegistryInjector { @Override public FlowModInput deserialize(ByteBuf rawMessage) { FlowModInputBuilder builder = new FlowModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); builder.setCookie(new BigInteger(1, cookie)); byte[] cookie_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie_mask); builder.setCookieMask(new BigInteger(1, cookie_mask)); builder.setTableId(new TableId((long) rawMessage.readUnsignedByte())); builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedByte())); builder.setIdleTimeout(rawMessage.readUnsignedShort()); builder.setHardTimeout(rawMessage.readUnsignedShort()); builder.setPriority(rawMessage.readUnsignedShort()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setOutPort(new PortNumber(rawMessage.readUnsignedInt())); builder.setOutGroup(rawMessage.readUnsignedInt()); builder.setFlags(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort())); rawMessage.skipBytes(PADDING); OFDeserializer<Match> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); builder.setMatch(matchDeserializer.deserialize(rawMessage)); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry); builder.setInstruction(instructions); return builder.build(); }  }
FlowModInputMessageFactory implements OFDeserializer<FlowModInput>, DeserializerRegistryInjector { @Override public FlowModInput deserialize(ByteBuf rawMessage) { FlowModInputBuilder builder = new FlowModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); builder.setCookie(new BigInteger(1, cookie)); byte[] cookie_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie_mask); builder.setCookieMask(new BigInteger(1, cookie_mask)); builder.setTableId(new TableId((long) rawMessage.readUnsignedByte())); builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedByte())); builder.setIdleTimeout(rawMessage.readUnsignedShort()); builder.setHardTimeout(rawMessage.readUnsignedShort()); builder.setPriority(rawMessage.readUnsignedShort()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setOutPort(new PortNumber(rawMessage.readUnsignedInt())); builder.setOutGroup(rawMessage.readUnsignedInt()); builder.setFlags(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort())); rawMessage.skipBytes(PADDING); OFDeserializer<Match> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); builder.setMatch(matchDeserializer.deserialize(rawMessage)); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry); builder.setInstruction(instructions); return builder.build(); }  @Override FlowModInput deserialize(ByteBuf rawMessage); @Override void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry); }
FlowModInputMessageFactory implements OFDeserializer<FlowModInput>, DeserializerRegistryInjector { @Override public FlowModInput deserialize(ByteBuf rawMessage) { FlowModInputBuilder builder = new FlowModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); builder.setCookie(new BigInteger(1, cookie)); byte[] cookie_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie_mask); builder.setCookieMask(new BigInteger(1, cookie_mask)); builder.setTableId(new TableId((long) rawMessage.readUnsignedByte())); builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedByte())); builder.setIdleTimeout(rawMessage.readUnsignedShort()); builder.setHardTimeout(rawMessage.readUnsignedShort()); builder.setPriority(rawMessage.readUnsignedShort()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setOutPort(new PortNumber(rawMessage.readUnsignedInt())); builder.setOutGroup(rawMessage.readUnsignedInt()); builder.setFlags(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort())); rawMessage.skipBytes(PADDING); OFDeserializer<Match> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); builder.setMatch(matchDeserializer.deserialize(rawMessage)); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry); builder.setInstruction(instructions); return builder.build(); }  @Override FlowModInput deserialize(ByteBuf rawMessage); @Override void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry);  }