Skip to content

Commit c6de96b

Browse files
authored
Fix overlay nexthop ref_count is incorrect issue when add and delete route at same time. (sonic-net#1698)
reference sonic-net#1501: remove overlay nexthop after updating the reference counter for a bulk of routes
1 parent 73601f8 commit c6de96b

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

orchagent/routeorch.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,15 @@ void RouteOrch::doTask(Consumer& consumer)
781781
}
782782

783783
/* Remove next hop group if the reference count decreases to zero */
784-
for (auto it_nhg = m_bulkNhgReducedRefCnt.begin(); it_nhg != m_bulkNhgReducedRefCnt.end(); it_nhg++)
784+
for (auto& it_nhg : m_bulkNhgReducedRefCnt)
785785
{
786-
if (m_syncdNextHopGroups[*it_nhg].ref_count == 0)
786+
if (it_nhg.first.is_overlay_nexthop() && it_nhg.second != 0)
787787
{
788-
removeNextHopGroup(*it_nhg);
788+
removeOverlayNextHops(it_nhg.second, it_nhg.first);
789+
}
790+
else if (m_syncdNextHopGroups[it_nhg.first].ref_count == 0)
791+
{
792+
removeNextHopGroup(it_nhg.first);
789793
}
790794
}
791795
}
@@ -1516,7 +1520,7 @@ bool RouteOrch::addRoute(RouteBulkContext& ctx, const NextHopGroupKey &nextHops)
15161520
auto old_nextHops = it_route->second;
15171521

15181522
if (old_nextHops.is_overlay_nexthop()) {
1519-
nexthop = NextHopKey(it_route->second.to_string(), true);
1523+
nexthop = NextHopKey(old_nextHops.to_string(), true);
15201524
} else {
15211525
nexthop = NextHopKey(it_route->second.to_string());
15221526
}
@@ -1729,7 +1733,7 @@ bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey
17291733
if (it_route->second.getSize() > 1
17301734
&& m_syncdNextHopGroups[it_route->second].ref_count == 0)
17311735
{
1732-
m_bulkNhgReducedRefCnt.emplace(it_route->second);
1736+
m_bulkNhgReducedRefCnt.emplace(it_route->second, 0);
17331737
}
17341738
}
17351739
SWSS_LOG_INFO("FG Post set route %s with next hop(s) %s",
@@ -1817,11 +1821,10 @@ bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey
18171821
if (it_route->second.getSize() > 1
18181822
&& m_syncdNextHopGroups[it_route->second].ref_count == 0)
18191823
{
1820-
m_bulkNhgReducedRefCnt.emplace(it_route->second);
1824+
m_bulkNhgReducedRefCnt.emplace(it_route->second, 0);
18211825
} else if (ol_nextHops.is_overlay_nexthop()){
1822-
18231826
SWSS_LOG_NOTICE("Update overlay Nexthop %s", ol_nextHops.to_string().c_str());
1824-
removeOverlayNextHops(vrf_id, ol_nextHops);
1827+
m_bulkNhgReducedRefCnt.emplace(ol_nextHops, vrf_id);
18251828
}
18261829
}
18271830

@@ -1996,10 +1999,10 @@ bool RouteOrch::removeRoutePost(const RouteBulkContext& ctx)
19961999
if (it_route->second.getSize() > 1
19972000
&& m_syncdNextHopGroups[it_route->second].ref_count == 0)
19982001
{
1999-
m_bulkNhgReducedRefCnt.emplace(it_route->second);
2002+
m_bulkNhgReducedRefCnt.emplace(it_route->second, 0);
20002003
} else if (ol_nextHops.is_overlay_nexthop()){
20012004
SWSS_LOG_NOTICE("Remove overlay Nexthop %s", ol_nextHops.to_string().c_str());
2002-
removeOverlayNextHops(vrf_id, ol_nextHops);
2005+
m_bulkNhgReducedRefCnt.emplace(ol_nextHops, vrf_id);
20032006
}
20042007
}
20052008

orchagent/routeorch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ class RouteOrch : public Orch, public Subject
135135
RouteTables m_syncdRoutes;
136136
NextHopGroupTable m_syncdNextHopGroups;
137137

138-
std::set<NextHopGroupKey> m_bulkNhgReducedRefCnt;
138+
std::set<std::pair<NextHopGroupKey, sai_object_id_t>> m_bulkNhgReducedRefCnt;
139+
/* m_bulkNhgReducedRefCnt: nexthop, vrf_id */
139140

140141
NextHopObserverTable m_nextHopObservers;
141142

0 commit comments

Comments
 (0)