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.core.Node;
21 import org.opendaylight.controller.sal.core.Node.NodeIDType;
22 import org.opendaylight.controller.sal.core.NodeConnector;
23 import org.opendaylight.controller.sal.core.NodeTable;
24 import org.opendaylight.controller.sal.flowprogrammer.Flow;
25 import org.opendaylight.controller.sal.reader.FlowOnNode;
26 import org.opendaylight.controller.sal.reader.IPluginInReadService;
27 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
28 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
29 import org.opendaylight.controller.sal.reader.NodeDescription;
30 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * Container Instance of IPluginInReadService implementation class
37 public class ReadService implements IPluginInReadService, IReadFilterInternalListener {
38 private static final Logger logger = LoggerFactory
39 .getLogger(ReadService.class);
40 private IReadServiceFilter filter;
41 private Set<IPluginOutReadService> pluginOutReadServices;
42 private String containerName;
45 * Function called by the dependency manager when all the required
46 * dependencies are satisfied
49 @SuppressWarnings("unchecked")
50 void init(Component c) {
51 Dictionary<Object, Object> props = c.getServiceProperties();
52 containerName = (props != null) ? (String) props.get("containerName")
54 pluginOutReadServices = new CopyOnWriteArraySet<IPluginOutReadService>();
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.
67 * Function called by dependency manager after "init ()" is called
68 * and after the services provided by the class are registered in
69 * the service registry
76 * Function called by the dependency manager before the services
77 * exported by the component are unregistered, this will be
78 * followed by a "destroy ()" calls
84 public void setService(IReadServiceFilter filter) {
88 public void unsetService(IReadServiceFilter filter) {
92 public void setPluginOutReadServices(IPluginOutReadService service) {
93 logger.trace("Got a service set request {}", service);
94 if (this.pluginOutReadServices != null) {
95 this.pluginOutReadServices.add(service);
99 public void unsetPluginOutReadServices(
100 IPluginOutReadService service) {
101 logger.trace("Got a service UNset request");
102 if (this.pluginOutReadServices != null) {
103 this.pluginOutReadServices.remove(service);
107 public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
108 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
109 logger.error("Invalid node type");
113 return filter.readFlow(containerName, node, flow, cached);
117 public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
118 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
119 logger.error("Invalid node type");
123 return filter.readAllFlow(containerName, node, cached);
127 public NodeDescription readDescription(Node node, boolean cached) {
128 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
129 logger.error("Invalid node type");
133 return filter.readDescription(node, cached);
137 public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
139 if (!connector.getNode().getType()
140 .equals(NodeIDType.OPENFLOW)) {
141 logger.error("Invalid node type");
144 return filter.readNodeConnector(containerName, connector, cached);
148 public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
150 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
151 logger.error("Invalid node type");
155 return filter.readAllNodeConnector(containerName, node, cached);
159 public long getTransmitRate(NodeConnector connector) {
160 if (!connector.getNode().getType()
161 .equals(NodeIDType.OPENFLOW)) {
162 logger.error("Invalid node type");
165 return filter.getTransmitRate(containerName, connector);
169 public NodeTableStatistics readNodeTable(NodeTable table, boolean cached) {
170 if (!table.getNode().getType()
171 .equals(NodeIDType.OPENFLOW)) {
172 logger.error("Invalid node type");
175 return filter.readNodeTable(containerName, table, cached);
179 public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
180 if (!node.getType().equals(NodeIDType.OPENFLOW)) {
181 logger.error("Invalid node type");
185 return filter.readAllNodeTable(containerName, node, cached);
189 public void nodeFlowStatisticsUpdated(Node node, List<FlowOnNode> flowStatsList) {
190 for (IPluginOutReadService service : pluginOutReadServices) {
191 service.nodeFlowStatisticsUpdated(node, flowStatsList);
196 public void nodeConnectorStatisticsUpdated(Node node, List<NodeConnectorStatistics> ncStatsList) {
197 for (IPluginOutReadService service : pluginOutReadServices) {
198 service.nodeConnectorStatisticsUpdated(node, ncStatsList);
203 public void nodeTableStatisticsUpdated(Node node, List<NodeTableStatistics> tableStatsList) {
204 for (IPluginOutReadService service : pluginOutReadServices) {
205 service.nodeTableStatisticsUpdated(node, tableStatsList);
210 public void nodeDescriptionStatisticsUpdated(Node node, NodeDescription nodeDescription) {
211 for (IPluginOutReadService service : pluginOutReadServices) {
212 service.descriptionStatisticsUpdated(node, nodeDescription);