Merge "OF plugin classes must have a strict dependency on Connection Service"
[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.connection.IPluginInConnectionService;
32 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
33 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
34 import org.opendaylight.controller.sal.core.IContainerListener;
35 import org.opendaylight.controller.sal.core.Node;
36 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
37 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
38 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
39 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
40 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
41 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
42 import org.opendaylight.controller.sal.reader.IPluginInReadService;
43 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
44 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
45 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
46 import org.opendaylight.controller.sal.utils.GlobalConstants;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49
50 /**
51  * Openflow protocol plugin Activator
52  *
53  *
54  */
55 public class Activator extends ComponentActivatorAbstractBase {
56     protected static final Logger logger = LoggerFactory
57             .getLogger(Activator.class);
58
59     /**
60      * Function called when the activator starts just after some initializations
61      * are done by the ComponentActivatorAbstractBase.
62      *
63      */
64     @Override
65     public void init() {
66     }
67
68     /**
69      * Function called when the activator stops just before the cleanup done by
70      * ComponentActivatorAbstractBase
71      *
72      */
73     @Override
74     public void destroy() {
75     }
76
77     /**
78      * Function that is used to communicate to dependency manager the list of
79      * known implementations for services inside a container
80      *
81      *
82      * @return An array containing all the CLASS objects that will be
83      *         instantiated in order to get an fully working implementation
84      *         Object
85      */
86     @Override
87     public Object[] getImplementations() {
88         Object[] res = { TopologyServices.class, DataPacketServices.class,
89                 InventoryService.class, ReadService.class,
90                 FlowProgrammerNotifier.class };
91         return res;
92     }
93
94     /**
95      * Function that is called when configuration of the dependencies is
96      * required.
97      *
98      * @param c
99      *            dependency manager Component object, used for configuring the
100      *            dependencies exported and imported
101      * @param imp
102      *            Implementation class that is being configured, needed as long
103      *            as the same routine can configure multiple implementations
104      * @param containerName
105      *            The containerName being configured, this allow also optional
106      *            per-container different behavior if needed, usually should not
107      *            be the case though.
108      */
109     @Override
110     public void configureInstance(Component c, Object imp, String containerName) {
111         if (imp.equals(TopologyServices.class)) {
112             // export the service to be used by SAL
113             c.setInterface(
114                     new String[] { IPluginInTopologyService.class.getName(),
115                             ITopologyServiceShimListener.class.getName() }, null);
116             // Hook the services coming in from SAL, as optional in
117             // case SAL is not yet there, could happen
118             c.add(createContainerServiceDependency(containerName)
119                     .setService(IPluginOutTopologyService.class)
120                     .setCallbacks("setPluginOutTopologyService",
121                             "unsetPluginOutTopologyService").setRequired(false));
122             c.add(createServiceDependency()
123                     .setService(IRefreshInternalProvider.class)
124                     .setCallbacks("setRefreshInternalProvider",
125                             "unsetRefreshInternalProvider").setRequired(false));
126         }
127
128         if (imp.equals(InventoryService.class)) {
129             // export the service
130             c.setInterface(
131                     new String[] {
132                             IPluginInInventoryService.class.getName(),
133                             IInventoryShimInternalListener.class.getName(),
134                             IInventoryProvider.class.getName() }, null);
135
136             // Now lets add a service dependency to make sure the
137             // provider of service exists
138             c.add(createServiceDependency()
139                     .setService(IController.class, "(name=Controller)")
140                     .setCallbacks("setController", "unsetController")
141                     .setRequired(true));
142             c.add(createContainerServiceDependency(containerName)
143                     .setService(IPluginOutInventoryService.class)
144                     .setCallbacks("setPluginOutInventoryServices",
145                             "unsetPluginOutInventoryServices")
146                     .setRequired(false));
147         }
148
149         if (imp.equals(DataPacketServices.class)) {
150             // export the service to be used by SAL
151             Dictionary<String, Object> props = new Hashtable<String, Object>();
152             // Set the protocolPluginType property which will be used
153             // by SAL
154             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
155             c.setInterface(IPluginInDataPacketService.class.getName(), props);
156             // Hook the services coming in from SAL, as optional in
157             // case SAL is not yet there, could happen
158             c.add(createServiceDependency()
159                     .setService(IController.class, "(name=Controller)")
160                     .setCallbacks("setController", "unsetController")
161                     .setRequired(true));
162             // This is required for the transmission to happen properly
163             c.add(createServiceDependency().setService(IDataPacketMux.class)
164                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
165                     .setRequired(true));
166             c.add(createContainerServiceDependency(containerName)
167                     .setService(IPluginOutDataPacketService.class)
168                     .setCallbacks("setPluginOutDataPacketService",
169                             "unsetPluginOutDataPacketService")
170                     .setRequired(false));
171             c.add(createServiceDependency()
172                     .setService(IPluginOutConnectionService.class)
173                     .setCallbacks("setIPluginOutConnectionService",
174                             "unsetIPluginOutConnectionService")
175                     .setRequired(true));
176         }
177
178         if (imp.equals(ReadService.class)) {
179             // export the service to be used by SAL
180             Dictionary<String, Object> props = new Hashtable<String, Object>();
181             // Set the protocolPluginType property which will be used
182             // by SAL
183             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
184             c.setInterface(new String[] {
185                     IReadFilterInternalListener.class.getName(),
186                     IPluginInReadService.class.getName() }, props);
187
188             c.add(createServiceDependency()
189                     .setService(IReadServiceFilter.class)
190                     .setCallbacks("setService", "unsetService")
191                     .setRequired(true));
192
193             c.add(createContainerServiceDependency(containerName)
194                     .setService(IPluginOutReadService.class)
195                     .setCallbacks("setPluginOutReadServices",
196                             "unsetPluginOutReadServices")
197                     .setRequired(false));
198
199             c.add(createServiceDependency()
200                     .setService(IPluginOutConnectionService.class)
201                     .setCallbacks("setIPluginOutConnectionService",
202                             "unsetIPluginOutConnectionService")
203                     .setRequired(true));
204         }
205
206         if (imp.equals(FlowProgrammerNotifier.class)) {
207             // export the service to be used by SAL
208             Dictionary<String, Object> props = new Hashtable<String, Object>();
209             // Set the protocolPluginType property which will be used
210             // by SAL
211             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
212             c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
213
214             c.add(createContainerServiceDependency(containerName)
215                     .setService(IPluginOutFlowProgrammerService.class)
216                     .setCallbacks("setPluginOutFlowProgrammerService",
217                             "unsetPluginOutFlowProgrammerService")
218                     .setRequired(true));
219             c.add(createServiceDependency()
220                     .setService(IPluginOutConnectionService.class)
221                     .setCallbacks("setIPluginOutConnectionService",
222                             "unsetIPluginOutConnectionService")
223                     .setRequired(true));
224         }
225     }
226
227     /**
228      * Function that is used to communicate to dependency manager the list of
229      * known implementations for services that are container independent.
230      *
231      *
232      * @return An array containing all the CLASS objects that will be
233      *         instantiated in order to get an fully working implementation
234      *         Object
235      */
236     @Override
237     public Object[] getGlobalImplementations() {
238         Object[] res = { Controller.class, OFStatisticsManager.class,
239                 FlowProgrammerService.class, ReadServiceFilter.class,
240                 DiscoveryService.class, DataPacketMuxDemux.class, InventoryService.class,
241                 InventoryServiceShim.class, TopologyServiceShim.class };
242         return res;
243     }
244
245     /**
246      * Function that is called when configuration of the dependencies is
247      * required.
248      *
249      * @param c
250      *            dependency manager Component object, used for configuring the
251      *            dependencies exported and imported
252      * @param imp
253      *            Implementation class that is being configured, needed as long
254      *            as the same routine can configure multiple implementations
255      */
256     @Override
257     public void configureGlobalInstance(Component c, Object imp) {
258
259         if (imp.equals(Controller.class)) {
260             logger.debug("Activator configureGlobalInstance( ) is called");
261             Dictionary<String, Object> props = new Hashtable<String, Object>();
262             props.put("name", "Controller");
263             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
264             c.setInterface(new String[] { IController.class.getName(),
265                                           IPluginInConnectionService.class.getName()},
266                                           props);
267         }
268
269         if (imp.equals(FlowProgrammerService.class)) {
270             // export the service to be used by SAL
271             Dictionary<String, Object> props = new Hashtable<String, Object>();
272             // Set the protocolPluginType property which will be used
273             // by SAL
274             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
275             c.setInterface(
276                     new String[] {
277                             IPluginInFlowProgrammerService.class.getName(),
278                             IMessageListener.class.getName(),
279                             IContainerListener.class.getName(),
280                             IInventoryShimExternalListener.class.getName() },
281                             props);
282
283             c.add(createServiceDependency()
284                     .setService(IController.class, "(name=Controller)")
285                     .setCallbacks("setController", "unsetController")
286                     .setRequired(true));
287
288             c.add(createServiceDependency()
289                     .setService(IFlowProgrammerNotifier.class)
290                     .setCallbacks("setFlowProgrammerNotifier",
291                             "unsetsetFlowProgrammerNotifier")
292                     .setRequired(false));
293
294             c.add(createServiceDependency()
295                     .setService(IPluginOutConnectionService.class)
296                     .setCallbacks("setIPluginOutConnectionService",
297                             "unsetIPluginOutConnectionService")
298                     .setRequired(true));
299         }
300
301         if (imp.equals(ReadServiceFilter.class)) {
302
303             c.setInterface(new String[] {
304                     IReadServiceFilter.class.getName(),
305                     IContainerListener.class.getName(),
306                     IOFStatisticsListener.class.getName() }, null);
307
308             c.add(createServiceDependency()
309                     .setService(IController.class, "(name=Controller)")
310                     .setCallbacks("setController", "unsetController")
311                     .setRequired(true));
312             c.add(createServiceDependency()
313                     .setService(IOFStatisticsManager.class)
314                     .setCallbacks("setService", "unsetService")
315                     .setRequired(true));
316             c.add(createServiceDependency()
317                     .setService(IReadFilterInternalListener.class)
318                     .setCallbacks("setReadFilterInternalListener",
319                             "unsetReadFilterInternalListener")
320                     .setRequired(false));
321         }
322
323         if (imp.equals(OFStatisticsManager.class)) {
324
325             c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
326                     IInventoryShimExternalListener.class.getName() }, null);
327
328             c.add(createServiceDependency()
329                     .setService(IController.class, "(name=Controller)")
330                     .setCallbacks("setController", "unsetController")
331                     .setRequired(true));
332             c.add(createServiceDependency()
333                     .setService(IOFStatisticsListener.class)
334                     .setCallbacks("setStatisticsListener",
335                             "unsetStatisticsListener").setRequired(false));
336         }
337
338         if (imp.equals(DiscoveryService.class)) {
339             // export the service
340             c.setInterface(
341                     new String[] {
342                             IInventoryShimExternalListener.class.getName(),
343                             IDataPacketListen.class.getName(),
344                             IContainerListener.class.getName() }, null);
345
346             c.add(createServiceDependency()
347                     .setService(IController.class, "(name=Controller)")
348                     .setCallbacks("setController", "unsetController")
349                     .setRequired(true));
350             c.add(createContainerServiceDependency(
351                     GlobalConstants.DEFAULT.toString())
352                     .setService(IInventoryProvider.class)
353                     .setCallbacks("setInventoryProvider",
354                     "unsetInventoryProvider").setRequired(true));
355             c.add(createServiceDependency().setService(IDataPacketMux.class)
356                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
357                     .setRequired(true));
358             c.add(createServiceDependency()
359                     .setService(IDiscoveryListener.class)
360                     .setCallbacks("setDiscoveryListener",
361                             "unsetDiscoveryListener").setRequired(true));
362             c.add(createServiceDependency()
363                     .setService(IPluginOutConnectionService.class)
364                     .setCallbacks("setIPluginOutConnectionService",
365                             "unsetIPluginOutConnectionService")
366                     .setRequired(true));
367         }
368
369         // DataPacket mux/demux services, which is teh actual engine
370         // doing the packet switching
371         if (imp.equals(DataPacketMuxDemux.class)) {
372             c.setInterface(new String[] { IDataPacketMux.class.getName(),
373                     IContainerListener.class.getName(),
374                     IInventoryShimExternalListener.class.getName() }, null);
375
376             c.add(createServiceDependency()
377                     .setService(IController.class, "(name=Controller)")
378                     .setCallbacks("setController", "unsetController")
379                     .setRequired(true));
380             c.add(createServiceDependency()
381                     .setService(IPluginOutDataPacketService.class)
382                     .setCallbacks("setPluginOutDataPacketService",
383                             "unsetPluginOutDataPacketService")
384                     .setRequired(false));
385             // See if there is any local packet dispatcher
386             c.add(createServiceDependency()
387                     .setService(IDataPacketListen.class)
388                     .setCallbacks("setIDataPacketListen",
389                             "unsetIDataPacketListen").setRequired(false));
390             c.add(createServiceDependency()
391                     .setService(IPluginOutConnectionService.class)
392                     .setCallbacks("setIPluginOutConnectionService",
393                             "unsetIPluginOutConnectionService")
394                     .setRequired(true));
395         }
396
397         if (imp.equals(InventoryService.class)) {
398             // export the service
399             Dictionary<String, Object> props = new Hashtable<String, Object>();
400             props.put("scope", "Global");
401
402             c.setInterface(
403                     new String[] { IPluginInInventoryService.class.getName(),
404                             IInventoryShimInternalListener.class.getName(),
405                             IInventoryProvider.class.getName() }, props);
406
407             // Now lets add a service dependency to make sure the
408             // provider of service exists
409             c.add(createServiceDependency()
410                     .setService(IController.class, "(name=Controller)")
411                     .setCallbacks("setController", "unsetController")
412                     .setRequired(true));
413             c.add(createServiceDependency()
414                     .setService(IPluginOutInventoryService.class, "(scope=Global)")
415                     .setCallbacks("setPluginOutInventoryServices",
416                             "unsetPluginOutInventoryServices")
417                     .setRequired(true));
418         }
419
420         if (imp.equals(InventoryServiceShim.class)) {
421             c.setInterface(new String[] { IContainerListener.class.getName(),
422                     IOFStatisticsListener.class.getName()}, null);
423
424             c.add(createServiceDependency()
425                     .setService(IController.class, "(name=Controller)")
426                     .setCallbacks("setController", "unsetController")
427                     .setRequired(true));
428             c.add(createServiceDependency()
429                     .setService(IInventoryShimInternalListener.class, "(!(scope=Global))")
430                     .setCallbacks("setInventoryShimInternalListener",
431                             "unsetInventoryShimInternalListener")
432                     .setRequired(true));
433             c.add(createServiceDependency()
434                     .setService(IInventoryShimInternalListener.class, "(scope=Global)")
435                     .setCallbacks("setInventoryShimGlobalInternalListener",
436                             "unsetInventoryShimGlobalInternalListener")
437                     .setRequired(true));
438             c.add(createServiceDependency()
439                     .setService(IInventoryShimExternalListener.class)
440                     .setCallbacks("setInventoryShimExternalListener",
441                             "unsetInventoryShimExternalListener")
442                     .setRequired(false));
443             c.add(createServiceDependency()
444                     .setService(IPluginOutConnectionService.class)
445                     .setCallbacks("setIPluginOutConnectionService",
446                             "unsetIPluginOutConnectionService")
447                     .setRequired(true));
448         }
449
450         if (imp.equals(TopologyServiceShim.class)) {
451             c.setInterface(new String[] { IDiscoveryListener.class.getName(),
452                     IContainerListener.class.getName(),
453                     IRefreshInternalProvider.class.getName(),
454                     IInventoryShimExternalListener.class.getName() }, null);
455           c.add(createServiceDependency()
456                     .setService(ITopologyServiceShimListener.class)
457                     .setCallbacks("setTopologyServiceShimListener",
458                             "unsetTopologyServiceShimListener")
459                     .setRequired(true));
460             c.add(createServiceDependency()
461                     .setService(IOFStatisticsManager.class)
462                     .setCallbacks("setStatisticsManager",
463                             "unsetStatisticsManager").setRequired(false));
464         }
465     }
466 }