X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Finternal%2FSwitchManager.java;h=d3d41be19f8d6061d2f5f9502c0678fe71cf332e;hb=78ef04c45c5a7fbee9bbb9ae77ecb1882add8623;hp=4c4adf047853410d325b5d67fad2c197ef66866e;hpb=89f53da1dd72537642e2901ffb3be57cd28b1397;p=controller.git 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 4c4adf0478..d3d41be19f 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 @@ -16,7 +16,6 @@ import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.Dictionary; import java.util.EnumSet; import java.util.Enumeration; @@ -34,7 +33,6 @@ import org.eclipse.osgi.framework.console.CommandInterpreter; import org.eclipse.osgi.framework.console.CommandProvider; import org.opendaylight.controller.clustering.services.CacheConfigException; import org.opendaylight.controller.clustering.services.CacheExistException; -import org.opendaylight.controller.clustering.services.ICacheUpdateAware; import org.opendaylight.controller.clustering.services.IClusterContainerServices; import org.opendaylight.controller.clustering.services.IClusterServices; import org.opendaylight.controller.configuration.IConfigurationContainerAware; @@ -54,6 +52,7 @@ import org.opendaylight.controller.sal.core.Tier; import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.controller.sal.inventory.IInventoryService; import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates; +import org.opendaylight.controller.sal.reader.NodeDescription; import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.HexEncode; import org.opendaylight.controller.sal.utils.IObjectReader; @@ -61,6 +60,7 @@ import org.opendaylight.controller.sal.utils.ObjectReader; import org.opendaylight.controller.sal.utils.ObjectWriter; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; +import org.opendaylight.controller.statisticsmanager.IStatisticsManager; import org.opendaylight.controller.switchmanager.IInventoryListener; import org.opendaylight.controller.switchmanager.ISpanAware; import org.opendaylight.controller.switchmanager.ISwitchManager; @@ -83,13 +83,10 @@ import org.slf4j.LoggerFactory; * instance per container of the network. All the node/nodeConnector properties * are maintained in the default container only. */ -public class SwitchManager implements ISwitchManager, -IConfigurationContainerAware, IObjectReader, -ICacheUpdateAware, IListenInventoryUpdates, -CommandProvider { +public class SwitchManager implements ISwitchManager, IConfigurationContainerAware, + IObjectReader, IListenInventoryUpdates, CommandProvider { private static Logger log = LoggerFactory.getLogger(SwitchManager.class); private static String ROOT = GlobalConstants.STARTUPHOME.toString(); - private static final String SAVE = "Save"; private String subnetFileName, spanFileName, switchConfigFileName; private final List spanNodeConnectors = new CopyOnWriteArrayList(); // Collection of Subnets keyed by the InetAddress @@ -98,12 +95,12 @@ CommandProvider { private ConcurrentMap spanConfigList; // manually configured parameters for the node such as name, tier, mode private ConcurrentMap nodeConfigList; - private ConcurrentMap configSaveEvent; private ConcurrentMap> nodeProps; private ConcurrentMap> nodeConnectorProps; private ConcurrentMap> nodeConnectorNames; private ConcurrentMap controllerProps; private IInventoryService inventoryService; + private IStatisticsManager statisticsManager; private final Set switchManagerAware = Collections .synchronizedSet(new HashSet()); private final Set inventoryListeners = Collections @@ -207,27 +204,27 @@ CommandProvider { try { clusterContainerService.createCache( "switchmanager.subnetsConfigList", - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache("switchmanager.spanConfigList", - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache("switchmanager.nodeConfigList", - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache("switchmanager.subnets", - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache( "switchmanager.configSaveEvent", - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache("switchmanager.nodeProps", - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache( "switchmanager.nodeConnectorProps", - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache( "switchmanager.nodeConnectorNames", - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache( "switchmanager.controllerProps", - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); } catch (CacheConfigException cce) { log.error("\nCache configuration invalid - check cache mode"); } catch (CacheExistException ce) { @@ -266,12 +263,6 @@ CommandProvider { log.error("\nFailed to get cache for subnets"); } - configSaveEvent = (ConcurrentMap) clusterContainerService - .getCache("switchmanager.configSaveEvent"); - if (configSaveEvent == null) { - log.error("\nFailed to get cache for configSaveEvent"); - } - nodeProps = (ConcurrentMap>) clusterContainerService .getCache("switchmanager.nodeProps"); if (nodeProps == null) { @@ -302,7 +293,6 @@ CommandProvider { spanConfigList = new ConcurrentHashMap(); nodeConfigList = new ConcurrentHashMap(); subnets = new ConcurrentHashMap(); - configSaveEvent = new ConcurrentHashMap(); nodeProps = new ConcurrentHashMap>(); nodeConnectorProps = new ConcurrentHashMap>(); nodeConnectorNames = new ConcurrentHashMap>(); @@ -698,18 +688,43 @@ CommandProvider { } Map updateProperties = switchConfig.getNodeProperties(); - String nodeId = switchConfig.getNodeId(); ForwardingMode mode = (ForwardingMode) updateProperties.get(ForwardingMode.name); if (mode != null) { if (isDefaultContainer) { if (!mode.isValid()) { - return new Status(StatusCode.BADREQUEST, "Invalid Forwarding Mode Value."); + return new Status(StatusCode.BADREQUEST, "Invalid Forwarding Mode Value"); } } else { return new Status(StatusCode.NOTACCEPTABLE, "Forwarding Mode modification is allowed only in default container"); } } + + Description description = (Description) switchConfig.getProperty(Description.propertyName); + String nodeId = switchConfig.getNodeId(); + Node node = Node.fromString(nodeId); + NodeDescription nodeDesc = (this.statisticsManager == null) ? null : this.statisticsManager + .getNodeDescription(node); + String advertisedDesc = (nodeDesc == null) ? "" : nodeDesc.getDescription(); + if (description != null && description.getValue() != null) { + if (description.getValue().isEmpty() || description.getValue().equals(advertisedDesc)) { + updateProperties.remove(Description.propertyName); + switchConfig = new SwitchConfig(nodeId, updateProperties); + } else { + // check if description is configured or was published by any other node + 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); + String advDesc = (nDesc == null) ? "" : nDesc.getDescription(); + if ((description.equals(desc) || description.getValue().equals(advDesc)) && !node.equals(n)) { + return new Status(StatusCode.CONFLICT, "Node name already in use"); + } + } + } + } + boolean modeChange = false; SwitchConfig sc = nodeConfigList.get(nodeId); Map prevNodeProperties = new HashMap(); @@ -743,30 +758,28 @@ CommandProvider { } } } - Node node = Node.fromString(nodeId); Map propMapCurr = nodeProps.get(node); if (propMapCurr == null) { return new Status(StatusCode.SUCCESS); } Map propMap = new HashMap(propMapCurr); - if (!prevNodeProperties.isEmpty()) { - for (String prop : prevNodeProperties.keySet()) { - if (!updateProperties.containsKey(prop)) { - if (prop.equals(Description.propertyName)) { - Map> nodeProp = this.inventoryService.getNodeProps(); - if (nodeProp.get(node) != null) { - propMap.put(Description.propertyName, nodeProp.get(node).get(Description.propertyName)); - continue; - } + for (Map.Entry entry : prevNodeProperties.entrySet()) { + String prop = entry.getKey(); + if (!updateProperties.containsKey(prop)) { + if (prop.equals(Description.propertyName)) { + if (!advertisedDesc.isEmpty()) { + Property desc = new Description(advertisedDesc); + propMap.put(Description.propertyName, desc); } - propMap.remove(prop); + continue; } + propMap.remove(prop); } } propMap.putAll(updateProperties); if (!nodeProps.replace(node, propMapCurr, propMap)) { // TODO rollback using Transactionality - return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration."); + return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration"); } if (modeChange) { notifyModeChange(node, (mode == null) ? false : mode.isProactive()); @@ -784,7 +797,8 @@ CommandProvider { 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) { @@ -806,8 +820,6 @@ CommandProvider { @Override public Status saveSwitchConfig() { - // Publish the save config event to the cluster nodes - configSaveEvent.put(new Date().getTime(), SAVE); return saveSwitchConfigInternal(); } @@ -882,20 +894,6 @@ CommandProvider { return ncList; } - @Override - public void entryCreated(Long key, String cacheName, boolean local) { - } - - @Override - public void entryUpdated(Long key, String new_value, String cacheName, - boolean originLocal) { - saveSwitchConfigInternal(); - } - - @Override - public void entryDeleted(Long key, String cacheName, boolean originLocal) { - } - private void addNode(Node node, Set props) { log.trace("{} added, props: {}", node, props); if (nodeProps == null) { @@ -960,6 +958,17 @@ CommandProvider { 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); @@ -1033,6 +1042,7 @@ CommandProvider { public void updateNodeConnector(NodeConnector nodeConnector, UpdateType type, Set props) { Map propMap = new HashMap(); + boolean update = true; log.debug("updateNodeConnector: {} type {} props {} for container {}", new Object[] { nodeConnector, type, props, containerName }); @@ -1043,7 +1053,6 @@ CommandProvider { switch (type) { case ADDED: - case CHANGED: if (props != null) { for (Property prop : props) { addNodeConnectorProp(nodeConnector, prop); @@ -1055,17 +1064,33 @@ CommandProvider { addSpanPort(nodeConnector); break; + case CHANGED: + if (!nodeConnectorProps.containsKey(nodeConnector) || (props == null)) { + update = false; + } else { + for (Property prop : props) { + addNodeConnectorProp(nodeConnector, prop); + propMap.put(prop.getName(), prop); + } + } + break; case REMOVED: + if (!nodeConnectorProps.containsKey(nodeConnector)) { + update = false; + } removeNodeConnectorAllProps(nodeConnector); // clean up span config removeSpanPort(nodeConnector); break; default: + update = false; break; } - notifyNodeConnector(nodeConnector, type, propMap); + if (update) { + notifyNodeConnector(nodeConnector, type, propMap); + } } @Override @@ -1166,7 +1191,8 @@ CommandProvider { } 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; } @@ -1185,7 +1211,8 @@ CommandProvider { } 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; } @@ -1202,7 +1229,8 @@ CommandProvider { } 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; @@ -1341,9 +1369,10 @@ CommandProvider { 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(); } @@ -1402,9 +1431,10 @@ CommandProvider { 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(); } @@ -1438,17 +1468,22 @@ CommandProvider { 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(); } } map.remove(name.getValue()); - if (!nodeConnectorNames.replace(node, mapCurr, map)) { - log.warn("Cluster conflict: Unable remove Name property of nodeconnector {}, skip.", - nodeConnector.getID()); + if (map.isEmpty()) { + nodeConnectorNames.remove(node); + } else { + if (!nodeConnectorNames.replace(node, mapCurr, map)) { + log.warn("Cluster conflict: Unable remove Name property of nodeconnector {}, skip.", + nodeConnector.getID()); + } } } @@ -1532,6 +1567,16 @@ CommandProvider { clearInventories(); } + public void setStatisticsManager(IStatisticsManager statisticsManager) { + log.trace("Got statistics manager set request {}", statisticsManager); + this.statisticsManager = statisticsManager; + } + + public void unsetStatisticsManager(IStatisticsManager statisticsManager) { + log.trace("Got statistics manager UNset request"); + this.statisticsManager = null; + } + public void setSwitchManagerAware(ISwitchManagerAware service) { log.trace("Got inventory service set request {}", service); if (this.switchManagerAware != null) { @@ -1673,7 +1718,8 @@ CommandProvider { 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); } @@ -2024,12 +2070,6 @@ CommandProvider { nodeProps.put(node, propMap); } - private void removeNodeProps(Node node) { - if (getUpNodeConnectors(node).size() == 0) { - nodeProps.remove(node); - } - } - @Override public Status saveConfiguration() { return saveSwitchConfig();