Skip to content

Commit

Permalink
lr-wpan: (fixes #741) add a post-rx error model
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyPec committed Oct 16, 2022
1 parent 85ade4e commit a606815
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 43 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Release 3-dev
- (utils) `utils/bench-scheduler` has been enhanced to test multiple schedulers.
- (lte) LTE handover failure is now handled for joining and leaving timeouts, RACH failure, and preamble allocation failure.
- (lr-wpan) !1131 - Add support for configurable tx queue and ind tx queue limits.
- (lr-wpan) !1133 - Add a post-rx error model.

### Bugs fixed

Expand Down
112 changes: 69 additions & 43 deletions src/lr-wpan/model/lr-wpan-phy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
#include <ns3/abort.h>
#include <ns3/antenna-model.h>
#include <ns3/double.h>
#include <ns3/error-model.h>
#include <ns3/log.h>
#include <ns3/mobility-model.h>
#include <ns3/net-device.h>
#include <ns3/node.h>
#include <ns3/packet-burst.h>
#include <ns3/packet.h>
#include <ns3/pointer.h>
#include <ns3/random-variable-stream.h>
#include <ns3/simulator.h>
#include <ns3/spectrum-channel.h>
Expand Down Expand Up @@ -80,49 +82,58 @@ const LrWpanPhyPpduHeaderSymbolNumber
TypeId
LrWpanPhy::GetTypeId()
{
static TypeId tid = TypeId("ns3::LrWpanPhy")
.SetParent<SpectrumPhy>()
.SetGroupName("LrWpan")
.AddConstructor<LrWpanPhy>()
.AddTraceSource("TrxStateValue",
"The state of the transceiver",
MakeTraceSourceAccessor(&LrWpanPhy::m_trxState),
"ns3::TracedValueCallback::LrWpanPhyEnumeration")
.AddTraceSource("TrxState",
"The state of the transceiver",
MakeTraceSourceAccessor(&LrWpanPhy::m_trxStateLogger),
"ns3::LrWpanPhy::StateTracedCallback")
.AddTraceSource("PhyTxBegin",
"Trace source indicating a packet has "
"begun transmitting over the channel medium",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyTxBeginTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource("PhyTxEnd",
"Trace source indicating a packet has been "
"completely transmitted over the channel.",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyTxEndTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource("PhyTxDrop",
"Trace source indicating a packet has been "
"dropped by the device during transmission",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyTxDropTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource("PhyRxBegin",
"Trace source indicating a packet has begun "
"being received from the channel medium by the device",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyRxBeginTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource("PhyRxEnd",
"Trace source indicating a packet has been "
"completely received from the channel medium "
"by the device",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyRxEndTrace),
"ns3::Packet::SinrTracedCallback")
.AddTraceSource("PhyRxDrop",
"Trace source indicating a packet has been "
"dropped by the device during reception",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyRxDropTrace),
"ns3::Packet::TracedCallback");
static TypeId tid =
TypeId("ns3::LrWpanPhy")
.SetParent<SpectrumPhy>()
.SetGroupName("LrWpan")
.AddConstructor<LrWpanPhy>()
.AddAttribute("PostReceptionErrorModel",
"An optional packet error model can be added to the receive "
"packet process after any propagation-based (SNR-based) error "
"models have been applied. Typically this is used to force "
"specific packet drops, for testing purposes.",
PointerValue(),
MakePointerAccessor(&LrWpanPhy::m_postReceptionErrorModel),
MakePointerChecker<ErrorModel>())
.AddTraceSource("TrxStateValue",
"The state of the transceiver",
MakeTraceSourceAccessor(&LrWpanPhy::m_trxState),
"ns3::TracedValueCallback::LrWpanPhyEnumeration")
.AddTraceSource("TrxState",
"The state of the transceiver",
MakeTraceSourceAccessor(&LrWpanPhy::m_trxStateLogger),
"ns3::LrWpanPhy::StateTracedCallback")
.AddTraceSource("PhyTxBegin",
"Trace source indicating a packet has "
"begun transmitting over the channel medium",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyTxBeginTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource("PhyTxEnd",
"Trace source indicating a packet has been "
"completely transmitted over the channel.",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyTxEndTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource("PhyTxDrop",
"Trace source indicating a packet has been "
"dropped by the device during transmission",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyTxDropTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource("PhyRxBegin",
"Trace source indicating a packet has begun "
"being received from the channel medium by the device",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyRxBeginTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource("PhyRxEnd",
"Trace source indicating a packet has been "
"completely received from the channel medium "
"by the device",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyRxEndTrace),
"ns3::Packet::SinrTracedCallback")
.AddTraceSource("PhyRxDrop",
"Trace source indicating a packet has been "
"dropped by the device during reception",
MakeTraceSourceAccessor(&LrWpanPhy::m_phyRxDropTrace),
"ns3::Packet::TracedCallback");
return tid;
}

Expand Down Expand Up @@ -196,6 +207,7 @@ LrWpanPhy::DoDispose()
m_errorModel = nullptr;
m_currentRxPacket.first = nullptr;
m_currentTxPacket.first = nullptr;
m_postReceptionErrorModel = nullptr;

m_ccaRequest.Cancel();
m_edRequest.Cancel();
Expand Down Expand Up @@ -514,6 +526,13 @@ LrWpanPhy::EndRx(Ptr<SpectrumSignalParameters> par)
Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets().front();
NS_ASSERT(currentPacket);

if (m_postReceptionErrorModel &&
m_postReceptionErrorModel->IsCorrupt(currentPacket->Copy()))
{
NS_LOG_DEBUG("Reception failed due to post-rx error model");
m_currentRxPacket.second = true;
}

// If there is no error model attached to the PHY, we always report the maximum LQI value.
LrWpanLqiTag tag(std::numeric_limits<uint8_t>::max());
currentPacket->PeekPacketTag(tag);
Expand Down Expand Up @@ -1802,4 +1821,11 @@ LrWpanPhy::AssignStreams(int64_t stream)
return 1;
}

void
LrWpanPhy::SetPostReceptionErrorModel(const Ptr<ErrorModel> em)
{
NS_LOG_FUNCTION(this << em);
m_postReceptionErrorModel = em;
}

} // namespace ns3
16 changes: 16 additions & 0 deletions src/lr-wpan/model/lr-wpan-phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SpectrumModel;
class AntennaModel;
class NetDevice;
class UniformRandomVariable;
class ErrorModel;

/**
* \ingroup lr-wpan
Expand Down Expand Up @@ -481,6 +482,19 @@ class LrWpanPhy : public SpectrumPhy
*/
Ptr<LrWpanErrorModel> GetErrorModel() const;

/**
* Attach a receive ErrorModel to the LrWpanPhy.
*
* The LrWpanPhy may optionally include an ErrorModel in
* the packet receive chain. The error model is additive
* to any modulation-based error model based on SNR, and
* is typically used to force specific packet losses or
* for testing purposes.
*
* \param em Pointer to the ErrorModel.
*/
void SetPostReceptionErrorModel(const Ptr<ErrorModel> em);

/**
* Get the duration of the SHR (preamble and SFD) in symbols, depending on
* the currently selected channel.
Expand Down Expand Up @@ -924,6 +938,8 @@ class LrWpanPhy : public SpectrumPhy
* Uniform random variable stream.
*/
Ptr<UniformRandomVariable> m_random;

Ptr<ErrorModel> m_postReceptionErrorModel; //!< Error model for receive packet events
};

} // namespace ns3
Expand Down

0 comments on commit a606815

Please sign in to comment.