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 IStatisticsListener.class.getName(),
125 IInventoryShimInternalListener.class.getName() },
128 // Now lets add a service dependency to make sure the
129 // provider of service exists
130 c.add(createServiceDependency()
131 .setService(IController.class, "(name=Controller)")
132 .setCallbacks("setController", "unsetController")
134 c.add(createContainerServiceDependency(containerName)
135 .setService(IPluginOutInventoryService.class)
136 .setCallbacks("setPluginOutInventoryServices",
137 "unsetPluginOutInventoryServices")
138 .setRequired(false));
141 if (imp.equals(DataPacketServices.class)) {
142 // export the service to be used by SAL
143 Dictionary<String, Object> props = new Hashtable<String, Object>();
144 // Set the protocolPluginType property which will be used
146 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
147 c.setInterface(IPluginInDataPacketService.class.getName(), props);
148 // Hook the services coming in from SAL, as optional in
149 // case SAL is not yet there, could happen
150 c.add(createServiceDependency()
151 .setService(IController.class, "(name=Controller)")
152 .setCallbacks("setController", "unsetController")
154 // This is required for the transmission to happen properly
155 c.add(createServiceDependency().setService(IDataPacketMux.class)
156 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
158 c.add(createContainerServiceDependency(containerName)
159 .setService(IPluginOutDataPacketService.class)
160 .setCallbacks("setPluginOutDataPacketService",
161 "unsetPluginOutDataPacketService")
162 .setRequired(false));
165 if (imp.equals(ReadService.class)) {
166 // export the service to be used by SAL
167 Dictionary<String, Object> props = new Hashtable<String, Object>();
168 // Set the protocolPluginType property which will be used
170 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
171 c.setInterface(IPluginInReadService.class.getName(), props);
172 c.add(createServiceDependency()
173 .setService(IPluginReadServiceFilter.class)
174 .setCallbacks("setService", "unsetService")
178 if (imp.equals(FlowProgrammerNotifier.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("protocolPluginType", Node.NodeIDType.OPENFLOW);
184 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
186 c.add(createContainerServiceDependency(containerName)
187 .setService(IPluginOutFlowProgrammerService.class)
188 .setCallbacks("setPluginOutFlowProgrammerService",
189 "unsetPluginOutFlowProgrammerService")
195 * Function that is used to communicate to dependency manager the list of
196 * known implementations for services that are container independent.
199 * @return An array containing all the CLASS objects that will be
200 * instantiated in order to get an fully working implementation
203 public Object[] getGlobalImplementations() {
204 Object[] res = { Controller.class, OFStatisticsManager.class,
205 FlowProgrammerService.class, ReadServiceFilter.class,
206 DiscoveryService.class, DataPacketMuxDemux.class,
207 InventoryServiceShim.class, TopologyServiceShim.class };
212 * Function that is called when configuration of the dependencies is
216 * dependency manager Component object, used for configuring the
217 * dependencies exported and imported
219 * Implementation class that is being configured, needed as long
220 * as the same routine can configure multiple implementations
222 public void configureGlobalInstance(Component c, Object imp) {
224 if (imp.equals(Controller.class)) {
225 logger.debug("Activator configureGlobalInstance( ) is called");
226 Dictionary<String, Object> props = new Hashtable<String, Object>();
227 props.put("name", "Controller");
228 c.setInterface(IController.class.getName(), props);
231 if (imp.equals(FlowProgrammerService.class)) {
232 // export the service to be used by SAL
233 Dictionary<String, Object> props = new Hashtable<String, Object>();
234 // Set the protocolPluginType property which will be used
236 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
239 IPluginInFlowProgrammerService.class.getName(),
240 IMessageListener.class.getName(),
241 IContainerListener.class.getName() }, props);
243 c.add(createServiceDependency()
244 .setService(IController.class, "(name=Controller)")
245 .setCallbacks("setController", "unsetController")
248 c.add(createServiceDependency()
249 .setService(IFlowProgrammerNotifier.class)
250 .setCallbacks("setFlowProgrammerNotifier",
251 "unsetsetFlowProgrammerNotifier")
252 .setRequired(false));
256 if (imp.equals(ReadServiceFilter.class)) {
259 new String[] { IPluginReadServiceFilter.class.getName(),
260 IContainerListener.class.getName() }, null);
262 c.add(createServiceDependency()
263 .setService(IController.class, "(name=Controller)")
264 .setCallbacks("setController", "unsetController")
266 c.add(createServiceDependency()
267 .setService(IOFStatisticsManager.class)
268 .setCallbacks("setService", "unsetService")
272 if (imp.equals(OFStatisticsManager.class)) {
274 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
275 IInventoryShimExternalListener.class.getName() }, null);
277 c.add(createServiceDependency()
278 .setService(IController.class, "(name=Controller)")
279 .setCallbacks("setController", "unsetController")
281 c.add(createServiceDependency()
282 .setService(IStatisticsListener.class)
283 .setCallbacks("setStatisticsListener",
284 "unsetStatisticsListener").setRequired(false));
287 if (imp.equals(DiscoveryService.class)) {
288 // export the service
291 IInventoryShimExternalListener.class.getName(),
292 IDataPacketListen.class.getName(),
293 IContainerListener.class.getName() }, null);
295 c.add(createServiceDependency()
296 .setService(IController.class, "(name=Controller)")
297 .setCallbacks("setController", "unsetController")
299 c.add(createContainerServiceDependency(
300 GlobalConstants.DEFAULT.toString())
301 .setService(IPluginInInventoryService.class)
302 .setCallbacks("setPluginInInventoryService",
303 "unsetPluginInInventoryService").setRequired(true));
304 c.add(createServiceDependency().setService(IDataPacketMux.class)
305 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
307 c.add(createServiceDependency()
308 .setService(IDiscoveryService.class)
309 .setCallbacks("setDiscoveryService",
310 "unsetDiscoveryService").setRequired(true));
313 // DataPacket mux/demux services, which is teh actual engine
314 // doing the packet switching
315 if (imp.equals(DataPacketMuxDemux.class)) {
316 c.setInterface(new String[] { IDataPacketMux.class.getName(),
317 IContainerListener.class.getName(),
318 IInventoryShimExternalListener.class.getName() }, null);
320 c.add(createServiceDependency()
321 .setService(IController.class, "(name=Controller)")
322 .setCallbacks("setController", "unsetController")
324 c.add(createServiceDependency()
325 .setService(IPluginOutDataPacketService.class)
326 .setCallbacks("setPluginOutDataPacketService",
327 "unsetPluginOutDataPacketService")
328 .setRequired(false));
329 // See if there is any local packet dispatcher
330 c.add(createServiceDependency()
331 .setService(IDataPacketListen.class)
332 .setCallbacks("setIDataPacketListen",
333 "unsetIDataPacketListen").setRequired(false));
336 if (imp.equals(InventoryServiceShim.class)) {
337 c.setInterface(new String[] { IContainerListener.class.getName() },
340 c.add(createServiceDependency()
341 .setService(IController.class, "(name=Controller)")
342 .setCallbacks("setController", "unsetController")
344 c.add(createServiceDependency()
345 .setService(IInventoryShimInternalListener.class)
346 .setCallbacks("setInventoryShimInternalListener",
347 "unsetInventoryShimInternalListener")
349 c.add(createServiceDependency()
350 .setService(IInventoryShimExternalListener.class)
351 .setCallbacks("setInventoryShimExternalListener",
352 "unsetInventoryShimExternalListener")
353 .setRequired(false));
356 if (imp.equals(TopologyServiceShim.class)) {
357 c.setInterface(new String[] { IDiscoveryService.class.getName(),
358 IContainerListener.class.getName(),
359 IRefreshInternalProvider.class.getName() }, null);
360 c.add(createServiceDependency()
361 .setService(ITopologyServiceShimListener.class)
362 .setCallbacks("setTopologyServiceShimListener",
363 "unsetTopologyServiceShimListener")
365 c.add(createServiceDependency()
366 .setService(IOFStatisticsManager.class)
367 .setCallbacks("setStatisticsManager",
368 "unsetStatisticsManager").setRequired(false));