# HG changeset patch # User Tommaso Pecorella # Date 1510445804 -3600 # Parent 182e6ced7e39b0b2284728ca2748d6b092521a81 Split MAC in abstract and concrete classes diff --git a/src/lr-wpan/helper/lr-wpan-helper.cc b/src/lr-wpan/helper/lr-wpan-helper.cc --- a/src/lr-wpan/helper/lr-wpan-helper.cc +++ b/src/lr-wpan/helper/lr-wpan-helper.cc @@ -106,6 +106,7 @@ LogComponentEnable ("LrWpanErrorModel", LOG_LEVEL_ALL); LogComponentEnable ("LrWpanInterferenceHelper", LOG_LEVEL_ALL); LogComponentEnable ("LrWpanMac", LOG_LEVEL_ALL); + LogComponentEnable ("LrWpanNullMac", LOG_LEVEL_ALL); LogComponentEnable ("LrWpanNetDevice", LOG_LEVEL_ALL); LogComponentEnable ("LrWpanPhy", LOG_LEVEL_ALL); LogComponentEnable ("LrWpanSpectrumSignalParameters", LOG_LEVEL_ALL); diff --git a/src/lr-wpan/model/lr-wpan-mac.cc b/src/lr-wpan/model/lr-wpan-mac.cc --- a/src/lr-wpan/model/lr-wpan-mac.cc +++ b/src/lr-wpan/model/lr-wpan-mac.cc @@ -52,7 +52,6 @@ static TypeId tid = TypeId ("ns3::LrWpanMac") .SetParent () .SetGroupName ("LrWpan") - .AddConstructor () .AddAttribute ("PanId", "16-bit identifier of the associated PAN", UintegerValue (), MakeUintegerAccessor (&LrWpanMac::m_macPanId), @@ -929,66 +928,6 @@ NS_LOG_FUNCTION (this << status << id); } -void -LrWpanMac::SetLrWpanMacState (LrWpanMacState macState) -{ - NS_LOG_FUNCTION (this << "mac state = " << macState); - - McpsDataConfirmParams confirmParams; - - if (macState == MAC_IDLE) - { - ChangeMacState (MAC_IDLE); - - if (m_macRxOnWhenIdle) - { - m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON); - } - else - { - m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF); - } - - CheckQueue (); - } - else if (macState == MAC_ACK_PENDING) - { - ChangeMacState (MAC_ACK_PENDING); - m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON); - } - else if (macState == MAC_CSMA) - { - NS_ASSERT (m_lrWpanMacState == MAC_IDLE || m_lrWpanMacState == MAC_ACK_PENDING); - - ChangeMacState (MAC_CSMA); - m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON); - } - else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_IDLE) - { - // Channel is idle, set transmitter to TX_ON - ChangeMacState (MAC_SENDING); - m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON); - } - else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_ACCESS_FAILURE) - { - NS_ASSERT (m_txPkt); - - // cannot find a clear channel, drop the current packet. - NS_LOG_DEBUG ( this << " cannot find clear channel"); - confirmParams.m_msduHandle = m_txQueue.front ()->txQMsduHandle; - confirmParams.m_status = IEEE_802_15_4_CHANNEL_ACCESS_FAILURE; - m_macTxDropTrace (m_txPkt); - if (!m_mcpsDataConfirmCallback.IsNull ()) - { - m_mcpsDataConfirmCallback (confirmParams); - } - // remove the copy of the packet that was just sent - RemoveFirstTxQElement (); - - ChangeMacState (MAC_IDLE); - } -} - LrWpanAssociationStatus LrWpanMac::GetAssociationStatus (void) const { diff --git a/src/lr-wpan/model/lr-wpan-mac.h b/src/lr-wpan/model/lr-wpan-mac.h --- a/src/lr-wpan/model/lr-wpan-mac.h +++ b/src/lr-wpan/model/lr-wpan-mac.h @@ -243,14 +243,14 @@ * * \return true, if the receiver is enabled during idle periods, false otherwise */ - bool GetRxOnWhenIdle (void); + virtual bool GetRxOnWhenIdle (void); /** * Set if the receiver should be enabled when the MAC is idle. * * \param rxOnWhenIdle set to true to enable the receiver during idle periods */ - void SetRxOnWhenIdle (bool rxOnWhenIdle); + virtual void SetRxOnWhenIdle (bool rxOnWhenIdle); // XXX these setters will become obsolete if we use the attribute system /** @@ -413,7 +413,7 @@ * * \param macState indicate BUSY oder IDLE channel condition */ - void SetLrWpanMacState (LrWpanMacState macState); + virtual void SetLrWpanMacState (LrWpanMacState macState) = 0; /** * Get the current association status. @@ -429,56 +429,6 @@ */ void SetAssociationStatus (LrWpanAssociationStatus status); - //MAC sublayer constants - /** - * Length of a superframe slot in symbols. Defaults to 60 symbols in each - * superframe slot. - * See IEEE 802.15.4-2006, section 7.4.1, Table 85. - */ - uint64_t m_aBaseSlotDuration; - - /** - * Number of a superframe slots per superframe. Defaults to 16. - * See IEEE 802.15.4-2006, section 7.4.1, Table 85. - */ - uint64_t m_aNumSuperframeSlots; - - /** - * Length of a superframe in symbols. Defaults to - * aBaseSlotDuration * aNumSuperframeSlots in symbols. - * See IEEE 802.15.4-2006, section 7.4.1, Table 85. - */ - uint64_t m_aBaseSuperframeDuration; - - //MAC PIB attributes - /** - * The time that the device transmitted its last beacon frame, in symbol - * periods. Only 24 bits used. - * See IEEE 802.15.4-2006, section 7.4.2, Table 86. - */ - uint64_t m_macBeaconTxTime; - - /** - * Symbol boundary is same as m_macBeaconTxTime. - * See IEEE 802.15.4-2006, section 7.4.2, Table 86. - */ - uint64_t m_macSyncSymbolOffset; - - /** - * Specification of how often the coordinator transmits its beacon. - * 0 - 15 with 15 means no beacons are being sent. - * See IEEE 802.15.4-2006, section 7.4.2, Table 86. - */ - uint64_t m_macBeaconOrder; - - /** - * The length of the active portion of the outgoing superframe, including the - * beacon frame. - * 0 - 15 with 15 means the superframe will not be active after the beacon. - * See IEEE 802.15.4-2006, section 7.4.2, Table 86. - */ - uint64_t m_macSuperframeOrder; - /** * Indicates if MAC sublayer is in receive all mode. True mean accept all * frames from PHY. @@ -560,7 +510,6 @@ virtual void DoInitialize (void); virtual void DoDispose (void); -private: /** * Helper structure for managing transmission queue elements. */ diff --git a/src/lr-wpan/model/lr-wpan-net-device.cc b/src/lr-wpan/model/lr-wpan-net-device.cc --- a/src/lr-wpan/model/lr-wpan-net-device.cc +++ b/src/lr-wpan/model/lr-wpan-net-device.cc @@ -32,6 +32,7 @@ #include #include #include +#include namespace ns3 { @@ -73,7 +74,7 @@ : m_configComplete (false) { NS_LOG_FUNCTION (this); - m_mac = CreateObject (); + m_mac = CreateObject (); m_phy = CreateObject (); m_csmaca = CreateObject (); CompleteConfig (); @@ -146,7 +147,7 @@ m_phy->SetPlmeSetAttributeConfirmCallback (MakeCallback (&LrWpanMac::PlmeSetAttributeConfirm, m_mac)); m_csmaca->SetLrWpanMacStateCallback (MakeCallback (&LrWpanMac::SetLrWpanMacState, m_mac)); - m_phy->SetPlmeCcaConfirmCallback (MakeCallback (&LrWpanCsmaCa::PlmeCcaConfirm, m_csmaca)); + m_phy->SetPlmeCcaConfirmCallback (MakeCallback (&LrWpanMac::PlmeCcaConfirm, m_mac)); m_configComplete = true; } @@ -203,6 +204,7 @@ NS_LOG_FUNCTION (this); return m_csmaca; } + void LrWpanNetDevice::SetIfIndex (const uint32_t index) { diff --git a/src/lr-wpan/model/lr-wpan-nullmac.cc b/src/lr-wpan/model/lr-wpan-nullmac.cc new file mode 100644 --- /dev/null +++ b/src/lr-wpan/model/lr-wpan-nullmac.cc @@ -0,0 +1,191 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ +#include "lr-wpan-nullmac.h" +#include "lr-wpan-csmaca.h" +#include "lr-wpan-mac-header.h" +#include "lr-wpan-mac-trailer.h" +#include +#include +#include +#include +#include +#include +#include + +#undef NS_LOG_APPEND_CONTEXT +#define NS_LOG_APPEND_CONTEXT \ + std::clog << "[address " << m_shortAddress << "] "; + +namespace ns3 { + +NS_LOG_COMPONENT_DEFINE ("LrWpanNullMac"); + +NS_OBJECT_ENSURE_REGISTERED (LrWpanNullMac); + +TypeId +LrWpanNullMac::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::LrWpanNullMac") + .SetParent () + .SetGroupName ("LrWpan") + .AddConstructor () + ; + return tid; +} + +LrWpanNullMac::LrWpanNullMac () +{ + // First set the state to a known value, call ChangeMacState to fire trace source. + m_lrWpanMacState = MAC_IDLE; + ChangeMacState (MAC_IDLE); + + m_macRxOnWhenIdle = true; + m_macPanId = 0; + m_associationStatus = ASSOCIATED; + m_selfExt = Mac64Address::Allocate (); + m_macPromiscuousMode = false; + m_macMaxFrameRetries = 3; + m_retransmission = 0; + m_numCsmacaRetry = 0; + m_txPkt = 0; + + Ptr uniformVar = CreateObject (); + uniformVar->SetAttribute ("Min", DoubleValue (0.0)); + uniformVar->SetAttribute ("Max", DoubleValue (255.0)); + m_macDsn = SequenceNumber8 (uniformVar->GetValue ()); + m_shortAddress = Mac16Address ("00:00"); +} + +LrWpanNullMac::~LrWpanNullMac () +{ +} + +void +LrWpanNullMac::DoInitialize () +{ + if (m_macRxOnWhenIdle) + { + m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON); + } + else + { + m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF); + } + + LrWpanMac::DoInitialize (); +} + +void +LrWpanNullMac::DoDispose () +{ + LrWpanMac::DoDispose (); +} + +bool +LrWpanNullMac::GetRxOnWhenIdle () +{ + return m_macRxOnWhenIdle; +} + +void +LrWpanNullMac::SetRxOnWhenIdle (bool rxOnWhenIdle) +{ + NS_LOG_FUNCTION (this << rxOnWhenIdle); + m_macRxOnWhenIdle = rxOnWhenIdle; + + if (m_lrWpanMacState == MAC_IDLE) + { + if (m_macRxOnWhenIdle) + { + m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON); + } + else + { + m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF); + } + } +} + +void +LrWpanNullMac::SetLrWpanMacState (LrWpanMacState macState) +{ + NS_LOG_FUNCTION (this << "mac state = " << macState); + + McpsDataConfirmParams confirmParams; + + if (macState == MAC_IDLE) + { + ChangeMacState (MAC_IDLE); + + if (m_macRxOnWhenIdle) + { + m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON); + } + else + { + m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF); + } + + CheckQueue (); + } + else if (macState == MAC_ACK_PENDING) + { + ChangeMacState (MAC_ACK_PENDING); + m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON); + } + else if (macState == MAC_CSMA) + { + NS_ASSERT (m_lrWpanMacState == MAC_IDLE || m_lrWpanMacState == MAC_ACK_PENDING); + + ChangeMacState (MAC_CSMA); + m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON); + } + else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_IDLE) + { + // Channel is idle, set transmitter to TX_ON + ChangeMacState (MAC_SENDING); + m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON); + } + else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_ACCESS_FAILURE) + { + NS_ASSERT (m_txPkt); + + // cannot find a clear channel, drop the current packet. + NS_LOG_DEBUG ( this << " cannot find clear channel"); + confirmParams.m_msduHandle = m_txQueue.front ()->txQMsduHandle; + confirmParams.m_status = IEEE_802_15_4_CHANNEL_ACCESS_FAILURE; + m_macTxDropTrace (m_txPkt); + if (!m_mcpsDataConfirmCallback.IsNull ()) + { + m_mcpsDataConfirmCallback (confirmParams); + } + // remove the copy of the packet that was just sent + RemoveFirstTxQElement (); + + ChangeMacState (MAC_IDLE); + } +} + +} // namespace ns3 diff --git a/src/lr-wpan/model/lr-wpan-nullmac.h b/src/lr-wpan/model/lr-wpan-nullmac.h new file mode 100644 --- /dev/null +++ b/src/lr-wpan/model/lr-wpan-nullmac.h @@ -0,0 +1,149 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ +#ifndef LR_WPAN_NULLMAC_H +#define LR_WPAN_NULLMAC_H + +#include "lr-wpan-mac.h" + + +namespace ns3 { + +/** + * \defgroup lr-wpan LR-WPAN models + * + * This section documents the API of the IEEE 802.15.4-related models. For a generic functional description, please refer to the ns-3 manual. + */ + +/** + * \ingroup lr-wpan + * + * Class that implements the LR-WPAN Mac state machine + */ +class LrWpanNullMac : public LrWpanMac +{ +public: + /** + * Get the type ID. + * + * \return the object TypeId + */ + static TypeId GetTypeId (void); + + /** + * Default constructor. + */ + LrWpanNullMac (void); + virtual ~LrWpanNullMac (void); + + /** + * Check if the receiver will be enabled when the MAC is idle. + * + * \return true, if the receiver is enabled during idle periods, false otherwise + */ + virtual bool GetRxOnWhenIdle (void); + + /** + * Set if the receiver should be enabled when the MAC is idle. + * + * \param rxOnWhenIdle set to true to enable the receiver during idle periods + */ + virtual void SetRxOnWhenIdle (bool rxOnWhenIdle); + + /** + * CSMA-CA algorithm calls back the MAC after executing channel assessment. + * + * \param macState indicate BUSY oder IDLE channel condition + */ + virtual void SetLrWpanMacState (LrWpanMacState macState); + + //MAC sublayer constants + /** + * Length of a superframe slot in symbols. Defaults to 60 symbols in each + * superframe slot. + * See IEEE 802.15.4-2006, section 7.4.1, Table 85. + */ + uint64_t m_aBaseSlotDuration; + + /** + * Number of a superframe slots per superframe. Defaults to 16. + * See IEEE 802.15.4-2006, section 7.4.1, Table 85. + */ + uint64_t m_aNumSuperframeSlots; + + /** + * Length of a superframe in symbols. Defaults to + * aBaseSlotDuration * aNumSuperframeSlots in symbols. + * See IEEE 802.15.4-2006, section 7.4.1, Table 85. + */ + uint64_t m_aBaseSuperframeDuration; + + //MAC PIB attributes + /** + * The time that the device transmitted its last beacon frame, in symbol + * periods. Only 24 bits used. + * See IEEE 802.15.4-2006, section 7.4.2, Table 86. + */ + uint64_t m_macBeaconTxTime; + + /** + * Symbol boundary is same as m_macBeaconTxTime. + * See IEEE 802.15.4-2006, section 7.4.2, Table 86. + */ + uint64_t m_macSyncSymbolOffset; + + /** + * Specification of how often the coordinator transmits its beacon. + * 0 - 15 with 15 means no beacons are being sent. + * See IEEE 802.15.4-2006, section 7.4.2, Table 86. + */ + uint64_t m_macBeaconOrder; + + /** + * The length of the active portion of the outgoing superframe, including the + * beacon frame. + * 0 - 15 with 15 means the superframe will not be active after the beacon. + * See IEEE 802.15.4-2006, section 7.4.2, Table 86. + */ + uint64_t m_macSuperframeOrder; + + /** + * Indication of whether the MAC sublayer is to enable its receiver during + * idle periods. + * See IEEE 802.15.4-2006, section 7.4.2, Table 86. + */ + bool m_macRxOnWhenIdle; + +protected: + // Inherited from Object. + virtual void DoInitialize (void); + virtual void DoDispose (void); + +private: + +}; + + +} // namespace ns3 + +#endif /* LR_WPAN_MAC_H */ diff --git a/src/lr-wpan/wscript b/src/lr-wpan/wscript --- a/src/lr-wpan/wscript +++ b/src/lr-wpan/wscript @@ -7,6 +7,7 @@ 'model/lr-wpan-interference-helper.cc', 'model/lr-wpan-phy.cc', 'model/lr-wpan-mac.cc', + 'model/lr-wpan-nullmac.cc', 'model/lr-wpan-mac-header.cc', 'model/lr-wpan-mac-trailer.cc', 'model/lr-wpan-csmaca.cc', @@ -36,6 +37,7 @@ 'model/lr-wpan-interference-helper.h', 'model/lr-wpan-phy.h', 'model/lr-wpan-mac.h', + 'model/lr-wpan-nullmac.h', 'model/lr-wpan-mac-header.h', 'model/lr-wpan-mac-trailer.h', 'model/lr-wpan-csmaca.h',