Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TACappleman committed Oct 12, 2021
1 parent 54234b4 commit 2b0a533
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 109 deletions.
208 changes: 100 additions & 108 deletions orchagent/mplsrouteorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,97 +474,93 @@ bool RouteOrch::addLabelRoute(LabelRouteBulkContext& ctx, const NextHopGroupKey

auto it_route = m_syncdLabelRoutes.at(vrf_id).find(label);

if (ctx.nhg_index.empty())
if (!ctx.nhg_index.empty())
{
if (nextHops.getSize() == 0)
try
{
/* The route is pointing to a blackhole */
blackhole = true;
const NextHopGroup& nhg = gNhgOrch->getNhg(ctx.nhg_index);
next_hop_id = nhg.getId();
}
/* The route is pointing to a next hop */
else if (nextHops.getSize() == 1)
catch(const std::out_of_range& e)
{
const NextHopKey& nexthop = *nextHops.getNextHops().begin();
if (nexthop.isIntfNextHop())
SWSS_LOG_WARN("Next hop group key %s does not exist", ctx.nhg_index.c_str());
return false;
}
}
else if (nextHops.getSize() == 0)
{
/* The route is pointing to a blackhole */
blackhole = true;
}
/* The route is pointing to a next hop */
else if (nextHops.getSize() == 1)
{
const NextHopKey& nexthop = *nextHops.getNextHops().begin();
if (nexthop.isIntfNextHop())
{
next_hop_id = m_intfsOrch->getRouterIntfsId(nexthop.alias);
/* rif is not created yet */
if (next_hop_id == SAI_NULL_OBJECT_ID)
{
next_hop_id = m_intfsOrch->getRouterIntfsId(nexthop.alias);
/* rif is not created yet */
if (next_hop_id == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_INFO("Failed to get next hop %s for %u",
nextHops.to_string().c_str(), label);
return false;
}
SWSS_LOG_INFO("Failed to get next hop %s for %u",
nextHops.to_string().c_str(), label);
return false;
}
}
else
{
if (m_neighOrch->hasNextHop(nexthop))
{
next_hop_id = m_neighOrch->getNextHopId(nexthop);
}
/* See if there is an IP neighbor nexthop */
else if (nexthop.isMplsNextHop() &&
m_neighOrch->isNeighborResolved(nexthop))
{
m_neighOrch->addNextHop(nexthop);
next_hop_id = m_neighOrch->getNextHopId(nexthop);
}
else
{
if (m_neighOrch->hasNextHop(nexthop))
{
next_hop_id = m_neighOrch->getNextHopId(nexthop);
}
/* See if there is an IP neighbor nexthop */
else if (nexthop.isMplsNextHop() &&
m_neighOrch->isNeighborResolved(nexthop))
{
m_neighOrch->addNextHop(nexthop);
next_hop_id = m_neighOrch->getNextHopId(nexthop);
}
else
{
SWSS_LOG_INFO("Failed to get next hop %s for %u",
nextHops.to_string().c_str(), label);
return false;
}
SWSS_LOG_INFO("Failed to get next hop %s for %u",
nextHops.to_string().c_str(), label);
return false;
}
}
/* The route is pointing to a next hop group */
else
}
/* The route is pointing to a next hop group */
else
{
/* Check if there is already an existing next hop group */
if (!hasNextHopGroup(nextHops))
{
/* Check if there is already an existing next hop group */
if (!hasNextHopGroup(nextHops))
/* Try to create a new next hop group */
if (!addNextHopGroup(nextHops))
{
/* Try to create a new next hop group */
if (!addNextHopGroup(nextHops))
{
/* Failed to create the next hop group and check if a temporary route is needed */
/* 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_syncdLabelRoutes.at(vrf_id).end() &&
it_route->second.nhg_key.getSize() == 1)
/* 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_syncdLabelRoutes.at(vrf_id).end() &&
it_route->second.nhg_key.getSize() == 1)
{
const NextHopKey& nexthop = *it_route->second.nhg_key.getNextHops().begin();
if (nextHops.contains(nexthop))
{
const NextHopKey& nexthop = *it_route->second.nhg_key.getNextHops().begin();
if (nextHops.contains(nexthop))
{
return false;
}
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. */
addTempLabelRoute(ctx, nextHops);
/* Return false since the original route is not successfully added */
return false;
}
}

next_hop_id = m_syncdNextHopGroups[nextHops].next_hop_group_id;
}
}
else
{
SWSS_LOG_DEBUG("Next hop group is owned by NhgOrch with index %s", ctx.nhg_index.c_str());
try
{
const NextHopGroup& nhg = gNhgOrch->getNhg(ctx.nhg_index);
next_hop_id = nhg.getId();
}
catch(const std::out_of_range& e)
{
SWSS_LOG_WARN("Next hop group key %s does not exist", ctx.nhg_index.c_str());
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. */
addTempLabelRoute(ctx, nextHops);
/* Return false since the original route is not successfully added */
return false;
}
}

next_hop_id = m_syncdNextHopGroups[nextHops].next_hop_group_id;
}

