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.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.IStatisticsServiceShimListener;
25 import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener;
26 import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
27 import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener;
28 import org.opendaylight.controller.protocol_plugin.openflow.core.internal.EnhancedController;
29 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
30 import org.opendaylight.controller.sal.core.IContainerListener;
31 import org.opendaylight.controller.sal.core.Node;
32 import org.opendaylight.controller.sal.discovery.IDiscoveryService;
33 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
34 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
35 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
36 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
37 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
38 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
39 import org.opendaylight.controller.sal.reader.IPluginInReadService;
40 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
41 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
42 import org.opendaylight.controller.sal.utils.GlobalConstants;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * Openflow protocol plugin Activator
51 public class Activator extends ComponentActivatorAbstractBase {
52 protected static final Logger logger = LoggerFactory
53 .getLogger(Activator.class);
56 * Function called when the activator starts just after some initializations
57 * are done by the ComponentActivatorAbstractBase.
64 * Function called when the activator stops just before the cleanup done by
65 * ComponentActivatorAbstractBase
68 public void destroy() {
72 * Function that is used to communicate to dependency manager the list of
73 * known implementations for services inside a container
76 * @return An array containing all the CLASS objects that will be
77 * instantiated in order to get an fully working implementation
80 public Object[] getImplementations() {
81 Object[] res = { TopologyServices.class, DataPacketServices.class,
82 InventoryService.class, ReadService.class,
83 FlowProgrammerNotifier.class };
88 * Function that is called when configuration of the dependencies is
92 * dependency manager Component object, used for configuring the
93 * dependencies exported and imported
95 * Implementation class that is being configured, needed as long
96 * as the same routine can configure multiple implementations
97 * @param containerName
98 * The containerName being configured, this allow also optional
99 * per-container different behavior if needed, usually should not
100 * be the case though.
102 public void configureInstance(Component c, Object imp, String containerName) {
103 if (imp.equals(TopologyServices.class)) {
104 // export the service to be used by SAL
106 new String[] { IPluginInTopologyService.class.getName(),
107 ITopologyServiceShimListener.class.getName() },
109 // Hook the services coming in from SAL, as optional in
110 // case SAL is not yet there, could happen
111 c.add(createContainerServiceDependency(containerName)
112 .setService(IPluginOutTopologyService.class)
113 .setCallbacks("setPluginOutTopologyService",
114 "unsetPluginOutTopologyService").setRequired(false));
115 c.add(createServiceDependency()
116 .setService(IRefreshInternalProvider.class)
117 .setCallbacks("setRefreshInternalProvider",
118 "unsetRefreshInternalProvider").setRequired(false));
121 if (imp.equals(InventoryService.class)) {
122 // export the service
124 new String[] { IPluginInInventoryService.class.getName(),
125 IStatisticsListener.class.getName(),
126 IInventoryShimInternalListener.class.getName() },
129 // Now lets add a service dependency to make sure the
130 // provider of service exists
131 c.add(createServiceDependency()
132 .setService(IController.class, "(name=Controller)")
133 .setCallbacks("setController", "unsetController")
135 c.add(createContainerServiceDependency(containerName)
136 .setService(IPluginOutInventoryService.class)
137 .setCallbacks("setPluginOutInventoryServices",
138 "unsetPluginOutInventoryServices")
139 .setRequired(false));
142 if (imp.equals(DataPacketServices.class)) {
143 // export the service to be used by SAL
144 Dictionary<String, Object> props = new Hashtable<String, Object>();
145 // Set the protocolPluginType property which will be used
147 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
148 c.setInterface(IPluginInDataPacketService.class.getName(), props);
149 // Hook the services coming in from SAL, as optional in
150 // case SAL is not yet there, could happen
151 c.add(createServiceDependency()
152 .setService(IController.class, "(name=Controller)")
153 .setCallbacks("setController", "unsetController")
155 // This is required for the transmission to happen properly
156 c.add(createServiceDependency().setService(IDataPacketMux.class)
157 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
159 c.add(createContainerServiceDependency(containerName)
160 .setService(IPluginOutDataPacketService.class)
161 .setCallbacks("setPluginOutDataPacketService",
162 "unsetPluginOutDataPacketService")
163 .setRequired(false));
166 if (imp.equals(ReadService.class)) {
167 // export the service to be used by SAL
168 Dictionary<String, Object> props = new Hashtable<String, Object>();
169 // Set the protocolPluginType property which will be used
171 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
172 c.setInterface(IPluginInReadService.class.getName(), props);
173 c.add(createServiceDependency()
174 .setService(IPluginReadServiceFilter.class)
175 .setCallbacks("setService", "unsetService")
179 if (imp.equals(FlowProgrammerNotifier.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("protocolPluginType", Node.NodeIDType.OPENFLOW);
185 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
187 c.add(createContainerServiceDependency(containerName)
188 .setService(IPluginOutFlowProgrammerService.class)
189 .setCallbacks("setPluginOutFlowProgrammerService",
190 "unsetPluginOutFlowProgrammerService")
196 * Function that is used to communicate to dependency manager the list of
197 * known implementations for services that are container independent.
200 * @return An array containing all the CLASS objects that will be
201 * instantiated in order to get an fully working implementation
204 public Object[] getGlobalImplementations() {
205 Object[] res = { EnhancedController.class, OFStatisticsManager.class,
206 FlowProgrammerService.class, ReadServiceFilter.class,
207 DiscoveryService.class, DataPacketMuxDemux.class,
208 InventoryServiceShim.class, TopologyServiceShim.class };
213 * Function that is called when configuration of the dependencies is
217 * dependency manager Component object, used for configuring the
218 * dependencies exported and imported
220 * Implementation class that is being configured, needed as long
221 * as the same routine can configure multiple implementations
223 public void configureGlobalInstance(Component c, Object imp) {
225 if (imp.equals(EnhancedController.class)) {
226 logger.debug("Activator configureGlobalInstance( ) is called");
227 Dictionary<String, Object> props = new Hashtable<String, Object>();
228 props.put("name", "Controller");
229 c.setInterface(IController.class.getName(), props);
232 if (imp.equals(FlowProgrammerService.class)) {
233 // export the service to be used by SAL
234 Dictionary<String, Object> props = new Hashtable<String, Object>();
235 // Set the protocolPluginType property which will be used
237 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
240 IPluginInFlowProgrammerService.class.getName(),
241 IMessageListener.class.getName(),
242 IContainerListener.class.getName(),
243 IInventoryShimExternalListener.class.getName() },
246 c.add(createServiceDependency()
247 .setService(IController.class, "(name=Controller)")
248 .setCallbacks("setController", "unsetController")
251 c.add(createServiceDependency()
252 .setService(IFlowProgrammerNotifier.class)
253 .setCallbacks("setFlowProgrammerNotifier",
254 "unsetsetFlowProgrammerNotifier")
255 .setRequired(false));
259 if (imp.equals(ReadServiceFilter.class)) {
262 new String[] { IPluginReadServiceFilter.class.getName(),
263 IContainerListener.class.getName() }, null);
265 c.add(createServiceDependency()
266 .setService(IController.class, "(name=Controller)")
267 .setCallbacks("setController", "unsetController")
269 c.add(createServiceDependency()
270 .setService(IOFStatisticsManager.class)
271 .setCallbacks("setService", "unsetService")
275 if (imp.equals(OFStatisticsManager.class)) {
277 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
278 IInventoryShimExternalListener.class.getName() }, null);
280 c.add(createServiceDependency()
281 .setService(IController.class, "(name=Controller)")
282 .setCallbacks("setController", "unsetController")
284 c.add(createServiceDependency()
285 .setService(IStatisticsListener.class)
286 .setCallbacks("setStatisticsListener",
287 "unsetStatisticsListener").setRequired(false));
290 if (imp.equals(DiscoveryService.class)) {
291 // export the service
294 IInventoryShimExternalListener.class.getName(),
295 IDataPacketListen.class.getName(),
296 IContainerListener.class.getName() }, null);
298 c.add(createServiceDependency()
299 .setService(IController.class, "(name=Controller)")
300 .setCallbacks("setController", "unsetController")
302 c.add(createContainerServiceDependency(
303 GlobalConstants.DEFAULT.toString())
304 .setService(IPluginInInventoryService.class)
305 .setCallbacks("setPluginInInventoryService",
306 "unsetPluginInInventoryService").setRequired(true));
307 c.add(createServiceDependency().setService(IDataPacketMux.class)
308 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
310 c.add(createServiceDependency()
311 .setService(IDiscoveryService.class)
312 .setCallbacks("setDiscoveryService",
313 "unsetDiscoveryService").setRequired(true));
316 // DataPacket mux/demux services, which is teh actual engine
317 // doing the packet switching
318 if (imp.equals(DataPacketMuxDemux.class)) {
319 c.setInterface(new String[] { IDataPacketMux.class.getName(),
320 IContainerListener.class.getName(),
321 IInventoryShimExternalListener.class.getName() }, null);
323 c.add(createServiceDependency()
324 .setService(IController.class, "(name=Controller)")
325 .setCallbacks("setController", "unsetController")
327 c.add(createServiceDependency()
328 .setService(IPluginOutDataPacketService.class)
329 .setCallbacks("setPluginOutDataPacketService",
330 "unsetPluginOutDataPacketService")
331 .setRequired(false));
332 // See if there is any local packet dispatcher
333 c.add(createServiceDependency()
334 .setService(IDataPacketListen.class)
335 .setCallbacks("setIDataPacketListen",
336 "unsetIDataPacketListen").setRequired(false));
339 if (imp.equals(InventoryServiceShim.class)) {
340 c.setInterface(new String[] { IContainerListener.class.getName() },
343 c.add(createServiceDependency()
344 .setService(IController.class, "(name=Controller)")
345 .setCallbacks("setController", "unsetController")
347 c.add(createServiceDependency()
348 .setService(IInventoryShimInternalListener.class)
349 .setCallbacks("setInventoryShimInternalListener",
350 "unsetInventoryShimInternalListener")
352 c.add(createServiceDependency()
353 .setService(IInventoryShimExternalListener.class)
354 .setCallbacks("setInventoryShimExternalListener",
355 "unsetInventoryShimExternalListener")
356 .setRequired(false));
359 if (imp.equals(TopologyServiceShim.class)) {
360 c.setInterface(new String[] { IDiscoveryService.class.getName(),
361 IContainerListener.class.getName(),
362 IRefreshInternalProvider.class.getName(),
363 IInventoryShimExternalListener.class.getName() }, null);
364 c.add(createServiceDependency()
365 .setService(ITopologyServiceShimListener.class)
366 .setCallbacks("setTopologyServiceShimListener",
367 "unsetTopologyServiceShimListener")
369 c.add(createServiceDependency()
370 .setService(IOFStatisticsManager.class)
371 .setCallbacks("setStatisticsManager",
372 "unsetStatisticsManager").setRequired(false));