3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.protocol_plugin.openflow.internal;
12 import java.util.Dictionary;
13 import java.util.List;
15 import java.util.concurrent.CopyOnWriteArraySet;
17 import org.apache.felix.dm.Component;
18 import org.opendaylight.controller.protocol_plugin.openflow.IReadFilterInternalListener;
19 import org.opendaylight.controller.protocol_plugin.openflow.IReadServiceFilter;
20 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
21 import org.opendaylight.controller.sal.core.Node;
22 import org.opendaylight.controller.sal.core.Node.NodeIDType;
23 import org.opendaylight.controller.sal.core.NodeConnector;
24 import org.opendaylight.controller.sal.core.NodeTable;
25 import org.opendaylight.controller.sal.flowprogrammer.Flow;
26 import org.opendaylight.controller.sal.reader.FlowOnNode;
27 import org.opendaylight.controller.sal.reader.IPluginInReadService;
28 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
29 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
30 import org.opendaylight.controller.sal.reader.NodeDescription;
31 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Container Instance of IPluginInReadService implementation class
38 public class ReadService implements IPluginInReadService, IReadFilterInternalListener {
39 private static final Logger logger = LoggerFactory
40 .getLogger(ReadService.class);
41 private IReadServiceFilter filter;
42 private Set<IPluginOutReadService> pluginOutReadServices = new CopyOnWriteArraySet<IPluginOutReadService>();
43 private String containerName;
44 private IPluginOutConnectionService connectionOutService;
47 * Function called by the dependency manager when all the required
48 * dependencies are satisfied
51 @SuppressWarnings("unchecked")
52 void init(Component c) {
53 Dictionary<Object, Object> props = c.getServiceProperties();
54 containerName = (props != null) ? (String) props.get("containerName") : null;
58 * Function called by the dependency manager when at least one
59 * dependency become unsatisfied or when the component is shutting
60 * down because for example bundle is being stopped.
64 pluginOutReadServices.clear();
68 * Function called by dependency manager after "init ()" is called
69 * and after the services provided by the class are registered in
70 * the service registry
77 * Function called by the dependency manager before the services
78 * exported by the component are unregistered, this will be
79 * followed by a "destroy ()" calls
85 public void setService(IReadServiceFilter filter) {
89 public void unsetService(IReadServiceFilter filter) {
93 public void setPluginOutReadServices(IPluginOutReadService service) {
94 logger.trace("Got a service set request {}", service);
95 if (this.pluginOutReadServices != null) {
96 this.pluginOutReadServices.add(service);
100 public void unsetPluginOutReadServices(
101 IPluginOutReadService service) {
102 logger.trace("Got a service UNset request");
103 if (this.pluginOutReadServices != null) {
104 this.pluginOutReadServices.remove(service);
108 public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
109 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
110 logger.error("Invalid node type");
114 if (!connectionOutService.isLocal(node)) {
115 logger.debug("This Controller is not the master for the node : " + node);
118 return filter.readFlow(containerName, node, flow, cached);
122 public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
123 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
124 logger.error("Invalid node type");
128 if (!connectionOutService.isLocal(node)) {
129 logger.debug("This Controller is not the master for the node : " + node);
133 return filter.readAllFlow(containerName, node, cached);
137 public NodeDescription readDescription(Node node, boolean cached) {
138 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
139 logger.error("Invalid node type");
143 if (!connectionOutService.isLocal(node)) {
144 logger.debug("This Controller is not the master for the node : " + node);
148 return filter.readDescription(node, cached);
152 public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
154 if (!connector.getNode().getType()
155 .equals(NodeIDType.OPENFLOW)) {
156 logger.error("Invalid node type");
160 if (!connectionOutService.isLocal(connector.getNode())) {
161 logger.debug("This Controller is not the master for connector : "+connector);
165 return filter.readNodeConnector(containerName, connector, cached);
169 public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
171 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
172 logger.error("Invalid node type");
176 if (!connectionOutService.isLocal(node)) {
177 logger.debug("This Controller is not the master for node : " + node);
181 return filter.readAllNodeConnector(containerName, node, cached);
185 public long getTransmitRate(NodeConnector connector) {
186 if (!connector.getNode().getType()
187 .equals(NodeIDType.OPENFLOW)) {
188 logger.error("Invalid node type");
192 if (!connectionOutService.isLocal(connector.getNode())) {
193 logger.debug("This Controller is not the master for connector : "+connector);
197 return filter.getTransmitRate(containerName, connector);
201 public NodeTableStatistics readNodeTable(NodeTable table, boolean cached) {
202 if (!table.getNode().getType()
203 .equals(NodeIDType.OPENFLOW)) {
204 logger.error("Invalid node type");
208 if (!connectionOutService.isLocal(table.getNode())) {
209 logger.debug("This Controller is not the master for connector : "+table);
213 return filter.readNodeTable(containerName, table, cached);
217 public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
218 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
219 logger.error("Invalid node type");
223 if (!connectionOutService.isLocal(node)) {
224 logger.debug("This Controller is not the master for node : " + node);
228 return filter.readAllNodeTable(containerName, node, cached);
232 public void nodeFlowStatisticsUpdated(Node node, List<FlowOnNode> flowStatsList) {
233 if (!connectionOutService.isLocal(node)) {
234 logger.debug("This Controller is not the master for node : " + node);
237 for (IPluginOutReadService service : pluginOutReadServices) {
238 service.nodeFlowStatisticsUpdated(node, flowStatsList);
243 public void nodeConnectorStatisticsUpdated(Node node, List<NodeConnectorStatistics> ncStatsList) {
244 if (!connectionOutService.isLocal(node)) {
245 logger.debug("This Controller is not the master for node : " + node);
248 for (IPluginOutReadService service : pluginOutReadServices) {
249 service.nodeConnectorStatisticsUpdated(node, ncStatsList);
254 public void nodeTableStatisticsUpdated(Node node, List<NodeTableStatistics> tableStatsList) {
255 if (!connectionOutService.isLocal(node)) {
256 logger.debug("This Controller is not the master for node : " + node);
259 for (IPluginOutReadService service : pluginOutReadServices) {
260 service.nodeTableStatisticsUpdated(node, tableStatsList);
265 public void nodeDescriptionStatisticsUpdated(Node node, NodeDescription nodeDescription) {
266 if (!connectionOutService.isLocal(node)) {
267 logger.debug("This Controller is not the master for node : " + node);
270 for (IPluginOutReadService service : pluginOutReadServices) {
271 service.descriptionStatisticsUpdated(node, nodeDescription);
275 void setIPluginOutConnectionService(IPluginOutConnectionService s) {
276 connectionOutService = s;
279 void unsetIPluginOutConnectionService(IPluginOutConnectionService s) {
280 if (connectionOutService == s) {
281 connectionOutService = null;