Bug 2369: Fixed NPE in update-flow RPC.
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / FlowConvertor.java
index e2c6ddae20259a34ec343de4596938083e73805a..a9ad360cc51245988cb9570f6adfad42a36d92b4 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2013 Ericsson. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Ericsson. 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,
@@ -84,12 +84,13 @@ public class FlowConvertor {
     private static final Logger logger = LoggerFactory.getLogger(FlowConvertor.class);
 
     // Default values for when things are null
-    private static final BigInteger DEFAULT_COOKIE = BigInteger.ZERO;
-    private static final BigInteger DEFAULT_COOKIE_MASK = BigInteger.ZERO;
     private static final TableId DEFAULT_TABLE_ID = new TableId(0L);
-    private static final Integer DEFAULT_IDLE_TIMEOUT = 5 * 60;
-    private static final Integer DEFAULT_HARD_TIMEOUT = 10 * 60;
-    private static final Integer DEFAULT_PRIORITY = Integer.parseInt("8000", 16);
+    /** Default idle timeout */
+    public static final Integer DEFAULT_IDLE_TIMEOUT = 5 * 60;
+    /** Default hard timeout */
+    public static final Integer DEFAULT_HARD_TIMEOUT = 10 * 60;
+    /** Default priority */
+    public static final Integer DEFAULT_PRIORITY = Integer.parseInt("8000", 16);
     private static final Long DEFAULT_BUFFER_ID = Long.parseLong("ffffffff", 16);
     private static final Long OFPP_ANY = Long.parseLong("ffffffff", 16);
     private static final Long DEFAULT_OUT_PORT = OFPP_ANY;
@@ -135,13 +136,13 @@ public class FlowConvertor {
         if (flow.getCookie() != null) {
             flowMod.setCookie(flow.getCookie().getValue());
         } else {
-            flowMod.setCookie(DEFAULT_COOKIE);
+            flowMod.setCookie(OFConstants.DEFAULT_COOKIE);
         }
 
         if (flow.getCookieMask() != null) {
             flowMod.setCookieMask(flow.getCookieMask().getValue());
         } else {
-            flowMod.setCookieMask(DEFAULT_COOKIE_MASK);
+            flowMod.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
         }
 
         if (flow.getTableId() != null) {
@@ -206,8 +207,8 @@ public class FlowConvertor {
         MatchReactor.getInstance().convert(flow.getMatch(), version, flowMod,datapathid);
 
         if (flow.getInstructions() != null) {
-            flowMod.setInstruction(toInstructions(flow.getInstructions(), version,datapathid));
-            flowMod.setAction(getActions(flow.getInstructions(), version,datapathid));
+            flowMod.setInstruction(toInstructions(flow, version,datapathid));
+            flowMod.setAction(getActions(version,datapathid, flow));
         }
         flowMod.setVersion(version);
         
@@ -215,10 +216,11 @@ public class FlowConvertor {
     }
 
     private static List<Instruction> toInstructions(
-            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions,
+            Flow flow,
             short version,BigInteger datapathid) {
         List<Instruction> instructionsList = new ArrayList<>();
 
+        org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions = flow.getInstructions();
         for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction instruction : instructions
                 .getInstruction()) {
             InstructionBuilder instructionBuilder = new InstructionBuilder();
@@ -257,7 +259,7 @@ public class FlowConvertor {
                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions.class);
                 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
                 actionsInstructionBuilder.setAction(ActionConvertor.getActions(writeActions.getAction(),
-                        version,datapathid));
+                        version,datapathid, flow));
                 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
                 instructionsList.add(instructionBuilder.build());
             }
@@ -269,7 +271,7 @@ public class FlowConvertor {
                         .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
                 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
                 actionsInstructionBuilder.setAction(ActionConvertor.getActions(applyActions.getAction(),
-                        version,datapathid));
+                        version,datapathid, flow));
                 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
                 instructionsList.add(instructionBuilder.build());
             }
@@ -297,10 +299,12 @@ public class FlowConvertor {
         return instructionsList;
     }
     
-    private static List<Action> getActions(
+    /*private static List<Action> getActions(
             org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions,
-            short version,BigInteger datapathid) {
-
+            short version,BigInteger datapathid) {*/
+    private static List<Action> getActions(short version,BigInteger datapathid, Flow flow) {
+        
+        org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions = flow.getInstructions();
         List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> sortedInstructions =
             Ordering.from(OrderComparator.<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction>toInstance())
                 .sortedCopy(instructions.getInstruction());
@@ -312,7 +316,7 @@ public class FlowConvertor {
             if (curInstruction instanceof ApplyActionsCase) {
                 ApplyActionsCase applyActionscase = (ApplyActionsCase) curInstruction;
                 ApplyActions applyActions = applyActionscase.getApplyActions();
-                return ActionConvertor.getActions(applyActions.getAction(), version,datapathid);
+                return ActionConvertor.getActions(applyActions.getAction(), version,datapathid, flow);
             }
         }
         return null;