package org.opendaylight.controller.sal.implementation.internal;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArraySet;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
import org.opendaylight.controller.sal.action.PopVlan;
import org.opendaylight.controller.sal.core.ConstructionException;
import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeTable;
-import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.Node.NodeIDType;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.NodeTable;
import org.opendaylight.controller.sal.flowprogrammer.Flow;
import org.opendaylight.controller.sal.match.Match;
import org.opendaylight.controller.sal.match.MatchType;
import org.opendaylight.controller.sal.reader.FlowOnNode;
import org.opendaylight.controller.sal.reader.IPluginInReadService;
+import org.opendaylight.controller.sal.reader.IPluginOutReadService;
import org.opendaylight.controller.sal.reader.IReadService;
+import org.opendaylight.controller.sal.reader.IReadServiceListener;
import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
import org.opendaylight.controller.sal.reader.NodeDescription;
import org.opendaylight.controller.sal.reader.NodeTableStatistics;
import org.slf4j.LoggerFactory;
/**
- * The SAL Read Service. It dispatches the read request to
- * the proper SDN protocol plugin
- *
- *
- *
+ * The SAL Read Service. Dispatches read requests to the proper SDN protocol
+ * plugin, and notifies any listeners on updates from any plugin readers
*/
-public class ReadService implements IReadService, CommandProvider {
+public class ReadService implements IReadService, CommandProvider, IPluginOutReadService {
- protected static final Logger logger = LoggerFactory
- .getLogger(ReadService.class);
- private ConcurrentHashMap<String, IPluginInReadService>
- pluginReader =
- new ConcurrentHashMap<String, IPluginInReadService>();
+ protected static final Logger logger = LoggerFactory.getLogger(ReadService.class);
+ private ConcurrentHashMap<String, IPluginInReadService> pluginReader;
+ private Set<IReadServiceListener> readerListeners;
/**
* Function called by the dependency manager when all the required
*
*/
void init() {
+ pluginReader = new ConcurrentHashMap<String, IPluginInReadService>();
+ readerListeners = new CopyOnWriteArraySet<IReadServiceListener>();
}
/**
}
// Set the reference to the plugin flow Reader service
- public void setService(Map props, IPluginInReadService s) {
+ public void setService(Map<?, ?> props, IPluginInReadService s) {
if (this.pluginReader == null) {
logger.error("pluginReader store null");
return;
logger.trace("Got a service set request {}", s);
String type = null;
for (Object e : props.entrySet()) {
- Map.Entry entry = (Map.Entry) e;
+ Map.Entry<?, ?> entry = (Map.Entry<?, ?>) e;
logger.trace("Prop key:({}) value:({})", entry.getKey(),
entry.getValue());
}
}
}
- public void unsetService(Map props, IPluginInReadService s) {
+ public void unsetService(Map<?, ?> props, IPluginInReadService s) {
if (this.pluginReader == null) {
logger.error("pluginReader store null");
return;
String type = null;
logger.debug("Received unsetpluginReader request");
for (Object e : props.entrySet()) {
- Map.Entry entry = (Map.Entry) e;
+ Map.Entry<?, ?> entry = (Map.Entry<?, ?>) e;
logger.trace("Prop key:({}) value:({})", entry.getKey(),
entry.getValue());
}
logger.debug("Removed the pluginReader for type: {}", type);
}
}
+ public void setReaderListener(IReadServiceListener service) {
+ logger.trace("Got a listener set request {}", service);
+ this.readerListeners.add(service);
+ }
+
+ public void unsetReaderListener(IReadServiceListener service) {
+ logger.trace("Got a listener Unset request");
+ this.readerListeners.remove(service);
+ }
@Override
public FlowOnNode readFlow(Node node, Flow flow) {
.readFlow(node, flow, true);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readFlow(node, flow, false);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readAllFlow(node, true);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readAllFlow(node, false);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readDescription(node, true);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readDescription(node, false);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readNodeConnector(connector, true);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readNodeConnector(connector, false);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readAllNodeConnector(node, true);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readAllNodeTable(node, true);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readNodeTable(table, false);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readNodeTable(table, true);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.readAllNodeConnector(node, false);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return null;
}
.getTransmitRate(connector);
}
}
- logger.warn("Plugin unavailable");
+ logger.warn("Plugin {} unavailable", node.getType());
return 0;
}
+ @Override
+ public void nodeFlowStatisticsUpdated(Node node, List<FlowOnNode> flowStatsList) {
+ for (IReadServiceListener l : readerListeners){
+ l.nodeFlowStatisticsUpdated(node, flowStatsList);
+ }
+ }
+
+ @Override
+ public void nodeConnectorStatisticsUpdated(Node node, List<NodeConnectorStatistics> ncStatsList) {
+ for (IReadServiceListener l : readerListeners){
+ l.nodeConnectorStatisticsUpdated(node, ncStatsList);
+ }
+ }
+
+ @Override
+ public void nodeTableStatisticsUpdated(Node node, List<NodeTableStatistics> tableStatsList) {
+ for (IReadServiceListener l : readerListeners){
+ l.nodeTableStatisticsUpdated(node, tableStatsList);
+ }
+ }
+
+ @Override
+ public void descriptionStatisticsUpdated(Node node, NodeDescription nodeDescription) {
+ for (IReadServiceListener l : readerListeners){
+ l.descriptionStatisticsUpdated(node, nodeDescription);
+ }
+ }
+
// ---------------- OSGI TEST CODE ------------------------------//
private void registerWithOSGIConsole() {
actions.add(new Controller());
return new Flow(match, actions);
}
-
}