3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.protocol_plugin.openflow.internal;
12 import java.util.Dictionary;
13 import java.util.Hashtable;
15 import org.apache.felix.dm.Component;
16 import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketListen;
17 import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketMux;
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.internal.Controller;
27 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
28 import org.opendaylight.controller.sal.core.IContainerListener;
29 import org.opendaylight.controller.sal.core.Node;
30 import org.opendaylight.controller.sal.discovery.IDiscoveryService;
31 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
32 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
33 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
34 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
35 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
36 import org.opendaylight.controller.sal.reader.IPluginInReadService;
37 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
38 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
39 import org.opendaylight.controller.sal.utils.GlobalConstants;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * Openflow protocol plugin Activator
48 public class Activator extends ComponentActivatorAbstractBase {
49 protected static final Logger logger = LoggerFactory
50 .getLogger(Activator.class);
53 * Function called when the activator starts just after some
54 * initializations are done by the
55 * ComponentActivatorAbstractBase.
62 * Function called when the activator stops just before the
63 * cleanup done by ComponentActivatorAbstractBase
66 public void destroy() {
70 * Function that is used to communicate to dependency manager the
71 * list of known implementations for services inside a container
74 * @return An array containing all the CLASS objects that will be
75 * instantiated in order to get an fully working implementation
78 public Object[] getImplementations() {
79 Object[] res = { TopologyServices.class, DataPacketServices.class,
80 InventoryService.class, ReadService.class };
85 * Function that is called when configuration of the dependencies
88 * @param c dependency manager Component object, used for
89 * configuring the dependencies exported and imported
90 * @param imp Implementation class that is being configured,
91 * needed as long as the same routine can configure multiple
93 * @param containerName The containerName being configured, this allow
94 * also optional per-container different behavior if needed, usually
95 * should not be the case though.
97 public void configureInstance(Component c, Object imp, String containerName) {
98 if (imp.equals(TopologyServices.class)) {
99 // export the service to be used by SAL
100 c.setInterface(new String[] {
101 IPluginInTopologyService.class.getName(),
102 ITopologyServiceShimListener.class.getName() }, null);
103 // Hook the services coming in from SAL, as optional in
104 // case SAL is not yet there, could happen
105 c.add(createContainerServiceDependency(containerName).setService(
106 IPluginOutTopologyService.class).setCallbacks(
107 "setPluginOutTopologyService",
108 "unsetPluginOutTopologyService").setRequired(false));
109 c.add(createServiceDependency().setService(
110 IRefreshInternalProvider.class).setCallbacks(
111 "setRefreshInternalProvider",
112 "unsetRefreshInternalProvider").setRequired(false));
115 if (imp.equals(InventoryService.class)) {
116 // export the service
117 c.setInterface(new String[] {
118 IPluginInInventoryService.class.getName(),
119 IStatisticsListener.class.getName(),
120 IInventoryShimInternalListener.class.getName() }, null);
122 // Now lets add a service dependency to make sure the
123 // provider of service exists
124 c.add(createServiceDependency().setService(IController.class,
125 "(name=Controller)").setCallbacks("setController",
126 "unsetController").setRequired(true));
127 c.add(createContainerServiceDependency(containerName).setService(
128 IPluginOutInventoryService.class).setCallbacks(
129 "setPluginOutInventoryServices",
130 "unsetPluginOutInventoryServices").setRequired(false));
133 if (imp.equals(DataPacketServices.class)) {
134 // export the service to be used by SAL
135 Dictionary<String, Object> props = new Hashtable<String, Object>();
136 // Set the protocolPluginType property which will be used
138 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
139 c.setInterface(IPluginInDataPacketService.class.getName(), props);
140 // Hook the services coming in from SAL, as optional in
141 // case SAL is not yet there, could happen
142 c.add(createServiceDependency().setService(IController.class,
143 "(name=Controller)").setCallbacks("setController",
144 "unsetController").setRequired(true));
145 // This is required for the transmission to happen properly
146 c.add(createServiceDependency().setService(IDataPacketMux.class)
147 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
149 c.add(createContainerServiceDependency(containerName).setService(
150 IPluginOutDataPacketService.class).setCallbacks(
151 "setPluginOutDataPacketService",
152 "unsetPluginOutDataPacketService").setRequired(false));
155 if (imp.equals(ReadService.class)) {
156 // export the service to be used by SAL
157 Dictionary<String, Object> props = new Hashtable<String, Object>();
158 // Set the protocolPluginType property which will be used
160 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
161 c.setInterface(IPluginInReadService.class.getName(), props);
162 c.add(createServiceDependency().setService(
163 IPluginReadServiceFilter.class).setCallbacks("setService",
164 "unsetService").setRequired(true));
169 * Function that is used to communicate to dependency manager the
170 * list of known implementations for services that are container
174 * @return An array containing all the CLASS objects that will be
175 * instantiated in order to get an fully working implementation
178 public Object[] getGlobalImplementations() {
179 Object[] res = { Controller.class, OFStatisticsManager.class,
180 FlowProgrammerService.class, ReadServiceFilter.class,
181 DiscoveryService.class, DataPacketMuxDemux.class,
182 InventoryServiceShim.class, TopologyServiceShim.class };
187 * Function that is called when configuration of the dependencies
190 * @param c dependency manager Component object, used for
191 * configuring the dependencies exported and imported
192 * @param imp Implementation class that is being configured,
193 * needed as long as the same routine can configure multiple
196 public void configureGlobalInstance(Component c, Object imp) {
198 if (imp.equals(Controller.class)) {
199 logger.debug("Activator configureGlobalInstance( ) is called");
200 Dictionary<String, Object> props = new Hashtable<String, Object>();
201 props.put("name", "Controller");
202 c.setInterface(IController.class.getName(), props);
205 if (imp.equals(FlowProgrammerService.class)) {
206 // export the service to be used by SAL
207 Dictionary<String, Object> props = new Hashtable<String, Object>();
208 // Set the protocolPluginType property which will be used
210 props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
211 c.setInterface(IPluginInFlowProgrammerService.class
214 c.add(createServiceDependency().setService(IController.class,
215 "(name=Controller)").setCallbacks("setController",
216 "unsetController").setRequired(true));
219 if (imp.equals(ReadServiceFilter.class)) {
221 c.setInterface(new String[] {
222 IPluginReadServiceFilter.class.getName(),
223 IContainerListener.class.getName() }, null);
225 c.add(createServiceDependency().setService(IController.class,
226 "(name=Controller)").setCallbacks("setController",
227 "unsetController").setRequired(true));
228 c.add(createServiceDependency().setService(
229 IOFStatisticsManager.class).setCallbacks("setService",
230 "unsetService").setRequired(true));
233 if (imp.equals(OFStatisticsManager.class)) {
235 c.setInterface(new String[] { IOFStatisticsManager.class.getName(),
236 IInventoryShimExternalListener.class.getName() }, null);
238 c.add(createServiceDependency().setService(IController.class,
239 "(name=Controller)").setCallbacks("setController",
240 "unsetController").setRequired(true));
241 c.add(createServiceDependency().setService(
242 IStatisticsListener.class)
243 .setCallbacks("setStatisticsListener",
244 "unsetStatisticsListener").setRequired(false));
247 if (imp.equals(DiscoveryService.class)) {
248 // export the service
249 c.setInterface(new String[] {
250 IInventoryShimExternalListener.class.getName(),
251 IDataPacketListen.class.getName(),
252 IContainerListener.class.getName() }, null);
254 c.add(createServiceDependency().setService(IController.class,
255 "(name=Controller)").setCallbacks("setController",
256 "unsetController").setRequired(true));
257 c.add(createContainerServiceDependency(
258 GlobalConstants.DEFAULT.toString()).setService(
259 IPluginInInventoryService.class).setCallbacks(
260 "setPluginInInventoryService",
261 "unsetPluginInInventoryService").setRequired(true));
262 c.add(createServiceDependency().setService(IDataPacketMux.class)
263 .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux")
265 c.add(createServiceDependency().setService(IDiscoveryService.class)
266 .setCallbacks("setDiscoveryService",
267 "unsetDiscoveryService").setRequired(true));
270 // DataPacket mux/demux services, which is teh actual engine
271 // doing the packet switching
272 if (imp.equals(DataPacketMuxDemux.class)) {
273 c.setInterface(new String[] { IDataPacketMux.class.getName(),
274 IContainerListener.class.getName(),
275 IInventoryShimExternalListener.class.getName() }, null);
277 c.add(createServiceDependency().setService(IController.class,
278 "(name=Controller)").setCallbacks("setController",
279 "unsetController").setRequired(true));
280 c.add(createServiceDependency().setService(
281 IPluginOutDataPacketService.class).setCallbacks(
282 "setPluginOutDataPacketService",
283 "unsetPluginOutDataPacketService").setRequired(false));
284 // See if there is any local packet dispatcher
285 c.add(createServiceDependency().setService(IDataPacketListen.class)
286 .setCallbacks("setIDataPacketListen",
287 "unsetIDataPacketListen").setRequired(false));
290 if (imp.equals(InventoryServiceShim.class)) {
291 c.setInterface(new String[] { IContainerListener.class.getName() },
294 c.add(createServiceDependency().setService(IController.class,
295 "(name=Controller)").setCallbacks("setController",
296 "unsetController").setRequired(true));
297 c.add(createServiceDependency().setService(
298 IInventoryShimInternalListener.class).setCallbacks(
299 "setInventoryShimInternalListener",
300 "unsetInventoryShimInternalListener").setRequired(true));
301 c.add(createServiceDependency().setService(
302 IInventoryShimExternalListener.class).setCallbacks(
303 "setInventoryShimExternalListener",
304 "unsetInventoryShimExternalListener").setRequired(false));
307 if (imp.equals(TopologyServiceShim.class)) {
308 c.setInterface(new String[] { IDiscoveryService.class.getName(),
309 IContainerListener.class.getName(),
310 IRefreshInternalProvider.class.getName() }, null);
311 c.add(createServiceDependency().setService(
312 ITopologyServiceShimListener.class).setCallbacks(
313 "setTopologyServiceShimListener",
314 "unsetTopologyServiceShimListener").setRequired(true));
315 c.add(createServiceDependency().setService(
316 IOFStatisticsManager.class).setCallbacks(
317 "setStatisticsManager", "unsetStatisticsManager")
318 .setRequired(false));