Adding Passive connection support to plugin layer.
[netvirt.git] / plugin / src / main / java / org / opendaylight / ovsdb / plugin / 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
9  */
10 package org.opendaylight.ovsdb.plugin;
11
12 import java.util.Dictionary;
13 import java.util.Hashtable;
14
15 import org.apache.felix.dm.Component;
16 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
17 import org.opendaylight.controller.sal.connection.IPluginInConnectionService;
18 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.core.NodeConnector;
21 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
22 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
23 import org.opendaylight.controller.sal.networkconfig.bridgedomain.IPluginInBridgeDomainConfigService;
24 import org.opendaylight.controller.sal.utils.GlobalConstants;
25 import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
26 import org.opendaylight.controller.sal.utils.INodeFactory;
27 import org.opendaylight.ovsdb.lib.OvsdbConnection;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * OVSDB protocol plugin Activator
33  *
34  *
35  */
36 public class Activator extends ComponentActivatorAbstractBase {
37     protected static final Logger logger = LoggerFactory
38             .getLogger(Activator.class);
39
40     /**
41      * Function called when the activator starts just after some initializations
42      * are done by the ComponentActivatorAbstractBase.
43      * Here it registers the node Type
44      *
45      */
46     @Override
47     public void init() {
48         Node.NodeIDType.registerIDType("OVS", String.class);
49         NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
50     }
51
52     /**
53      * Function called when the activator stops just before the cleanup done by
54      * ComponentActivatorAbstractBase
55      *
56      */
57     @Override
58     public void destroy() {
59         Node.NodeIDType.unRegisterIDType("OVS");
60         NodeConnector.NodeConnectorIDType.unRegisterIDType("OVS");
61     }
62     @Override
63     public Object[] getGlobalImplementations() {
64         Object[] res = { ConnectionService.class, ConfigurationService.class, NodeFactory.class, NodeConnectorFactory.class, InventoryService.class };
65         return res;
66     }
67
68     @Override
69     public void configureGlobalInstance(Component c, Object imp){
70         if (imp.equals(ConfigurationService.class)) {
71             // export the service to be used by SAL
72             Dictionary<String, Object> props = new Hashtable<String, Object>();
73             // Set the protocolPluginType property which will be used
74             // by SAL
75             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
76             c.setInterface(new String[] { IPluginInBridgeDomainConfigService.class.getName(),
77                                           OVSDBConfigService.class.getName()}, props);
78
79             c.add(createServiceDependency()
80                     .setService(IConnectionServiceInternal.class)
81                     .setCallbacks("setConnectionServiceInternal", "unsetConnectionServiceInternal")
82                     .setRequired(true));
83             c.add(createServiceDependency()
84                     .setService(InventoryServiceInternal.class)
85                     .setCallbacks("setInventoryServiceInternal", "unsetInventoryServiceInternal")
86                     .setRequired(true));
87         }
88
89         if (imp.equals(ConnectionService.class)) {
90             // export the service to be used by SAL
91             Dictionary<String, Object> props = new Hashtable<String, Object>();
92             // Set the protocolPluginType property which will be used
93             // by SAL
94             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
95             c.setInterface(
96                     new String[] {IPluginInConnectionService.class.getName(),
97                                   IConnectionServiceInternal.class.getName()}, props);
98
99             c.add(createServiceDependency()
100                     .setService(InventoryServiceInternal.class)
101                     .setCallbacks("setInventoryServiceInternal", "unsetInventoryServiceInternal")
102                     .setRequired(true));
103             c.add(createServiceDependency()
104                     .setService(IClusterGlobalServices.class)
105                     .setCallbacks("setClusterServices", "unsetClusterServices")
106                     .setRequired(false));
107             c.add(createServiceDependency()
108                     .setService(OvsdbConnection.class)
109                     .setCallbacks("setOvsdbConnection", "unsetOvsdbConnection")
110                     .setRequired(true));
111         }
112
113         if (imp.equals(InventoryService.class)) {
114             Dictionary<String, Object> props = new Hashtable<String, Object>();
115             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
116             c.setInterface(
117                     new String[] {IPluginInInventoryService.class.getName(),
118                             InventoryServiceInternal.class.getName()}, props);
119             c.add(createServiceDependency()
120                     .setService(IPluginOutInventoryService.class, "(scope=Global)")
121                     .setCallbacks("setPluginOutInventoryServices",
122                             "unsetPluginOutInventoryServices")
123                     .setRequired(true));
124         }
125
126         if (imp.equals(NodeFactory.class)) {
127             // export the service to be used by SAL
128             Dictionary<String, Object> props = new Hashtable<String, Object>();
129             // Set the protocolPluginType property which will be used
130             // by SAL
131             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
132             props.put("protocolName", "OVS");
133             c.setInterface(INodeFactory.class.getName(), props);
134         }
135         if (imp.equals(NodeConnectorFactory.class)) {
136             // export the service to be used by SAL
137             Dictionary<String, Object> props = new Hashtable<String, Object>();
138             // Set the protocolPluginType property which will be used
139             // by SAL
140             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
141             props.put("protocolName", "OVS");
142             c.setInterface(INodeConnectorFactory.class.getName(), props);
143         }
144
145     }
146 }