Added Template classes for all the static services.
[ovsdb.git] / openstack / net-virt-providers / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / providers / Activator.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
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  * Authors : Madhu Venugopal, Brent Salisbury, Dave Tucker
9  */
10
11 package org.opendaylight.ovsdb.openstack.netvirt.providers;
12
13 import java.util.Properties;
14
15 import org.apache.felix.dm.Component;
16 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
18 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
19 import org.opendaylight.controller.switchmanager.ISwitchManager;
20 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
21 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
22 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
23 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
24 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow10.OF10Provider;
25 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
26 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.MdsalConsumer;
27 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.MdsalConsumerImpl;
28 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.OF13Provider;
29 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
30 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestratorImpl;
31 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
32 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.ArpResponderService;
33 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.ClassifierService;
34 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.EgressAclService;
35 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.InboundNatService;
36 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.IngressAclService;
37 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.L2ForwardingService;
38 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.L2RewriteService;
39 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.LoadBalancerService;
40 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.OutboundNatService;
41 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services.RoutingService;
42 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
43 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
44
45 /**
46  * OSGi Bundle Activator for the Neutron providers
47  */
48 public class Activator extends ComponentActivatorAbstractBase {
49     /**
50      * Function called when the activator starts just after some
51      * initializations are done by the
52      * ComponentActivatorAbstractBase.
53      */
54     @Override
55     public void init() {
56     }
57
58     /**
59      * Function called when the activator stops just before the
60      * cleanup done by ComponentActivatorAbstractBase.
61      *
62      */
63     @Override
64     public void destroy() {
65     }
66
67     /**
68      * Function that is used to communicate to dependency manager the
69      * list of known implementations for services inside a container.
70      *
71      * @return An array containing all the CLASS objects that will be
72      * instantiated in order to get an fully working implementation
73      * Object
74      */
75     @Override
76     public Object[] getImplementations() {
77         Object[] res = {MdsalConsumerImpl.class,
78                         OF10Provider.class,
79                         OF13Provider.class,
80                         PipelineOrchestratorImpl.class,
81                         ClassifierService.class,
82                         ArpResponderService.class,
83                         InboundNatService.class,
84                         IngressAclService.class,
85                         LoadBalancerService.class,
86                         RoutingService.class,
87                         L2RewriteService.class,
88                         L2ForwardingService.class,
89                         EgressAclService.class,
90                         OutboundNatService.class};
91         return res;
92     }
93
94     /**
95      * Function that is called when configuration of the dependencies
96      * is required.
97      *
98      * @param c dependency manager Component object, used for
99      * configuring the dependencies exported and imported
100      * @param imp Implementation class that is being configured,
101      * needed as long as the same routine can configure multiple
102      * implementations
103      * @param containerName The containerName being configured, this allow
104      * also optional per-container different behavior if needed, usually
105      * should not be the case though.
106      */
107     @Override
108     public void configureInstance(Component c, Object imp,
109                                   String containerName) {
110
111         if (imp.equals(MdsalConsumerImpl.class)) {
112             c.setInterface(MdsalConsumer.class.getName(), null);
113             c.add(createServiceDependency().setService(BindingAwareBroker.class).setRequired(true));
114         }
115
116         if (imp.equals(OF10Provider.class)) {
117             Properties of10Properties = new Properties();
118             of10Properties.put(Constants.SOUTHBOUND_PROTOCOL_PROPERTY, "ovsdb");
119             of10Properties.put(Constants.OPENFLOW_VERSION_PROPERTY, Constants.OPENFLOW10);
120
121             c.setInterface(NetworkingProvider.class.getName(), of10Properties);
122             c.add(createServiceDependency()
123                           .setService(org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService.class)
124                           .setRequired(true));
125             c.add(createServiceDependency()
126                           .setService(BridgeConfigurationManager.class)
127                           .setRequired(true));
128             c.add(createServiceDependency()
129                           .setService(TenantNetworkManager.class)
130                           .setRequired(true));
131             c.add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true));
132             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
133             c.add(createServiceDependency().
134                     setService(IForwardingRulesManager.class).
135                     setRequired(true));
136             c.add(createServiceDependency().
137                     setService(ISwitchManager.class).
138                     setRequired(true));
139         }
140
141         if (imp.equals(OF13Provider.class)) {
142             Properties of13Properties = new Properties();
143             of13Properties.put(Constants.SOUTHBOUND_PROTOCOL_PROPERTY, "ovsdb");
144             of13Properties.put(Constants.OPENFLOW_VERSION_PROPERTY, Constants.OPENFLOW13);
145
146             c.setInterface(NetworkingProvider.class.getName(), of13Properties);
147             c.add(createServiceDependency()
148                           .setService(org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService.class)
149                           .setRequired(true));
150             c.add(createServiceDependency()
151                           .setService(BridgeConfigurationManager.class)
152                           .setRequired(true));
153             c.add(createServiceDependency()
154                           .setService(TenantNetworkManager.class)
155                           .setRequired(true));
156             c.add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true));
157             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
158             c.add(createServiceDependency().setService(MdsalConsumer.class).setRequired(true));
159         }
160
161         if (imp.equals(PipelineOrchestratorImpl.class)) {
162             c.setInterface(PipelineOrchestrator.class.getName(), null);
163             c.add(createServiceDependency()
164                            .setService(AbstractServiceInstance.class)
165                            .setCallbacks("registerService", "unregisterService"));
166         }
167
168         if (AbstractServiceInstance.class.isAssignableFrom((Class)imp)) {
169             c.add(createServiceDependency()
170                     .setService(PipelineOrchestrator.class)
171                     .setRequired(true));
172             c.add(createServiceDependency().setService(MdsalConsumer.class).setRequired(true));
173         }
174
175         if (imp.equals(ClassifierService.class)) {
176             Properties properties = new Properties();
177             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.CLASSIFIER);
178             c.setInterface(AbstractServiceInstance.class.getName(), properties);
179         }
180
181         if (imp.equals(ArpResponderService.class)) {
182             Properties properties = new Properties();
183             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.ARP_RESPONDER);
184             c.setInterface(AbstractServiceInstance.class.getName(), properties);
185         }
186
187         if (imp.equals(InboundNatService.class)) {
188             Properties properties = new Properties();
189             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.INBOUND_NAT);
190             c.setInterface(AbstractServiceInstance.class.getName(), properties);
191         }
192
193         if (imp.equals(IngressAclService.class)) {
194             Properties properties = new Properties();
195             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.INGRESS_ACL);
196             c.setInterface(AbstractServiceInstance.class.getName(), properties);
197         }
198
199         if (imp.equals(LoadBalancerService.class)) {
200             Properties properties = new Properties();
201             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.LOAD_BALANCER);
202             c.setInterface(AbstractServiceInstance.class.getName(), properties);
203         }
204
205         if (imp.equals(RoutingService.class)) {
206             Properties properties = new Properties();
207             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.ROUTING);
208             c.setInterface(AbstractServiceInstance.class.getName(), properties);
209         }
210
211         if (imp.equals(L2RewriteService.class)) {
212             Properties properties = new Properties();
213             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.L2_REWRITE);
214             c.setInterface(AbstractServiceInstance.class.getName(), properties);
215         }
216
217         if (imp.equals(L2ForwardingService.class)) {
218             Properties properties = new Properties();
219             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.L2_FORWARDING);
220             c.setInterface(AbstractServiceInstance.class.getName(), properties);
221         }
222
223         if (imp.equals(IngressAclService.class)) {
224             Properties properties = new Properties();
225             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.INGRESS_ACL);
226             c.setInterface(AbstractServiceInstance.class.getName(), properties);
227         }
228
229         if (imp.equals(OutboundNatService.class)) {
230             Properties properties = new Properties();
231             properties.put(AbstractServiceInstance.SERVICE_PROPERTY, Service.OUTBOUND_NAT);
232             c.setInterface(AbstractServiceInstance.class.getName(), properties);
233         }
234     }
235 }