2 * Copyright © 2017 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.natservice.internal;
10 import java.util.concurrent.ExecutionException;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.opendaylight.genius.networkutils.VniUtils;
14 import org.opendaylight.yangtools.yang.common.Uint32;
15 import org.opendaylight.yangtools.yang.common.Uint64;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 public class NatOverVxlanUtil {
22 private static final Logger LOG = LoggerFactory.getLogger(NatOverVxlanUtil.class);
24 private VniUtils vniUtils;
27 public NatOverVxlanUtil(final VniUtils vniUtils) {
28 this.vniUtils = vniUtils;
31 public Uint32 getInternetVpnVni(String vpnUuid, Uint32 vpnid) {
32 Uint32 internetVpnVni = Uint32.valueOf(getVNI(vpnUuid).longValue());
33 if (internetVpnVni.longValue() == 0) {
34 LOG.warn("getInternetVpnVni : Unable to obtain Internet Vpn VNI from VNI POOL for Vpn {}."
35 + "Will use tunnel_id {} as Internet VNI", vpnUuid, vpnid);
39 return internetVpnVni;
42 public Uint64 getRouterVni(String routerName, Uint32 routerId) {
43 Uint64 routerVni = getVNI(routerName);
44 if (routerVni.longValue() == 0) {
45 LOG.warn("getRouterVni : Unable to obtain Router VNI from VNI POOL for router {}."
46 + "Router ID will be used as tun_id", routerName);
47 return Uint64.valueOf(routerId);
52 public void releaseVNI(String vniKey) {
54 vniUtils.releaseVNI(vniKey);
55 } catch (InterruptedException | ExecutionException e) {
56 LOG.error("releaseVNI : Exception in release VNI for Key {}", vniKey, e);
60 private Uint64 getVNI(String vniKey) {
62 return vniUtils.getVNI(vniKey);
63 } catch (InterruptedException | ExecutionException e) {
64 LOG.error("getVNI : Exception in get VNI for key {}", vniKey, e);