X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Finternal%2FSwitchManagerImpl.java;h=443c7a42ab7da517fbb8df65082c36d1a220a79e;hp=d9333e9f824d1cdd7c6bd2dc579e9efb0cd009fb;hb=eae5ef7cfee9bacecc5281cc378a904fe9ae4b96;hpb=4b51e79b36e17fb1f17d3a9b9a3ea6495486ccac 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..443c7a42ab 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,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.utils.HexEncode; import org.opendaylight.controller.sal.utils.StatusCode; import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.IObjectReader; @@ -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; } @@ -184,12 +187,15 @@ 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(); } @@ -314,12 +320,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 +351,7 @@ public class SwitchManagerImpl implements ISwitchManager, return new ArrayList(nodeConfigList.values()); } + @Override public SwitchConfig getSwitchConfig(String switchId) { return nodeConfigList.get(switchId); } @@ -351,7 +359,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 +378,7 @@ public class SwitchManagerImpl implements ISwitchManager, return sw; } + @Override public List getNetworkDevices() { Set nodeSet = getNodes(); List swList = new ArrayList(); @@ -400,8 +413,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 +468,7 @@ public class SwitchManagerImpl implements ISwitchManager, /** * Adds Subnet configured in GUI or API3 */ + @Override public Status addSubnet(SubnetConfig conf) { return this.addRemoveSubnet(conf, true); } @@ -805,6 +820,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 +843,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; @@ -908,8 +926,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 +952,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 +971,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 +988,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 +1072,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); } @@ -1313,6 +1338,8 @@ public class SwitchManagerImpl implements ISwitchManager, Set nodeSet = nodeProps.keySet(); if (nodeSet != null) { for (Node node : nodeSet) { + log.debug("getInventories: {} added for container {}", + new Object[] { node, containerName }); addNode(node, null); } } @@ -1362,17 +1389,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 +1420,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 +1447,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 +1460,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 +1618,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 +1651,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 @@ -1678,7 +1704,7 @@ public class SwitchManagerImpl implements ISwitchManager, List ncLists = new ArrayList(); for (NodeConnector nodeConnector : nodeConncetors) { - if (!spanNodeConnectors.contains(nodeConnector)) { + if (spanNodeConnectors.contains(nodeConnector)) { ncLists.add(nodeConnector); } }