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.openflowplugin.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.sal.connection.IPluginOutConnectionService;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.core.Node.NodeIDType;
21 import org.opendaylight.controller.sal.core.NodeConnector;
22 import org.opendaylight.controller.sal.core.NodeTable;
23 import org.opendaylight.controller.sal.flowprogrammer.Flow;
24 import org.opendaylight.controller.sal.reader.FlowOnNode;
25 import org.opendaylight.controller.sal.reader.IPluginInReadService;
26 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
27 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
28 import org.opendaylight.controller.sal.reader.NodeDescription;
29 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
30 import org.opendaylight.openflowplugin.openflow.IReadFilterInternalListener;
31 import org.opendaylight.openflowplugin.openflow.IReadServiceFilter;
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;
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")
56 pluginOutReadServices = new CopyOnWriteArraySet<IPluginOutReadService>();
60 * Function called by the dependency manager when at least one
61 * dependency become unsatisfied or when the component is shutting
62 * down because for example bundle is being stopped.
69 * Function called by dependency manager after "init ()" is called
70 * and after the services provided by the class are registered in
71 * the service registry
78 * Function called by the dependency manager before the services
79 * exported by the component are unregistered, this will be
80 * followed by a "destroy ()" calls
86 public void setService(IReadServiceFilter filter) {
90 public void unsetService(IReadServiceFilter filter) {
94 public void setPluginOutReadServices(IPluginOutReadService service) {
95 logger.trace("Got a service set request {}", service);
96 if (this.pluginOutReadServices != null) {
97 this.pluginOutReadServices.add(service);
101 public void unsetPluginOutReadServices(
102 IPluginOutReadService service) {
103 logger.trace("Got a service UNset request");
104 if (this.pluginOutReadServices != null) {
105 this.pluginOutReadServices.remove(service);
109 public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
110 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
111 logger.error("Invalid node type");
115 if (!connectionOutService.isLocal(node)) {
116 logger.debug("This Controller is not the master for the node : " + node);
119 return filter.readFlow(containerName, node, flow, cached);
123 public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
124 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
125 logger.error("Invalid node type");
129 if (!connectionOutService.isLocal(node)) {
130 logger.debug("This Controller is not the master for the node : " + node);
134 return filter.readAllFlow(containerName, node, cached);
138 public NodeDescription readDescription(Node node, boolean cached) {
139 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
140 logger.error("Invalid node type");
144 if (!connectionOutService.isLocal(node)) {
145 logger.debug("This Controller is not the master for the node : " + node);
149 return filter.readDescription(node, cached);
153 public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
155 if (!connector.getNode().getType()
156 .equals(NodeIDType.OPENFLOW)) {
157 logger.error("Invalid node type");
161 if (!connectionOutService.isLocal(connector.getNode())) {
162 logger.debug("This Controller is not the master for connector : "+connector);
166 return filter.readNodeConnector(containerName, connector, cached);
170 public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
172 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
173 logger.error("Invalid node type");
177 if (!connectionOutService.isLocal(node)) {
178 logger.debug("This Controller is not the master for node : " + node);
182 return filter.readAllNodeConnector(containerName, node, cached);
186 public long getTransmitRate(NodeConnector connector) {
187 if (!connector.getNode().getType()
188 .equals(NodeIDType.OPENFLOW)) {
189 logger.error("Invalid node type");
193 if (!connectionOutService.isLocal(connector.getNode())) {
194 logger.debug("This Controller is not the master for connector : "+connector);
198 return filter.getTransmitRate(containerName, connector);
202 public NodeTableStatistics readNodeTable(NodeTable table, boolean cached) {
203 if (!table.getNode().getType()
204 .equals(NodeIDType.OPENFLOW)) {
205 logger.error("Invalid node type");
209 if (!connectionOutService.isLocal(table.getNode())) {
210 logger.debug("This Controller is not the master for connector : "+table);
214 return filter.readNodeTable(containerName, table, cached);
218 public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
219 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
220 logger.error("Invalid node type");
224 if (!connectionOutService.isLocal(node)) {
225 logger.debug("This Controller is not the master for node : " + node);
229 return filter.readAllNodeTable(containerName, node, cached);
233 public void nodeFlowStatisticsUpdated(Node node, List<FlowOnNode> flowStatsList) {
234 if (!connectionOutService.isLocal(node)) {
235 logger.debug("This Controller is not the master for node : " + node);
238 for (IPluginOutReadService service : pluginOutReadServices) {
239 service.nodeFlowStatisticsUpdated(node, flowStatsList);
244 public void nodeConnectorStatisticsUpdated(Node node, List<NodeConnectorStatistics> ncStatsList) {
245 if (!connectionOutService.isLocal(node)) {
246 logger.debug("This Controller is not the master for node : " + node);
249 for (IPluginOutReadService service : pluginOutReadServices) {
250 service.nodeConnectorStatisticsUpdated(node, ncStatsList);
255 public void nodeTableStatisticsUpdated(Node node, List<NodeTableStatistics> tableStatsList) {
256 if (!connectionOutService.isLocal(node)) {
257 logger.debug("This Controller is not the master for node : " + node);
260 for (IPluginOutReadService service : pluginOutReadServices) {
261 service.nodeTableStatisticsUpdated(node, tableStatsList);
266 public void nodeDescriptionStatisticsUpdated(Node node, NodeDescription nodeDescription) {
267 if (!connectionOutService.isLocal(node)) {
268 logger.debug("This Controller is not the master for node : " + node);
271 for (IPluginOutReadService service : pluginOutReadServices) {
272 service.descriptionStatisticsUpdated(node, nodeDescription);
276 void setIPluginOutConnectionService(IPluginOutConnectionService s) {
277 connectionOutService = s;
280 void unsetIPluginOutConnectionService(IPluginOutConnectionService s) {
281 if (connectionOutService == s) {
282 connectionOutService = null;