Skip to content

Commit

Permalink
[routeorch]: Fix observer detaching procedure for next hop observers (s…
Browse files Browse the repository at this point in the history
…onic-net#985)

- erase the correct observer in the observer list
- remove the NextHopObserverEntry once no observer is observing the entry
- refine some logs and comments

Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
  • Loading branch information
stcheng authored Jul 22, 2019
1 parent 63afbd5 commit 7382995
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void RouteOrch::attach(Observer *observer, const IpAddress& dstAddr)
dstAddr.to_string().c_str());

// Trigger next hop change for the first time the observer is attached
// Note that rbegin() is pointing to the entry with longest prefix match
auto route = observerEntry->second.routeTable.rbegin();
if (route != observerEntry->second.routeTable.rend())
{
Expand All @@ -171,19 +172,34 @@ void RouteOrch::attach(Observer *observer, const IpAddress& dstAddr)
void RouteOrch::detach(Observer *observer, const IpAddress& dstAddr)
{
SWSS_LOG_ENTER();

auto observerEntry = m_nextHopObservers.find(dstAddr);

if (observerEntry == m_nextHopObservers.end())
{
SWSS_LOG_ERROR("Failed to detach observer for %s. Entry not found.\n", dstAddr.to_string().c_str());
SWSS_LOG_ERROR("Failed to locate observer for destination IP %s",
dstAddr.to_string().c_str());
assert(false);
return;
}

for (auto iter = observerEntry->second.observers.begin(); iter != observerEntry->second.observers.end(); ++iter)
// Find the observer
for (auto iter = observerEntry->second.observers.begin();
iter != observerEntry->second.observers.end(); ++iter)
{
if (observer == *iter)
{
m_observers.erase(iter);
observerEntry->second.observers.erase(iter);

SWSS_LOG_NOTICE("Detached next hop observer for destination IP %s",
dstAddr.to_string().c_str());

// Remove NextHopObserverEntry if no observer is tracking this
// destination IP.
if (observerEntry->second.observers.empty())
{
m_nextHopObservers.erase(observerEntry);
}
break;
}
}
Expand Down

0 comments on commit 7382995

Please sign in to comment.