1 package org.opendaylight.ovsdb.openstack.netvirt;
3 import java.util.ArrayList;
4 import java.util.Dictionary;
5 import java.util.Hashtable;
7 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
8 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
9 import org.opendaylight.neutron.spi.*;
10 import org.opendaylight.ovsdb.openstack.netvirt.api.*;
11 import org.opendaylight.ovsdb.openstack.netvirt.impl.*;
12 import org.osgi.framework.BundleActivator;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.ServiceReference;
15 import org.osgi.framework.ServiceRegistration;
16 import org.osgi.util.tracker.ServiceTracker;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class ConfigActivator implements BundleActivator {
21 private static final Logger LOG = LoggerFactory.getLogger(ConfigActivator.class);
22 private List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
23 private ProviderContext providerContext;
24 private ServiceTracker iNeutronNetworkCRUDTracker;
25 private ServiceTracker iNeutronPortCRUDTracker;
26 private ServiceTracker iNeutronLoadBalancerCRUDTracker;
27 private ServiceTracker iNeutronLoadBalancerPoolCRUDTracker;
28 private ServiceTracker iNeutronSubnetCRUDTracker;
29 private ServiceTracker loadBalancerProviderTracker;
30 private ServiceTracker arpProviderTracker;
31 private ServiceTracker inboundNatProviderTracker;
32 private ServiceTracker outboundNatProviderTracker;
33 private ServiceTracker routingProviderTracker;
34 private ServiceTracker l3ForwardingProviderTracker;
36 public ConfigActivator(ProviderContext providerContext) {
37 this.providerContext = providerContext;
41 public void start(BundleContext context) throws Exception {
42 LOG.info("ConfigActivator start:");
44 ConfigurationServiceImpl configurationService = new ConfigurationServiceImpl();
45 registerService(context, new String[] {ConfigurationService.class.getName()},
46 null, configurationService);
48 BridgeConfigurationManagerImpl bridgeConfigurationManager = new BridgeConfigurationManagerImpl();
49 registerService(context, new String[] {BridgeConfigurationManager.class.getName()},
50 null, bridgeConfigurationManager);
52 final TenantNetworkManagerImpl tenantNetworkManager = new TenantNetworkManagerImpl();
53 registerService(context, new String[] {TenantNetworkManager.class.getName()},
54 null, tenantNetworkManager);
56 VlanConfigurationCacheImpl vlanConfigurationCache = new VlanConfigurationCacheImpl();
57 registerService(context, new String[] {VlanConfigurationCache.class.getName()},
58 null, vlanConfigurationCache);
60 Dictionary<String, Object> floatingIPHandlerProperties = new Hashtable<>();
61 floatingIPHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
62 AbstractEvent.HandlerType.NEUTRON_FLOATING_IP);
63 FloatingIPHandler floatingIPHandler = new FloatingIPHandler();
64 registerService(context,
65 new String[] {INeutronFloatingIPAware.class.getName(), AbstractHandler.class.getName()},
66 floatingIPHandlerProperties, floatingIPHandler);
68 Dictionary<String, Object> networkHandlerProperties = new Hashtable<>();
69 networkHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_NETWORK);
70 final NetworkHandler networkHandler = new NetworkHandler();
71 registerService(context,
72 new String[]{INeutronNetworkAware.class.getName(), AbstractHandler.class.getName()},
73 networkHandlerProperties, networkHandler);
75 Dictionary<String, Object> subnetHandlerProperties = new Hashtable<>();
76 subnetHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_SUBNET);
77 SubnetHandler subnetHandler = new SubnetHandler();
78 registerService(context,
79 new String[] {INeutronSubnetAware.class.getName(), AbstractHandler.class.getName()},
80 subnetHandlerProperties, subnetHandler);
82 Dictionary<String, Object> portHandlerProperties = new Hashtable<>();
83 portHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_PORT);
84 PortHandler portHandler = new PortHandler();
85 registerService(context,
86 new String[]{INeutronPortAware.class.getName(), AbstractHandler.class.getName()},
87 portHandlerProperties, portHandler);
89 Dictionary<String, Object> routerHandlerProperties = new Hashtable<>();
90 routerHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_ROUTER);
91 RouterHandler routerHandler = new RouterHandler();
92 registerService(context,
93 new String[]{INeutronRouterAware.class.getName(), AbstractHandler.class.getName()},
94 routerHandlerProperties, routerHandler);
96 Dictionary<String, Object> southboundHandlerProperties = new Hashtable<>();
97 southboundHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.SOUTHBOUND);
98 SouthboundHandler southboundHandler = new SouthboundHandler();
99 registerService(context,
100 new String[]{OvsdbInventoryListener.class.getName(),
101 NodeCacheListener.class.getName(),
102 AbstractHandler.class.getName()},
103 southboundHandlerProperties, southboundHandler);
105 Dictionary<String, Object> lbaasHandlerProperties = new Hashtable<>();
106 lbaasHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
107 AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER);
108 final LBaaSHandler lBaaSHandler = new LBaaSHandler();
109 registerService(context,
110 new String[]{INeutronLoadBalancerAware.class.getName(),
111 NodeCacheListener.class.getName(), AbstractHandler.class.getName()},
112 lbaasHandlerProperties, lBaaSHandler);
114 Dictionary<String, Object> lbaasPoolHandlerProperties = new Hashtable<>();
115 lbaasPoolHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
116 AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL);
117 final LBaaSPoolHandler lBaaSPoolHandler = new LBaaSPoolHandler();
118 registerService(context,
119 new String[]{INeutronLoadBalancerPoolAware.class.getName(),
120 AbstractHandler.class.getName()}, lbaasPoolHandlerProperties, lBaaSPoolHandler);
122 Dictionary<String, Object> lbaasPoolMemberHandlerProperties = new Hashtable<>();
123 lbaasPoolMemberHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
124 AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL_MEMBER);
125 final LBaaSPoolMemberHandler lBaaSPoolMemberHandler = new LBaaSPoolMemberHandler();
126 registerService(context,
127 new String[]{INeutronLoadBalancerPoolMemberAware.class.getName(),
128 AbstractHandler.class.getName()}, lbaasPoolMemberHandlerProperties, lBaaSPoolMemberHandler);
130 Dictionary<String, Object> portSecurityHandlerProperties = new Hashtable<>();
131 portSecurityHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
132 AbstractEvent.HandlerType.NEUTRON_PORT_SECURITY);
133 PortSecurityHandler portSecurityHandler = new PortSecurityHandler();
134 registerService(context,
135 new String[]{INeutronSecurityRuleAware.class.getName(),
136 INeutronSecurityGroupAware.class.getName(), AbstractHandler.class.getName()},
137 portSecurityHandlerProperties, portSecurityHandler);
139 final SecurityServicesImpl securityServices = new SecurityServicesImpl();
140 registerService(context,
141 new String[]{SecurityServicesManager.class.getName()}, null, securityServices);
143 Dictionary<String, Object> fWaasHandlerProperties = new Hashtable<>();
144 fWaasHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_FWAAS);
145 FWaasHandler fWaasHandler = new FWaasHandler();
146 registerService(context,
147 new String[]{INeutronFirewallAware.class.getName(),
148 INeutronFirewallRuleAware.class.getName(), INeutronFirewallPolicyAware.class.getName(),
149 AbstractHandler.class.getName()}, fWaasHandlerProperties, fWaasHandler);
151 ProviderNetworkManagerImpl providerNetworkManager = new ProviderNetworkManagerImpl();
152 registerService(context,
153 new String[]{NetworkingProviderManager.class.getName()}, null, providerNetworkManager);
155 EventDispatcherImpl eventDispatcher = new EventDispatcherImpl();
156 registerService(context,
157 new String[]{EventDispatcher.class.getName()}, null, eventDispatcher);
159 final NeutronL3Adapter neutronL3Adapter = new NeutronL3Adapter();
160 registerService(context,
161 new String[]{NeutronL3Adapter.class.getName()}, null, neutronL3Adapter);
163 OpenstackRouter openstackRouter = new OpenstackRouter();
164 registerService(context,
165 new String[]{MultiTenantAwareRouter.class.getName()}, null, openstackRouter);
167 Southbound southbound = new SouthboundImpl(providerContext.getSALService(DataBroker.class));
168 registerService(context,
169 new String[]{Southbound.class.getName()}, null, southbound);
171 Dictionary<String, Object> nodeCacheManagerProperties = new Hashtable<>();
172 nodeCacheManagerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NODE);
173 NodeCacheManagerImpl nodeCacheManager = new NodeCacheManagerImpl();
174 registerService(context,
175 new String[]{NodeCacheManager.class.getName(), AbstractHandler.class.getName()},
176 nodeCacheManagerProperties, nodeCacheManager);
178 OvsdbInventoryServiceImpl ovsdbInventoryService = new OvsdbInventoryServiceImpl(providerContext);
179 registerService(context,
180 new String[] {OvsdbInventoryService.class.getName()}, null, ovsdbInventoryService);
182 ovsdbInventoryService.setDependencies(context, null);
183 nodeCacheManager.setDependencies(context, null);
184 openstackRouter.setDependencies(context, null);
185 neutronL3Adapter.setDependencies(context, null);
186 eventDispatcher.setDependencies(context, null);
187 providerNetworkManager.setDependencies(context, null);
188 fWaasHandler.setDependencies(context, null);
189 securityServices.setDependencies(context, null);
190 portSecurityHandler.setDependencies(context, null);
191 lBaaSPoolMemberHandler.setDependencies(context, null);
192 lBaaSPoolHandler.setDependencies(context, null);
193 lBaaSHandler.setDependencies(context, null);
194 southboundHandler.setDependencies(context, null);
195 routerHandler.setDependencies(context, null);
196 portHandler.setDependencies(context, null);
197 subnetHandler.setDependencies(context, null);
198 networkHandler.setDependencies(context, null);
199 floatingIPHandler.setDependencies(context, null);
200 vlanConfigurationCache.setDependencies(context, null);
201 tenantNetworkManager.setDependencies(context, null);
202 bridgeConfigurationManager.setDependencies(context, null);
203 configurationService.setDependencies(context, null);
205 // TODO check if services are already available and setDependencies
206 // addingService may not be called if the service is already available when the ServiceTracker
208 @SuppressWarnings("unchecked")
209 ServiceTracker iNeutronNetworkCRUDTracker = new ServiceTracker(context, INeutronNetworkCRUD.class, null) {
211 public Object addingService(ServiceReference reference) {
212 LOG.info("addingService INeutronNetworkCRUD");
213 INeutronNetworkCRUD service = (INeutronNetworkCRUD)context.getService(reference);
214 if (service != null) {
215 tenantNetworkManager.setDependencies(service);
216 networkHandler.setDependencies(service);
217 lBaaSHandler.setDependencies(service);
218 lBaaSPoolHandler.setDependencies(service);
219 lBaaSPoolMemberHandler.setDependencies(service);
220 neutronL3Adapter.setDependencies(service);
225 iNeutronNetworkCRUDTracker.open();
226 this.iNeutronNetworkCRUDTracker = iNeutronNetworkCRUDTracker;
228 @SuppressWarnings("unchecked")
229 ServiceTracker iNeutronSubnetCRUDTracker = new ServiceTracker(context, INeutronSubnetCRUD.class, null) {
231 public Object addingService(ServiceReference reference) {
232 LOG.info("addingService INeutronSubnetCRUD");
233 INeutronSubnetCRUD service = (INeutronSubnetCRUD) context.getService(reference);
234 if (service != null) {
235 lBaaSHandler.setDependencies(service);
236 lBaaSPoolHandler.setDependencies(service);
237 lBaaSPoolMemberHandler.setDependencies(service);
238 securityServices.setDependencies(service);
239 neutronL3Adapter.setDependencies(service);
244 iNeutronSubnetCRUDTracker.open();
245 this.iNeutronSubnetCRUDTracker = iNeutronSubnetCRUDTracker;
247 @SuppressWarnings("unchecked")
248 ServiceTracker iNeutronPortCRUDTracker = new ServiceTracker(context, INeutronPortCRUD.class, null) {
250 public Object addingService(ServiceReference reference) {
251 LOG.info("addingService INeutronPortCRUD");
252 INeutronPortCRUD service = (INeutronPortCRUD) context.getService(reference);
253 if (service != null) {
254 tenantNetworkManager.setDependencies(service);
255 lBaaSHandler.setDependencies(service);
256 lBaaSPoolHandler.setDependencies(service);
257 lBaaSPoolMemberHandler.setDependencies(service);
258 securityServices.setDependencies(service);
259 neutronL3Adapter.setDependencies(service);
264 iNeutronPortCRUDTracker.open();
265 this.iNeutronPortCRUDTracker = iNeutronPortCRUDTracker;
267 @SuppressWarnings("unchecked")
268 ServiceTracker iNeutronLoadBalancerCRUDTracker = new ServiceTracker(context,
269 INeutronLoadBalancerCRUD.class, null) {
271 public Object addingService(ServiceReference reference) {
272 LOG.info("addingService INeutronLoadBalancerCRUD");
273 INeutronLoadBalancerCRUD service = (INeutronLoadBalancerCRUD) context.getService(reference);
274 if (service != null) {
275 lBaaSHandler.setDependencies(service);
276 lBaaSPoolHandler.setDependencies(service);
277 lBaaSPoolMemberHandler.setDependencies(service);
282 iNeutronLoadBalancerCRUDTracker.open();
283 this.iNeutronLoadBalancerCRUDTracker = iNeutronLoadBalancerCRUDTracker;
285 @SuppressWarnings("unchecked")
286 ServiceTracker iNeutronLoadBalancerPoolCRUDTracker = new ServiceTracker(context,
287 INeutronLoadBalancerPoolCRUD.class, null) {
289 public Object addingService(ServiceReference reference) {
290 LOG.info("addingService INeutronLoadBalancerPoolCRUD");
291 INeutronLoadBalancerPoolCRUD service =
292 (INeutronLoadBalancerPoolCRUD) context.getService(reference);
293 if (service != null) {
294 lBaaSHandler.setDependencies(service);
295 lBaaSPoolMemberHandler.setDependencies(service);
300 iNeutronLoadBalancerPoolCRUDTracker.open();
301 this.iNeutronLoadBalancerPoolCRUDTracker = iNeutronLoadBalancerPoolCRUDTracker;
303 @SuppressWarnings("unchecked")
304 ServiceTracker ioadBalancerProviderTracker = new ServiceTracker(context,
305 LoadBalancerProvider.class, null) {
307 public Object addingService(ServiceReference reference) {
308 LOG.info("addingService LoadBalancerProvider");
309 LoadBalancerProvider service =
310 (LoadBalancerProvider) context.getService(reference);
311 if (service != null) {
312 lBaaSHandler.setDependencies(service);
313 lBaaSPoolHandler.setDependencies(service);
314 lBaaSPoolMemberHandler.setDependencies(service);
319 ioadBalancerProviderTracker.open();
320 this.loadBalancerProviderTracker = ioadBalancerProviderTracker;
322 @SuppressWarnings("unchecked")
323 ServiceTracker arpProviderTracker = new ServiceTracker(context,
324 ArpProvider.class, null) {
326 public Object addingService(ServiceReference reference) {
327 LOG.info("addingService ArpProvider");
328 ArpProvider service =
329 (ArpProvider) context.getService(reference);
330 if (service != null) {
331 neutronL3Adapter.setDependencies(service);
336 arpProviderTracker.open();
337 this.arpProviderTracker = arpProviderTracker;
339 @SuppressWarnings("unchecked")
340 ServiceTracker inboundNatProviderTracker = new ServiceTracker(context,
341 InboundNatProvider.class, null) {
343 public Object addingService(ServiceReference reference) {
344 LOG.info("addingService InboundNatProvider");
345 InboundNatProvider service =
346 (InboundNatProvider) context.getService(reference);
347 if (service != null) {
348 neutronL3Adapter.setDependencies(service);
353 inboundNatProviderTracker.open();
354 this.inboundNatProviderTracker = inboundNatProviderTracker;
356 @SuppressWarnings("unchecked")
357 ServiceTracker outboundNatProviderTracker = new ServiceTracker(context,
358 OutboundNatProvider.class, null) {
360 public Object addingService(ServiceReference reference) {
361 LOG.info("addingService OutboundNatProvider");
362 OutboundNatProvider service =
363 (OutboundNatProvider) context.getService(reference);
364 if (service != null) {
365 neutronL3Adapter.setDependencies(service);
370 outboundNatProviderTracker.open();
371 this.outboundNatProviderTracker = outboundNatProviderTracker;
373 @SuppressWarnings("unchecked")
374 ServiceTracker routingProviderTracker = new ServiceTracker(context,
375 RoutingProvider.class, null) {
377 public Object addingService(ServiceReference reference) {
378 LOG.info("addingService RoutingProvider");
379 RoutingProvider service =
380 (RoutingProvider) context.getService(reference);
381 if (service != null) {
382 neutronL3Adapter.setDependencies(service);
387 routingProviderTracker.open();
388 this.routingProviderTracker = routingProviderTracker;
390 @SuppressWarnings("unchecked")
391 ServiceTracker l3ForwardingProviderTracker = new ServiceTracker(context,
392 L3ForwardingProvider.class, null) {
394 public Object addingService(ServiceReference reference) {
395 LOG.info("addingService L3ForwardingProvider");
396 L3ForwardingProvider service =
397 (L3ForwardingProvider) context.getService(reference);
398 if (service != null) {
399 neutronL3Adapter.setDependencies(service);
404 l3ForwardingProviderTracker.open();
405 this.l3ForwardingProviderTracker = l3ForwardingProviderTracker;
409 public void stop(BundleContext context) throws Exception {
410 LOG.info("ConfigActivator stop");
411 /* ServiceTrackers and services are already released when bundle stops
412 iNeutronNetworkCRUDTracker.close();
413 iNeutronPortCRUDTracker.close();
414 iNeutronSubnetCRUDTracker.close();
415 iNeutronLoadBalancerCRUDTracker.close();
416 iNeutronLoadBalancerPoolCRUDTracker.close();
417 loadBalancerProviderTracker.close();
419 for (ServiceRegistration registration : registrations) {
420 if (registration != null) {
421 registration.unregister();
426 private ServiceRegistration<?> registerService(BundleContext bundleContext, String[] interfaces,
427 Dictionary<String, Object> properties, Object impl) {
428 ServiceRegistration<?> serviceRegistration = bundleContext.registerService(interfaces, impl, properties);
429 if (serviceRegistration != null) {
430 registrations.add(serviceRegistration);
432 return serviceRegistration;