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