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