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;
35 private ServiceTracker gatewayMacResolverProviderTracker;
37 public ConfigActivator(ProviderContext providerContext) {
38 this.providerContext = providerContext;
42 public void start(BundleContext context) throws Exception {
43 LOG.info("ConfigActivator start:");
45 ConfigurationServiceImpl configurationService = new ConfigurationServiceImpl();
46 registerService(context, new String[] {ConfigurationService.class.getName()},
47 null, configurationService);
49 BridgeConfigurationManagerImpl bridgeConfigurationManager = new BridgeConfigurationManagerImpl();
50 registerService(context, new String[] {BridgeConfigurationManager.class.getName()},
51 null, bridgeConfigurationManager);
53 final TenantNetworkManagerImpl tenantNetworkManager = new TenantNetworkManagerImpl();
54 registerService(context, new String[] {TenantNetworkManager.class.getName()},
55 null, tenantNetworkManager);
57 VlanConfigurationCacheImpl vlanConfigurationCache = new VlanConfigurationCacheImpl();
58 registerService(context, new String[] {VlanConfigurationCache.class.getName()},
59 null, vlanConfigurationCache);
61 Dictionary<String, Object> floatingIPHandlerProperties = new Hashtable<>();
62 floatingIPHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
63 AbstractEvent.HandlerType.NEUTRON_FLOATING_IP);
64 FloatingIPHandler floatingIPHandler = new FloatingIPHandler();
65 registerService(context,
66 new String[] {INeutronFloatingIPAware.class.getName(), AbstractHandler.class.getName()},
67 floatingIPHandlerProperties, floatingIPHandler);
69 Dictionary<String, Object> networkHandlerProperties = new Hashtable<>();
70 networkHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_NETWORK);
71 final NetworkHandler networkHandler = new NetworkHandler();
72 registerService(context,
73 new String[]{INeutronNetworkAware.class.getName(), AbstractHandler.class.getName()},
74 networkHandlerProperties, networkHandler);
76 Dictionary<String, Object> subnetHandlerProperties = new Hashtable<>();
77 subnetHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_SUBNET);
78 SubnetHandler subnetHandler = new SubnetHandler();
79 registerService(context,
80 new String[] {INeutronSubnetAware.class.getName(), AbstractHandler.class.getName()},
81 subnetHandlerProperties, subnetHandler);
83 Dictionary<String, Object> portHandlerProperties = new Hashtable<>();
84 portHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_PORT);
85 PortHandler portHandler = new PortHandler();
86 registerService(context,
87 new String[]{INeutronPortAware.class.getName(), AbstractHandler.class.getName()},
88 portHandlerProperties, portHandler);
90 Dictionary<String, Object> routerHandlerProperties = new Hashtable<>();
91 routerHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_ROUTER);
92 RouterHandler routerHandler = new RouterHandler();
93 registerService(context,
94 new String[]{INeutronRouterAware.class.getName(), AbstractHandler.class.getName()},
95 routerHandlerProperties, routerHandler);
97 Dictionary<String, Object> southboundHandlerProperties = new Hashtable<>();
98 southboundHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.SOUTHBOUND);
99 SouthboundHandler southboundHandler = new SouthboundHandler();
100 registerService(context,
101 new String[]{OvsdbInventoryListener.class.getName(),
102 NodeCacheListener.class.getName(),
103 AbstractHandler.class.getName()},
104 southboundHandlerProperties, southboundHandler);
106 Dictionary<String, Object> lbaasHandlerProperties = new Hashtable<>();
107 lbaasHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
108 AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER);
109 final LBaaSHandler lBaaSHandler = new LBaaSHandler();
110 registerService(context,
111 new String[]{INeutronLoadBalancerAware.class.getName(),
112 NodeCacheListener.class.getName(), AbstractHandler.class.getName()},
113 lbaasHandlerProperties, lBaaSHandler);
115 Dictionary<String, Object> lbaasPoolHandlerProperties = new Hashtable<>();
116 lbaasPoolHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
117 AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL);
118 final LBaaSPoolHandler lBaaSPoolHandler = new LBaaSPoolHandler();
119 registerService(context,
120 new String[]{INeutronLoadBalancerPoolAware.class.getName(),
121 AbstractHandler.class.getName()}, lbaasPoolHandlerProperties, lBaaSPoolHandler);
123 Dictionary<String, Object> lbaasPoolMemberHandlerProperties = new Hashtable<>();
124 lbaasPoolMemberHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
125 AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL_MEMBER);
126 final LBaaSPoolMemberHandler lBaaSPoolMemberHandler = new LBaaSPoolMemberHandler();
127 registerService(context,
128 new String[]{INeutronLoadBalancerPoolMemberAware.class.getName(),
129 AbstractHandler.class.getName()}, lbaasPoolMemberHandlerProperties, lBaaSPoolMemberHandler);
131 Dictionary<String, Object> portSecurityHandlerProperties = new Hashtable<>();
132 portSecurityHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
133 AbstractEvent.HandlerType.NEUTRON_PORT_SECURITY);
134 PortSecurityHandler portSecurityHandler = new PortSecurityHandler();
135 registerService(context,
136 new String[]{INeutronSecurityRuleAware.class.getName(),
137 INeutronSecurityGroupAware.class.getName(), AbstractHandler.class.getName()},
138 portSecurityHandlerProperties, portSecurityHandler);
140 final SecurityServicesImpl securityServices = new SecurityServicesImpl();
141 registerService(context,
142 new String[]{SecurityServicesManager.class.getName()}, null, securityServices);
144 Dictionary<String, Object> fWaasHandlerProperties = new Hashtable<>();
145 fWaasHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_FWAAS);
146 FWaasHandler fWaasHandler = new FWaasHandler();
147 registerService(context,
148 new String[]{INeutronFirewallAware.class.getName(),
149 INeutronFirewallRuleAware.class.getName(), INeutronFirewallPolicyAware.class.getName(),
150 AbstractHandler.class.getName()}, fWaasHandlerProperties, fWaasHandler);
152 ProviderNetworkManagerImpl providerNetworkManager = new ProviderNetworkManagerImpl();
153 registerService(context,
154 new String[]{NetworkingProviderManager.class.getName()}, null, providerNetworkManager);
156 EventDispatcherImpl eventDispatcher = new EventDispatcherImpl();
157 registerService(context,
158 new String[]{EventDispatcher.class.getName()}, null, eventDispatcher);
160 final NeutronL3Adapter neutronL3Adapter = new NeutronL3Adapter();
161 registerService(context,
162 new String[]{NeutronL3Adapter.class.getName()}, null, neutronL3Adapter);
164 OpenstackRouter openstackRouter = new OpenstackRouter();
165 registerService(context,
166 new String[]{MultiTenantAwareRouter.class.getName()}, null, openstackRouter);
168 Southbound southbound = new SouthboundImpl(providerContext.getSALService(DataBroker.class));
169 registerService(context,
170 new String[]{Southbound.class.getName()}, null, southbound);
172 Dictionary<String, Object> nodeCacheManagerProperties = new Hashtable<>();
173 nodeCacheManagerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NODE);
174 NodeCacheManagerImpl nodeCacheManager = new NodeCacheManagerImpl();
175 registerService(context,
176 new String[]{NodeCacheManager.class.getName(), AbstractHandler.class.getName()},
177 nodeCacheManagerProperties, nodeCacheManager);
179 OvsdbInventoryServiceImpl ovsdbInventoryService = new OvsdbInventoryServiceImpl(providerContext);
180 registerService(context,
181 new String[] {OvsdbInventoryService.class.getName()}, null, ovsdbInventoryService);
183 ovsdbInventoryService.setDependencies(context, null);
184 nodeCacheManager.setDependencies(context, null);
185 openstackRouter.setDependencies(context, null);
186 neutronL3Adapter.setDependencies(context, null);
187 eventDispatcher.setDependencies(context, null);
188 providerNetworkManager.setDependencies(context, null);
189 fWaasHandler.setDependencies(context, null);
190 securityServices.setDependencies(context, null);
191 portSecurityHandler.setDependencies(context, null);
192 lBaaSPoolMemberHandler.setDependencies(context, null);
193 lBaaSPoolHandler.setDependencies(context, null);
194 lBaaSHandler.setDependencies(context, null);
195 southboundHandler.setDependencies(context, null);
196 routerHandler.setDependencies(context, null);
197 portHandler.setDependencies(context, null);
198 subnetHandler.setDependencies(context, null);
199 networkHandler.setDependencies(context, null);
200 floatingIPHandler.setDependencies(context, null);
201 vlanConfigurationCache.setDependencies(context, null);
202 tenantNetworkManager.setDependencies(context, null);
203 bridgeConfigurationManager.setDependencies(context, null);
204 configurationService.setDependencies(context, null);
206 // TODO check if services are already available and setDependencies
207 // addingService may not be called if the service is already available when the ServiceTracker
209 @SuppressWarnings("unchecked")
210 ServiceTracker iNeutronNetworkCRUDTracker = new ServiceTracker(context, INeutronNetworkCRUD.class, null) {
212 public Object addingService(ServiceReference reference) {
213 LOG.info("addingService INeutronNetworkCRUD");
214 INeutronNetworkCRUD service = (INeutronNetworkCRUD)context.getService(reference);
215 if (service != null) {
216 tenantNetworkManager.setDependencies(service);
217 networkHandler.setDependencies(service);
218 lBaaSHandler.setDependencies(service);
219 lBaaSPoolHandler.setDependencies(service);
220 lBaaSPoolMemberHandler.setDependencies(service);
221 neutronL3Adapter.setDependencies(service);
226 iNeutronNetworkCRUDTracker.open();
227 this.iNeutronNetworkCRUDTracker = iNeutronNetworkCRUDTracker;
229 @SuppressWarnings("unchecked")
230 ServiceTracker iNeutronSubnetCRUDTracker = new ServiceTracker(context, INeutronSubnetCRUD.class, null) {
232 public Object addingService(ServiceReference reference) {
233 LOG.info("addingService INeutronSubnetCRUD");
234 INeutronSubnetCRUD service = (INeutronSubnetCRUD) context.getService(reference);
235 if (service != null) {
236 lBaaSHandler.setDependencies(service);
237 lBaaSPoolHandler.setDependencies(service);
238 lBaaSPoolMemberHandler.setDependencies(service);
239 securityServices.setDependencies(service);
240 neutronL3Adapter.setDependencies(service);
245 iNeutronSubnetCRUDTracker.open();
246 this.iNeutronSubnetCRUDTracker = iNeutronSubnetCRUDTracker;
248 @SuppressWarnings("unchecked")
249 ServiceTracker iNeutronPortCRUDTracker = new ServiceTracker(context, INeutronPortCRUD.class, null) {
251 public Object addingService(ServiceReference reference) {
252 LOG.info("addingService INeutronPortCRUD");
253 INeutronPortCRUD service = (INeutronPortCRUD) context.getService(reference);
254 if (service != null) {
255 tenantNetworkManager.setDependencies(service);
256 lBaaSHandler.setDependencies(service);
257 lBaaSPoolHandler.setDependencies(service);
258 lBaaSPoolMemberHandler.setDependencies(service);
259 securityServices.setDependencies(service);
260 neutronL3Adapter.setDependencies(service);
265 iNeutronPortCRUDTracker.open();
266 this.iNeutronPortCRUDTracker = iNeutronPortCRUDTracker;
268 @SuppressWarnings("unchecked")
269 ServiceTracker iNeutronLoadBalancerCRUDTracker = new ServiceTracker(context,
270 INeutronLoadBalancerCRUD.class, null) {
272 public Object addingService(ServiceReference reference) {
273 LOG.info("addingService INeutronLoadBalancerCRUD");
274 INeutronLoadBalancerCRUD service = (INeutronLoadBalancerCRUD) context.getService(reference);
275 if (service != null) {
276 lBaaSHandler.setDependencies(service);
277 lBaaSPoolHandler.setDependencies(service);
278 lBaaSPoolMemberHandler.setDependencies(service);
283 iNeutronLoadBalancerCRUDTracker.open();
284 this.iNeutronLoadBalancerCRUDTracker = iNeutronLoadBalancerCRUDTracker;
286 @SuppressWarnings("unchecked")
287 ServiceTracker iNeutronLoadBalancerPoolCRUDTracker = new ServiceTracker(context,
288 INeutronLoadBalancerPoolCRUD.class, null) {
290 public Object addingService(ServiceReference reference) {
291 LOG.info("addingService INeutronLoadBalancerPoolCRUD");
292 INeutronLoadBalancerPoolCRUD service =
293 (INeutronLoadBalancerPoolCRUD) context.getService(reference);
294 if (service != null) {
295 lBaaSHandler.setDependencies(service);
296 lBaaSPoolMemberHandler.setDependencies(service);
301 iNeutronLoadBalancerPoolCRUDTracker.open();
302 this.iNeutronLoadBalancerPoolCRUDTracker = iNeutronLoadBalancerPoolCRUDTracker;
304 @SuppressWarnings("unchecked")
305 ServiceTracker ioadBalancerProviderTracker = new ServiceTracker(context,
306 LoadBalancerProvider.class, null) {
308 public Object addingService(ServiceReference reference) {
309 LOG.info("addingService LoadBalancerProvider");
310 LoadBalancerProvider service =
311 (LoadBalancerProvider) context.getService(reference);
312 if (service != null) {
313 lBaaSHandler.setDependencies(service);
314 lBaaSPoolHandler.setDependencies(service);
315 lBaaSPoolMemberHandler.setDependencies(service);
320 ioadBalancerProviderTracker.open();
321 this.loadBalancerProviderTracker = ioadBalancerProviderTracker;
323 @SuppressWarnings("unchecked")
324 ServiceTracker arpProviderTracker = new ServiceTracker(context,
325 ArpProvider.class, null) {
327 public Object addingService(ServiceReference reference) {
328 LOG.info("addingService ArpProvider");
329 ArpProvider service =
330 (ArpProvider) context.getService(reference);
331 if (service != null) {
332 neutronL3Adapter.setDependencies(service);
337 arpProviderTracker.open();
338 this.arpProviderTracker = arpProviderTracker;
340 @SuppressWarnings("unchecked")
341 ServiceTracker inboundNatProviderTracker = new ServiceTracker(context,
342 InboundNatProvider.class, null) {
344 public Object addingService(ServiceReference reference) {
345 LOG.info("addingService InboundNatProvider");
346 InboundNatProvider service =
347 (InboundNatProvider) context.getService(reference);
348 if (service != null) {
349 neutronL3Adapter.setDependencies(service);
354 inboundNatProviderTracker.open();
355 this.inboundNatProviderTracker = inboundNatProviderTracker;
357 @SuppressWarnings("unchecked")
358 ServiceTracker outboundNatProviderTracker = new ServiceTracker(context,
359 OutboundNatProvider.class, null) {
361 public Object addingService(ServiceReference reference) {
362 LOG.info("addingService OutboundNatProvider");
363 OutboundNatProvider service =
364 (OutboundNatProvider) context.getService(reference);
365 if (service != null) {
366 neutronL3Adapter.setDependencies(service);
371 outboundNatProviderTracker.open();
372 this.outboundNatProviderTracker = outboundNatProviderTracker;
374 @SuppressWarnings("unchecked")
375 ServiceTracker routingProviderTracker = new ServiceTracker(context,
376 RoutingProvider.class, null) {
378 public Object addingService(ServiceReference reference) {
379 LOG.info("addingService RoutingProvider");
380 RoutingProvider service =
381 (RoutingProvider) context.getService(reference);
382 if (service != null) {
383 neutronL3Adapter.setDependencies(service);
388 routingProviderTracker.open();
389 this.routingProviderTracker = routingProviderTracker;
391 @SuppressWarnings("unchecked")
392 ServiceTracker l3ForwardingProviderTracker = new ServiceTracker(context,
393 L3ForwardingProvider.class, null) {
395 public Object addingService(ServiceReference reference) {
396 LOG.info("addingService L3ForwardingProvider");
397 L3ForwardingProvider service =
398 (L3ForwardingProvider) context.getService(reference);
399 if (service != null) {
400 neutronL3Adapter.setDependencies(service);
405 l3ForwardingProviderTracker.open();
406 this.l3ForwardingProviderTracker = l3ForwardingProviderTracker;
408 @SuppressWarnings("unchecked")
409 ServiceTracker gatewayMacResolverProviderTracker = new ServiceTracker(context,
410 GatewayMacResolver.class, null) {
412 public Object addingService(ServiceReference reference) {
413 LOG.info("addingService GatwayMacResolverProvider");
414 GatewayMacResolver service =
415 (GatewayMacResolver) context.getService(reference);
416 if (service != null) {
417 neutronL3Adapter.setDependencies(service);
422 gatewayMacResolverProviderTracker.open();
423 this.gatewayMacResolverProviderTracker = gatewayMacResolverProviderTracker;
428 public void stop(BundleContext context) throws Exception {
429 LOG.info("ConfigActivator stop");
430 /* ServiceTrackers and services are already released when bundle stops
431 iNeutronNetworkCRUDTracker.close();
432 iNeutronPortCRUDTracker.close();
433 iNeutronSubnetCRUDTracker.close();
434 iNeutronLoadBalancerCRUDTracker.close();
435 iNeutronLoadBalancerPoolCRUDTracker.close();
436 loadBalancerProviderTracker.close();
438 for (ServiceRegistration registration : registrations) {
439 if (registration != null) {
440 registration.unregister();
445 private ServiceRegistration<?> registerService(BundleContext bundleContext, String[] interfaces,
446 Dictionary<String, Object> properties, Object impl) {
447 ServiceRegistration<?> serviceRegistration = bundleContext.registerService(interfaces, impl, properties);
448 if (serviceRegistration != null) {
449 registrations.add(serviceRegistration);
451 return serviceRegistration;