X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fserialization%2Ffactories%2FGroupModInputMessageFactory.java;h=99f578c479ede7c436506071b67b236271a8319f;hb=26aeaa7e2754b2cf4f6ad63055ab3ce34f68c961;hp=c92db9886d2a3571f01cfc2655f5f874be72d679;hpb=a4af04c204a636b6c0782cc2248068e0860a69ad;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java index c92db988..99f578c4 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java @@ -12,9 +12,13 @@ import io.netty.buffer.ByteBuf; import java.util.List; -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.EnhancedTypeKeyMakerFactory; +import org.opendaylight.openflowjava.protocol.impl.util.ListSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList; @@ -23,81 +27,42 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * @author timotej.kubas * @author michal.polkorab */ -public class GroupModInputMessageFactory implements OFSerializer { +public class GroupModInputMessageFactory implements OFSerializer, SerializerRegistryInjector { private static final byte MESSAGE_TYPE = 15; - private static final int MESSAGE_LENGTH = 16; private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1; - private static final byte LENGTH_OF_BUCKET_STRUCTURE = 16; private static final byte PADDING_IN_BUCKET = 4; - private static GroupModInputMessageFactory instance; - - private GroupModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized GroupModInputMessageFactory getInstance() { - if (instance == null) { - instance = new GroupModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - GroupModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getCommand().getIntValue()); - out.writeByte(message.getType().getIntValue()); - ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, out); - out.writeInt(message.getGroupId().getValue().intValue()); - encodeBuckets(message.getBucketsList(), out); - } + private SerializerRegistry registry; @Override - public int computeLength(GroupModInput message) { - return MESSAGE_LENGTH + computeLengthOfBuckets(message.getBucketsList()); + public void serialize(GroupModInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeShort(message.getCommand().getIntValue()); + outBuffer.writeByte(message.getType().getIntValue()); + ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, outBuffer); + outBuffer.writeInt(message.getGroupId().getValue().intValue()); + serializerBuckets(message.getBucketsList(), outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); } - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static void encodeBuckets(List buckets, ByteBuf outBuffer) { + private void serializerBuckets(List buckets, ByteBuf outBuffer) { if (buckets != null) { for (BucketsList currentBucket : buckets) { - outBuffer.writeShort(computeLengthOfBucket(currentBucket)); + int bucketLengthIndex = outBuffer.writerIndex(); + outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); outBuffer.writeShort(currentBucket.getWeight().shortValue()); outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue()); outBuffer.writeInt(currentBucket.getWatchGroup().intValue()); ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer); - ActionsSerializer.encodeActions(currentBucket.getAction(), outBuffer); + ListSerializer.serializeList(currentBucket.getAction(), EnhancedTypeKeyMakerFactory + .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, outBuffer); + outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex); } } } - - private static int computeLengthOfBucket(BucketsList bucket) { - int lengthOfBuckets = 0; - if (bucket != null) { - lengthOfBuckets = LENGTH_OF_BUCKET_STRUCTURE - + ActionsSerializer.computeLengthOfActions(bucket.getAction()); - } - return lengthOfBuckets; - } - - private static int computeLengthOfBuckets(List buckets) { - int lengthOfBuckets = 0; - if (buckets != null) { - for (BucketsList currentBucket : buckets) { - lengthOfBuckets += LENGTH_OF_BUCKET_STRUCTURE - + ActionsSerializer.computeLengthOfActions(currentBucket.getAction()); - } - } - return lengthOfBuckets; + + @Override + public void injectSerializerRegistry(SerializerRegistry serializerRegistry) { + this.registry = serializerRegistry; } - }