[netif] simplify ThreadNetif (#8882)

This commit simplifies `ThreadNetif` class by removing methods
like `IsOnMesh()` and `SendMessage()` which just call same method
on other modules (`NetworkData::Leader` and `MeshForwarder`). It
also moves the `RouteLookup()` method to `Ip6` class.
This commit is contained in:
Abtin Keshavarzian
2023-03-21 17:54:08 -07:00
committed by GitHub
parent b3dbc6c2e9
commit 32a538f773
5 changed files with 27 additions and 63 deletions
+25 -9
View File
@@ -1192,7 +1192,7 @@ start:
forwardThread = true;
#endif
}
else if (Get<ThreadNetif>().RouteLookup(header.GetSource(), header.GetDestination()) == kErrorNone)
else if (RouteLookup(header.GetSource(), header.GetDestination()) == kErrorNone)
{
forwardThread = true;
}
@@ -1310,7 +1310,7 @@ start:
#endif
// `SendMessage()` takes custody of message in the success case
SuccessOrExit(error = Get<ThreadNetif>().SendMessage(aMessage));
SuccessOrExit(error = Get<MeshForwarder>().SendMessage(aMessage));
shouldFreeMessage = false;
}
@@ -1442,23 +1442,39 @@ exit:
bool Ip6::IsOnLink(const Address &aAddress) const
{
bool rval = false;
bool isOnLink = false;
if (Get<ThreadNetif>().IsOnMesh(aAddress))
if (Get<NetworkData::Leader>().IsOnMesh(aAddress))
{
ExitNow(rval = true);
ExitNow(isOnLink = true);
}
for (const Netif::UnicastAddress &cur : Get<ThreadNetif>().GetUnicastAddresses())
for (const Netif::UnicastAddress &unicastAddr : Get<ThreadNetif>().GetUnicastAddresses())
{
if (cur.GetAddress().PrefixMatch(aAddress) >= cur.mPrefixLength)
if (unicastAddr.GetAddress().PrefixMatch(aAddress) >= unicastAddr.mPrefixLength)
{
ExitNow(rval = true);
ExitNow(isOnLink = true);
}
}
exit:
return rval;
return isOnLink;
}
Error Ip6::RouteLookup(const Address &aSource, const Address &aDestination) const
{
Error error;
uint16_t rloc;
SuccessOrExit(error = Get<NetworkData::Leader>().RouteLookup(aSource, aDestination, rloc));
if (rloc == Get<Mle::Mle>().GetRloc16())
{
error = kErrorNoRoute;
}
exit:
return error;
}
#if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE
+1
View File
@@ -409,6 +409,7 @@ private:
uint8_t aIpProto,
Message::Ownership aMessageOwnership);
bool IsOnLink(const Address &aAddress) const;
Error RouteLookup(const Address &aSource, const Address &aDestination) const;
#if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE
void UpdateBorderRoutingCounters(const Header &aHeader, uint16_t aMessageLength, bool aIsInbound);
#endif
+1 -1
View File
@@ -83,7 +83,7 @@ void ChildSupervisor::SendMessage(Child &aChild)
childIndex = Get<ChildTable>().GetChildIndex(aChild);
SuccessOrExit(message->Append(childIndex));
SuccessOrExit(Get<ThreadNetif>().SendMessage(*message));
SuccessOrExit(Get<MeshForwarder>().SendMessage(*message));
message = nullptr;
LogInfo("Sending supervision message to child 0x%04x", aChild.GetRloc16());
-20
View File
@@ -118,24 +118,4 @@ exit:
return;
}
Error ThreadNetif::SendMessage(Message &aMessage) { return Get<MeshForwarder>().SendMessage(aMessage); }
Error ThreadNetif::RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination)
{
Error error;
uint16_t rloc;
SuccessOrExit(error = Get<NetworkData::Leader>().RouteLookup(aSource, aDestination, rloc));
if (rloc == Get<Mle::MleRouter>().GetRloc16())
{
error = kErrorNoRoute;
}
exit:
return error;
}
bool ThreadNetif::IsOnMesh(const Ip6::Address &aAddress) const { return Get<NetworkData::Leader>().IsOnMesh(aAddress); }
} // namespace ot
-33
View File
@@ -82,39 +82,6 @@ public:
*/
bool IsUp(void) const { return mIsUp; }
/**
* This method submits a message to the network interface.
*
* @param[in] aMessage A reference to the message.
*
* @retval kErrorNone Successfully submitted the message to the interface.
*
*/
Error SendMessage(Message &aMessage);
/**
* This method performs a route lookup.
*
* @param[in] aSource A reference to the IPv6 source address.
* @param[in] aDestination A reference to the IPv6 destination address.
*
* @retval kErrorNone Successfully found a route.
* @retval kErrorNoRoute Could not find a valid route.
*
*/
Error RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination);
/**
* This method indicates whether @p aAddress matches an on-mesh prefix.
*
* @param[in] aAddress The IPv6 address.
*
* @retval TRUE If @p aAddress matches an on-mesh prefix.
* @retval FALSE If @p aAddress does not match an on-mesh prefix.
*
*/
bool IsOnMesh(const Ip6::Address &aAddress) const;
private:
bool mIsUp;
};