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.openflowplugin.openflow.internal;
11 import java.util.Dictionary;
12 import java.util.Hashtable;
14 import org.apache.felix.dm.Component;
15 import org.opendaylight.controller.sal.connection.IPluginInConnectionService;
16 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
17 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
18 import org.opendaylight.controller.sal.core.IContainerListener;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
21 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
22 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
23 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
24 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
25 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
26 import org.opendaylight.controller.sal.reader.IPluginInReadService;
27 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
28 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
29 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
30 import org.opendaylight.controller.sal.utils.GlobalConstants;
31 import org.opendaylight.openflowplugin.openflow.IDataPacketListen;
32 import org.opendaylight.openflowplugin.openflow.IDataPacketMux;
33 import org.opendaylight.openflowplugin.openflow.IDiscoveryListener;
34 import org.opendaylight.openflowplugin.openflow.IFlowProgrammerNotifier;
35 import org.opendaylight.openflowplugin.openflow.IInventoryProvider;
36 import org.opendaylight.openflowplugin.openflow.IInventoryShimExternalListener;
37 import org.opendaylight.openflowplugin.openflow.IInventoryShimInternalListener;
38 import org.opendaylight.openflowplugin.openflow.IOFStatisticsListener;
39 import org.opendaylight.openflowplugin.openflow.IOFStatisticsManager;
40 import org.opendaylight.openflowplugin.openflow.IReadFilterInternalListener;
41 import org.opendaylight.openflowplugin.openflow.IReadServiceFilter;
42 import org.opendaylight.openflowplugin.openflow.IRefreshInternalProvider;
43 import org.opendaylight.openflowplugin.openflow.ITopologyServiceShimListener;
44 import org.opendaylight.openflowplugin.openflow.core.IController;
45 import org.opendaylight.openflowplugin.openflow.core.IMessageListener;
46 import org.opendaylight.openflowplugin.openflow.core.internal.Controller;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * Openflow protocol plugin Activator
55 public class Activator extends ComponentActivatorAbstractBase {
56 protected static final Logger logger = LoggerFactory
57 .getLogger(Activator.class);
60 * Function called when the activator starts just after some initializations
61 * are done by the ComponentActivatorAbstractBase.
68 * Function called when the activator stops just before the cleanup done by
69 * ComponentActivatorAbstractBase
72 public void destroy() {
76 * Function that is used to communicate to dependency manager the list of
77 * known implementations for services inside a container
80 * @return An array containing all the CLASS objects that will be
81 * instantiated in order to get an fully working implementation
84 public Object[] getImplementations() {
85 Object[] res = { TopologyServices.class, DataPacketServices.class,
86 InventoryService.class, ReadService.class,
87 FlowProgrammerNotifier.class };
92 * Function that is called when configuration of the dependencies is
96 * dependency manager Component object, used for configuring the
97 * dependencies exported and imported
99 * Implementation class that is being configured, needed as long
100 * as the same routine can configure multiple implementations
101 * @param containerName
102 * The containerName being configured, this allow also optional
103 * per-container different behavior if needed, usually should not
104 * be the case though.
106 public void configureInstance(Component c, Object imp, String containerName) {
107 if (imp.equals(TopologyServices.class)) {
108 // export the service to be used by SAL
110 new String[] { IPluginInTopologyService.class.getName(),
111 ITopologyServiceShimListener.class.getName() }, null);
112 // Hook the services coming in from SAL, as optional in
113 // case SAL is not yet there, could happen
114 c.add(createContainerServiceDependency(containerName)
115 .setService(IPluginOutTopologyService.class)
116 .setCallbacks("setPluginOutTopologyService",
117 "unsetPluginOutTopologyService").setRequired(false));
118 c.add(createServiceDependency()
119 .setService(IRefreshInternalProvider.class)
120 .setCallbacks("setRefreshInternalProvider",
121 "unsetRefreshInternalProvider").setRequired(false));
124 if (imp.equals(InventoryService.class)) {
125 // export the service
128 IPluginInInventoryService.class.getName(),
129 IInventoryShimInternalListener.class.getName(),
130 IInventoryProvider.class.getName() }, null);
132 // Now lets add a service dependency to make sure the
133 // provider of service exists
134 c.add(createServiceDependency()
135 .setService(IController.class, "(name=Controller)")
136 .setCallbacks("setController", "unsetController")
138 c.add(createContainerServiceDependency(containerName)
139 .setService(IPluginOutInventoryService.class)
140 .setCallbacks("setPluginOutInventoryServices",
141 "unsetPluginOutInventoryServices")
142 .setRequired(false));
145 if (imp.equals(DataPacketServices.class)) {
146 // export the service to be used by SAL
147 Dictionary<String, Object> props = new Hashtable<String, Object>();
148 // Set the protocolPluginType property which will be used
150 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
151 c.setInterface(IPluginInDataPacketService.class.getName(), props);
152 // Hook the services coming in from SAL, as optional in
153 // case SAL is not yet there, could happen
154 c.add(createServiceDependency()
155 .setService(IController.class, "(name=Controller)")
156 .setCallbacks("setController", "unsetController")
158 // This is required for the transmission to happen properly
159 c.add(createServiceDependency().setService(IDataPacketMux.class)
160 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
162 c.add(createContainerServiceDependency(containerName)
163 .setService(IPluginOutDataPacketService.class)
164 .setCallbacks("setPluginOutDataPacketService",
165 "unsetPluginOutDataPacketService")
166 .setRequired(false));
167 c.add(createServiceDependency()
168 .setService(IPluginOutConnectionService.class)
169 .setCallbacks("setIPluginOutConnectionService",
170 "unsetIPluginOutConnectionService")
171 .setRequired(false));
174 if (imp.equals(ReadService.class)) {
175 // export the service to be used by SAL
176 Dictionary<String, Object> props = new Hashtable<String, Object>();
177 // Set the protocolPluginType property which will be used
179 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
180 c.setInterface(new String[] {
181 IReadFilterInternalListener.class.getName(),
182 IPluginInReadService.class.getName() }, props);
184 c.add(createServiceDependency()
185 .setService(IReadServiceFilter.class)
186 .setCallbacks("setService", "unsetService")
189 c.add(createContainerServiceDependency(containerName)
190 .setService(IPluginOutReadService.class)
191 .setCallbacks("setPluginOutReadServices",
192 "unsetPluginOutReadServices")
193 .setRequired(false));
195 c.add(createServiceDependency()
196 .setService(IPluginOutConnectionService.class)
197 .setCallbacks("setIPluginOutConnectionService",
198 "unsetIPluginOutConnectionService")
199 .setRequired(false));
202 if (imp.equals(FlowProgrammerNotifier.class)) {
203 // export the service to be used by SAL
204 Dictionary<String, Object> props = new Hashtable<String, Object>();
205 // Set the protocolPluginType property which will be used
207 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
208 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
210 c.add(createContainerServiceDependency(containerName)
211 .setService(IPluginOutFlowProgrammerService.class)
212 .setCallbacks("setPluginOutFlowProgrammerService",
213 "unsetPluginOutFlowProgrammerService")
215 c.add(createServiceDependency()
216 .setService(IPluginOutConnectionService.class)
217 .setCallbacks("setIPluginOutConnectionService",
218 "unsetIPluginOutConnectionService")
219 .setRequired(false));
224 * Function that is used to communicate to dependency manager the list of
225 * known implementations for services that are container independent.
228 * @return An array containing all the CLASS objects that will be
229 * instantiated in order to get an fully working implementation
232 public Object[] getGlobalImplementations() {
233 Object[] res = { Controller.class, OFStatisticsManager.class,
234 FlowProgrammerService.class, ReadServiceFilter.class,
235 DiscoveryService.class, DataPacketMuxDemux.class, InventoryService.class,
236 InventoryServiceShim.class, TopologyServiceShim.class };
241 * Function that is called when configuration of the dependencies is
245 * dependency manager Component object, used for configuring the
246 * dependencies exported and imported
248 * Implementation class that is being configured, needed as long
249 * as the same routine can configure multiple implementations
251 public void configureGlobalInstance(Component c, Object imp) {
253 if (imp.equals(Controller.class)) {
254 logger.debug("Activator configureGlobalInstance( ) is called");
255 Dictionary<String, Object> props = new Hashtable<String, Object>();
256 props.put("name", "Controller");
257 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
258 c.setInterface(new String[] { IController.class.getName(),
259 IPluginInConnectionService.class.getName()},
263 if (imp.equals(FlowProgrammerService.class)) {
264 // export the service to be used by SAL
265 Dictionary<String, Object> props = new Hashtable<String, Object>();
266 // Set the protocolPluginType property which will be used
268 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
271 IPluginInFlowProgrammerService.class.getName(),
272 IMessageListener.class.getName(),
273 IContainerListener.class.getName(),
274 IInventoryShimExternalListener.class.getName() },
277 c.add(createServiceDependency()
278 .setService(IController.class, "(name=Controller)")
279 .setCallbacks("setController", "unsetController")
282 c.add(createServiceDependency()
283 .setService(IFlowProgrammerNotifier.class)
284 .setCallbacks("setFlowProgrammerNotifier",
285 "unsetsetFlowProgrammerNotifier")
286 .setRequired(false));
288 c.add(createServiceDependency()
289 .setService(IPluginOutConnectionService.class)
290 .setCallbacks("setIPluginOutConnectionService",
291 "unsetIPluginOutConnectionService")
292 .setRequired(false));
295 if (imp.equals(ReadServiceFilter.class)) {
297 c.setInterface(new String[] {
298 IReadServiceFilter.class.getName(),
299 IContainerListener.class.getName(),
300 IOFStatisticsListener.class.getName() }, null);
302 c.add(createServiceDependency()
303 .setService(IController.class, "(name=Controller)")
304 .setCallbacks("setController", "unsetController")
306 c.add(createServiceDependency()
307 .setService(IOFStatisticsManager.class)
308 .setCallbacks("setService", "unsetService")
310 c.add(createServiceDependency()
311 .setService(IReadFilterInternalListener.class)
312 .setCallbacks("setReadFilterInternalListener",
313 "unsetReadFilterInternalListener")
314 .setRequired(false));
317 if (imp.equals(OFStatisticsManager.class)) {
319 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
320 IInventoryShimExternalListener.class.getName() }, null);
322 c.add(createServiceDependency()
323 .setService(IController.class, "(name=Controller)")
324 .setCallbacks("setController", "unsetController")
326 c.add(createServiceDependency()
327 .setService(IOFStatisticsListener.class)
328 .setCallbacks("setStatisticsListener",
329 "unsetStatisticsListener").setRequired(false));
332 if (imp.equals(DiscoveryService.class)) {
333 // export the service
336 IInventoryShimExternalListener.class.getName(),
337 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")
360 .setRequired(false));
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(),
367 IContainerListener.class.getName(),
368 IInventoryShimExternalListener.class.getName() }, null);
370 c.add(createServiceDependency()
371 .setService(IController.class, "(name=Controller)")
372 .setCallbacks("setController", "unsetController")
374 c.add(createServiceDependency()
375 .setService(IPluginOutDataPacketService.class)
376 .setCallbacks("setPluginOutDataPacketService",
377 "unsetPluginOutDataPacketService")
378 .setRequired(false));
379 // See if there is any local packet dispatcher
380 c.add(createServiceDependency()
381 .setService(IDataPacketListen.class)
382 .setCallbacks("setIDataPacketListen",
383 "unsetIDataPacketListen").setRequired(false));
384 c.add(createServiceDependency()
385 .setService(IPluginOutConnectionService.class)
386 .setCallbacks("setIPluginOutConnectionService",
387 "unsetIPluginOutConnectionService")
388 .setRequired(false));
391 if (imp.equals(InventoryService.class)) {
392 // export the service
393 Dictionary<String, Object> props = new Hashtable<String, Object>();
394 props.put("scope", "Global");
397 new String[] { IPluginInInventoryService.class.getName(),
398 IInventoryShimInternalListener.class.getName(),
399 IInventoryProvider.class.getName() }, props);
401 // Now lets add a service dependency to make sure the
402 // provider of service exists
403 c.add(createServiceDependency()
404 .setService(IController.class, "(name=Controller)")
405 .setCallbacks("setController", "unsetController")
407 c.add(createServiceDependency()
408 .setService(IPluginOutInventoryService.class, "(scope=Global)")
409 .setCallbacks("setPluginOutInventoryServices",
410 "unsetPluginOutInventoryServices")
411 .setRequired(false));
414 if (imp.equals(InventoryServiceShim.class)) {
415 c.setInterface(new String[] { IContainerListener.class.getName(),
416 IOFStatisticsListener.class.getName()}, null);
418 c.add(createServiceDependency()
419 .setService(IController.class, "(name=Controller)")
420 .setCallbacks("setController", "unsetController")
422 c.add(createServiceDependency()
423 .setService(IInventoryShimInternalListener.class, "(!(scope=Global))")
424 .setCallbacks("setInventoryShimInternalListener",
425 "unsetInventoryShimInternalListener")
427 c.add(createServiceDependency()
428 .setService(IInventoryShimInternalListener.class, "(scope=Global)")
429 .setCallbacks("setInventoryShimGlobalInternalListener",
430 "unsetInventoryShimGlobalInternalListener")
432 c.add(createServiceDependency()
433 .setService(IInventoryShimExternalListener.class)
434 .setCallbacks("setInventoryShimExternalListener",
435 "unsetInventoryShimExternalListener")
436 .setRequired(false));
437 c.add(createServiceDependency()
438 .setService(IPluginOutConnectionService.class)
439 .setCallbacks("setIPluginOutConnectionService",
440 "unsetIPluginOutConnectionService")
441 .setRequired(false));
444 if (imp.equals(TopologyServiceShim.class)) {
445 c.setInterface(new String[] { IDiscoveryListener.class.getName(),
446 IContainerListener.class.getName(),
447 IRefreshInternalProvider.class.getName(),
448 IInventoryShimExternalListener.class.getName() }, null);
449 c.add(createServiceDependency()
450 .setService(ITopologyServiceShimListener.class)
451 .setCallbacks("setTopologyServiceShimListener",
452 "unsetTopologyServiceShimListener")
454 c.add(createServiceDependency()
455 .setService(IOFStatisticsManager.class)
456 .setCallbacks("setStatisticsManager",
457 "unsetStatisticsManager").setRequired(false));