From 895ecc8a12a777158cc86a8e83e52257ad04fabf Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sun, 2 Jul 2017 21:32:55 -0700 Subject: [PATCH] wifi: Further changes to commit 12941 for smart pointer usage * Use ns3::Object only when trace sources or attributes are anticipated; otherwise use reference counted smart pointer * Remove RandomStream class because it adds no real functionality. It provides a TestRandomStream class for deterministic random variables (for testing) but this test class is unused and could be accomplished by other means. --- src/wifi/model/block-ack-manager.cc | 13 +++ src/wifi/model/block-ack-manager.h | 6 ++ src/wifi/model/dca-txop.cc | 17 ++-- src/wifi/model/dca-txop.h | 4 +- src/wifi/model/dcf-state.cc | 12 +++ src/wifi/model/dcf-state.h | 7 ++ src/wifi/model/edca-txop-n.cc | 23 ++--- src/wifi/model/mac-rx-middle.h | 4 +- src/wifi/model/mac-tx-middle.h | 4 +- src/wifi/model/qos-blocked-destinations.h | 4 +- src/wifi/model/random-stream.cc | 68 ------------- src/wifi/model/random-stream.h | 118 ---------------------- src/wifi/model/regular-wifi-mac.cc | 4 +- src/wifi/test/wifi-aggregation-test.cc | 2 +- src/wifi/wscript | 2 +- 15 files changed, 69 insertions(+), 219 deletions(-) delete mode 100644 src/wifi/model/random-stream.cc delete mode 100644 src/wifi/model/random-stream.h diff --git a/src/wifi/model/block-ack-manager.cc b/src/wifi/model/block-ack-manager.cc index f1fa607c1..5788ca0ff 100644 --- a/src/wifi/model/block-ack-manager.cc +++ b/src/wifi/model/block-ack-manager.cc @@ -56,6 +56,19 @@ Bar::Bar (Ptr bar, Mac48Address recipient, uint8_t tid, bool immed NS_LOG_FUNCTION (this << bar << recipient << (uint16_t)tid << immediate); } +NS_OBJECT_ENSURE_REGISTERED (BlockAckManager); + +TypeId +BlockAckManager::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::BlockAckManager") + .SetParent () + .SetGroupName ("Wifi") + .AddConstructor () + ; + return tid; +} + BlockAckManager::BlockAckManager () { NS_LOG_FUNCTION (this); diff --git a/src/wifi/model/block-ack-manager.h b/src/wifi/model/block-ack-manager.h index e07d76e5e..2e308693c 100644 --- a/src/wifi/model/block-ack-manager.h +++ b/src/wifi/model/block-ack-manager.h @@ -79,6 +79,12 @@ private: public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ + static TypeId GetTypeId (void); + BlockAckManager (); ~BlockAckManager (); diff --git a/src/wifi/model/dca-txop.cc b/src/wifi/model/dca-txop.cc index 84f3ede3f..68870b7fa 100644 --- a/src/wifi/model/dca-txop.cc +++ b/src/wifi/model/dca-txop.cc @@ -25,7 +25,6 @@ #include "dcf-state.h" #include "wifi-mac-queue.h" #include "mac-tx-middle.h" -#include "random-stream.h" #undef NS_LOG_APPEND_CONTEXT #define NS_LOG_APPEND_CONTEXT if (m_low != 0) { std::clog << "[mac=" << m_low->GetAddress () << "] "; } @@ -78,7 +77,7 @@ DcaTxop::DcaTxop () NS_LOG_FUNCTION (this); m_dcf = CreateObject (this); m_queue = CreateObject (); - m_rng = CreateObject (); + m_rng = CreateObject (); } DcaTxop::~DcaTxop () @@ -229,7 +228,7 @@ int64_t DcaTxop::AssignStreams (int64_t stream) { NS_LOG_FUNCTION (this << stream); - m_rng->AssignStreams (stream); + m_rng->SetStream (stream); return 1; } @@ -269,7 +268,7 @@ DcaTxop::DoInitialize () { NS_LOG_FUNCTION (this); m_dcf->ResetCw (); - m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ())); + m_dcf->StartBackoffNow (m_rng->GetInteger (0, m_dcf->GetCw ())); } bool @@ -436,7 +435,7 @@ void DcaTxop::NotifyCollision (void) { NS_LOG_FUNCTION (this); - m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ())); + m_dcf->StartBackoffNow (m_rng->GetInteger (0, m_dcf->GetCw ())); RestartAccessIfNeeded (); } @@ -487,7 +486,7 @@ DcaTxop::MissedCts (void) { m_dcf->UpdateFailedCw (); } - m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ())); + m_dcf->StartBackoffNow (m_rng->GetInteger (0, m_dcf->GetCw ())); RestartAccessIfNeeded (); } @@ -509,7 +508,7 @@ DcaTxop::GotAck (void) */ m_currentPacket = 0; m_dcf->ResetCw (); - m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ())); + m_dcf->StartBackoffNow (m_rng->GetInteger (0, m_dcf->GetCw ())); RestartAccessIfNeeded (); } else @@ -541,7 +540,7 @@ DcaTxop::MissedAck (void) m_currentHdr.SetRetry (); m_dcf->UpdateFailedCw (); } - m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ())); + m_dcf->StartBackoffNow (m_rng->GetInteger (0, m_dcf->GetCw ())); RestartAccessIfNeeded (); } @@ -582,7 +581,7 @@ DcaTxop::EndTxNoAck (void) NS_LOG_DEBUG ("a transmission that did not require an ACK just finished"); m_currentPacket = 0; m_dcf->ResetCw (); - m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ())); + m_dcf->StartBackoffNow (m_rng->GetInteger (0, m_dcf->GetCw ())); StartAccessIfNeeded (); } diff --git a/src/wifi/model/dca-txop.h b/src/wifi/model/dca-txop.h index 83dbad036..a61540c21 100644 --- a/src/wifi/model/dca-txop.h +++ b/src/wifi/model/dca-txop.h @@ -30,7 +30,7 @@ namespace ns3 { class DcfState; class DcfManager; class MacTxMiddle; -class RandomStream; +class UniformRandomVariable; class CtrlBAckResponseHeader; /** @@ -410,7 +410,7 @@ protected: Ptr m_txMiddle; //!< the MacTxMiddle Ptr m_low; //!< the MacLow Ptr m_stationManager; //!< the wifi remote station manager - Ptr m_rng; //!< the random stream + Ptr m_rng; //!< the random stream Ptr m_currentPacket; //!< the current packet WifiMacHeader m_currentHdr; //!< the current header diff --git a/src/wifi/model/dcf-state.cc b/src/wifi/model/dcf-state.cc index 837b87635..e78554a1f 100644 --- a/src/wifi/model/dcf-state.cc +++ b/src/wifi/model/dcf-state.cc @@ -26,6 +26,18 @@ namespace ns3 { NS_LOG_COMPONENT_DEFINE ("DcfState"); +NS_OBJECT_ENSURE_REGISTERED (DcfState); + +TypeId +DcfState::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::DcfState") + .SetParent () + .SetGroupName ("Wifi") + ; + return tid; +} + DcfState::DcfState (Ptr txop) : m_backoffSlots (0), m_backoffStart (Seconds (0.0)), diff --git a/src/wifi/model/dcf-state.h b/src/wifi/model/dcf-state.h index 0adb2cdc8..51a385eb4 100644 --- a/src/wifi/model/dcf-state.h +++ b/src/wifi/model/dcf-state.h @@ -41,6 +41,13 @@ class DcaTxop; class DcfState : public Object { public: + + /** + * \brief Get the type ID. + * \return the object TypeId + */ + static TypeId GetTypeId (void); + /** * Constructor * diff --git a/src/wifi/model/edca-txop-n.cc b/src/wifi/model/edca-txop-n.cc index 6c2858ada..6cf9e48db 100644 --- a/src/wifi/model/edca-txop-n.cc +++ b/src/wifi/model/edca-txop-n.cc @@ -27,7 +27,6 @@ #include "dcf-state.h" #include "mac-tx-middle.h" #include "wifi-mac-trailer.h" -#include "random-stream.h" #include "wifi-mac-queue.h" #include "qos-blocked-destinations.h" #include "ns3/simulator.h" @@ -74,7 +73,7 @@ EdcaTxopN::EdcaTxopN () m_currentIsFragmented (false) { NS_LOG_FUNCTION (this); - m_qosBlockedDestinations = CreateObject (); + m_qosBlockedDestinations = Create (); m_baManager = CreateObject (); m_baManager->SetQueue (m_queue); m_baManager->SetBlockAckType (m_blockAckType); @@ -423,7 +422,7 @@ void EdcaTxopN::NotifyInternalCollision (void) m_dcf->UpdateFailedCw (); } } - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); RestartAccessIfNeeded (); } @@ -432,7 +431,7 @@ void EdcaTxopN::NotifyCollision (void) { NS_LOG_FUNCTION (this); - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); RestartAccessIfNeeded (); } @@ -495,7 +494,7 @@ EdcaTxopN::MissedCts (void) m_dcf->UpdateFailedCw (); m_cwTrace = m_dcf->GetCw (); } - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); RestartAccessIfNeeded (); } @@ -543,7 +542,7 @@ EdcaTxopN::GotAck (void) m_txopTrace (m_startTxop, Simulator::Now () - m_startTxop); } m_cwTrace = m_dcf->GetCw (); - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); RestartAccessIfNeeded (); } @@ -557,7 +556,7 @@ EdcaTxopN::GotAck (void) { m_txopTrace (m_startTxop, Simulator::Now () - m_startTxop); m_cwTrace = m_dcf->GetCw (); - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); m_fragmentNumber++; RestartAccessIfNeeded (); @@ -626,7 +625,7 @@ EdcaTxopN::MissedAck (void) m_dcf->UpdateFailedCw (); m_cwTrace = m_dcf->GetCw (); } - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); RestartAccessIfNeeded (); } @@ -700,7 +699,7 @@ EdcaTxopN::MissedBlockAck (uint8_t nMpdus) m_dcf->ResetCw (); m_cwTrace = m_dcf->GetCw (); } - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); RestartAccessIfNeeded (); } @@ -963,7 +962,7 @@ EdcaTxopN::EndTxNoAck (void) m_currentPacket = 0; m_dcf->ResetCw (); m_cwTrace = m_dcf->GetCw (); - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); StartAccessIfNeeded (); } @@ -1293,7 +1292,7 @@ EdcaTxopN::GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address rec m_txopTrace (m_startTxop, Simulator::Now () - m_startTxop); } m_cwTrace = m_dcf->GetCw (); - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); RestartAccessIfNeeded (); } @@ -1563,7 +1562,7 @@ EdcaTxopN::DoInitialize () NS_LOG_FUNCTION (this); m_dcf->ResetCw (); m_cwTrace = m_dcf->GetCw (); - m_backoffTrace = m_rng->GetNext (0, m_dcf->GetCw ()); + m_backoffTrace = m_rng->GetInteger (0, m_dcf->GetCw ()); m_dcf->StartBackoffNow (m_backoffTrace); } diff --git a/src/wifi/model/mac-rx-middle.h b/src/wifi/model/mac-rx-middle.h index c04095d8a..9c84a908c 100644 --- a/src/wifi/model/mac-rx-middle.h +++ b/src/wifi/model/mac-rx-middle.h @@ -23,7 +23,7 @@ #include #include "ns3/packet.h" -#include "ns3/object.h" +#include "ns3/simple-ref-count.h" namespace ns3 { @@ -35,7 +35,7 @@ class OriginatorRxStatus; * * This class handles duplicate detection and recomposition of fragments. */ -class MacRxMiddle : public Object +class MacRxMiddle : public SimpleRefCount { public: /** diff --git a/src/wifi/model/mac-tx-middle.h b/src/wifi/model/mac-tx-middle.h index bc3469eca..1056084d8 100644 --- a/src/wifi/model/mac-tx-middle.h +++ b/src/wifi/model/mac-tx-middle.h @@ -25,7 +25,7 @@ #include #include "ns3/mac48-address.h" -#include "ns3/object.h" +#include "ns3/simple-ref-count.h" namespace ns3 { @@ -36,7 +36,7 @@ class WifiMacHeader; * * Handles sequence numbering of IEEE 802.11 data frames */ -class MacTxMiddle : public Object +class MacTxMiddle : public SimpleRefCount { public: MacTxMiddle (); diff --git a/src/wifi/model/qos-blocked-destinations.h b/src/wifi/model/qos-blocked-destinations.h index 4960b3671..96ba07e9f 100644 --- a/src/wifi/model/qos-blocked-destinations.h +++ b/src/wifi/model/qos-blocked-destinations.h @@ -24,7 +24,7 @@ #include #include "ns3/mac48-address.h" -#include "ns3/object.h" +#include "ns3/simple-ref-count.h" namespace ns3 { @@ -32,7 +32,7 @@ namespace ns3 { * Keep track of destination address - TID pairs that are waiting * for a block ACK response. */ -class QosBlockedDestinations : public Object +class QosBlockedDestinations : public SimpleRefCount { public: QosBlockedDestinations (); diff --git a/src/wifi/model/random-stream.cc b/src/wifi/model/random-stream.cc deleted file mode 100644 index 54e23f77c..000000000 --- a/src/wifi/model/random-stream.cc +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * - * 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 - * - * Author: Mathieu Lacage - */ - -#include "random-stream.h" - -namespace ns3 { - -RandomStream::~RandomStream () -{ -} - -RealRandomStream::RealRandomStream () -{ - m_stream = CreateObject (); -} - -uint32_t -RealRandomStream::GetNext (uint32_t min, uint32_t max) -{ - return m_stream->GetInteger (min, max); -} - -int64_t -RealRandomStream::AssignStreams (int64_t stream) -{ - m_stream->SetStream (stream); - return 1; -} - -void -TestRandomStream::AddNext (uint32_t v) -{ - m_nexts.push_back (v); -} - -uint32_t -TestRandomStream::GetNext (uint32_t min, uint32_t max) -{ - NS_ASSERT (!m_nexts.empty ()); - uint32_t next = m_nexts.front (); - m_nexts.pop_front (); - return next; -} - -int64_t -TestRandomStream::AssignStreams (int64_t stream) -{ - return 0; -} - -} //namespace ns3 diff --git a/src/wifi/model/random-stream.h b/src/wifi/model/random-stream.h deleted file mode 100644 index 0c4c4896e..000000000 --- a/src/wifi/model/random-stream.h +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * - * 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 - * - * Author: Mathieu Lacage - */ - -#ifndef RANDOM_STREAM_H -#define RANDOM_STREAM_H - -#include "ns3/random-variable-stream.h" - -namespace ns3 { - -/** - * A simple wrapper around RngStream to make testing - * of the code easier. - */ -class RandomStream : public Object -{ -public: - virtual ~RandomStream (); - /** - * Get integer between min and max (including min and max). - * - * \param min lower bound (inclusive) - * \param max upper bound (inclusive) - * - * \return a random number between min and max (including min and max) - */ - virtual uint32_t GetNext (uint32_t min, uint32_t max) = 0; - - /** - * Assign a fixed random variable stream number to the random variables - * used by this model. Return the number of streams (possibly zero) that - * have been assigned. - * - * \param stream first stream index to use - * - * \return the number of stream indices assigned by this model - */ - virtual int64_t AssignStreams (int64_t stream) = 0; -}; - - -/** - * RealRandomStream class - */ -class RealRandomStream : public RandomStream -{ -public: - RealRandomStream (); - virtual uint32_t GetNext (uint32_t min, uint32_t max); - - /** - * Assign a fixed random variable stream number to the random variables - * used by this model. Return the number of streams (possibly zero) that - * have been assigned. - * - * \param stream first stream index to use - * - * \return the number of stream indices assigned by this model - */ - virtual int64_t AssignStreams (int64_t stream); - - -private: - /// Provides uniform random variables. - Ptr m_stream; -}; - - -/** - * TestRandomStream class - */ -class TestRandomStream : public RandomStream -{ -public: - /** - * Add the given value to the list. - * - * \param v - */ - void AddNext (uint32_t v); - virtual uint32_t GetNext (uint32_t min, uint32_t max); - - /** - * Assign a fixed random variable stream number to the random variables - * used by this model. Return the number of streams (possibly zero) that - * have been assigned. - * - * \param stream first stream index to use - * - * \return the number of stream indices assigned by this model - */ - virtual int64_t AssignStreams (int64_t stream); - - -private: - std::list m_nexts; ///< nexts -}; - -} //namespace ns3 - -#endif /* RANDOM_STREAM_H */ diff --git a/src/wifi/model/regular-wifi-mac.cc b/src/wifi/model/regular-wifi-mac.cc index 7ae5ee06c..d83f31fc8 100644 --- a/src/wifi/model/regular-wifi-mac.cc +++ b/src/wifi/model/regular-wifi-mac.cc @@ -42,10 +42,10 @@ RegularWifiMac::RegularWifiMac () m_heSupported (0) { NS_LOG_FUNCTION (this); - m_rxMiddle = CreateObject (); + m_rxMiddle = Create (); m_rxMiddle->SetForwardCallback (MakeCallback (&RegularWifiMac::Receive, this)); - m_txMiddle = CreateObject (); + m_txMiddle = Create (); m_low = CreateObject (); m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle)); diff --git a/src/wifi/test/wifi-aggregation-test.cc b/src/wifi/test/wifi-aggregation-test.cc index e6a899a2b..8961c4e83 100644 --- a/src/wifi/test/wifi-aggregation-test.cc +++ b/src/wifi/test/wifi-aggregation-test.cc @@ -98,7 +98,7 @@ AmpduAggregationTest::DoRun (void) m_edca->SetWifiRemoteStationManager (m_manager); m_edca->SetManager (m_dcfManager); - m_txMiddle = CreateObject (); + m_txMiddle = Create (); m_edca->SetTxMiddle (m_txMiddle); m_edca->CompleteConfig (); diff --git a/src/wifi/wscript b/src/wifi/wscript index a8ddd1df0..78d28ea01 100644 --- a/src/wifi/wscript +++ b/src/wifi/wscript @@ -32,7 +32,6 @@ def build(bld): 'model/capability-information.cc', 'model/status-code.cc', 'model/mgt-headers.cc', - 'model/random-stream.cc', 'model/dcf-manager.cc', 'model/dcf-state.cc', 'model/wifi-mac.cc', @@ -194,6 +193,7 @@ def build(bld): 'model/he-capabilities.h', 'model/frame-capture-model.h', 'model/simple-frame-capture-model.h', + 'model/qos-blocked-destinations.h', 'helper/wifi-radio-energy-model-helper.h', 'helper/vht-wifi-mac-helper.h', 'helper/ht-wifi-mac-helper.h',