30834cbe1371ca9f42f08e2160751dd51ac2079c
[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                             IInventoryShimInternalListener.class.getName() },
125                     null);
126
127             // Now lets add a service dependency to make sure the
128             // provider of service exists
129             c.add(createServiceDependency()
130                     .setService(IController.class, "(name=Controller)")
131                     .setCallbacks("setController", "unsetController")
132                     .setRequired(true));
133             c.add(createContainerServiceDependency(containerName)
134                     .setService(IPluginOutInventoryService.class)
135                     .setCallbacks("setPluginOutInventoryServices",
136                             "unsetPluginOutInventoryServices")
137                     .setRequired(false));
138         }
139
140         if (imp.equals(DataPacketServices.class)) {
141             // export the service to be used by SAL
142             Dictionary<String, Object> props = new Hashtable<String, Object>();
143             // Set the protocolPluginType property which will be used
144             // by SAL
145             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
146             c.setInterface(IPluginInDataPacketService.class.getName(), props);
147             // Hook the services coming in from SAL, as optional in
148             // case SAL is not yet there, could happen
149             c.add(createServiceDependency()
150                     .setService(IController.class, "(name=Controller)")
151                     .setCallbacks("setController", "unsetController")
152                     .setRequired(true));
153             // This is required for the transmission to happen properly
154             c.add(createServiceDependency().setService(IDataPacketMux.class)
155                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
156                     .setRequired(true));
157             c.add(createContainerServiceDependency(containerName)
158                     .setService(IPluginOutDataPacketService.class)
159                     .setCallbacks("setPluginOutDataPacketService",
160                             "unsetPluginOutDataPacketService")
161                     .setRequired(false));
162         }
163
164         if (imp.equals(ReadService.class)) {
165             // export the service to be used by SAL
166             Dictionary<String, Object> props = new Hashtable<String, Object>();
167             // Set the protocolPluginType property which will be used
168             // by SAL
169             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
170             c.setInterface(IPluginInReadService.class.getName(), props);
171             c.add(createServiceDependency()
172                     .setService(IPluginReadServiceFilter.class)
173                     .setCallbacks("setService", "unsetService")
174                     .setRequired(true));
175         }
176
177         if (imp.equals(FlowProgrammerNotifier.class)) {
178             // export the service to be used by SAL
179             Dictionary<String, Object> props = new Hashtable<String, Object>();
180             // Set the protocolPluginType property which will be used
181             // by SAL
182             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
183             c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
184
185             c.add(createContainerServiceDependency(containerName)
186                     .setService(IPluginOutFlowProgrammerService.class)
187                     .setCallbacks("setPluginOutFlowProgrammerService",
188                             "unsetPluginOutFlowProgrammerService")
189                     .setRequired(true));
190         }
191     }
192
193     /**
194      * Function that is used to communicate to dependency manager the list of
195      * known implementations for services that are container independent.
196      * 
197      * 
198      * @return An array containing all the CLASS objects that will be
199      *         instantiated in order to get an fully working implementation
200      *         Object
201      */
202     public Object[] getGlobalImplementations() {
203         Object[] res = { Controller.class, OFStatisticsManager.class,
204                 FlowProgrammerService.class, ReadServiceFilter.class,
205                 DiscoveryService.class, DataPacketMuxDemux.class,
206                 InventoryServiceShim.class, TopologyServiceShim.class };
207         return res;
208     }
209
210     /**
211      * Function that is called when configuration of the dependencies is
212      * required.
213      * 
214      * @param c
215      *            dependency manager Component object, used for configuring the
216      *            dependencies exported and imported
217      * @param imp
218      *            Implementation class that is being configured, needed as long
219      *            as the same routine can configure multiple implementations
220      */
221     public void configureGlobalInstance(Component c, Object imp) {
222
223         if (imp.equals(Controller.class)) {
224             logger.debug("Activator configureGlobalInstance( ) is called");
225             Dictionary<String, Object> props = new Hashtable<String, Object>();
226             props.put("name", "Controller");
227             c.setInterface(IController.class.getName(), props);
228         }
229
230         if (imp.equals(FlowProgrammerService.class)) {
231             // export the service to be used by SAL
232             Dictionary<String, Object> props = new Hashtable<String, Object>();
233             // Set the protocolPluginType property which will be used
234             // by SAL
235             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
236             c.setInterface(
237                     new String[] {
238                             IPluginInFlowProgrammerService.class.getName(),
239                             IMessageListener.class.getName(),
240                             IContainerListener.class.getName(),
241                             IInventoryShimExternalListener.class.getName() },
242                     props);
243
244             c.add(createServiceDependency()
245                     .setService(IController.class, "(name=Controller)")
246                     .setCallbacks("setController", "unsetController")
247                     .setRequired(true));
248
249             c.add(createServiceDependency()
250                     .setService(IFlowProgrammerNotifier.class)
251                     .setCallbacks("setFlowProgrammerNotifier",
252                             "unsetsetFlowProgrammerNotifier")
253                     .setRequired(false));
254
255         }
256
257         if (imp.equals(ReadServiceFilter.class)) {
258
259             c.setInterface(
260                     new String[] { IPluginReadServiceFilter.class.getName(),
261                             IContainerListener.class.getName() }, null);
262
263             c.add(createServiceDependency()
264                     .setService(IController.class, "(name=Controller)")
265                     .setCallbacks("setController", "unsetController")
266                     .setRequired(true));
267             c.add(createServiceDependency()
268                     .setService(IOFStatisticsManager.class)
269                     .setCallbacks("setService", "unsetService")
270                     .setRequired(true));
271         }
272
273         if (imp.equals(OFStatisticsManager.class)) {
274
275             c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
276                     IInventoryShimExternalListener.class.getName() }, null);
277
278             c.add(createServiceDependency()
279                     .setService(IController.class, "(name=Controller)")
280                     .setCallbacks("setController", "unsetController")
281                     .setRequired(true));
282             c.add(createServiceDependency()
283                     .setService(IStatisticsListener.class)
284                     .setCallbacks("setStatisticsListener",
285                             "unsetStatisticsListener").setRequired(false));
286         }
287
288         if (imp.equals(DiscoveryService.class)) {
289             // export the service
290             c.setInterface(
291                     new String[] {
292                             IInventoryShimExternalListener.class.getName(),
293                             IDataPacketListen.class.getName(),
294                             IContainerListener.class.getName() }, null);
295
296             c.add(createServiceDependency()
297                     .setService(IController.class, "(name=Controller)")
298                     .setCallbacks("setController", "unsetController")
299                     .setRequired(true));
300             c.add(createContainerServiceDependency(
301                     GlobalConstants.DEFAULT.toString())
302                     .setService(IPluginInInventoryService.class)
303                     .setCallbacks("setPluginInInventoryService",
304                             "unsetPluginInInventoryService").setRequired(true));
305             c.add(createServiceDependency().setService(IDataPacketMux.class)
306                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
307                     .setRequired(true));
308             c.add(createServiceDependency()
309                     .setService(IDiscoveryService.class)
310                     .setCallbacks("setDiscoveryService",
311                             "unsetDiscoveryService").setRequired(true));
312         }
313
314         // DataPacket mux/demux services, which is teh actual engine
315         // doing the packet switching
316         if (imp.equals(DataPacketMuxDemux.class)) {
317             c.setInterface(new String[] { IDataPacketMux.class.getName(),
318                     IContainerListener.class.getName(),
319                     IInventoryShimExternalListener.class.getName() }, null);
320
321             c.add(createServiceDependency()
322                     .setService(IController.class, "(name=Controller)")
323                     .setCallbacks("setController", "unsetController")
324                     .setRequired(true));
325             c.add(createServiceDependency()
326                     .setService(IPluginOutDataPacketService.class)
327                     .setCallbacks("setPluginOutDataPacketService",
328                             "unsetPluginOutDataPacketService")
329                     .setRequired(false));
330             // See if there is any local packet dispatcher
331             c.add(createServiceDependency()
332                     .setService(IDataPacketListen.class)
333                     .setCallbacks("setIDataPacketListen",
334                             "unsetIDataPacketListen").setRequired(false));
335         }
336
337         if (imp.equals(InventoryServiceShim.class)) {
338             c.setInterface(new String[] { IContainerListener.class.getName(),
339                     IStatisticsListener.class.getName()}, null);
340
341             c.add(createServiceDependency()
342                     .setService(IController.class, "(name=Controller)")
343                     .setCallbacks("setController", "unsetController")
344                     .setRequired(true));
345             c.add(createServiceDependency()
346                     .setService(IInventoryShimInternalListener.class)
347                     .setCallbacks("setInventoryShimInternalListener",
348                             "unsetInventoryShimInternalListener")
349                     .setRequired(true));
350             c.add(createServiceDependency()
351                     .setService(IInventoryShimExternalListener.class)
352                     .setCallbacks("setInventoryShimExternalListener",
353                             "unsetInventoryShimExternalListener")
354                     .setRequired(false));
355         }
356
357         if (imp.equals(TopologyServiceShim.class)) {
358             c.setInterface(new String[] { IDiscoveryService.class.getName(),
359                     IContainerListener.class.getName(),
360                     IRefreshInternalProvider.class.getName(),
361                     IInventoryShimExternalListener.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 }