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);
62 * Function that is used to communicate to dependency manager the list of
63 * known implementations for services inside a container
66 * @return An array containing all the CLASS objects that will be
67 * instantiated in order to get an fully working implementation
71 public Object[] getImplementations() {
72 Object[] res = { TopologyServices.class, DataPacketServices.class,
73 InventoryService.class, ReadService.class,
74 FlowProgrammerNotifier.class };
79 * Function that is called when configuration of the dependencies is
83 * dependency manager Component object, used for configuring the
84 * dependencies exported and imported
86 * Implementation class that is being configured, needed as long
87 * as the same routine can configure multiple implementations
88 * @param containerName
89 * The containerName being configured, this allow also optional
90 * per-container different behavior if needed, usually should not
94 public void configureInstance(Component c, Object imp, String containerName) {
95 if (imp.equals(TopologyServices.class)) {
96 // export the service to be used by SAL
98 new String[] { IPluginInTopologyService.class.getName(),
99 ITopologyServiceShimListener.class.getName() }, null);
100 // Hook the services coming in from SAL, as optional in
101 // case SAL is not yet there, could happen
102 c.add(createContainerServiceDependency(containerName)
103 .setService(IPluginOutTopologyService.class)
104 .setCallbacks("setPluginOutTopologyService",
105 "unsetPluginOutTopologyService").setRequired(false));
106 c.add(createServiceDependency()
107 .setService(IRefreshInternalProvider.class)
108 .setCallbacks("setRefreshInternalProvider",
109 "unsetRefreshInternalProvider").setRequired(false));
112 if (imp.equals(InventoryService.class)) {
113 // export the service
116 IPluginInInventoryService.class.getName(),
117 IInventoryShimInternalListener.class.getName(),
118 IInventoryProvider.class.getName() }, null);
120 // Now lets add a service dependency to make sure the
121 // provider of service exists
122 c.add(createServiceDependency()
123 .setService(IController.class, "(name=Controller)")
124 .setCallbacks("setController", "unsetController")
126 c.add(createContainerServiceDependency(containerName)
127 .setService(IPluginOutInventoryService.class)
128 .setCallbacks("setPluginOutInventoryServices",
129 "unsetPluginOutInventoryServices")
130 .setRequired(false));
133 if (imp.equals(DataPacketServices.class)) {
134 // export the service to be used by SAL
135 Dictionary<String, Object> props = new Hashtable<String, Object>();
136 // Set the protocolPluginType property which will be used
138 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
139 c.setInterface(IPluginInDataPacketService.class.getName(), props);
140 // Hook the services coming in from SAL, as optional in
141 // case SAL is not yet there, could happen
142 c.add(createServiceDependency()
143 .setService(IController.class, "(name=Controller)")
144 .setCallbacks("setController", "unsetController")
146 // This is required for the transmission to happen properly
147 c.add(createServiceDependency().setService(IDataPacketMux.class)
148 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
150 c.add(createContainerServiceDependency(containerName)
151 .setService(IPluginOutDataPacketService.class)
152 .setCallbacks("setPluginOutDataPacketService",
153 "unsetPluginOutDataPacketService")
154 .setRequired(false));
155 c.add(createServiceDependency()
156 .setService(IPluginOutConnectionService.class)
157 .setCallbacks("setIPluginOutConnectionService",
158 "unsetIPluginOutConnectionService")
162 if (imp.equals(ReadService.class)) {
163 // export the service to be used by SAL
164 Dictionary<String, Object> props = new Hashtable<String, Object>();
165 // Set the protocolPluginType property which will be used
167 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
168 c.setInterface(new String[] {
169 IReadFilterInternalListener.class.getName(),
170 IPluginInReadService.class.getName() }, props);
172 c.add(createServiceDependency()
173 .setService(IReadServiceFilter.class)
174 .setCallbacks("setService", "unsetService")
177 c.add(createContainerServiceDependency(containerName)
178 .setService(IPluginOutReadService.class)
179 .setCallbacks("setPluginOutReadServices",
180 "unsetPluginOutReadServices")
181 .setRequired(false));
183 c.add(createServiceDependency()
184 .setService(IPluginOutConnectionService.class)
185 .setCallbacks("setIPluginOutConnectionService",
186 "unsetIPluginOutConnectionService")
190 if (imp.equals(FlowProgrammerNotifier.class)) {
191 // export the service to be used by SAL
192 Dictionary<String, Object> props = new Hashtable<String, Object>();
193 // Set the protocolPluginType property which will be used
195 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
196 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
198 c.add(createContainerServiceDependency(containerName)
199 .setService(IPluginOutFlowProgrammerService.class)
200 .setCallbacks("setPluginOutFlowProgrammerService",
201 "unsetPluginOutFlowProgrammerService")
203 c.add(createServiceDependency()
204 .setService(IPluginOutConnectionService.class)
205 .setCallbacks("setIPluginOutConnectionService",
206 "unsetIPluginOutConnectionService")
212 * Function that is used to communicate to dependency manager the list of
213 * known implementations for services that are container independent.
216 * @return An array containing all the CLASS objects that will be
217 * instantiated in order to get an fully working implementation
221 public Object[] getGlobalImplementations() {
222 Object[] res = { Controller.class, OFStatisticsManager.class,
223 FlowProgrammerService.class, ReadServiceFilter.class,
224 DiscoveryService.class, DataPacketMuxDemux.class, InventoryService.class,
225 InventoryServiceShim.class, TopologyServiceShim.class };
230 * Function that is called when configuration of the dependencies is
234 * dependency manager Component object, used for configuring the
235 * dependencies exported and imported
237 * Implementation class that is being configured, needed as long
238 * as the same routine can configure multiple implementations
241 public void configureGlobalInstance(Component c, Object imp) {
243 if (imp.equals(Controller.class)) {
244 logger.debug("Activator configureGlobalInstance( ) is called");
245 Dictionary<String, Object> props = new Hashtable<String, Object>();
246 props.put("name", "Controller");
247 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
248 c.setInterface(new String[] { IController.class.getName(),
249 IPluginInConnectionService.class.getName()},
253 if (imp.equals(FlowProgrammerService.class)) {
254 // export the service to be used by SAL
255 Dictionary<String, Object> props = new Hashtable<String, Object>();
256 // Set the protocolPluginType property which will be used
258 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
260 new String[] { IPluginInFlowProgrammerService.class.getName(), IMessageListener.class.getName(),
261 IContainerListener.class.getName(), IInventoryShimExternalListener.class.getName(),
262 IContainerAware.class.getName() }, props);
264 c.add(createServiceDependency()
265 .setService(IController.class, "(name=Controller)")
266 .setCallbacks("setController", "unsetController")
269 c.add(createServiceDependency()
270 .setService(IFlowProgrammerNotifier.class)
271 .setCallbacks("setFlowProgrammerNotifier",
272 "unsetFlowProgrammerNotifier")
273 .setRequired(false));
275 c.add(createServiceDependency()
276 .setService(IPluginOutConnectionService.class)
277 .setCallbacks("setIPluginOutConnectionService",
278 "unsetIPluginOutConnectionService")
282 if (imp.equals(ReadServiceFilter.class)) {
284 c.setInterface(new String[] { IReadServiceFilter.class.getName(), IContainerListener.class.getName(),
285 IOFStatisticsListener.class.getName(), IContainerAware.class.getName() }, null);
287 c.add(createServiceDependency()
288 .setService(IController.class, "(name=Controller)")
289 .setCallbacks("setController", "unsetController")
291 c.add(createServiceDependency()
292 .setService(IOFStatisticsManager.class)
293 .setCallbacks("setService", "unsetService")
295 c.add(createServiceDependency()
296 .setService(IReadFilterInternalListener.class)
297 .setCallbacks("setReadFilterInternalListener",
298 "unsetReadFilterInternalListener")
299 .setRequired(false));
302 if (imp.equals(OFStatisticsManager.class)) {
304 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
305 IInventoryShimExternalListener.class.getName() }, null);
307 c.add(createServiceDependency()
308 .setService(IController.class, "(name=Controller)")
309 .setCallbacks("setController", "unsetController")
311 c.add(createServiceDependency()
312 .setService(IOFStatisticsListener.class)
313 .setCallbacks("setStatisticsListener",
314 "unsetStatisticsListener").setRequired(false));
317 if (imp.equals(DiscoveryService.class)) {
318 // export the service
320 new String[] { IInventoryShimExternalListener.class.getName(), IDataPacketListen.class.getName(),
321 IContainerListener.class.getName() }, null);
323 c.add(createServiceDependency()
324 .setService(IController.class, "(name=Controller)")
325 .setCallbacks("setController", "unsetController")
327 c.add(createContainerServiceDependency(
328 GlobalConstants.DEFAULT.toString())
329 .setService(IInventoryProvider.class)
330 .setCallbacks("setInventoryProvider",
331 "unsetInventoryProvider").setRequired(true));
332 c.add(createServiceDependency().setService(IDataPacketMux.class)
333 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
335 c.add(createServiceDependency()
336 .setService(IDiscoveryListener.class)
337 .setCallbacks("setDiscoveryListener",
338 "unsetDiscoveryListener").setRequired(true));
339 c.add(createServiceDependency()
340 .setService(IPluginOutConnectionService.class)
341 .setCallbacks("setIPluginOutConnectionService",
342 "unsetIPluginOutConnectionService")
346 // DataPacket mux/demux services, which is teh actual engine
347 // doing the packet switching
348 if (imp.equals(DataPacketMuxDemux.class)) {
349 c.setInterface(new String[] { IDataPacketMux.class.getName(), IContainerListener.class.getName(),
350 IInventoryShimExternalListener.class.getName(), IContainerAware.class.getName() }, null);
352 c.add(createServiceDependency()
353 .setService(IController.class, "(name=Controller)")
354 .setCallbacks("setController", "unsetController")
356 c.add(createServiceDependency()
357 .setService(IPluginOutDataPacketService.class)
358 .setCallbacks("setPluginOutDataPacketService",
359 "unsetPluginOutDataPacketService")
360 .setRequired(false));
361 // See if there is any local packet dispatcher
362 c.add(createServiceDependency()
363 .setService(IDataPacketListen.class)
364 .setCallbacks("setIDataPacketListen",
365 "unsetIDataPacketListen").setRequired(false));
366 c.add(createServiceDependency()
367 .setService(IPluginOutConnectionService.class)
368 .setCallbacks("setIPluginOutConnectionService",
369 "unsetIPluginOutConnectionService")
373 if (imp.equals(InventoryService.class)) {
374 // export the service
375 Dictionary<String, Object> props = new Hashtable<String, Object>();
376 props.put("scope", "Global");
379 new String[] { IPluginInInventoryService.class.getName(),
380 IInventoryShimInternalListener.class.getName(),
381 IInventoryProvider.class.getName() }, props);
383 // Now lets add a service dependency to make sure the
384 // provider of service exists
385 c.add(createServiceDependency()
386 .setService(IController.class, "(name=Controller)")
387 .setCallbacks("setController", "unsetController")
389 c.add(createServiceDependency()
390 .setService(IPluginOutInventoryService.class, "(scope=Global)")
391 .setCallbacks("setPluginOutInventoryServices",
392 "unsetPluginOutInventoryServices")
396 if (imp.equals(InventoryServiceShim.class)) {
397 c.setInterface(new String[] { IContainerListener.class.getName(),
398 IOFStatisticsListener.class.getName(), IContainerAware.class.getName() }, null);
400 c.add(createServiceDependency()
401 .setService(IController.class, "(name=Controller)")
402 .setCallbacks("setController", "unsetController")
404 c.add(createServiceDependency()
405 .setService(IInventoryShimInternalListener.class, "(!(scope=Global))")
406 .setCallbacks("setInventoryShimInternalListener",
407 "unsetInventoryShimInternalListener")
409 c.add(createServiceDependency()
410 .setService(IInventoryShimInternalListener.class, "(scope=Global)")
411 .setCallbacks("setInventoryShimGlobalInternalListener",
412 "unsetInventoryShimGlobalInternalListener")
414 c.add(createServiceDependency()
415 .setService(IInventoryShimExternalListener.class)
416 .setCallbacks("setInventoryShimExternalListener",
417 "unsetInventoryShimExternalListener")
418 .setRequired(false));
419 c.add(createServiceDependency()
420 .setService(IPluginOutConnectionService.class)
421 .setCallbacks("setIPluginOutConnectionService",
422 "unsetIPluginOutConnectionService")
426 if (imp.equals(TopologyServiceShim.class)) {
427 c.setInterface(new String[] { IDiscoveryListener.class.getName(), IContainerListener.class.getName(),
428 IRefreshInternalProvider.class.getName(), IInventoryShimExternalListener.class.getName(),
429 IContainerAware.class.getName() }, null);
430 c.add(createServiceDependency()
431 .setService(ITopologyServiceShimListener.class)
432 .setCallbacks("setTopologyServiceShimListener",
433 "unsetTopologyServiceShimListener")
435 c.add(createServiceDependency()
436 .setService(IOFStatisticsManager.class)
437 .setCallbacks("setStatisticsManager",
438 "unsetStatisticsManager").setRequired(false));