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