Skip to content

Commit

Permalink
[vnet] Maintain the reference count of the nexthop when creating a vn… (
Browse files Browse the repository at this point in the history
sonic-net#1414)

* [vnet] Maintain the reference count of the nexthop when creating a vnet route
  • Loading branch information
liron-ze authored and abdosi committed Sep 3, 2020
1 parent debc5bb commit 2d3a575
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions orchagent/vnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -171,6 +220,7 @@ bool VNetVrfObject::addRoute(IpPrefix& ipPrefix, nextHop& nh)
return false;
}

increaseNextHopRefCount(nh);
routes_[ipPrefix] = nh;
return true;
}
Expand All @@ -194,6 +244,8 @@ bool VNetVrfObject::removeRoute(IpPrefix& ipPrefix)
}
else
{
nextHop nh = routes_[ipPrefix];
decreaseNextHopRefCount(nh);
routes_.erase(ipPrefix);
}
return true;
Expand Down
2 changes: 2 additions & 0 deletions orchagent/vnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 2d3a575

Please sign in to comment.