mirror of
https://github.com/espressif/openthread.git
synced 2026-08-20 01:19:51 +00:00
[mesh-forwarder] simplify GetForwardFramePriority() and remove GetMeshHeader() (#4453)
Before passing the frame to `GetForwardFramePriority()` the mesh header is skipped (to avoid re-reading the mesh header). Also the src/dest parameters are renamed to indicate they are mesh source and mesh destination (also the order of parameters changed to start with source and then dest). With this change we can remove `GetMeshHeader()` (since no longer used/needed).
This commit is contained in:
committed by
Jonathan Hui
parent
1a96fef16d
commit
5eba7f1cb4
@@ -389,18 +389,6 @@ void MeshForwarder::GetMacDestinationAddress(const Ip6::Address &aIp6Addr, Mac::
|
||||
}
|
||||
}
|
||||
|
||||
otError MeshForwarder::GetMeshHeader(const uint8_t *&aFrame, uint16_t &aFrameLength, Lowpan::MeshHeader &aMeshHeader)
|
||||
{
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(aFrameLength >= 1 && reinterpret_cast<const Lowpan::MeshHeader *>(aFrame)->IsMeshHeader(),
|
||||
error = OT_ERROR_NOT_FOUND);
|
||||
SuccessOrExit(error = aMeshHeader.Init(aFrame, aFrameLength));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError MeshForwarder::SkipMeshHeader(const uint8_t *&aFrame, uint16_t &aFrameLength)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -345,7 +345,6 @@ private:
|
||||
const Mac::Address &aMeshSource,
|
||||
const Mac::Address &aMeshDest);
|
||||
|
||||
otError GetMeshHeader(const uint8_t *&aFrame, uint16_t &aFrameLength, Lowpan::MeshHeader &aMeshHeader);
|
||||
otError SkipMeshHeader(const uint8_t *&aFrame, uint16_t &aFrameLength);
|
||||
otError DecompressIp6Header(const uint8_t * aFrame,
|
||||
uint16_t aFrameLength,
|
||||
@@ -425,8 +424,8 @@ private:
|
||||
otError GetFragmentPriority(Lowpan::FragmentHeader &aFragmentHeader, uint16_t aSrcRloc16, uint8_t &aPriority);
|
||||
otError GetForwardFramePriority(const uint8_t * aFrame,
|
||||
uint16_t aFrameLength,
|
||||
const Mac::Address &aMacDest,
|
||||
const Mac::Address &aMacSource,
|
||||
const Mac::Address &aMeshSource,
|
||||
const Mac::Address &aMeshDest,
|
||||
uint8_t & aPriority);
|
||||
|
||||
FragmentPriorityEntry *FindFragmentPriorityEntry(uint16_t aTag, uint16_t aSrcRloc16);
|
||||
|
||||
@@ -547,7 +547,8 @@ void MeshForwarder::HandleMesh(uint8_t * aFrame,
|
||||
meshHeader.SetHopsLeft(meshHeader.GetHopsLeft() - 1);
|
||||
meshHeader.AppendTo(aFrame);
|
||||
|
||||
GetForwardFramePriority(aFrame, aFrameLength, meshDest, meshSource, priority);
|
||||
GetForwardFramePriority(aFrame + meshHeader.GetHeaderLength(), aFrameLength - meshHeader.GetHeaderLength(),
|
||||
meshSource, meshDest, priority);
|
||||
VerifyOrExit((message = Get<MessagePool>().New(Message::kType6lowpan, priority)) != NULL,
|
||||
error = OT_ERROR_NO_BUFS);
|
||||
SuccessOrExit(error = message->SetLength(aFrameLength));
|
||||
@@ -725,19 +726,14 @@ exit:
|
||||
|
||||
otError MeshForwarder::GetForwardFramePriority(const uint8_t * aFrame,
|
||||
uint16_t aFrameLength,
|
||||
const Mac::Address &aMacDest,
|
||||
const Mac::Address &aMacSource,
|
||||
const Mac::Address &aMeshSource,
|
||||
const Mac::Address &aMeshDest,
|
||||
uint8_t & aPriority)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool isFragment = false;
|
||||
Lowpan::MeshHeader meshHeader;
|
||||
Lowpan::FragmentHeader fragmentHeader;
|
||||
|
||||
SuccessOrExit(error = GetMeshHeader(aFrame, aFrameLength, meshHeader));
|
||||
aFrame += meshHeader.GetHeaderLength();
|
||||
aFrameLength -= meshHeader.GetHeaderLength();
|
||||
|
||||
if (GetFragmentHeader(aFrame, aFrameLength, fragmentHeader) == OT_ERROR_NONE)
|
||||
{
|
||||
isFragment = true;
|
||||
@@ -747,23 +743,23 @@ otError MeshForwarder::GetForwardFramePriority(const uint8_t * aFrame,
|
||||
if (fragmentHeader.GetDatagramOffset() > 0)
|
||||
{
|
||||
// Get priority from the pre-buffered info
|
||||
ExitNow(error = GetFragmentPriority(fragmentHeader, meshHeader.GetSource(), aPriority));
|
||||
ExitNow(error = GetFragmentPriority(fragmentHeader, aMeshSource.GetShort(), aPriority));
|
||||
}
|
||||
}
|
||||
|
||||
// Get priority from IPv6 header or UDP destination port directly
|
||||
error = GetFramePriority(aFrame, aFrameLength, aMacSource, aMacDest, aPriority);
|
||||
error = GetFramePriority(aFrame, aFrameLength, aMeshSource, aMeshDest, aPriority);
|
||||
|
||||
exit:
|
||||
if (error != OT_ERROR_NONE)
|
||||
{
|
||||
otLogNoteMac("Failed to get forwarded frame priority, error:%s, len:%d, dst:%s, src:%s",
|
||||
otThreadErrorToString(error), aFrameLength, aMacDest.ToString().AsCString(),
|
||||
aMacSource.ToString().AsCString());
|
||||
otLogNoteMac("Failed to get forwarded frame priority, error:%s, len:%d, src:%d, dst:%s",
|
||||
otThreadErrorToString(error), aFrameLength, aMeshSource.ToString().AsCString(),
|
||||
aMeshDest.ToString().AsCString());
|
||||
}
|
||||
else if (isFragment)
|
||||
{
|
||||
UpdateFragmentPriority(fragmentHeader, aFrameLength, meshHeader.GetSource(), aPriority);
|
||||
UpdateFragmentPriority(fragmentHeader, aFrameLength, aMeshSource.GetShort(), aPriority);
|
||||
}
|
||||
|
||||
return error;
|
||||
|
||||
Reference in New Issue
Block a user