Merge "Controller to listen to expired flow removal message - Added plugin-to-FM...
[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                             IStatisticsListener.class.getName(),
125                             IInventoryShimInternalListener.class.getName() },
126                     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() }, props);
242
243             c.add(createServiceDependency()
244                     .setService(IController.class, "(name=Controller)")
245                     .setCallbacks("setController", "unsetController")
246                     .setRequired(true));
247
248             c.add(createServiceDependency()
249                     .setService(IFlowProgrammerNotifier.class)
250                     .setCallbacks("setFlowProgrammerNotifier",
251                             "unsetsetFlowProgrammerNotifier")
252                     .setRequired(false));
253
254         }
255
256         if (imp.equals(ReadServiceFilter.class)) {
257
258             c.setInterface(
259                     new String[] { IPluginReadServiceFilter.class.getName(),
260                             IContainerListener.class.getName() }, null);
261
262             c.add(createServiceDependency()
263                     .setService(IController.class, "(name=Controller)")
264                     .setCallbacks("setController", "unsetController")
265                     .setRequired(true));
266             c.add(createServiceDependency()
267                     .setService(IOFStatisticsManager.class)
268                     .setCallbacks("setService", "unsetService")
269                     .setRequired(true));
270         }
271
272         if (imp.equals(OFStatisticsManager.class)) {
273
274             c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
275                     IInventoryShimExternalListener.class.getName() }, null);
276
277             c.add(createServiceDependency()
278                     .setService(IController.class, "(name=Controller)")
279                     .setCallbacks("setController", "unsetController")
280                     .setRequired(true));
281             c.add(createServiceDependency()
282                     .setService(IStatisticsListener.class)
283                     .setCallbacks("setStatisticsListener",
284                             "unsetStatisticsListener").setRequired(false));
285         }
286
287         if (imp.equals(DiscoveryService.class)) {
288             // export the service
289             c.setInterface(
290                     new String[] {
291                             IInventoryShimExternalListener.class.getName(),
292                             IDataPacketListen.class.getName(),
293                             IContainerListener.class.getName() }, null);
294
295             c.add(createServiceDependency()
296                     .setService(IController.class, "(name=Controller)")
297                     .setCallbacks("setController", "unsetController")
298                     .setRequired(true));
299             c.add(createContainerServiceDependency(
300                     GlobalConstants.DEFAULT.toString())
301                     .setService(IPluginInInventoryService.class)
302                     .setCallbacks("setPluginInInventoryService",
303                             "unsetPluginInInventoryService").setRequired(true));
304             c.add(createServiceDependency().setService(IDataPacketMux.class)
305                     .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
306                     .setRequired(true));
307             c.add(createServiceDependency()
308                     .setService(IDiscoveryService.class)
309                     .setCallbacks("setDiscoveryService",
310                             "unsetDiscoveryService").setRequired(true));
311         }
312
313         // DataPacket mux/demux services, which is teh actual engine
314         // doing the packet switching
315         if (imp.equals(DataPacketMuxDemux.class)) {
316             c.setInterface(new String[] { IDataPacketMux.class.getName(),
317                     IContainerListener.class.getName(),
318                     IInventoryShimExternalListener.class.getName() }, null);
319
320             c.add(createServiceDependency()
321                     .setService(IController.class, "(name=Controller)")
322                     .setCallbacks("setController", "unsetController")
323                     .setRequired(true));
324             c.add(createServiceDependency()
325                     .setService(IPluginOutDataPacketService.class)
326                     .setCallbacks("setPluginOutDataPacketService",
327                             "unsetPluginOutDataPacketService")
328                     .setRequired(false));
329             // See if there is any local packet dispatcher
330             c.add(createServiceDependency()
331                     .setService(IDataPacketListen.class)
332                     .setCallbacks("setIDataPacketListen",
333                             "unsetIDataPacketListen").setRequired(false));
334         }
335
336         if (imp.equals(InventoryServiceShim.class)) {
337             c.setInterface(new String[] { IContainerListener.class.getName() },
338                     null);
339
340             c.add(createServiceDependency()
341                     .setService(IController.class, "(name=Controller)")
342                     .setCallbacks("setController", "unsetController")
343                     .setRequired(true));
344             c.add(createServiceDependency()
345                     .setService(IInventoryShimInternalListener.class)
346                     .setCallbacks("setInventoryShimInternalListener",
347                             "unsetInventoryShimInternalListener")
348                     .setRequired(true));
349             c.add(createServiceDependency()
350                     .setService(IInventoryShimExternalListener.class)
351                     .setCallbacks("setInventoryShimExternalListener",
352                             "unsetInventoryShimExternalListener")
353                     .setRequired(false));
354         }
355
356         if (imp.equals(TopologyServiceShim.class)) {
357             c.setInterface(new String[] { IDiscoveryService.class.getName(),
358                     IContainerListener.class.getName(),
359                     IRefreshInternalProvider.class.getName() }, null);
360             c.add(createServiceDependency()
361                     .setService(ITopologyServiceShimListener.class)
362                     .setCallbacks("setTopologyServiceShimListener",
363                             "unsetTopologyServiceShimListener")
364                     .setRequired(true));
365             c.add(createServiceDependency()
366                     .setService(IOFStatisticsManager.class)
367                     .setCallbacks("setStatisticsManager",
368                             "unsetStatisticsManager").setRequired(false));
369         }
370     }
371 }