Bug 752 - removed model ambiguities
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / GroupModInputMessageFactory.java
index 594e4f3aa4a184f866f463e1d7161b621bea224e..c92db9886d2a3571f01cfc2655f5f874be72d679 100644 (file)
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import java.util.List;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.BucketsList;\r
-\r
-/**\r
- * Translates GroupMod messages\r
- * @author timotej.kubas\r
- * @author michal.polkorab\r
- */\r
-public class GroupModInputMessageFactory implements OFSerializer<GroupModInput> {\r
-    private static final byte MESSAGE_TYPE = 15;\r
-    private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;\r
-    private static final int MESSAGE_LENGTH = 16;\r
-    private static final byte LENGTH_OF_BUCKET_STRUCTURE = 16;\r
-    private static GroupModInputMessageFactory instance;\r
-\r
-    private GroupModInputMessageFactory() {\r
-        // singleton\r
-    }\r
-    \r
-    /**\r
-     * @return singleton factory\r
-     */\r
-    public static synchronized GroupModInputMessageFactory getInstance() {\r
-        if (instance == null) {\r
-            instance = new GroupModInputMessageFactory();\r
-        }\r
-        return instance;\r
-    }\r
-    \r
-    @Override\r
-    public void messageToBuffer(short version, ByteBuf out,\r
-            GroupModInput message) {\r
-        ByteBufUtils.writeOFHeader(instance, message, out);\r
-        out.writeShort(message.getCommand().getIntValue());\r
-        out.writeByte(message.getType().getIntValue());\r
-        ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, out);\r
-        out.writeInt(message.getGroupId().intValue());\r
-        encodeBuckets(message.getBucketsList(), out);\r
-    }\r
-\r
-    @Override\r
-    public int computeLength(GroupModInput message) {\r
-        return MESSAGE_LENGTH + computeLengthOfBuckets(message.getBucketsList());\r
-    }\r
-\r
-    @Override\r
-    public byte getMessageType() {\r
-        return MESSAGE_TYPE;\r
-    }\r
-    \r
-    private static void encodeBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {\r
-        final byte PADDING_IN_BUCKET = 4;\r
-        if (buckets != null) {\r
-            for (BucketsList currentBucket : buckets) {\r
-                outBuffer.writeShort(computeLengthOfBucket(currentBucket));\r
-                outBuffer.writeShort(currentBucket.getWeight().shortValue());\r
-                outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue());\r
-                outBuffer.writeInt(currentBucket.getWatchGroup().intValue());\r
-                ByteBufUtils.padBuffer(PADDING_IN_BUCKET, outBuffer);\r
-                ActionsSerializer.encodeActions(currentBucket.getActionsList(), outBuffer);\r
-            }\r
-        }\r
-    }\r
-    \r
-    private static int computeLengthOfBucket(BucketsList bucket) {\r
-        int lengthOfBuckets = 0;\r
-        if (bucket != null) {\r
-            lengthOfBuckets = LENGTH_OF_BUCKET_STRUCTURE + ActionsSerializer.computeLengthOfActions(bucket.getActionsList());\r
-        }\r
-        return lengthOfBuckets;\r
-    }\r
-    \r
-    private static int computeLengthOfBuckets(List<BucketsList> buckets) {\r
-        int lengthOfBuckets = 0;\r
-        if (buckets != null) {\r
-            for (BucketsList currentBucket : buckets) {\r
-                lengthOfBuckets += LENGTH_OF_BUCKET_STRUCTURE + ActionsSerializer.computeLengthOfActions(currentBucket.getActionsList());\r
-            }\r
-        }\r
-        return lengthOfBuckets;\r
-    }\r
-\r
-    \r
-}\r
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
+
+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.impl.util.ByteBufUtils;
+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;
+
+/**
+ * Translates GroupMod messages
+ * @author timotej.kubas
+ * @author michal.polkorab
+ */
+public class GroupModInputMessageFactory implements OFSerializer<GroupModInput> {
+    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);
+    }
+
+    @Override
+    public int computeLength(GroupModInput message) {
+        return MESSAGE_LENGTH + computeLengthOfBuckets(message.getBucketsList());
+    }
+
+    @Override
+    public byte getMessageType() {
+        return MESSAGE_TYPE;
+    }
+    
+    private static void encodeBuckets(List<BucketsList> buckets, ByteBuf outBuffer) {
+        if (buckets != null) {
+            for (BucketsList currentBucket : buckets) {
+                outBuffer.writeShort(computeLengthOfBucket(currentBucket));
+                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);
+            }
+        }
+    }
+    
+    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<BucketsList> buckets) {
+        int lengthOfBuckets = 0;
+        if (buckets != null) {
+            for (BucketsList currentBucket : buckets) {
+                lengthOfBuckets += LENGTH_OF_BUCKET_STRUCTURE
+                        + ActionsSerializer.computeLengthOfActions(currentBucket.getAction());
+            }
+        }
+        return lengthOfBuckets;
+    }
+
+    
+}