BUG-2794: incorporate openflowjava api changes to openflowplugin
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / OFToMDSalFlowConvertor.java
index 14cffba4f6449dc608ee2324334fa4d4c562a26a..0c9b19e0fb1d03a5f97ff7d7b8a68e6d3a03c12b 100644 (file)
@@ -33,13 +33,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionsInstruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.MetadataInstruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.MeterIdInstruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.TableIdInstruction;
 
 public class OFToMDSalFlowConvertor {
 
+    private OFToMDSalFlowConvertor() {
+        // hiding implicite constructor
+    }
+
     /**
      * Method convert Openflow 1.3+ specific instructions to MD-SAL format
      * flow instruction
@@ -55,6 +59,7 @@ public class OFToMDSalFlowConvertor {
 
         List<Instruction> salInstructionList = new ArrayList<Instruction>();
         int instructionTreeNodekey = 0;
+        org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction salInstruction;
         for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction switchInst : instructions) {
             if (switchInst.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class)) {
 
@@ -66,26 +71,14 @@ public class OFToMDSalFlowConvertor {
                 applyActionsBuilder.setAction(wrapActionList(ActionConvertor.toMDSalActions(actionsInstruction.getAction(), ofVersion, ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION)));
 
                 applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build());
-
-                InstructionBuilder instBuilder = new InstructionBuilder();
-                instBuilder.setInstruction(applyActionsCaseBuilder.build());
-                instBuilder.setKey(new InstructionKey(instructionTreeNodekey));
-                instBuilder.setOrder(instructionTreeNodekey);
-                instructionTreeNodekey++;
-                salInstructionList.add(instBuilder.build());
+                salInstruction = applyActionsCaseBuilder.build();
             } else if (switchInst.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions.class)) {
-                InstructionBuilder instBuilder = new InstructionBuilder();
 
                 ClearActionsCaseBuilder clearActionsCaseBuilder = new ClearActionsCaseBuilder();
                 ClearActionsBuilder clearActionsBuilder = new ClearActionsBuilder();
                 clearActionsCaseBuilder.setClearActions(clearActionsBuilder.build());
 
-                instBuilder.setInstruction(clearActionsCaseBuilder.build());
-                instBuilder.setKey(new InstructionKey(instructionTreeNodekey));
-                instBuilder.setOrder(instructionTreeNodekey);
-                instructionTreeNodekey++;
-
-                salInstructionList.add(instBuilder.build());
+                salInstruction = clearActionsCaseBuilder.build();
             } else if (switchInst.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable.class)) {
 
                 TableIdInstruction tableIdInstruction = (TableIdInstruction) switchInst.getAugmentation(TableIdInstruction.class);
@@ -95,30 +88,18 @@ public class OFToMDSalFlowConvertor {
                 goToTableBuilder.setTableId(tableIdInstruction.getTableId());
                 goToTableCaseBuilder.setGoToTable(goToTableBuilder.build());
 
-                InstructionBuilder instBuilder = new InstructionBuilder();
-                instBuilder.setInstruction(goToTableCaseBuilder.build());
-                instBuilder.setKey(new InstructionKey(instructionTreeNodekey));
-                instBuilder.setOrder(instructionTreeNodekey);
-                instructionTreeNodekey++;
-
-                salInstructionList.add(instBuilder.build());
+                salInstruction = goToTableCaseBuilder.build();
             } else if (switchInst.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter.class)) {
 
                 MeterIdInstruction meterIdInstruction = (MeterIdInstruction) switchInst.getAugmentation(MeterIdInstruction.class);
 
-                InstructionBuilder instBuilder = new InstructionBuilder();
 
                 MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
                 MeterBuilder meterBuilder = new MeterBuilder();
                 meterBuilder.setMeterId(new MeterId(meterIdInstruction.getMeterId()));
                 meterCaseBuilder.setMeter(meterBuilder.build());
 
-                instBuilder.setInstruction(meterCaseBuilder.build());
-                instBuilder.setKey(new InstructionKey(instructionTreeNodekey));
-                instBuilder.setOrder(instructionTreeNodekey);
-                instructionTreeNodekey++;
-
-                salInstructionList.add(instBuilder.build());
+                salInstruction = meterCaseBuilder.build();
             } else if (switchInst.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions.class)) {
 
                 ActionsInstruction actionsInstruction = (ActionsInstruction) switchInst.getAugmentation(ActionsInstruction.class);
@@ -128,14 +109,7 @@ public class OFToMDSalFlowConvertor {
                 writeActionsBuilder.setAction(wrapActionList(ActionConvertor.toMDSalActions(actionsInstruction.getAction(), ofVersion, ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION)));
                 writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build());
 
-                InstructionBuilder instBuilder = new InstructionBuilder();
-                instBuilder.setInstruction(writeActionsCaseBuilder.build());
-                instBuilder.setKey(new InstructionKey(instructionTreeNodekey));
-                instBuilder.setOrder(instructionTreeNodekey);
-                instructionTreeNodekey++;
-
-                salInstructionList.add(instBuilder.build());
-
+                salInstruction = writeActionsCaseBuilder.build();
             } else if (switchInst.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata.class)) {
 
                 MetadataInstruction metadataInstruction = (MetadataInstruction) switchInst.getAugmentation(MetadataInstruction.class);
@@ -146,14 +120,18 @@ public class OFToMDSalFlowConvertor {
                 writeMetadataBuilder.setMetadataMask(new BigInteger(1, metadataInstruction.getMetadataMask()));
                 writeMetadataCaseBuilder.setWriteMetadata(writeMetadataBuilder.build());
 
-                InstructionBuilder instBuilder = new InstructionBuilder();
-                instBuilder.setInstruction(writeMetadataCaseBuilder.build());
-                instBuilder.setKey(new InstructionKey(instructionTreeNodekey));
-                instBuilder.setOrder(instructionTreeNodekey);
-                instructionTreeNodekey++;
-
-                salInstructionList.add(instBuilder.build());
+                salInstruction = writeMetadataCaseBuilder.build();
+            } else {
+                continue;
             }
+
+            InstructionBuilder instBuilder = new InstructionBuilder();
+            instBuilder.setInstruction(salInstruction);
+            instBuilder.setKey(new InstructionKey(instructionTreeNodekey));
+            instBuilder.setOrder(instructionTreeNodekey);
+            instructionTreeNodekey++;
+            salInstructionList.add(instBuilder.build());
+
         }
         instructionsBuilder.setInstruction(salInstructionList);
         return instructionsBuilder.build();