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.Collections;
13 import java.util.Dictionary;
14 import java.util.List;
16 import java.util.concurrent.CopyOnWriteArraySet;
18 import org.apache.felix.dm.Component;
19 import org.opendaylight.controller.protocol_plugin.openflow.IReadFilterInternalListener;
20 import org.opendaylight.controller.protocol_plugin.openflow.IReadServiceFilter;
21 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
22 import org.opendaylight.controller.sal.core.Node;
23 import org.opendaylight.controller.sal.core.Node.NodeIDType;
24 import org.opendaylight.controller.sal.core.NodeConnector;
25 import org.opendaylight.controller.sal.core.NodeTable;
26 import org.opendaylight.controller.sal.flowprogrammer.Flow;
27 import org.opendaylight.controller.sal.reader.FlowOnNode;
28 import org.opendaylight.controller.sal.reader.IPluginInReadService;
29 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
30 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
31 import org.opendaylight.controller.sal.reader.NodeDescription;
32 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * Container Instance of IPluginInReadService implementation class
39 public class ReadService implements IPluginInReadService, IReadFilterInternalListener {
40 private static final Logger logger = LoggerFactory
41 .getLogger(ReadService.class);
42 private IReadServiceFilter filter;
43 private Set<IPluginOutReadService> pluginOutReadServices = new CopyOnWriteArraySet<IPluginOutReadService>();
44 private String containerName;
45 private IPluginOutConnectionService connectionOutService;
48 * Function called by the dependency manager when all the required
49 * dependencies are satisfied
52 @SuppressWarnings("unchecked")
53 void init(Component c) {
54 Dictionary<Object, Object> props = c.getServiceProperties();
55 containerName = (props != null) ? (String) props.get("containerName") : null;
59 * Function called by the dependency manager when at least one
60 * dependency become unsatisfied or when the component is shutting
61 * down because for example bundle is being stopped.
65 pluginOutReadServices.clear();
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");
126 return Collections.emptyList();
129 if (!connectionOutService.isLocal(node)) {
130 logger.debug("This Controller is not the master for the node : " + node);
131 return Collections.emptyList();
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");
174 return Collections.emptyList();
177 if (!connectionOutService.isLocal(node)) {
178 logger.debug("This Controller is not the master for node : " + node);
179 return Collections.emptyList();
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");
221 return Collections.emptyList();
224 if (!connectionOutService.isLocal(node)) {
225 logger.debug("This Controller is not the master for node : " + node);
226 return Collections.emptyList();
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;