9bccbd1d68f450dc60889b1c35f21742da690d1e
[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.IFlowProgrammerNotifier;
18 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener;
19 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener;
20 import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager;
21 import org.opendaylight.controller.protocol_plugin.openflow.IPluginReadServiceFilter;
22 import org.opendaylight.controller.protocol_plugin.openflow.IRefreshInternalProvider;
23 import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener;
24 import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener;
25 import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
26 import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener;
27 import org.opendaylight.controller.protocol_plugin.openflow.core.internal.Controller;
28 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
29 import org.opendaylight.controller.sal.core.IContainerListener;
30 import org.opendaylight.controller.sal.core.Node;
31 import org.opendaylight.controller.sal.discovery.IDiscoveryService;
32 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
33 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
34 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
35 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
36 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
37 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
38 import org.opendaylight.controller.sal.reader.IPluginInReadService;
39 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
40 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
41 import org.opendaylight.controller.sal.utils.GlobalConstants;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 /**
46  * Openflow protocol plugin Activator
47  * 
48  * 
49  */
50 public class Activator extends ComponentActivatorAbstractBase {
51     protected static final Logger logger = LoggerFactory
52             .getLogger(Activator.class);
53
54     /**
55      * Function called when the activator starts just after some initializations
56      * are done by the ComponentActivatorAbstractBase.
57      * 
58      */
59     public void init() {
60     }
61
62     /**
63      * Function called when the activator stops just before the cleanup done by
64      * ComponentActivatorAbstractBase
65      * 
66      */
67     public void destroy() {
68     }
69
70     /**
71      * Function that is used to communicate to dependency manager the list of
72      * known implementations for services inside a container
73      * 
74      * 
75      * @return An array containing all the CLASS objects that will be
76      *         instantiated in order to get an fully working implementation
77      *         Object
78      */
79     public Object[] getImplementations() {
80         Object[] res = { TopologyServices.class, DataPacketServices.class,
81                 InventoryService.class, ReadService.class,
82                 FlowProgrammerNotifier.class };
83         return res;
84     }
85
86     /**
87      * Function that is called when configuration of the dependencies is
88      * required.
89      * 
90      * @param c
91      *            dependency manager Component object, used for configuring the
92      *            dependencies exported and imported
93      * @param imp
94      *            Implementation class that is being configured, needed as long
95      *            as the same routine can configure multiple implementations
96      * @param containerName
97      *            The containerName being configured, this allow also optional
98      *            per-container different behavior if needed, usually should not
99      *            be the case though.
100      */
101     public void configureInstance(Component c, Object imp, String containerName) {
102         if (imp.equals(TopologyServices.class)) {
103             // export the service to be used by SAL
104             c.setInterface(
105                     new String[] { IPluginInTopologyService.class.getName(),
106                             ITopologyServiceShimListener.class.getName() },
107                     null);
108             // Hook the services coming in from SAL, as optional in
109             // case SAL is not yet there, could happen
110             c.add(createContainerServiceDependency(containerName)
111                     .setService(IPluginOutTopologyService.class)
112                     .setCallbacks("setPluginOutTopologyService",
113                             "unsetPluginOutTopologyService").setRequired(false));
114             c.add(createServiceDependency()
115                     .setService(IRefreshInternalProvider.class)
116                     .setCallbacks("setRefreshInternalProvider",
117                             "unsetRefreshInternalProvider").setRequired(false));
118         }
119
120         if (imp.equals(InventoryService.class)) {
121             // export the service
122             c.setInterface(
123                     new String[] { IPluginInInventoryService.class.getName(),
124                             IStatisticsListener.class.getName(),
125                             IInventoryShimInternalListener.class.getName() },
126                     null);
127
128             // Now lets add a service dependency to make sure the
129             // provider of service exists
130             c.add(createServiceDependency()
131                     .setService(IController.class, "(name=Controller)")
132                     .setCallbacks("setController", "unsetController")
133                     .setRequired(true));
134             c.add(createContainerServiceDependency(containerName)
135                     .setService(IPluginOutInventoryService.class)
136                     .setCallbacks("setPluginOutInventoryServices",
137                             "unsetPluginOutInventoryServices")
138                     .setRequired(false));
139         }
140
141         if (imp.equals(DataPacketServices.class)) {
142             // export the service to be used by SAL
143             Dictionary<String, Object> props = new Hashtable<String, Object>();
144             // Set the protocolPluginType property which will be used
145             // by SAL
146             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
147             c.setInterface(IPluginInDataPacketService.class.getName(), props);
148             // Hook the services coming in from SAL, as optional in
149             // case SAL is not yet there, could happen
150             c.add(createServiceDependency()
151                     .setService(IController.class, "(name=Controller)")
152                     .setCallbacks("setController", "unsetController")
153                     .setRequired(true));
154             // This is required for the transmission to happen properly
155             c.add(createServiceDependency().setService(IDataPacketMux.class)
156                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
157                     .setRequired(true));
158             c.add(createContainerServiceDependency(containerName)
159                     .setService(IPluginOutDataPacketService.class)
160                     .setCallbacks("setPluginOutDataPacketService",
161                             "unsetPluginOutDataPacketService")
162                     .setRequired(false));
163         }
164
165         if (imp.equals(ReadService.class)) {
166             // export the service to be used by SAL
167             Dictionary<String, Object> props = new Hashtable<String, Object>();
168             // Set the protocolPluginType property which will be used
169             // by SAL
170             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
171             c.setInterface(IPluginInReadService.class.getName(), props);
172             c.add(createServiceDependency()
173                     .setService(IPluginReadServiceFilter.class)
174                     .setCallbacks("setService", "unsetService")
175                     .setRequired(true));
176         }
177
178         if (imp.equals(FlowProgrammerNotifier.class)) {
179             // export the service to be used by SAL
180             Dictionary<String, Object> props = new Hashtable<String, Object>();
181             // Set the protocolPluginType property which will be used
182             // by SAL
183             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
184             c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
185
186             c.add(createContainerServiceDependency(containerName)
187                     .setService(IPluginOutFlowProgrammerService.class)
188                     .setCallbacks("setPluginOutFlowProgrammerService",
189                             "unsetPluginOutFlowProgrammerService")
190                     .setRequired(true));
191         }
192     }
193
194     /**
195      * Function that is used to communicate to dependency manager the list of
196      * known implementations for services that are container independent.
197      * 
198      * 
199      * @return An array containing all the CLASS objects that will be
200      *         instantiated in order to get an fully working implementation
201      *         Object
202      */
203     public Object[] getGlobalImplementations() {
204         Object[] res = { Controller.class, OFStatisticsManager.class,
205                 FlowProgrammerService.class, ReadServiceFilter.class,
206                 DiscoveryService.class, DataPacketMuxDemux.class,
207                 InventoryServiceShim.class, TopologyServiceShim.class };
208         return res;
209     }
210
211     /**
212      * Function that is called when configuration of the dependencies is
213      * required.
214      * 
215      * @param c
216      *            dependency manager Component object, used for configuring the
217      *            dependencies exported and imported
218      * @param imp
219      *            Implementation class that is being configured, needed as long
220      *            as the same routine can configure multiple implementations
221      */
222     public void configureGlobalInstance(Component c, Object imp) {
223
224         if (imp.equals(Controller.class)) {
225             logger.debug("Activator configureGlobalInstance( ) is called");
226             Dictionary<String, Object> props = new Hashtable<String, Object>();
227             props.put("name", "Controller");
228             c.setInterface(IController.class.getName(), props);
229         }
230
231         if (imp.equals(FlowProgrammerService.class)) {
232             // export the service to be used by SAL
233             Dictionary<String, Object> props = new Hashtable<String, Object>();
234             // Set the protocolPluginType property which will be used
235             // by SAL
236             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
237             c.setInterface(
238                     new String[] {
239                             IPluginInFlowProgrammerService.class.getName(),
240                             IMessageListener.class.getName(),
241                             IContainerListener.class.getName(),
242                             IInventoryShimExternalListener.class.getName() },
243                     props);
244
245             c.add(createServiceDependency()
246                     .setService(IController.class, "(name=Controller)")
247                     .setCallbacks("setController", "unsetController")
248                     .setRequired(true));
249
250             c.add(createServiceDependency()
251                     .setService(IFlowProgrammerNotifier.class)
252                     .setCallbacks("setFlowProgrammerNotifier",
253                             "unsetsetFlowProgrammerNotifier")
254                     .setRequired(false));
255
256         }
257
258         if (imp.equals(ReadServiceFilter.class)) {
259
260             c.setInterface(
261                     new String[] { IPluginReadServiceFilter.class.getName(),
262                             IContainerListener.class.getName() }, null);
263
264             c.add(createServiceDependency()
265                     .setService(IController.class, "(name=Controller)")
266                     .setCallbacks("setController", "unsetController")
267                     .setRequired(true));
268             c.add(createServiceDependency()
269                     .setService(IOFStatisticsManager.class)
270                     .setCallbacks("setService", "unsetService")
271                     .setRequired(true));
272         }
273
274         if (imp.equals(OFStatisticsManager.class)) {
275
276             c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
277                     IInventoryShimExternalListener.class.getName() }, null);
278
279             c.add(createServiceDependency()
280                     .setService(IController.class, "(name=Controller)")
281                     .setCallbacks("setController", "unsetController")
282                     .setRequired(true));
283             c.add(createServiceDependency()
284                     .setService(IStatisticsListener.class)
285                     .setCallbacks("setStatisticsListener",
286                             "unsetStatisticsListener").setRequired(false));
287         }
288
289         if (imp.equals(DiscoveryService.class)) {
290             // export the service
291             c.setInterface(
292                     new String[] {
293                             IInventoryShimExternalListener.class.getName(),
294                             IDataPacketListen.class.getName(),
295                             IContainerListener.class.getName() }, null);
296
297             c.add(createServiceDependency()
298                     .setService(IController.class, "(name=Controller)")
299                     .setCallbacks("setController", "unsetController")
300                     .setRequired(true));
301             c.add(createContainerServiceDependency(
302                     GlobalConstants.DEFAULT.toString())
303                     .setService(IPluginInInventoryService.class)
304                     .setCallbacks("setPluginInInventoryService",
305                             "unsetPluginInInventoryService").setRequired(true));
306             c.add(createServiceDependency().setService(IDataPacketMux.class)
307                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
308                     .setRequired(true));
309             c.add(createServiceDependency()
310                     .setService(IDiscoveryService.class)
311                     .setCallbacks("setDiscoveryService",
312                             "unsetDiscoveryService").setRequired(true));
313         }
314
315         // DataPacket mux/demux services, which is teh actual engine
316         // doing the packet switching
317         if (imp.equals(DataPacketMuxDemux.class)) {
318             c.setInterface(new String[] { IDataPacketMux.class.getName(),
319                     IContainerListener.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(IPluginOutDataPacketService.class)
328                     .setCallbacks("setPluginOutDataPacketService",
329                             "unsetPluginOutDataPacketService")
330                     .setRequired(false));
331             // See if there is any local packet dispatcher
332             c.add(createServiceDependency()
333                     .setService(IDataPacketListen.class)
334                     .setCallbacks("setIDataPacketListen",
335                             "unsetIDataPacketListen").setRequired(false));
336         }
337
338         if (imp.equals(InventoryServiceShim.class)) {
339             c.setInterface(new String[] { IContainerListener.class.getName() },
340                     null);
341
342             c.add(createServiceDependency()
343                     .setService(IController.class, "(name=Controller)")
344                     .setCallbacks("setController", "unsetController")
345                     .setRequired(true));
346             c.add(createServiceDependency()
347                     .setService(IInventoryShimInternalListener.class)
348                     .setCallbacks("setInventoryShimInternalListener",
349                             "unsetInventoryShimInternalListener")
350                     .setRequired(true));
351             c.add(createServiceDependency()
352                     .setService(IInventoryShimExternalListener.class)
353                     .setCallbacks("setInventoryShimExternalListener",
354                             "unsetInventoryShimExternalListener")
355                     .setRequired(false));
356         }
357
358         if (imp.equals(TopologyServiceShim.class)) {
359             c.setInterface(new String[] { IDiscoveryService.class.getName(),
360                     IContainerListener.class.getName(),
361                     IRefreshInternalProvider.class.getName() }, null);
362             c.add(createServiceDependency()
363                     .setService(ITopologyServiceShimListener.class)
364                     .setCallbacks("setTopologyServiceShimListener",
365                             "unsetTopologyServiceShimListener")
366                     .setRequired(true));
367             c.add(createServiceDependency()
368                     .setService(IOFStatisticsManager.class)
369                     .setCallbacks("setStatisticsManager",
370                             "unsetStatisticsManager").setRequired(false));
371         }
372     }
373 }