1 package org.opendaylight.ovsdb.openstack.netvirt.providers;
3 import java.util.ArrayList;
4 import java.util.Dictionary;
5 import java.util.Hashtable;
7 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
8 import org.opendaylight.ovsdb.openstack.netvirt.api.*;
9 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
10 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.OF13Provider;
11 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
12 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestratorImpl;
13 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
14 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.*;
15 import org.osgi.framework.BundleActivator;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.ServiceReference;
18 import org.osgi.framework.ServiceRegistration;
19 import org.osgi.util.tracker.ServiceTracker;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class ConfigActivator implements BundleActivator {
24 private static final Logger LOG = LoggerFactory.getLogger(ConfigActivator.class);
25 private List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
26 private ProviderContext providerContext;
27 private ServiceTracker NetworkingProviderManagerTracker;
29 public ConfigActivator(ProviderContext providerContext) {
30 this.providerContext = providerContext;
34 public void start(BundleContext context) throws Exception {
35 LOG.info("ConfigActivator start:");
37 PipelineOrchestratorImpl pipelineOrchestrator = new PipelineOrchestratorImpl();
38 registerService(context,
39 new String[] {PipelineOrchestrator.class.getName(),NodeCacheListener.class.getName()},
40 null, pipelineOrchestrator);
42 Dictionary<String, Object> of13ProviderProperties = new Hashtable<>();
43 of13ProviderProperties.put(Constants.SOUTHBOUND_PROTOCOL_PROPERTY, "ovsdb");
44 of13ProviderProperties.put(Constants.OPENFLOW_VERSION_PROPERTY, Constants.OPENFLOW13);
45 final OF13Provider of13Provider = new OF13Provider();
46 registerService(context,
47 new String[] {NetworkingProvider.class.getName()},
48 of13ProviderProperties, of13Provider);
50 ClassifierService classifierService = new ClassifierService();
51 registerService(context, ClassifierProvider.class.getName(),
52 classifierService, Service.CLASSIFIER);
54 ArpResponderService arpResponderService = new ArpResponderService();
55 registerService(context, ArpProvider.class.getName(),
56 arpResponderService, Service.ARP_RESPONDER);
58 InboundNatService inboundNatService = new InboundNatService();
59 registerService(context, InboundNatProvider.class.getName(),
60 inboundNatService, Service.INBOUND_NAT);
62 IngressAclService ingressAclService = new IngressAclService();
63 registerService(context, IngressAclProvider.class.getName(),
64 ingressAclService, Service.INGRESS_ACL);
66 LoadBalancerService loadBalancerService = new LoadBalancerService();
67 registerService(context, LoadBalancerProvider.class.getName(),
68 loadBalancerService, Service.LOAD_BALANCER);
70 RoutingService routingService = new RoutingService();
71 registerService(context, RoutingProvider.class.getName(),
72 routingService, Service.ROUTING);
74 L3ForwardingService l3ForwardingService = new L3ForwardingService();
75 registerService(context, L3ForwardingProvider.class.getName(),
76 l3ForwardingService, Service.L3_FORWARDING);
78 L2RewriteService l2RewriteService = new L2RewriteService();
79 registerService(context, L2RewriteProvider.class.getName(),
80 l2RewriteService, Service.L2_REWRITE);
82 L2ForwardingService l2ForwardingService = new L2ForwardingService();
83 registerService(context, L2ForwardingProvider.class.getName(),
84 l2ForwardingService, Service.L2_FORWARDING);
86 EgressAclService egressAclService = new EgressAclService();
87 registerService(context, EgressAclProvider.class.getName(),
88 egressAclService, Service.EGRESS_ACL);
90 OutboundNatService outboundNatService = new OutboundNatService();
91 registerService(context, OutboundNatProvider.class.getName(),
92 outboundNatService, Service.OUTBOUND_NAT);
94 pipelineOrchestrator.setDependencies(context, null);
95 outboundNatService.setDependencies(context, null);
96 egressAclService.setDependencies(context, null);
97 l2ForwardingService.setDependencies(context, null);
98 l2RewriteService.setDependencies(context, null);
99 l3ForwardingService.setDependencies(context, null);
100 routingService.setDependencies(context, null);
101 loadBalancerService.setDependencies(context, null);
102 ingressAclService.setDependencies(context, null);
103 inboundNatService.setDependencies(context, null);
104 arpResponderService.setDependencies(context, null);
105 classifierService.setDependencies(context, null);
106 of13Provider.setDependencies(context, null);
108 @SuppressWarnings("unchecked")
109 ServiceTracker NetworkingProviderManagerTracker = new ServiceTracker(context,
110 NetworkingProviderManager.class, null) {
112 public Object addingService(ServiceReference reference) {
113 LOG.info("addingService NetworkingProviderManager");
114 NetworkingProviderManager service =
115 (NetworkingProviderManager) context.getService(reference);
116 if (service != null) {
117 of13Provider.setDependencies(service);
122 NetworkingProviderManagerTracker.open();
123 this.NetworkingProviderManagerTracker = NetworkingProviderManagerTracker;
127 public void stop(BundleContext context) throws Exception {
128 LOG.info("ConfigActivator stop");
129 //NetworkingProviderManagerTracker.close();
130 for (ServiceRegistration registration : registrations) {
131 if (registration != null) {
132 registration.unregister();
137 private ServiceRegistration<?> registerService(BundleContext bundleContext, String[] interfaces,
138 Dictionary<String, Object> properties, Object impl) {
139 ServiceRegistration<?> serviceRegistration = bundleContext.registerService(interfaces, impl, properties);
140 if (serviceRegistration != null) {
141 registrations.add(serviceRegistration);
143 return serviceRegistration;
146 private ServiceRegistration<?> registerService(BundleContext bundleContext, String interfaceClassName,
147 Object impl, Object serviceProperty) {
148 Dictionary<String, Object> properties = new Hashtable<>();
149 properties.put(AbstractServiceInstance.SERVICE_PROPERTY, serviceProperty);
150 properties.put(Constants.PROVIDER_NAME_PROPERTY, OF13Provider.NAME);
151 return registerService(bundleContext,
152 new String[] {AbstractServiceInstance.class.getName(), interfaceClassName},