From cffdfafd2b23b24025f5ba4b32f16bca501bfeb5 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Tue, 2 Apr 2013 14:05:14 -0700 Subject: [PATCH] ISSUE Opendaylight controller to get node description from OF description statistics datapath description field CHANGE - Switch Mgr to expose a getNodeDescription() method which returns the description configured by user if any, otherwise the one learnt from the proto plugin - Web bunldes to make use of the above api (Currently they are ignoring the info learnt by the plugin) - OFStatisticsManager to implement a IStatistics interface for informing listeners that the description statistics info has been refreshed - Removing current logic where OFStatisticsManager was explicitely invoking the description property update on InventoryService through IOFInventoryService - Removed logic where InventoryServiceShim queries OFStatisticsManager about node description as information is not available at that time and IStatisticsListener updates will serve same purpose - Removing statistics request timeouts from OFStatisticsManager as the timeout is compeltely handled by core.internal.StatisticsCollector Change-Id: I0d2941d3012ca6dc77a386570dbbd8e5c7832a03 Signed-off-by: Alessandro Boch --- .../IInventoryShimInternalListener.java | 4 +- .../openflow/IOFInventoryService.java | 31 -- .../openflow/IOFStatisticsManager.java | 2 +- .../openflow/IStatisticsListener.java | 13 + .../openflow/internal/Activator.java | 21 +- .../internal/DescStatisticsConverter.java | 2 +- .../openflow/internal/InventoryService.java | 106 ++++--- .../internal/InventoryServiceShim.java | 47 +-- .../internal/OFStatisticsManager.java | 281 ++++++++---------- .../openflow/internal/ReadServiceFilter.java | 10 +- .../internal/TopologyServiceShim.java | 11 +- .../internal/DijkstraImplementation.java | 1 - .../controller/sal/action/ActionType.java | 6 +- .../controller/sal/core/Description.java | 54 ++++ .../controller/sal/core/Name.java | 2 - .../controller/sal/core/Node.java | 18 +- .../controller/sal/core/NodeConnector.java | 16 +- .../controller/sal/flowprogrammer/Flow.java | 6 +- .../inventory/IListenInventoryUpdates.java | 4 +- .../inventory/IPluginOutInventoryService.java | 4 +- .../controller/sal/match/Match.java | 7 +- .../controller/sal/match/MatchField.java | 8 +- .../controller/sal/match/MatchType.java | 6 +- .../sal/reader/NodeDescription.java | 21 +- .../controller/sal/action/ActionTest.java | 4 +- .../sal/reader/NodeDescriptionTest.java | 6 +- .../switchmanager/IInventoryListener.java | 4 +- .../switchmanager/ISwitchManager.java | 26 +- .../switchmanager/SubnetConfig.java | 7 +- .../switchmanager/SwitchConfig.java | 10 +- .../internal/SwitchManagerImpl.java | 52 ++-- .../controller/switchmanager/SwitchTest.java | 4 +- .../controller/devices/web/Devices.java | 24 +- .../controller/flows/web/Flows.java | 43 +-- .../controller/topology/web/Topology.java | 6 +- .../troubleshoot/web/Troubleshoot.java | 38 +-- 36 files changed, 434 insertions(+), 471 deletions(-) delete mode 100644 opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFInventoryService.java create mode 100644 opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsListener.java create mode 100644 opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimInternalListener.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimInternalListener.java index 50a4bcae19..e7c11a6eea 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimInternalListener.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimInternalListener.java @@ -29,7 +29,7 @@ public interface IInventoryShimInternalListener { * @param node {@link org.opendaylight.controller.sal.core.Node} being updated * @param type {@link org.opendaylight.controller.sal.core.UpdateType} * @param props set of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.Tier} etc. */ public void updateNode(Node node, UpdateType type, Set props); @@ -40,7 +40,7 @@ public interface IInventoryShimInternalListener { * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector} being updated * @param type {@link org.opendaylight.controller.sal.core.UpdateType} * @param props set of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.State} etc. */ public void updateNodeConnector(NodeConnector nodeConnector, diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFInventoryService.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFInventoryService.java deleted file mode 100644 index f46f24deae..0000000000 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFInventoryService.java +++ /dev/null @@ -1,31 +0,0 @@ - -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.protocol_plugin.openflow; - -import java.util.Set; - -import org.opendaylight.controller.sal.core.Property; - -/** - * - * Interface for Inventory Service visible inside the protocol plugin only - * - * - * - */ -public interface IOFInventoryService { - /** - * Tell Inventory Service a property has been updated - * for the specified switch with the specified value - * - * @param switchId - */ - public void updateSwitchProperty(Long switchId, Set propertySet); -} diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFStatisticsManager.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFStatisticsManager.java index 36bed4fd53..18fe686dd5 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFStatisticsManager.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFStatisticsManager.java @@ -86,7 +86,7 @@ public interface IOFStatisticsManager { * @return the list of openflow statistics */ List queryStatistics(Long switchId, - OFStatisticsType statType, Object target, long timeout); + OFStatisticsType statType, Object target); /** * Returns the averaged transmit rate for the passed switch port diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsListener.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsListener.java new file mode 100644 index 0000000000..4f15a1055a --- /dev/null +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsListener.java @@ -0,0 +1,13 @@ +package org.opendaylight.controller.protocol_plugin.openflow; + +import org.openflow.protocol.statistics.OFDescriptionStatistics; + +/** + * Interface which defines the api which gets called when the information + * contained in the OF description statistics reply message from a network + * is updated with new one. + */ +public interface IStatisticsListener { + public void descriptionRefreshed(Long switchId, + OFDescriptionStatistics description); +} diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Activator.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Activator.java index 75ba17447c..45c0211787 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Activator.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Activator.java @@ -9,7 +9,6 @@ package org.opendaylight.controller.protocol_plugin.openflow.internal; -import org.opendaylight.controller.sal.core.IContainerListener; import java.util.Dictionary; import java.util.Hashtable; @@ -18,18 +17,16 @@ import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketListen; import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketMux; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IOFInventoryService; import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager; import org.opendaylight.controller.protocol_plugin.openflow.IPluginReadServiceFilter; import org.opendaylight.controller.protocol_plugin.openflow.IRefreshInternalProvider; +import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener; import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener; import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.internal.Controller; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; +import org.opendaylight.controller.sal.core.IContainerListener; +import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.discovery.IDiscoveryService; import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService; import org.opendaylight.controller.sal.inventory.IPluginInInventoryService; @@ -40,6 +37,8 @@ import org.opendaylight.controller.sal.reader.IPluginInReadService; import org.opendaylight.controller.sal.topology.IPluginInTopologyService; import org.opendaylight.controller.sal.topology.IPluginOutTopologyService; import org.opendaylight.controller.sal.utils.GlobalConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Openflow protocol plugin Activator @@ -117,7 +116,7 @@ public class Activator extends ComponentActivatorAbstractBase { // export the service c.setInterface(new String[] { IPluginInInventoryService.class.getName(), - IOFInventoryService.class.getName(), + IStatisticsListener.class.getName(), IInventoryShimInternalListener.class.getName() }, null); // Now lets add a service dependency to make sure the @@ -239,6 +238,10 @@ public class Activator extends ComponentActivatorAbstractBase { c.add(createServiceDependency().setService(IController.class, "(name=Controller)").setCallbacks("setController", "unsetController").setRequired(true)); + c.add(createServiceDependency().setService( + IStatisticsListener.class) + .setCallbacks("setStatisticsListener", + "unsetStatisticsListener").setRequired(false)); } if (imp.equals(DiscoveryService.class)) { @@ -299,10 +302,6 @@ public class Activator extends ComponentActivatorAbstractBase { IInventoryShimExternalListener.class).setCallbacks( "setInventoryShimExternalListener", "unsetInventoryShimExternalListener").setRequired(false)); - c.add(createServiceDependency().setService( - IOFStatisticsManager.class).setCallbacks( - "setStatisticsManager", "unsetStatisticsManager") - .setRequired(false)); } if (imp.equals(TopologyServiceShim.class)) { diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DescStatisticsConverter.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DescStatisticsConverter.java index 33918c5cde..7a09a480dc 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DescStatisticsConverter.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DescStatisticsConverter.java @@ -38,7 +38,7 @@ public class DescStatisticsConverter { hwDesc.setManufacturer(ofDesc.getManufacturerDescription()); hwDesc.setHardware(ofDesc.getHardwareDescription()); hwDesc.setSoftware(ofDesc.getSoftwareDescription()); - hwDesc.setSdnProtocolDescription(ofDesc.getDatapathDescription()); + hwDesc.setDescription(ofDesc.getDatapathDescription()); hwDesc.setSerialNumber(ofDesc.getSerialNumber()); } return hwDesc; diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java index 7041f447e3..e7132597ec 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java @@ -21,26 +21,27 @@ import java.util.concurrent.ConcurrentMap; import org.apache.felix.dm.Component; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IOFInventoryService; +import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener; import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import org.opendaylight.controller.sal.core.Actions; +import org.opendaylight.controller.sal.core.Buffers; +import org.opendaylight.controller.sal.core.Capabilities; import org.opendaylight.controller.sal.core.ConstructionException; +import org.opendaylight.controller.sal.core.Description; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.Node.NodeIDType; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.TimeStamp; import org.opendaylight.controller.sal.core.Tables; -import org.opendaylight.controller.sal.core.Actions; -import org.opendaylight.controller.sal.core.Buffers; -import org.opendaylight.controller.sal.core.Capabilities; +import org.opendaylight.controller.sal.core.TimeStamp; import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.controller.sal.inventory.IPluginInInventoryService; import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService; import org.opendaylight.controller.sal.utils.GlobalConstants; +import org.openflow.protocol.statistics.OFDescriptionStatistics; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The class describes inventory service protocol plugin. One instance per @@ -51,7 +52,7 @@ import org.opendaylight.controller.sal.utils.GlobalConstants; * */ public class InventoryService implements IInventoryShimInternalListener, - IPluginInInventoryService, IOFInventoryService { + IPluginInInventoryService, IStatisticsListener { protected static final Logger logger = LoggerFactory .getLogger(InventoryService.class); private Set pluginOutInventoryServices = Collections @@ -224,31 +225,31 @@ public class InventoryService implements IInventoryShimInternalListener, + type.getName() + " for Node id " + nodeConnector.getNode().getID()); - if (nodeConnectorProps == null) + if (nodeConnectorProps == null) { return; + } + + + Map propMap = nodeConnectorProps + .get(nodeConnector); + switch (type) { + case ADDED: + case CHANGED: + if (propMap == null) + propMap = new HashMap(); - synchronized (nodeConnectorProps) { - Map propMap = nodeConnectorProps - .get(nodeConnector); - switch (type) { - case ADDED: - case CHANGED: - if (propMap == null) - propMap = new HashMap(); - - if (props != null) { - for (Property prop : props) { - propMap.put(prop.getName(), prop); - } + if (props != null) { + for (Property prop : props) { + propMap.put(prop.getName(), prop); } - nodeConnectorProps.put(nodeConnector, propMap); - break; - case REMOVED: - nodeConnectorProps.remove(nodeConnector); - break; - default: - return; } + nodeConnectorProps.put(nodeConnector, propMap); + break; + case REMOVED: + nodeConnectorProps.remove(nodeConnector); + break; + default: + return; } // update sal and discovery @@ -305,27 +306,33 @@ public class InventoryService implements IInventoryShimInternalListener, } } - /* - * Function called by other protocol plugin modules to notify Inventory Service - * that a property has changed for the specified switch - */ - @Override - public void updateSwitchProperty(Long switchId, Set propSet) { + + private void updateSwitchProperty(Long switchId, Set propSet) { // update local cache - Node node = OFSwitchToNode(controller.getSwitches().get(switchId)); + Node node = OFSwitchToNode(controller.getSwitch(switchId)); Map propMap = nodeProps.get(node); - if (propMap == null) + if (propMap == null) { propMap = new HashMap(); + } + + boolean change = false; for (Property prop : propSet) { - propMap.put(prop.getName(), prop); + String propertyName = prop.getName(); + Property currentProp = propMap.get(propertyName); + if (!prop.equals(currentProp)) { + change = true; + propMap.put(propertyName, prop); + } } nodeProps.put(node, propMap); - // update sal - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.CHANGED, propSet); - } + // Update sal if any of the properties has changed + if (change) { + synchronized (pluginOutInventoryServices) { + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + service.updateNode(node, UpdateType.CHANGED, propSet); + } + } } } @@ -342,4 +349,15 @@ public class InventoryService implements IInventoryShimInternalListener, break; } } + + @Override + public void descriptionRefreshed(Long switchId, + OFDescriptionStatistics descriptionStats) { + + Set propSet = new HashSet(1); + Description desc = + new Description(descriptionStats.getDatapathDescription()); + propSet.add(desc); + this.updateSwitchProperty(switchId, propSet); + } } diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java index cd05f3125a..8d157ac29f 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java @@ -20,35 +20,30 @@ import java.util.concurrent.CopyOnWriteArrayList; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager; import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitchStateListener; -import org.openflow.protocol.OFMessage; -import org.openflow.protocol.OFPortStatus; -import org.openflow.protocol.OFPortStatus.OFPortReason; -import org.openflow.protocol.OFType; -import org.openflow.protocol.statistics.OFDescriptionStatistics; -import org.openflow.protocol.statistics.OFStatistics; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import org.opendaylight.controller.sal.core.Actions; import org.opendaylight.controller.sal.core.Buffers; import org.opendaylight.controller.sal.core.Capabilities; import org.opendaylight.controller.sal.core.ConstructionException; import org.opendaylight.controller.sal.core.ContainerFlow; import org.opendaylight.controller.sal.core.IContainerListener; -import org.opendaylight.controller.sal.core.Name; import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.Tables; import org.opendaylight.controller.sal.core.Node.NodeIDType; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.Property; +import org.opendaylight.controller.sal.core.Tables; import org.opendaylight.controller.sal.core.TimeStamp; import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.controller.sal.utils.GlobalConstants; +import org.openflow.protocol.OFMessage; +import org.openflow.protocol.OFPortStatus; +import org.openflow.protocol.OFPortStatus.OFPortReason; +import org.openflow.protocol.OFType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The class describes a shim layer that bridges inventory events from Openflow @@ -65,7 +60,6 @@ public class InventoryServiceShim implements IContainerListener, private ConcurrentMap inventoryShimInternalListeners = new ConcurrentHashMap(); private List inventoryShimExternalListeners = new CopyOnWriteArrayList(); private ConcurrentMap> containerMap = new ConcurrentHashMap>(); - private IOFStatisticsManager statsMgr; void setController(IController s) { this.controller = s; @@ -77,16 +71,6 @@ public class InventoryServiceShim implements IContainerListener, } } - void setStatisticsManager(IOFStatisticsManager s) { - this.statsMgr = s; - } - - void unsetStatisticsManager(IOFStatisticsManager s) { - if (this.statsMgr == s) { - this.statsMgr = null; - } - } - void setInventoryShimInternalListener(Map props, IInventoryShimInternalListener s) { if (props == null) { @@ -99,7 +83,7 @@ public class InventoryServiceShim implements IContainerListener, return; } if ((this.inventoryShimInternalListeners != null) - && !this.inventoryShimInternalListeners.containsKey(s)) { + && !this.inventoryShimInternalListeners.containsValue(s)) { this.inventoryShimInternalListeners.put(containerName, s); logger.trace("Added inventoryShimInternalListener for container:" + containerName); @@ -118,7 +102,10 @@ public class InventoryServiceShim implements IContainerListener, return; } if ((this.inventoryShimInternalListeners != null) - && this.inventoryShimInternalListeners.containsKey(s)) { + && this.inventoryShimInternalListeners + .get(containerName) != null + && this.inventoryShimInternalListeners + .get(containerName).equals(s)) { this.inventoryShimInternalListeners.remove(containerName); logger .trace("Removed inventoryShimInternalListener for container: " @@ -390,16 +377,6 @@ public class InventoryServiceShim implements IContainerListener, .getTime(); props.add(new TimeStamp(connectedSinceTime, "connectedSince")); - String name = ""; - if (statsMgr != null && statsMgr.getOFDescStatistics(sid) != null) { - List stats = statsMgr.getOFDescStatistics(sid); - if (stats.size() > 0) { - name = ((OFDescriptionStatistics) stats.get(0)) - .getSerialNumber(); - } - } - props.add(new Name(name)); - byte tables = sw.getTables(); Tables t = new Tables(tables); if (t != null) { diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/OFStatisticsManager.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/OFStatisticsManager.java index bd31f8b7b3..bc61f3b071 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/OFStatisticsManager.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/OFStatisticsManager.java @@ -30,13 +30,18 @@ import java.util.concurrent.LinkedBlockingQueue; import org.eclipse.osgi.framework.console.CommandInterpreter; import org.eclipse.osgi.framework.console.CommandProvider; import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IOFInventoryService; import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager; +import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener; import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match; import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsReply; import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsRequest; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.controller.sal.core.Property; +import org.opendaylight.controller.sal.core.UpdateType; +import org.opendaylight.controller.sal.utils.HexEncode; import org.openflow.protocol.OFError; import org.openflow.protocol.OFMatch; import org.openflow.protocol.OFPort; @@ -57,22 +62,10 @@ import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.opendaylight.controller.sal.core.Name; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.opendaylight.controller.sal.utils.HexEncode; -import org.opendaylight.controller.sal.utils.ServiceHelper; - /** * It periodically polls the different OF statistics from the OF switches * and caches them for quick retrieval for the above layers' modules * It also provides an API to directly query the switch about the statistics - * - * - * */ public class OFStatisticsManager implements IOFStatisticsManager, IInventoryShimExternalListener, CommandProvider { @@ -82,7 +75,6 @@ public class OFStatisticsManager implements IOFStatisticsManager, private static final long flowStatsPeriod = 10000; private static final long descriptionStatsPeriod = 60000; private static final long portStatsPeriod = 5000; - private long statisticsTimeout = 4000; private static final long tickPeriod = 1000; private static short statisticsTickNumber = (short) (flowStatsPeriod / tickPeriod); private static short descriptionTickNumber = (short) (descriptionStatsPeriod / tickPeriod); @@ -102,8 +94,8 @@ public class OFStatisticsManager implements IOFStatisticsManager, private Timer statisticsTimer; private TimerTask statisticsTimerTask; private ConcurrentMap switchSupportsVendorExtStats; - private Map switchNamesDB; private Map> txRates; // Per port sampled (every portStatsPeriod) transmit rate + private Set descriptionListeners; /** * The object containing the latest factoredSamples tx rate samples @@ -166,54 +158,10 @@ public class OFStatisticsManager implements IOFStatisticsManager, * */ void init() { - } - - /** - * 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() { - } - - /** - * 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() { - // Start managed timers - statisticsTimer.scheduleAtFixedRate(statisticsTimerTask, 0, tickPeriod); - - // Start statistics collector thread - statisticsCollector.start(); - - // Start bandwidth utilization computer thread - txRatesUpdater.start(); - - // OSGI console - registerWithOSGIConsole(); - } - - /** - * 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() { - // Stop managed timers - statisticsTimer.cancel(); - } - - public OFStatisticsManager() { - flowStatistics = new ConcurrentHashMap>(); + flowStatistics = new ConcurrentHashMap>(); descStatistics = new ConcurrentHashMap>(); portStatistics = new ConcurrentHashMap>(); dummyList = new ArrayList(1); - switchNamesDB = new HashMap(); statisticsTimerTicks = new ConcurrentHashMap( initialSize); pendingStatsRequests = new LinkedBlockingQueue( @@ -222,6 +170,7 @@ public class OFStatisticsManager implements IOFStatisticsManager, switchSupportsVendorExtStats = new ConcurrentHashMap( initialSize); txRates = new HashMap>(initialSize); + descriptionListeners = new HashSet(); // Initialize managed timers statisticsTimer = new Timer(); @@ -239,11 +188,10 @@ public class OFStatisticsManager implements IOFStatisticsManager, while (true) { try { StatsRequest req = pendingStatsRequests.take(); - acquireStatistics(req.switchId, req.type, - statisticsTimeout); + acquireStatistics(req.switchId, req.type); } catch (InterruptedException e) { - log - .warn("Flow Statistics Collector thread interrupted"); + log.warn("Flow Statistics Collector thread " + + "interrupted"); } } } @@ -263,9 +211,58 @@ public class OFStatisticsManager implements IOFStatisticsManager, } } }, "TX Rate Updater"); + } + /** + * 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() { } + /** + * 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() { + // Start managed timers + statisticsTimer.scheduleAtFixedRate(statisticsTimerTask, 0, tickPeriod); + + // Start statistics collector thread + statisticsCollector.start(); + + // Start bandwidth utilization computer thread + txRatesUpdater.start(); + + // OSGI console + registerWithOSGIConsole(); + } + + /** + * 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() { + // Stop managed timers + statisticsTimer.cancel(); + } + + public void setStatisticsListener(IStatisticsListener s) { + this.descriptionListeners.add(s); + } + + public void unsetStatisticsListener(IStatisticsListener s) { + if (s != null) { + this.descriptionListeners.remove(s); + } + } + private void registerWithOSGIConsole() { BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()) .getBundleContext(); @@ -456,12 +453,11 @@ public class OFStatisticsManager implements IOFStatisticsManager, + HexString.toHexString(switchId)); } - private void acquireStatistics(Long switchId, OFStatisticsType statType, - long timeout) { + private void acquireStatistics(Long switchId, OFStatisticsType statType) { // Query the switch on all matches List values = this.acquireStatistics(switchId, statType, - null, timeout); + null); // Update local caching database if got a valid response if (values != null && !values.isEmpty()) { @@ -469,31 +465,10 @@ public class OFStatisticsManager implements IOFStatisticsManager, || (statType == OFStatisticsType.VENDOR)) { flowStatistics.put(switchId, values); } else if (statType == OFStatisticsType.DESC) { - if ((switchNamesDB != null) - && switchNamesDB.containsKey(switchId)) { - // Check if user manually configured a name for the switch - for (OFStatistics entry : values) { - OFDescriptionStatistics reply = (OFDescriptionStatistics) entry; - reply.setSerialNumber(switchNamesDB.get(switchId)); - } - } - // check if notification is needed - if (descStatistics.get(switchId) == null - || !(descStatistics.get(switchId).get(0).equals(values - .get(0)))) { - IOFInventoryService inventory = (IOFInventoryService) ServiceHelper - .getInstance(IOFInventoryService.class, - GlobalConstants.DEFAULT.toString(), this); - if (inventory != null) { - // Notify Inventory Service about the name update - Set propSet = new HashSet(1); - Name name = new Name(((OFDescriptionStatistics) values - .get(0)).getSerialNumber()); - propSet.add(name); - inventory.updateSwitchProperty(switchId, propSet); - } - } - // overwrite cache + // Notify who may be interested in a description change + notifyDescriptionListeners(switchId, values); + + // Overwrite cache descStatistics.put(switchId, values); } else if (statType == OFStatisticsType.PORT) { // Overwrite cache with new port statistics for this switch @@ -505,12 +480,20 @@ public class OFStatisticsManager implements IOFStatisticsManager, } } + private void notifyDescriptionListeners(Long switchId, + List values) { + for (IStatisticsListener l : this.descriptionListeners) { + l.descriptionRefreshed(switchId, + ((OFDescriptionStatistics)values.get(0))); + } + } + /* * Generic function to get the statistics form a OF switch */ @SuppressWarnings("unchecked") private List acquireStatistics(Long switchId, - OFStatisticsType statsType, Object target, long timeout) { + OFStatisticsType statsType, Object target) { List values = null; String type = null; ISwitch sw = controller.getSwitch(switchId); @@ -742,7 +725,7 @@ public class OFStatisticsManager implements IOFStatisticsManager, @Override public List queryStatistics(Long switchId, - OFStatisticsType statType, Object target, long timeout) { + OFStatisticsType statType, Object target) { /* * Caller does not know and it is not supposed to know whether * this switch supports vendor extension. We adjust the target for him @@ -754,7 +737,7 @@ public class OFStatisticsManager implements IOFStatisticsManager, } List list = this.acquireStatistics(switchId, statType, - target, timeout); + target); return (list == null) ? null : (statType == OFStatisticsType.VENDOR) ? v6StatsListToOFStatsList(list) @@ -877,17 +860,9 @@ public class OFStatisticsManager implements IOFStatisticsManager, @Override public String getHelp() { StringBuffer help = new StringBuffer(); - help.append("---OF Switch ID to Name Mapping---\n"); - help - .append("\t ofaddname - Add a switchId to name mapping entry\n"); - help - .append("\t ofdeletename - Delete a switchId from the mapping db\n"); - help.append("\t ofprintnames - Print the mapping db\n"); help.append("---OF Statistics Manager utilities---\n"); - help - .append("\t ofdumpstatsmgr - Print Internal Stats Mgr db\n"); - help - .append("\t ofstatstimeout - Change Statistics request's timeout value\n"); + help.append("\t ofdumpstatsmgr - " + + "Print Internal Stats Mgr db\n"); return help.toString(); } @@ -918,43 +893,6 @@ public class OFStatisticsManager implements IOFStatisticsManager, return Long.parseLong(switchString, radix); } - public void _ofaddname(CommandInterpreter ci) { - if (switchNamesDB == null) - switchNamesDB = new HashMap(); - String switchId = ci.nextArgument(); - if (!isValidSwitchId(switchId)) { - ci.println("Please provide a valid SwithcId"); - return; - } - Long sid = getSwitchIDLong(switchId); - String switchName = ci.nextArgument(); - if (switchName == null) { - ci.println("Please provide a valid Switch name"); - return; - } - switchNamesDB.put(sid, switchName); - } - - public void _ofdeletename(CommandInterpreter ci) { - if (switchNamesDB == null) - return; - String switchId = ci.nextArgument(); - if (!isValidSwitchId(switchId)) { - ci.println("Please provide a valid SwitchId"); - return; - } - Long sid = getSwitchIDLong(switchId); - switchNamesDB.remove(sid); - } - - public void _ofprintnames(CommandInterpreter ci) { - if (switchNamesDB == null) - return; - for (Long key : switchNamesDB.keySet()) { - ci.println(key + " -> " + switchNamesDB.get(key) + "\n"); - } - } - /* * Internal information dump code */ @@ -983,24 +921,6 @@ public class OFStatisticsManager implements IOFStatisticsManager, ci.println("Flow Stats Period: " + statisticsTickNumber + " s"); ci.println("Desc Stats Period: " + descriptionTickNumber + " s"); ci.println("Port Stats Period: " + portTickNumber + " s"); - ci.println("Stats request timeout: " + Float.valueOf(statisticsTimeout) - / 1000.0 + " s"); - } - - public void _ofstatstimeout(CommandInterpreter ci) { - String timeoutString = ci.nextArgument(); - if (timeoutString == null || !timeoutString.matches("^[0-9]+$")) { - ci.println("Invalid value. Has to be numeric."); - return; - } - - long newTimeout = Long.valueOf(timeoutString); - if (newTimeout < 50 || newTimeout > 60000) { - ci.println("Invalid value. Valid range is [50-60000]ms"); - return; - } - this.statisticsTimeout = newTimeout; - ci.println("New value: " + statisticsTimeout + " ms"); } public void _resetSwitchCapability(CommandInterpreter ci) { @@ -1053,10 +973,9 @@ public class OFStatisticsManager implements IOFStatisticsManager, String averageWindow = ci.nextArgument(); short seconds = 0; if (averageWindow == null) { - ci - .println("Insert the length in seconds of the average window for tx rate"); - ci - .println("Current: " + factoredSamples * portTickNumber + ci.println("Insert the length in seconds of the median " + + "window for tx rate"); + ci.println("Current: " + factoredSamples * portTickNumber + " secs"); return; } @@ -1065,8 +984,40 @@ public class OFStatisticsManager implements IOFStatisticsManager, } catch (NumberFormatException e) { ci.println("Invalid period."); } - OFStatisticsManager.factoredSamples = (short) (seconds / portTickNumber); + OFStatisticsManager.factoredSamples = (short) (seconds/portTickNumber); ci.println("New: " + factoredSamples * portTickNumber + " secs"); } + public void _ofstatsmgrintervals(CommandInterpreter ci) { + String flowStatsInterv = ci.nextArgument(); + String portStatsInterv = ci.nextArgument(); + + if (flowStatsInterv == null || portStatsInterv == null) { + + ci.println("Usage: ostatsmgrintervals (in seconds)"); + ci.println("Current Values: fP=" + statisticsTickNumber + + "s pP=" + portTickNumber + "s"); + return; + } + Short fP, pP; + try { + fP = Short.parseShort(flowStatsInterv); + pP = Short.parseShort(portStatsInterv); + } catch (Exception e) { + ci.println("Invalid format values: " + e.getMessage()); + return; + } + + if (pP <= 1 || fP <=1) { + ci.println("Invalid values. fP and pP have to be greater than 1."); + return; + } + + statisticsTickNumber = fP; + portTickNumber = pP; + + ci.println("New Values: fP=" + statisticsTickNumber + + "s pP=" + portTickNumber + "s"); + } + } diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java index 4301bfd6ef..1b71c3bec3 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java @@ -128,7 +128,7 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, OFMatch ofMatch = new FlowConverter(flow).getOFMatch(); List ofList = (cached == true) ? statsMgr .getOFFlowStatistics(sid, ofMatch) : statsMgr.queryStatistics( - sid, OFStatisticsType.FLOW, ofMatch, 6000); + sid, OFStatisticsType.FLOW, ofMatch); /* * Convert and filter the statistics per container @@ -149,7 +149,7 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, long sid = (Long) node.getID(); List ofList = (cached == true) ? statsMgr .getOFFlowStatistics(sid) : statsMgr.queryStatistics(sid, - OFStatisticsType.FLOW, null, 6000); + OFStatisticsType.FLOW, null); /* * Convert and filter the statistics per container @@ -174,7 +174,7 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, long sid = (Long) node.getID(); List ofList = (cached == true) ? statsMgr .getOFDescStatistics(sid) : statsMgr.queryStatistics(sid, - OFStatisticsType.DESC, null, 6000); + OFStatisticsType.DESC, null); return new DescStatisticsConverter(ofList).getHwDescription(); } @@ -382,7 +382,7 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, short portId = (Short) connector.getID(); List ofList = (cached == true) ? statsMgr .getOFPortStatistics(sid, portId) : statsMgr.queryStatistics( - sid, OFStatisticsType.PORT, portId, 6000); + sid, OFStatisticsType.PORT, portId); List ncStatistics = new PortStatisticsConverter( sid, ofList).getNodeConnectorStatsList(); @@ -397,7 +397,7 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, long sid = (Long) node.getID(); List ofList = (cached == true) ? statsMgr .getOFPortStatistics(sid) : statsMgr.queryStatistics(sid, - OFStatisticsType.FLOW, null, 6000); + OFStatisticsType.FLOW, null); List filteredList = filterPortListPerContainer( containerName, sid, ofList); diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServiceShim.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServiceShim.java index b62b068b81..5d0ee5dccb 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServiceShim.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServiceShim.java @@ -226,7 +226,7 @@ public class TopologyServiceShim implements IDiscoveryService, for (NodeConnector connector : globalContainerEdges.keySet()) { // Skip if node connector belongs to production switch - if (connector.getType() == NodeConnector.NodeConnectorIDType.PRODUCTION) { + if (connector.getType().equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) { continue; } @@ -326,7 +326,8 @@ public class TopologyServiceShim implements IDiscoveryService, return; } if ((this.topologyServiceShimListeners != null) - && !this.topologyServiceShimListeners.containsKey(s)) { + && !this.topologyServiceShimListeners + .containsKey(containerName)) { this.topologyServiceShimListeners.put(containerName, s); logger.trace("Added topologyServiceShimListener for container:" + containerName); @@ -345,7 +346,11 @@ public class TopologyServiceShim implements IDiscoveryService, return; } if ((this.topologyServiceShimListeners != null) - && this.topologyServiceShimListeners.containsKey(s)) { + && this.topologyServiceShimListeners + .containsKey(containerName) + && this.topologyServiceShimListeners + .get(containerName).equals(s) + ) { this.topologyServiceShimListeners.remove(containerName); logger.trace("Removed topologyServiceShimListener for container: " + containerName); diff --git a/opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java b/opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java index 77e6d95dc9..34cfd4b223 100644 --- a/opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java +++ b/opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java @@ -360,7 +360,6 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { updateTopo(e, (short) bw.getValue(), add); } if (this.routingAware != null) { - log.info("Invoking routingAware listeners"); for (IListenRoutingUpdates ra : this.routingAware) { try { ra.recalculateDone(); diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/ActionType.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/ActionType.java index 8582046fa9..6ff233b69a 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/ActionType.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/ActionType.java @@ -23,14 +23,14 @@ public enum ActionType { SW_PATH("software path", 0, 0), // OF Local HW_PATH("harware path", 0, 0), OUTPUT("output", 0, 0xffff), // physical port ENQUEUE("enqueue", 0, 0xffff), SET_DL_SRC("setDlSrc", 0, 0), SET_DL_DST( - "setDlDst", 0, 0), SET_VLAN_ID("setVlan", 2, 0xfff), SET_VLAN_PCP( + "setDlDst", 0, 0), SET_VLAN_ID("setVlan", 1, 0xfff), SET_VLAN_PCP( "setVlanPcp", 0, 0x7), SET_VLAN_CFI("setVlanCif", 0, 0x1), POP_VLAN( "stripVlan", 0, 0), // Pop PUSH_VLAN("pushVlan", 0, 0xffff), // Push (the max value only takes into account the TCI portion of the 802.1q header) SET_DL_TYPE("setDlType", 0, 0xffff), // Set ethertype/length field SET_NW_SRC("setNwSrc", 0, 0), SET_NW_DST("setNwDst", 0, 0), SET_NW_TOS( - "setNwTos", 0, 0xff), SET_TP_SRC("setTpSrc", 0, 0xffff), SET_TP_DST( - "setTpDst", 0, 0xffff), SET_NEXT_HOP("setNextHop", 0, 0); + "setNwTos", 0, 0xff), SET_TP_SRC("setTpSrc", 1, 0xffff), SET_TP_DST( + "setTpDst", 1, 0xffff), SET_NEXT_HOP("setNextHop", 0, 0); private String id; private int minValue; diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java new file mode 100644 index 0000000000..4233dcbb68 --- /dev/null +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java @@ -0,0 +1,54 @@ +package org.opendaylight.controller.sal.core; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +/** + * The class represents the Name property of an element. + */ +@XmlRootElement +@SuppressWarnings("serial") +public class Description extends Property { + @XmlElement + private String description; + public static final String propertyName = "description"; + + /* + * Private constructor used for JAXB mapping + */ + private Description() { + super(propertyName); + this.description = null; + } + + public Description(String description) { + super(propertyName); + this.description = description; + } + + public Description clone() { + return new Description(this.description); + } + + public String getValue() { + return this.description; + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + @Override + public boolean equals(Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } + + @Override + public String toString() { + return "Description[" + description + "]"; + } +} diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Name.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Name.java index 74617c7c5b..bf67ed8861 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Name.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Name.java @@ -18,8 +18,6 @@ import javax.xml.bind.annotation.XmlElement; /** * The class represents the Name property of an element. - * - * */ @XmlRootElement @SuppressWarnings("serial") diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java index b199e5ce72..f54a515576 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Node.java @@ -18,24 +18,20 @@ */ package org.opendaylight.controller.sal.core; -import java.util.concurrent.ConcurrentHashMap; -import java.util.Set; -import java.math.BigInteger; - import java.io.Serializable; -import java.lang.String; +import java.math.BigInteger; +import java.util.Set; import java.util.UUID; -import java.lang.Long; -import java.lang.Class; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.opendaylight.controller.sal.utils.HexEncode; +import java.util.concurrent.ConcurrentHashMap; -import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.opendaylight.controller.sal.utils.HexEncode; + /** * Describe a generic network element in multiple SDNs technologies. A * Node is identified by the pair (NodeType, NodeID), the nodetype are diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java index bbe952ddea..96e6cc7f10 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/NodeConnector.java @@ -18,20 +18,18 @@ */ package org.opendaylight.controller.sal.core; -import org.apache.commons.lang3.tuple.ImmutablePair; -import java.util.concurrent.ConcurrentHashMap; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; +import java.util.concurrent.ConcurrentHashMap; -import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.tuple.ImmutablePair; /** * Describe a generic network element attachment points, diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/flowprogrammer/Flow.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/flowprogrammer/Flow.java index 16c85a105a..f39de8f023 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/flowprogrammer/Flow.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/flowprogrammer/Flow.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.sal.flowprogrammer; +import java.io.Serializable; import java.net.Inet6Address; import java.util.ArrayList; import java.util.Iterator; @@ -35,8 +36,9 @@ import org.opendaylight.controller.sal.utils.EtherTypes; */ @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) -public class Flow implements Cloneable { - @XmlElement +public class Flow implements Cloneable, Serializable { + private static final long serialVersionUID = 1L; + @XmlElement private Match match; @XmlElement private List actions; diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/inventory/IListenInventoryUpdates.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/inventory/IListenInventoryUpdates.java index 7dbb5933b4..41b91e1919 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/inventory/IListenInventoryUpdates.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/inventory/IListenInventoryUpdates.java @@ -27,7 +27,7 @@ public interface IListenInventoryUpdates { * @param node {@link org.opendaylight.controller.sal.core.Node} being updated * @param type {@link org.opendaylight.controller.sal.core.UpdateType} * @param props set of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.Tier} etc. */ public void updateNode(Node node, UpdateType type, Set props); @@ -38,7 +38,7 @@ public interface IListenInventoryUpdates { * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector} being updated * @param type {@link org.opendaylight.controller.sal.core.UpdateType} * @param props set of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.State} etc. */ public void updateNodeConnector(NodeConnector nodeConnector, diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/inventory/IPluginOutInventoryService.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/inventory/IPluginOutInventoryService.java index 6fb9283755..124c34ab3e 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/inventory/IPluginOutInventoryService.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/inventory/IPluginOutInventoryService.java @@ -27,7 +27,7 @@ public interface IPluginOutInventoryService { * @param node {@link org.opendaylight.controller.sal.core.Node} being updated * @param type {@link org.opendaylight.controller.sal.core.UpdateType} * @param props set of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.Tier} etc. */ public void updateNode(Node node, UpdateType type, Set props); @@ -38,7 +38,7 @@ public interface IPluginOutInventoryService { * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector} being updated * @param type {@link org.opendaylight.controller.sal.core.UpdateType} * @param props set of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.State} etc. */ public void updateNodeConnector(NodeConnector nodeConnector, diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java index e376ba7a17..736314caed 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java @@ -9,12 +9,12 @@ package org.opendaylight.controller.sal.match; +import java.io.Serializable; import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -39,8 +39,9 @@ import org.opendaylight.controller.sal.utils.NetUtils; */ @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) -public class Match implements Cloneable { - private static final Map reversableMatches; +public class Match implements Cloneable, Serializable { + private static final long serialVersionUID = 1L; + private static final Map reversableMatches; static { Map map = new HashMap(); map.put(MatchType.DL_SRC, MatchType.DL_DST); diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchField.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchField.java index 08d4fa698f..12e772890e 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchField.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchField.java @@ -9,6 +9,8 @@ package org.opendaylight.controller.sal.match; +import java.io.Serializable; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -16,7 +18,6 @@ import javax.xml.bind.annotation.XmlRootElement; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.opendaylight.controller.sal.utils.HexEncode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,8 +29,9 @@ import org.slf4j.LoggerFactory; @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) -public class MatchField implements Cloneable { - private static final Logger logger = LoggerFactory +public class MatchField implements Cloneable, Serializable { + private static final long serialVersionUID = 1L; + private static final Logger logger = LoggerFactory .getLogger(MatchField.class); private MatchType type; // the field we want to match private Object value; // the value of the field we want to match diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchType.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchType.java index 8379f073dc..96ddbf47f4 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchType.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchType.java @@ -25,9 +25,9 @@ public enum MatchType { IN_PORT("inPort", 1 << 0, NodeConnector.class, 1, 0), DL_SRC("dlSrc", 1 << 1, Byte[].class, 0, 0xffffffffffffL), DL_DST("dlDst", 1 << 2, Byte[].class, 0, 0xffffffffffffL), - DL_VLAN("dlVlan", 1 << 3, Short.class, 2, 0xfff), // 2 bytes + DL_VLAN("dlVlan", 1 << 3, Short.class, 1, 0xfff), // 2 bytes DL_VLAN_PR("dlVlanPriority", 1 << 4, Byte.class, 0, 0x7), // 3 bits - DL_OUTER_VLAN("dlOuterVlan", 1 << 5, Short.class, 2, 0xfff), + DL_OUTER_VLAN("dlOuterVlan", 1 << 5, Short.class, 1, 0xfff), DL_OUTER_VLAN_PR("dlOuterVlanPriority", 1 << 6, Short.class, 0, 0x7), DL_TYPE("dlType", 1 << 7, Short.class, 0, 0xffff), // 2 bytes NW_TOS("nwTOS", 1 << 8, Byte.class, 0, 0xff), // 1 byte @@ -216,6 +216,8 @@ public enum MatchType { return ((Integer) (((Short)value).intValue() & 0x7FFF | 0x8000)).toString(); } break; + default: + break; } return value.toString(); } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeDescription.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeDescription.java index b68326707d..65efd3c29d 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeDescription.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeDescription.java @@ -9,20 +9,16 @@ package org.opendaylight.controller.sal.reader; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; /** - * Represents the switch description information - * - * - * + * Represents the network node description information */ public class NodeDescription { private String manufacturer; private String hardware; private String software; private String serialNumber; - private String sdnProtocolDescription; + private String description; public NodeDescription() { @@ -60,17 +56,18 @@ public class NodeDescription { this.serialNumber = serialNumber; } - public String getSdnProtocolDescription() { - return sdnProtocolDescription; + public String getDescription() { + return description; } - public void setSdnProtocolDescription(String sdnProtocolDescription) { - this.sdnProtocolDescription = sdnProtocolDescription; + public void setDescription(String description) { + this.description = description; } @Override public String toString() { - return "HwDescription[" + ReflectionToStringBuilder.toString(this) - + "]"; + return "HwDescription[manufacturer=" + manufacturer + ", hardware=" + + hardware + ", software=" + software + ", serialNumber=" + + serialNumber + ", description=" + description + "]"; } } diff --git a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java index cf0f022980..eeddc0b9b0 100644 --- a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java +++ b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java @@ -66,7 +66,7 @@ public class ActionTest { Assert.assertFalse(action.isValid()); action = new SetVlanId(1); - Assert.assertFalse(action.isValid()); + Assert.assertTrue(action.isValid()); action = new SetVlanId(4096); Assert.assertFalse(action.isValid()); @@ -184,7 +184,7 @@ public class ActionTest { Assert.assertTrue(action.isValid()); action = new SetTpDst(0); - Assert.assertTrue(action.isValid()); + Assert.assertFalse(action.isValid()); action = new SetTpSrc(-1); Assert.assertFalse(action.isValid()); diff --git a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/reader/NodeDescriptionTest.java b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/reader/NodeDescriptionTest.java index a78182ff09..a720bdf680 100644 --- a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/reader/NodeDescriptionTest.java +++ b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/reader/NodeDescriptionTest.java @@ -20,19 +20,19 @@ public class NodeDescriptionTest { NodeDescription ncDesc = new NodeDescription(); ncDesc.setHardware("Hardware1"); ncDesc.setManufacturer("Manufacturer1"); - ncDesc.setSdnProtocolDescription("SDNProtocol1"); + ncDesc.setDescription("SDNProtocol1"); ncDesc.setSerialNumber("serialNumber1"); ncDesc.setSoftware("Software1"); Assert.assertTrue(ncDesc.getHardware().equals("Hardware1")); Assert.assertTrue(ncDesc.getManufacturer().equals("Manufacturer1")); - Assert.assertTrue(ncDesc.getSdnProtocolDescription().equals("SDNProtocol1")); + Assert.assertTrue(ncDesc.getDescription().equals("SDNProtocol1")); Assert.assertTrue(ncDesc.getSerialNumber().equals("serialNumber1")); Assert.assertTrue(ncDesc.getSoftware().equals("Software1")); Assert.assertFalse(ncDesc.getHardware().equals("Hardware2")); Assert.assertFalse(ncDesc.getManufacturer().equals("Manufacturer2")); - Assert.assertFalse(ncDesc.getSdnProtocolDescription().equals("SDNProtocol2")); + Assert.assertFalse(ncDesc.getDescription().equals("SDNProtocol2")); Assert.assertFalse(ncDesc.getSerialNumber().equals("serialNumber2")); Assert.assertFalse(ncDesc.getSoftware().equals("Software2")); diff --git a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/IInventoryListener.java b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/IInventoryListener.java index 73e33762bb..e7b8c59dff 100644 --- a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/IInventoryListener.java +++ b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/IInventoryListener.java @@ -26,7 +26,7 @@ public interface IInventoryListener { * @param node {@link org.opendaylight.controller.sal.core.Node} being updated * @param type {@link org.opendaylight.controller.sal.core.UpdateType} * @param propMap map of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.Tier} etc. */ public void notifyNode(Node node, UpdateType type, @@ -38,7 +38,7 @@ public interface IInventoryListener { * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector} being updated * @param type {@link org.opendaylight.controller.sal.core.UpdateType} * @param propMap map of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.State} etc. */ public void notifyNodeConnector(NodeConnector nodeConnector, diff --git a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java index 15aeda3881..ddc5f8ffee 100755 --- a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java +++ b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java @@ -170,7 +170,7 @@ public interface ISwitchManager { * * @param node {@link org.opendaylight.controller.sal.core.Node} * @return map of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.Tier} etc. */ public Map getNodeProps(Node node); @@ -238,7 +238,7 @@ public interface ISwitchManager { * * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector} * @return map of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Name} and/or + * {@link org.opendaylight.controller.sal.core.Description} and/or * {@link org.opendaylight.controller.sal.core.State} etc. */ public Map getNodeConnectorProps( @@ -307,17 +307,6 @@ public interface ISwitchManager { */ public Boolean isNodeConnectorEnabled(NodeConnector nodeConnector); - /** - * Return the list of mapping "nodeId"/"nodeName" for each connected node. - * Each map contains two string keys: "nodeId", "nodeName". - * Value associated to "nodeId" is the node id in string hex format. - * Value associated to "nodeName" is the name of the node. If no name was set, - * it will be the node id in string hex format. - * - * @return list of map - */ - public List> getListNodeIdNameMap(); - /** * Return controller MAC address * @@ -358,4 +347,15 @@ public interface ISwitchManager { * @return {@link org.opendaylight.controller.sal.core.Property} */ public Property createProperty(String propName, String propValue); + + /** + * Returns the description for the specified node. It is either the one + * configured by user or the description advertised by the node. + * + * @param node the network node identifier + * @return the description of the specified node. If no description is + * configured and the network node does not provide its description, + * an empty string is returned. + */ + public String getNodeDescription(Node node); } diff --git a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/SubnetConfig.java b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/SubnetConfig.java index 3624dd7754..87dd99da7f 100644 --- a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/SubnetConfig.java +++ b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/SubnetConfig.java @@ -10,18 +10,19 @@ package org.opendaylight.controller.switchmanager; import java.io.Serializable; -import java.lang.reflect.Field; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.xml.bind.annotation.XmlRootElement; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.utils.GUIField; diff --git a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java index 758a99b8b0..ffb8ec042c 100644 --- a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java +++ b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java @@ -21,14 +21,14 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; public class SwitchConfig implements Serializable { private static final long serialVersionUID = 1L; String nodeId; - String nodeName; + String description; String tier; String mode; - public SwitchConfig(String nodeId, String nodeName, String tier, String mode) { + public SwitchConfig(String nodeId, String description, String tier, String mode) { super(); this.nodeId = nodeId; - this.nodeName = nodeName; + this.description = description; this.tier = tier; this.mode = mode; } @@ -37,8 +37,8 @@ public class SwitchConfig implements Serializable { return nodeId; } - public String getNodeName() { - return nodeName; + public String getNodeDescription() { + return description; } public String getTier() { diff --git a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java index d8180040e8..54508de6d2 100755 --- a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java +++ b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java @@ -41,6 +41,7 @@ import org.opendaylight.controller.clustering.services.IClusterServices; 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.Name; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; @@ -601,8 +602,8 @@ public class SwitchManagerImpl implements ISwitchManager, } else { propMap = new HashMap(); } - Property name = new Name(cfgObject.getNodeName()); - propMap.put(name.getName(), name); + 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); @@ -738,8 +739,8 @@ public class SwitchManagerImpl implements ISwitchManager, String nodeId = node.getNodeIDString(); for (SwitchConfig conf : nodeConfigList.values()) { if (conf.getNodeId().equals(nodeId)) { - Property name = new Name(conf.getNodeName()); - propMap.put(name.getName(), name); + Property description = new Description(conf.getNodeDescription()); + propMap.put(description.getName(), description); Property tier = new Tier(Integer.parseInt(conf.getTier())); propMap.put(tier.getName(), tier); proactiveForwarding = conf.isProactive(); @@ -1034,24 +1035,6 @@ public class SwitchManagerImpl implements ISwitchManager, return (propMap != null) ? propMap.get(propName) : null; } - @Override - public List> getListNodeIdNameMap() { - List> list = new ArrayList>(); - Set nset = this.nodeProps.keySet(); - if (nset == null) { - return list; - } - for (Node node : nset) { - Map map = new HashMap(2); - Name nodeName = (Name) getNodeProp(node, Name.NamePropName); - map.put("nodeId", node.toString()); - map.put("nodeName", ((nodeName == null) || nodeName.getValue() - .equals("")) ? node.toString() : nodeName.getValue()); - list.add(map); - } - return list; - } - private byte[] getHardwareMAC() { Enumeration nis; try { @@ -1470,9 +1453,9 @@ public class SwitchManagerImpl implements ISwitchManager, return; } for (Node node : nodeSet) { - Name name = ((Name) getNodeProp(node, Name.NamePropName)); + Description desc = ((Description) getNodeProp(node, Description.propertyName)); Tier tier = ((Tier) getNodeProp(node, Tier.TierPropName)); - String nodeName = (name == null) ? "" : name.getValue(); + String nodeName = (desc == null) ? "" : desc.getValue(); int tierNum = (tier == null) ? 0 : tier.getValue(); ci.println(node + " " + node.getType() + " " + nodeName + " " + tierNum); @@ -1762,8 +1745,8 @@ public class SwitchManagerImpl implements ISwitchManager, } try { - if (propName.equalsIgnoreCase(Name.NamePropName)) { - return new Name(propValue); + if (propName.equalsIgnoreCase(Description.propertyName)) { + return new Description(propValue); } else if (propName.equalsIgnoreCase(Tier.TierPropName)) { int tier = Integer.parseInt(propValue); return new Tier(tier); @@ -1779,4 +1762,21 @@ public class SwitchManagerImpl implements ISwitchManager, return null; } + + @Override + public String getNodeDescription(Node node) { + // Check first if user configured a name + SwitchConfig config = getSwitchConfig(node.getNodeIDString()); + if (config != null) { + String configuredDesc = config.getNodeDescription(); + if (configuredDesc != null && !configuredDesc.isEmpty()) { + return configuredDesc; + } + } + + // No name configured by user, get the node advertised name + Description desc = (Description) getNodeProp(node, Description.propertyName); + return (desc == null /*|| desc.getValue().equalsIgnoreCase("none")*/) ? + "" : desc.getValue(); + } } diff --git a/opendaylight/switchmanager/src/test/java/org/opendaylight/controller/switchmanager/SwitchTest.java b/opendaylight/switchmanager/src/test/java/org/opendaylight/controller/switchmanager/SwitchTest.java index 6b0a2589c7..1499f9e2ef 100644 --- a/opendaylight/switchmanager/src/test/java/org/opendaylight/controller/switchmanager/SwitchTest.java +++ b/opendaylight/switchmanager/src/test/java/org/opendaylight/controller/switchmanager/SwitchTest.java @@ -129,7 +129,7 @@ public class SwitchTest { Assert.assertNull(sc.getMode()); Assert.assertNull(sc.getNodeId()); Assert.assertNull(sc.getTier()); - Assert.assertNull(sc.getNodeName()); + Assert.assertNull(sc.getNodeDescription()); SwitchConfig sc3 = new SwitchConfig("123", "name", "tier", "mode"); SwitchConfig sc4 = new SwitchConfig("123", "name", "tier", "mode"); @@ -137,7 +137,7 @@ public class SwitchTest { Assert.assertTrue(sc3.equals(sc4)); Assert.assertTrue(sc3.getNodeId().equals("123")); - Assert.assertTrue(sc3.getNodeName().equals("name")); + Assert.assertTrue(sc3.getNodeDescription().equals("name")); Assert.assertTrue(sc3.getTier().equals("tier")); Assert.assertTrue(sc3.getMode().equals("mode")); } diff --git a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java index 77b3e13101..5be771af96 100644 --- a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java +++ b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java @@ -89,12 +89,11 @@ public class Devices implements IOneWeb { for (Switch device : switchManager.getNetworkDevices()) { HashMap nodeDatum = new HashMap(); Node node = device.getNode(); - SwitchConfig switchConfig = switchManager.getSwitchConfig(node.getNodeIDString()); Tier tier = (Tier) switchManager.getNodeProp(node, Tier.TierPropName); - String swName = switchConfig == null ? null : switchConfig.getNodeName(); + nodeDatum.put("containerName", containerName); - nodeDatum.put("nodeName", swName); + nodeDatum.put("nodeName", switchManager.getNodeDescription(node)); nodeDatum.put("nodeId", node.getNodeIDString()); int tierNumber = (tier == null) ? TierHelper.unknownTierNumber : tier.getValue(); @@ -442,7 +441,7 @@ public class Devices implements IOneWeb { config.put(name, config_data.get(name)); // Add switch name value (non-configuration field) config.put("nodeName", - getNodeName(config_data.get("nodeId"))); + getNodeDesc(config_data.get("nodeId"))); } config.put("json", config_json); spanConfigs.add(config); @@ -551,22 +550,19 @@ public class Devices implements IOneWeb { return resultBean; } - private String getNodeName(String nodeId) { - String nodeName = nodeId; + private String getNodeDesc(String nodeId) { ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - - Node node = Node.fromString(nodeId); + String description = ""; if (switchManager != null) { - SwitchConfig config = switchManager.getSwitchConfig(node - .getNodeIDString()); - if (config != null) { - nodeName = config.getNodeName(); - } + description = switchManager + .getNodeDescription(Node.fromString(nodeId)); } - return nodeName; + return (description.isEmpty() || description.equalsIgnoreCase("none"))? + nodeId : description; } + /** * Is the operation permitted for the given level * diff --git a/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java b/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java index 77470224fb..d75d14c623 100644 --- a/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java +++ b/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java @@ -21,6 +21,7 @@ import org.opendaylight.controller.sal.authorization.UserLevel; import org.opendaylight.controller.sal.core.Name; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; @@ -46,6 +47,7 @@ public class Flows implements IOneWeb { private static final String WEB_NAME = "Flows"; private static final String WEB_ID = "flows"; private static final short WEB_ORDER = 2; + private final String containerName = GlobalConstants.DEFAULT.toString(); public Flows() { ServiceHelper.registerGlobalService(IOneWeb.class, this, null); @@ -76,12 +78,12 @@ public class Flows implements IOneWeb { public Set> getFlows() { // fetch frm IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper - .getInstance(IForwardingRulesManager.class, "default", this); + .getInstance(IForwardingRulesManager.class, containerName, this); if (frm == null) { return null; } // fetch sm ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, "default", this); + .getInstance(ISwitchManager.class, containerName, this); if (switchManager == null) { return null; } // get static flow list @@ -91,12 +93,12 @@ public class Flows implements IOneWeb { Map entry = new HashMap(); entry.put("flow", flowConfig); entry.put("name", flowConfig.getName()); - - Node node = flowConfig.getNode(); - SwitchConfig switchConfig = switchManager.getSwitchConfig(node.getNodeIDString()); - String nodeName = node.toString(); - if (switchConfig != null) { nodeName = switchConfig.getNodeName(); } - entry.put("node", nodeName); + Node node = flowConfig.getNode(); + String description = switchManager.getNodeDescription(node); + entry.put("node", + (description.isEmpty() || + description.equalsIgnoreCase("none"))? + node.toString() : description); entry.put("nodeId", node.toString()); output.add(entry); } @@ -108,7 +110,7 @@ public class Flows implements IOneWeb { @ResponseBody public Map getNodePorts() { ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, "default", this); + .getInstance(ISwitchManager.class, containerName, this); if (switchManager == null) { return null; } Map nodes = new HashMap(); @@ -134,12 +136,11 @@ public class Flows implements IOneWeb { entry.put("ports", port); // add name - String nodeName = node.getNode().toString(); - SwitchConfig config = switchManager.getSwitchConfig(node.getNode().getNodeIDString()); - if (config != null) { - nodeName = config.getNodeName(); - } - entry.put("name", nodeName); + String description = switchManager + .getNodeDescription(node.getNode()); + entry.put("name", (description.isEmpty() || + description.equalsIgnoreCase("none"))? + node.getNode().toString() : description); // add to the node nodes.put(node.getNode().toString(), entry); @@ -152,7 +153,7 @@ public class Flows implements IOneWeb { @ResponseBody public Map getNodeFlows() { ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, "default", this); + .getInstance(ISwitchManager.class, containerName, this); if (switchManager == null) { return null; } IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper .getInstance(IForwardingRulesManager.class, "default", this); @@ -165,13 +166,13 @@ public class Flows implements IOneWeb { List flows = frm.getStaticFlows(node); - String nodeName = node.toString(); + String nodeDesc = node.toString(); SwitchConfig config = switchManager.getSwitchConfig(node.getNodeIDString()); if (config != null) { - nodeName = config.getNodeName(); + nodeDesc = config.getNodeDescription(); } - nodes.put(nodeName, flows.size()); + nodes.put(nodeDesc, flows.size()); } return nodes; @@ -186,7 +187,7 @@ public class Flows implements IOneWeb { } IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper - .getInstance(IForwardingRulesManager.class, "default", this); + .getInstance(IForwardingRulesManager.class, containerName, this); if (frm == null) { return null; } Gson gson = new Gson(); @@ -208,7 +209,7 @@ public class Flows implements IOneWeb { if (!isUserAuthorized(UserLevel.NETWORKADMIN)) { return "Operation not authorized"; } IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper - .getInstance(IForwardingRulesManager.class, "default", this); + .getInstance(IForwardingRulesManager.class, containerName, this); if (frm == null) { return null; } Status result = null; diff --git a/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java b/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java index aeffad241b..33669128f3 100644 --- a/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java +++ b/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java @@ -151,7 +151,7 @@ public class Topology { Map nodeEntry = cache.get(node.id()); if (config != null) { Map data = (Map) nodeEntry.get("data"); - data.put("$desc", config.getNodeName()); + data.put("$desc", config.getNodeDescription()); nodeEntry.put("data", data); } stage.put(node.id(), nodeEntry); @@ -164,7 +164,7 @@ public class Topology { protected NodeBean createNodeBean(SwitchConfig config, Node node) { NodeBean bean = null; if (config != null) { - bean = new NodeBean(node.toString(), config.getNodeName(), NodeType.NODE); + bean = new NodeBean(node.toString(), config.getNodeDescription(), NodeType.NODE); } else { bean = new NodeBean(node.toString(), node.toString(), NodeType.NODE); } @@ -183,7 +183,7 @@ public class Topology { Map nodeEntry = cache.get(node.id()); if (config != null) { Map data = (Map) nodeEntry.get("data"); - data.put("$desc", config.getNodeName()); + data.put("$desc", config.getNodeDescription()); nodeEntry.put("data", data); } stage.put(node.id(), nodeEntry); diff --git a/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java b/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java index e20c35abf1..c2d9614879 100644 --- a/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java +++ b/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java @@ -35,7 +35,6 @@ import org.opendaylight.controller.sal.utils.IPProtocols; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.controller.statisticsmanager.IStatisticsManager; import org.opendaylight.controller.switchmanager.ISwitchManager; -import org.opendaylight.controller.switchmanager.SwitchConfig; import org.opendaylight.controller.web.IOneWeb; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -85,15 +84,11 @@ public class Troubleshoot implements IOneWeb { Set nodeSet = null; if (switchManager != null) { nodeSet = switchManager.getNodes(); - } else { - // TODO: Change to use logger instead. - System.out.println("SwitchManager reference is NULL"); } if (nodeSet != null) { for (Node node : nodeSet) { HashMap device = new HashMap(); - SwitchConfig switchConfig = switchManager.getSwitchConfig(node.getNodeIDString()); - device.put("nodeName", switchConfig == null ? "" : switchConfig.getNodeName()); + device.put("nodeName", switchManager.getNodeDescription(node)); device.put("nodeId", node.toString()); lines.add(device); } @@ -101,7 +96,7 @@ public class Troubleshoot implements IOneWeb { TroubleshootingJsonBean result = new TroubleshootingJsonBean(); List guiFieldNames = new ArrayList(); - guiFieldNames.add("Node Names"); + guiFieldNames.add("Node"); guiFieldNames.add("Node ID"); guiFieldNames.add("Statistics"); @@ -119,15 +114,11 @@ public class Troubleshoot implements IOneWeb { Set nodeSet = null; if (switchManager != null) { nodeSet = switchManager.getNodes(); - } else { - // TODO: Change to use logger instead. - System.out.println("SwitchManager reference is NULL"); } if (nodeSet != null) { for (Node node : nodeSet) { HashMap device = new HashMap(); - SwitchConfig switchConfig = switchManager.getSwitchConfig(node.getNodeIDString()); - device.put("nodeName", switchConfig == null ? "" : switchConfig.getNodeName()); + device.put("nodeName", switchManager.getNodeDescription(node)); device.put("nodeId", node.toString()); TimeStamp timeStamp = (TimeStamp) switchManager.getNodeProp( node, TimeStamp.TimeStampPropName); @@ -140,7 +131,7 @@ public class Troubleshoot implements IOneWeb { TroubleshootingJsonBean result = new TroubleshootingJsonBean(); List guiFieldNames = new ArrayList(); - guiFieldNames.add("Node Names"); + guiFieldNames.add("Node"); guiFieldNames.add("Node ID"); guiFieldNames.add("Connected"); @@ -228,7 +219,13 @@ public class Troubleshoot implements IOneWeb { HashMap row = new HashMap(); Flow flow = flowOnNode.getFlow(); Match match = flow.getMatch(); - row.put("nodeName", getNodeName(node)); + ISwitchManager switchManager = (ISwitchManager) ServiceHelper + .getInstance(ISwitchManager.class, containerName, this); + String desc = (switchManager == null)? + "" : switchManager.getNodeDescription(node); + desc = (desc.isEmpty() || desc.equalsIgnoreCase("none"))? + node.toString(): desc; + row.put("nodeName", desc); if (match.isPresent(MatchType.IN_PORT)) { row.put(MatchType.IN_PORT.id(), ((NodeConnector) flow.getMatch() .getField(MatchType.IN_PORT).getValue()).getID().toString()); @@ -350,17 +347,4 @@ public class Troubleshoot implements IOneWeb { return row; } - private String getNodeName(Node node) { - String nodeName = ""; - ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, containerName, this); - if (switchManager != null) { - SwitchConfig config = switchManager.getSwitchConfig(node - .getNodeIDString()); - if (config != null) { - nodeName = config.getNodeName(); - } - } - return nodeName; - } } -- 2.36.6