Replace src/csma usage of RandomVariable with RandomVariableStream
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -281,6 +281,23 @@ CsmaHelper::Install (const NodeContainer &c, std::string channelName) const
|
||||
return Install (c, channel);
|
||||
}
|
||||
|
||||
int64_t
|
||||
CsmaHelper::AssignStreams (NetDeviceContainer c, int64_t stream)
|
||||
{
|
||||
int64_t currentStream = stream;
|
||||
Ptr<NetDevice> netDevice;
|
||||
for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
|
||||
{
|
||||
netDevice = (*i);
|
||||
Ptr<CsmaNetDevice> csma = DynamicCast<CsmaNetDevice> (netDevice);
|
||||
if (csma)
|
||||
{
|
||||
currentStream += csma->AssignStreams (currentStream);
|
||||
}
|
||||
}
|
||||
return (currentStream - stream);
|
||||
}
|
||||
|
||||
Ptr<NetDevice>
|
||||
CsmaHelper::InstallPriv (Ptr<Node> node, Ptr<CsmaChannel> channel) const
|
||||
{
|
||||
|
||||
@@ -192,6 +192,19 @@ public:
|
||||
*/
|
||||
NetDeviceContainer Install (const NodeContainer &c, std::string channelName) const;
|
||||
|
||||
/**
|
||||
* 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. The Install() method should have previously been
|
||||
* called by the user.
|
||||
*
|
||||
* \param c NetDeviceContainer of the set of net devices for which the
|
||||
* CsmaNetDevice should be modified to use a fixed stream
|
||||
* \param stream first stream index to use
|
||||
* \return the number of stream indices assigned by this helper
|
||||
*/
|
||||
int64_t AssignStreams (NetDeviceContainer c, int64_t stream);
|
||||
|
||||
private:
|
||||
/*
|
||||
* \internal
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
*/
|
||||
|
||||
#include "backoff.h"
|
||||
#include "ns3/log.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("Backoff");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -29,6 +32,7 @@ Backoff::Backoff ()
|
||||
m_maxSlots = 1000;
|
||||
m_ceiling = 10;
|
||||
m_maxRetries = 1000;
|
||||
m_rng = CreateObject<UniformRandomVariable> ();
|
||||
|
||||
ResetBackoffTime ();
|
||||
}
|
||||
@@ -40,7 +44,7 @@ Backoff::Backoff(Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t c
|
||||
m_maxSlots = maxSlots;
|
||||
m_ceiling = ceiling;
|
||||
m_maxRetries = maxRetries;
|
||||
m_rng = UniformVariable ();
|
||||
m_rng = CreateObject<UniformRandomVariable> ();
|
||||
}
|
||||
|
||||
Time
|
||||
@@ -64,7 +68,7 @@ Backoff::GetBackoffTime (void)
|
||||
maxSlot = m_maxSlots;
|
||||
}
|
||||
|
||||
uint32_t backoffSlots = (uint32_t)m_rng.GetValue (minSlot, maxSlot);
|
||||
uint32_t backoffSlots = (uint32_t)m_rng->GetValue (minSlot, maxSlot);
|
||||
|
||||
Time backoff = Time (backoffSlots * m_slotTime);
|
||||
return backoff;
|
||||
@@ -88,4 +92,12 @@ Backoff::IncrNumRetries (void)
|
||||
m_numBackoffRetries++;
|
||||
}
|
||||
|
||||
int64_t
|
||||
Backoff::AssignStreams (int64_t stream)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << stream);
|
||||
m_rng->SetStream (stream);
|
||||
return 1;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -24,7 +24,7 @@ Transmi */
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/random-variable-stream.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -87,13 +87,23 @@ public:
|
||||
*/
|
||||
void IncrNumRetries (void);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
int64_t AssignStreams (int64_t stream);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Number of times that the transmitter has tried to unsuccessfully transmit the current packet.
|
||||
*/
|
||||
uint32_t m_numBackoffRetries;
|
||||
UniformVariable m_rng;
|
||||
Ptr<UniformRandomVariable> m_rng;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -1014,4 +1014,10 @@ CsmaNetDevice::SupportsSendFrom () const
|
||||
return true;
|
||||
}
|
||||
|
||||
int64_t
|
||||
CsmaNetDevice::AssignStreams (int64_t stream)
|
||||
{
|
||||
return m_backoff.AssignStreams (stream);
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/data-rate.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/mac48-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
@@ -322,6 +321,16 @@ public:
|
||||
virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb);
|
||||
virtual bool SupportsSendFrom (void) const;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
int64_t AssignStreams (int64_t stream);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Perform any object release functionality required to break reference
|
||||
|
||||
Reference in New Issue
Block a user