2 * Copyright (c) 2013-2014 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.connection.IPluginInConnectionService;
32 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
33 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
34 import org.opendaylight.controller.sal.core.IContainerAware;
35 import org.opendaylight.controller.sal.core.IContainerListener;
36 import org.opendaylight.controller.sal.core.Node;
37 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
38 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
39 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
40 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
41 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
42 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
43 import org.opendaylight.controller.sal.reader.IPluginInReadService;
44 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
45 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
46 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
47 import org.opendaylight.controller.sal.utils.GlobalConstants;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
52 * Openflow protocol plugin Activator
56 public class Activator extends ComponentActivatorAbstractBase {
57 protected static final Logger logger = LoggerFactory
58 .getLogger(Activator.class);
61 * Priority to determine whether to override existing protocol service.
63 private static final int PLUGIN_PRIORITY = 10;
66 * Function that is used to communicate to dependency manager the list of
67 * known implementations for services inside a container
70 * @return An array containing all the CLASS objects that will be
71 * instantiated in order to get an fully working implementation
75 public Object[] getImplementations() {
76 Object[] res = { TopologyServices.class, DataPacketServices.class,
77 InventoryService.class, ReadService.class,
78 FlowProgrammerNotifier.class };
83 * Function that is called when configuration of the dependencies is
87 * dependency manager Component object, used for configuring the
88 * dependencies exported and imported
90 * Implementation class that is being configured, needed as long
91 * as the same routine can configure multiple implementations
92 * @param containerName
93 * The containerName being configured, this allow also optional
94 * per-container different behavior if needed, usually should not
98 public void configureInstance(Component c, Object imp, String containerName) {
99 if (imp.equals(TopologyServices.class)) {
100 // export the service to be used by SAL
102 new String[] { IPluginInTopologyService.class.getName(),
103 ITopologyServiceShimListener.class.getName() }, null);
104 // Hook the services coming in from SAL, as optional in
105 // case SAL is not yet there, could happen
106 c.add(createContainerServiceDependency(containerName)
107 .setService(IPluginOutTopologyService.class)
108 .setCallbacks("setPluginOutTopologyService",
109 "unsetPluginOutTopologyService").setRequired(false));
110 c.add(createServiceDependency()
111 .setService(IRefreshInternalProvider.class)
112 .setCallbacks("setRefreshInternalProvider",
113 "unsetRefreshInternalProvider").setRequired(false));
116 if (imp.equals(InventoryService.class)) {
117 // export the service
120 IPluginInInventoryService.class.getName(),
121 IInventoryShimInternalListener.class.getName(),
122 IInventoryProvider.class.getName() }, null);
124 // Now lets add a service dependency to make sure the
125 // provider of service exists
126 c.add(createServiceDependency()
127 .setService(IController.class, "(name=Controller)")
128 .setCallbacks("setController", "unsetController")
130 c.add(createContainerServiceDependency(containerName)
131 .setService(IPluginOutInventoryService.class)
132 .setCallbacks("setPluginOutInventoryServices",
133 "unsetPluginOutInventoryServices")
134 .setRequired(false));
137 if (imp.equals(DataPacketServices.class)) {
138 // export the service to be used by SAL
139 Dictionary<String, Object> props = new Hashtable<String, Object>();
140 // Set the protocolPluginType property which will be used
142 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
143 props.put(GlobalConstants.PROTOCOLPLUGINPRIORITY.toString(),
144 Integer.valueOf(PLUGIN_PRIORITY));
145 c.setInterface(IPluginInDataPacketService.class.getName(), props);
146 // Hook the services coming in from SAL, as optional in
147 // case SAL is not yet there, could happen
148 c.add(createServiceDependency()
149 .setService(IController.class, "(name=Controller)")
150 .setCallbacks("setController", "unsetController")
152 // This is required for the transmission to happen properly
153 c.add(createServiceDependency().setService(IDataPacketMux.class)
154 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
156 c.add(createContainerServiceDependency(containerName)
157 .setService(IPluginOutDataPacketService.class)
158 .setCallbacks("setPluginOutDataPacketService",
159 "unsetPluginOutDataPacketService")
160 .setRequired(false));
161 c.add(createServiceDependency()
162 .setService(IPluginOutConnectionService.class)
163 .setCallbacks("setIPluginOutConnectionService",
164 "unsetIPluginOutConnectionService")
168 if (imp.equals(ReadService.class)) {
169 // export the service to be used by SAL
170 Dictionary<String, Object> props = new Hashtable<String, Object>();
171 // Set the protocolPluginType property which will be used
173 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
174 props.put(GlobalConstants.PROTOCOLPLUGINPRIORITY.toString(),
175 Integer.valueOf(PLUGIN_PRIORITY));
176 c.setInterface(new String[] {
177 IReadFilterInternalListener.class.getName(),
178 IPluginInReadService.class.getName() }, props);
180 c.add(createServiceDependency()
181 .setService(IReadServiceFilter.class)
182 .setCallbacks("setService", "unsetService")
185 c.add(createContainerServiceDependency(containerName)
186 .setService(IPluginOutReadService.class)
187 .setCallbacks("setPluginOutReadServices",
188 "unsetPluginOutReadServices")
189 .setRequired(false));
191 c.add(createServiceDependency()
192 .setService(IPluginOutConnectionService.class)
193 .setCallbacks("setIPluginOutConnectionService",
194 "unsetIPluginOutConnectionService")
198 if (imp.equals(FlowProgrammerNotifier.class)) {
199 // export the service to be used by SAL
200 Dictionary<String, Object> props = new Hashtable<String, Object>();
201 // Set the protocolPluginType property which will be used
203 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
204 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
206 c.add(createContainerServiceDependency(containerName)
207 .setService(IPluginOutFlowProgrammerService.class)
208 .setCallbacks("setPluginOutFlowProgrammerService",
209 "unsetPluginOutFlowProgrammerService")
211 c.add(createServiceDependency()
212 .setService(IPluginOutConnectionService.class)
213 .setCallbacks("setIPluginOutConnectionService",
214 "unsetIPluginOutConnectionService")
220 * Function that is used to communicate to dependency manager the list of
221 * known implementations for services that are container independent.
224 * @return An array containing all the CLASS objects that will be
225 * instantiated in order to get an fully working implementation
229 public Object[] getGlobalImplementations() {
230 Object[] res = { Controller.class, OFStatisticsManager.class,
231 FlowProgrammerService.class, ReadServiceFilter.class,
232 DiscoveryService.class, DataPacketMuxDemux.class, InventoryService.class,
233 InventoryServiceShim.class, TopologyServiceShim.class };
238 * Function that is called when configuration of the dependencies is
242 * dependency manager Component object, used for configuring the
243 * dependencies exported and imported
245 * Implementation class that is being configured, needed as long
246 * as the same routine can configure multiple implementations
249 public void configureGlobalInstance(Component c, Object imp) {
251 if (imp.equals(Controller.class)) {
252 logger.debug("Activator configureGlobalInstance( ) is called");
253 Dictionary<String, Object> props = new Hashtable<String, Object>();
254 props.put("name", "Controller");
255 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
256 c.setInterface(new String[] { IController.class.getName(),
257 IPluginInConnectionService.class.getName()},
261 if (imp.equals(FlowProgrammerService.class)) {
262 // export the service to be used by SAL
263 Dictionary<String, Object> props = new Hashtable<String, Object>();
264 // Set the protocolPluginType property which will be used
266 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
267 props.put(GlobalConstants.PROTOCOLPLUGINPRIORITY.toString(),
268 Integer.valueOf(PLUGIN_PRIORITY));
270 new String[] { IPluginInFlowProgrammerService.class.getName(), IMessageListener.class.getName(),
271 IContainerListener.class.getName(), IInventoryShimExternalListener.class.getName(),
272 IContainerAware.class.getName() }, props);
274 c.add(createServiceDependency()
275 .setService(IController.class, "(name=Controller)")
276 .setCallbacks("setController", "unsetController")
279 c.add(createServiceDependency()
280 .setService(IFlowProgrammerNotifier.class)
281 .setCallbacks("setFlowProgrammerNotifier",
282 "unsetFlowProgrammerNotifier")
283 .setRequired(false));
285 c.add(createServiceDependency()
286 .setService(IPluginOutConnectionService.class)
287 .setCallbacks("setIPluginOutConnectionService",
288 "unsetIPluginOutConnectionService")
292 if (imp.equals(ReadServiceFilter.class)) {
294 c.setInterface(new String[] { IReadServiceFilter.class.getName(), IContainerListener.class.getName(),
295 IOFStatisticsListener.class.getName(), IContainerAware.class.getName() }, null);
297 c.add(createServiceDependency()
298 .setService(IController.class, "(name=Controller)")
299 .setCallbacks("setController", "unsetController")
301 c.add(createServiceDependency()
302 .setService(IOFStatisticsManager.class)
303 .setCallbacks("setService", "unsetService")
305 c.add(createServiceDependency()
306 .setService(IReadFilterInternalListener.class)
307 .setCallbacks("setReadFilterInternalListener",
308 "unsetReadFilterInternalListener")
309 .setRequired(false));
312 if (imp.equals(OFStatisticsManager.class)) {
314 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
315 IInventoryShimExternalListener.class.getName() }, null);
317 c.add(createServiceDependency()
318 .setService(IController.class, "(name=Controller)")
319 .setCallbacks("setController", "unsetController")
321 c.add(createServiceDependency()
322 .setService(IOFStatisticsListener.class)
323 .setCallbacks("setStatisticsListener",
324 "unsetStatisticsListener").setRequired(false));
327 if (imp.equals(DiscoveryService.class)) {
328 // export the service
330 new String[] { IInventoryShimExternalListener.class.getName(), IDataPacketListen.class.getName(),
331 IContainerListener.class.getName() }, null);
333 c.add(createServiceDependency()
334 .setService(IController.class, "(name=Controller)")
335 .setCallbacks("setController", "unsetController")
337 c.add(createContainerServiceDependency(
338 GlobalConstants.DEFAULT.toString())
339 .setService(IInventoryProvider.class)
340 .setCallbacks("setInventoryProvider",
341 "unsetInventoryProvider").setRequired(true));
342 c.add(createServiceDependency().setService(IDataPacketMux.class)
343 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
345 c.add(createServiceDependency()
346 .setService(IDiscoveryListener.class)
347 .setCallbacks("setDiscoveryListener",
348 "unsetDiscoveryListener").setRequired(true));
349 c.add(createServiceDependency()
350 .setService(IPluginOutConnectionService.class)
351 .setCallbacks("setIPluginOutConnectionService",
352 "unsetIPluginOutConnectionService")
356 // DataPacket mux/demux services, which is teh actual engine
357 // doing the packet switching
358 if (imp.equals(DataPacketMuxDemux.class)) {
359 c.setInterface(new String[] { IDataPacketMux.class.getName(), IContainerListener.class.getName(),
360 IInventoryShimExternalListener.class.getName(), IContainerAware.class.getName() }, null);
362 c.add(createServiceDependency()
363 .setService(IController.class, "(name=Controller)")
364 .setCallbacks("setController", "unsetController")
366 c.add(createServiceDependency()
367 .setService(IPluginOutDataPacketService.class)
368 .setCallbacks("setPluginOutDataPacketService",
369 "unsetPluginOutDataPacketService")
370 .setRequired(false));
371 // See if there is any local packet dispatcher
372 c.add(createServiceDependency()
373 .setService(IDataPacketListen.class)
374 .setCallbacks("setIDataPacketListen",
375 "unsetIDataPacketListen").setRequired(false));
376 c.add(createServiceDependency()
377 .setService(IPluginOutConnectionService.class)
378 .setCallbacks("setIPluginOutConnectionService",
379 "unsetIPluginOutConnectionService")
383 if (imp.equals(InventoryService.class)) {
384 // export the service
385 Dictionary<String, Object> props = new Hashtable<String, Object>();
386 props.put("scope", "Global");
389 new String[] { IPluginInInventoryService.class.getName(),
390 IInventoryShimInternalListener.class.getName(),
391 IInventoryProvider.class.getName() }, props);
393 // Now lets add a service dependency to make sure the
394 // provider of service exists
395 c.add(createServiceDependency()
396 .setService(IController.class, "(name=Controller)")
397 .setCallbacks("setController", "unsetController")
399 c.add(createServiceDependency()
400 .setService(IPluginOutInventoryService.class, "(scope=Global)")
401 .setCallbacks("setPluginOutInventoryServices",
402 "unsetPluginOutInventoryServices")
406 if (imp.equals(InventoryServiceShim.class)) {
407 c.setInterface(new String[] { IContainerListener.class.getName(),
408 IOFStatisticsListener.class.getName(), IContainerAware.class.getName() }, null);
410 c.add(createServiceDependency()
411 .setService(IController.class, "(name=Controller)")
412 .setCallbacks("setController", "unsetController")
414 c.add(createServiceDependency()
415 .setService(IInventoryShimInternalListener.class, "(!(scope=Global))")
416 .setCallbacks("setInventoryShimInternalListener",
417 "unsetInventoryShimInternalListener")
419 c.add(createServiceDependency()
420 .setService(IInventoryShimInternalListener.class, "(scope=Global)")
421 .setCallbacks("setInventoryShimGlobalInternalListener",
422 "unsetInventoryShimGlobalInternalListener")
424 c.add(createServiceDependency()
425 .setService(IInventoryShimExternalListener.class)
426 .setCallbacks("setInventoryShimExternalListener",
427 "unsetInventoryShimExternalListener")
428 .setRequired(false));
429 c.add(createServiceDependency()
430 .setService(IPluginOutConnectionService.class)
431 .setCallbacks("setIPluginOutConnectionService",
432 "unsetIPluginOutConnectionService")
436 if (imp.equals(TopologyServiceShim.class)) {
437 c.setInterface(new String[] { IDiscoveryListener.class.getName(), IContainerListener.class.getName(),
438 IRefreshInternalProvider.class.getName(), IInventoryShimExternalListener.class.getName(),
439 IContainerAware.class.getName() }, null);
440 c.add(createServiceDependency()
441 .setService(ITopologyServiceShimListener.class)
442 .setCallbacks("setTopologyServiceShimListener",
443 "unsetTopologyServiceShimListener")
445 c.add(createServiceDependency()
446 .setService(IOFStatisticsManager.class)
447 .setCallbacks("setStatisticsManager",
448 "unsetStatisticsManager").setRequired(false));