eplace src/application usage of RandomVariable with RandomVariableStream
authorMitch Watrous
Mon, 13 Aug 2012 10:46:09 -0700
changeset 8965 cfed4f87e003
parent 8964 3a0af8a1c005
child 8966 060dba23e9bb
eplace src/application usage of RandomVariable with RandomVariableStream
src/aodv/model/aodv-routing-protocol.cc
src/aodv/model/aodv-routing-protocol.h
src/aodv/test/aodv-regression.cc
src/aodv/test/loopback.cc
--- a/src/aodv/model/aodv-routing-protocol.cc	Wed Aug 08 13:17:14 2012 -0700
+++ b/src/aodv/model/aodv-routing-protocol.cc	Mon Aug 13 10:46:09 2012 -0700
@@ -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 @@
                    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 @@
   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 @@
   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 @@
       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 @@
       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 @@
   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);
 }
 
--- a/src/aodv/model/aodv-routing-protocol.h	Wed Aug 08 13:17:14 2012 -0700
+++ b/src/aodv/model/aodv-routing-protocol.h	Mon Aug 13 10:46:09 2012 -0700
@@ -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 @@
   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 @@
   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;  
 };
 
 }
--- a/src/aodv/test/aodv-regression.cc	Wed Aug 08 13:17:14 2012 -0700
+++ b/src/aodv/test/aodv-regression.cc	Mon Aug 13 10:46:09 2012 -0700
@@ -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"
--- a/src/aodv/test/loopback.cc	Wed Aug 08 13:17:14 2012 -0700
+++ b/src/aodv/test/loopback.cc	Mon Aug 13 10:46:09 2012 -0700
@@ -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"