Upgrade ietf-{inet,yang}-types to 2013-07-15
[vpnservice.git] / dhcpservice / dhcpservice-impl / src / main / java / org / opendaylight / vpnservice / dhcpservice / DhcpL2GatewayConnectionListener.java
index 6ba17767dc2667928ceb7715d674d81428bf59a8..3d833768003240503125f9b79430bc3562d7459f 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.vpnservice.dhcpservice.api.DHCPMConstants;
 import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections;
@@ -58,20 +58,13 @@ public class DhcpL2GatewayConnectionListener extends AsyncClusteredDataChangeLis
                 .child(L2gateway.class, new L2gatewayKey(gatewayId));
         Optional<L2gateway> l2Gateway = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, inst);
         if (!l2Gateway.isPresent()) {
+            logger.trace("L2Gw not present id {}", gatewayId);
             return;
         }
         Uuid networkUuid = del.getNetworkId();
-        boolean isLastConnection = true;
-        InstanceIdentifier<L2gatewayConnections> l2gatewayConnectionIdentifier = InstanceIdentifier.create(Neutron.class).child(L2gatewayConnections.class);
-        Optional<L2gatewayConnections> l2GwConnection = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, l2gatewayConnectionIdentifier);
-        List<L2gatewayConnection> l2GatewayConnectionList = l2GwConnection.get().getL2gatewayConnection();
-        for (L2gatewayConnection l2gatewayConnection : l2GatewayConnectionList) {
-            if (networkUuid.equals(l2gatewayConnection.getNetworkId())) {
-                isLastConnection = false;
-                break;
-            }
-        }
+        boolean isLastConnection = isLastGatewayConnection(networkUuid);
         if (!isLastConnection) {
+            logger.trace("Not the last L2GatewayConnection. Not removing flows.");
             return;
         }
         List<Devices> l2Devices = l2Gateway.get().getDevices();
@@ -88,6 +81,20 @@ public class DhcpL2GatewayConnectionListener extends AsyncClusteredDataChangeLis
         }
     }
 
+    private boolean isLastGatewayConnection(Uuid networkUuid) {
+        boolean isLastConnection = true;
+        InstanceIdentifier<L2gatewayConnections> l2gatewayConnectionIdentifier = InstanceIdentifier.create(Neutron.class).child(L2gatewayConnections.class);
+        Optional<L2gatewayConnections> l2GwConnection = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, l2gatewayConnectionIdentifier);
+        List<L2gatewayConnection> l2GatewayConnectionList = l2GwConnection.get().getL2gatewayConnection();
+        for (L2gatewayConnection l2gatewayConnection : l2GatewayConnectionList) {
+            if (networkUuid.equals(l2gatewayConnection.getNetworkId())) {
+                isLastConnection = false;
+                break;
+            }
+        }
+        return isLastConnection;
+    }
+
     @Override
     protected void update(InstanceIdentifier<L2gatewayConnection> identifier,
             L2gatewayConnection original, L2gatewayConnection update) {