From 8c9a1cf398348546e6e5ba74a2012ed942a2fddb Mon Sep 17 00:00:00 2001 From: Pramila Singh Date: Thu, 15 Aug 2013 15:06:15 -0700 Subject: [PATCH] Fix: Switch manager should clean the nodeconnector info when a switch disconnects Change-Id: I2ccdf1a6d2ed38e1e78242ae99d9bb1711f20040 Signed-off-by: Pramila Singh --- .../switchmanager/internal/SwitchManager.java | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java index 835f40e6c6..78c78f5542 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java @@ -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 - for (Node n : nodeProps.keySet()) { + for (Map.Entry> entry : nodeProps.entrySet()) { + Node n = entry.getKey(); 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 propMap = new HashMap(propMapCurr); - for (String prop : prevNodeProperties.keySet()) { + for (Map.Entry entry : prevNodeProperties.entrySet()) { + String prop = entry.getKey(); if (!updateProperties.containsKey(prop)) { if (prop.equals(Description.propertyName)) { if (!advertisedDesc.isEmpty()) { @@ -795,7 +797,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa Map propMapCurr = nodeProps.get(node); if ((propMapCurr != null) && (nodeProperties != null) && (!nodeProperties.isEmpty())) { Map propMap = new HashMap(propMapCurr); - for (String prop : nodeProperties.keySet()) { + for (Map.Entry entry : nodeProperties.entrySet()) { + String prop = entry.getKey(); if (prop.equals(Description.propertyName)) { Map> nodeProp = this.inventoryService.getNodeProps(); if (nodeProp.get(node) != null) { @@ -955,6 +958,17 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa return; } nodeProps.remove(node); + nodeConnectorNames.remove(node); + Set removeNodeConnectorSet = new HashSet(); + for (Map.Entry> 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); @@ -1161,7 +1175,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } Set nodeConnectorSet = new HashSet(); - for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) { + for (Map.Entry> entry : nodeConnectorProps.entrySet()) { + NodeConnector nodeConnector = entry.getKey(); if (!nodeConnector.getNode().equals(node)) { continue; } @@ -1180,7 +1195,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } Set nodeConnectorSet = new HashSet(); - for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) { + for (Map.Entry> entry : nodeConnectorProps.entrySet()) { + NodeConnector nodeConnector = entry.getKey(); if (!nodeConnector.getNode().equals(node)) { continue; } @@ -1197,7 +1213,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } Set nodeConnectorSet = new HashSet(); - for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) { + for (Map.Entry> entry : nodeConnectorProps.entrySet()) { + NodeConnector nodeConnector = entry.getKey(); if (!nodeConnector.getNode().equals(node) || isSpecial(nodeConnector)) { continue; @@ -1336,9 +1353,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa Map mapCurr = nodeConnectorNames.get(node); Map map = new HashMap(); if (mapCurr != null) { - for (String s : mapCurr.keySet()) { + for (Map.Entry entry : mapCurr.entrySet()) { + String s = entry.getKey(); try { - map.put(s, new NodeConnector(mapCurr.get(s))); + map.put(s, new NodeConnector(entry.getValue())); } catch (ConstructionException e) { e.printStackTrace(); } @@ -1397,9 +1415,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa Map mapCurr = nodeConnectorNames.get(node); if (mapCurr != null) { Map map = new HashMap(); - for (String s : mapCurr.keySet()) { + for (Map.Entry entry : mapCurr.entrySet()) { + String s = entry.getKey(); try { - map.put(s, new NodeConnector(mapCurr.get(s))); + map.put(s, new NodeConnector(entry.getValue())); } catch (ConstructionException e) { e.printStackTrace(); } @@ -1433,9 +1452,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa Map mapCurr = nodeConnectorNames.get(node); if (mapCurr != null) { Map map = new HashMap(); - for (String s : mapCurr.keySet()) { + for (Map.Entry entry : mapCurr.entrySet()) { + String s = entry.getKey(); try { - map.put(s, new NodeConnector(mapCurr.get(s))); + map.put(s, new NodeConnector(entry.getValue())); } catch (ConstructionException e) { e.printStackTrace(); } @@ -1682,7 +1702,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa service.notifyNode(node, type, propMap); } - for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) { + for (Map.Entry> entry : nodeConnectorProps.entrySet()) { + NodeConnector nodeConnector = entry.getKey(); propMap = nodeConnectorProps.get(nodeConnector); service.notifyNodeConnector(nodeConnector, type, propMap); } -- 2.36.6