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.openflowplugin.openflow.internal;
11 import java.util.Collection;
12 import java.util.Collections;
13 import java.util.Dictionary;
14 import java.util.Hashtable;
16 import org.apache.felix.dm.Component;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality;
22 import org.opendaylight.controller.sal.connection.IPluginInConnectionService;
23 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
24 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
25 import org.opendaylight.controller.sal.core.IContainerListener;
26 import org.opendaylight.controller.sal.core.Node;
27 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
28 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
29 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
30 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
31 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
32 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
33 import org.opendaylight.controller.sal.reader.IPluginInReadService;
34 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
35 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
36 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
37 import org.opendaylight.controller.sal.utils.GlobalConstants;
38 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
39 import org.opendaylight.openflowplugin.openflow.IDataPacketListen;
40 import org.opendaylight.openflowplugin.openflow.IDataPacketMux;
41 import org.opendaylight.openflowplugin.openflow.IDiscoveryListener;
42 import org.opendaylight.openflowplugin.openflow.IFlowProgrammerNotifier;
43 import org.opendaylight.openflowplugin.openflow.IInventoryProvider;
44 import org.opendaylight.openflowplugin.openflow.IInventoryShimExternalListener;
45 import org.opendaylight.openflowplugin.openflow.IInventoryShimInternalListener;
46 import org.opendaylight.openflowplugin.openflow.IOFStatisticsListener;
47 import org.opendaylight.openflowplugin.openflow.IOFStatisticsManager;
48 import org.opendaylight.openflowplugin.openflow.IReadFilterInternalListener;
49 import org.opendaylight.openflowplugin.openflow.IReadServiceFilter;
50 import org.opendaylight.openflowplugin.openflow.IRefreshInternalProvider;
51 import org.opendaylight.openflowplugin.openflow.ITopologyServiceShimListener;
52 import org.opendaylight.openflowplugin.openflow.core.IController;
53 import org.opendaylight.openflowplugin.openflow.core.IMessageListener;
54 import org.opendaylight.openflowplugin.openflow.core.internal.Controller;
55 import org.opendaylight.openflowplugin.openflow.md.core.MDController;
56 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
57 import org.opendaylight.openflowplugin.openflow.md.core.sal.SalRegistrationManager;
58 import org.opendaylight.yangtools.yang.binding.RpcService;
59 import org.osgi.framework.BundleContext;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
64 * Openflow protocol plugin Activator
66 public class Activator extends ComponentActivatorAbstractBase {
67 protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
69 private OpenflowPluginProvider pluginProvider = new OpenflowPluginProvider();
72 * Function called when the activator starts just after some initializations
73 * are done by the ComponentActivatorAbstractBase.
80 * Function called when the activator stops just before the cleanup done by
81 * ComponentActivatorAbstractBase
84 public void destroy() {
88 public void start(BundleContext arg0) {
90 pluginProvider.setContext(arg0);
94 * Function that is used to communicate to dependency manager the list of
95 * known implementations for services inside a container
98 * @return An array containing all the CLASS objects that will be
99 * instantiated in order to get an fully working implementation
102 public Object[] getImplementations() {
103 Object[] res = { TopologyServices.class, DataPacketServices.class, InventoryService.class, ReadService.class,
104 FlowProgrammerNotifier.class };
109 * Function that is called when configuration of the dependencies is
113 * dependency manager Component object, used for configuring the
114 * dependencies exported and imported
116 * Implementation class that is being configured, needed as long
117 * as the same routine can configure multiple implementations
118 * @param containerName
119 * The containerName being configured, this allow also optional
120 * per-container different behavior if needed, usually should not
121 * be the case though.
123 public void configureInstance(Component c, Object imp, String containerName) {
124 if (imp.equals(TopologyServices.class)) {
125 // export the service to be used by SAL
127 new String[] { IPluginInTopologyService.class.getName(),
128 ITopologyServiceShimListener.class.getName() }, null);
129 // Hook the services coming in from SAL, as optional in
130 // case SAL is not yet there, could happen
131 c.add(createContainerServiceDependency(containerName).setService(IPluginOutTopologyService.class)
132 .setCallbacks("setPluginOutTopologyService", "unsetPluginOutTopologyService").setRequired(false));
133 c.add(createServiceDependency().setService(IRefreshInternalProvider.class)
134 .setCallbacks("setRefreshInternalProvider", "unsetRefreshInternalProvider").setRequired(false));
137 if (imp.equals(InventoryService.class)) {
138 // export the service
139 c.setInterface(new String[] { IPluginInInventoryService.class.getName(),
140 IInventoryShimInternalListener.class.getName(), IInventoryProvider.class.getName() }, null);
142 // Now lets add a service dependency to make sure the
143 // provider of service exists
144 c.add(createServiceDependency().setService(IController.class, "(name=Controller)")
145 .setCallbacks("setController", "unsetController").setRequired(true));
146 c.add(createContainerServiceDependency(containerName).setService(IPluginOutInventoryService.class)
147 .setCallbacks("setPluginOutInventoryServices", "unsetPluginOutInventoryServices")
148 .setRequired(false));
151 if (imp.equals(DataPacketServices.class)) {
152 // export the service to be used by SAL
153 Dictionary<String, Object> props = new Hashtable<String, Object>();
154 // Set the protocolPluginType property which will be used
156 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
157 c.setInterface(IPluginInDataPacketService.class.getName(), props);
158 // Hook the services coming in from SAL, as optional in
159 // case SAL is not yet there, could happen
160 c.add(createServiceDependency().setService(IController.class, "(name=Controller)")
161 .setCallbacks("setController", "unsetController").setRequired(true));
162 // This is required for the transmission to happen properly
163 c.add(createServiceDependency().setService(IDataPacketMux.class)
164 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux").setRequired(true));
165 c.add(createContainerServiceDependency(containerName).setService(IPluginOutDataPacketService.class)
166 .setCallbacks("setPluginOutDataPacketService", "unsetPluginOutDataPacketService")
167 .setRequired(false));
168 c.add(createServiceDependency().setService(IPluginOutConnectionService.class)
169 .setCallbacks("setIPluginOutConnectionService", "unsetIPluginOutConnectionService")
170 .setRequired(false));
173 if (imp.equals(ReadService.class)) {
174 // export the service to be used by SAL
175 Dictionary<String, Object> props = new Hashtable<String, Object>();
176 // Set the protocolPluginType property which will be used
178 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
180 new String[] { IReadFilterInternalListener.class.getName(), IPluginInReadService.class.getName() },
183 c.add(createServiceDependency().setService(IReadServiceFilter.class)
184 .setCallbacks("setService", "unsetService").setRequired(true));
186 c.add(createContainerServiceDependency(containerName).setService(IPluginOutReadService.class)
187 .setCallbacks("setPluginOutReadServices", "unsetPluginOutReadServices").setRequired(false));
189 c.add(createServiceDependency().setService(IPluginOutConnectionService.class)
190 .setCallbacks("setIPluginOutConnectionService", "unsetIPluginOutConnectionService")
191 .setRequired(false));
194 if (imp.equals(FlowProgrammerNotifier.class)) {
195 // export the service to be used by SAL
196 Dictionary<String, Object> props = new Hashtable<String, Object>();
197 // Set the protocolPluginType property which will be used
199 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
200 c.setInterface(IFlowProgrammerNotifier.class.getName(), props);
202 c.add(createContainerServiceDependency(containerName).setService(IPluginOutFlowProgrammerService.class)
203 .setCallbacks("setPluginOutFlowProgrammerService", "unsetPluginOutFlowProgrammerService")
205 c.add(createServiceDependency().setService(IPluginOutConnectionService.class)
206 .setCallbacks("setIPluginOutConnectionService", "unsetIPluginOutConnectionService")
207 .setRequired(false));
212 * Function that is used to communicate to dependency manager the list of
213 * known implementations for services that are container independent.
216 * @return An array containing all the CLASS objects that will be
217 * instantiated in order to get an fully working implementation
220 public Object[] getGlobalImplementations() {
221 Object[] res = { Controller.class, OFStatisticsManager.class, FlowProgrammerService.class,
222 ReadServiceFilter.class, DiscoveryService.class, DataPacketMuxDemux.class, InventoryService.class,
223 InventoryServiceShim.class, TopologyServiceShim.class, MDController.class, pluginProvider };
228 * Function that is called when configuration of the dependencies is
232 * dependency manager Component object, used for configuring the
233 * dependencies exported and imported
235 * Implementation class that is being configured, needed as long
236 * as the same routine can configure multiple implementations
238 public void configureGlobalInstance(Component c, Object imp) {
240 if (imp.equals(Controller.class)) {
241 logger.debug("Activator configureGlobalInstance( ) is called");
242 Dictionary<String, Object> props = new Hashtable<String, Object>();
243 props.put("name", "Controller");
244 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
245 c.setInterface(new String[] { IController.class.getName(), IPluginInConnectionService.class.getName() },
249 if (imp.equals(FlowProgrammerService.class)) {
250 // export the service to be used by SAL
251 Dictionary<String, Object> props = new Hashtable<String, Object>();
252 // Set the protocolPluginType property which will be used
254 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), Node.NodeIDType.OPENFLOW);
256 new String[] { IPluginInFlowProgrammerService.class.getName(), IMessageListener.class.getName(),
257 IContainerListener.class.getName(), IInventoryShimExternalListener.class.getName() }, props);
259 c.add(createServiceDependency().setService(IController.class, "(name=Controller)")
260 .setCallbacks("setController", "unsetController").setRequired(true));
262 c.add(createServiceDependency().setService(IFlowProgrammerNotifier.class)
263 .setCallbacks("setFlowProgrammerNotifier", "unsetsetFlowProgrammerNotifier").setRequired(false));
265 c.add(createServiceDependency().setService(IPluginOutConnectionService.class)
266 .setCallbacks("setIPluginOutConnectionService", "unsetIPluginOutConnectionService")
267 .setRequired(false));
270 if (imp.equals(ReadServiceFilter.class)) {
272 c.setInterface(new String[] { IReadServiceFilter.class.getName(), IContainerListener.class.getName(),
273 IOFStatisticsListener.class.getName() }, null);
275 c.add(createServiceDependency().setService(IController.class, "(name=Controller)")
276 .setCallbacks("setController", "unsetController").setRequired(true));
277 c.add(createServiceDependency().setService(IOFStatisticsManager.class)
278 .setCallbacks("setService", "unsetService").setRequired(true));
279 c.add(createServiceDependency().setService(IReadFilterInternalListener.class)
280 .setCallbacks("setReadFilterInternalListener", "unsetReadFilterInternalListener")
281 .setRequired(false));
284 if (imp.equals(OFStatisticsManager.class)) {
287 new String[] { IOFStatisticsManager.class.getName(), IInventoryShimExternalListener.class.getName() },
290 c.add(createServiceDependency().setService(IController.class, "(name=Controller)")
291 .setCallbacks("setController", "unsetController").setRequired(true));
292 c.add(createServiceDependency().setService(IOFStatisticsListener.class)
293 .setCallbacks("setStatisticsListener", "unsetStatisticsListener").setRequired(false));
296 if (imp.equals(DiscoveryService.class)) {
297 // export the service
299 new String[] { IInventoryShimExternalListener.class.getName(), IDataPacketListen.class.getName(),
300 IContainerListener.class.getName() }, null);
302 c.add(createServiceDependency().setService(IController.class, "(name=Controller)")
303 .setCallbacks("setController", "unsetController").setRequired(true));
304 c.add(createContainerServiceDependency(GlobalConstants.DEFAULT.toString())
305 .setService(IInventoryProvider.class)
306 .setCallbacks("setInventoryProvider", "unsetInventoryProvider").setRequired(true));
307 c.add(createServiceDependency().setService(IDataPacketMux.class)
308 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux").setRequired(true));
309 c.add(createServiceDependency().setService(IDiscoveryListener.class)
310 .setCallbacks("setDiscoveryListener", "unsetDiscoveryListener").setRequired(true));
311 c.add(createServiceDependency().setService(IPluginOutConnectionService.class)
312 .setCallbacks("setIPluginOutConnectionService", "unsetIPluginOutConnectionService")
313 .setRequired(false));
316 // DataPacket mux/demux services, which is teh actual engine
317 // doing the packet switching
318 if (imp.equals(DataPacketMuxDemux.class)) {
319 c.setInterface(new String[] { IDataPacketMux.class.getName(), IContainerListener.class.getName(),
320 IInventoryShimExternalListener.class.getName() }, null);
322 c.add(createServiceDependency().setService(IController.class, "(name=Controller)")
323 .setCallbacks("setController", "unsetController").setRequired(true));
324 c.add(createServiceDependency().setService(IPluginOutDataPacketService.class)
325 .setCallbacks("setPluginOutDataPacketService", "unsetPluginOutDataPacketService")
326 .setRequired(false));
327 // See if there is any local packet dispatcher
328 c.add(createServiceDependency().setService(IDataPacketListen.class)
329 .setCallbacks("setIDataPacketListen", "unsetIDataPacketListen").setRequired(false));
330 c.add(createServiceDependency().setService(IPluginOutConnectionService.class)
331 .setCallbacks("setIPluginOutConnectionService", "unsetIPluginOutConnectionService")
332 .setRequired(false));
335 if (imp.equals(InventoryService.class)) {
336 // export the service
337 Dictionary<String, Object> props = new Hashtable<String, Object>();
338 props.put("scope", "Global");
340 c.setInterface(new String[] { IPluginInInventoryService.class.getName(),
341 IInventoryShimInternalListener.class.getName(), IInventoryProvider.class.getName() }, props);
343 // Now lets add a service dependency to make sure the
344 // provider of service exists
345 c.add(createServiceDependency().setService(IController.class, "(name=Controller)")
346 .setCallbacks("setController", "unsetController").setRequired(true));
347 c.add(createServiceDependency().setService(IPluginOutInventoryService.class, "(scope=Global)")
348 .setCallbacks("setPluginOutInventoryServices", "unsetPluginOutInventoryServices")
349 .setRequired(false));
352 if (imp.equals(InventoryServiceShim.class)) {
353 c.setInterface(new String[] { IContainerListener.class.getName(), IOFStatisticsListener.class.getName() },
356 c.add(createServiceDependency().setService(IController.class, "(name=Controller)")
357 .setCallbacks("setController", "unsetController").setRequired(true));
358 c.add(createServiceDependency().setService(IInventoryShimInternalListener.class, "(!(scope=Global))")
359 .setCallbacks("setInventoryShimInternalListener", "unsetInventoryShimInternalListener")
361 c.add(createServiceDependency().setService(IInventoryShimInternalListener.class, "(scope=Global)")
362 .setCallbacks("setInventoryShimGlobalInternalListener", "unsetInventoryShimGlobalInternalListener")
364 c.add(createServiceDependency().setService(IInventoryShimExternalListener.class)
365 .setCallbacks("setInventoryShimExternalListener", "unsetInventoryShimExternalListener")
366 .setRequired(false));
367 c.add(createServiceDependency().setService(IPluginOutConnectionService.class)
368 .setCallbacks("setIPluginOutConnectionService", "unsetIPluginOutConnectionService")
369 .setRequired(false));
372 if (imp.equals(TopologyServiceShim.class)) {
373 c.setInterface(new String[] { IDiscoveryListener.class.getName(), IContainerListener.class.getName(),
374 IRefreshInternalProvider.class.getName(), IInventoryShimExternalListener.class.getName() }, null);
375 c.add(createServiceDependency().setService(ITopologyServiceShimListener.class)
376 .setCallbacks("setTopologyServiceShimListener", "unsetTopologyServiceShimListener")
378 c.add(createServiceDependency().setService(IOFStatisticsManager.class)
379 .setCallbacks("setStatisticsManager", "unsetStatisticsManager").setRequired(false));
382 if (imp == pluginProvider) {
383 // c.setInterface(new String[] { IDiscoveryListener.class.getName(),
384 // IContainerListener.class.getName(),
385 // IRefreshInternalProvider.class.getName(),
386 // IInventoryShimExternalListener.class.getName() }, null);
387 c.add(createServiceDependency().setService(BindingAwareBroker.class)
388 .setCallbacks("setBroker", "unsetBroker").setRequired(true));
389 c.add(createServiceDependency().setService(SwitchConnectionProvider.class)
390 .setCallbacks("setSwitchConnectionProvider", "unsetSwitchConnectionProvider").setRequired(true));
391 logger.debug("configuring Binding Aware Provider");