Skip to content

Commit

Permalink
[router-table] handle the part of neighbor's route64 tlv which contai…
Browse files Browse the repository at this point in the history
…ns its own information
  • Loading branch information
gytxxsy committed Jan 8, 2025
1 parent dc4acf0 commit 6e1740d
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions src/core/thread/router_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ void RouterTable::UpdateRoutes(const Mle::RouteTlv &aRouteTlv, uint8_t aNeighbor

router = FindRouterById(routerId);

if (router == nullptr || Get<Mle::Mle>().HasRloc16(router->GetRloc16()) || router == neighbor)
if (router == nullptr || Get<Mle::Mle>().HasRloc16(router->GetRloc16()))
{
continue;
}
Expand All @@ -627,33 +627,53 @@ void RouterTable::UpdateRoutes(const Mle::RouteTlv &aRouteTlv, uint8_t aNeighbor
cost = aRouteTlv.GetRouteCost(index);
cost = (cost == 0) ? Mle::kMaxRouteCost : cost;

if ((nextHop == nullptr) || (nextHop == neighbor))
if (router == neighbor)
{
// `router` has no next hop or next hop is neighbor (sender)

if (cost + linkCostToNeighbor < Mle::kMaxRouteCost)
uint8_t curCost = router->GetCost();
uint8_t newCost = linkCostToNeighbor;
if (nextHop == nullptr)
{
if (router->SetNextHopAndCost(aNeighborId, cost))
{
SignalTableChanged();
}
curCost += Mle::kMaxRouteCost;
}
else if (nextHop == neighbor)
else
{
curCost += GetLinkCost(*nextHop);
}
if (newCost <= curCost && router->SetNextHopAndCost(aNeighborId, newCost))
{
router->SetNextHopToInvalid();
router->SetLastHeard(TimerMilli::GetNow());
SignalTableChanged();
}
}
else
{
uint8_t curCost = router->GetCost() + GetLinkCost(*nextHop);
uint8_t newCost = cost + linkCostToNeighbor;
if ((nextHop == nullptr) || (nextHop == neighbor))
{
// `router` has no next hop or next hop is neighbor (sender)

if (newCost < curCost)
if (cost + linkCostToNeighbor < Mle::kMaxRouteCost)
{
if (router->SetNextHopAndCost(aNeighborId, cost))
{
SignalTableChanged();
}
}
else if (nextHop == neighbor)
{
router->SetNextHopToInvalid();
router->SetLastHeard(TimerMilli::GetNow());
SignalTableChanged();
}
}
else
{
router->SetNextHopAndCost(aNeighborId, cost);
SignalTableChanged();
uint8_t curCost = router->GetCost() + GetLinkCost(*nextHop);
uint8_t newCost = cost + linkCostToNeighbor;

if (newCost < curCost)
{
router->SetNextHopAndCost(aNeighborId, cost);
SignalTableChanged();
}
}
}
}
Expand Down

0 comments on commit 6e1740d

Please sign in to comment.