OpenDaylight Controller functional modules.
[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.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.NodeConnectorStatistics;
27 import org.opendaylight.controller.sal.reader.NodeDescription;
28
29 /**
30  * Container Instance of IPluginInReadService implementation class
31  *
32  *
33  *
34  */
35 public class ReadService implements IPluginInReadService {
36     private static final Logger logger = LoggerFactory
37             .getLogger(ReadService.class);
38     private IPluginReadServiceFilter filter;
39     private String containerName;
40
41     /**
42      * Function called by the dependency manager when all the required
43      * dependencies are satisfied
44      *
45      */
46     @SuppressWarnings("unchecked")
47     void init(Component c) {
48         Dictionary<Object, Object> props = c.getServiceProperties();
49         containerName = (props != null) ? (String) props.get("containerName")
50                 : null;
51     }
52
53     /**
54      * Function called by the dependency manager when at least one
55      * dependency become unsatisfied or when the component is shutting
56      * down because for example bundle is being stopped.
57      *
58      */
59     void destroy() {
60     }
61
62     /**
63      * Function called by dependency manager after "init ()" is called
64      * and after the services provided by the class are registered in
65      * the service registry
66      *
67      */
68     void start() {
69     }
70
71     /**
72      * Function called by the dependency manager before the services
73      * exported by the component are unregistered, this will be
74      * followed by a "destroy ()" calls
75      *
76      */
77     void stop() {
78     }
79
80     public void setService(IPluginReadServiceFilter filter) {
81         this.filter = filter;
82     }
83
84     public void unsetService(IPluginReadServiceFilter filter) {
85         this.filter = null;
86     }
87
88     @Override
89     public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
90         if (!node.getType().equals(NodeIDType.OPENFLOW)) {
91             logger.error("Invalid node type");
92             return null;
93         }
94
95         return filter.readFlow(containerName, node, flow, cached);
96     }
97
98     @Override
99     public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
100         if (!node.getType().equals(NodeIDType.OPENFLOW)) {
101             logger.error("Invalid node type");
102             return null;
103         }
104
105         return filter.readAllFlow(containerName, node, cached);
106     }
107
108     @Override
109     public NodeDescription readDescription(Node node, boolean cached) {
110         if (!node.getType().equals(NodeIDType.OPENFLOW)) {
111             logger.error("Invalid node type");
112             return null;
113         }
114
115         return filter.readDescription(node, cached);
116     }
117
118     @Override
119     public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
120             boolean cached) {
121         if (!connector.getNode().getType()
122             .equals(NodeIDType.OPENFLOW)) {
123             logger.error("Invalid node type");
124             return null;
125         }
126         return filter.readNodeConnector(containerName, connector, cached);
127     }
128
129     @Override
130     public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
131             boolean cached) {
132         if (!node.getType().equals(NodeIDType.OPENFLOW)) {
133             logger.error("Invalid node type");
134             return null;
135         }
136
137         return filter.readAllNodeConnector(containerName, node, cached);
138     }
139
140     @Override
141     public long getTransmitRate(NodeConnector connector) {
142         if (!connector.getNode().getType()
143             .equals(NodeIDType.OPENFLOW)) {
144             logger.error("Invalid node type");
145             return 0;
146         }
147         return filter.getTransmitRate(containerName, connector);
148     }
149 }