General Sonar clean-up
[netvirt.git] / utils / mdsal-openflow / src / main / java / org / opendaylight / ovsdb / utils / mdsal / openflow / InstructionUtils.java
index b8a1af5aa06ba1cc8fef38d4623a36fbfce0fff3..39cef222f42e0929e7418ccc6c83f2e83c677c28 100644 (file)
@@ -79,7 +79,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 public class InstructionUtils {
-    private static final Logger logger = LoggerFactory.getLogger(InstructionUtils.class);
+    private static final Logger LOG = LoggerFactory.getLogger(InstructionUtils.class);
     private static final int IPV4 = 0x8100;
     private static final int MAX_LENGTH = 0xffff;
 
@@ -158,7 +158,7 @@ public class InstructionUtils {
     public static InstructionBuilder createOutputPortInstructions(InstructionBuilder ib, Long dpidLong, Long port) {
 
         NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
-        logger.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} inPort={} ",
+        LOG.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} inPort={} ",
                 dpidLong, port);
 
         List<Action> actionList = Lists.newArrayList();
@@ -193,7 +193,7 @@ public class InstructionUtils {
             Long dpidLong, Long port,
             List<Instruction> instructions) {
         NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
-        logger.debug(
+        LOG.debug(
                 "addOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}",
                 dpidLong, port, instructions);
 
@@ -239,7 +239,7 @@ public class InstructionUtils {
 
         final NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
         final Uri ncidUri = new Uri(ncid);
-        logger.debug(
+        LOG.debug(
                 "removeOutputPortFromInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}",
                 dpidLong, port, instructions);
 
@@ -293,14 +293,14 @@ public class InstructionUtils {
                     ab = new ActionBuilder();
                     ab.setAction(action.getAction());
                     ab.setOrder(action.getOrder() - 1);
-                    ab.setKey(new ActionKey(i));
+                    ab.setKey(new ActionKey(action.getOrder() - 1));
                     Action actionNewOrder = ab.build();
                     actionList.remove(action);
                     actionList.add(i, actionNewOrder);
                 } else if (action.getOrder() == removedActionOrder) {
                     // Sanity: implementation assumes no two actions have the same order
                     //
-                    logger.error("Found action with same order as the action removed for {}, order {} index {}: {}",
+                    LOG.error("Found action with same order as the action removed for {}, order {} index {}: {}",
                             ncid, removedActionOrder, i, action);
                 }
 
@@ -316,8 +316,8 @@ public class InstructionUtils {
             // If port we are asked to delete is not found, this implementation will leave actions
             // alone and not remove the flow, as long as a remaining OutputActionCase is found.
             //
-            for (int i = 0; i < actionList.size(); i++) {
-                if (actionList.get(i).getAction() instanceof OutputActionCase) {
+            for (Action action : actionList) {
+                if (action.getAction() instanceof OutputActionCase) {
                     removeFlow = false;
                     break;
                 }
@@ -329,7 +329,7 @@ public class InstructionUtils {
             ApplyActionsBuilder aab = new ApplyActionsBuilder();
             aab.setAction(actionList);
             ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-            logger.debug("removeOutputPortFromInstructions() : applyAction {}", aab.build());
+            LOG.debug("removeOutputPortFromInstructions() : applyAction {}", aab.build());
             return false;
         } else {
             /* if all output ports are removed. Return true to indicate flow remove */
@@ -435,9 +435,11 @@ public class InstructionUtils {
      *
      * @param ib        Map InstructionBuilder without any instructions
      * @param prefixdst String containing an IPv4 prefix
+     * @param extraAction (optional) Additional action to be performed in actionList
      * @return ib Map InstructionBuilder with instructions
      */
-    public static InstructionBuilder createNwDstInstructions(InstructionBuilder ib, Ipv4Prefix prefixdst) {
+    public static InstructionBuilder createNwDstInstructions(InstructionBuilder ib, Ipv4Prefix prefixdst,
+                                                             ActionBuilder extraAction) {
 
         List<Action> actionList = Lists.newArrayList();
         ActionBuilder ab = new ActionBuilder();
@@ -451,6 +453,12 @@ public class InstructionUtils {
         ab.setKey(new ActionKey(0));
         actionList.add(ab.build());
 
+        if (extraAction != null) {
+            extraAction.setOrder(1);
+            extraAction.setKey(new ActionKey(1));
+            actionList.add(extraAction.build());
+        }
+
         // Create an Apply Action
         ApplyActionsBuilder aab = new ApplyActionsBuilder();
         aab.setAction(actionList);