diff --git a/orchagent/vnetorch.cpp b/orchagent/vnetorch.cpp index 8fe1731d2153..5795b0aae2f0 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 a58fae41ed0d..6d24bb5201bd 100644 --- a/orchagent/vnetorch.h +++ b/orchagent/vnetorch.h @@ -175,6 +175,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();