sanitize Boolean autoboxing NPE
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / FlowConvertor.java
index cfd8cebe1283be6a88d8f2bf3b6f44a3f713e7e6..db543037cb767c2600f39bc071995dfc3bc76fd2 100644 (file)
@@ -15,6 +15,7 @@ import java.util.List;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag.FlowFlagReactor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.ActionList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
@@ -39,6 +40,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
@@ -52,6 +54,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Objects;
+
 /**
  * Utility class for converting a MD-SAL Flow into the OF flow mod
  */
@@ -110,13 +114,13 @@ public class FlowConvertor {
         if (flow instanceof AddFlowInput) {
             flowMod.setCommand(FlowModCommand.OFPFCADD);
         } else if (flow instanceof RemoveFlowInput) {
-            if (flow.isStrict() != null && flow.isStrict()) {
+            if (Objects.firstNonNull(flow.isStrict(), Boolean.FALSE)) {
                 flowMod.setCommand(FlowModCommand.OFPFCDELETESTRICT);
             } else {
                 flowMod.setCommand(FlowModCommand.OFPFCDELETE);
             }
         } else if (flow instanceof UpdatedFlow) {
-            if (flow.isStrict() != null && flow.isStrict()) {
+            if (Objects.firstNonNull(flow.isStrict(), Boolean.FALSE)) {
                 flowMod.setCommand(FlowModCommand.OFPFCMODIFYSTRICT);
             } else {
                 flowMod.setCommand(FlowModCommand.OFPFCMODIFY);
@@ -163,8 +167,10 @@ public class FlowConvertor {
 
         if (flow.getInstructions() != null) {
             flowMod.setInstructions(toInstructions(flow.getInstructions(), version));
+            flowMod.setActionsList(getActionsList(flow.getInstructions(), version));
         }
         flowMod.setVersion(version);
+        
         return flowMod.build();
     }
 
@@ -252,4 +258,23 @@ public class FlowConvertor {
         }
         return instructionsList;
     }
+    
+    private static List<ActionsList> getActionsList(
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions,
+            short version) {
+
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction instruction : instructions
+                .getInstruction()) {
+            org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curInstruction = instruction
+                    .getInstruction();
+
+            if (curInstruction instanceof ApplyActionsCase) {
+                ApplyActionsCase applyActionscase = (ApplyActionsCase) curInstruction;
+                ApplyActions applyActions = applyActionscase.getApplyActions();
+                return ActionConvertor.getActionList(applyActions.getAction(), version);
+            }
+
+        }
+        return null;
+    }
 }
\ No newline at end of file