* @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<Property> props);
* @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,
+++ /dev/null
-
-/*
- * 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<Property> propertySet);
-}
* @return the list of openflow statistics
*/
List<OFStatistics> queryStatistics(Long switchId,
- OFStatisticsType statType, Object target, long timeout);
+ OFStatisticsType statType, Object target);
/**
* Returns the averaged transmit rate for the passed switch port
--- /dev/null
+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);
+}
package org.opendaylight.controller.protocol_plugin.openflow.internal;
-import org.opendaylight.controller.sal.core.IContainerListener;
import java.util.Dictionary;
import java.util.Hashtable;
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;
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
// 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
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)) {
IInventoryShimExternalListener.class).setCallbacks(
"setInventoryShimExternalListener",
"unsetInventoryShimExternalListener").setRequired(false));
- c.add(createServiceDependency().setService(
- IOFStatisticsManager.class).setCallbacks(
- "setStatisticsManager", "unsetStatisticsManager")
- .setRequired(false));
}
if (imp.equals(TopologyServiceShim.class)) {
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;
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
*
*/
public class InventoryService implements IInventoryShimInternalListener,
- IPluginInInventoryService, IOFInventoryService {
+ IPluginInInventoryService, IStatisticsListener {
protected static final Logger logger = LoggerFactory
.getLogger(InventoryService.class);
private Set<IPluginOutInventoryService> pluginOutInventoryServices = Collections
+ type.getName() + " for Node id "
+ nodeConnector.getNode().getID());
- if (nodeConnectorProps == null)
+ if (nodeConnectorProps == null) {
return;
+ }
+
+
+ Map<String, Property> propMap = nodeConnectorProps
+ .get(nodeConnector);
+ switch (type) {
+ case ADDED:
+ case CHANGED:
+ if (propMap == null)
+ propMap = new HashMap<String, Property>();
- synchronized (nodeConnectorProps) {
- Map<String, Property> propMap = nodeConnectorProps
- .get(nodeConnector);
- switch (type) {
- case ADDED:
- case CHANGED:
- if (propMap == null)
- propMap = new HashMap<String, Property>();
-
- 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
}
}
- /*
- * 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<Property> propSet) {
+
+ private void updateSwitchProperty(Long switchId, Set<Property> propSet) {
// update local cache
- Node node = OFSwitchToNode(controller.getSwitches().get(switchId));
+ Node node = OFSwitchToNode(controller.getSwitch(switchId));
Map<String, Property> propMap = nodeProps.get(node);
- if (propMap == null)
+ if (propMap == null) {
propMap = new HashMap<String, Property>();
+ }
+
+ 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);
+ }
+ }
}
}
break;
}
}
+
+ @Override
+ public void descriptionRefreshed(Long switchId,
+ OFDescriptionStatistics descriptionStats) {
+
+ Set<Property> propSet = new HashSet<Property>(1);
+ Description desc =
+ new Description(descriptionStats.getDatapathDescription());
+ propSet.add(desc);
+ this.updateSwitchProperty(switchId, propSet);
+ }
}
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
private ConcurrentMap<String, IInventoryShimInternalListener> inventoryShimInternalListeners = new ConcurrentHashMap<String, IInventoryShimInternalListener>();
private List<IInventoryShimExternalListener> inventoryShimExternalListeners = new CopyOnWriteArrayList<IInventoryShimExternalListener>();
private ConcurrentMap<NodeConnector, List<String>> containerMap = new ConcurrentHashMap<NodeConnector, List<String>>();
- private IOFStatisticsManager statsMgr;
void setController(IController s) {
this.controller = s;
}
}
- 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) {
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);
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: "
.getTime();
props.add(new TimeStamp(connectedSinceTime, "connectedSince"));
- String name = "";
- if (statsMgr != null && statsMgr.getOFDescStatistics(sid) != null) {
- List<OFStatistics> 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) {
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;
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 {
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);
private Timer statisticsTimer;
private TimerTask statisticsTimerTask;
private ConcurrentMap<Long, Boolean> switchSupportsVendorExtStats;
- private Map<Long, String> switchNamesDB;
private Map<Long, Map<Short, TxRates>> txRates; // Per port sampled (every portStatsPeriod) transmit rate
+ private Set<IStatisticsListener> descriptionListeners;
/**
* The object containing the latest factoredSamples tx rate samples
*
*/
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<Long, List<OFStatistics>>();
+ flowStatistics = new ConcurrentHashMap<Long, List<OFStatistics>>();
descStatistics = new ConcurrentHashMap<Long, List<OFStatistics>>();
portStatistics = new ConcurrentHashMap<Long, List<OFStatistics>>();
dummyList = new ArrayList<OFStatistics>(1);
- switchNamesDB = new HashMap<Long, String>();
statisticsTimerTicks = new ConcurrentHashMap<Long, StatisticsTicks>(
initialSize);
pendingStatsRequests = new LinkedBlockingQueue<StatsRequest>(
switchSupportsVendorExtStats = new ConcurrentHashMap<Long, Boolean>(
initialSize);
txRates = new HashMap<Long, Map<Short, TxRates>>(initialSize);
+ descriptionListeners = new HashSet<IStatisticsListener>();
// Initialize managed timers
statisticsTimer = new Timer();
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");
}
}
}
}
}
}, "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();
+ 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<OFStatistics> values = this.acquireStatistics(switchId, statType,
- null, timeout);
+ null);
// Update local caching database if got a valid response
if (values != null && !values.isEmpty()) {
|| (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<Property> propSet = new HashSet<Property>(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
}
}
+ private void notifyDescriptionListeners(Long switchId,
+ List<OFStatistics> 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<OFStatistics> acquireStatistics(Long switchId,
- OFStatisticsType statsType, Object target, long timeout) {
+ OFStatisticsType statsType, Object target) {
List<OFStatistics> values = null;
String type = null;
ISwitch sw = controller.getSwitch(switchId);
@Override
public List<OFStatistics> 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
}
List<OFStatistics> list = this.acquireStatistics(switchId, statType,
- target, timeout);
+ target);
return (list == null) ? null
: (statType == OFStatisticsType.VENDOR) ? v6StatsListToOFStatsList(list)
@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();
}
return Long.parseLong(switchString, radix);
}
- public void _ofaddname(CommandInterpreter ci) {
- if (switchNamesDB == null)
- switchNamesDB = new HashMap<Long, String>();
- 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
*/
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) {
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;
}
} 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 <fP> <pP> (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");
+ }
+
}
OFMatch ofMatch = new FlowConverter(flow).getOFMatch();
List<OFStatistics> 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
long sid = (Long) node.getID();
List<OFStatistics> ofList = (cached == true) ? statsMgr
.getOFFlowStatistics(sid) : statsMgr.queryStatistics(sid,
- OFStatisticsType.FLOW, null, 6000);
+ OFStatisticsType.FLOW, null);
/*
* Convert and filter the statistics per container
long sid = (Long) node.getID();
List<OFStatistics> ofList = (cached == true) ? statsMgr
.getOFDescStatistics(sid) : statsMgr.queryStatistics(sid,
- OFStatisticsType.DESC, null, 6000);
+ OFStatisticsType.DESC, null);
return new DescStatisticsConverter(ofList).getHwDescription();
}
short portId = (Short) connector.getID();
List<OFStatistics> ofList = (cached == true) ? statsMgr
.getOFPortStatistics(sid, portId) : statsMgr.queryStatistics(
- sid, OFStatisticsType.PORT, portId, 6000);
+ sid, OFStatisticsType.PORT, portId);
List<NodeConnectorStatistics> ncStatistics = new PortStatisticsConverter(
sid, ofList).getNodeConnectorStatsList();
long sid = (Long) node.getID();
List<OFStatistics> ofList = (cached == true) ? statsMgr
.getOFPortStatistics(sid) : statsMgr.queryStatistics(sid,
- OFStatisticsType.FLOW, null, 6000);
+ OFStatisticsType.FLOW, null);
List<OFStatistics> filteredList = filterPortListPerContainer(
containerName, sid, ofList);
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;
}
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);
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);
updateTopo(e, (short) bw.getValue(), add);
}
if (this.routingAware != null) {
- log.info("Invoking routingAware listeners");
for (IListenRoutingUpdates ra : this.routingAware) {
try {
ra.recalculateDone();
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;
--- /dev/null
+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 + "]";
+ }
+}
/**
* The class represents the Name property of an element.
- *
- *
*/
@XmlRootElement
@SuppressWarnings("serial")
*/
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
*/
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,
package org.opendaylight.controller.sal.flowprogrammer;
+import java.io.Serializable;
import java.net.Inet6Address;
import java.util.ArrayList;
import java.util.Iterator;
*/
@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<Action> actions;
* @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<Property> props);
* @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,
* @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<Property> props);
* @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,
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;
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
-public class Match implements Cloneable {
- private static final Map<MatchType, MatchType> reversableMatches;
+public class Match implements Cloneable, Serializable {
+ private static final long serialVersionUID = 1L;
+ private static final Map<MatchType, MatchType> reversableMatches;
static {
Map<MatchType, MatchType> map = new HashMap<MatchType, MatchType>();
map.put(MatchType.DL_SRC, MatchType.DL_DST);
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;
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;
@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
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
return ((Integer) (((Short)value).intValue() & 0x7FFF | 0x8000)).toString();
}
break;
+ default:
+ break;
}
return value.toString();
}
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() {
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 + "]";
}
}
Assert.assertFalse(action.isValid());
action = new SetVlanId(1);
- Assert.assertFalse(action.isValid());
+ Assert.assertTrue(action.isValid());
action = new SetVlanId(4096);
Assert.assertFalse(action.isValid());
Assert.assertTrue(action.isValid());
action = new SetTpDst(0);
- Assert.assertTrue(action.isValid());
+ Assert.assertFalse(action.isValid());
action = new SetTpSrc(-1);
Assert.assertFalse(action.isValid());
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"));
* @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,
* @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,
*
* @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<String, Property> getNodeProps(Node node);
*
* @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<String, Property> getNodeConnectorProps(
*/
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<Map<String, String>> getListNodeIdNameMap();
-
/**
* Return controller MAC address
*
* @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);
}
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;
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;
}
return nodeId;
}
- public String getNodeName() {
- return nodeName;
+ public String getNodeDescription() {
+ return description;
}
public String getTier() {
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;
} else {
propMap = new HashMap<String, Property>();
}
- 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);
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();
return (propMap != null) ? propMap.get(propName) : null;
}
- @Override
- public List<Map<String, String>> getListNodeIdNameMap() {
- List<Map<String, String>> list = new ArrayList<Map<String, String>>();
- Set<Node> nset = this.nodeProps.keySet();
- if (nset == null) {
- return list;
- }
- for (Node node : nset) {
- Map<String, String> map = new HashMap<String, String>(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<NetworkInterface> nis;
try {
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);
}
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);
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();
+ }
}
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");
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"));
}
for (Switch device : switchManager.getNetworkDevices()) {
HashMap<String, String> nodeDatum = new HashMap<String, String>();
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();
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);
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
*
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;
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);
public Set<Map<String, Object>> 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
Map<String, Object> entry = new HashMap<String, Object>();
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);
}
@ResponseBody
public Map<String, Object> getNodePorts() {
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, "default", this);
+ .getInstance(ISwitchManager.class, containerName, this);
if (switchManager == null) { return null; }
Map<String, Object> nodes = new HashMap<String, Object>();
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);
@ResponseBody
public Map<String, Object> 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);
List<FlowConfig> 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;
}
IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
- .getInstance(IForwardingRulesManager.class, "default", this);
+ .getInstance(IForwardingRulesManager.class, containerName, this);
if (frm == null) { return null; }
Gson gson = new Gson();
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;
Map<String, Object> nodeEntry = cache.get(node.id());
if (config != null) {
Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
- data.put("$desc", config.getNodeName());
+ data.put("$desc", config.getNodeDescription());
nodeEntry.put("data", data);
}
stage.put(node.id(), nodeEntry);
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);
}
Map<String, Object> nodeEntry = cache.get(node.id());
if (config != null) {
Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
- data.put("$desc", config.getNodeName());
+ data.put("$desc", config.getNodeDescription());
nodeEntry.put("data", data);
}
stage.put(node.id(), nodeEntry);
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;
Set<Node> 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<String, String> device = new HashMap<String, String>();
- 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);
}
TroubleshootingJsonBean result = new TroubleshootingJsonBean();
List<String> guiFieldNames = new ArrayList<String>();
- guiFieldNames.add("Node Names");
+ guiFieldNames.add("Node");
guiFieldNames.add("Node ID");
guiFieldNames.add("Statistics");
Set<Node> 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<String, String> device = new HashMap<String, String>();
- 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);
TroubleshootingJsonBean result = new TroubleshootingJsonBean();
List<String> guiFieldNames = new ArrayList<String>();
- guiFieldNames.add("Node Names");
+ guiFieldNames.add("Node");
guiFieldNames.add("Node ID");
guiFieldNames.add("Connected");
HashMap<String, String> row = new HashMap<String, String>();
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());
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;
- }
}