/* Sync the inseg entry */
Expand Down Expand Up @@ -661,57 +657,53 @@ bool RouteOrch::addLabelRoutePost(const LabelRouteBulkContext& ctx, const NextHo
sai_object_id_t next_hop_id;

/* Check that the next hop group is not owned by NhgOrch. */
if (ctx.nhg_index.empty())
if (!ctx.nhg_index.empty())
{
if (nextHops.getSize() == 0)
if (!gNhgOrch->hasNhg(ctx.nhg_index))
{
/* The route is pointing to a blackhole */
blackhole = true;
SWSS_LOG_WARN("Failed to get next hop group with index %s", ctx.nhg_index.c_str());
return false;
}
/* The route is pointing to a next hop */
else if (nextHops.getSize() == 1)
}
else if (nextHops.getSize() == 0)
{
/* The route is pointing to a blackhole */
blackhole = true;
}
/* The route is pointing to a next hop */
else if (nextHops.getSize() == 1)
{
const NextHopKey& nexthop = *nextHops.getNextHops().begin();
if (nexthop.isIntfNextHop())
{
const NextHopKey& nexthop = *nextHops.getNextHops().begin();
if (nexthop.isIntfNextHop())
{

next_hop_id = m_intfsOrch->getRouterIntfsId(nexthop.alias);
/* rif is not created yet */
if (next_hop_id == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_INFO("Failed to get next hop %s for label %u",
nextHops.to_string().c_str(), label);
return false;
}
}
else
next_hop_id = m_intfsOrch->getRouterIntfsId(nexthop.alias);
/* rif is not created yet */
if (next_hop_id == SAI_NULL_OBJECT_ID)
{
if (!m_neighOrch->hasNextHop(nexthop))
{
SWSS_LOG_INFO("Failed to get next hop %s for label %u",
nextHops.to_string().c_str(), label);
return false;
}
SWSS_LOG_INFO("Failed to get next hop %s for label %u",
nextHops.to_string().c_str(), label);
return false;
}
}
/* The route is pointing to a next hop group */
else if (nextHops.getSize() > 1)
else
{
if (!hasNextHopGroup(nextHops))
if (!m_neighOrch->hasNextHop(nexthop))
{
// Previous added an temporary route
auto& tmp_next_hop = ctx.tmp_next_hop;
addLabelRoutePost(ctx, tmp_next_hop);
SWSS_LOG_INFO("Failed to get next hop %s for label %u",
nextHops.to_string().c_str(), label);
return false;
}
}
}
else
/* The route is pointing to a next hop group */
else if (nextHops.getSize() > 1)
{
SWSS_LOG_DEBUG("NhgOrch owns the next hop group with index %s", ctx.nhg_index.c_str());
if (!gNhgOrch->hasNhg(ctx.nhg_index))
if (!hasNextHopGroup(nextHops))
{
SWSS_LOG_WARN("Failed to get next hop group with index %s", ctx.nhg_index.c_str());
// Previous added an temporary route
auto& tmp_next_hop = ctx.tmp_next_hop;
addLabelRoutePost(ctx, tmp_next_hop);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion orchagent/routeorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct LabelRouteBulkContext
class RouteOrch : public Orch, public Subject
{
public:
RouteOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames, SwitchOrch *switchOrc, NeighOrch *neighOrch, IntfsOrch *intfsOrch, VRFOrch *vrfOrch, FgNhgOrch *fgNhgOrch);
RouteOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames, SwitchOrch *switchOrch, NeighOrch *neighOrch, IntfsOrch *intfsOrch, VRFOrch *vrfOrch, FgNhgOrch *fgNhgOrch);

bool hasNextHopGroup(const NextHopGroupKey&) const;
sai_object_id_t getNextHopGroupId(const NextHopGroupKey&);
Expand Down

0 comments on commit 2b0a533

Please sign in to comment.