Code ReOrganization and Re-Architecture changes
[ovsdb.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / provider / OF13ProviderManager.java
index 53bd3ec63d1196e3c98f7aa630e497c80d7e2e67..561039fae43859bba85a919ef3f86352af99684d 100644 (file)
@@ -47,6 +47,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
@@ -75,8 +76,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 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.tables.table.FlowKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
@@ -169,7 +172,7 @@ class OF13ProviderManager extends ProviderNetworkManager {
             String bridgeUUID = null;
             String tunnelBridgeName = AdminConfigManager.getManager().getIntegrationBridgeName();
             OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
-            Map<String, org.opendaylight.ovsdb.lib.table.internal.Table<?>> bridgeTable = ovsdbTable.getRows(node, Bridge.NAME.getName());
+            Map<String, org.opendaylight.ovsdb.lib.table.Table<?>> bridgeTable = ovsdbTable.getRows(node, Bridge.NAME.getName());
             if (bridgeTable != null) {
                 for (String uuid : bridgeTable.keySet()) {
                     Bridge bridge = (Bridge)bridgeTable.get(uuid);
@@ -253,9 +256,7 @@ class OF13ProviderManager extends ProviderNetworkManager {
          * Action: Drop w/ a low priority
          */
 
-         // TODO : Drop flows causing problems with other existing flows. Commenting them out for now till it is fixed.
-
-         // writeDropSrcIface(dpid, localPort);
+         writeDropSrcIface(dpid, localPort);
 
          /*
           * Table(2) Rule #1
@@ -299,8 +300,7 @@ class OF13ProviderManager extends ProviderNetworkManager {
            * table=2,priority=8192,tun_id=0x5 actions=drop
            */
 
-           // TODO : Drop flows causing problems with other existing flows. Commenting them out for now till it is fixed.
-           // writeLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId);
+           writeLocalTableMiss(dpid, TABLE_2_LOCAL_FORWARD, segmentationId);
     }
 
     private void programLocalIngressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
@@ -312,6 +312,19 @@ class OF13ProviderManager extends ProviderNetworkManager {
          */
 
          writeTunnelIn(dpid, TABLE_0_DEFAULT_INGRESS, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort);
+
+         /*
+          * Table(1) Rule #2
+          * ----------------
+          * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
+          * Action: Flood to selected destination TEPs
+          * -------------------------------------------
+          * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
+          * actions=output:10,output:11,goto_table:2
+          */
+
+         writeTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort);
+
     }
 
     private void programRemoteEgressTunnelBridgeRules(Node node, Long dpid, String segmentationId, String attachedMac, long tunnelOFPort, long localPort) {
@@ -326,18 +339,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
          */
 
         writeTunnelOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort, attachedMac);
-
-        /*
-         * Table(1) Rule #2
-         * ----------------
-         * Match: Match Tunnel ID and L2 ::::FF:FF Flooding
-         * Action: Flood to selected destination TEPs
-         * -------------------------------------------
-         * table=1,priority=16384,tun_id=0x5,dl_dst=ff:ff:ff:ff:ff:ff \
-         * actions=output:10,output:11,goto_table:2
-         */
-
-        writeTunnelFloodOut(dpid, TABLE_1_ISOLATE_TENANT, TABLE_2_LOCAL_FORWARD, segmentationId, tunnelOFPort);
     }
 
     private Long getIntegrationBridgeOFDPID (Node node) {
@@ -422,9 +423,9 @@ class OF13ProviderManager extends ProviderNetworkManager {
                 return;
             }
 
-            Map<String, org.opendaylight.ovsdb.lib.table.internal.Table<?>> intfs = ovsdbTable.getRows(node, Interface.NAME.getName());
+            Map<String, org.opendaylight.ovsdb.lib.table.Table<?>> intfs = ovsdbTable.getRows(node, Interface.NAME.getName());
             if (intfs != null) {
-                for (org.opendaylight.ovsdb.lib.table.internal.Table<?> row : intfs.values()) {
+                for (org.opendaylight.ovsdb.lib.table.Table<?> row : intfs.values()) {
                     Interface tunIntf = (Interface)row;
                     if (tunIntf.getName().equals(this.getTunnelName(tunnelType, dst))) {
                         of_ports = tunIntf.getOfport();
@@ -469,7 +470,7 @@ class OF13ProviderManager extends ProviderNetworkManager {
             if (ofNodes != null) {
                 for (Node ofNode : ofNodes) {
                     if (ofNode.toString().contains(dpid+"")) {
-                        logger.info("Identified the Openflow node via toString {}", ofNode);
+                        logger.debug("Identified the Openflow node via toString {}", ofNode);
                         ofNodeFound = true;
                         break;
                     }
@@ -489,11 +490,9 @@ class OF13ProviderManager extends ProviderNetworkManager {
         this.programLocalRules(tunnelType, tunnelKey, srcNode, intf);
 
         for (Node dstNode : nodes) {
-            Status status = getTunnelReadinessStatus(dstNode, tunnelKey);
-            if (!status.isSuccess()) continue;
             InetAddress src = AdminConfigManager.getManager().getTunnelEndPoint(srcNode);
             InetAddress dst = AdminConfigManager.getManager().getTunnelEndPoint(dstNode);
-            status = addTunnelPort(srcNode, tunnelType, src, dst);
+            Status status = addTunnelPort(srcNode, tunnelType, src, dst);
             if (status.isSuccess()) {
                 this.programTunnelRules(tunnelType, tunnelKey, dst, srcNode, intf, true);
             }
@@ -509,9 +508,9 @@ class OF13ProviderManager extends ProviderNetworkManager {
     private Status triggerInterfaceUpdates(Node node) {
         try {
             OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
-            Map<String, org.opendaylight.ovsdb.lib.table.internal.Table<?>> intfs = ovsdbTable.getRows(node, Interface.NAME.getName());
+            Map<String, org.opendaylight.ovsdb.lib.table.Table<?>> intfs = ovsdbTable.getRows(node, Interface.NAME.getName());
             if (intfs != null) {
-                for (org.opendaylight.ovsdb.lib.table.internal.Table<?> row : intfs.values()) {
+                for (org.opendaylight.ovsdb.lib.table.Table<?> row : intfs.values()) {
                     Interface intf = (Interface)row;
                     NeutronNetwork network = TenantNetworkManager.getManager().getTenantNetworkForInterface(intf);
                     logger.debug("Trigger Interface update for {}", intf);
@@ -533,7 +532,8 @@ class OF13ProviderManager extends ProviderNetworkManager {
     }
 
     @Override
-    public Status deleteTunnels(String tunnelType, String tunnelKey, Node source, Interface intf) {
+    public Status handleInterfaceDelete(String tunnelType, String tunnelKey, Node source, Interface intf,
+            boolean isLastInstanceOnNode) {
         // TODO Auto-generated method stub
         return null;
     }
@@ -594,6 +594,8 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Call the InstructionBuilder Methods Containing Actions
         createSendToControllerInstructions(ib);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -643,6 +645,8 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Call the InstructionBuilder Methods Containing Actions
         createGotoTableInstructions(ib, goToTableId);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -655,6 +659,7 @@ class OF13ProviderManager extends ProviderNetworkManager {
         // Add Flow Attributes
         flowBuilder.setId(new FlowId(flowId));
         FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(true);
         flowBuilder.setBarrier(false);
         flowBuilder.setTableId(writeTable);
         flowBuilder.setKey(key);
@@ -685,6 +690,18 @@ class OF13ProviderManager extends ProviderNetworkManager {
         // TODO Broken In_Port Match
         flowBuilder.setMatch(createInPortMatch(matchBuilder, dpidLong, inPort).build());
 
+        String flowId = "LocalMac_"+segmentationId+"_"+inPort+"_"+attachedMac;
+        // Add Flow Attributes
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(true);
+        flowBuilder.setBarrier(false);
+        flowBuilder.setTableId(writeTable);
+        flowBuilder.setKey(key);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+
         // Instantiate the Builders for the OF Actions and Instructions
         InstructionBuilder ib = new InstructionBuilder();
         InstructionsBuilder isb = new InstructionsBuilder();
@@ -694,9 +711,13 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // GOTO Instuctions Need to be added first to the List
         createGotoTableInstructions(ib, goToTableId);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
         // TODO Broken SetTunID
         createSetTunnelIdInstructions(ib, new BigInteger(segmentationId));
+        ib.setOrder(1);
+        ib.setKey(new InstructionKey(1));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -705,16 +726,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
         // Add InstructionsBuilder to FlowBuilder
         flowBuilder.setInstructions(isb.build());
 
-        String flowId = "LocalMac_"+segmentationId+"_"+inPort+"_"+attachedMac;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
         writeFlow(flowBuilder, nodeBuilder);
     }
 
@@ -746,6 +757,8 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Call the InstructionBuilder Methods Containing Actions
         createDropInstructions(ib);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -758,6 +771,7 @@ class OF13ProviderManager extends ProviderNetworkManager {
         // Add Flow Attributes
         flowBuilder.setId(new FlowId(flowId));
         FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(true);
         flowBuilder.setBarrier(false);
         flowBuilder.setTableId((short) 0);
         flowBuilder.setKey(key);
@@ -788,6 +802,17 @@ class OF13ProviderManager extends ProviderNetworkManager {
         flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
         flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
 
+        String flowId = "TunnelOut_"+segmentationId+"_"+OFPortOut+"_"+attachedMac;
+        // Add Flow Attributes
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(true);
+        flowBuilder.setBarrier(false);
+        flowBuilder.setTableId(writeTable);
+        flowBuilder.setKey(key);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
         // Instantiate the Builders for the OF Actions and Instructions
         InstructionBuilder ib = new InstructionBuilder();
         InstructionsBuilder isb = new InstructionsBuilder();
@@ -797,9 +822,13 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // GOTO Instuctions
         createGotoTableInstructions(ib, goToTableId);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
         // Set the Output Port/Iface
         createOutputPortInstructions(ib, dpidLong, OFPortOut);
+        ib.setOrder(1);
+        ib.setKey(new InstructionKey(1));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -808,16 +837,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
         // Add InstructionsBuilder to FlowBuilder
         flowBuilder.setInstructions(isb.build());
 
-        String flowId = "TunnelOut_"+segmentationId+"_"+OFPortOut+"_"+attachedMac;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
         writeFlow(flowBuilder, nodeBuilder);
     }
 
@@ -844,18 +863,39 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"), new MacAddress("01:00:00:00:00:00")).build());
 
+        String flowId = "TunnelFloodOut_"+segmentationId;
+        // Add Flow Attributes
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setBarrier(true);
+        flowBuilder.setTableId(writeTable);
+        flowBuilder.setKey(key);
+        flowBuilder.setPriority(16384);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+
+        Flow flow = this.getFlow(flowBuilder, nodeBuilder);
         // Instantiate the Builders for the OF Actions and Instructions
         InstructionBuilder ib = new InstructionBuilder();
         InstructionsBuilder isb = new InstructionsBuilder();
-
-        // Instructions List Stores Individual Instructions
         List<Instruction> instructions = new ArrayList<Instruction>();
-
+        List<Instruction> existingInstructions = null;
+        if (flow != null) {
+            Instructions ins = flow.getInstructions();
+            if (ins != null) {
+                existingInstructions = ins.getInstruction();
+            }
+        }
         // GOTO Instuction
         createGotoTableInstructions(ib, localTable);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
         // Set the Output Port/Iface
-        createOutputPortInstructions(ib, dpidLong, OFPortOut);
+        createOutputPortInstructions(ib, dpidLong, OFPortOut, existingInstructions);
+        ib.setOrder(1);
+        ib.setKey(new InstructionKey(1));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -864,17 +904,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
         // Add InstructionsBuilder to FlowBuilder
         flowBuilder.setInstructions(isb.build());
 
-        String flowId = "TunnelFloodOut_"+segmentationId;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setBarrier(true);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setPriority(16384);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
         writeFlow(flowBuilder, nodeBuilder);
     }
 
@@ -905,6 +934,8 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Call the InstructionBuilder Methods Containing Actions
         createGotoTableInstructions(ib, goToTableId);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -917,6 +948,7 @@ class OF13ProviderManager extends ProviderNetworkManager {
         // Add Flow Attributes
         flowBuilder.setId(new FlowId(flowId));
         FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(true);
         flowBuilder.setBarrier(false);
         flowBuilder.setTableId(writeTable);
         flowBuilder.setKey(key);
@@ -946,6 +978,18 @@ class OF13ProviderManager extends ProviderNetworkManager {
         flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
         flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress(attachedMac), null).build());
 
+        String flowId = "UcastOut_"+segmentationId+"_"+localPort+"_"+attachedMac;
+        // Add Flow Attributes
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(true);
+        flowBuilder.setBarrier(false);
+        flowBuilder.setTableId(writeTable);
+        flowBuilder.setKey(key);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+
         // Instantiate the Builders for the OF Actions and Instructions
         InstructionBuilder ib = new InstructionBuilder();
         InstructionsBuilder isb = new InstructionsBuilder();
@@ -955,6 +999,8 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Set the Output Port/Iface
         createOutputPortInstructions(ib, dpidLong, localPort);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -962,17 +1008,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Add InstructionsBuilder to FlowBuilder
         flowBuilder.setInstructions(isb.build());
-
-        String flowId = "UcastOut_"+segmentationId+"_"+localPort+"_"+attachedMac;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
         writeFlow(flowBuilder, nodeBuilder);
     }
 
@@ -995,15 +1030,35 @@ class OF13ProviderManager extends ProviderNetworkManager {
         flowBuilder.setMatch(createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId)).build());
         flowBuilder.setMatch(createDestEthMatch(matchBuilder, new MacAddress("01:00:00:00:00:00"), new MacAddress("01:00:00:00:00:00")).build());
 
+        String flowId = "BcastOut_"+segmentationId;
+        // Add Flow Attributes
+        flowBuilder.setId(new FlowId(flowId));
+        FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(true);
+        flowBuilder.setBarrier(false);
+        flowBuilder.setTableId(writeTable);
+        flowBuilder.setKey(key);
+        flowBuilder.setPriority(16384);
+        flowBuilder.setFlowName(flowId);
+        flowBuilder.setHardTimeout(0);
+        flowBuilder.setIdleTimeout(0);
+        Flow flow = this.getFlow(flowBuilder, nodeBuilder);
         // Instantiate the Builders for the OF Actions and Instructions
         InstructionBuilder ib = new InstructionBuilder();
         InstructionsBuilder isb = new InstructionsBuilder();
-
-        // Instructions List Stores Individual Instructions
         List<Instruction> instructions = new ArrayList<Instruction>();
+        List<Instruction> existingInstructions = null;
+        if (flow != null) {
+            Instructions ins = flow.getInstructions();
+            if (ins != null) {
+                existingInstructions = ins.getInstruction();
+            }
+        }
 
         // Broken OutPort TODO: localPort needs to be a list of Ports)
-        createOutputPortInstructions(ib, dpidLong, localPort);
+        createOutputPortInstructions(ib, dpidLong, localPort, existingInstructions);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -1012,17 +1067,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
         // Add InstructionsBuilder to FlowBuilder
         flowBuilder.setInstructions(isb.build());
 
-        String flowId = "BcastOut_"+segmentationId;
-        // Add Flow Attributes
-        flowBuilder.setId(new FlowId(flowId));
-        FlowKey key = new FlowKey(new FlowId(flowId));
-        flowBuilder.setBarrier(false);
-        flowBuilder.setTableId(writeTable);
-        flowBuilder.setKey(key);
-        flowBuilder.setPriority(16384);
-        flowBuilder.setFlowName(flowId);
-        flowBuilder.setHardTimeout(0);
-        flowBuilder.setIdleTimeout(0);
         writeFlow(flowBuilder, nodeBuilder);
     }
 
@@ -1053,6 +1097,8 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Call the InstructionBuilder Methods Containing Actions
         createDropInstructions(ib);
+        ib.setOrder(0);
+        ib.setKey(new InstructionKey(0));
         instructions.add(ib.build());
 
         // Add InstructionBuilder to the Instruction(s)Builder List
@@ -1065,6 +1111,7 @@ class OF13ProviderManager extends ProviderNetworkManager {
         // Add Flow Attributes
         flowBuilder.setId(new FlowId(flowId));
         FlowKey key = new FlowKey(new FlowId(flowId));
+        flowBuilder.setStrict(true);
         flowBuilder.setBarrier(false);
         flowBuilder.setTableId(writeTable);
         flowBuilder.setKey(key);
@@ -1075,6 +1122,26 @@ class OF13ProviderManager extends ProviderNetworkManager {
         writeFlow(flowBuilder, nodeBuilder);
     }
 
+    private Flow getFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
+        IMDSALConsumer mdsalConsumer = (IMDSALConsumer) ServiceHelper.getInstance(IMDSALConsumer.class, "default", this);
+        if (mdsalConsumer == null) {
+            logger.error("ERROR finding MDSAL Service. Its possible that writeFlow is called too soon ?");
+            return null;
+        }
+
+        dataBrokerService = mdsalConsumer.getDataBrokerService();
+
+        if (dataBrokerService == null) {
+            logger.error("ERROR finding reference for DataBrokerService. Please check out the MD-SAL support on the Controller.");
+            return null;
+        }
+
+        InstanceIdentifier<Flow> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory
+                .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class,
+                new TableKey(flowBuilder.getTableId())).child(Flow.class, flowBuilder.getKey()).build();
+        return (Flow)dataBrokerService.readConfigurationData(path1);
+    }
+
     private void writeFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder) {
         IMDSALConsumer mdsalConsumer = (IMDSALConsumer) ServiceHelper.getInstance(IMDSALConsumer.class, "default", this);
         if (mdsalConsumer == null) {
@@ -1375,8 +1442,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Wrap our Apply Action in an Instruction
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-        ib.setOrder(0);
-        ib.setKey(new InstructionKey(0));
 
         return ib;
     }
@@ -1400,8 +1465,8 @@ class OF13ProviderManager extends ProviderNetworkManager {
         oab.setOutputNodeConnector(ncid);
 
         ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
-        ab.setOrder(5);
-        ab.setKey(new ActionKey(5));
+        ab.setOrder(0);
+        ab.setKey(new ActionKey(0));
         actionList.add(ab.build());
 
         // Create an Apply Action
@@ -1412,6 +1477,58 @@ class OF13ProviderManager extends ProviderNetworkManager {
         return ib;
     }
 
+    /**
+     * Create Output Port Instruction
+     *
+     * @param ib       Map InstructionBuilder without any instructions
+     * @param dpidLong Long the datapath ID of a switch/node
+     * @param port     Long representing a port on a switch/node
+     * @return ib InstructionBuilder Map with instructions
+     */
+    protected static InstructionBuilder createOutputPortInstructions(InstructionBuilder ib, Long dpidLong, Long port , List<Instruction> instructions) {
+
+        NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + port);
+        logger.debug("createOutputPortInstructions() Node Connector ID is - Type=openflow: DPID={} port={} existingInstructions={}", dpidLong, port, instructions);
+
+        List<Action> actionList = new ArrayList<Action>();
+        ActionBuilder ab = new ActionBuilder();
+
+        List<Action> existingActions = null;
+        if (instructions != null) {
+            for (Instruction in : instructions) {
+                if (in.getInstruction() instanceof ApplyActionsCase) {
+                    existingActions = (((ApplyActionsCase) in.getInstruction()).getApplyActions().getAction());
+                    actionList.addAll(existingActions);
+                }
+            }
+        }
+
+        OutputActionBuilder oab = new OutputActionBuilder();
+        oab.setOutputNodeConnector(ncid);
+        ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
+        ab.setOrder(0);
+        ab.setKey(new ActionKey(0));
+        Action newAction = ab.build();
+        boolean addNew = true;
+        for (Action action : actionList) {
+            if (action.getAction() instanceof OutputActionCase) {
+                OutputActionCase opAction = (OutputActionCase)action.getAction();
+                if (opAction.getOutputAction().getOutputNodeConnector().equals(new Uri(ncid))) {
+                    addNew = false;
+                    break;
+                }
+            }
+        }
+        if (addNew) actionList.add(newAction);
+
+        // Create an Apply Action
+        ApplyActionsBuilder aab = new ApplyActionsBuilder();
+        aab.setAction(actionList);
+        ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+
+        return ib;
+    }
+
     /**
      * Create Set Vlan ID Instruction
      *
@@ -1461,8 +1578,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Wrap our Apply Action in an Instruction
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-        ib.setOrder(0);
-        ib.setKey(new InstructionKey(0));
 
         return ib;
     }
@@ -1548,8 +1663,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Wrap our Apply Action in an Instruction
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-        ib.setOrder(0);
-        ib.setKey(new InstructionKey(0));
 
         return ib;
     }
@@ -1568,8 +1681,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Wrap our Apply Action in an InstructionBuilder
         ib.setInstruction(new GoToTableCaseBuilder().setGoToTable(gttb.build()).build());
-        ib.setOrder(0);
-        ib.setKey(new InstructionKey(0));
 
         return ib;
     }
@@ -1598,8 +1709,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
         aab.setAction(actionList);
 
         // Wrap the Apply Action in an InstructionBuilder and return
-        ib.setOrder(0);
-        ib.setKey(new InstructionKey(0));
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
 
         return ib;
@@ -1630,7 +1739,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         ApplyActionsBuilder aab = new ApplyActionsBuilder();
         aab.setAction(actionList);
-        ib.setKey(new InstructionKey(1));
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
 
         return ib;
@@ -1661,7 +1769,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         ApplyActionsBuilder aab = new ApplyActionsBuilder();
         aab.setAction(actionList);
-        ib.setKey(new InstructionKey(1));
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
 
         return ib;
@@ -1692,7 +1799,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         ApplyActionsBuilder aab = new ApplyActionsBuilder();
         aab.setAction(actionList);
-        ib.setKey(new InstructionKey(1));
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
 
         return ib;
@@ -1723,7 +1829,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         ApplyActionsBuilder aab = new ApplyActionsBuilder();
         aab.setAction(actionList);
-        ib.setKey(new InstructionKey(1));
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
 
         return ib;
@@ -1755,7 +1860,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
         aab.setAction(actionList);
 
         // Wrap our Apply Action in an Instruction
-        ib.setKey(new InstructionKey(0));
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
 
         return ib;
@@ -1785,7 +1889,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
         aab.setAction(actionList);
 
         // Wrap our Apply Action in an Instruction
-        ib.setKey(new InstructionKey(1));
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
 
         return ib;
@@ -1813,8 +1916,6 @@ class OF13ProviderManager extends ProviderNetworkManager {
 
         // Wrap our Apply Action in an Instruction
         ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
-        ib.setKey(new InstructionKey(0));
-        ib.setOrder(0);
 
         return ib;
     }
@@ -1918,7 +2019,7 @@ class OF13ProviderManager extends ProviderNetworkManager {
         for (Node ovsNode : ovsNodes) {
             Long dpid = this.getIntegrationBridgeOFDPID(ovsNode);
             logger.debug("Compare openflowNode to OVS br-int node {} vs {}", openflowNode.getID(), dpid);
-            String openflowID = (String)openflowNode.getID();
+            String openflowID = ""+openflowNode.getID();
             if (openflowID.contains(""+dpid)) {
                 this.initializeFlowRules(ovsNode, AdminConfigManager.getManager().getIntegrationBridgeName());
                 this.triggerInterfaceUpdates(ovsNode);