diff --git a/src/aodv/model/aodv-routing-protocol.cc b/src/aodv/model/aodv-routing-protocol.cc index 6cee53bce..5b24341c1 100644 --- a/src/aodv/model/aodv-routing-protocol.cc +++ b/src/aodv/model/aodv-routing-protocol.cc @@ -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 #include @@ -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 ()) ; return tid; } @@ -294,6 +301,14 @@ RoutingProtocol::PrintRoutingTable (Ptr 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) 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 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); } diff --git a/src/aodv/model/aodv-routing-protocol.h b/src/aodv/model/aodv-routing-protocol.h index edaf275d5..c56237f79 100644 --- a/src/aodv/model/aodv-routing-protocol.h +++ b/src/aodv/model/aodv-routing-protocol.h @@ -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 m_uniformRandomVariable; }; } diff --git a/src/aodv/test/aodv-regression.cc b/src/aodv/test/aodv-regression.cc index df095273d..33b308a72 100644 --- a/src/aodv/test/aodv-regression.cc +++ b/src/aodv/test/aodv-regression.cc @@ -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" diff --git a/src/aodv/test/loopback.cc b/src/aodv/test/loopback.cc index ccba734f6..5a8e3c5ff 100644 --- a/src/aodv/test/loopback.cc +++ b/src/aodv/test/loopback.cc @@ -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"