Manage disconnection of a Netconf device from ODL 84/64184/6
authorGilles Thouenon <gilles.thouenon@orange.com>
Thu, 12 Oct 2017 07:46:53 +0000 (09:46 +0200)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Thu, 19 Oct 2017 15:47:31 +0000 (15:47 +0000)
Updates PortMapping to manage the case when a netconf device is
disconnected from Karaf.
Corrects a bug in RendererNotificationsImpl. During the transient
state of node deletion, the nnode value becomes null. So the
disconnection treatment inside the condition nnode!=null was never
executed.

Change-Id: Icd7db2d1864ec3e2b8fba1526665a4b8520b1447
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
renderer/src/main/java/org/opendaylight/transportpce/renderer/RendererNotificationsImpl.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/mapping/PortMapping.java

index 8ddd081d44c15a75b89fa3e3835fee7504fbc54f..ae9715be33edc22f684ecabe83924cfb632b77c2 100644 (file)
@@ -12,12 +12,10 @@ import com.google.common.base.Preconditions;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
-
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
@@ -110,31 +108,26 @@ public class RendererNotificationsImpl implements DataTreeChangeListener<Node> {
         LOG.info("Registering notification listener on {} for node: {}", AlarmNotification.QNAME, nodeId);
         // Register notification listener
 
-
         final OrgOpenroadmDeOperationsListener deOperationsListener;
         deOperationsListener = new DeOperationsListener();
         LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
         // Register notification listener
 
-
         final OrgOpenroadmDeviceListener deviceListener;
         deviceListener = new DeviceListener();
         LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
         // Register notification listener
 
-
         final OrgOpenroadmLldpListener lldpListener;
         lldpListener = new LldpListener();
         LOG.info("Registering notification listener on OrgOpenroadmLldpListener for node: {}", nodeId);
         // Register notification listener
 
-
         final OrgOpenroadmTcaListener tcaListener;
         tcaListener = new TcaListener();
         LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
         // Register notification listener
 
-
         // Listening to NETCONF datastream
         final String streamName = "NETCONF";
         final Optional<RpcConsumerRegistry> service = mountPoint.getService(RpcConsumerRegistry.class);
@@ -170,6 +163,14 @@ public class RendererNotificationsImpl implements DataTreeChangeListener<Node> {
                     "Node not connected via Netconf protocol");
                 nodeId = rootNode.getDataAfter().getKey().getNodeId().getValue();
             }
+
+            if (rootNode.getModificationType() == ModificationType.DELETE) {
+                String nodeid = rootNode.getDataBefore().getKey().getNodeId().getValue();
+                LOG.info("Node " + nodeid + " removed...");
+                currentMountedDevice.remove(nodeid);
+                new PortMapping(dataBroker, mountService, nodeid).deleteMappingData();
+            }
+
             if (nnode != null) {
                 if (nodeId.equals("controller-config")) {
                     // We shouldn't process controller-config as an OpenROAM device
@@ -191,10 +192,10 @@ public class RendererNotificationsImpl implements DataTreeChangeListener<Node> {
                                 .stream().map(cp -> cp.getCapability()).collect(Collectors.toList());
                             LOG.info("Capabilities: {}", capabilities);
                             /*
-                             * TODO: check for required
-                             * capabilities to listen for notifications
+                             * TODO: check for required capabilities to listen
+                             * for notifications
                              */
-                            registerNotificationListener(rootNode.getDataAfter(). getNodeId());
+                            registerNotificationListener(rootNode.getDataAfter().getNodeId());
                             currentMountedDevice.add(nodeId);
                             new PortMapping(dataBroker, mountService, nodeId).createMappingData();
                             break;
@@ -210,11 +211,9 @@ public class RendererNotificationsImpl implements DataTreeChangeListener<Node> {
                         default:
                             LOG.warn("Unexpected connection status " + csts.getName());
                     }
-                } else if (rootNode.getModificationType() ==  ModificationType.DELETE) {
-                    LOG.info("Node removed " + nodeId);
-                    currentMountedDevice.remove(nodeId);
                 }
             }
         }
+        LOG.info("Netconf devices currently mounted are : " + currentMountedDevice.toString());
     }
 }
index 560a0048906e1aa06a50824c3d366e80db9b9a65..b0e975cacb6c68900b379157fcc4064c64cce901 100644 (file)
@@ -10,11 +10,11 @@ package org.opendaylight.transportpce.renderer.mapping;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
-
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
@@ -149,6 +149,24 @@ public class PortMapping {
         return postPortMapping(deviceInfo, portMapList, nodeType);
     }
 
+    /**
+     * This method removes mapping data from the datastore after disconnecting
+     * ODL from a Netconf device.
+     */
+    public void deleteMappingData() {
+        LOG.info("Deleting Mapping Data corresponding at node " + nodeId);
+        WriteTransaction rw = db.newWriteOnlyTransaction();
+        InstanceIdentifier<Nodes> nodesIID = InstanceIdentifier.create(Network.class)
+            .child(Nodes.class, new NodesKey(nodeId));
+        rw.delete(LogicalDatastoreType.CONFIGURATION, nodesIID);
+        try {
+            rw.submit().get(1, TimeUnit.SECONDS);
+            LOG.info("Port mapping removal for node " + nodeId);
+        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+            LOG.error("Error for removing port mapping infos for node " + nodeId);
+        }
+    }
+
     /**
      * This private method gets the list of external ports on a degree. For each
      * port in the degree, it does a get on port subtree with
@@ -196,7 +214,7 @@ public class PortMapping {
                 }
             } catch (InterruptedException | ExecutionException ex) {
                 LOG.warn("Read failed for Logical Connection Point value missing for " + circuitPackName + " "
-                    + portName,ex);
+                    + portName, ex);
                 return false;
             }
         }
@@ -280,7 +298,7 @@ public class PortMapping {
 
                 }
             } catch (InterruptedException | ExecutionException ex) {
-                LOG.warn("Read failed for " + circuitPackName,ex);
+                LOG.warn("Read failed for " + circuitPackName, ex);
                 return false;
             }
         }
@@ -345,7 +363,7 @@ public class PortMapping {
             }
 
         } catch (InterruptedException | ExecutionException ex) {
-            LOG.warn("Read failed for CircuitPacks of " + nodeId,ex);
+            LOG.warn("Read failed for CircuitPacks of " + nodeId, ex);
             return false;
         }
         return true;
@@ -465,7 +483,7 @@ public class PortMapping {
                     break;
                 }
             } catch (InterruptedException | ExecutionException ex) {
-                LOG.error("Failed to read degree " + degreeCounter,ex);
+                LOG.error("Failed to read degree " + degreeCounter, ex);
                 break;
 
             }
@@ -521,7 +539,7 @@ public class PortMapping {
                     break;
                 }
             } catch (InterruptedException | ExecutionException ex) {
-                LOG.warn("Failed to read Srg " + srgCounter,ex);
+                LOG.warn("Failed to read Srg " + srgCounter, ex);
                 break;
             }
             srgCounter++;
@@ -617,7 +635,7 @@ public class PortMapping {
             }
         } catch (InterruptedException | ExecutionException ex) {
             LOG.error("Unable to read mapping for logical connection point : " + logicalConnPoint + " for nodeId "
-                + nodeId,ex);
+                + nodeId, ex);
         }
         return null;
     }