2 * Copyright (c) 2015 - 2016 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.netvirt.vpnmanager;
10 import java.math.BigInteger;
11 import java.util.concurrent.ExecutionException;
12 import java.util.concurrent.Future;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
15 import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class VpnManagerImpl implements IVpnManager {
24 private static final Logger LOG = LoggerFactory.getLogger(VpnManagerImpl.class);
25 private final DataBroker dataBroker;
26 private final VpnInterfaceManager vpnInterfaceManager;
27 private final VpnInstanceListener vpnInstanceListener;
28 private final IdManagerService idManager;
30 public VpnManagerImpl(final DataBroker dataBroker,
31 final IdManagerService idManagerService,
32 final VpnInstanceListener vpnInstanceListener,
33 final VpnInterfaceManager vpnInterfaceManager) {
34 this.dataBroker = dataBroker;
35 this.vpnInterfaceManager = vpnInterfaceManager;
36 this.vpnInstanceListener = vpnInstanceListener;
37 this.idManager = idManagerService;
41 LOG.info("{} start", getClass().getSimpleName());
45 private void createIdPool() {
46 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
47 .setPoolName(VpnConstants.VPN_IDPOOL_NAME)
48 .setLow(VpnConstants.VPN_IDPOOL_START)
49 .setHigh(new BigInteger(VpnConstants.VPN_IDPOOL_SIZE).longValue())
52 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
53 if ((result != null) && (result.get().isSuccessful())) {
54 LOG.info("Created IdPool for VPN Service");
56 } catch (InterruptedException | ExecutionException e) {
57 LOG.error("Failed to create idPool for VPN Service",e);
62 public void setFibManager(IFibManager fibManager) {
67 public void addExtraRoute(String destination, String nextHop, String rd, String routerID, int label) {
68 LOG.info("Adding extra route with destination {}, nextHop {} and label{}", destination, nextHop, label);
69 vpnInterfaceManager.addExtraRoute(destination, nextHop, rd, routerID, label, /*intfName*/ null);
73 public void delExtraRoute(String destination, String nextHop, String rd, String routerID) {
74 LOG.info("Deleting extra route with destination {} and nextHop {}", destination, nextHop);
75 vpnInterfaceManager.delExtraRoute(destination, nextHop, rd, routerID, null);
79 public boolean isVPNConfigured() {
80 return vpnInstanceListener.isVPNConfigured();
84 public boolean existsVpn(String vpnName) {
85 return VpnUtil.getVpnInstance(dataBroker, vpnName) != null;