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(),
242 IInventoryShimExternalListener.class.getName() },
245 c.add(createServiceDependency()
246 .setService(IController.class, "(name=Controller)")
247 .setCallbacks("setController", "unsetController")
250 c.add(createServiceDependency()
251 .setService(IFlowProgrammerNotifier.class)
252 .setCallbacks("setFlowProgrammerNotifier",
253 "unsetsetFlowProgrammerNotifier")
254 .setRequired(false));
258 if (imp.equals(ReadServiceFilter.class)) {
261 new String[] { IPluginReadServiceFilter.class.getName(),
262 IContainerListener.class.getName() }, null);
264 c.add(createServiceDependency()
265 .setService(IController.class, "(name=Controller)")
266 .setCallbacks("setController", "unsetController")
268 c.add(createServiceDependency()
269 .setService(IOFStatisticsManager.class)
270 .setCallbacks("setService", "unsetService")
274 if (imp.equals(OFStatisticsManager.class)) {
276 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
277 IInventoryShimExternalListener.class.getName() }, null);
279 c.add(createServiceDependency()
280 .setService(IController.class, "(name=Controller)")
281 .setCallbacks("setController", "unsetController")
283 c.add(createServiceDependency()
284 .setService(IStatisticsListener.class)
285 .setCallbacks("setStatisticsListener",
286 "unsetStatisticsListener").setRequired(false));
289 if (imp.equals(DiscoveryService.class)) {
290 // export the service
293 IInventoryShimExternalListener.class.getName(),
294 IDataPacketListen.class.getName(),
295 IContainerListener.class.getName() }, null);
297 c.add(createServiceDependency()
298 .setService(IController.class, "(name=Controller)")
299 .setCallbacks("setController", "unsetController")
301 c.add(createContainerServiceDependency(
302 GlobalConstants.DEFAULT.toString())
303 .setService(IPluginInInventoryService.class)
304 .setCallbacks("setPluginInInventoryService",
305 "unsetPluginInInventoryService").setRequired(true));
306 c.add(createServiceDependency().setService(IDataPacketMux.class)
307 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
309 c.add(createServiceDependency()
310 .setService(IDiscoveryService.class)
311 .setCallbacks("setDiscoveryService",
312 "unsetDiscoveryService").setRequired(true));
315 // DataPacket mux/demux services, which is teh actual engine
316 // doing the packet switching
317 if (imp.equals(DataPacketMuxDemux.class)) {
318 c.setInterface(new String[] { IDataPacketMux.class.getName(),
319 IContainerListener.class.getName(),
320 IInventoryShimExternalListener.class.getName() }, null);
322 c.add(createServiceDependency()
323 .setService(IController.class, "(name=Controller)")
324 .setCallbacks("setController", "unsetController")
326 c.add(createServiceDependency()
327 .setService(IPluginOutDataPacketService.class)
328 .setCallbacks("setPluginOutDataPacketService",
329 "unsetPluginOutDataPacketService")
330 .setRequired(false));
331 // See if there is any local packet dispatcher
332 c.add(createServiceDependency()
333 .setService(IDataPacketListen.class)
334 .setCallbacks("setIDataPacketListen",
335 "unsetIDataPacketListen").setRequired(false));
338 if (imp.equals(InventoryServiceShim.class)) {
339 c.setInterface(new String[] { IContainerListener.class.getName() },
342 c.add(createServiceDependency()
343 .setService(IController.class, "(name=Controller)")
344 .setCallbacks("setController", "unsetController")
346 c.add(createServiceDependency()
347 .setService(IInventoryShimInternalListener.class)
348 .setCallbacks("setInventoryShimInternalListener",
349 "unsetInventoryShimInternalListener")
351 c.add(createServiceDependency()
352 .setService(IInventoryShimExternalListener.class)
353 .setCallbacks("setInventoryShimExternalListener",
354 "unsetInventoryShimExternalListener")
355 .setRequired(false));
358 if (imp.equals(TopologyServiceShim.class)) {
359 c.setInterface(new String[] { IDiscoveryService.class.getName(),
360 IContainerListener.class.getName(),
361 IRefreshInternalProvider.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));