Fix issue where NodeConnector ADDED events were propagated as NodeConnector CHANGED...
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / ComponentActivator.xtend
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.compatibility
9
10 import java.util.Arrays
11 import java.util.Dictionary
12 import java.util.Hashtable
13 import org.apache.felix.dm.Component
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext
16 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer
17 import org.opendaylight.controller.sal.binding.api.NotificationService
18 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService
19 import org.opendaylight.controller.sal.binding.api.data.DataProviderService
20 import org.opendaylight.controller.sal.compatibility.topology.TopologyAdapter
21 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase
22 import org.opendaylight.controller.sal.core.Node
23 import org.opendaylight.controller.sal.core.NodeConnector
24 import org.opendaylight.controller.sal.discovery.IDiscoveryService
25 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService
26 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService
27 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService
28 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService
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.opendaylight.controller.clustering.services.IClusterGlobalServices
38 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService
39
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService
46 import org.osgi.framework.BundleContext
47
48 import static org.opendaylight.controller.sal.compatibility.NodeMapping.*
49 import org.opendaylight.controller.sal.compatibility.topology.TopologyProvider
50 import org.opendaylight.controller.sal.compatibility.adsal.DataPacketServiceAdapter
51 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider
52 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext
53
54 class ComponentActivator extends ComponentActivatorAbstractBase {
55
56     private BundleContext context;
57
58     @Property
59     FlowProgrammerAdapter flow = new FlowProgrammerAdapter;
60
61     @Property
62     InventoryAndReadAdapter inventory = new InventoryAndReadAdapter;
63
64     @Property
65     DataPacketAdapter dataPacket = new DataPacketAdapter;
66
67     @Property
68     INodeFactory nodeFactory = new MDSalNodeFactory
69
70     @Property
71     INodeConnectorFactory nodeConnectorFactory = new MDSalNodeConnectorFactory
72     
73     @Property
74     TopologyAdapter topology = new TopologyAdapter
75     
76     @Property
77     TopologyProvider tpProvider = new TopologyProvider()
78
79     @Property
80     DataPacketServiceAdapter dataPacketService = new DataPacketServiceAdapter()
81
82
83
84     override protected init() {
85         Node.NodeIDType.registerIDType(MD_SAL_TYPE, String);
86         NodeConnector.NodeConnectorIDType.registerIDType(MD_SAL_TYPE, String, MD_SAL_TYPE);
87     }
88
89     override start(BundleContext context) {
90         super.start(context)
91         this.context = context;
92     }
93
94     def setBroker(BindingAwareBroker broker) {
95         broker.registerProvider(new SalCompatibilityProvider(this), context)
96     }
97
98
99     override protected getGlobalImplementations() {
100         return Arrays.asList(this, flow, inventory, dataPacket, nodeFactory, nodeConnectorFactory,topology,tpProvider)
101     }
102
103     override protected configureGlobalInstance(Component c, Object imp) {
104         configure(imp, c);
105     }
106
107     override protected getImplementations() {
108         return Arrays.asList(dataPacketService)
109     }
110
111     override protected configureInstance(Component c, Object imp, String containerName) {
112         instanceConfigure(imp, c, containerName);
113     }
114
115     private def dispatch configure(MDSalNodeFactory imp, Component it) {
116         setInterface(INodeFactory.name, properties);
117     }
118
119     private def dispatch configure(MDSalNodeConnectorFactory imp, Component it) {
120         setInterface(INodeConnectorFactory.name, properties);
121     }
122
123     private def dispatch configure(ComponentActivator imp, Component it) {
124         add(
125             createServiceDependency().setService(BindingAwareBroker) //
126             .setCallbacks("setBroker", "setBroker") //
127             .setRequired(true))
128
129
130     }
131
132     private def dispatch configure(DataPacketAdapter imp, Component it) {
133         add(
134             createServiceDependency() //
135             .setService(IPluginOutDataPacketService) //
136             .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher") //
137             .setRequired(false))
138     }
139
140     private def dispatch configure(FlowProgrammerAdapter imp, Component it) {
141         setInterface(IPluginInFlowProgrammerService.name, properties)
142         add(
143             createServiceDependency() //
144             .setService(IPluginOutFlowProgrammerService) //
145             .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher") //
146             .setRequired(false))
147
148         add(
149             createServiceDependency() //
150             .setService(IClusterGlobalServices) //
151             .setCallbacks("setClusterGlobalServices", "unsetClusterGlobalServices") //
152             .setRequired(false))
153
154     }
155
156     private def dispatch instanceConfigure(DataPacketServiceAdapter imp, Component it, String containerName) {
157         setInterface(IPluginInDataPacketService.name, properties)
158     }
159
160     private def dispatch instanceConfigure(ComponentActivator imp, Component it, String containerName) {
161     }
162
163
164     private def dispatch configure(InventoryAndReadAdapter imp, Component it) {
165         setInterface(Arrays.asList(IPluginInInventoryService.name, IPluginInReadService.name), properties)
166         add(
167             createServiceDependency() //
168             .setService(IPluginOutReadService) //
169             .setCallbacks("setReadPublisher", "unsetReadPublisher") //
170             .setRequired(false))
171         add(
172             createServiceDependency() //
173             .setService(IPluginOutInventoryService) //
174             .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher") //
175             .setRequired(false))
176         add(
177             createServiceDependency() //
178             .setService(IDiscoveryService) //
179             .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher") //
180             .setRequired(false))
181
182         
183     }
184     
185     private def dispatch configure (TopologyAdapter imp, Component it) {
186         setInterface(Arrays.asList(IPluginInTopologyService.name), properties)
187         add(
188             createServiceDependency() //
189             .setService(IPluginOutTopologyService) //
190             .setCallbacks("setTopologyPublisher", "setTopologyPublisher") //
191             .setRequired(false))
192     }
193     
194     private def dispatch configure (TopologyProvider imp, Component it) {
195         add(
196             createServiceDependency() //
197             .setService(IPluginOutTopologyService) //
198             .setCallbacks("setTopologyPublisher", "setTopologyPublisher") //
199             .setRequired(false))
200     }
201
202     private def Dictionary<String, Object> properties() {
203         val props = new Hashtable<String, Object>();
204         props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString, MD_SAL_TYPE)
205         props.put("protocolName", MD_SAL_TYPE);
206         return props;
207     }
208 }
209 package class SalCompatibilityProvider implements BindingAwareProvider {
210     
211     private val ComponentActivator activator;
212     
213     new(ComponentActivator cmpAct) {
214         activator = cmpAct;
215     }
216     
217     override getFunctionality() {
218         // Noop
219     }
220     
221     override getImplementations() {
222         // Noop
223     }
224     
225     
226     override onSessionInitialized(ConsumerContext session) {
227         // Noop
228     }
229     
230     
231     override onSessionInitiated(ProviderContext session) {
232         val it = activator
233                 val subscribe = session.getSALService(NotificationService)
234
235         // Registration of Flow Service
236         flow.delegate = session.getRpcService(SalFlowService)
237         flow.dataBrokerService = session.getSALService(DataBrokerService);
238         subscribe.registerNotificationListener(flow);
239
240         // Data Packet Service
241         subscribe.registerNotificationListener(inventory);
242         dataPacketService.delegate = session.getRpcService(PacketProcessingService)
243
244         // Inventory Service
245         inventory.dataService = session.getSALService(DataBrokerService);
246         inventory.flowStatisticsService = session.getRpcService(OpendaylightFlowStatisticsService);
247         inventory.flowTableStatisticsService = session.getRpcService(OpendaylightFlowTableStatisticsService);
248         inventory.nodeConnectorStatisticsService = session.getRpcService(OpendaylightPortStatisticsService);
249         inventory.topologyDiscovery = session.getRpcService(FlowTopologyDiscoveryService);
250         inventory.dataProviderService = session.getSALService(DataProviderService)
251         topology.dataService = session.getSALService(DataProviderService)
252         tpProvider.dataService = session.getSALService(DataProviderService)
253
254         inventory.start();
255
256         tpProvider.start();
257
258         subscribe.registerNotificationListener(dataPacket)
259     }
260 }