Fix: Switch manager should clean the nodeconnector info when a switch disconnects 85/885/2
authorPramila Singh <pramisin@cisco.com>
Thu, 15 Aug 2013 22:06:15 +0000 (15:06 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 16 Aug 2013 22:55:20 +0000 (22:55 +0000)
Change-Id: I2ccdf1a6d2ed38e1e78242ae99d9bb1711f20040
Signed-off-by: Pramila Singh <pramisin@cisco.com>
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java

index 835f40e6c6663e1f2a04f9c99922def15defabec..78c78f55429980466e42d5074e07e133c9cfa0bb 100644 (file)
@@ -712,7 +712,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                 switchConfig = new SwitchConfig(nodeId, updateProperties);
             } else {
                 // check if description is configured or was published by any other node
                 switchConfig = new SwitchConfig(nodeId, updateProperties);
             } else {
                 // check if description is configured or was published by any other node
-                for (Node n : nodeProps.keySet()) {
+                for (Map.Entry<Node, Map<String, Property>> entry : nodeProps.entrySet()) {
+                    Node n = entry.getKey();
                     Description desc = (Description) getNodeProp(n, Description.propertyName);
                     NodeDescription nDesc = (this.statisticsManager == null) ? null : this.statisticsManager
                             .getNodeDescription(n);
                     Description desc = (Description) getNodeProp(n, Description.propertyName);
                     NodeDescription nDesc = (this.statisticsManager == null) ? null : this.statisticsManager
                             .getNodeDescription(n);
@@ -762,7 +763,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             return new Status(StatusCode.SUCCESS);
         }
         Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
             return new Status(StatusCode.SUCCESS);
         }
         Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
-        for (String prop : prevNodeProperties.keySet()) {
+        for (Map.Entry<String, Property> entry : prevNodeProperties.entrySet()) {
+            String prop = entry.getKey();
             if (!updateProperties.containsKey(prop)) {
                 if (prop.equals(Description.propertyName)) {
                     if (!advertisedDesc.isEmpty()) {
             if (!updateProperties.containsKey(prop)) {
                 if (prop.equals(Description.propertyName)) {
                     if (!advertisedDesc.isEmpty()) {
@@ -795,7 +797,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         Map<String, Property> propMapCurr = nodeProps.get(node);
         if ((propMapCurr != null) && (nodeProperties != null) && (!nodeProperties.isEmpty())) {
             Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
         Map<String, Property> propMapCurr = nodeProps.get(node);
         if ((propMapCurr != null) && (nodeProperties != null) && (!nodeProperties.isEmpty())) {
             Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
-            for (String prop : nodeProperties.keySet()) {
+            for (Map.Entry<String, Property> entry : nodeProperties.entrySet()) {
+                String prop = entry.getKey();
                 if (prop.equals(Description.propertyName)) {
                     Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
                     if (nodeProp.get(node) != null) {
                 if (prop.equals(Description.propertyName)) {
                     Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
                     if (nodeProp.get(node) != null) {
@@ -955,6 +958,17 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             return;
         }
         nodeProps.remove(node);
             return;
         }
         nodeProps.remove(node);
+        nodeConnectorNames.remove(node);
+        Set<NodeConnector> removeNodeConnectorSet = new HashSet<NodeConnector>();
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
+            if (nodeConnector.getNode().equals(node)) {
+                removeNodeConnectorSet.add(nodeConnector);
+            }
+        }
+        for (NodeConnector nc : removeNodeConnectorSet) {
+            nodeConnectorProps.remove(nc);
+        }
 
         // check if span ports need to be cleaned up
         removeSpanPorts(node);
 
         // check if span ports need to be cleaned up
         removeSpanPorts(node);
@@ -1161,7 +1175,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         }
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
         }
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
-        for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
             if (!nodeConnector.getNode().equals(node)) {
                 continue;
             }
             if (!nodeConnector.getNode().equals(node)) {
                 continue;
             }
@@ -1180,7 +1195,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         }
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
         }
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
-        for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
             if (!nodeConnector.getNode().equals(node)) {
                 continue;
             }
             if (!nodeConnector.getNode().equals(node)) {
                 continue;
             }
@@ -1197,7 +1213,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         }
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
         }
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
-        for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
             if (!nodeConnector.getNode().equals(node)
                     || isSpecial(nodeConnector)) {
                 continue;
             if (!nodeConnector.getNode().equals(node)
                     || isSpecial(nodeConnector)) {
                 continue;
@@ -1336,9 +1353,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                 Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
                 Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
                 if (mapCurr != null) {
                 Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
                 Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
                 if (mapCurr != null) {
-                    for (String s : mapCurr.keySet()) {
+                    for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+                        String s = entry.getKey();
                         try {
                         try {
-                            map.put(s, new NodeConnector(mapCurr.get(s)));
+                            map.put(s, new NodeConnector(entry.getValue()));
                         } catch (ConstructionException e) {
                             e.printStackTrace();
                         }
                         } catch (ConstructionException e) {
                             e.printStackTrace();
                         }
@@ -1397,9 +1415,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                     Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
                     if (mapCurr != null) {
                         Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
                     Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
                     if (mapCurr != null) {
                         Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
-                        for (String s : mapCurr.keySet()) {
+                        for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+                            String s = entry.getKey();
                             try {
                             try {
-                                map.put(s, new NodeConnector(mapCurr.get(s)));
+                                map.put(s, new NodeConnector(entry.getValue()));
                             } catch (ConstructionException e) {
                                 e.printStackTrace();
                             }
                             } catch (ConstructionException e) {
                                 e.printStackTrace();
                             }
@@ -1433,9 +1452,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                 Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
                 if (mapCurr != null) {
                     Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
                 Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
                 if (mapCurr != null) {
                     Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
-                    for (String s : mapCurr.keySet()) {
+                    for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+                        String s = entry.getKey();
                         try {
                         try {
-                            map.put(s, new NodeConnector(mapCurr.get(s)));
+                            map.put(s, new NodeConnector(entry.getValue()));
                         } catch (ConstructionException e) {
                             e.printStackTrace();
                         }
                         } catch (ConstructionException e) {
                             e.printStackTrace();
                         }
@@ -1682,7 +1702,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             service.notifyNode(node, type, propMap);
         }
 
             service.notifyNode(node, type, propMap);
         }
 
-        for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
             propMap = nodeConnectorProps.get(nodeConnector);
             service.notifyNodeConnector(nodeConnector, type, propMap);
         }
             propMap = nodeConnectorProps.get(nodeConnector);
             service.notifyNodeConnector(nodeConnector, type, propMap);
         }