Merge "Adding Karaf feature for openflow Nicira Extensions support"
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / 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;
12
13 import org.opendaylight.controller.networkconfig.neutron.INeutronFirewallAware;
14 import org.opendaylight.controller.networkconfig.neutron.INeutronFirewallPolicyAware;
15 import org.opendaylight.controller.networkconfig.neutron.INeutronFirewallRuleAware;
16 import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPAware;
17 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
18 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
19 import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
20 import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
21 import org.opendaylight.controller.networkconfig.neutron.INeutronRouterAware;
22 import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityGroupAware;
23 import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleAware;
24 import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware;
25 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
26 import org.opendaylight.controller.switchmanager.IInventoryListener;
27 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
28 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
29 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
30 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
31 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
32 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
33 import org.opendaylight.ovsdb.openstack.netvirt.api.VlanConfigurationCache;
34 import org.opendaylight.ovsdb.openstack.netvirt.impl.BridgeConfigurationManagerImpl;
35 import org.opendaylight.ovsdb.openstack.netvirt.impl.ConfigurationServiceImpl;
36 import org.opendaylight.ovsdb.openstack.netvirt.impl.EventDispatcherImpl;
37 import org.opendaylight.ovsdb.openstack.netvirt.impl.ProviderNetworkManagerImpl;
38 import org.opendaylight.ovsdb.openstack.netvirt.impl.TenantNetworkManagerImpl;
39 import org.opendaylight.ovsdb.openstack.netvirt.impl.VlanConfigurationCacheImpl;
40 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
41 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
42 import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener;
43
44 import org.apache.felix.dm.Component;
45
46 import java.util.Properties;
47
48 /**
49  * OSGi bundle activator for the OVSDB Neutron Interface.
50  */
51 public class Activator extends ComponentActivatorAbstractBase {
52     /**
53      * Function called when the activator starts just after some
54      * initializations are done by the
55      * ComponentActivatorAbstractBase.
56      */
57     @Override
58     public void init() {
59     }
60
61     /**
62      * Function called when the activator stops just before the
63      * cleanup done by ComponentActivatorAbstractBase.
64      *
65      */
66     @Override
67     public void destroy() {
68     }
69
70     /**
71      * Function that is used to communicate to dependency manager the
72      * list of known implementations for services inside a container.
73      *
74      * @return An array containing all the CLASS objects that will be
75      * instantiated in order to get an fully working implementation
76      * Object
77      */
78     @Override
79     public Object[] getImplementations() {
80         Object[] res = {ConfigurationServiceImpl.class,
81                         BridgeConfigurationManagerImpl.class,
82                         TenantNetworkManagerImpl.class,
83                         VlanConfigurationCacheImpl.class,
84                         FloatingIPHandler.class,
85                         NetworkHandler.class,
86                         SubnetHandler.class,
87                         PortHandler.class,
88                         RouterHandler.class,
89                         SouthboundHandler.class,
90                         PortSecurityHandler.class,
91                         ProviderNetworkManagerImpl.class,
92                         EventDispatcherImpl.class,
93                         FWaasHandler.class};
94         return res;
95     }
96
97     /**
98      * Function that is called when configuration of the dependencies
99      * is required.
100      *
101      * @param c dependency manager Component object, used for
102      * configuring the dependencies exported and imported
103      * @param imp Implementation class that is being configured,
104      * needed as long as the same routine can configure multiple
105      * implementations
106      * @param containerName The containerName being configured, this allow
107      * also optional per-container different behavior if needed, usually
108      * should not be the case though.
109      */
110     @Override
111     public void configureInstance(Component c, Object imp,
112                                   String containerName) {
113         if (imp.equals(ConfigurationServiceImpl.class)) {
114             c.setInterface(org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService.class.getName(), null);
115             c.add(createServiceDependency().setService(OvsdbConfigurationService.class));
116         }
117
118         if (imp.equals(BridgeConfigurationManagerImpl.class)) {
119             c.setInterface(BridgeConfigurationManager.class.getName(), null);
120             c.add(createServiceDependency().setService(
121                     org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService.class).setRequired(true));
122             c.add(createServiceDependency().setService(NetworkingProviderManager.class));
123             c.add(createServiceDependency().setService(OvsdbConfigurationService.class));
124         }
125
126         if (imp.equals(TenantNetworkManagerImpl.class)) {
127             c.setInterface(TenantNetworkManager.class.getName(), null);
128             c.add(createServiceDependency().setService(NetworkingProviderManager.class));
129             c.add(createServiceDependency().setService(OvsdbConfigurationService.class));
130             c.add(createServiceDependency().setService(OvsdbConnectionService.class));
131             c.add(createServiceDependency().
132                     setService(INeutronNetworkCRUD.class).
133                     setRequired(true));
134             c.add(createServiceDependency().
135                     setService(INeutronPortCRUD.class).
136                     setRequired(true));
137             c.add(createServiceDependency().setService(VlanConfigurationCache.class));
138         }
139
140         if (imp.equals(VlanConfigurationCacheImpl.class)) {
141             c.setInterface(VlanConfigurationCache.class.getName(), null);
142             c.add(createServiceDependency().setService(OvsdbConfigurationService.class));
143             c.add(createServiceDependency().setService(TenantNetworkManager.class));
144         }
145
146         if (imp.equals(FloatingIPHandler.class)) {
147             Properties floatingIPHandlerPorperties = new Properties();
148             floatingIPHandlerPorperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
149                                             AbstractEvent.HandlerType.NEUTRON_FLOATING_IP);
150             c.setInterface(new String[] {INeutronFloatingIPAware.class.getName(),
151                                          AbstractHandler.class.getName()},
152                            floatingIPHandlerPorperties);
153             c.add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true));
154             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
155             c.add(createServiceDependency().setService(OvsdbInventoryListener.class).setRequired(true));
156             c.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true));
157         }
158
159         if (imp.equals(NetworkHandler.class)) {
160             Properties networkHandlerProperties = new Properties();
161             networkHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
162                                          AbstractEvent.HandlerType.NEUTRON_NETWORK);
163             c.setInterface(new String[] {INeutronNetworkAware.class.getName(),
164                                          AbstractHandler.class.getName()},
165                            networkHandlerProperties);
166             c.add(createServiceDependency().setService(TenantNetworkManager.class).setRequired(true));
167             c.add(createServiceDependency().setService(BridgeConfigurationManager.class).setRequired(true));
168             c.add(createServiceDependency().setService(
169                     org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService.class).setRequired(true));
170             c.add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true));
171             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
172             c.add(createServiceDependency().setService(INeutronNetworkCRUD.class).setRequired(true));
173             c.add(createServiceDependency().setService(OvsdbInventoryListener.class).setRequired(true));
174             c.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true));
175         }
176
177         if (imp.equals(SubnetHandler.class)) {
178             Properties subnetHandlerProperties = new Properties();
179             subnetHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_SUBNET);
180             c.setInterface(new String[] {INeutronSubnetAware.class.getName(),
181                                          AbstractHandler.class.getName()},
182                            subnetHandlerProperties);
183             c.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true));
184         }
185
186         if (imp.equals(PortHandler.class)) {
187             Properties portHandlerProperties = new Properties();
188             portHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_PORT);
189             c.setInterface(new String[] {INeutronPortAware.class.getName(),
190                                          AbstractHandler.class.getName()},
191                            portHandlerProperties);
192             c.add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true));
193             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
194             c.add(createServiceDependency().setService(OvsdbInventoryListener.class).setRequired(true));
195             c.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true));
196         }
197
198         if (imp.equals(RouterHandler.class)) {
199             Properties routerHandlerProperties = new Properties();
200             routerHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_ROUTER);
201             c.setInterface(new String[] {INeutronRouterAware.class.getName(),
202                                          AbstractHandler.class.getName()},
203                            routerHandlerProperties);
204             c.add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true));
205             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
206             c.add(createServiceDependency().setService(OvsdbInventoryListener.class).setRequired(true));
207             c.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true));
208         }
209
210         if (imp.equals(SouthboundHandler.class)) {
211             Properties southboundHandlerProperties = new Properties();
212             southboundHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.SOUTHBOUND);
213             c.setInterface(new String[] {OvsdbInventoryListener.class.getName(),
214                                          IInventoryListener.class.getName(),
215                                          AbstractHandler.class.getName()},
216                            southboundHandlerProperties);
217             c.add(createServiceDependency().setService(
218                     org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService.class).setRequired(true));
219             c.add(createServiceDependency().setService(BridgeConfigurationManager.class).setRequired(true));
220             c.add(createServiceDependency().setService(TenantNetworkManager.class).setRequired(true));
221             c.add(createServiceDependency().setService(NetworkingProviderManager.class).setRequired(true));
222             c.add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true));
223             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
224             c.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true));
225         }
226
227         if (imp.equals(PortSecurityHandler.class)) {
228             Properties portSecurityHandlerProperties = new Properties();
229             portSecurityHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
230                                               AbstractEvent.HandlerType.NEUTRON_PORT_SECURITY);
231             c.setInterface(new String[] {INeutronSecurityRuleAware.class.getName(),
232                                          INeutronSecurityGroupAware.class.getName(),
233                                          AbstractHandler.class.getName()},
234                            portSecurityHandlerProperties);
235             c.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true));
236         }
237
238         if (imp.equals(FWaasHandler.class)) {
239             Properties fWaasHandlerProperties = new Properties();
240             fWaasHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_FWAAS);
241             c.setInterface(new String[] {INeutronFirewallAware.class.getName(),
242                             INeutronFirewallRuleAware.class.getName(),
243                             INeutronFirewallPolicyAware.class.getName(),
244                             AbstractHandler.class.getName()},
245                     fWaasHandlerProperties);
246             c.add(createServiceDependency().setService(EventDispatcher.class).setRequired(true));
247         }
248
249         if (imp.equals(ProviderNetworkManagerImpl.class)) {
250             c.setInterface(NetworkingProviderManager.class.getName(), null);
251             c.add(createServiceDependency()
252                     .setService(org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService.class)
253                     .setRequired(true));
254             c.add(createServiceDependency()
255                     .setService(NetworkingProvider.class)
256                     .setCallbacks("providerAdded", "providerRemoved"));
257         }
258
259         if (imp.equals(EventDispatcherImpl.class)) {
260             c.setInterface(EventDispatcher.class.getName(), null);
261             c.add(createServiceDependency()
262                           .setService(AbstractHandler.class)
263                           .setCallbacks("eventHandlerAdded", "eventHandlerRemoved"));
264         }
265     }
266 }