Move stats caching to FM StatisticsManager
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / Activator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.protocol_plugin.openflow.internal;
10
11 import java.util.Dictionary;
12 import java.util.Hashtable;
13
14 import org.apache.felix.dm.Component;
15 import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketListen;
16 import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketMux;
17 import org.opendaylight.controller.protocol_plugin.openflow.IDiscoveryListener;
18 import org.opendaylight.controller.protocol_plugin.openflow.IFlowProgrammerNotifier;
19 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryProvider;
20 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener;
21 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener;
22 import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsListener;
23 import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager;
24 import org.opendaylight.controller.protocol_plugin.openflow.IReadFilterInternalListener;
25 import org.opendaylight.controller.protocol_plugin.openflow.IReadServiceFilter;
26 import org.opendaylight.controller.protocol_plugin.openflow.IRefreshInternalProvider;
27 import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener;
28 import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
29 import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener;
30 import org.opendaylight.controller.protocol_plugin.openflow.core.internal.Controller;
31 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
32 import org.opendaylight.controller.sal.core.IContainerListener;
33 import org.opendaylight.controller.sal.core.Node;
34 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
35 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
36 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
37 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
38 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
39 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
40 import org.opendaylight.controller.sal.reader.IPluginInReadService;
41 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
42 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
43 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
44 import org.opendaylight.controller.sal.utils.GlobalConstants;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 /**
49  * Openflow protocol plugin Activator
50  *
51  *
52  */
53 public class Activator extends ComponentActivatorAbstractBase {
54     protected static final Logger logger = LoggerFactory
55             .getLogger(Activator.class);
56
57     /**
58      * Function called when the activator starts just after some initializations
59      * are done by the ComponentActivatorAbstractBase.
60      *
61      */
62     public void init() {
63     }
64
65     /**
66      * Function called when the activator stops just before the cleanup done by
67      * ComponentActivatorAbstractBase
68      *
69      */
70     public void destroy() {
71     }
72
73     /**
74      * Function that is used to communicate to dependency manager the list of
75      * known implementations for services inside a container
76      *
77      *
78      * @return An array containing all the CLASS objects that will be
79      *         instantiated in order to get an fully working implementation
80      *         Object
81      */
82     public Object[] getImplementations() {
83         Object[] res = { TopologyServices.class, DataPacketServices.class,
84                 InventoryService.class, ReadService.class,
85                 FlowProgrammerNotifier.class };
86         return res;
87     }
88
89     /**
90      * Function that is called when configuration of the dependencies is
91      * required.
92      *
93      * @param c
94      *            dependency manager Component object, used for configuring the
95      *            dependencies exported and imported
96      * @param imp
97      *            Implementation class that is being configured, needed as long
98      *            as the same routine can configure multiple implementations
99      * @param containerName
100      *            The containerName being configured, this allow also optional
101      *            per-container different behavior if needed, usually should not
102      *            be the case though.
103      */
104     public void configureInstance(Component c, Object imp, String containerName) {
105         if (imp.equals(TopologyServices.class)) {
106             // export the service to be used by SAL
107             c.setInterface(
108                     new String[] { IPluginInTopologyService.class.getName(),
109                             ITopologyServiceShimListener.class.getName() }, null);
110             // Hook the services coming in from SAL, as optional in
111             // case SAL is not yet there, could happen
112             c.add(createContainerServiceDependency(containerName)
113                     .setService(IPluginOutTopologyService.class)
114                     .setCallbacks("setPluginOutTopologyService",
115                             "unsetPluginOutTopologyService").setRequired(false));
116             c.add(createServiceDependency()
117                     .setService(IRefreshInternalProvider.class)
118                     .setCallbacks("setRefreshInternalProvider",
119                             "unsetRefreshInternalProvider").setRequired(false));
120         }
121
122         if (imp.equals(InventoryService.class)) {
123             // export the service
124             c.setInterface(
125                     new String[] {
126                             IPluginInInventoryService.class.getName(),
127                             IInventoryShimInternalListener.class.getName(),
128                             IInventoryProvider.class.getName() }, null);
129
130             // Now lets add a service dependency to make sure the
131             // provider of service exists
132             c.add(createServiceDependency()
133                     .setService(IController.class, "(name=Controller)")
134                     .setCallbacks("setController", "unsetController")
135                     .setRequired(true));
136             c.add(createContainerServiceDependency(containerName)
137                     .setService(IPluginOutInventoryService.class)
138                     .setCallbacks("setPluginOutInventoryServices",
139                             "unsetPluginOutInventoryServices")
140                     .setRequired(false));
141         }
142
143         if (imp.equals(DataPacketServices.class)) {
144             // export the service to be used by SAL
145             Dictionary<String, Object> props = new Hashtable<String, Object>();
146             // Set the protocolPluginType property which will be used
147             // by SAL
148             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
149             c.setInterface(IPluginInDataPacketService.class.getName(), props);
150             // Hook the services coming in from SAL, as optional in
151             // case SAL is not yet there, could happen
152             c.add(createServiceDependency()
153                     .setService(IController.class, "(name=Controller)")
154                     .setCallbacks("setController", "unsetController")
155                     .setRequired(true));
156             // This is required for the transmission to happen properly
157             c.add(createServiceDependency().setService(IDataPacketMux.class)
158                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
159                     .setRequired(true));
160             c.add(createContainerServiceDependency(containerName)
161                     .setService(IPluginOutDataPacketService.class)
162                     .setCallbacks("setPluginOutDataPacketService",
163                             "unsetPluginOutDataPacketService")
164                     .setRequired(false));
165         }
166
167         if (imp.equals(ReadService.class)) {
168             // export the service to be used by SAL
169             Dictionary<String, Object> props = new Hashtable<String, Object>();
170             // Set the protocolPluginType property which will be used
171             // by SAL
172             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
173             c.setInterface(new String[] {
174                     IReadFilterInternalListener.class.getName(),
175                     IPluginInReadService.class.getName() }, props);
176
177             c.add(createServiceDependency()
178                     .setService(IReadServiceFilter.class)
179                     .setCallbacks("setService", "unsetService")
180                     .setRequired(true));
181             c.add(createContainerServiceDependency(containerName)
182                     .setService(IPluginOutReadService.class)
183                     .setCallbacks("setPluginOutReadServices",
184                             "unsetPluginOutReadServices")
185                     .setRequired(false));
186         }
187
188         if (imp.equals(FlowProgrammerNotifier.class)) {
189             // export the service to be used by SAL
190             Dictionary<String, Object> props = new Hashtable<String, Object>();
191             // Set the protocolPluginType property which will be used
192             // by SAL
193             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
194             c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
195
196             c.add(createContainerServiceDependency(containerName)
197                     .setService(IPluginOutFlowProgrammerService.class)
198                     .setCallbacks("setPluginOutFlowProgrammerService",
199                             "unsetPluginOutFlowProgrammerService")
200                     .setRequired(true));
201         }
202     }
203
204     /**
205      * Function that is used to communicate to dependency manager the list of
206      * known implementations for services that are container independent.
207      *
208      *
209      * @return An array containing all the CLASS objects that will be
210      *         instantiated in order to get an fully working implementation
211      *         Object
212      */
213     public Object[] getGlobalImplementations() {
214         Object[] res = { Controller.class, OFStatisticsManager.class,
215                 FlowProgrammerService.class, ReadServiceFilter.class,
216                 DiscoveryService.class, DataPacketMuxDemux.class,
217                 InventoryServiceShim.class, TopologyServiceShim.class };
218         return res;
219     }
220
221     /**
222      * Function that is called when configuration of the dependencies is
223      * required.
224      *
225      * @param c
226      *            dependency manager Component object, used for configuring the
227      *            dependencies exported and imported
228      * @param imp
229      *            Implementation class that is being configured, needed as long
230      *            as the same routine can configure multiple implementations
231      */
232     public void configureGlobalInstance(Component c, Object imp) {
233
234         if (imp.equals(Controller.class)) {
235             logger.debug("Activator configureGlobalInstance( ) is called");
236             Dictionary<String, Object> props = new Hashtable<String, Object>();
237             props.put("name", "Controller");
238             c.setInterface(IController.class.getName(), props);
239         }
240
241         if (imp.equals(FlowProgrammerService.class)) {
242             // export the service to be used by SAL
243             Dictionary<String, Object> props = new Hashtable<String, Object>();
244             // Set the protocolPluginType property which will be used
245             // by SAL
246             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
247             c.setInterface(
248                     new String[] {
249                             IPluginInFlowProgrammerService.class.getName(),
250                             IMessageListener.class.getName(),
251                             IContainerListener.class.getName(),
252                             IInventoryShimExternalListener.class.getName() },
253                             props);
254
255             c.add(createServiceDependency()
256                     .setService(IController.class, "(name=Controller)")
257                     .setCallbacks("setController", "unsetController")
258                     .setRequired(true));
259
260             c.add(createServiceDependency()
261                     .setService(IFlowProgrammerNotifier.class)
262                     .setCallbacks("setFlowProgrammerNotifier",
263                             "unsetsetFlowProgrammerNotifier")
264                     .setRequired(false));
265
266         }
267
268         if (imp.equals(ReadServiceFilter.class)) {
269
270             c.setInterface(new String[] {
271                     IReadServiceFilter.class.getName(),
272                     IContainerListener.class.getName(),
273                     IOFStatisticsListener.class.getName() }, null);
274
275             c.add(createServiceDependency()
276                     .setService(IController.class, "(name=Controller)")
277                     .setCallbacks("setController", "unsetController")
278                     .setRequired(true));
279             c.add(createServiceDependency()
280                     .setService(IOFStatisticsManager.class)
281                     .setCallbacks("setService", "unsetService")
282                     .setRequired(true));
283             c.add(createServiceDependency()
284                     .setService(IReadFilterInternalListener.class)
285                     .setCallbacks("setReadFilterInternalListener",
286                             "unsetReadFilterInternalListener")
287                     .setRequired(false));
288
289         }
290
291         if (imp.equals(OFStatisticsManager.class)) {
292
293             c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
294                     IInventoryShimExternalListener.class.getName() }, null);
295
296             c.add(createServiceDependency()
297                     .setService(IController.class, "(name=Controller)")
298                     .setCallbacks("setController", "unsetController")
299                     .setRequired(true));
300             c.add(createServiceDependency()
301                     .setService(IOFStatisticsListener.class)
302                     .setCallbacks("setStatisticsListener",
303                             "unsetStatisticsListener").setRequired(false));
304         }
305
306         if (imp.equals(DiscoveryService.class)) {
307             // export the service
308             c.setInterface(
309                     new String[] {
310                             IInventoryShimExternalListener.class.getName(),
311                             IDataPacketListen.class.getName(),
312                             IContainerListener.class.getName() }, null);
313
314             c.add(createServiceDependency()
315                     .setService(IController.class, "(name=Controller)")
316                     .setCallbacks("setController", "unsetController")
317                     .setRequired(true));
318             c.add(createContainerServiceDependency(
319                     GlobalConstants.DEFAULT.toString())
320                     .setService(IInventoryProvider.class)
321                     .setCallbacks("setInventoryProvider",
322                     "unsetInventoryProvider").setRequired(true));
323             c.add(createServiceDependency().setService(IDataPacketMux.class)
324                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
325                     .setRequired(true));
326             c.add(createServiceDependency()
327                     .setService(IDiscoveryListener.class)
328                     .setCallbacks("setDiscoveryListener",
329                             "unsetDiscoveryListener").setRequired(true));
330         }
331
332         // DataPacket mux/demux services, which is teh actual engine
333         // doing the packet switching
334         if (imp.equals(DataPacketMuxDemux.class)) {
335             c.setInterface(new String[] { IDataPacketMux.class.getName(),
336                     IContainerListener.class.getName(),
337                     IInventoryShimExternalListener.class.getName() }, null);
338
339             c.add(createServiceDependency()
340                     .setService(IController.class, "(name=Controller)")
341                     .setCallbacks("setController", "unsetController")
342                     .setRequired(true));
343             c.add(createServiceDependency()
344                     .setService(IPluginOutDataPacketService.class)
345                     .setCallbacks("setPluginOutDataPacketService",
346                             "unsetPluginOutDataPacketService")
347                     .setRequired(false));
348             // See if there is any local packet dispatcher
349             c.add(createServiceDependency()
350                     .setService(IDataPacketListen.class)
351                     .setCallbacks("setIDataPacketListen",
352                             "unsetIDataPacketListen").setRequired(false));
353         }
354
355         if (imp.equals(InventoryServiceShim.class)) {
356             c.setInterface(new String[] { IContainerListener.class.getName(),
357                     IOFStatisticsListener.class.getName()}, null);
358
359             c.add(createServiceDependency()
360                     .setService(IController.class, "(name=Controller)")
361                     .setCallbacks("setController", "unsetController")
362                     .setRequired(true));
363             c.add(createServiceDependency()
364                     .setService(IInventoryShimInternalListener.class)
365                     .setCallbacks("setInventoryShimInternalListener",
366                             "unsetInventoryShimInternalListener")
367                     .setRequired(true));
368             c.add(createServiceDependency()
369                     .setService(IInventoryShimExternalListener.class)
370                     .setCallbacks("setInventoryShimExternalListener",
371                             "unsetInventoryShimExternalListener")
372                     .setRequired(false));
373         }
374
375         if (imp.equals(TopologyServiceShim.class)) {
376             c.setInterface(new String[] { IDiscoveryListener.class.getName(),
377                     IContainerListener.class.getName(),
378                     IRefreshInternalProvider.class.getName(),
379                     IInventoryShimExternalListener.class.getName() }, null);
380           c.add(createServiceDependency()
381                     .setService(ITopologyServiceShimListener.class)
382                     .setCallbacks("setTopologyServiceShimListener",
383                             "unsetTopologyServiceShimListener")
384                     .setRequired(true));
385             c.add(createServiceDependency()
386                     .setService(IOFStatisticsManager.class)
387                     .setCallbacks("setStatisticsManager",
388                             "unsetStatisticsManager").setRequired(false));
389         }
390     }
391 }