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.ITopologyServiceShimListener;
25 import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
26 import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener;
27 import org.opendaylight.controller.protocol_plugin.openflow.core.internal.Controller;
28 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
29 import org.opendaylight.controller.sal.core.IContainerListener;
30 import org.opendaylight.controller.sal.core.Node;
31 import org.opendaylight.controller.sal.discovery.IDiscoveryService;
32 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
33 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
34 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
35 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
36 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
37 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
38 import org.opendaylight.controller.sal.reader.IPluginInReadService;
39 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
40 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
41 import org.opendaylight.controller.sal.utils.GlobalConstants;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 * Openflow protocol plugin Activator
50 public class Activator extends ComponentActivatorAbstractBase {
51 protected static final Logger logger = LoggerFactory
52 .getLogger(Activator.class);
55 * Function called when the activator starts just after some initializations
56 * are done by the ComponentActivatorAbstractBase.
63 * Function called when the activator stops just before the cleanup done by
64 * ComponentActivatorAbstractBase
67 public void destroy() {
71 * Function that is used to communicate to dependency manager the list of
72 * known implementations for services inside a container
75 * @return An array containing all the CLASS objects that will be
76 * instantiated in order to get an fully working implementation
79 public Object[] getImplementations() {
80 Object[] res = { TopologyServices.class, DataPacketServices.class,
81 InventoryService.class, ReadService.class,
82 FlowProgrammerNotifier.class };
87 * Function that is called when configuration of the dependencies is
91 * dependency manager Component object, used for configuring the
92 * dependencies exported and imported
94 * Implementation class that is being configured, needed as long
95 * as the same routine can configure multiple implementations
96 * @param containerName
97 * The containerName being configured, this allow also optional
98 * per-container different behavior if needed, usually should not
101 public void configureInstance(Component c, Object imp, String containerName) {
102 if (imp.equals(TopologyServices.class)) {
103 // export the service to be used by SAL
105 new String[] { IPluginInTopologyService.class.getName(),
106 ITopologyServiceShimListener.class.getName() },
108 // Hook the services coming in from SAL, as optional in
109 // case SAL is not yet there, could happen
110 c.add(createContainerServiceDependency(containerName)
111 .setService(IPluginOutTopologyService.class)
112 .setCallbacks("setPluginOutTopologyService",
113 "unsetPluginOutTopologyService").setRequired(false));
114 c.add(createServiceDependency()
115 .setService(IRefreshInternalProvider.class)
116 .setCallbacks("setRefreshInternalProvider",
117 "unsetRefreshInternalProvider").setRequired(false));
120 if (imp.equals(InventoryService.class)) {
121 // export the service
123 new String[] { IPluginInInventoryService.class.getName(),
124 IInventoryShimInternalListener.class.getName() },
127 // Now lets add a service dependency to make sure the
128 // provider of service exists
129 c.add(createServiceDependency()
130 .setService(IController.class, "(name=Controller)")
131 .setCallbacks("setController", "unsetController")
133 c.add(createContainerServiceDependency(containerName)
134 .setService(IPluginOutInventoryService.class)
135 .setCallbacks("setPluginOutInventoryServices",
136 "unsetPluginOutInventoryServices")
137 .setRequired(false));
140 if (imp.equals(DataPacketServices.class)) {
141 // export the service to be used by SAL
142 Dictionary<String, Object> props = new Hashtable<String, Object>();
143 // Set the protocolPluginType property which will be used
145 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
146 c.setInterface(IPluginInDataPacketService.class.getName(), props);
147 // Hook the services coming in from SAL, as optional in
148 // case SAL is not yet there, could happen
149 c.add(createServiceDependency()
150 .setService(IController.class, "(name=Controller)")
151 .setCallbacks("setController", "unsetController")
153 // This is required for the transmission to happen properly
154 c.add(createServiceDependency().setService(IDataPacketMux.class)
155 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
157 c.add(createContainerServiceDependency(containerName)
158 .setService(IPluginOutDataPacketService.class)
159 .setCallbacks("setPluginOutDataPacketService",
160 "unsetPluginOutDataPacketService")
161 .setRequired(false));
164 if (imp.equals(ReadService.class)) {
165 // export the service to be used by SAL
166 Dictionary<String, Object> props = new Hashtable<String, Object>();
167 // Set the protocolPluginType property which will be used
169 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
170 c.setInterface(IPluginInReadService.class.getName(), props);
171 c.add(createServiceDependency()
172 .setService(IPluginReadServiceFilter.class)
173 .setCallbacks("setService", "unsetService")
177 if (imp.equals(FlowProgrammerNotifier.class)) {
178 // export the service to be used by SAL
179 Dictionary<String, Object> props = new Hashtable<String, Object>();
180 // Set the protocolPluginType property which will be used
182 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
183 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
185 c.add(createContainerServiceDependency(containerName)
186 .setService(IPluginOutFlowProgrammerService.class)
187 .setCallbacks("setPluginOutFlowProgrammerService",
188 "unsetPluginOutFlowProgrammerService")
194 * Function that is used to communicate to dependency manager the list of
195 * known implementations for services that are container independent.
198 * @return An array containing all the CLASS objects that will be
199 * instantiated in order to get an fully working implementation
202 public Object[] getGlobalImplementations() {
203 Object[] res = { Controller.class, OFStatisticsManager.class,
204 FlowProgrammerService.class, ReadServiceFilter.class,
205 DiscoveryService.class, DataPacketMuxDemux.class,
206 InventoryServiceShim.class, TopologyServiceShim.class };
211 * Function that is called when configuration of the dependencies is
215 * dependency manager Component object, used for configuring the
216 * dependencies exported and imported
218 * Implementation class that is being configured, needed as long
219 * as the same routine can configure multiple implementations
221 public void configureGlobalInstance(Component c, Object imp) {
223 if (imp.equals(Controller.class)) {
224 logger.debug("Activator configureGlobalInstance( ) is called");
225 Dictionary<String, Object> props = new Hashtable<String, Object>();
226 props.put("name", "Controller");
227 c.setInterface(IController.class.getName(), props);
230 if (imp.equals(FlowProgrammerService.class)) {
231 // export the service to be used by SAL
232 Dictionary<String, Object> props = new Hashtable<String, Object>();
233 // Set the protocolPluginType property which will be used
235 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
238 IPluginInFlowProgrammerService.class.getName(),
239 IMessageListener.class.getName(),
240 IContainerListener.class.getName(),
241 IInventoryShimExternalListener.class.getName() },
244 c.add(createServiceDependency()
245 .setService(IController.class, "(name=Controller)")
246 .setCallbacks("setController", "unsetController")
249 c.add(createServiceDependency()
250 .setService(IFlowProgrammerNotifier.class)
251 .setCallbacks("setFlowProgrammerNotifier",
252 "unsetsetFlowProgrammerNotifier")
253 .setRequired(false));
257 if (imp.equals(ReadServiceFilter.class)) {
260 new String[] { IPluginReadServiceFilter.class.getName(),
261 IContainerListener.class.getName() }, null);
263 c.add(createServiceDependency()
264 .setService(IController.class, "(name=Controller)")
265 .setCallbacks("setController", "unsetController")
267 c.add(createServiceDependency()
268 .setService(IOFStatisticsManager.class)
269 .setCallbacks("setService", "unsetService")
273 if (imp.equals(OFStatisticsManager.class)) {
275 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
276 IInventoryShimExternalListener.class.getName() }, null);
278 c.add(createServiceDependency()
279 .setService(IController.class, "(name=Controller)")
280 .setCallbacks("setController", "unsetController")
282 c.add(createServiceDependency()
283 .setService(IStatisticsListener.class)
284 .setCallbacks("setStatisticsListener",
285 "unsetStatisticsListener").setRequired(false));
288 if (imp.equals(DiscoveryService.class)) {
289 // export the service
292 IInventoryShimExternalListener.class.getName(),
293 IDataPacketListen.class.getName(),
294 IContainerListener.class.getName() }, null);
296 c.add(createServiceDependency()
297 .setService(IController.class, "(name=Controller)")
298 .setCallbacks("setController", "unsetController")
300 c.add(createContainerServiceDependency(
301 GlobalConstants.DEFAULT.toString())
302 .setService(IPluginInInventoryService.class)
303 .setCallbacks("setPluginInInventoryService",
304 "unsetPluginInInventoryService").setRequired(true));
305 c.add(createServiceDependency().setService(IDataPacketMux.class)
306 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
308 c.add(createServiceDependency()
309 .setService(IDiscoveryService.class)
310 .setCallbacks("setDiscoveryService",
311 "unsetDiscoveryService").setRequired(true));
314 // DataPacket mux/demux services, which is teh actual engine
315 // doing the packet switching
316 if (imp.equals(DataPacketMuxDemux.class)) {
317 c.setInterface(new String[] { IDataPacketMux.class.getName(),
318 IContainerListener.class.getName(),
319 IInventoryShimExternalListener.class.getName() }, null);
321 c.add(createServiceDependency()
322 .setService(IController.class, "(name=Controller)")
323 .setCallbacks("setController", "unsetController")
325 c.add(createServiceDependency()
326 .setService(IPluginOutDataPacketService.class)
327 .setCallbacks("setPluginOutDataPacketService",
328 "unsetPluginOutDataPacketService")
329 .setRequired(false));
330 // See if there is any local packet dispatcher
331 c.add(createServiceDependency()
332 .setService(IDataPacketListen.class)
333 .setCallbacks("setIDataPacketListen",
334 "unsetIDataPacketListen").setRequired(false));
337 if (imp.equals(InventoryServiceShim.class)) {
338 c.setInterface(new String[] { IContainerListener.class.getName(),
339 IStatisticsListener.class.getName()}, null);
341 c.add(createServiceDependency()
342 .setService(IController.class, "(name=Controller)")
343 .setCallbacks("setController", "unsetController")
345 c.add(createServiceDependency()
346 .setService(IInventoryShimInternalListener.class)
347 .setCallbacks("setInventoryShimInternalListener",
348 "unsetInventoryShimInternalListener")
350 c.add(createServiceDependency()
351 .setService(IInventoryShimExternalListener.class)
352 .setCallbacks("setInventoryShimExternalListener",
353 "unsetInventoryShimExternalListener")
354 .setRequired(false));
357 if (imp.equals(TopologyServiceShim.class)) {
358 c.setInterface(new String[] { IDiscoveryService.class.getName(),
359 IContainerListener.class.getName(),
360 IRefreshInternalProvider.class.getName(),
361 IInventoryShimExternalListener.class.getName() }, null);
362 c.add(createServiceDependency()
363 .setService(ITopologyServiceShimListener.class)
364 .setCallbacks("setTopologyServiceShimListener",
365 "unsetTopologyServiceShimListener")
367 c.add(createServiceDependency()
368 .setService(IOFStatisticsManager.class)
369 .setCallbacks("setStatisticsManager",
370 "unsetStatisticsManager").setRequired(false));