2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.protocol_plugin.openflow.internal;
11 import java.util.Dictionary;
12 import java.util.Hashtable;
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.IOFStatisticsListener;
23 import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager;
24 import org.opendaylight.controller.protocol_plugin.openflow.IReadFilterInternalListener;
25 import org.opendaylight.controller.protocol_plugin.openflow.IReadServiceFilter;
26 import org.opendaylight.controller.protocol_plugin.openflow.IRefreshInternalProvider;
27 import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener;
28 import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
29 import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener;
30 import org.opendaylight.controller.protocol_plugin.openflow.core.internal.Controller;
31 import org.opendaylight.controller.sal.connection.IPluginInConnectionService;
32 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
33 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
34 import org.opendaylight.controller.sal.core.IContainerAware;
35 import org.opendaylight.controller.sal.core.IContainerListener;
36 import org.opendaylight.controller.sal.core.Node;
37 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
38 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
39 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
40 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
41 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
42 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
43 import org.opendaylight.controller.sal.reader.IPluginInReadService;
44 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
45 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
46 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
47 import org.opendaylight.controller.sal.utils.GlobalConstants;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
52 * Openflow protocol plugin Activator
56 public class Activator extends ComponentActivatorAbstractBase {
57 protected static final Logger logger = LoggerFactory
58 .getLogger(Activator.class);
61 * Function called when the activator starts just after some initializations
62 * are done by the ComponentActivatorAbstractBase.
70 * Function called when the activator stops just before the cleanup done by
71 * ComponentActivatorAbstractBase
75 public void destroy() {
79 * Function that is used to communicate to dependency manager the list of
80 * known implementations for services inside a container
83 * @return An array containing all the CLASS objects that will be
84 * instantiated in order to get an fully working implementation
88 public Object[] getImplementations() {
89 Object[] res = { TopologyServices.class, DataPacketServices.class,
90 InventoryService.class, ReadService.class,
91 FlowProgrammerNotifier.class };
96 * Function that is called when configuration of the dependencies is
100 * dependency manager Component object, used for configuring the
101 * dependencies exported and imported
103 * Implementation class that is being configured, needed as long
104 * as the same routine can configure multiple implementations
105 * @param containerName
106 * The containerName being configured, this allow also optional
107 * per-container different behavior if needed, usually should not
108 * be the case though.
111 public void configureInstance(Component c, Object imp, String containerName) {
112 if (imp.equals(TopologyServices.class)) {
113 // export the service to be used by SAL
115 new String[] { IPluginInTopologyService.class.getName(),
116 ITopologyServiceShimListener.class.getName() }, null);
117 // Hook the services coming in from SAL, as optional in
118 // case SAL is not yet there, could happen
119 c.add(createContainerServiceDependency(containerName)
120 .setService(IPluginOutTopologyService.class)
121 .setCallbacks("setPluginOutTopologyService",
122 "unsetPluginOutTopologyService").setRequired(false));
123 c.add(createServiceDependency()
124 .setService(IRefreshInternalProvider.class)
125 .setCallbacks("setRefreshInternalProvider",
126 "unsetRefreshInternalProvider").setRequired(false));
129 if (imp.equals(InventoryService.class)) {
130 // export the service
133 IPluginInInventoryService.class.getName(),
134 IInventoryShimInternalListener.class.getName(),
135 IInventoryProvider.class.getName() }, null);
137 // Now lets add a service dependency to make sure the
138 // provider of service exists
139 c.add(createServiceDependency()
140 .setService(IController.class, "(name=Controller)")
141 .setCallbacks("setController", "unsetController")
143 c.add(createContainerServiceDependency(containerName)
144 .setService(IPluginOutInventoryService.class)
145 .setCallbacks("setPluginOutInventoryServices",
146 "unsetPluginOutInventoryServices")
147 .setRequired(false));
150 if (imp.equals(DataPacketServices.class)) {
151 // export the service to be used by SAL
152 Dictionary<String, Object> props = new Hashtable<String, Object>();
153 // Set the protocolPluginType property which will be used
155 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
156 c.setInterface(IPluginInDataPacketService.class.getName(), props);
157 // Hook the services coming in from SAL, as optional in
158 // case SAL is not yet there, could happen
159 c.add(createServiceDependency()
160 .setService(IController.class, "(name=Controller)")
161 .setCallbacks("setController", "unsetController")
163 // This is required for the transmission to happen properly
164 c.add(createServiceDependency().setService(IDataPacketMux.class)
165 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
167 c.add(createContainerServiceDependency(containerName)
168 .setService(IPluginOutDataPacketService.class)
169 .setCallbacks("setPluginOutDataPacketService",
170 "unsetPluginOutDataPacketService")
171 .setRequired(false));
172 c.add(createServiceDependency()
173 .setService(IPluginOutConnectionService.class)
174 .setCallbacks("setIPluginOutConnectionService",
175 "unsetIPluginOutConnectionService")
179 if (imp.equals(ReadService.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
184 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
185 c.setInterface(new String[] {
186 IReadFilterInternalListener.class.getName(),
187 IPluginInReadService.class.getName() }, props);
189 c.add(createServiceDependency()
190 .setService(IReadServiceFilter.class)
191 .setCallbacks("setService", "unsetService")
194 c.add(createContainerServiceDependency(containerName)
195 .setService(IPluginOutReadService.class)
196 .setCallbacks("setPluginOutReadServices",
197 "unsetPluginOutReadServices")
198 .setRequired(false));
200 c.add(createServiceDependency()
201 .setService(IPluginOutConnectionService.class)
202 .setCallbacks("setIPluginOutConnectionService",
203 "unsetIPluginOutConnectionService")
207 if (imp.equals(FlowProgrammerNotifier.class)) {
208 // export the service to be used by SAL
209 Dictionary<String, Object> props = new Hashtable<String, Object>();
210 // Set the protocolPluginType property which will be used
212 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
213 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
215 c.add(createContainerServiceDependency(containerName)
216 .setService(IPluginOutFlowProgrammerService.class)
217 .setCallbacks("setPluginOutFlowProgrammerService",
218 "unsetPluginOutFlowProgrammerService")
220 c.add(createServiceDependency()
221 .setService(IPluginOutConnectionService.class)
222 .setCallbacks("setIPluginOutConnectionService",
223 "unsetIPluginOutConnectionService")
229 * Function that is used to communicate to dependency manager the list of
230 * known implementations for services that are container independent.
233 * @return An array containing all the CLASS objects that will be
234 * instantiated in order to get an fully working implementation
238 public Object[] getGlobalImplementations() {
239 Object[] res = { Controller.class, OFStatisticsManager.class,
240 FlowProgrammerService.class, ReadServiceFilter.class,
241 DiscoveryService.class, DataPacketMuxDemux.class, InventoryService.class,
242 InventoryServiceShim.class, TopologyServiceShim.class };
247 * Function that is called when configuration of the dependencies is
251 * dependency manager Component object, used for configuring the
252 * dependencies exported and imported
254 * Implementation class that is being configured, needed as long
255 * as the same routine can configure multiple implementations
258 public void configureGlobalInstance(Component c, Object imp) {
260 if (imp.equals(Controller.class)) {
261 logger.debug("Activator configureGlobalInstance( ) is called");
262 Dictionary<String, Object> props = new Hashtable<String, Object>();
263 props.put("name", "Controller");
264 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
265 c.setInterface(new String[] { IController.class.getName(),
266 IPluginInConnectionService.class.getName()},
270 if (imp.equals(FlowProgrammerService.class)) {
271 // export the service to be used by SAL
272 Dictionary<String, Object> props = new Hashtable<String, Object>();
273 // Set the protocolPluginType property which will be used
275 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
277 new String[] { IPluginInFlowProgrammerService.class.getName(), IMessageListener.class.getName(),
278 IContainerListener.class.getName(), IInventoryShimExternalListener.class.getName(),
279 IContainerAware.class.getName() }, props);
281 c.add(createServiceDependency()
282 .setService(IController.class, "(name=Controller)")
283 .setCallbacks("setController", "unsetController")
286 c.add(createServiceDependency()
287 .setService(IFlowProgrammerNotifier.class)
288 .setCallbacks("setFlowProgrammerNotifier",
289 "unsetsetFlowProgrammerNotifier")
290 .setRequired(false));
292 c.add(createServiceDependency()
293 .setService(IPluginOutConnectionService.class)
294 .setCallbacks("setIPluginOutConnectionService",
295 "unsetIPluginOutConnectionService")
299 if (imp.equals(ReadServiceFilter.class)) {
301 c.setInterface(new String[] { IReadServiceFilter.class.getName(), IContainerListener.class.getName(),
302 IOFStatisticsListener.class.getName(), IContainerAware.class.getName() }, null);
304 c.add(createServiceDependency()
305 .setService(IController.class, "(name=Controller)")
306 .setCallbacks("setController", "unsetController")
308 c.add(createServiceDependency()
309 .setService(IOFStatisticsManager.class)
310 .setCallbacks("setService", "unsetService")
312 c.add(createServiceDependency()
313 .setService(IReadFilterInternalListener.class)
314 .setCallbacks("setReadFilterInternalListener",
315 "unsetReadFilterInternalListener")
316 .setRequired(false));
319 if (imp.equals(OFStatisticsManager.class)) {
321 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
322 IInventoryShimExternalListener.class.getName() }, null);
324 c.add(createServiceDependency()
325 .setService(IController.class, "(name=Controller)")
326 .setCallbacks("setController", "unsetController")
328 c.add(createServiceDependency()
329 .setService(IOFStatisticsListener.class)
330 .setCallbacks("setStatisticsListener",
331 "unsetStatisticsListener").setRequired(false));
334 if (imp.equals(DiscoveryService.class)) {
335 // export the service
337 new String[] { IInventoryShimExternalListener.class.getName(), IDataPacketListen.class.getName(),
338 IContainerListener.class.getName() }, null);
340 c.add(createServiceDependency()
341 .setService(IController.class, "(name=Controller)")
342 .setCallbacks("setController", "unsetController")
344 c.add(createContainerServiceDependency(
345 GlobalConstants.DEFAULT.toString())
346 .setService(IInventoryProvider.class)
347 .setCallbacks("setInventoryProvider",
348 "unsetInventoryProvider").setRequired(true));
349 c.add(createServiceDependency().setService(IDataPacketMux.class)
350 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
352 c.add(createServiceDependency()
353 .setService(IDiscoveryListener.class)
354 .setCallbacks("setDiscoveryListener",
355 "unsetDiscoveryListener").setRequired(true));
356 c.add(createServiceDependency()
357 .setService(IPluginOutConnectionService.class)
358 .setCallbacks("setIPluginOutConnectionService",
359 "unsetIPluginOutConnectionService")
363 // DataPacket mux/demux services, which is teh actual engine
364 // doing the packet switching
365 if (imp.equals(DataPacketMuxDemux.class)) {
366 c.setInterface(new String[] { IDataPacketMux.class.getName(), IContainerListener.class.getName(),
367 IInventoryShimExternalListener.class.getName(), IContainerAware.class.getName() }, null);
369 c.add(createServiceDependency()
370 .setService(IController.class, "(name=Controller)")
371 .setCallbacks("setController", "unsetController")
373 c.add(createServiceDependency()
374 .setService(IPluginOutDataPacketService.class)
375 .setCallbacks("setPluginOutDataPacketService",
376 "unsetPluginOutDataPacketService")
377 .setRequired(false));
378 // See if there is any local packet dispatcher
379 c.add(createServiceDependency()
380 .setService(IDataPacketListen.class)
381 .setCallbacks("setIDataPacketListen",
382 "unsetIDataPacketListen").setRequired(false));
383 c.add(createServiceDependency()
384 .setService(IPluginOutConnectionService.class)
385 .setCallbacks("setIPluginOutConnectionService",
386 "unsetIPluginOutConnectionService")
390 if (imp.equals(InventoryService.class)) {
391 // export the service
392 Dictionary<String, Object> props = new Hashtable<String, Object>();
393 props.put("scope", "Global");
396 new String[] { IPluginInInventoryService.class.getName(),
397 IInventoryShimInternalListener.class.getName(),
398 IInventoryProvider.class.getName() }, props);
400 // Now lets add a service dependency to make sure the
401 // provider of service exists
402 c.add(createServiceDependency()
403 .setService(IController.class, "(name=Controller)")
404 .setCallbacks("setController", "unsetController")
406 c.add(createServiceDependency()
407 .setService(IPluginOutInventoryService.class, "(scope=Global)")
408 .setCallbacks("setPluginOutInventoryServices",
409 "unsetPluginOutInventoryServices")
413 if (imp.equals(InventoryServiceShim.class)) {
414 c.setInterface(new String[] { IContainerListener.class.getName(),
415 IOFStatisticsListener.class.getName(), IContainerAware.class.getName() }, null);
417 c.add(createServiceDependency()
418 .setService(IController.class, "(name=Controller)")
419 .setCallbacks("setController", "unsetController")
421 c.add(createServiceDependency()
422 .setService(IInventoryShimInternalListener.class, "(!(scope=Global))")
423 .setCallbacks("setInventoryShimInternalListener",
424 "unsetInventoryShimInternalListener")
426 c.add(createServiceDependency()
427 .setService(IInventoryShimInternalListener.class, "(scope=Global)")
428 .setCallbacks("setInventoryShimGlobalInternalListener",
429 "unsetInventoryShimGlobalInternalListener")
431 c.add(createServiceDependency()
432 .setService(IInventoryShimExternalListener.class)
433 .setCallbacks("setInventoryShimExternalListener",
434 "unsetInventoryShimExternalListener")
435 .setRequired(false));
436 c.add(createServiceDependency()
437 .setService(IPluginOutConnectionService.class)
438 .setCallbacks("setIPluginOutConnectionService",
439 "unsetIPluginOutConnectionService")
443 if (imp.equals(TopologyServiceShim.class)) {
444 c.setInterface(new String[] { IDiscoveryListener.class.getName(), IContainerListener.class.getName(),
445 IRefreshInternalProvider.class.getName(), IInventoryShimExternalListener.class.getName(),
446 IContainerAware.class.getName() }, null);
447 c.add(createServiceDependency()
448 .setService(ITopologyServiceShimListener.class)
449 .setCallbacks("setTopologyServiceShimListener",
450 "unsetTopologyServiceShimListener")
452 c.add(createServiceDependency()
453 .setService(IOFStatisticsManager.class)
454 .setCallbacks("setStatisticsManager",
455 "unsetStatisticsManager").setRequired(false));