OpenDaylight Controller functional modules.
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / Activator.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.protocol_plugin.openflow.internal;
11
12 import org.opendaylight.controller.sal.core.IContainerListener;
13 import java.util.Dictionary;
14 import java.util.Hashtable;
15
16 import org.apache.felix.dm.Component;
17 import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketListen;
18 import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketMux;
19 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener;
20 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener;
21 import org.opendaylight.controller.protocol_plugin.openflow.IOFInventoryService;
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.ITopologyServiceShimListener;
26 import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
27 import org.opendaylight.controller.protocol_plugin.openflow.core.internal.Controller;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import org.opendaylight.controller.sal.core.Node;
32 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
33 import org.opendaylight.controller.sal.discovery.IDiscoveryService;
34 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
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
44 /**
45  * Openflow protocol plugin Activator
46  *
47  *
48  */
49 public class Activator extends ComponentActivatorAbstractBase {
50     protected static final Logger logger = LoggerFactory
51             .getLogger(Activator.class);
52
53     /**
54      * Function called when the activator starts just after some
55      * initializations are done by the
56      * ComponentActivatorAbstractBase.
57      *
58      */
59     public void init() {
60     }
61
62     /**
63      * Function called when the activator stops just before the
64      * cleanup done by ComponentActivatorAbstractBase
65      *
66      */
67     public void destroy() {
68     }
69
70     /**
71      * Function that is used to communicate to dependency manager the
72      * list of 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         return res;
83     }
84
85     /**
86      * Function that is called when configuration of the dependencies
87      * is required.
88      *
89      * @param c dependency manager Component object, used for
90      * configuring the dependencies exported and imported
91      * @param imp Implementation class that is being configured,
92      * needed as long as the same routine can configure multiple
93      * implementations
94      * @param containerName The containerName being configured, this allow
95      * also optional per-container different behavior if needed, usually
96      * should not be the case though.
97      */
98     public void configureInstance(Component c, Object imp, String containerName) {
99         if (imp.equals(TopologyServices.class)) {
100             // export the service to be used by SAL
101             c.setInterface(new String[] {
102                     IPluginInTopologyService.class.getName(),
103                     ITopologyServiceShimListener.class.getName() }, null);
104             // Hook the services coming in from SAL, as optional in
105             // case SAL is not yet there, could happen
106             c.add(createContainerServiceDependency(containerName).setService(
107                     IPluginOutTopologyService.class).setCallbacks(
108                     "setPluginOutTopologyService",
109                     "unsetPluginOutTopologyService").setRequired(false));
110             c.add(createServiceDependency().setService(
111                     IRefreshInternalProvider.class).setCallbacks(
112                     "setRefreshInternalProvider",
113                     "unsetRefreshInternalProvider").setRequired(false));
114         }
115
116         if (imp.equals(InventoryService.class)) {
117             // export the service
118             c.setInterface(new String[] {
119                     IPluginInInventoryService.class.getName(),
120                     IOFInventoryService.class.getName(),
121                     IInventoryShimInternalListener.class.getName() }, null);
122
123             // Now lets add a service dependency to make sure the
124             // provider of service exists
125             c.add(createServiceDependency().setService(IController.class,
126                     "(name=Controller)").setCallbacks("setController",
127                     "unsetController").setRequired(true));
128             c.add(createContainerServiceDependency(containerName).setService(
129                     IPluginOutInventoryService.class).setCallbacks(
130                     "setPluginOutInventoryServices",
131                     "unsetPluginOutInventoryServices").setRequired(false));
132         }
133
134         if (imp.equals(DataPacketServices.class)) {
135             // export the service to be used by SAL
136             Dictionary<String, Object> props = new Hashtable<String, Object>();
137             // Set the protocolPluginType property which will be used
138             // by SAL
139             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
140             c.setInterface(IPluginInDataPacketService.class.getName(), props);
141             // Hook the services coming in from SAL, as optional in
142             // case SAL is not yet there, could happen
143             c.add(createServiceDependency().setService(IController.class,
144                     "(name=Controller)").setCallbacks("setController",
145                     "unsetController").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).setService(
151                     IPluginOutDataPacketService.class).setCallbacks(
152                     "setPluginOutDataPacketService",
153                     "unsetPluginOutDataPacketService").setRequired(false));
154         }
155
156         if (imp.equals(ReadService.class)) {
157             // export the service to be used by SAL
158             Dictionary<String, Object> props = new Hashtable<String, Object>();
159             // Set the protocolPluginType property which will be used
160             // by SAL
161             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
162             c.setInterface(IPluginInReadService.class.getName(), props);
163             c.add(createServiceDependency().setService(
164                     IPluginReadServiceFilter.class).setCallbacks("setService",
165                     "unsetService").setRequired(true));
166         }
167     }
168
169     /**
170      * Function that is used to communicate to dependency manager the
171      * list of known implementations for services that are container
172      * independent.
173      *
174      *
175      * @return An array containing all the CLASS objects that will be
176      * instantiated in order to get an fully working implementation
177      * Object
178      */
179     public Object[] getGlobalImplementations() {
180         Object[] res = { Controller.class, OFStatisticsManager.class,
181                 FlowProgrammerService.class, ReadServiceFilter.class,
182                 DiscoveryService.class, DataPacketMuxDemux.class,
183                 InventoryServiceShim.class, TopologyServiceShim.class };
184         return res;
185     }
186
187     /**
188      * Function that is called when configuration of the dependencies
189      * is required.
190      *
191      * @param c dependency manager Component object, used for
192      * configuring the dependencies exported and imported
193      * @param imp Implementation class that is being configured,
194      * needed as long as the same routine can configure multiple
195      * implementations
196      */
197     public void configureGlobalInstance(Component c, Object imp) {
198
199         if (imp.equals(Controller.class)) {
200             logger.debug("Activator configureGlobalInstance( ) is called");
201             Dictionary<String, Object> props = new Hashtable<String, Object>();
202             props.put("name", "Controller");
203             c.setInterface(IController.class.getName(), props);
204         }
205
206         if (imp.equals(FlowProgrammerService.class)) {
207             // export the service to be used by SAL
208             Dictionary<String, Object> props = new Hashtable<String, Object>();
209             // Set the protocolPluginType property which will be used
210             // by SAL
211             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
212             c.setInterface(IPluginInFlowProgrammerService.class
213                            .getName(), props);
214
215             c.add(createServiceDependency().setService(IController.class,
216                     "(name=Controller)").setCallbacks("setController",
217                     "unsetController").setRequired(true));
218         }
219
220         if (imp.equals(ReadServiceFilter.class)) {
221
222             c.setInterface(new String[] {
223                     IPluginReadServiceFilter.class.getName(),
224                     IContainerListener.class.getName() }, null);
225
226             c.add(createServiceDependency().setService(IController.class,
227                     "(name=Controller)").setCallbacks("setController",
228                     "unsetController").setRequired(true));
229             c.add(createServiceDependency().setService(
230                     IOFStatisticsManager.class).setCallbacks("setService",
231                     "unsetService").setRequired(true));
232         }
233
234         if (imp.equals(OFStatisticsManager.class)) {
235
236             c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
237                     IInventoryShimExternalListener.class.getName() }, null);
238
239             c.add(createServiceDependency().setService(IController.class,
240                     "(name=Controller)").setCallbacks("setController",
241                     "unsetController").setRequired(true));
242         }
243
244         if (imp.equals(DiscoveryService.class)) {
245             // export the service
246             c.setInterface(new String[] {
247                     IInventoryShimExternalListener.class.getName(),
248                     IDataPacketListen.class.getName(),
249                     IContainerListener.class.getName() }, null);
250
251             c.add(createServiceDependency().setService(IController.class,
252                     "(name=Controller)").setCallbacks("setController",
253                     "unsetController").setRequired(true));
254             c.add(createContainerServiceDependency(
255                     GlobalConstants.DEFAULT.toString()).setService(
256                     IPluginInInventoryService.class).setCallbacks(
257                     "setPluginInInventoryService",
258                     "unsetPluginInInventoryService").setRequired(true));
259             c.add(createServiceDependency().setService(IDataPacketMux.class)
260                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
261                     .setRequired(true));
262             c.add(createServiceDependency().setService(IDiscoveryService.class)
263                     .setCallbacks("setDiscoveryService",
264                             "unsetDiscoveryService").setRequired(true));
265         }
266
267         // DataPacket mux/demux services, which is teh actual engine
268         // doing the packet switching
269         if (imp.equals(DataPacketMuxDemux.class)) {
270             c.setInterface(new String[] { IDataPacketMux.class.getName(),
271                     IContainerListener.class.getName(),
272                     IInventoryShimExternalListener.class.getName() }, null);
273
274             c.add(createServiceDependency().setService(IController.class,
275                     "(name=Controller)").setCallbacks("setController",
276                     "unsetController").setRequired(true));
277             c.add(createServiceDependency().setService(
278                     IPluginOutDataPacketService.class).setCallbacks(
279                     "setPluginOutDataPacketService",
280                     "unsetPluginOutDataPacketService").setRequired(false));
281             // See if there is any local packet dispatcher
282             c.add(createServiceDependency().setService(IDataPacketListen.class)
283                     .setCallbacks("setIDataPacketListen",
284                             "unsetIDataPacketListen").setRequired(false));
285         }
286
287         if (imp.equals(InventoryServiceShim.class)) {
288             c.setInterface(new String[] { IContainerListener.class.getName() },
289                     null);
290
291             c.add(createServiceDependency().setService(IController.class,
292                     "(name=Controller)").setCallbacks("setController",
293                     "unsetController").setRequired(true));
294             c.add(createServiceDependency().setService(
295                     IInventoryShimInternalListener.class).setCallbacks(
296                     "setInventoryShimInternalListener",
297                     "unsetInventoryShimInternalListener").setRequired(true));
298             c.add(createServiceDependency().setService(
299                     IInventoryShimExternalListener.class).setCallbacks(
300                     "setInventoryShimExternalListener",
301                     "unsetInventoryShimExternalListener").setRequired(false));
302             c.add(createServiceDependency().setService(
303                     IOFStatisticsManager.class).setCallbacks(
304                     "setStatisticsManager", "unsetStatisticsManager")
305                     .setRequired(false));
306         }
307
308         if (imp.equals(TopologyServiceShim.class)) {
309             c.setInterface(new String[] { IDiscoveryService.class.getName(),
310                     IContainerListener.class.getName(),
311                     IRefreshInternalProvider.class.getName() }, null);
312             c.add(createServiceDependency().setService(
313                     ITopologyServiceShimListener.class).setCallbacks(
314                     "setTopologyServiceShimListener",
315                     "unsetTopologyServiceShimListener").setRequired(true));
316             c.add(createServiceDependency().setService(
317                     IOFStatisticsManager.class).setCallbacks(
318                     "setStatisticsManager", "unsetStatisticsManager")
319                     .setRequired(false));
320         }
321     }
322 }