From c5d109fb2eab0c0a7ee8285261b688521eb77f80 Mon Sep 17 00:00:00 2001 From: liron-ze Date: Tue, 1 Sep 2020 02:53:17 +0800 Subject: [PATCH] =?UTF-8?q?[vnet]=20Maintain=20the=20reference=20count=20o?= =?UTF-8?q?f=20the=20nexthop=20when=20creating=20a=20vn=E2=80=A6=20(#1414)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [vnet] Maintain the reference count of the nexthop when creating a vnet route --- orchagent/vnetorch.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ orchagent/vnetorch.h | 2 ++ 2 files changed, 54 insertions(+) diff --git a/orchagent/vnetorch.cpp b/orchagent/vnetorch.cpp index 00b7494e02..1832e8990c 100644 --- a/orchagent/vnetorch.cpp +++ b/orchagent/vnetorch.cpp @@ -163,6 +163,55 @@ bool VNetVrfObject::addRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp) return true; } +void VNetVrfObject::increaseNextHopRefCount(const nextHop& nh) +{ + /* Return when there is no next hop (dropped) */ + if (nh.ips.getSize() == 0) + { + return; + } + else if (nh.ips.getSize() == 1) + { + NextHopKey nexthop(nh.ips.to_string(), nh.ifname); + if (nexthop.ip_address.isZero()) + { + gIntfsOrch->increaseRouterIntfsRefCount(nexthop.alias); + } + else + { + gNeighOrch->increaseNextHopRefCount(nexthop); + } + } + else + { + /* Handle ECMP routes */ + } +} +void VNetVrfObject::decreaseNextHopRefCount(const nextHop& nh) +{ + /* Return when there is no next hop (dropped) */ + if (nh.ips.getSize() == 0) + { + return; + } + else if (nh.ips.getSize() == 1) + { + NextHopKey nexthop(nh.ips.to_string(), nh.ifname); + if (nexthop.ip_address.isZero()) + { + gIntfsOrch->decreaseRouterIntfsRefCount(nexthop.alias); + } + else + { + gNeighOrch->decreaseNextHopRefCount(nexthop); + } + } + else + { + /* Handle ECMP routes */ + } +} + bool VNetVrfObject::addRoute(IpPrefix& ipPrefix, nextHop& nh) { if (hasRoute(ipPrefix)) @@ -171,6 +220,7 @@ bool VNetVrfObject::addRoute(IpPrefix& ipPrefix, nextHop& nh) return false; } + increaseNextHopRefCount(nh); routes_[ipPrefix] = nh; return true; } @@ -194,6 +244,8 @@ bool VNetVrfObject::removeRoute(IpPrefix& ipPrefix) } else { + nextHop nh = routes_[ipPrefix]; + decreaseNextHopRefCount(nh); routes_.erase(ipPrefix); } return true; diff --git a/orchagent/vnetorch.h b/orchagent/vnetorch.h index 1827e8af76..7a23021e11 100644 --- a/orchagent/vnetorch.h +++ b/orchagent/vnetorch.h @@ -174,6 +174,8 @@ class VNetVrfObject : public VNetObject sai_object_id_t getTunnelNextHop(tunnelEndpoint& endp); bool removeTunnelNextHop(tunnelEndpoint& endp); + void increaseNextHopRefCount(const nextHop&); + void decreaseNextHopRefCount(const nextHop&); ~VNetVrfObject();