lr-wpan: Fixes PHY reaction after a TX during BUSY_RX

This commit is contained in:
Alberto Gallegos Ramonet
2022-09-30 13:32:58 +09:00
committed by Alberto Gallegos
parent 0b2e26f3b7
commit fdda633d6d
6 changed files with 88 additions and 60 deletions

View File

@@ -181,7 +181,6 @@ LrWpanCsmaCa::GetUnitBackoffPeriod (void) const
return m_aUnitBackoffPeriod;
}
Time
LrWpanCsmaCa::GetTimeToNextSlot (void) const
{
@@ -239,7 +238,6 @@ LrWpanCsmaCa::GetTimeToNextSlot (void) const
}
void
LrWpanCsmaCa::Start ()
{
@@ -290,8 +288,6 @@ LrWpanCsmaCa::Cancel ()
m_mac->GetPhy ()->CcaCancel ();
}
void
LrWpanCsmaCa::RandomBackoffDelay ()
{
@@ -336,7 +332,7 @@ LrWpanCsmaCa::RandomBackoffDelay ()
<< timeLeftInCap.As (Time::S) << ")");
if (randomBackoff > timeLeftInCap)
if (randomBackoff >= timeLeftInCap)
{
uint64_t usedBackoffs = (double)(timeLeftInCap.GetSeconds () * symbolRate) / m_aUnitBackoffPeriod;
m_randomBackoffPeriodsLeft -= usedBackoffs;
@@ -351,7 +347,6 @@ LrWpanCsmaCa::RandomBackoffDelay ()
}
}
Time
LrWpanCsmaCa::GetTimeLeftInCap ()
{
@@ -386,7 +381,6 @@ LrWpanCsmaCa::GetTimeLeftInCap ()
return (endCapTime - currentTime);
}
void
LrWpanCsmaCa::CanProceed ()
{
@@ -547,7 +541,6 @@ LrWpanCsmaCa::PlmeCcaConfirm (LrWpanPhyEnumeration status)
}
}
void
LrWpanCsmaCa::SetLrWpanMacTransCostCallback (LrWpanMacTransCostCallback c)
{
@@ -555,7 +548,6 @@ LrWpanCsmaCa::SetLrWpanMacTransCostCallback (LrWpanMacTransCostCallback c)
m_lrWpanMacTransCostCallback = c;
}
void
LrWpanCsmaCa::SetLrWpanMacStateCallback (LrWpanMacStateCallback c)
{
@@ -569,7 +561,6 @@ LrWpanCsmaCa::SetBatteryLifeExtension (bool batteryLifeExtension)
m_macBattLifeExt = batteryLifeExtension;
}
int64_t
LrWpanCsmaCa::AssignStreams (int64_t stream)
{

View File

@@ -223,20 +223,35 @@ LrWpanMac::DoDispose ()
if (m_csmaCa)
{
m_csmaCa->Dispose ();
m_csmaCa = 0;
m_csmaCa = nullptr;
}
m_txPkt = nullptr;
for (uint32_t i = 0; i < m_txQueue.size (); i++)
{
m_txQueue[i]->txQPkt = 0;
m_txQueue[i]->txQPkt = nullptr;
delete m_txQueue[i];
}
m_txQueue.clear ();
m_phy = 0;
m_mcpsDataIndicationCallback = MakeNullCallback< void, McpsDataIndicationParams, Ptr<Packet> > ();
m_mlmeAssociateIndicationCallback = MakeNullCallback <void, MlmeAssociateIndicationParams> ();
m_mlmeCommStatusIndicationCallback = MakeNullCallback <void, MlmeCommStatusIndicationParams> ();
m_mcpsDataConfirmCallback = MakeNullCallback< void, McpsDataConfirmParams > ();
for (uint32_t i = 0; i < m_indTxQueue.size (); i++)
{
m_indTxQueue[i]->txQPkt = nullptr;
m_indTxQueue[i].release ();
}
m_indTxQueue.clear ();
m_phy = nullptr;
m_mcpsDataConfirmCallback = MakeNullCallback<void, McpsDataConfirmParams> ();
m_mcpsDataIndicationCallback = MakeNullCallback<void, McpsDataIndicationParams, Ptr<Packet> > ();
m_mlmeStartConfirmCallback = MakeNullCallback<void, MlmeStartConfirmParams> ();
m_mlmeBeaconNotifyIndicationCallback = MakeNullCallback<void, MlmeBeaconNotifyIndicationParams, Ptr<Packet> > ();
m_mlmeSyncLossIndicationCallback = MakeNullCallback<void, MlmeSyncLossIndicationParams> ();
m_mlmePollConfirmCallback = MakeNullCallback<void, MlmePollConfirmParams> ();
m_mlmeScanConfirmCallback = MakeNullCallback<void, MlmeScanConfirmParams> ();
m_mlmeAssociateConfirmCallback = MakeNullCallback<void, MlmeAssociateConfirmParams> ();
m_mlmeAssociateIndicationCallback = MakeNullCallback<void, MlmeAssociateIndicationParams> ();
m_mlmeCommStatusIndicationCallback = MakeNullCallback<void, MlmeCommStatusIndicationParams> ();
m_beaconEvent.Cancel ();
@@ -271,14 +286,14 @@ LrWpanMac::SetRxOnWhenIdle (bool rxOnWhenIdle)
void
LrWpanMac::SetShortAddress (Mac16Address address)
{
//NS_LOG_FUNCTION (this << address);
NS_LOG_FUNCTION (this << address);
m_shortAddress = address;
}
void
LrWpanMac::SetExtendedAddress (Mac64Address address)
{
//NS_LOG_FUNCTION (this << address);
NS_LOG_FUNCTION (this << address);
m_selfExt = address;
}
@@ -1039,7 +1054,7 @@ LrWpanMac::SendAssocResponseCommand (Ptr<Packet> rxDataReqPkt)
{
TxQueueElement *txQElement = new TxQueueElement;
txQElement->txQPkt = indTxQElement->txQPkt;
m_txQueue.push_back (txQElement);
m_txQueue.emplace_back (txQElement);
}
else
{
@@ -2448,11 +2463,12 @@ LrWpanMac::DequeueInd (Mac64Address dst, IndTxQueueElement * entry)
{
PurgeInd ();
for (uint32_t i = 0; i < m_indTxQueue.size (); i++)
for (auto iter = m_indTxQueue.begin (); iter != m_indTxQueue.end (); iter ++)
{
if (m_indTxQueue[i]->dstExtAddress == dst)
if ((*iter)->dstExtAddress == dst)
{
*entry = *m_indTxQueue[i];
*entry = **iter;
m_indTxQueue.erase (iter);
return true;
}
}

View File

@@ -1875,7 +1875,7 @@ private:
std::deque<TxQueueElement*> m_txQueue;
/**
* The indirect transmit queue used by the MAC pending messages.
* The indirect transmit queue used by the MAC pending messages (a.k.a. The pending transaction list).
*/
std::deque<std::unique_ptr <IndTxQueueElement> > m_indTxQueue;

View File

@@ -143,7 +143,7 @@ LrWpanPhy::LrWpanPhy (void)
m_random->SetAttribute ("Min", DoubleValue (0.0));
m_random->SetAttribute ("Max", DoubleValue (1.0));
m_isRxCanceled = false;
ChangeTrxState (IEEE_802_15_4_PHY_TRX_OFF);
}
@@ -160,13 +160,23 @@ LrWpanPhy::DoDispose (void)
m_trxState = IEEE_802_15_4_PHY_TRX_OFF;
m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
m_mobility = 0;
m_device = 0;
m_channel = 0;
m_txPsd = 0;
m_noise = 0;
m_signal = 0;
m_errorModel = 0;
m_mobility = nullptr;
m_device = nullptr;
m_channel = nullptr;
m_antenna = nullptr;
m_txPsd = nullptr;
m_noise = nullptr;
m_signal = nullptr;
m_errorModel = nullptr;
m_currentRxPacket.first = nullptr;
m_currentTxPacket.first = nullptr;
m_ccaRequest.Cancel ();
m_edRequest.Cancel ();
m_setTRXState.Cancel ();
m_pdDataRequest.Cancel ();
m_random = nullptr;
m_pdDataIndicationCallback = MakeNullCallback< void, uint32_t, Ptr<Packet>, uint8_t > ();
m_pdDataConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
m_plmeCcaConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
@@ -258,7 +268,6 @@ void
LrWpanPhy::StartRx (Ptr<SpectrumSignalParameters> spectrumRxParams)
{
NS_LOG_FUNCTION (this << spectrumRxParams);
LrWpanSpectrumValueHelper psdHelper;
if (!m_edRequest.IsExpired ())
{
@@ -285,7 +294,7 @@ LrWpanPhy::StartRx (Ptr<SpectrumSignalParameters> spectrumRxParams)
}
}
m_rxEvent = Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
return;
}
@@ -371,7 +380,7 @@ LrWpanPhy::StartRx (Ptr<SpectrumSignalParameters> spectrumRxParams)
// Always call EndRx to update the interference.
// We keep track of this event, and if necessary cancel this event when a TX of a packet.
m_rxEvent = Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
}
void
@@ -477,25 +486,36 @@ LrWpanPhy::EndRx (Ptr<SpectrumSignalParameters> par)
Ptr<LrWpanSpectrumSignalParameters> none = 0;
m_currentRxPacket = std::make_pair (none, true);
// We may be waiting to apply a pending state change.
if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE)
if (!m_isRxCanceled)
{
// Only change the state immediately, if the transceiver is not already
// switching the state.
if (!m_setTRXState.IsRunning ())
// We may be waiting to apply a pending state change.
if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE)
{
NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
ChangeTrxState (m_trxStatePending);
m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
// Only change the state immediately, if the transceiver is not already
// switching the state.
if (!m_setTRXState.IsRunning ())
{
m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_SUCCESS);
NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
ChangeTrxState (m_trxStatePending);
m_trxStatePending = IEEE_802_15_4_PHY_IDLE;
if (!m_plmeSetTRXStateConfirmCallback.IsNull ())
{
m_plmeSetTRXStateConfirmCallback (IEEE_802_15_4_PHY_SUCCESS);
}
}
}
else
{
ChangeTrxState (IEEE_802_15_4_PHY_RX_ON);
}
}
else
{
ChangeTrxState (IEEE_802_15_4_PHY_RX_ON);
// A TX event was forced during the reception of the frame.
// There is no need to change the PHY state after handling the signal,
// because the Forced TX already changed the PHY state.
// Return flag to default state
m_isRxCanceled = false;
}
}
}
@@ -756,11 +776,12 @@ LrWpanPhy::PlmeSetTRXStateRequest (LrWpanPhyEnumeration state)
{
if (m_currentRxPacket.first)
{
//terminate reception if needed
//incomplete reception -- force packet discard
// TX_ON is being forced during a reception (For example, when a ACK or Beacon is issued)
// The current RX frame is marked as incomplete and the reception as canceled
// EndRx () will handle the rest accordingly
NS_LOG_DEBUG ("force TX_ON, terminate reception");
m_currentRxPacket.second = true;
m_rxEvent.Cancel();
m_isRxCanceled = true;
}
// If CCA is in progress, cancel CCA and return BUSY.
@@ -775,7 +796,7 @@ LrWpanPhy::PlmeSetTRXStateRequest (LrWpanPhyEnumeration state)
m_trxStatePending = IEEE_802_15_4_PHY_TX_ON;
// Delay for turnaround time
// Delay for turnaround time (BUSY_RX|RX_ON ---> TX_ON)
Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
m_setTRXState = Simulator::Schedule (setTime, &LrWpanPhy::EndSetTRXState, this);
return;
@@ -811,11 +832,12 @@ LrWpanPhy::PlmeSetTRXStateRequest (LrWpanPhyEnumeration state)
{
NS_LOG_DEBUG ("force TRX_OFF, SUCCESS");
if (m_currentRxPacket.first)
{ //terminate reception if needed
//incomplete reception -- force packet discard
{
// Terminate reception
// Mark the packet as incomplete and reception as canceled.
NS_LOG_DEBUG ("force TRX_OFF, terminate reception");
m_currentRxPacket.second = true;
m_rxEvent.Cancel();
m_isRxCanceled = true;
}
if (m_trxState == IEEE_802_15_4_PHY_BUSY_TX)
{

View File

@@ -863,6 +863,12 @@ private:
*/
double m_rxSensitivity;
/**
* Indicates if the reception of frame has been canceled.
*/
bool m_isRxCanceled;
/**
* The accumulated signals currently received by the transceiver, including
* the signal of a possibly received packet, as well as all signals
@@ -911,13 +917,6 @@ private:
*/
EventId m_pdDataRequest;
/**
* Scheduler event for a currently running data reception. It makes possible to
* cancel the reception of a packet in case a packet with higher priority needs to
* be transmitted (i.e. Beacon or ACK ).
*/
EventId m_rxEvent;
/**
* Uniform random variable stream.
*/