Skip to content

Commit

Permalink
lr-wpan: DoDispose SIGSEGV and beacon fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Gallegos Ramonet committed Dec 11, 2023
1 parent fc294e9 commit 3f26052
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Changes from ns-3.40 to ns-3-dev
* (antenna) `GetNumberOfElements` is renamed to `GetNumElems` for the sake of simplifying the long lines of code that use complex mathematical expressions.
* (spectrum) `PhasedArraySpectrumPropagationLossModel::CalcRxPowerSpectralDensity` return type is changed from `Ptr<SpectrumValue>` to `Ptr<SpectrumSignalParameters>` to support MIMO, because when multiple transmit and receive antenna ports are present, it is not enough to have a single PSD (represented by `Ptr<SpectrumValue>`) but also the 3D channel matrix is needed per receive and transmit antenna port. Notice that `CalcRxPowerSpectralDensity` is typically called from within `MultiModelSpectrumChannel`, but if some external ns-3 module is calling directly this function, it can still access to its original return value through `Ptr<SpectrumSignalParameters>` which contains `Ptr<SpectrumValue>`.
* (wifi) The default value for `WifiRemoteStationManager::RtsCtsThreshold` has been increased from 65535 to 4692480.
* (lr-wpan) Add the capability to see the enum values of the MAC transition states in log prints for easier debugging.

### Changes to build system

Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Release 3-dev
- (lr-wpan) !1673 - Fixes PHY BUSY_RX -> RX_ON operation
- (wifi) - Fix agreement not always properly torn down when Block Ack inactivity timeout is elapsed
- (wifi) - Stop A-MSDU aggregation when an A-MSDU is found in the queue
- (lr-wpan) !1769 - `DoDispose` SIGSEGV and beacon fixes

Release 3.40
------------
Expand Down
98 changes: 71 additions & 27 deletions src/lr-wpan/model/lr-wpan-mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,45 @@ namespace ns3
NS_LOG_COMPONENT_DEFINE("LrWpanMac");
NS_OBJECT_ENSURE_REGISTERED(LrWpanMac);

std::ostream&
operator<<(std::ostream& os, const LrWpanMacState& state)
{
switch (state)
{
case LrWpanMacState::MAC_IDLE:
os << "MAC IDLE";
break;
case LrWpanMacState::MAC_CSMA:
os << "CSMA";
break;
case LrWpanMacState::MAC_SENDING:
os << "SENDING";
break;
case LrWpanMacState::MAC_ACK_PENDING:
os << "ACK PENDING";
break;
case LrWpanMacState::CHANNEL_ACCESS_FAILURE:
os << "CHANNEL_ACCESS_FAILURE";
break;
case LrWpanMacState::CHANNEL_IDLE:
os << "CHANNEL IDLE";
break;
case LrWpanMacState::SET_PHY_TX_ON:
os << "SET PHY to TX ON";
break;
case LrWpanMacState::MAC_GTS:
os << "MAC GTS PERIOD";
break;
case LrWpanMacState::MAC_INACTIVE:
os << "SUPERFRAME INACTIVE PERIOD";
break;
case LrWpanMacState::MAC_CSMA_DEFERRED:
os << "CSMA DEFERRED TO NEXT PERIOD";
break;
}
return os;
};

TypeId
LrWpanMac::GetTypeId()
{
Expand Down Expand Up @@ -254,16 +293,12 @@ LrWpanMac::DoDispose()
for (uint32_t i = 0; i < m_txQueue.size(); i++)
{
m_txQueue[i]->txQPkt = nullptr;
m_txQueue[i]->txQMsduHandle = 0;
}
m_txQueue.clear();

for (uint32_t i = 0; i < m_indTxQueue.size(); i++)
{
m_indTxQueue[i]->txQPkt = nullptr;
m_indTxQueue[i]->seqNum = 0;
m_indTxQueue[i]->dstExtAddress = nullptr;
m_indTxQueue[i]->dstShortAddress = nullptr;
}
m_indTxQueue.clear();

Expand Down Expand Up @@ -2119,35 +2154,44 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
m_incomingSuperframeOrder = incomingSuperframe.GetFrameOrder();
m_incomingFnlCapSlot = incomingSuperframe.GetFinalCapSlot();

m_incomingBeaconInterval =
(static_cast<uint32_t>(1 << m_incomingBeaconOrder)) *
lrwpan::aBaseSuperframeDuration;
m_incomingSuperframeDuration =
lrwpan::aBaseSuperframeDuration *
(static_cast<uint32_t>(1 << m_incomingSuperframeOrder));

if (incomingSuperframe.IsBattLifeExt())
if (m_incomingBeaconOrder < 15)
{
m_csmaCa->SetBatteryLifeExtension(true);
// Start Beacon-enabled mode
m_csmaCa->SetSlottedCsmaCa();
m_incomingBeaconInterval =
(static_cast<uint32_t>(1 << m_incomingBeaconOrder)) *
lrwpan::aBaseSuperframeDuration;
m_incomingSuperframeDuration =
lrwpan::aBaseSuperframeDuration *
(static_cast<uint32_t>(1 << m_incomingSuperframeOrder));

if (incomingSuperframe.IsBattLifeExt())
{
m_csmaCa->SetBatteryLifeExtension(true);
}
else
{
m_csmaCa->SetBatteryLifeExtension(false);
}

// TODO: get Incoming frame GTS Fields here

// Begin CAP on the current device using info from
// the Incoming superframe
NS_LOG_DEBUG("Incoming superframe Active Portion "
<< "(Beacon + CAP + CFP): " << m_incomingSuperframeDuration
<< " symbols");

m_incCapEvent = Simulator::ScheduleNow(&LrWpanMac::StartCAP,
this,
SuperframeType::INCOMING);
}
else
{
m_csmaCa->SetBatteryLifeExtension(false);
// Start non-beacon enabled mode
m_csmaCa->SetUnSlottedCsmaCa();
}

if (m_incomingBeaconOrder < 15 && !m_csmaCa->IsSlottedCsmaCa())
{
m_csmaCa->SetSlottedCsmaCa();
}

// TODO: get Incoming frame GTS Fields here

// Begin CAP on the current device using info from the Incoming superframe
NS_LOG_DEBUG("Incoming superframe Active Portion (Beacon + CAP + CFP): "
<< m_incomingSuperframeDuration << " symbols");
m_incCapEvent = Simulator::ScheduleNow(&LrWpanMac::StartCAP,
this,
SuperframeType::INCOMING);
m_setMacState =
Simulator::ScheduleNow(&LrWpanMac::SetLrWpanMacState, this, MAC_IDLE);
}
Expand Down
9 changes: 9 additions & 0 deletions src/lr-wpan/model/lr-wpan-mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ enum LrWpanMacState
MAC_CSMA_DEFERRED //!< MAC_CSMA_DEFERRED
};

/**
* Overloaded operator to print the value of a LrWpanMacState.
*
* \param os The output stream
* \param state The text value of the PHY state
* \return The output stream with text value of the MAC state
*/
std::ostream& operator<<(std::ostream& os, const LrWpanMacState& state);

/**
* \ingroup lr-wpan
*
Expand Down

0 comments on commit 3f26052

Please sign in to comment.