2 * Copyright (c) 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
8 package org.opendaylight.controller.sal.compatibility;
10 import com.google.common.base.Preconditions;
11 import org.apache.felix.dm.Component;
12 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.controller.sal.compatibility.adsal.DataPacketServiceAdapter;
16 import org.opendaylight.controller.sal.compatibility.topology.TopologyAdapter;
17 import org.opendaylight.controller.sal.compatibility.topology.TopologyProvider;
18 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
19 import org.opendaylight.controller.sal.core.Node.NodeIDType;
20 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
21 import org.opendaylight.controller.sal.discovery.IDiscoveryService;
22 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
23 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
24 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
25 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
26 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
27 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
28 import org.opendaylight.controller.sal.reader.IPluginInReadService;
29 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
30 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
31 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
32 import org.opendaylight.controller.sal.utils.GlobalConstants;
33 import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
34 import org.opendaylight.controller.sal.utils.INodeFactory;
35 import org.osgi.framework.BundleContext;
37 import java.util.Dictionary;
38 import java.util.Hashtable;
40 public class ComponentActivator extends ComponentActivatorAbstractBase {
41 private final INodeConnectorFactory nodeConnectorFactory = new MDSalNodeConnectorFactory();
42 private final DataPacketServiceAdapter dataPacketService = new DataPacketServiceAdapter();
43 private final InventoryAndReadAdapter inventory = new InventoryAndReadAdapter();
44 private final FlowProgrammerAdapter flow = new FlowProgrammerAdapter();
45 private final DataPacketAdapter dataPacket = new DataPacketAdapter();
46 private final TopologyProvider tpProvider = new TopologyProvider();
47 private final INodeFactory nodeFactory = new MDSalNodeFactory();
48 private final TopologyAdapter topology = new TopologyAdapter();
49 private BundleContext context;
51 public INodeConnectorFactory getNodeConnectorFactory() {
52 return nodeConnectorFactory;
55 public DataPacketServiceAdapter getDataPacketService() {
56 return dataPacketService;
59 public InventoryAndReadAdapter getInventory() {
63 public FlowProgrammerAdapter getFlow() {
67 public DataPacketAdapter getDataPacket() {
71 public TopologyProvider getTpProvider() {
75 public INodeFactory getNodeFactory() {
79 public TopologyAdapter getTopology() {
84 protected void init() {
85 // TODO: deprecated, should be removed soon
86 NodeIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class);
87 NodeConnectorIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class, NodeMapping.MD_SAL_TYPE);
91 public void start(final BundleContext context) {
92 this.context = Preconditions.checkNotNull(context);
96 public ProviderContext setBroker(final BindingAwareBroker broker) {
97 return broker.registerProvider(new SalCompatibilityProvider(this), context);
101 protected Object[] getGlobalImplementations() {
102 return new Object[] {
103 this, // Used for setBroker callback
108 nodeConnectorFactory,
115 protected void configureGlobalInstance(final Component c, final Object imp) {
116 if (imp instanceof DataPacketAdapter) {
117 _configure((DataPacketAdapter)imp, c);
118 } else if (imp instanceof FlowProgrammerAdapter) {
119 _configure((FlowProgrammerAdapter)imp, c);
120 } else if (imp instanceof InventoryAndReadAdapter) {
121 _configure((InventoryAndReadAdapter)imp, c);
122 } else if (imp instanceof ComponentActivator) {
123 _configure((ComponentActivator)imp, c);
124 } else if (imp instanceof MDSalNodeConnectorFactory) {
125 _configure((MDSalNodeConnectorFactory)imp, c);
126 } else if (imp instanceof MDSalNodeFactory) {
127 _configure((MDSalNodeFactory)imp, c);
128 } else if (imp instanceof TopologyAdapter) {
129 _configure((TopologyAdapter)imp, c);
130 } else if (imp instanceof TopologyProvider) {
131 _configure((TopologyProvider)imp, c);
133 throw new IllegalArgumentException(String.format("Unhandled implementation class %s", imp.getClass()));
138 protected Object[] getImplementations() {
139 return new Object[] {
146 protected void configureInstance(final Component c, final Object imp, final String containerName) {
147 if (imp instanceof ComponentActivator) {
148 _instanceConfigure((ComponentActivator)imp, c, containerName);
149 } else if (imp instanceof DataPacketServiceAdapter) {
150 _instanceConfigure((DataPacketServiceAdapter)imp, c, containerName);
151 } else if (imp instanceof InventoryAndReadAdapter) {
152 _instanceConfigure((InventoryAndReadAdapter)imp, c, containerName);
154 throw new IllegalArgumentException(String.format("Unhandled implementation class %s", imp.getClass()));
158 private void _configure(final MDSalNodeFactory imp, final Component it) {
159 it.setInterface(INodeFactory.class.getName(), properties());
162 private void _configure(final MDSalNodeConnectorFactory imp, final Component it) {
163 it.setInterface(INodeConnectorFactory.class.getName(), properties());
166 private void _configure(final ComponentActivator imp, final Component it) {
167 it.add(createServiceDependency()
168 .setService(BindingAwareBroker.class)
169 .setCallbacks("setBroker", "setBroker")
173 private void _configure(final DataPacketAdapter imp, final Component it) {
174 it.add(createServiceDependency()
175 .setService(IPluginOutDataPacketService.class)
176 .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher")
177 .setRequired(false));
180 private void _configure(final FlowProgrammerAdapter imp, final Component it) {
181 it.setInterface(IPluginInFlowProgrammerService.class.getName(), properties());
182 it.add(createServiceDependency()
183 .setService(IPluginOutFlowProgrammerService.class)
184 .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher")
185 .setRequired(false));
186 it.add(createServiceDependency()
187 .setService(IClusterGlobalServices.class)
188 .setCallbacks("setClusterGlobalServices", "unsetClusterGlobalServices")
189 .setRequired(false));
192 private void _instanceConfigure(final DataPacketServiceAdapter imp, final Component it, final String containerName) {
193 it.setInterface(IPluginInDataPacketService.class.getName(), properties());
196 private void _instanceConfigure(final ComponentActivator imp, final Component it, final String containerName) {
200 private void _configure(final InventoryAndReadAdapter imp, final Component it) {
201 it.setInterface(new String[] {
202 IPluginInInventoryService.class.getName(),
203 IPluginInReadService.class.getName(),
206 it.add(createServiceDependency()
207 .setService(IPluginOutReadService.class)
208 .setCallbacks("setReadPublisher", "unsetReadPublisher")
209 .setRequired(false));
210 it.add(createServiceDependency()
211 .setService(IPluginOutInventoryService.class)
212 .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher")
213 .setRequired(false));
214 it.add(createServiceDependency()
215 .setService(IDiscoveryService.class)
216 .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher")
217 .setRequired(false));
218 it.add(createServiceDependency()
219 .setService(BindingAwareBroker.class)
223 private void _instanceConfigure(final InventoryAndReadAdapter imp, final Component it, String containerName) {
224 it.setInterface(new String[] {
225 IPluginInInventoryService.class.getName(),
226 IPluginInReadService.class.getName(),
229 it.add(createServiceDependency()
230 .setService(IPluginOutReadService.class)
231 .setCallbacks("setReadPublisher", "unsetReadPublisher")
232 .setRequired(false));
233 it.add(createServiceDependency()
234 .setService(IPluginOutInventoryService.class)
235 .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher")
236 .setRequired(false));
237 it.add(createServiceDependency()
238 .setService(BindingAwareBroker.class)
242 private void _configure(final TopologyAdapter imp, final Component it) {
243 it.setInterface(IPluginInTopologyService.class.getName(), properties());
245 it.add(createServiceDependency()
246 .setService(IPluginOutTopologyService.class)
247 .setCallbacks("setTopologyPublisher", "setTopologyPublisher")
248 .setRequired(false));
251 private void _configure(final TopologyProvider imp, final Component it) {
252 it.add(createServiceDependency()
253 .setService(IPluginOutTopologyService.class)
254 .setCallbacks("setTopologyPublisher", "setTopologyPublisher")
255 .setRequired(false));
258 private Dictionary<String,Object> properties() {
259 final Hashtable<String,Object> props = new Hashtable<String, Object>();
260 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), NodeIDType.OPENFLOW);
261 props.put("protocolName", NodeIDType.OPENFLOW);