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;
10 import java.math.BigInteger;
11 import java.util.Collections;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.Future;
15 import org.opendaylight.bgpmanager.api.IBgpManager;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
19 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
20 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class VpnserviceProvider implements BindingAwareProvider,
31 private static final Logger LOG = LoggerFactory.getLogger(VpnserviceProvider.class);
32 private VpnInterfaceManager vpnInterfaceManager;
33 private VpnManager vpnManager;
34 private IBgpManager bgpManager;
35 private IMdsalApiManager mdsalManager;
36 private IInterfaceManager interfaceManager;
37 private IdManagerService idManager;
40 public void onSessionInitiated(ProviderContext session) {
41 LOG.info("VpnserviceProvider Session Initiated");
43 final DataBroker dataBroker = session.getSALService(DataBroker.class);
44 vpnManager = new VpnManager(dataBroker, bgpManager);
45 vpnManager.setIdManager(idManager);
46 vpnInterfaceManager = new VpnInterfaceManager(dataBroker, bgpManager);
47 vpnInterfaceManager.setMdsalManager(mdsalManager);
48 vpnInterfaceManager.setInterfaceManager(interfaceManager);
49 vpnInterfaceManager.setIdManager(idManager);
51 } catch (Exception e) {
52 LOG.error("Error initializing services", e);
56 public void setBgpManager(IBgpManager bgpManager) {
57 LOG.debug("BGP Manager reference initialized");
58 this.bgpManager = bgpManager;
61 public void setMdsalManager(IMdsalApiManager mdsalManager) {
62 this.mdsalManager = mdsalManager;
65 public void setInterfaceManager(IInterfaceManager interfaceManager) {
66 this.interfaceManager = interfaceManager;
69 public void setIdManager(IdManagerService idManager) {
70 this.idManager = idManager;
73 private void createIdPool() {
74 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
75 .setPoolName(VpnConstants.VPN_IDPOOL_NAME)
76 .setIdStart(VpnConstants.VPN_IDPOOL_START)
77 .setPoolSize(new BigInteger(VpnConstants.VPN_IDPOOL_SIZE))
80 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
81 if ((result != null) && (result.get().isSuccessful())) {
82 LOG.info("Created IdPool for VPN Service");
84 } catch (InterruptedException | ExecutionException e) {
85 LOG.error("Failed to create idPool for VPN Service",e);
90 public void close() throws Exception {
92 vpnInterfaceManager.close();