Fixing issues with batching transactions during bind service
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / servicebindings / flowbased / confighelpers / FlowBasedServicesConfigBindHelper.java
index 1b02e87266bbbce07f2a8a2d55a2ea32ffa9ac75..e34e2b069a93d52a933e2a9a73b727994e090f5f 100644 (file)
@@ -40,7 +40,7 @@ public class FlowBasedServicesConfigBindHelper {
     public static List<ListenableFuture<Void>> bindService(InstanceIdentifier<BoundServices> instanceIdentifier,
                                                            BoundServices boundServiceNew, DataBroker dataBroker) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
-        WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
         String interfaceName =
                 InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)).getInterfaceName();
 
@@ -72,28 +72,23 @@ public class FlowBasedServicesConfigBindHelper {
         long portNo = Long.parseLong(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
         BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
 
-        Long lportTag = FlowBasedServicesUtils.getLPortTag(iface, dataBroker);
         if (allServices.size() == 1) {
             // If only one service present, install instructions in table 0.
             int vlanId = 0;
             List<MatchInfo> matches = null;
             if (iface.getType().isAssignableFrom(L2vlan.class)) {
-                IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class);
-                if( l2vlan != null){
-                    vlanId = l2vlan.getVlanId().getValue();
-                }
-                matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, vlanId);
+                matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface);
             } else if (iface.getType().isAssignableFrom(Tunnel.class)){
                 matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface);
             }
 
             if (matches != null) {
-                FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface.getName(), vlanId, boundServiceNew,
-                        dataBroker, t, matches, lportTag.intValue(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE);
+                FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, boundServiceNew,
+                        transaction, matches, ifState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE);
             }
 
-            if (t != null) {
-                futures.add(t.submit());
+            if (transaction != null) {
+                futures.add(transaction.submit());
             }
             return futures;
         }
@@ -112,35 +107,37 @@ public class FlowBasedServicesConfigBindHelper {
                     highestPriority = boundService.getServicePriority();
                 }
             }
-            LOG.error("Reached unexpected part 1 of the code when handling bind service for interface: {}, when binding" +
-                    "service: {}", iface, boundServiceNew);
         }
 
         if (!isCurrentServiceHighestPriority) {
-            FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundServiceNew, iface, dataBroker,  t,
-                    lportTag.intValue());
+            FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundServiceNew, iface, transaction,
+                    ifState.getIfIndex());
         } else {
             BoundServices serviceToReplace = tmpServicesMap.get(highestPriority);
-            FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, serviceToReplace, iface, dataBroker, t,
-                    lportTag.intValue());
-            int vlanId = 0;
+            FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, serviceToReplace, iface, transaction,
+                    ifState.getIfIndex());
             List<MatchInfo> matches = null;
             if (iface.getType().isAssignableFrom(L2vlan.class)) {
-                vlanId = iface.getAugmentation(IfL2vlan.class).getVlanId().getValue();
-                matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, vlanId);
+                matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface);
             } else if (iface.getType().isAssignableFrom(Tunnel.class)){
                 matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface);
             }
 
             if (matches != null) {
-                FlowBasedServicesUtils.removeIngressFlow(iface, serviceToReplace, dpId, dataBroker, t);
-                FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface.getName(), vlanId, boundServiceNew, dataBroker, t,
-                        matches, lportTag.intValue(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE);
+
+                WriteTransaction removeFlowTransaction = dataBroker.newWriteOnlyTransaction();
+                FlowBasedServicesUtils.removeIngressFlow(iface, serviceToReplace, dpId, removeFlowTransaction);
+                futures.add(removeFlowTransaction.submit());
+
+                WriteTransaction installFlowTransaction = dataBroker.newWriteOnlyTransaction();
+                FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, boundServiceNew, installFlowTransaction,
+                        matches, ifState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE);
+                futures.add(installFlowTransaction.submit());
             }
         }
 
-        if (t != null) {
-            futures.add(t.submit());
+        if (transaction != null) {
+            futures.add(transaction.submit());
         }
         return futures;
     }