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.
This commit is contained in:
Tom Henderson
2017-07-02 21:32:55 -07:00
parent 85e5d91383
commit 895ecc8a12
15 changed files with 69 additions and 219 deletions

View File

@@ -56,6 +56,19 @@ Bar::Bar (Ptr<const Packet> 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<Object> ()
.SetGroupName ("Wifi")
.AddConstructor<BlockAckManager> ()
;
return tid;
}
BlockAckManager::BlockAckManager ()
{
NS_LOG_FUNCTION (this);

View File

@@ -79,6 +79,12 @@ private:
public:
/**
* \brief Get the type ID.
* \return the object TypeId
*/
static TypeId GetTypeId (void);
BlockAckManager ();
~BlockAckManager ();

View File

@@ -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<DcfState> (this);
m_queue = CreateObject<WifiMacQueue> ();
m_rng = CreateObject<RealRandomStream> ();
m_rng = CreateObject<UniformRandomVariable> ();
}
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 ();
}

View File

@@ -30,7 +30,7 @@ namespace ns3 {
class DcfState;
class DcfManager;
class MacTxMiddle;
class RandomStream;
class UniformRandomVariable;
class CtrlBAckResponseHeader;
/**
@@ -410,7 +410,7 @@ protected:
Ptr<MacTxMiddle> m_txMiddle; //!< the MacTxMiddle
Ptr <MacLow> m_low; //!< the MacLow
Ptr<WifiRemoteStationManager> m_stationManager; //!< the wifi remote station manager
Ptr<RandomStream> m_rng; //!< the random stream
Ptr<UniformRandomVariable> m_rng; //!< the random stream
Ptr<const Packet> m_currentPacket; //!< the current packet
WifiMacHeader m_currentHdr; //!< the current header

View File

@@ -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<Object> ()
.SetGroupName ("Wifi")
;
return tid;
}
DcfState::DcfState (Ptr<DcaTxop> txop)
: m_backoffSlots (0),
m_backoffStart (Seconds (0.0)),

View File

@@ -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
*

View File

@@ -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<QosBlockedDestinations> ();
m_qosBlockedDestinations = Create<QosBlockedDestinations> ();
m_baManager = CreateObject<BlockAckManager> ();
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);
}

View File

@@ -23,7 +23,7 @@
#include <map>
#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<MacRxMiddle>
{
public:
/**

View File

@@ -25,7 +25,7 @@
#include <map>
#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<MacTxMiddle>
{
public:
MacTxMiddle ();

View File

@@ -24,7 +24,7 @@
#include <set>
#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<QosBlockedDestinations>
{
public:
QosBlockedDestinations ();

View File

@@ -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 <mathieu.lacage@sophia.inria.fr>
*/
#include "random-stream.h"
namespace ns3 {
RandomStream::~RandomStream ()
{
}
RealRandomStream::RealRandomStream ()
{
m_stream = CreateObject<UniformRandomVariable> ();
}
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

View File

@@ -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 <mathieu.lacage@sophia.inria.fr>
*/
#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<UniformRandomVariable> 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<uint32_t> m_nexts; ///< nexts
};
} //namespace ns3
#endif /* RANDOM_STREAM_H */

View File

@@ -42,10 +42,10 @@ RegularWifiMac::RegularWifiMac ()
m_heSupported (0)
{
NS_LOG_FUNCTION (this);
m_rxMiddle = CreateObject<MacRxMiddle> ();
m_rxMiddle = Create<MacRxMiddle> ();
m_rxMiddle->SetForwardCallback (MakeCallback (&RegularWifiMac::Receive, this));
m_txMiddle = CreateObject<MacTxMiddle> ();
m_txMiddle = Create<MacTxMiddle> ();
m_low = CreateObject<MacLow> ();
m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle));

View File

@@ -98,7 +98,7 @@ AmpduAggregationTest::DoRun (void)
m_edca->SetWifiRemoteStationManager (m_manager);
m_edca->SetManager (m_dcfManager);
m_txMiddle = CreateObject<MacTxMiddle> ();
m_txMiddle = Create<MacTxMiddle> ();
m_edca->SetTxMiddle (m_txMiddle);
m_edca->CompleteConfig ();

View File

@@ -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',