@Test public void testSerialize() { PortStatusMessageFactory serializer = new PortStatusMessageFactory(); SerializerRegistry registry = new NetIdeSerializerRegistryImpl(); registry.init(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(message, serializedBuffer); BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 80); Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(PADDING); Assert.assertEquals("Wrong PortNo", message.getPortNo().intValue(), serializedBuffer.readUnsignedInt()); serializedBuffer.skipBytes(PORT_PADDING_1); byte[] address = new byte[6]; serializedBuffer.readBytes(address); Assert.assertEquals("Wrong MacAddress", message.getHwAddr().getValue().toLowerCase(), new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase()); serializedBuffer.skipBytes(PORT_PADDING_2); byte[] name = new byte[16]; serializedBuffer.readBytes(name); Assert.assertEquals("Wrong name", message.getName(), new String(name).trim()); Assert.assertEquals("Wrong config", message.getConfig(), createPortConfig(serializedBuffer.readInt())); Assert.assertEquals("Wrong state", message.getState(), createPortState(serializedBuffer.readInt())); Assert.assertEquals("Wrong current", message.getCurrentFeatures(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong advertised", message.getAdvertisedFeatures(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong supported", message.getSupportedFeatures(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong peer", message.getPeerFeatures(), createPortFeatures(serializedBuffer.readInt())); Assert.assertEquals("Wrong Current speed", message.getCurrSpeed().longValue(), serializedBuffer.readInt()); Assert.assertEquals("Wrong Max speed", message.getMaxSpeed().longValue(), serializedBuffer.readInt()); }
@Override public void serialize(PortStatusMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getPortNo().intValue()); outBuffer.writeZero(PORT_PADDING_1); writeMacAddress(message.getHwAddr().getValue(), outBuffer); outBuffer.writeZero(PORT_PADDING_2); writeName(message.getName(), outBuffer); writePortConfig(message.getConfig(), outBuffer); writePortState(message.getState(), outBuffer); writePortFeatures(message.getCurrentFeatures(), outBuffer); writePortFeatures(message.getAdvertisedFeatures(), outBuffer); writePortFeatures(message.getSupportedFeatures(), outBuffer); writePortFeatures(message.getPeerFeatures(), outBuffer); outBuffer.writeInt(message.getCurrSpeed().intValue()); outBuffer.writeInt(message.getMaxSpeed().intValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }
PortStatusMessageFactory implements OFSerializer<PortStatusMessage> { @Override public void serialize(PortStatusMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getPortNo().intValue()); outBuffer.writeZero(PORT_PADDING_1); writeMacAddress(message.getHwAddr().getValue(), outBuffer); outBuffer.writeZero(PORT_PADDING_2); writeName(message.getName(), outBuffer); writePortConfig(message.getConfig(), outBuffer); writePortState(message.getState(), outBuffer); writePortFeatures(message.getCurrentFeatures(), outBuffer); writePortFeatures(message.getAdvertisedFeatures(), outBuffer); writePortFeatures(message.getSupportedFeatures(), outBuffer); writePortFeatures(message.getPeerFeatures(), outBuffer); outBuffer.writeInt(message.getCurrSpeed().intValue()); outBuffer.writeInt(message.getMaxSpeed().intValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); } }
PortStatusMessageFactory implements OFSerializer<PortStatusMessage> { @Override public void serialize(PortStatusMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getPortNo().intValue()); outBuffer.writeZero(PORT_PADDING_1); writeMacAddress(message.getHwAddr().getValue(), outBuffer); outBuffer.writeZero(PORT_PADDING_2); writeName(message.getName(), outBuffer); writePortConfig(message.getConfig(), outBuffer); writePortState(message.getState(), outBuffer); writePortFeatures(message.getCurrentFeatures(), outBuffer); writePortFeatures(message.getAdvertisedFeatures(), outBuffer); writePortFeatures(message.getSupportedFeatures(), outBuffer); writePortFeatures(message.getPeerFeatures(), outBuffer); outBuffer.writeInt(message.getCurrSpeed().intValue()); outBuffer.writeInt(message.getMaxSpeed().intValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }  }
PortStatusMessageFactory implements OFSerializer<PortStatusMessage> { @Override public void serialize(PortStatusMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getPortNo().intValue()); outBuffer.writeZero(PORT_PADDING_1); writeMacAddress(message.getHwAddr().getValue(), outBuffer); outBuffer.writeZero(PORT_PADDING_2); writeName(message.getName(), outBuffer); writePortConfig(message.getConfig(), outBuffer); writePortState(message.getState(), outBuffer); writePortFeatures(message.getCurrentFeatures(), outBuffer); writePortFeatures(message.getAdvertisedFeatures(), outBuffer); writePortFeatures(message.getSupportedFeatures(), outBuffer); writePortFeatures(message.getPeerFeatures(), outBuffer); outBuffer.writeInt(message.getCurrSpeed().intValue()); outBuffer.writeInt(message.getMaxSpeed().intValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void serialize(PortStatusMessage message, ByteBuf outBuffer); }
PortStatusMessageFactory implements OFSerializer<PortStatusMessage> { @Override public void serialize(PortStatusMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getPortNo().intValue()); outBuffer.writeZero(PORT_PADDING_1); writeMacAddress(message.getHwAddr().getValue(), outBuffer); outBuffer.writeZero(PORT_PADDING_2); writeName(message.getName(), outBuffer); writePortConfig(message.getConfig(), outBuffer); writePortState(message.getState(), outBuffer); writePortFeatures(message.getCurrentFeatures(), outBuffer); writePortFeatures(message.getAdvertisedFeatures(), outBuffer); writePortFeatures(message.getSupportedFeatures(), outBuffer); writePortFeatures(message.getPeerFeatures(), outBuffer); outBuffer.writeInt(message.getCurrSpeed().intValue()); outBuffer.writeInt(message.getMaxSpeed().intValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }  @Override void serialize(PortStatusMessage message, ByteBuf outBuffer);  }