Initial onSessionRemove work to remove Inventory Node when the session is removed. 62/2662/2
authorEd Warnicke <eaw@cisco.com>
Tue, 12 Nov 2013 12:10:26 +0000 (06:10 -0600)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 13 Nov 2013 09:42:18 +0000 (09:42 +0000)
Signed-off-by: Ed Warnicke <eaw@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/SalRegistrationManager.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionListener.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionManagerOFImpl.java

index c8694858ab2c838a3a437c03ffb7c3912da1595d..63e2224500196f2105c7c47f4a42ce2d1945a192 100644 (file)
@@ -15,6 +15,8 @@ import org.opendaylight.openflowplugin.openflow.md.core.session.SessionListener;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemovedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdatedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -63,7 +65,7 @@ public class SalRegistrationManager implements SessionListener, SwitchInventory
         GetFeaturesOutput features = context.getFeatures();
         BigInteger datapathId = features.getDatapathId();
         InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId);
-
+        NodeRef nodeRef = new NodeRef(identifier);
         NodeId nodeId = nodeIdFromDatapathId(datapathId);
         ModelDrivenSwitchImpl ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier, context);
         salSwitches.put(identifier, ofSwitch);
@@ -71,16 +73,31 @@ public class SalRegistrationManager implements SessionListener, SwitchInventory
 
         LOG.info("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId.toString());
 
-        publishService.publish(nodeAdded(ofSwitch, features));
+        publishService.publish(nodeAdded(ofSwitch, features,nodeRef));
     }
 
-    private NodeUpdated nodeAdded(ModelDrivenSwitch sw, GetFeaturesOutput features) {
+    @Override
+    public void onSessionRemoved(SessionContext context) {
+        GetFeaturesOutput features = context.getFeatures();
+        BigInteger datapathId = features.getDatapathId();
+        InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId);
+        NodeRef nodeRef = new NodeRef(identifier);
+        NodeRemoved nodeRemoved = nodeRemoved(nodeRef);
+
+        LOG.info("ModelDrivenSwitch for {} unregistred from MD-SAL.", datapathId.toString());
+        publishService.publish(nodeRemoved);
+    }
+
+    private NodeUpdated nodeAdded(ModelDrivenSwitch sw, GetFeaturesOutput features, NodeRef nodeRef) {
         NodeUpdatedBuilder builder = new NodeUpdatedBuilder();
         builder.setId(sw.getNodeId());
-        builder.setNodeRef(new NodeRef(InstanceIdentifier.builder()
-                .node(Nodes.class)
-                .node(Node.class, new NodeKey(builder.getId()))
-                .toInstance()));
+        builder.setNodeRef(nodeRef);
+        return builder.build();
+    }
+
+    private NodeRemoved nodeRemoved(NodeRef nodeRef) {
+        NodeRemovedBuilder builder = new NodeRemovedBuilder();
+        builder.setNodeRef(nodeRef);
         return builder.build();
     }
 
index 6b2debcafcbc8704fb3eb97798ffd4d89e2e62d9..5430c030bfd1bc1caf06bd09f4a3b7ed69e18ee3 100644 (file)
@@ -8,4 +8,6 @@ public interface SessionListener extends EventListener {
 
     void onSessionAdded(SwitchConnectionDistinguisher sessionKey, SessionContext context);
 
+    void onSessionRemoved(SessionContext context);
+
 }
index 71172f4763f72b15018063aef1587e9881fdf8e7..35da5e7acbecb9fefa093a73bbc2e787f04b3033 100644 (file)
@@ -13,7 +13,6 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageListener;
 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
@@ -65,7 +64,7 @@ public class SessionManagerOFImpl implements SessionManager {
             }
             context.getPrimaryConductor().disconnect();
             context.setValid(false);
-            sessionLot.remove(sessionKey);
+            removeSessionContext(context);
             // TODO:: notify listeners
         }
     }
@@ -79,11 +78,16 @@ public class SessionManagerOFImpl implements SessionManager {
                 invalidateAuxiliary(sessionContext, auxEntry.getKey(), true);
             }
             sessionContext.setValid(false);
-            sessionLot.remove(sessionContext.getSessionKey(), sessionContext);
+            removeSessionContext(sessionContext);
             // TODO:: notify listeners
         }
     }
 
+    private void removeSessionContext(SessionContext sessionContext) {
+        sessionLot.remove(sessionContext.getSessionKey(), sessionContext);
+        sessionNotifier.onSessionRemoved(sessionContext);
+    }
+
     @Override
     public void addSessionContext(SwitchConnectionDistinguisher sessionKey, SessionContext context) {
         sessionLot.put(sessionKey, context);
@@ -156,6 +160,16 @@ public class SessionManagerOFImpl implements SessionManager {
                 }
             }
         }
+
+        public void onSessionRemoved(SessionContext context) {
+            for (ListenerRegistration<SessionListener> listener : sessionListeners) {
+                try {
+                    listener.getInstance().onSessionRemoved(context);
+                } catch (Exception e) {
+                    LOG.error("Unhandled exeption occured while invoking onSessionRemoved on listener", e);
+                }
+            }
+        }
     };
 
     @Override