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.IContainerListener;
35 import org.opendaylight.controller.sal.core.Node;
36 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
37 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
38 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
39 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
40 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
41 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
42 import org.opendaylight.controller.sal.reader.IPluginInReadService;
43 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
44 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
45 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
46 import org.opendaylight.controller.sal.utils.GlobalConstants;
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.
69 * Function called when the activator stops just before the cleanup done by
70 * ComponentActivatorAbstractBase
74 public void destroy() {
78 * Function that is used to communicate to dependency manager the list of
79 * known implementations for services inside a container
82 * @return An array containing all the CLASS objects that will be
83 * instantiated in order to get an fully working implementation
87 public Object[] getImplementations() {
88 Object[] res = { TopologyServices.class, DataPacketServices.class,
89 InventoryService.class, ReadService.class,
90 FlowProgrammerNotifier.class };
95 * Function that is called when configuration of the dependencies is
99 * dependency manager Component object, used for configuring the
100 * dependencies exported and imported
102 * Implementation class that is being configured, needed as long
103 * as the same routine can configure multiple implementations
104 * @param containerName
105 * The containerName being configured, this allow also optional
106 * per-container different behavior if needed, usually should not
107 * be the case though.
110 public void configureInstance(Component c, Object imp, String containerName) {
111 if (imp.equals(TopologyServices.class)) {
112 // export the service to be used by SAL
114 new String[] { IPluginInTopologyService.class.getName(),
115 ITopologyServiceShimListener.class.getName() }, null);
116 // Hook the services coming in from SAL, as optional in
117 // case SAL is not yet there, could happen
118 c.add(createContainerServiceDependency(containerName)
119 .setService(IPluginOutTopologyService.class)
120 .setCallbacks("setPluginOutTopologyService",
121 "unsetPluginOutTopologyService").setRequired(false));
122 c.add(createServiceDependency()
123 .setService(IRefreshInternalProvider.class)
124 .setCallbacks("setRefreshInternalProvider",
125 "unsetRefreshInternalProvider").setRequired(false));
128 if (imp.equals(InventoryService.class)) {
129 // export the service
132 IPluginInInventoryService.class.getName(),
133 IInventoryShimInternalListener.class.getName(),
134 IInventoryProvider.class.getName() }, null);
136 // Now lets add a service dependency to make sure the
137 // provider of service exists
138 c.add(createServiceDependency()
139 .setService(IController.class, "(name=Controller)")
140 .setCallbacks("setController", "unsetController")
142 c.add(createContainerServiceDependency(containerName)
143 .setService(IPluginOutInventoryService.class)
144 .setCallbacks("setPluginOutInventoryServices",
145 "unsetPluginOutInventoryServices")
146 .setRequired(false));
149 if (imp.equals(DataPacketServices.class)) {
150 // export the service to be used by SAL
151 Dictionary<String, Object> props = new Hashtable<String, Object>();
152 // Set the protocolPluginType property which will be used
154 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
155 c.setInterface(IPluginInDataPacketService.class.getName(), props);
156 // Hook the services coming in from SAL, as optional in
157 // case SAL is not yet there, could happen
158 c.add(createServiceDependency()
159 .setService(IController.class, "(name=Controller)")
160 .setCallbacks("setController", "unsetController")
162 // This is required for the transmission to happen properly
163 c.add(createServiceDependency().setService(IDataPacketMux.class)
164 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
166 c.add(createContainerServiceDependency(containerName)
167 .setService(IPluginOutDataPacketService.class)
168 .setCallbacks("setPluginOutDataPacketService",
169 "unsetPluginOutDataPacketService")
170 .setRequired(false));
171 c.add(createServiceDependency()
172 .setService(IPluginOutConnectionService.class)
173 .setCallbacks("setIPluginOutConnectionService",
174 "unsetIPluginOutConnectionService")
178 if (imp.equals(ReadService.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
183 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
184 c.setInterface(new String[] {
185 IReadFilterInternalListener.class.getName(),
186 IPluginInReadService.class.getName() }, props);
188 c.add(createServiceDependency()
189 .setService(IReadServiceFilter.class)
190 .setCallbacks("setService", "unsetService")
193 c.add(createContainerServiceDependency(containerName)
194 .setService(IPluginOutReadService.class)
195 .setCallbacks("setPluginOutReadServices",
196 "unsetPluginOutReadServices")
197 .setRequired(false));
199 c.add(createServiceDependency()
200 .setService(IPluginOutConnectionService.class)
201 .setCallbacks("setIPluginOutConnectionService",
202 "unsetIPluginOutConnectionService")
206 if (imp.equals(FlowProgrammerNotifier.class)) {
207 // export the service to be used by SAL
208 Dictionary<String, Object> props = new Hashtable<String, Object>();
209 // Set the protocolPluginType property which will be used
211 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
212 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
214 c.add(createContainerServiceDependency(containerName)
215 .setService(IPluginOutFlowProgrammerService.class)
216 .setCallbacks("setPluginOutFlowProgrammerService",
217 "unsetPluginOutFlowProgrammerService")
219 c.add(createServiceDependency()
220 .setService(IPluginOutConnectionService.class)
221 .setCallbacks("setIPluginOutConnectionService",
222 "unsetIPluginOutConnectionService")
228 * Function that is used to communicate to dependency manager the list of
229 * known implementations for services that are container independent.
232 * @return An array containing all the CLASS objects that will be
233 * instantiated in order to get an fully working implementation
237 public Object[] getGlobalImplementations() {
238 Object[] res = { Controller.class, OFStatisticsManager.class,
239 FlowProgrammerService.class, ReadServiceFilter.class,
240 DiscoveryService.class, DataPacketMuxDemux.class, InventoryService.class,
241 InventoryServiceShim.class, TopologyServiceShim.class };
246 * Function that is called when configuration of the dependencies is
250 * dependency manager Component object, used for configuring the
251 * dependencies exported and imported
253 * Implementation class that is being configured, needed as long
254 * as the same routine can configure multiple implementations
257 public void configureGlobalInstance(Component c, Object imp) {
259 if (imp.equals(Controller.class)) {
260 logger.debug("Activator configureGlobalInstance( ) is called");
261 Dictionary<String, Object> props = new Hashtable<String, Object>();
262 props.put("name", "Controller");
263 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
264 c.setInterface(new String[] { IController.class.getName(),
265 IPluginInConnectionService.class.getName()},
269 if (imp.equals(FlowProgrammerService.class)) {
270 // export the service to be used by SAL
271 Dictionary<String, Object> props = new Hashtable<String, Object>();
272 // Set the protocolPluginType property which will be used
274 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
277 IPluginInFlowProgrammerService.class.getName(),
278 IMessageListener.class.getName(),
279 IContainerListener.class.getName(),
280 IInventoryShimExternalListener.class.getName() },
283 c.add(createServiceDependency()
284 .setService(IController.class, "(name=Controller)")
285 .setCallbacks("setController", "unsetController")
288 c.add(createServiceDependency()
289 .setService(IFlowProgrammerNotifier.class)
290 .setCallbacks("setFlowProgrammerNotifier",
291 "unsetsetFlowProgrammerNotifier")
292 .setRequired(false));
294 c.add(createServiceDependency()
295 .setService(IPluginOutConnectionService.class)
296 .setCallbacks("setIPluginOutConnectionService",
297 "unsetIPluginOutConnectionService")
301 if (imp.equals(ReadServiceFilter.class)) {
303 c.setInterface(new String[] {
304 IReadServiceFilter.class.getName(),
305 IContainerListener.class.getName(),
306 IOFStatisticsListener.class.getName() }, null);
308 c.add(createServiceDependency()
309 .setService(IController.class, "(name=Controller)")
310 .setCallbacks("setController", "unsetController")
312 c.add(createServiceDependency()
313 .setService(IOFStatisticsManager.class)
314 .setCallbacks("setService", "unsetService")
316 c.add(createServiceDependency()
317 .setService(IReadFilterInternalListener.class)
318 .setCallbacks("setReadFilterInternalListener",
319 "unsetReadFilterInternalListener")
320 .setRequired(false));
323 if (imp.equals(OFStatisticsManager.class)) {
325 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
326 IInventoryShimExternalListener.class.getName() }, null);
328 c.add(createServiceDependency()
329 .setService(IController.class, "(name=Controller)")
330 .setCallbacks("setController", "unsetController")
332 c.add(createServiceDependency()
333 .setService(IOFStatisticsListener.class)
334 .setCallbacks("setStatisticsListener",
335 "unsetStatisticsListener").setRequired(false));
338 if (imp.equals(DiscoveryService.class)) {
339 // export the service
342 IInventoryShimExternalListener.class.getName(),
343 IDataPacketListen.class.getName(),
344 IContainerListener.class.getName() }, null);
346 c.add(createServiceDependency()
347 .setService(IController.class, "(name=Controller)")
348 .setCallbacks("setController", "unsetController")
350 c.add(createContainerServiceDependency(
351 GlobalConstants.DEFAULT.toString())
352 .setService(IInventoryProvider.class)
353 .setCallbacks("setInventoryProvider",
354 "unsetInventoryProvider").setRequired(true));
355 c.add(createServiceDependency().setService(IDataPacketMux.class)
356 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
358 c.add(createServiceDependency()
359 .setService(IDiscoveryListener.class)
360 .setCallbacks("setDiscoveryListener",
361 "unsetDiscoveryListener").setRequired(true));
362 c.add(createServiceDependency()
363 .setService(IPluginOutConnectionService.class)
364 .setCallbacks("setIPluginOutConnectionService",
365 "unsetIPluginOutConnectionService")
369 // DataPacket mux/demux services, which is teh actual engine
370 // doing the packet switching
371 if (imp.equals(DataPacketMuxDemux.class)) {
372 c.setInterface(new String[] { IDataPacketMux.class.getName(),
373 IContainerListener.class.getName(),
374 IInventoryShimExternalListener.class.getName() }, null);
376 c.add(createServiceDependency()
377 .setService(IController.class, "(name=Controller)")
378 .setCallbacks("setController", "unsetController")
380 c.add(createServiceDependency()
381 .setService(IPluginOutDataPacketService.class)
382 .setCallbacks("setPluginOutDataPacketService",
383 "unsetPluginOutDataPacketService")
384 .setRequired(false));
385 // See if there is any local packet dispatcher
386 c.add(createServiceDependency()
387 .setService(IDataPacketListen.class)
388 .setCallbacks("setIDataPacketListen",
389 "unsetIDataPacketListen").setRequired(false));
390 c.add(createServiceDependency()
391 .setService(IPluginOutConnectionService.class)
392 .setCallbacks("setIPluginOutConnectionService",
393 "unsetIPluginOutConnectionService")
397 if (imp.equals(InventoryService.class)) {
398 // export the service
399 Dictionary<String, Object> props = new Hashtable<String, Object>();
400 props.put("scope", "Global");
403 new String[] { IPluginInInventoryService.class.getName(),
404 IInventoryShimInternalListener.class.getName(),
405 IInventoryProvider.class.getName() }, props);
407 // Now lets add a service dependency to make sure the
408 // provider of service exists
409 c.add(createServiceDependency()
410 .setService(IController.class, "(name=Controller)")
411 .setCallbacks("setController", "unsetController")
413 c.add(createServiceDependency()
414 .setService(IPluginOutInventoryService.class, "(scope=Global)")
415 .setCallbacks("setPluginOutInventoryServices",
416 "unsetPluginOutInventoryServices")
420 if (imp.equals(InventoryServiceShim.class)) {
421 c.setInterface(new String[] { IContainerListener.class.getName(),
422 IOFStatisticsListener.class.getName()}, null);
424 c.add(createServiceDependency()
425 .setService(IController.class, "(name=Controller)")
426 .setCallbacks("setController", "unsetController")
428 c.add(createServiceDependency()
429 .setService(IInventoryShimInternalListener.class, "(!(scope=Global))")
430 .setCallbacks("setInventoryShimInternalListener",
431 "unsetInventoryShimInternalListener")
433 c.add(createServiceDependency()
434 .setService(IInventoryShimInternalListener.class, "(scope=Global)")
435 .setCallbacks("setInventoryShimGlobalInternalListener",
436 "unsetInventoryShimGlobalInternalListener")
438 c.add(createServiceDependency()
439 .setService(IInventoryShimExternalListener.class)
440 .setCallbacks("setInventoryShimExternalListener",
441 "unsetInventoryShimExternalListener")
442 .setRequired(false));
443 c.add(createServiceDependency()
444 .setService(IPluginOutConnectionService.class)
445 .setCallbacks("setIPluginOutConnectionService",
446 "unsetIPluginOutConnectionService")
450 if (imp.equals(TopologyServiceShim.class)) {
451 c.setInterface(new String[] { IDiscoveryListener.class.getName(),
452 IContainerListener.class.getName(),
453 IRefreshInternalProvider.class.getName(),
454 IInventoryShimExternalListener.class.getName() }, null);
455 c.add(createServiceDependency()
456 .setService(ITopologyServiceShimListener.class)
457 .setCallbacks("setTopologyServiceShimListener",
458 "unsetTopologyServiceShimListener")
460 c.add(createServiceDependency()
461 .setService(IOFStatisticsManager.class)
462 .setCallbacks("setStatisticsManager",
463 "unsetStatisticsManager").setRequired(false));