Imported vpnservice as a subtree
[netvirt.git] / vpnservice / 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.idmanager.rev150403.IdManagerService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.l3nexthop.rev150409.L3nexthopService;
19 import org.opendaylight.idmanager.IdManager;
20 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class NexthopmgrProvider implements BindingAwareProvider, AutoCloseable {
25
26     private static final Logger LOG = LoggerFactory.getLogger(NexthopmgrProvider.class);
27     private VpnInterfaceChangeListener vpnIfListener;
28     private OdlInterfaceChangeListener odlIfListener;
29     private NexthopManager nhManager;
30     private IMdsalApiManager mdsalManager;
31     private IInterfaceManager interfaceManager;
32     private IdManagerService idManager;
33     private RpcProviderRegistry rpcProviderRegistry;
34
35     public RpcProviderRegistry getRpcProviderRegistry() {
36         return rpcProviderRegistry;
37     }
38
39     public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
40         this.rpcProviderRegistry = rpcProviderRegistry;
41     }
42
43     @Override
44     public void onSessionInitiated(ProviderContext session) {
45         try {
46         final  DataBroker dbx = session.getSALService(DataBroker.class);
47         nhManager = new NexthopManager(dbx);
48         vpnIfListener = new VpnInterfaceChangeListener(dbx, nhManager);
49         odlIfListener = new OdlInterfaceChangeListener(dbx, nhManager, interfaceManager);
50         idManager = rpcProviderRegistry.getRpcService(IdManagerService.class);
51         final BindingAwareBroker.RpcRegistration<L3nexthopService> rpcRegistration = getRpcProviderRegistry().addRpcImplementation(L3nexthopService.class, nhManager);
52         nhManager.setMdsalManager(mdsalManager);
53         nhManager.setInterfaceManager(interfaceManager);
54         nhManager.setIdManager(idManager);
55         nhManager.createNexthopPointerPool();
56         LOG.info("NexthopmgrProvider Session Initiated");
57         }
58         catch (Exception e)
59         {
60             LOG.error("Error initializing services", e);
61         }
62     }
63
64     public void setMdsalManager(IMdsalApiManager mdsalManager) {
65         this.mdsalManager = mdsalManager;
66     }
67
68     public void setInterfaceManager(IInterfaceManager interfaceManager) {
69         this.interfaceManager = interfaceManager;
70     }
71
72     public NexthopmgrProvider(RpcProviderRegistry rpcRegistry) {
73         this.rpcProviderRegistry = rpcRegistry;
74     }
75
76     @Override
77     public void close() throws Exception {
78         vpnIfListener.close();
79         odlIfListener.close();
80         nhManager.close();
81         LOG.info("NexthopmgrProvider Closed");
82     }
83
84 }