a93a8b7243cede7e2d81d212160dbe7a97806539
[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.IOFStatisticsManager;
23 import org.opendaylight.controller.protocol_plugin.openflow.IPluginReadServiceFilter;
24 import org.opendaylight.controller.protocol_plugin.openflow.IRefreshInternalProvider;
25 import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener;
26 import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener;
27 import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
28 import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener;
29 import org.opendaylight.controller.protocol_plugin.openflow.core.internal.Controller;
30 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
31 import org.opendaylight.controller.sal.core.IContainerListener;
32 import org.opendaylight.controller.sal.core.Node;
33 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
34 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
35 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
36 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
37 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
38 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
39 import org.opendaylight.controller.sal.reader.IPluginInReadService;
40 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
41 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
42 import org.opendaylight.controller.sal.utils.GlobalConstants;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45
46 /**
47  * Openflow protocol plugin Activator
48  *
49  *
50  */
51 public class Activator extends ComponentActivatorAbstractBase {
52     protected static final Logger logger = LoggerFactory
53             .getLogger(Activator.class);
54
55     /**
56      * Function called when the activator starts just after some initializations
57      * are done by the ComponentActivatorAbstractBase.
58      *
59      */
60     public void init() {
61     }
62
63     /**
64      * Function called when the activator stops just before the cleanup done by
65      * ComponentActivatorAbstractBase
66      *
67      */
68     public void destroy() {
69     }
70
71     /**
72      * Function that is used to communicate to dependency manager the list of
73      * known implementations for services inside a container
74      *
75      *
76      * @return An array containing all the CLASS objects that will be
77      *         instantiated in order to get an fully working implementation
78      *         Object
79      */
80     public Object[] getImplementations() {
81         Object[] res = { TopologyServices.class, DataPacketServices.class,
82                 InventoryService.class, ReadService.class,
83                 FlowProgrammerNotifier.class };
84         return res;
85     }
86
87     /**
88      * Function that is called when configuration of the dependencies is
89      * required.
90      *
91      * @param c
92      *            dependency manager Component object, used for configuring the
93      *            dependencies exported and imported
94      * @param imp
95      *            Implementation class that is being configured, needed as long
96      *            as the same routine can configure multiple implementations
97      * @param containerName
98      *            The containerName being configured, this allow also optional
99      *            per-container different behavior if needed, usually should not
100      *            be the case though.
101      */
102     public void configureInstance(Component c, Object imp, String containerName) {
103         if (imp.equals(TopologyServices.class)) {
104             // export the service to be used by SAL
105             c.setInterface(
106                     new String[] { IPluginInTopologyService.class.getName(),
107                             ITopologyServiceShimListener.class.getName() },
108                     null);
109             // Hook the services coming in from SAL, as optional in
110             // case SAL is not yet there, could happen
111             c.add(createContainerServiceDependency(containerName)
112                     .setService(IPluginOutTopologyService.class)
113                     .setCallbacks("setPluginOutTopologyService",
114                             "unsetPluginOutTopologyService").setRequired(false));
115             c.add(createServiceDependency()
116                     .setService(IRefreshInternalProvider.class)
117                     .setCallbacks("setRefreshInternalProvider",
118                             "unsetRefreshInternalProvider").setRequired(false));
119         }
120
121         if (imp.equals(InventoryService.class)) {
122             // export the service
123             c.setInterface(
124                     new String[] { IPluginInInventoryService.class.getName(),
125                             IInventoryShimInternalListener.class.getName(),
126                             IInventoryProvider.class.getName() }, 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(IInventoryProvider.class)
304                     .setCallbacks("setInventoryProvider",
305                     "unsetInventoryProvider").setRequired(true));
306             c.add(createServiceDependency().setService(IDataPacketMux.class)
307                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
308                     .setRequired(true));
309             c.add(createServiceDependency()
310                     .setService(IDiscoveryListener.class)
311                     .setCallbacks("setDiscoveryListener",
312                             "unsetDiscoveryListener").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                     IStatisticsListener.class.getName()}, 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[] { IDiscoveryListener.class.getName(),
360                     IContainerListener.class.getName(),
361                     IRefreshInternalProvider.class.getName(),
362                     IInventoryShimExternalListener.class.getName() }, null);
363           c.add(createServiceDependency()
364                     .setService(ITopologyServiceShimListener.class)
365                     .setCallbacks("setTopologyServiceShimListener",
366                             "unsetTopologyServiceShimListener")
367                     .setRequired(true));
368             c.add(createServiceDependency()
369                     .setService(IOFStatisticsManager.class)
370                     .setCallbacks("setStatisticsManager",
371                             "unsetStatisticsManager").setRequired(false));
372         }
373     }
374 }