Fix for Bug 271
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / MDFlowMapping.xtend
index bc6b88d9c845d233e4c15494e9c0ed41f7e72bf2..b0f6065bac751a25ceb57d6d1bde65ed9550f6cb 100644 (file)
@@ -105,6 +105,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId
 
 public class MDFlowMapping {
 
@@ -134,6 +135,27 @@ public class MDFlowMapping {
 
     }
     
+    public static def toMDFlow(Flow sourceFlow) {
+       if (sourceFlow == null)
+            throw new IllegalArgumentException();
+       val it = new FlowBuilder();
+       hardTimeout = sourceFlow.hardTimeout as int
+       idleTimeout = sourceFlow.idleTimeout as int
+       cookie = BigInteger.valueOf(sourceFlow.id)
+       priority = sourceFlow.priority as int
+       id = new FlowId(sourceFlow.id)
+    
+       val sourceActions = sourceFlow.actions;
+       val targetActions = new ArrayList<Action>();
+       for (sourceAction : sourceActions) {
+           targetActions.add(sourceAction.toAction());
+       }
+       instructions = targetActions.toApplyInstruction();
+       match = sourceFlow.match.toMatch();
+       tableId = new Integer(0).shortValue
+       return it.build();
+    }
+    
     public static def Instructions toApplyInstruction(ArrayList<Action> actions) {
         val it = new InstructionsBuilder;
         val applyActions = new InstructionBuilder;
@@ -146,6 +168,7 @@ public class MDFlowMapping {
     public static def removeFlowInput(Node sourceNode, Flow sourceFlow) {
         val source = flowAdded(sourceFlow);
         val it = new RemoveFlowInputBuilder(source as org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow);
+        node = sourceNode.toNodeRef()
         return it.build();
     }