Skip to content

Commit 6e1740d

Browse files
committed
[router-table] handle the part of neighbor's route64 tlv which contains its own information
1 parent dc4acf0 commit 6e1740d

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

src/core/thread/router_table.cpp

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ void RouterTable::UpdateRoutes(const Mle::RouteTlv &aRouteTlv, uint8_t aNeighbor
617617

618618
router = FindRouterById(routerId);
619619

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

630-
if ((nextHop == nullptr) || (nextHop == neighbor))
630+
if (router == neighbor)
631631
{
632-
// `router` has no next hop or next hop is neighbor (sender)
633-
634-
if (cost + linkCostToNeighbor < Mle::kMaxRouteCost)
632+
uint8_t curCost = router->GetCost();
633+
uint8_t newCost = linkCostToNeighbor;
634+
if (nextHop == nullptr)
635635
{
636-
if (router->SetNextHopAndCost(aNeighborId, cost))
637-
{
638-
SignalTableChanged();
639-
}
636+
curCost += Mle::kMaxRouteCost;
640637
}
641-
else if (nextHop == neighbor)
638+
else
639+
{
640+
curCost += GetLinkCost(*nextHop);
641+
}
642+
if (newCost <= curCost && router->SetNextHopAndCost(aNeighborId, newCost))
642643
{
643-
router->SetNextHopToInvalid();
644-
router->SetLastHeard(TimerMilli::GetNow());
645644
SignalTableChanged();
646645
}
647646
}
648647
else
649648
{
650-
uint8_t curCost = router->GetCost() + GetLinkCost(*nextHop);
651-
uint8_t newCost = cost + linkCostToNeighbor;
649+
if ((nextHop == nullptr) || (nextHop == neighbor))
650+
{
651+
// `router` has no next hop or next hop is neighbor (sender)
652652

653-
if (newCost < curCost)
653+
if (cost + linkCostToNeighbor < Mle::kMaxRouteCost)
654+
{
655+
if (router->SetNextHopAndCost(aNeighborId, cost))
656+
{
657+
SignalTableChanged();
658+
}
659+
}
660+
else if (nextHop == neighbor)
661+
{
662+
router->SetNextHopToInvalid();
663+
router->SetLastHeard(TimerMilli::GetNow());
664+
SignalTableChanged();
665+
}
666+
}
667+
else
654668
{
655-
router->SetNextHopAndCost(aNeighborId, cost);
656-
SignalTableChanged();
669+
uint8_t curCost = router->GetCost() + GetLinkCost(*nextHop);
670+
uint8_t newCost = cost + linkCostToNeighbor;
671+
672+
if (newCost < curCost)
673+
{
674+
router->SetNextHopAndCost(aNeighborId, cost);
675+
SignalTableChanged();
676+
}
657677
}
658678
}
659679
}

0 commit comments

Comments
 (0)