X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Finternal%2FSwitchManagerImpl.java;h=d32f98650b8b549ce8235fd3c14d22c55205ac56;hb=7aac9c5fcb0f617c6b15e527f3c0f3d87032b83a;hp=d9333e9f824d1cdd7c6bd2dc579e9efb0cd009fb;hpb=4b51e79b36e17fb1f17d3a9b9a3ea6495486ccac;p=controller.git diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java index d9333e9f82..d32f98650b 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java @@ -41,6 +41,7 @@ import org.opendaylight.controller.configuration.IConfigurationContainerAware; import org.opendaylight.controller.sal.core.Bandwidth; import org.opendaylight.controller.sal.core.Config; import org.opendaylight.controller.sal.core.Description; +import org.opendaylight.controller.sal.core.MacAddress; import org.opendaylight.controller.sal.core.Name; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; @@ -51,13 +52,14 @@ 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.utils.StatusCode; import org.opendaylight.controller.sal.utils.GlobalConstants; +import org.opendaylight.controller.sal.utils.HexEncode; import org.opendaylight.controller.sal.utils.IObjectReader; import org.opendaylight.controller.sal.utils.ObjectReader; import org.opendaylight.controller.sal.utils.ObjectWriter; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.controller.sal.utils.Status; +import org.opendaylight.controller.sal.utils.StatusCode; import org.opendaylight.controller.switchmanager.IInventoryListener; import org.opendaylight.controller.switchmanager.ISpanAware; import org.opendaylight.controller.switchmanager.ISwitchManager; @@ -81,16 +83,16 @@ import org.slf4j.LoggerFactory; * are maintained in the default container only. */ public class SwitchManagerImpl implements ISwitchManager, - IConfigurationContainerAware, IObjectReader, - ICacheUpdateAware, IListenInventoryUpdates, - CommandProvider { +IConfigurationContainerAware, IObjectReader, +ICacheUpdateAware, IListenInventoryUpdates, +CommandProvider { private static Logger log = LoggerFactory .getLogger(SwitchManagerImpl.class); private static String ROOT = GlobalConstants.STARTUPHOME.toString(); private static final String SAVE = "Save"; private String subnetFileName = null, spanFileName = null, switchConfigFileName = null; - private List spanNodeConnectors = new CopyOnWriteArrayList(); + private final List spanNodeConnectors = new CopyOnWriteArrayList(); private ConcurrentMap subnets; // set of Subnets keyed by the InetAddress private ConcurrentMap subnetsConfigList; private ConcurrentMap spanConfigList; @@ -100,11 +102,11 @@ public class SwitchManagerImpl implements ISwitchManager, private ConcurrentMap> nodeConnectorProps; // properties are maintained in global container only private ConcurrentMap> nodeConnectorNames; private IInventoryService inventoryService; - private Set switchManagerAware = Collections + private final Set switchManagerAware = Collections .synchronizedSet(new HashSet()); - private Set inventoryListeners = Collections + private final Set inventoryListeners = Collections .synchronizedSet(new HashSet()); - private Set spanAware = Collections + private final Set spanAware = Collections .synchronizedSet(new HashSet()); private byte[] MAC; private static boolean hostRefresh = true; @@ -116,14 +118,15 @@ public class SwitchManagerImpl implements ISwitchManager, public enum ReasonCode { SUCCESS("Success"), FAILURE("Failure"), INVALID_CONF( "Invalid Configuration"), EXIST("Entry Already Exist"), CONFLICT( - "Configuration Conflict with Existing Entry"); + "Configuration Conflict with Existing Entry"); - private String name; + private final String name; private ReasonCode(String name) { this.name = name; } + @Override public String toString() { return name; } @@ -171,7 +174,7 @@ public class SwitchManagerImpl implements ISwitchManager, public void startUp() { // Initialize configuration file names - subnetFileName = ROOT + "subnets" + this.getContainerName() + ".conf"; + subnetFileName = ROOT + "subnets_" + this.getContainerName() + ".conf"; spanFileName = ROOT + "spanPorts_" + this.getContainerName() + ".conf"; switchConfigFileName = ROOT + "switchConfig_" + this.getContainerName() + ".conf"; @@ -184,18 +187,20 @@ public class SwitchManagerImpl implements ISwitchManager, * Read startup and build database if we have not already gotten the * configurations synced from another node */ - if (subnetsConfigList.isEmpty()) + if (subnetsConfigList.isEmpty()) { loadSubnetConfiguration(); - if (spanConfigList.isEmpty()) + } + if (spanConfigList.isEmpty()) { loadSpanConfiguration(); - if (nodeConfigList.isEmpty()) + } + if (nodeConfigList.isEmpty()) { loadSwitchConfiguration(); + } MAC = getHardwareMAC(); } public void shutDown() { - destroyCaches(this.getContainerName()); } @SuppressWarnings("deprecation") @@ -314,12 +319,13 @@ public class SwitchManagerImpl implements ISwitchManager, clusterContainerService.destroyCache("switchmanager.configSaveEvent"); clusterContainerService.destroyCache("switchmanager.nodeProps"); clusterContainerService - .destroyCache("switchmanager.nodeConnectorProps"); + .destroyCache("switchmanager.nodeConnectorProps"); clusterContainerService - .destroyCache("switchmanager.nodeConnectorNames"); + .destroyCache("switchmanager.nodeConnectorNames"); nonClusterObjectCreate(); } + @Override public List getSubnetsConfigList() { return new ArrayList(subnetsConfigList.values()); } @@ -344,6 +350,7 @@ public class SwitchManagerImpl implements ISwitchManager, return new ArrayList(nodeConfigList.values()); } + @Override public SwitchConfig getSwitchConfig(String switchId) { return nodeConfigList.get(switchId); } @@ -351,7 +358,11 @@ public class SwitchManagerImpl implements ISwitchManager, public Switch getSwitchByNode(Node node) { Switch sw = new Switch(node); sw.setNode(node); - + MacAddress mac = (MacAddress) this.getNodeProp(node, + MacAddress.name); + if (mac != null) { + sw.setDataLayerAddress(mac.getMacAddress()); + } Set ncSet = getPhysicalNodeConnectors(node); sw.setNodeConnectors(ncSet); @@ -366,6 +377,7 @@ public class SwitchManagerImpl implements ISwitchManager, return sw; } + @Override public List getNetworkDevices() { Set nodeSet = getNodes(); List swList = new ArrayList(); @@ -400,8 +412,9 @@ public class SwitchManagerImpl implements ISwitchManager, } subnets.put(conf.getIPnum(), subnet); } else { // This is the deletion of the whole subnet - if (subnet == null) + if (subnet == null) { return; + } subnets.remove(conf.getIPnum()); } } @@ -454,6 +467,7 @@ public class SwitchManagerImpl implements ISwitchManager, /** * Adds Subnet configured in GUI or API3 */ + @Override public Status addSubnet(SubnetConfig conf) { return this.addRemoveSubnet(conf, true); } @@ -484,11 +498,13 @@ public class SwitchManagerImpl implements ISwitchManager, } conf.addNodeConnectors(switchPorts); + subnetsConfigList.put(name, conf); // Update Database Subnet sub = subnets.get(conf.getIPnum()); Set sp = conf.getNodeConnectors(switchPorts); sub.addNodeConnectors(sp); + subnets.put(conf.getIPnum(), sub); return new Status(StatusCode.SUCCESS, null); } @@ -500,11 +516,13 @@ public class SwitchManagerImpl implements ISwitchManager, return new Status(StatusCode.NOTFOUND, "Subnet does not exist"); } conf.removeNodeConnectors(switchPorts); + subnetsConfigList.put(name, conf); // Update Database Subnet sub = subnets.get(conf.getIPnum()); Set sp = conf.getNodeConnectors(switchPorts); sub.deleteNodeConnectors(sp); + subnets.put(conf.getIPnum(), sub); return new Status(StatusCode.SUCCESS, null); } @@ -539,7 +557,7 @@ public class SwitchManagerImpl implements ISwitchManager, @SuppressWarnings("unchecked") private void loadSubnetConfiguration() { ObjectReader objReader = new ObjectReader(); - ConcurrentMap confList = (ConcurrentMap) objReader + ConcurrentMap confList = (ConcurrentMap) objReader .read(this, subnetFileName); if (confList == null) { @@ -583,6 +601,11 @@ public class SwitchManagerImpl implements ISwitchManager, @Override public void updateSwitchConfig(SwitchConfig cfgObject) { + // update default container only + if (!isDefaultContainer) { + return; + } + boolean modeChange = false; SwitchConfig sc = nodeConfigList.get(cfgObject.getNodeId()); @@ -592,28 +615,25 @@ public class SwitchManagerImpl implements ISwitchManager, nodeConfigList.put(cfgObject.getNodeId(), cfgObject); try { - // update default container only - if (isDefaultContainer) { - String nodeId = cfgObject.getNodeId(); - Node node = Node.fromString(nodeId); - Map propMap; - if (nodeProps.get(node) != null) { - propMap = nodeProps.get(node); - } else { - propMap = new HashMap(); - } - Property desc = new Description(cfgObject.getNodeDescription()); - propMap.put(desc.getName(), desc); - Property tier = new Tier(Integer.parseInt(cfgObject.getTier())); - propMap.put(tier.getName(), tier); - addNodeProps(node, propMap); + String nodeId = cfgObject.getNodeId(); + Node node = Node.fromString(nodeId); + Map propMap; + if (nodeProps.get(node) != null) { + propMap = nodeProps.get(node); + } else { + propMap = new HashMap(); + } + Property desc = new Description(cfgObject.getNodeDescription()); + propMap.put(desc.getName(), desc); + Property tier = new Tier(Integer.parseInt(cfgObject.getTier())); + propMap.put(tier.getName(), tier); + addNodeProps(node, propMap); - log.info("Set Node {}'s Mode to {}", nodeId, - cfgObject.getMode()); + log.info("Set Node {}'s Mode to {}", nodeId, + cfgObject.getMode()); - if (modeChange) { - notifyModeChange(node, cfgObject.isProactive()); - } + if (modeChange) { + notifyModeChange(node, cfgObject.isProactive()); } } catch (Exception e) { log.debug("updateSwitchConfig: {}", e.getMessage()); @@ -805,6 +825,8 @@ public class SwitchManagerImpl implements ISwitchManager, @Override public void updateNode(Node node, UpdateType type, Set props) { + log.debug("updateNode: {} type {} props {} for container {}", + new Object[] { node, type, props, containerName }); switch (type) { case ADDED: addNode(node, props); @@ -826,7 +848,8 @@ public class SwitchManagerImpl implements ISwitchManager, Node node = nodeConnector.getNode(); Map propMap = new HashMap(); - log.trace("{} {}", nodeConnector, type); + log.debug("updateNodeConnector: {} type {} props {} for container {}", + new Object[] { nodeConnector, type, props, containerName }); if (nodeConnectorProps == null) { return; @@ -845,7 +868,6 @@ public class SwitchManagerImpl implements ISwitchManager, addNodeProps(node, null); } - // check if span is configed addSpanPort(nodeConnector); break; case REMOVED: @@ -908,8 +930,9 @@ public class SwitchManagerImpl implements ISwitchManager, public void setNodeProp(Node node, Property prop) { /* Get a copy of the property map */ Map propMap = getNodeProps(node); - if (propMap == null) + if (propMap == null) { return; + } propMap.put(prop.getName(), prop); this.nodeProps.put(node, propMap); @@ -933,16 +956,18 @@ public class SwitchManagerImpl implements ISwitchManager, @Override public Set getUpNodeConnectors(Node node) { - if (nodeConnectorProps == null) + if (nodeConnectorProps == null) { return null; + } Set nodeConnectorSet = new HashSet(); for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) { if (!nodeConnector.getNode().equals(node)) { continue; } - if (isNodeConnectorEnabled(nodeConnector)) + if (isNodeConnectorEnabled(nodeConnector)) { nodeConnectorSet.add(nodeConnector); + } } return nodeConnectorSet; @@ -950,8 +975,9 @@ public class SwitchManagerImpl implements ISwitchManager, @Override public Set getNodeConnectors(Node node) { - if (nodeConnectorProps == null) + if (nodeConnectorProps == null) { return null; + } Set nodeConnectorSet = new HashSet(); for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) { @@ -966,8 +992,9 @@ public class SwitchManagerImpl implements ISwitchManager, @Override public Set getPhysicalNodeConnectors(Node node) { - if (nodeConnectorProps == null) + if (nodeConnectorProps == null) { return null; + } Set nodeConnectorSet = new HashSet(); for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) { @@ -1049,12 +1076,14 @@ public class SwitchManagerImpl implements ISwitchManager, @Override public NodeConnector getNodeConnector(Node node, String nodeConnectorName) { - if (nodeConnectorNames == null) + if (nodeConnectorNames == null) { return null; + } Map map = nodeConnectorNames.get(node); - if (map == null) + if (map == null) { return null; + } return map.get(nodeConnectorName); } @@ -1309,15 +1338,26 @@ public class SwitchManagerImpl implements ISwitchManager, return; } - nodeProps = this.inventoryService.getNodeProps(); - Set nodeSet = nodeProps.keySet(); - if (nodeSet != null) { - for (Node node : nodeSet) { - addNode(node, null); + Map> nodeProp = this.inventoryService.getNodeProps(); + for(Map.Entry> entry : nodeProp.entrySet()) { + Node node = entry.getKey(); + log.debug("getInventories: {} added for container {}", + new Object[] { node, containerName }); + Map propMap = entry.getValue(); + Set props = new HashSet(); + for(Property property : propMap.values()) { + props.add(property); } + addNode(node, props); } - nodeConnectorProps = inventoryService.getNodeConnectorProps(); + Map> nodeConnectorProp = this.inventoryService.getNodeConnectorProps(); + for(Map.Entry> entry : nodeConnectorProp.entrySet()) { + Map propMap = entry.getValue(); + for(Property property : propMap.values()) { + addNodeConnectorProp(entry.getKey(), property); + } + } } private void clearInventories() { @@ -1362,17 +1402,17 @@ public class SwitchManagerImpl implements ISwitchManager, } private void bulkUpdateService(IInventoryListener service) { + Map propMap; + UpdateType type = UpdateType.ADDED; + for (Node node : getNodes()) { - service.notifyNode(node, UpdateType.ADDED, null); + propMap = nodeProps.get(node); + service.notifyNode(node, type, propMap); } - Map propMap = new HashMap(); - propMap.put(State.StatePropName, new State(State.EDGE_UP)); for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) { - if (isNodeConnectorEnabled(nodeConnector)) { - service.notifyNodeConnector(nodeConnector, UpdateType.ADDED, - propMap); - } + propMap = nodeConnectorProps.get(nodeConnector); + service.notifyNodeConnector(nodeConnector, type, propMap); } } @@ -1393,8 +1433,9 @@ public class SwitchManagerImpl implements ISwitchManager, @Override public Boolean isNodeConnectorEnabled(NodeConnector nodeConnector) { - if (nodeConnector == null) + if (nodeConnector == null) { return false; + } Config config = (Config) getNodeConnectorProp(nodeConnector, Config.ConfigPropName); @@ -1419,7 +1460,7 @@ public class SwitchManagerImpl implements ISwitchManager, } public void _pns(CommandInterpreter ci) { - ci.println(" Node Type Name Tier"); + ci.println(" Node Type MAC Name Tier"); if (nodeProps == null) { return; } @@ -1432,9 +1473,13 @@ public class SwitchManagerImpl implements ISwitchManager, Description.propertyName)); Tier tier = ((Tier) getNodeProp(node, Tier.TierPropName)); String nodeName = (desc == null) ? "" : desc.getValue(); + MacAddress mac = (MacAddress) getNodeProp(node, + MacAddress.name); + String macAddr = (mac == null) ? "" : HexEncode + .bytesToHexStringFormat(mac.getMacAddress()); int tierNum = (tier == null) ? 0 : tier.getValue(); - ci.println(node + " " + node.getType() + " " - + nodeName + " " + tierNum); + ci.println(node + " " + node.getType() + " " + macAddr + + " " + nodeName + " " + tierNum); } ci.println("Total number of Nodes: " + nodeSet.size()); } @@ -1586,17 +1631,19 @@ public class SwitchManagerImpl implements ISwitchManager, ci.println("expecting on/off/?"); return; } - if (mode.toLowerCase().equals("on")) + if (mode.toLowerCase().equals("on")) { hostRefresh = true; - else if (mode.toLowerCase().equals("off")) + } else if (mode.toLowerCase().equals("off")) { hostRefresh = false; - else if (mode.equals("?")) { - if (hostRefresh) + } else if (mode.equals("?")) { + if (hostRefresh) { ci.println("host refresh is ON"); - else + } else { ci.println("host refresh is OFF"); - } else + } + } else { ci.println("expecting on/off/?"); + } return; } @@ -1617,17 +1664,9 @@ public class SwitchManagerImpl implements ISwitchManager, @Override public byte[] getNodeMAC(Node node) { - if (node.getType().equals(Node.NodeIDType.OPENFLOW)) { - byte[] gmac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - long dpid = (Long) node.getID(); - - for (short i = 0; i < 6; i++) { - gmac[5 - i] = (byte) dpid; - dpid >>= 8; - } - return gmac; - } - return null; + MacAddress mac = (MacAddress) this.getNodeProp(node, + MacAddress.name); + return (mac != null) ? mac.getMacAddress() : null; } @Override @@ -1644,10 +1683,10 @@ public class SwitchManagerImpl implements ISwitchManager, /* * Add span configuration to local cache and notify clients */ - private void addSpanPorts(Node node, List nodeConncetors) { + private void addSpanPorts(Node node, List nodeConnectors) { List ncLists = new ArrayList(); - for (NodeConnector nodeConnector : nodeConncetors) { + for (NodeConnector nodeConnector : nodeConnectors) { if (!spanNodeConnectors.contains(nodeConnector)) { ncLists.add(nodeConnector); } @@ -1665,20 +1704,26 @@ public class SwitchManagerImpl implements ISwitchManager, } } - private void addSpanPort(NodeConnector nodeConncetor) { - List ncLists = new ArrayList(); - ncLists.add(nodeConncetor); - addSpanPorts(nodeConncetor.getNode(), ncLists); + private void addSpanPort(NodeConnector nodeConnector) { + // only add if span is configured on this nodeConnector + for (SpanConfig conf : getSpanConfigList(nodeConnector.getNode())) { + if (conf.getPortArrayList().contains(nodeConnector)) { + List ncLists = new ArrayList(); + ncLists.add(nodeConnector); + addSpanPorts(nodeConnector.getNode(), ncLists); + return; + } + } } /* * Remove span configuration to local cache and notify clients */ - private void removeSpanPorts(Node node, List nodeConncetors) { + private void removeSpanPorts(Node node, List nodeConnectors) { List ncLists = new ArrayList(); - for (NodeConnector nodeConnector : nodeConncetors) { - if (!spanNodeConnectors.contains(nodeConnector)) { + for (NodeConnector nodeConnector : nodeConnectors) { + if (spanNodeConnectors.contains(nodeConnector)) { ncLists.add(nodeConnector); } } @@ -1695,10 +1740,12 @@ public class SwitchManagerImpl implements ISwitchManager, } } - private void removeSpanPort(NodeConnector nodeConncetor) { - List ncLists = new ArrayList(); - ncLists.add(nodeConncetor); - removeSpanPorts(nodeConncetor.getNode(), ncLists); + private void removeSpanPort(NodeConnector nodeConnector) { + if (spanNodeConnectors.contains(nodeConnector)) { + List ncLists = new ArrayList(); + ncLists.add(nodeConnector); + removeSpanPorts(nodeConnector.getNode(), ncLists); + } } private void addNodeProps(Node node, Map propMap) {