2cfa61a3183f3b512c0873eea8a6a736c08418ce
[affinity.git] / nfchainagent / src / main / java / org / opendaylight / affinity / nfchainagent / Activator.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 /* Network function chaining service. */
11 package org.opendaylight.affinity.nfchainagent;
12
13 import java.util.Hashtable;
14 import java.util.Dictionary;
15 import org.apache.felix.dm.Component;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
20 import org.opendaylight.controller.sal.packet.IListenDataPacket;
21 import org.opendaylight.controller.sal.packet.IDataPacketService;
22 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
23 import org.opendaylight.controller.switchmanager.ISwitchManager;
24
25 import org.opendaylight.affinity.l2agent.IfL2Agent;
26 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
27 //import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
28
29 public class Activator extends ComponentActivatorAbstractBase {
30     protected static final Logger logger = LoggerFactory
31             .getLogger(Activator.class);
32
33     /**
34      * Function called when the activator starts just after some
35      * initializations are done by the
36      * ComponentActivatorAbstractBase.
37      *
38      */
39     public void init() {
40
41     }
42
43     /**
44      * Function called when the activator stops just before the
45      * cleanup done by ComponentActivatorAbstractBase
46      *
47      */
48     public void destroy() {
49
50     }
51
52     /**
53      * Function that is used to communicate to dependency manager the
54      * list of known implementations for services inside a container
55      *
56      *
57      * @return An array containing all the CLASS objects that will be
58      * instantiated in order to get an fully working implementation
59      * Object
60      */
61     public Object[] getImplementations() {
62         Object[] res = { NFchainAgent.class };
63         return res;
64     }
65
66     /**
67      * Function that is called when configuration of the dependencies
68      * is required.
69      *
70      * @param c dependency manager Component object, used for
71      * configuring the dependencies exported and imported
72      * @param imp Implementation class that is being configured,
73      * needed as long as the same routine can configure multiple
74      * implementations
75      * @param containerName The containerName being configured, this allow
76      * also optional per-container different behavior if needed, usually
77      * should not be the case though.
78      */
79     public void configureInstance(Component c, Object imp, String containerName) {
80         if (imp.equals(NFchainAgent.class)) {
81             // export the services
82             Dictionary<String, String> props = new Hashtable<String, String>();
83             props.put("salListenerName", "NFchainAgent");
84             c.setInterface(new String[] { IListenDataPacket.class.getName(),                    
85                                           NFchainAgent.class.getName() }, props);
86
87             // register dependent modules
88             c.add(createContainerServiceDependency(containerName)
89                   .setService(IfL2Agent.class)
90                   .setCallbacks("setL2Agent", "unsetL2Agent")
91                   .setRequired(true));
92
93             c.add(createContainerServiceDependency(containerName).setService(
94                     ISwitchManager.class).setCallbacks("setSwitchManager",
95                     "unsetSwitchManager").setRequired(true));
96
97             c.add(createContainerServiceDependency(containerName).setService(
98                     IFlowProgrammerService.class).setCallbacks(
99                     "setFlowProgrammerService", "unsetFlowProgrammerService")
100                     .setRequired(true));
101         }
102     }
103 }