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