eplace src/application usage of RandomVariable with RandomVariableStream

This commit is contained in:
Mitch Watrous committed 2012-08-13 10:46:09 -07:00
1 parent 037e8e47e8
commit 0e2574aa55
4 files changed
+35 -7

No files matched your search

+20 -5
View File
@@ -31,12 +31,14 @@
#include "aodv-routing-protocol.h"
#include "ns3/log.h"
#include "ns3/boolean.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "ns3/inet-socket-address.h"
#include "ns3/trace-source-accessor.h"
#include "ns3/udp-socket-factory.h"
#include "ns3/wifi-net-device.h"
#include "ns3/adhoc-wifi-mac.h"
#include "ns3/string.h"
#include "ns3/pointer.h"
#include <algorithm>
#include <limits>
@@ -253,6 +255,11 @@ RoutingProtocol::GetTypeId (void)
MakeBooleanAccessor (&RoutingProtocol::SetBroadcastEnable,
&RoutingProtocol::GetBroadcastEnable),
MakeBooleanChecker ())
.AddAttribute ("UniformRv",
"Access to the underlying UniformRandomVariable",
StringValue ("ns3::UniformRandomVariable"),
MakePointerAccessor (&RoutingProtocol::m_uniformRandomVariable),
MakePointerChecker<UniformRandomVariable> ())
;
return tid;
}
@@ -294,6 +301,14 @@ RoutingProtocol::PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const
m_routingTable.Print (stream);
}
int64_t
RoutingProtocol::AssignStreams (int64_t stream)
{
NS_LOG_FUNCTION (this << stream);
m_uniformRandomVariable->SetStream (stream);
return 1;
}
void
RoutingProtocol::Start ()
{
@@ -567,7 +582,7 @@ RoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4)
if (EnableHello)
{
m_htimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
m_htimer.Schedule (MilliSeconds (UniformVariable ().GetInteger (0, 100)));
m_htimer.Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0, 100)));
}
m_ipv4 = ipv4;
@@ -896,7 +911,7 @@ RoutingProtocol::SendRequest (Ipv4Address dst)
if (!m_htimer.IsRunning ())
{
m_htimer.Cancel ();
m_htimer.Schedule (HelloInterval - Time (0.01 * MilliSeconds (UniformVariable ().GetInteger (0, 10))));
m_htimer.Schedule (HelloInterval - Time (0.01 * MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))));
}
}
}
@@ -1163,7 +1178,7 @@ RoutingProtocol::RecvRequest (Ptr<Packet> p, Ipv4Address receiver, Ipv4Address s
if (!m_htimer.IsRunning ())
{
m_htimer.Cancel ();
m_htimer.Schedule (HelloInterval - Time (0.1 * MilliSeconds (UniformVariable ().GetInteger (0, 10))));
m_htimer.Schedule (HelloInterval - Time (0.1 * MilliSeconds (m_uniformRandomVariable->GetInteger (0, 10))));
}
}
}
@@ -1526,7 +1541,7 @@ RoutingProtocol::HelloTimerExpire ()
NS_LOG_FUNCTION (this);
SendHello ();
m_htimer.Cancel ();
Time t = Time (0.01 * MilliSeconds (UniformVariable ().GetInteger (0, 100)));
Time t = Time (0.01 * MilliSeconds (m_uniformRandomVariable->GetInteger (0, 100)));
m_htimer.Schedule (HelloInterval - t);
}
+15
View File
@@ -34,6 +34,7 @@
#include "aodv-neighbor.h"
#include "aodv-dpd.h"
#include "ns3/node.h"
#include "ns3/random-variable-stream.h"
#include "ns3/output-stream-wrapper.h"
#include "ns3/ipv4-routing-protocol.h"
#include "ns3/ipv4-interface.h"
@@ -89,6 +90,17 @@ public:
void SetBroadcastEnable (bool f) { EnableBroadcast = f; }
bool GetBroadcastEnable () const { return EnableBroadcast; }
//\}
/**
* 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:
///\name Protocol parameters.
//\{
@@ -254,6 +266,9 @@ private:
void RouteRequestTimerExpire (Ipv4Address dst);
/// Mark link to neighbor node as unidirectional for blacklistTimeout
void AckTimerExpire (Ipv4Address neighbor, Time blacklistTimeout);
/// Provides uniform random variables.
Ptr<UniformRandomVariable> m_uniformRandomVariable;
};
}
-1
View File
@@ -24,7 +24,6 @@
#include "ns3/mesh-helper.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/mobility-helper.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
-1
View File
@@ -20,7 +20,6 @@
#include "loopback.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/mobility-helper.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"