2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.vpnservice.nexthopmgr;
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;
23 public class NexthopmgrProvider implements BindingAwareProvider, AutoCloseable {
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;
34 public RpcProviderRegistry getRpcProviderRegistry() {
35 return rpcProviderRegistry;
38 public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
39 this.rpcProviderRegistry = rpcProviderRegistry;
43 public void onSessionInitiated(ProviderContext session) {
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");
59 LOG.error("Error initializing services", e);
63 public void setMdsalManager(IMdsalApiManager mdsalManager) {
64 this.mdsalManager = mdsalManager;
67 public void setInterfaceManager(IInterfaceManager interfaceManager) {
68 this.interfaceManager = interfaceManager;
71 public NexthopmgrProvider(RpcProviderRegistry rpcRegistry) {
72 this.rpcProviderRegistry = rpcRegistry;
76 public void close() throws Exception {
77 vpnIfListener.close();
78 odlIfListener.close();
80 LOG.info("NexthopmgrProvider Closed");