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=971213e483e567b4d4a6d0336ee613b85ceb25a8;hp=79159e5ff102270c0d2e094a732acd5fb77130a5;hb=94342ca1bfa231b36557e2c44d9e50460483354c;hpb=a3a28e8138fa25170b01e6b51a44490f002f6e91 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 79159e5ff1..971213e483 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,10 +52,10 @@ 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; -import org.opendaylight.controller.sal.utils.NodeCreator; import org.opendaylight.controller.sal.utils.ObjectReader; import org.opendaylight.controller.sal.utils.ObjectWriter; import org.opendaylight.controller.sal.utils.ServiceHelper; @@ -82,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; @@ -101,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; @@ -117,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; } @@ -185,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(); } @@ -315,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()); } @@ -345,6 +351,7 @@ public class SwitchManagerImpl implements ISwitchManager, return new ArrayList(nodeConfigList.values()); } + @Override public SwitchConfig getSwitchConfig(String switchId) { return nodeConfigList.get(switchId); } @@ -352,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); @@ -367,6 +378,7 @@ public class SwitchManagerImpl implements ISwitchManager, return sw; } + @Override public List getNetworkDevices() { Set nodeSet = getNodes(); List swList = new ArrayList(); @@ -401,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()); } } @@ -455,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); } @@ -869,26 +883,11 @@ public class SwitchManagerImpl implements ISwitchManager, : null; } - /* - * test utility function which assumes all nodes are OF nodes - */ - private Node getNode(Long id) { - Set nodes = getNodes(); - if (nodes != null) { - for (Node node : nodes) { - if (id.equals((Long) node.getID())) { - return node; - } - } - } - return null; - } - /* * Returns a copy of a list of properties for a given node - * + * * (non-Javadoc) - * + * * @see * org.opendaylight.controller.switchmanager.ISwitchManager#getNodeProps * (org.opendaylight.controller.sal.core.Node) @@ -924,8 +923,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); @@ -949,16 +949,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 (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node - .getID()) + if (!nodeConnector.getNode().equals(node)) { continue; - if (isNodeConnectorEnabled(nodeConnector)) + } + if (isNodeConnectorEnabled(nodeConnector)) { nodeConnectorSet.add(nodeConnector); + } } return nodeConnectorSet; @@ -966,14 +968,15 @@ 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()) { - if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node - .getID()) + if (!nodeConnector.getNode().equals(node)) { continue; + } nodeConnectorSet.add(nodeConnector); } @@ -982,8 +985,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()) { @@ -997,24 +1001,6 @@ public class SwitchManagerImpl implements ISwitchManager, return nodeConnectorSet; } - /* - * testing utility function which assumes we are dealing with OF Node - * nodeconnectors only - */ - @SuppressWarnings("unused") - private Set getEnabledNodeConnectorIds(Node node) { - Set ids = new HashSet(); - Set nodeConnectors = getUpNodeConnectors(node); - - if (nodeConnectors != null) { - for (NodeConnector nodeConnector : nodeConnectors) { - ids.add((Long) nodeConnector.getID()); - } - } - - return ids; - } - @Override public Map getNodeConnectorProps( NodeConnector nodeConnector) { @@ -1083,19 +1069,21 @@ 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); } /** * Adds a node connector and its property if any - * + * * @param nodeConnector * {@link org.opendaylight.controller.sal.core.NodeConnector} * @param propName @@ -1139,7 +1127,7 @@ public class SwitchManagerImpl implements ISwitchManager, /** * Removes one property of a node connector - * + * * @param nodeConnector * {@link org.opendaylight.controller.sal.core.NodeConnector} * @param propName @@ -1177,7 +1165,7 @@ public class SwitchManagerImpl implements ISwitchManager, /** * Removes all the properties of a node connector - * + * * @param nodeConnector * {@link org.opendaylight.controller.sal.core.NodeConnector} * @return success or failed reason @@ -1204,7 +1192,7 @@ public class SwitchManagerImpl implements ISwitchManager, /** * Function called by the dependency manager when all the required * dependencies are satisfied - * + * */ void init(Component c) { Dictionary props = c.getServiceProperties(); @@ -1225,7 +1213,7 @@ public class SwitchManagerImpl implements ISwitchManager, * Function called by the dependency manager when at least one dependency * become unsatisfied or when the component is shutting down because for * example bundle is being stopped. - * + * */ void destroy() { shutDown(); @@ -1234,7 +1222,7 @@ public class SwitchManagerImpl implements ISwitchManager, /** * Function called by dependency manager after "init ()" is called and after * the services provided by the class are registered in the service registry - * + * */ void start() { // OSGI console @@ -1253,7 +1241,7 @@ public class SwitchManagerImpl implements ISwitchManager, * Function called by the dependency manager before the services exported by * the component are unregistered, this will be followed by a "destroy ()" * calls - * + * */ void stop() { } @@ -1427,8 +1415,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); @@ -1453,7 +1442,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; } @@ -1466,9 +1455,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()); } @@ -1479,9 +1472,13 @@ public class SwitchManagerImpl implements ISwitchManager, ci.println("Please enter node id"); return; } - Long id = Long.decode(st); - Node node = NodeCreator.createOFNode(id); + Node node = Node.fromString(st); + if (node == null) { + ci.println("Please enter node id"); + return; + } + Set nodeConnectorSet = getUpNodeConnectors(node); if (nodeConnectorSet == null) { return; @@ -1501,10 +1498,14 @@ public class SwitchManagerImpl implements ISwitchManager, ci.println("Please enter node id"); return; } - Long id = Long.decode(st); + + Node node = Node.fromString(st); + if (node == null) { + ci.println("Please enter node id"); + return; + } ci.println(" NodeConnector BandWidth(Gbps) Admin State"); - Node node = NodeCreator.createOFNode(id); Set nodeConnectorSet = getNodeConnectors(node); if (nodeConnectorSet == null) { return; @@ -1534,8 +1535,14 @@ public class SwitchManagerImpl implements ISwitchManager, ci.println("Please enter node id"); return; } - Object id = Long.decode(st); - Switch sw = getSwitchByNode(NodeCreator.createOFNode((Long) id)); + + Node node = Node.fromString(st); + if (node == null) { + ci.println("Please enter node id"); + return; + } + + Switch sw = getSwitchByNode(node); ci.println(" NodeConnector Name"); if (sw == null) { @@ -1549,10 +1556,9 @@ public class SwitchManagerImpl implements ISwitchManager, nodeConnectorName = (propMap == null) ? null : ((Name) propMap .get(Name.NamePropName)).getValue(); if (nodeConnectorName != null) { - Node node = nodeConnector.getNode(); - if (!node.equals(getNode((Long) id))) { - log.debug("node not match {} {}", node, - getNode((Long) id)); + Node nd = nodeConnector.getNode(); + if (!nd.equals(node)) { + log.debug("node not match {} {}", nd, node); } Map map = nodeConnectorNames .get(node); @@ -1584,9 +1590,12 @@ public class SwitchManagerImpl implements ISwitchManager, ci.println("Please enter node id"); return; } - Long id = Long.decode(st); - Node node = NodeCreator.createOFNode(id); + Node node = Node.fromString(st); + if (node == null) { + ci.println("Please enter node id"); + return; + } st = ci.nextArgument(); if (st == null) { @@ -1604,17 +1613,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; } @@ -1635,17 +1646,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 @@ -1696,7 +1699,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); } } @@ -1740,7 +1743,7 @@ public class SwitchManagerImpl implements ISwitchManager, /** * Creates a Name/Tier/Bandwidth Property object based on given property * name and value. Other property types are not supported yet. - * + * * @param propName * Name of the Property * @param propValue