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 java.util.Dictionary;
11 import java.util.Hashtable;
13 import org.apache.felix.dm.Component;
14 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
17 import org.opendaylight.controller.sal.compatibility.adsal.DataPacketServiceAdapter;
18 import org.opendaylight.controller.sal.compatibility.topology.TopologyAdapter;
19 import org.opendaylight.controller.sal.compatibility.topology.TopologyProvider;
20 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
21 import org.opendaylight.controller.sal.core.Node.NodeIDType;
22 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
23 import org.opendaylight.controller.sal.discovery.IDiscoveryService;
24 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
25 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
26 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
27 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
28 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
29 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
30 import org.opendaylight.controller.sal.reader.IPluginInReadService;
31 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
32 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
33 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
34 import org.opendaylight.controller.sal.utils.GlobalConstants;
35 import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
36 import org.opendaylight.controller.sal.utils.INodeFactory;
37 import org.osgi.framework.BundleContext;
39 import com.google.common.base.Preconditions;
41 public class ComponentActivator extends ComponentActivatorAbstractBase {
42 private final INodeConnectorFactory nodeConnectorFactory = new MDSalNodeConnectorFactory();
43 private final DataPacketServiceAdapter dataPacketService = new DataPacketServiceAdapter();
44 private final InventoryAndReadAdapter inventory = new InventoryAndReadAdapter();
45 private final FlowProgrammerAdapter flow = new FlowProgrammerAdapter();
46 private final DataPacketAdapter dataPacket = new DataPacketAdapter();
47 private final TopologyProvider tpProvider = new TopologyProvider();
48 private final INodeFactory nodeFactory = new MDSalNodeFactory();
49 private final TopologyAdapter topology = new TopologyAdapter();
50 private BundleContext context;
52 public INodeConnectorFactory getNodeConnectorFactory() {
53 return nodeConnectorFactory;
56 public DataPacketServiceAdapter getDataPacketService() {
57 return dataPacketService;
60 public InventoryAndReadAdapter getInventory() {
64 public FlowProgrammerAdapter getFlow() {
68 public DataPacketAdapter getDataPacket() {
72 public TopologyProvider getTpProvider() {
76 public INodeFactory getNodeFactory() {
80 public TopologyAdapter getTopology() {
85 protected void init() {
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) {
93 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[] {
107 nodeConnectorFactory,
110 this // Used for setBroker callback
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[] {
145 protected void configureInstance(final Component c, final Object imp, final String containerName) {
146 if (imp instanceof ComponentActivator) {
147 _instanceConfigure((ComponentActivator)imp, c, containerName);
148 } else if (imp instanceof DataPacketServiceAdapter) {
149 _instanceConfigure((DataPacketServiceAdapter)imp, c, containerName);
151 throw new IllegalArgumentException(String.format("Unhandled implementation class %s", imp.getClass()));
155 private void _configure(final MDSalNodeFactory imp, final Component it) {
156 it.setInterface(INodeFactory.class.getName(), properties());
159 private void _configure(final MDSalNodeConnectorFactory imp, final Component it) {
160 it.setInterface(INodeConnectorFactory.class.getName(), properties());
163 private void _configure(final ComponentActivator imp, final Component it) {
164 it.add(createServiceDependency()
165 .setService(BindingAwareBroker.class)
166 .setCallbacks("setBroker", "setBroker")
170 private void _configure(final DataPacketAdapter imp, final Component it) {
171 it.add(createServiceDependency()
172 .setService(IPluginOutDataPacketService.class)
173 .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher")
174 .setRequired(false));
177 private void _configure(final FlowProgrammerAdapter imp, final Component it) {
178 it.setInterface(IPluginInFlowProgrammerService.class.getName(), properties());
179 it.add(createServiceDependency()
180 .setService(IPluginOutFlowProgrammerService.class)
181 .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher")
182 .setRequired(false));
183 it.add(createServiceDependency()
184 .setService(IClusterGlobalServices.class)
185 .setCallbacks("setClusterGlobalServices", "unsetClusterGlobalServices")
186 .setRequired(false));
189 private void _instanceConfigure(final DataPacketServiceAdapter imp, final Component it, final String containerName) {
190 it.setInterface(IPluginInDataPacketService.class.getName(), properties());
193 private void _instanceConfigure(final ComponentActivator imp, final Component it, final String containerName) {
197 private void _configure(final InventoryAndReadAdapter imp, final Component it) {
198 it.setInterface(new String[] {
199 IPluginInInventoryService.class.getName(),
200 IPluginInReadService.class.getName(),
203 it.add(createServiceDependency()
204 .setService(IPluginOutReadService.class)
205 .setCallbacks("setReadPublisher", "unsetReadPublisher")
206 .setRequired(false));
207 it.add(createServiceDependency()
208 .setService(IPluginOutInventoryService.class)
209 .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher")
210 .setRequired(false));
211 it.add(createServiceDependency()
212 .setService(IDiscoveryService.class)
213 .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher")
214 .setRequired(false));
217 private void _configure(final TopologyAdapter imp, final Component it) {
218 it.setInterface(IPluginInTopologyService.class.getName(), properties());
220 it.add(createServiceDependency()
221 .setService(IPluginOutTopologyService.class)
222 .setCallbacks("setTopologyPublisher", "setTopologyPublisher")
223 .setRequired(false));
226 private void _configure(final TopologyProvider imp, final Component it) {
227 it.add(createServiceDependency()
228 .setService(IPluginOutTopologyService.class)
229 .setCallbacks("setTopologyPublisher", "setTopologyPublisher")
230 .setRequired(false));
233 private Dictionary<String,Object> properties() {
234 final Hashtable<String,Object> props = new Hashtable<String, Object>();
235 props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), NodeMapping.MD_SAL_TYPE);
236 props.put("protocolName", NodeMapping.MD_SAL_TYPE);