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