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.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;
24 public class NexthopmgrProvider implements BindingAwareProvider, AutoCloseable {
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;
35 public RpcProviderRegistry getRpcProviderRegistry() {
36 return rpcProviderRegistry;
39 public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
40 this.rpcProviderRegistry = rpcProviderRegistry;
44 public void onSessionInitiated(ProviderContext session) {
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");
60 LOG.error("Error initializing services", e);
64 public void setMdsalManager(IMdsalApiManager mdsalManager) {
65 this.mdsalManager = mdsalManager;
68 public void setInterfaceManager(IInterfaceManager interfaceManager) {
69 this.interfaceManager = interfaceManager;
72 public NexthopmgrProvider(RpcProviderRegistry rpcRegistry) {
73 this.rpcProviderRegistry = rpcRegistry;
77 public void close() throws Exception {
78 vpnIfListener.close();
79 odlIfListener.close();
81 LOG.info("NexthopmgrProvider Closed");