diff --git a/CHANGES.md b/CHANGES.md index 585c802d0..34ffee479 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -29,6 +29,7 @@ Changes from ns-3.37 to ns-3.38 * (internet) TCP Westwood model has been removed due to a bug in BW estimation documented in . The TCP Westwood+ model is now named **TcpWestwoodPlus** and can be instantiated like all the other TCP flavors. * (internet) `TcpCubic` attribute `HyStartDetect` changed from `int` to `enum HybridSSDetectionMode`. * (internet-apps) Classes `v4Ping` and `Ping6` will be deprecated and removed in the future, replaced by the new `Ping` class. +* (lr-wpan) Add file `src/lr-wpan/model/lr-wpan-constants.h` with common constants of the LR-WPAN module. ### Changes to build system diff --git a/src/lr-wpan/CMakeLists.txt b/src/lr-wpan/CMakeLists.txt index a890844b1..55b267e60 100644 --- a/src/lr-wpan/CMakeLists.txt +++ b/src/lr-wpan/CMakeLists.txt @@ -17,6 +17,7 @@ build_lib( model/lr-wpan-spectrum-value-helper.cc HEADER_FILES helper/lr-wpan-helper.h + model/lr-wpan-constants.h model/lr-wpan-csmaca.h model/lr-wpan-error-model.h model/lr-wpan-fields.h diff --git a/src/lr-wpan/model/lr-wpan-constants.h b/src/lr-wpan/model/lr-wpan-constants.h new file mode 100644 index 000000000..af5da70e3 --- /dev/null +++ b/src/lr-wpan/model/lr-wpan-constants.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2011 The Boeing Company + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: + * Gary Pei + * kwong yin + * Tom Henderson + * Sascha Alexander Jopen + * Erwan Livolant + * Alberto Gallegos Ramonet + */ + +#ifndef LR_WPAN_CONSTANTS_H +#define LR_WPAN_CONSTANTS_H + +#include + +namespace ns3 +{ +namespace lrwpan +{ + +/** + * \defgroup LrWpanConstants + * \ingroup lr-wpan + * + * Contains common parameters about LR-WPAN that can be reused in multiple files. + * These parameters are defined in the IEEE 802.15.4-2011 standard and adopt the + * same names as in the standard. + * + * @{ + */ + +/** + * The minimum number of octets added by the MAC sublayer to the PSDU. + * See IEEE 802.15.4-2011, section 6.4.1, Table 51. + */ +constexpr uint32_t aMinMPDUOverhead{9}; + +/** + * Length of a superframe slot in symbols. Defaults to 60 symbols in each superframe slot. + * See IEEE 802.15.4-2011, section 6.4.1, Table 51. + */ +constexpr uint32_t aBaseSlotDuration{60}; + +/** + * Number of a superframe slots per superframe. Defaults to 16. + * See IEEE 802.15.4-2011, section 6.4.1, Table 51. + */ +constexpr uint32_t aNumSuperframeSlots{16}; + +/** + * Length of a superframe in symbols. Defaults to aBaseSlotDuration * aNumSuperframeSlots in + * symbols. + * See IEEE 802.15.4-2011, section 6.4.1, Table 51. + */ +constexpr uint32_t aBaseSuperframeDuration{aBaseSlotDuration * aNumSuperframeSlots}; + +/** + * The number of consecutive lost beacons that will cause the MAC sublayer of a receiving device to + * declare a loss of synchronization. + * See IEEE 802.15.4-2011, section 6.4.1, Table 51. + */ +constexpr uint32_t aMaxLostBeacons{4}; + +/** + * The maximum size of an MPDU, in octets, that can be followed by a Short InterFrame Spacing (SIFS) + * period. + * See IEEE 802.15.4-2011, section 6.4.1, Table 51. + */ +constexpr uint32_t aMaxSIFSFrameSize{18}; + +/** + * The maximum packet size accepted by the PHY. + * See Table 22 in section 6.4.1 of IEEE 802.15.4-2006 + */ +constexpr uint32_t aMaxPhyPacketSize{127}; + +/** + * The turnaround time in symbol periods for switching the transceiver from RX to TX or + * vice-versa. + * See Table 22 in section 6.4.1 of IEEE 802.15.4-2006 + */ +constexpr uint32_t aTurnaroundTime{12}; + +/** @} */ + +} // namespace lrwpan +} // namespace ns3 + +#endif // LR_WPAN_CONSTANTS_H diff --git a/src/lr-wpan/model/lr-wpan-csmaca.cc b/src/lr-wpan/model/lr-wpan-csmaca.cc index bafc1db7d..af1190e99 100644 --- a/src/lr-wpan/model/lr-wpan-csmaca.cc +++ b/src/lr-wpan/model/lr-wpan-csmaca.cc @@ -22,6 +22,8 @@ #include "lr-wpan-csmaca.h" +#include "lr-wpan-constants.h" + #include #include #include @@ -424,7 +426,7 @@ LrWpanCsmaCa::CanProceed() else { // time the PHY takes to switch from Rx to Tx and Tx to Rx - transactionSymbols += (m_mac->GetPhy()->aTurnaroundTime * 2); + transactionSymbols += (lrwpan::aTurnaroundTime * 2); } transactionSymbols += m_mac->GetIfsSize(); diff --git a/src/lr-wpan/model/lr-wpan-mac.cc b/src/lr-wpan/model/lr-wpan-mac.cc index 02bcbd82a..734383ed2 100644 --- a/src/lr-wpan/model/lr-wpan-mac.cc +++ b/src/lr-wpan/model/lr-wpan-mac.cc @@ -24,6 +24,7 @@ */ #include "lr-wpan-mac.h" +#include "lr-wpan-constants.h" #include "lr-wpan-csmaca.h" #include "lr-wpan-mac-header.h" #include "lr-wpan-mac-pl-headers.h" @@ -46,51 +47,6 @@ namespace ns3 NS_LOG_COMPONENT_DEFINE("LrWpanMac"); NS_OBJECT_ENSURE_REGISTERED(LrWpanMac); -/** - * \defgroup LrWpanMacSublayerConstants MAC sublayer constants - * \ingroup lr-wpan - * @{ - */ - -/** - * The minimum number of octets added by the MAC sublayer to the PSDU. - * See IEEE 802.15.4-2011, section 6.4.1, Table 51. - */ -constexpr uint32_t aMinMPDUOverhead = 9; - -/** - * Length of a superframe slot in symbols. Defaults to 60 symbols in each superframe slot. - * See IEEE 802.15.4-2011, section 6.4.1, Table 51. - */ -constexpr uint32_t aBaseSlotDuration = 60; - -/** - * Number of a superframe slots per superframe. Defaults to 16. - * See IEEE 802.15.4-2011, section 6.4.1, Table 51. - */ -constexpr uint32_t aNumSuperframeSlots = 16; - -/** - * Length of a superframe in symbols. Defaults to aBaseSlotDuration * aNumSuperframeSlots in - * symbols. See IEEE 802.15.4-2011, section 6.4.1, Table 51. - */ -constexpr uint32_t aBaseSuperframeDuration = aBaseSlotDuration * aNumSuperframeSlots; - -/** - * The number of consecutive lost beacons that will cause the MAC sublayer of a receiving device to - * declare a loss of synchronization. - * See IEEE 802.15.4-2011, section 6.4.1, Table 51. - */ -constexpr uint32_t aMaxLostBeacons = 4; - -/** - * The maximum size of an MPDU, in octets, that can be followed by a Short InterFrame Spacing (SIFS) - * period. See IEEE 802.15.4-2011, section 6.4.1, Table 51. - */ -constexpr uint32_t aMaxSIFSFrameSize = 18; - -/**@}*/ - TypeId LrWpanMac::GetTypeId() { @@ -247,7 +203,7 @@ LrWpanMac::LrWpanMac() m_channelScanIndex = 0; m_maxEnergyLevel = 0; - m_macResponseWaitTime = aBaseSuperframeDuration * 32; + m_macResponseWaitTime = lrwpan::aBaseSuperframeDuration * 32; m_assocRespCmdWaitTime = 960; m_maxTxQueueSize = m_txQueue.max_size(); @@ -393,7 +349,7 @@ LrWpanMac::McpsDataRequest(McpsDataRequestParams params, Ptr p) LrWpanMacHeader macHdr(LrWpanMacHeader::LRWPAN_MAC_DATA, m_macDsn.GetValue()); m_macDsn++; - if (p->GetSize() > LrWpanPhy::aMaxPhyPacketSize - aMinMPDUOverhead) + if (p->GetSize() > lrwpan::aMaxPhyPacketSize - lrwpan::aMinMPDUOverhead) { // Note, this is just testing maximum theoretical frame size per the spec // The frame could still be too large once headers are put on @@ -840,7 +796,8 @@ LrWpanMac::MlmeSyncRequest(MlmeSyncRequestParams params) { m_numLostBeacons = 0; // search for a beacon for a time = incomingSuperframe symbols + 960 symbols - searchSymbols = ((uint64_t)1 << m_incomingBeaconOrder) + 1 * aBaseSuperframeDuration; + searchSymbols = + ((uint64_t)1 << m_incomingBeaconOrder) + 1 * lrwpan::aBaseSuperframeDuration; searchBeaconTime = Seconds((double)searchSymbols / symbolRate); m_beaconTrackingOn = true; m_trackingEvent = @@ -1185,9 +1142,9 @@ LrWpanMac::EndStartRequest() m_fnlCapSlot = 15; m_beaconInterval = - (static_cast(1 << m_macBeaconOrder)) * aBaseSuperframeDuration; - m_superframeDuration = - (static_cast(1 << m_macSuperframeOrder)) * aBaseSuperframeDuration; + (static_cast(1 << m_macBeaconOrder)) * lrwpan::aBaseSuperframeDuration; + m_superframeDuration = (static_cast(1 << m_macSuperframeOrder)) * + lrwpan::aBaseSuperframeDuration; // TODO: change the beacon sending according to the startTime parameter (if not PAN // coordinator) @@ -1460,7 +1417,7 @@ LrWpanMac::BeaconSearchTimeout() { uint64_t symbolRate = (uint64_t)m_phy->GetDataOrSymbolRate(false); // symbols per second - if (m_numLostBeacons > aMaxLostBeacons) + if (m_numLostBeacons > lrwpan::aMaxLostBeacons) { MlmeSyncLossIndicationParams syncLossParams; // syncLossParams.m_logCh = @@ -1478,7 +1435,8 @@ LrWpanMac::BeaconSearchTimeout() // Search for one more beacon uint64_t searchSymbols; Time searchBeaconTime; - searchSymbols = ((uint64_t)1 << m_incomingBeaconOrder) + 1 * aBaseSuperframeDuration; + searchSymbols = + ((uint64_t)1 << m_incomingBeaconOrder) + 1 * lrwpan::aBaseSuperframeDuration; searchBeaconTime = Seconds((double)searchSymbols / symbolRate); m_trackingEvent = Simulator::Schedule(searchBeaconTime, &LrWpanMac::BeaconSearchTimeout, this); @@ -1830,7 +1788,7 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr p, uint8_t lqi) if (acceptFrame && (m_csmaCa->IsSlottedCsmaCa() && m_capEvent.IsRunning())) { Time timeLeftInCap = Simulator::GetDelayLeft(m_capEvent); - uint64_t ackSymbols = m_phy->aTurnaroundTime + m_phy->GetPhySHRDuration() + + uint64_t ackSymbols = lrwpan::aTurnaroundTime + m_phy->GetPhySHRDuration() + ceil(6 * m_phy->GetPhySymbolsPerOctet()); Time ackTime = Seconds((double)ackSymbols / symbolRate); @@ -1980,9 +1938,9 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr p, uint8_t lqi) m_incomingBeaconInterval = (static_cast(1 << m_incomingBeaconOrder)) * - aBaseSuperframeDuration; + lrwpan::aBaseSuperframeDuration; m_incomingSuperframeDuration = - aBaseSuperframeDuration * + lrwpan::aBaseSuperframeDuration * (static_cast(1 << m_incomingSuperframeOrder)); if (incomingSuperframe.IsBattLifeExt()) @@ -2084,7 +2042,7 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr p, uint8_t lqi) searchSymbols = (static_cast(1 << m_incomingBeaconOrder)) + - 1 * aBaseSuperframeDuration; + 1 * lrwpan::aBaseSuperframeDuration; searchBeaconTime = Seconds(static_cast(searchSymbols / symbolRate)); m_trackingEvent = @@ -2552,12 +2510,12 @@ LrWpanMac::EnqueueInd(Ptr p) if (m_macBeaconOrder == 15) { // Non-beacon enabled mode - unit = aBaseSuperframeDuration * m_macTransactionPersistenceTime; + unit = lrwpan::aBaseSuperframeDuration * m_macTransactionPersistenceTime; } else { // Beacon-enabled mode - unit = ((static_cast(1) << m_macBeaconOrder) * aBaseSuperframeDuration) * + unit = ((static_cast(1) << m_macBeaconOrder) * lrwpan::aBaseSuperframeDuration) * m_macTransactionPersistenceTime; } @@ -3104,7 +3062,7 @@ LrWpanMac::PlmeSetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttribu if (status == LrWpanPhyEnumeration::IEEE_802_15_4_PHY_SUCCESS) { uint64_t symbolRate = static_cast(m_phy->GetDataOrSymbolRate(false)); - uint64_t scanDuration = aBaseSuperframeDuration * + uint64_t scanDuration = lrwpan::aBaseSuperframeDuration * ((static_cast(1 << m_scanParams.m_scanDuration)) + 1); Time nextScanTime = Seconds(static_cast(scanDuration / symbolRate)); @@ -3477,7 +3435,7 @@ LrWpanMac::ChangeMacState(LrWpanMacState newState) uint64_t LrWpanMac::GetMacAckWaitDuration() const { - return m_csmaCa->GetUnitBackoffPeriod() + m_phy->aTurnaroundTime + m_phy->GetPhySHRDuration() + + return m_csmaCa->GetUnitBackoffPeriod() + lrwpan::aTurnaroundTime + m_phy->GetPhySHRDuration() + ceil(6 * m_phy->GetPhySymbolsPerOctet()); } @@ -3528,7 +3486,7 @@ LrWpanMac::GetIfsSize() { NS_ASSERT(m_txPkt); - if (m_txPkt->GetSize() <= aMaxSIFSFrameSize) + if (m_txPkt->GetSize() <= lrwpan::aMaxSIFSFrameSize) { return m_macSIFSPeriod; } diff --git a/src/lr-wpan/model/lr-wpan-phy.cc b/src/lr-wpan/model/lr-wpan-phy.cc index 6f7c10019..61b981890 100644 --- a/src/lr-wpan/model/lr-wpan-phy.cc +++ b/src/lr-wpan/model/lr-wpan-phy.cc @@ -20,6 +20,7 @@ */ #include "lr-wpan-phy.h" +#include "lr-wpan-constants.h" #include "lr-wpan-error-model.h" #include "lr-wpan-lqi-tag.h" #include "lr-wpan-net-device.h" @@ -597,7 +598,7 @@ LrWpanPhy::PdDataRequest(const uint32_t psduLength, Ptr p) { NS_LOG_FUNCTION(this << psduLength << p); - if (psduLength > aMaxPhyPacketSize) + if (psduLength > lrwpan::aMaxPhyPacketSize) { if (!m_pdDataConfirmCallback.IsNull()) { @@ -865,7 +866,7 @@ LrWpanPhy::PlmeSetTRXStateRequest(LrWpanPhyEnumeration state) m_trxStatePending = IEEE_802_15_4_PHY_TX_ON; // Delay for turnaround time (BUSY_RX|RX_ON ---> TX_ON) - Time setTime = Seconds((double)aTurnaroundTime / GetDataOrSymbolRate(false)); + Time setTime = Seconds((double)lrwpan::aTurnaroundTime / GetDataOrSymbolRate(false)); m_setTRXState = Simulator::Schedule(setTime, &LrWpanPhy::EndSetTRXState, this); return; } @@ -932,7 +933,7 @@ LrWpanPhy::PlmeSetTRXStateRequest(LrWpanPhyEnumeration state) // even when the transmitter is not busy? (6.9.1) m_trxStatePending = IEEE_802_15_4_PHY_RX_ON; - Time setTime = Seconds((double)aTurnaroundTime / GetDataOrSymbolRate(false)); + Time setTime = Seconds((double)lrwpan::aTurnaroundTime / GetDataOrSymbolRate(false)); m_setTRXState = Simulator::Schedule(setTime, &LrWpanPhy::EndSetTRXState, this); return; } diff --git a/src/lr-wpan/model/lr-wpan-phy.h b/src/lr-wpan/model/lr-wpan-phy.h index 9576016ae..94d6f8942 100644 --- a/src/lr-wpan/model/lr-wpan-phy.h +++ b/src/lr-wpan/model/lr-wpan-phy.h @@ -257,19 +257,6 @@ class LrWpanPhy : public SpectrumPhy */ static TypeId GetTypeId(); - /** - * The maximum packet size accepted by the PHY. - * See Table 22 in section 6.4.1 of IEEE 802.15.4-2006 - */ - static const uint32_t aMaxPhyPacketSize; - - /** - * The turnaround time for switching the transceiver from RX to TX or vice - * versa. - * See Table 22 in section 6.4.1 of IEEE 802.15.4-2006 - */ - static const uint32_t aTurnaroundTime; - /** * Default constructor. */