Merge "Fixing OF Multipart messages 1) So we have a MultipartRequestDesc message...
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / FlowModInputMessageFactory.java
index d42cf3471d084ec0f1ea39cda5990c01a84492d3..4793c286bf0556ba9dc4d1c04aadac5c02c1f8b8 100644 (file)
@@ -8,17 +8,20 @@ import java.util.Map;
 \r
 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.openflowjava.protocol.impl.util.InstructionsSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;\r
 \r
 /**\r
+ * Translates FlowMod messages\r
  * @author timotej.kubas\r
  * @author michal.polkorab\r
  */\r
 public class FlowModInputMessageFactory implements OFSerializer<FlowModInput> {\r
     private static final byte MESSAGE_TYPE = 14;\r
     private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2;\r
-    private static final int MESSAGE_LENGTH = 48; //flags\r
+    private static final int MESSAGE_LENGTH = 48;\r
     private static FlowModInputMessageFactory instance;\r
    \r
     private FlowModInputMessageFactory() {\r
@@ -28,7 +31,7 @@ public class FlowModInputMessageFactory implements OFSerializer<FlowModInput> {
     /**\r
      * @return singleton factory\r
      */\r
-    public static FlowModInputMessageFactory getInstance() {\r
+    public static synchronized FlowModInputMessageFactory getInstance() {\r
         if(instance == null) {\r
             instance = new FlowModInputMessageFactory();\r
         }\r
@@ -45,24 +48,27 @@ public class FlowModInputMessageFactory implements OFSerializer<FlowModInput> {
         out.writeShort(message.getIdleTimeout().intValue());\r
         out.writeShort(message.getHardTimeout().intValue());\r
         out.writeShort(message.getPriority());\r
+        out.writeInt(message.getBufferId().intValue());\r
         out.writeInt(message.getOutPort().getValue().intValue());\r
         out.writeInt(message.getOutGroup().intValue());\r
         out.writeShort(createFlowModFlagsBitmask(message.getFlags()));\r
         ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, out);\r
-        // TODO implementation of match structure\r
-        // TODO implementation of instructions\r
+        MatchSerializer.encodeMatch(message.getMatch(), out);\r
+        InstructionsSerializer.encodeInstructions(message.getInstructions(), out);\r
+        \r
     }\r
 \r
     @Override\r
-    public int computeLength() {\r
-        return MESSAGE_LENGTH;\r
+    public int computeLength(FlowModInput message) {\r
+        return MESSAGE_LENGTH + MatchSerializer.computeMatchLength(message.getMatch())\r
+                + InstructionsSerializer.computeInstructionsLength(message.getInstructions());\r
     }\r
 \r
     @Override\r
     public byte getMessageType() {\r
         return MESSAGE_TYPE;\r
     }\r
-    \r
+\r
     private static int createFlowModFlagsBitmask(FlowModFlags flags) {\r
         int flowModFlagBitmask = 0;\r
         Map<Integer, Boolean> flowModFlagsMap = new HashMap<>();\r
@@ -75,4 +81,6 @@ public class FlowModInputMessageFactory implements OFSerializer<FlowModInput> {
         flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap);\r
         return flowModFlagBitmask;\r
     }\r
+    \r
+    \r
 }\r