From d2a466db39815fab45fe50997b2788cf82ad3201 Mon Sep 17 00:00:00 2001 From: Shuotian Cheng Date: Wed, 31 May 2017 20:26:25 -0700 Subject: [PATCH] [routeorch]: Checking if a temp route is already there before adding a new one (#232) - Do not add a temporary route when there existing a route whose next hop is part of the next hop group to sync. This could prevent excessive route updates when routes fail to be inserted due to next hop group creat failure. --- orchagent/routeorch.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index bcba9fefbf7f..1ecdfffeaf99 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -552,11 +552,28 @@ bool RouteOrch::addRoute(IpPrefix ipPrefix, IpAddresses nextHops) /* The route is pointing to a next hop group */ else { - if (!hasNextHopGroup(nextHops)) /* Create a new next hop group */ + /* Check if there is already an existing next hop group */ + if (!hasNextHopGroup(nextHops)) { + /* Try to create a new next hop group */ if (!addNextHopGroup(nextHops)) { - /* Add a temporary route when a next hop group cannot be added */ + /* Failed to create the next hop group and check if a temporary route is needed */ + + /* If the current next hop is part of the next hop group to sync, + * then return false and no need to add another temporary route. */ + if (it_route != m_syncdRoutes.end() && it_route->second.getSize() == 1) + { + IpAddress ip_address(it_route->second.to_string()); + if (nextHops.contains(ip_address)) + { + return false; + } + } + + /* Add a temporary route when a next hop group cannot be added, + * and there is no temporary route right now or the current temporary + * route is not pointing to a member of the next hop group to sync. */ addTempRoute(ipPrefix, nextHops); /* Return false since the original route is not successfully added */ return false;