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.core.ComponentActivatorAbstractBase;
32 import org.opendaylight.controller.sal.core.IContainerListener;
33 import org.opendaylight.controller.sal.core.Node;
34 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
35 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
36 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
37 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
38 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
39 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
40 import org.opendaylight.controller.sal.reader.IPluginInReadService;
41 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
42 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
43 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
44 import org.opendaylight.controller.sal.utils.GlobalConstants;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * Openflow protocol plugin Activator
53 public class Activator extends ComponentActivatorAbstractBase {
54 protected static final Logger logger = LoggerFactory
55 .getLogger(Activator.class);
58 * Function called when the activator starts just after some initializations
59 * are done by the ComponentActivatorAbstractBase.
66 * Function called when the activator stops just before the cleanup done by
67 * ComponentActivatorAbstractBase
70 public void destroy() {
74 * Function that is used to communicate to dependency manager the list of
75 * known implementations for services inside a container
78 * @return An array containing all the CLASS objects that will be
79 * instantiated in order to get an fully working implementation
82 public Object[] getImplementations() {
83 Object[] res = { TopologyServices.class, DataPacketServices.class,
84 InventoryService.class, ReadService.class,
85 FlowProgrammerNotifier.class };
90 * Function that is called when configuration of the dependencies is
94 * dependency manager Component object, used for configuring the
95 * dependencies exported and imported
97 * Implementation class that is being configured, needed as long
98 * as the same routine can configure multiple implementations
99 * @param containerName
100 * The containerName being configured, this allow also optional
101 * per-container different behavior if needed, usually should not
102 * be the case though.
104 public void configureInstance(Component c, Object imp, String containerName) {
105 if (imp.equals(TopologyServices.class)) {
106 // export the service to be used by SAL
108 new String[] { IPluginInTopologyService.class.getName(),
109 ITopologyServiceShimListener.class.getName() }, null);
110 // Hook the services coming in from SAL, as optional in
111 // case SAL is not yet there, could happen
112 c.add(createContainerServiceDependency(containerName)
113 .setService(IPluginOutTopologyService.class)
114 .setCallbacks("setPluginOutTopologyService",
115 "unsetPluginOutTopologyService").setRequired(false));
116 c.add(createServiceDependency()
117 .setService(IRefreshInternalProvider.class)
118 .setCallbacks("setRefreshInternalProvider",
119 "unsetRefreshInternalProvider").setRequired(false));
122 if (imp.equals(InventoryService.class)) {
123 // export the service
126 IPluginInInventoryService.class.getName(),
127 IInventoryShimInternalListener.class.getName(),
128 IInventoryProvider.class.getName() }, null);
130 // Now lets add a service dependency to make sure the
131 // provider of service exists
132 c.add(createServiceDependency()
133 .setService(IController.class, "(name=Controller)")
134 .setCallbacks("setController", "unsetController")
136 c.add(createContainerServiceDependency(containerName)
137 .setService(IPluginOutInventoryService.class)
138 .setCallbacks("setPluginOutInventoryServices",
139 "unsetPluginOutInventoryServices")
140 .setRequired(false));
143 if (imp.equals(DataPacketServices.class)) {
144 // export the service to be used by SAL
145 Dictionary<String, Object> props = new Hashtable<String, Object>();
146 // Set the protocolPluginType property which will be used
148 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
149 c.setInterface(IPluginInDataPacketService.class.getName(), props);
150 // Hook the services coming in from SAL, as optional in
151 // case SAL is not yet there, could happen
152 c.add(createServiceDependency()
153 .setService(IController.class, "(name=Controller)")
154 .setCallbacks("setController", "unsetController")
156 // This is required for the transmission to happen properly
157 c.add(createServiceDependency().setService(IDataPacketMux.class)
158 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
160 c.add(createContainerServiceDependency(containerName)
161 .setService(IPluginOutDataPacketService.class)
162 .setCallbacks("setPluginOutDataPacketService",
163 "unsetPluginOutDataPacketService")
164 .setRequired(false));
167 if (imp.equals(ReadService.class)) {
168 // export the service to be used by SAL
169 Dictionary<String, Object> props = new Hashtable<String, Object>();
170 // Set the protocolPluginType property which will be used
172 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
173 c.setInterface(new String[] {
174 IReadFilterInternalListener.class.getName(),
175 IPluginInReadService.class.getName() }, props);
177 c.add(createServiceDependency()
178 .setService(IReadServiceFilter.class)
179 .setCallbacks("setService", "unsetService")
181 c.add(createContainerServiceDependency(containerName)
182 .setService(IPluginOutReadService.class)
183 .setCallbacks("setPluginOutReadServices",
184 "unsetPluginOutReadServices")
185 .setRequired(false));
188 if (imp.equals(FlowProgrammerNotifier.class)) {
189 // export the service to be used by SAL
190 Dictionary<String, Object> props = new Hashtable<String, Object>();
191 // Set the protocolPluginType property which will be used
193 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
194 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
196 c.add(createContainerServiceDependency(containerName)
197 .setService(IPluginOutFlowProgrammerService.class)
198 .setCallbacks("setPluginOutFlowProgrammerService",
199 "unsetPluginOutFlowProgrammerService")
205 * Function that is used to communicate to dependency manager the list of
206 * known implementations for services that are container independent.
209 * @return An array containing all the CLASS objects that will be
210 * instantiated in order to get an fully working implementation
213 public Object[] getGlobalImplementations() {
214 Object[] res = { Controller.class, OFStatisticsManager.class,
215 FlowProgrammerService.class, ReadServiceFilter.class,
216 DiscoveryService.class, DataPacketMuxDemux.class,
217 InventoryServiceShim.class, TopologyServiceShim.class };
222 * Function that is called when configuration of the dependencies is
226 * dependency manager Component object, used for configuring the
227 * dependencies exported and imported
229 * Implementation class that is being configured, needed as long
230 * as the same routine can configure multiple implementations
232 public void configureGlobalInstance(Component c, Object imp) {
234 if (imp.equals(Controller.class)) {
235 logger.debug("Activator configureGlobalInstance( ) is called");
236 Dictionary<String, Object> props = new Hashtable<String, Object>();
237 props.put("name", "Controller");
238 c.setInterface(IController.class.getName(), props);
241 if (imp.equals(FlowProgrammerService.class)) {
242 // export the service to be used by SAL
243 Dictionary<String, Object> props = new Hashtable<String, Object>();
244 // Set the protocolPluginType property which will be used
246 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
249 IPluginInFlowProgrammerService.class.getName(),
250 IMessageListener.class.getName(),
251 IContainerListener.class.getName(),
252 IInventoryShimExternalListener.class.getName() },
255 c.add(createServiceDependency()
256 .setService(IController.class, "(name=Controller)")
257 .setCallbacks("setController", "unsetController")
260 c.add(createServiceDependency()
261 .setService(IFlowProgrammerNotifier.class)
262 .setCallbacks("setFlowProgrammerNotifier",
263 "unsetsetFlowProgrammerNotifier")
264 .setRequired(false));
268 if (imp.equals(ReadServiceFilter.class)) {
270 c.setInterface(new String[] {
271 IReadServiceFilter.class.getName(),
272 IContainerListener.class.getName(),
273 IOFStatisticsListener.class.getName() }, null);
275 c.add(createServiceDependency()
276 .setService(IController.class, "(name=Controller)")
277 .setCallbacks("setController", "unsetController")
279 c.add(createServiceDependency()
280 .setService(IOFStatisticsManager.class)
281 .setCallbacks("setService", "unsetService")
283 c.add(createServiceDependency()
284 .setService(IReadFilterInternalListener.class)
285 .setCallbacks("setReadFilterInternalListener",
286 "unsetReadFilterInternalListener")
287 .setRequired(false));
291 if (imp.equals(OFStatisticsManager.class)) {
293 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
294 IInventoryShimExternalListener.class.getName() }, null);
296 c.add(createServiceDependency()
297 .setService(IController.class, "(name=Controller)")
298 .setCallbacks("setController", "unsetController")
300 c.add(createServiceDependency()
301 .setService(IOFStatisticsListener.class)
302 .setCallbacks("setStatisticsListener",
303 "unsetStatisticsListener").setRequired(false));
306 if (imp.equals(DiscoveryService.class)) {
307 // export the service
310 IInventoryShimExternalListener.class.getName(),
311 IDataPacketListen.class.getName(),
312 IContainerListener.class.getName() }, null);
314 c.add(createServiceDependency()
315 .setService(IController.class, "(name=Controller)")
316 .setCallbacks("setController", "unsetController")
318 c.add(createContainerServiceDependency(
319 GlobalConstants.DEFAULT.toString())
320 .setService(IInventoryProvider.class)
321 .setCallbacks("setInventoryProvider",
322 "unsetInventoryProvider").setRequired(true));
323 c.add(createServiceDependency().setService(IDataPacketMux.class)
324 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
326 c.add(createServiceDependency()
327 .setService(IDiscoveryListener.class)
328 .setCallbacks("setDiscoveryListener",
329 "unsetDiscoveryListener").setRequired(true));
332 // DataPacket mux/demux services, which is teh actual engine
333 // doing the packet switching
334 if (imp.equals(DataPacketMuxDemux.class)) {
335 c.setInterface(new String[] { IDataPacketMux.class.getName(),
336 IContainerListener.class.getName(),
337 IInventoryShimExternalListener.class.getName() }, null);
339 c.add(createServiceDependency()
340 .setService(IController.class, "(name=Controller)")
341 .setCallbacks("setController", "unsetController")
343 c.add(createServiceDependency()
344 .setService(IPluginOutDataPacketService.class)
345 .setCallbacks("setPluginOutDataPacketService",
346 "unsetPluginOutDataPacketService")
347 .setRequired(false));
348 // See if there is any local packet dispatcher
349 c.add(createServiceDependency()
350 .setService(IDataPacketListen.class)
351 .setCallbacks("setIDataPacketListen",
352 "unsetIDataPacketListen").setRequired(false));
355 if (imp.equals(InventoryServiceShim.class)) {
356 c.setInterface(new String[] { IContainerListener.class.getName(),
357 IOFStatisticsListener.class.getName()}, null);
359 c.add(createServiceDependency()
360 .setService(IController.class, "(name=Controller)")
361 .setCallbacks("setController", "unsetController")
363 c.add(createServiceDependency()
364 .setService(IInventoryShimInternalListener.class)
365 .setCallbacks("setInventoryShimInternalListener",
366 "unsetInventoryShimInternalListener")
368 c.add(createServiceDependency()
369 .setService(IInventoryShimExternalListener.class)
370 .setCallbacks("setInventoryShimExternalListener",
371 "unsetInventoryShimExternalListener")
372 .setRequired(false));
375 if (imp.equals(TopologyServiceShim.class)) {
376 c.setInterface(new String[] { IDiscoveryListener.class.getName(),
377 IContainerListener.class.getName(),
378 IRefreshInternalProvider.class.getName(),
379 IInventoryShimExternalListener.class.getName() }, null);
380 c.add(createServiceDependency()
381 .setService(ITopologyServiceShimListener.class)
382 .setCallbacks("setTopologyServiceShimListener",
383 "unsetTopologyServiceShimListener")
385 c.add(createServiceDependency()
386 .setService(IOFStatisticsManager.class)
387 .setCallbacks("setStatisticsManager",
388 "unsetStatisticsManager").setRequired(false));