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