de61812fe958519ecc17da8c6822308b1f2c7027
[vpnservice.git] / nexthopmgr / nexthopmgr-impl / src / main / java / org / opendaylight / vpnservice / nexthopmgr / NexthopmgrProvider.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
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 package org.opendaylight.vpnservice.nexthopmgr;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
14 import org.opendaylight.vpnservice.nexthopmgr.NexthopManager;
15 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
16 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.l3nexthop.rev150409.L3nexthopService;
18 import org.opendaylight.idmanager.IdManager;
19 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class NexthopmgrProvider implements BindingAwareProvider, AutoCloseable {
24
25     private static final Logger LOG = LoggerFactory.getLogger(NexthopmgrProvider.class);
26     private VpnInterfaceChangeListener vpnIfListener;
27     private OdlInterfaceChangeListener odlIfListener;
28     private NexthopManager nhManager;
29     private IMdsalApiManager mdsalManager;
30     private IInterfaceManager interfaceManager;
31     private IdManager idManager;
32     private RpcProviderRegistry rpcProviderRegistry;
33
34     public RpcProviderRegistry getRpcProviderRegistry() {
35         return rpcProviderRegistry;
36     }
37
38     public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
39         this.rpcProviderRegistry = rpcProviderRegistry;
40     }
41
42     @Override
43     public void onSessionInitiated(ProviderContext session) {
44         try {
45         final  DataBroker dbx = session.getSALService(DataBroker.class);
46         nhManager = new NexthopManager(dbx);
47         vpnIfListener = new VpnInterfaceChangeListener(dbx, nhManager);
48         odlIfListener = new OdlInterfaceChangeListener(dbx, nhManager, interfaceManager);
49         idManager = new IdManager(dbx);
50         final BindingAwareBroker.RpcRegistration<L3nexthopService> rpcRegistration = getRpcProviderRegistry().addRpcImplementation(L3nexthopService.class, nhManager);
51         nhManager.setMdsalManager(mdsalManager);
52         nhManager.setInterfaceManager(interfaceManager);
53         nhManager.setIdManager(idManager);
54         nhManager.createNexthopPointerPool();
55         LOG.info("NexthopmgrProvider Session Initiated");
56         }
57         catch (Exception e)
58         {
59             LOG.error("Error initializing services", e);
60         }
61     }
62
63     public void setMdsalManager(IMdsalApiManager mdsalManager) {
64         this.mdsalManager = mdsalManager;
65     }
66
67     public void setInterfaceManager(IInterfaceManager interfaceManager) {
68         this.interfaceManager = interfaceManager;
69     }
70
71     public NexthopmgrProvider(RpcProviderRegistry rpcRegistry) {
72         this.rpcProviderRegistry = rpcRegistry;
73     }
74
75     @Override
76     public void close() throws Exception {
77         vpnIfListener.close();
78         odlIfListener.close();
79         nhManager.close();
80         LOG.info("NexthopmgrProvider Closed");
81     }
82
83 }