Add 'TableStatistics' to SAL and Northbound Statistics API.
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / ReadService.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.protocol_plugin.openflow.internal;
11
12 import java.util.Dictionary;
13 import java.util.List;
14
15 import org.apache.felix.dm.Component;
16 import org.opendaylight.controller.protocol_plugin.openflow.IPluginReadServiceFilter;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
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.NodeConnectorStatistics;
28 import org.opendaylight.controller.sal.reader.NodeDescription;
29 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
30
31 /**
32  * Container Instance of IPluginInReadService implementation class
33  *
34  *
35  *
36  */
37 public class ReadService implements IPluginInReadService {
38     private static final Logger logger = LoggerFactory
39             .getLogger(ReadService.class);
40     private IPluginReadServiceFilter filter;
41     private String containerName;
42
43     /**
44      * Function called by the dependency manager when all the required
45      * dependencies are satisfied
46      *
47      */
48     @SuppressWarnings("unchecked")
49     void init(Component c) {
50         Dictionary<Object, Object> props = c.getServiceProperties();
51         containerName = (props != null) ? (String) props.get("containerName")
52                 : null;
53     }
54
55     /**
56      * Function called by the dependency manager when at least one
57      * dependency become unsatisfied or when the component is shutting
58      * down because for example bundle is being stopped.
59      *
60      */
61     void destroy() {
62     }
63
64     /**
65      * Function called by dependency manager after "init ()" is called
66      * and after the services provided by the class are registered in
67      * the service registry
68      *
69      */
70     void start() {
71     }
72
73     /**
74      * Function called by the dependency manager before the services
75      * exported by the component are unregistered, this will be
76      * followed by a "destroy ()" calls
77      *
78      */
79     void stop() {
80     }
81
82     public void setService(IPluginReadServiceFilter filter) {
83         this.filter = filter;
84     }
85
86     public void unsetService(IPluginReadServiceFilter filter) {
87         this.filter = null;
88     }
89
90     @Override
91     public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
92         if (!node.getType().equals(NodeIDType.OPENFLOW)) {
93             logger.error("Invalid node type");
94             return null;
95         }
96
97         return filter.readFlow(containerName, node, flow, cached);
98     }
99
100     @Override
101     public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
102         if (!node.getType().equals(NodeIDType.OPENFLOW)) {
103             logger.error("Invalid node type");
104             return null;
105         }
106
107         return filter.readAllFlow(containerName, node, cached);
108     }
109
110     @Override
111     public NodeDescription readDescription(Node node, boolean cached) {
112         if (!node.getType().equals(NodeIDType.OPENFLOW)) {
113             logger.error("Invalid node type");
114             return null;
115         }
116
117         return filter.readDescription(node, cached);
118     }
119
120     @Override
121     public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
122             boolean cached) {
123         if (!connector.getNode().getType()
124             .equals(NodeIDType.OPENFLOW)) {
125             logger.error("Invalid node type");
126             return null;
127         }
128         return filter.readNodeConnector(containerName, connector, cached);
129     }
130
131     @Override
132     public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
133             boolean cached) {
134         if (!node.getType().equals(NodeIDType.OPENFLOW)) {
135             logger.error("Invalid node type");
136             return null;
137         }
138
139         return filter.readAllNodeConnector(containerName, node, cached);
140     }
141
142     @Override
143     public long getTransmitRate(NodeConnector connector) {
144         if (!connector.getNode().getType()
145             .equals(NodeIDType.OPENFLOW)) {
146             logger.error("Invalid node type");
147             return 0;
148         }
149         return filter.getTransmitRate(containerName, connector);
150     }
151
152     @Override
153     public NodeTableStatistics readNodeTable(NodeTable table, boolean cached) {
154         if (!table.getNode().getType()
155                 .equals(NodeIDType.OPENFLOW)) {
156             logger.error("Invalid node type");
157             return null;
158         }
159         return filter.readNodeTable(containerName, table, cached);
160     }
161
162     @Override
163     public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
164         if (!node.getType().equals(NodeIDType.OPENFLOW)) {
165             logger.error("Invalid node type");
166             return null;
167         }
168
169         return filter.readAllNodeTable(containerName, node, cached);
170     }
171 }