diff --git a/src/dsr/model/dsr-options.cc b/src/dsr/model/dsr-options.cc index 119752cef..028a883af 100644 --- a/src/dsr/model/dsr-options.cc +++ b/src/dsr/model/dsr-options.cc @@ -43,7 +43,6 @@ #include "ns3/node.h" #include "ns3/uinteger.h" #include "ns3/trace-source-accessor.h" -#include "ns3/random-variable.h" #include "ns3/udp-header.h" #include "ns3/pointer.h" #include "ns3/node-list.h" diff --git a/src/dsr/model/dsr-routing.cc b/src/dsr/model/dsr-routing.cc index 0ac9aca1a..8f2b261aa 100644 --- a/src/dsr/model/dsr-routing.cc +++ b/src/dsr/model/dsr-routing.cc @@ -56,7 +56,6 @@ #include "ns3/ipv4-l3-protocol.h" #include "ns3/ipv4-route.h" #include "ns3/trace-source-accessor.h" -#include "ns3/random-variable.h" #include "ns3/icmpv4-l4-protocol.h" #include "ns3/adhoc-wifi-mac.h" #include "ns3/wifi-net-device.h" @@ -269,6 +268,9 @@ TypeId DsrRouting::GetTypeId () DsrRouting::DsrRouting () { NS_LOG_FUNCTION_NOARGS (); + + m_uniformRandomVariable = CreateObject (); + /* * The following Ptr statements created objects for all the options header for DSR, and each of them have * distinct option number assigned, when DSR Routing received a packet from higher layer, it will find @@ -786,7 +788,7 @@ void DsrRouting::SendRerrWhenBreaksLinkToNextHop (Ipv4Address nextHop, uint8_t p } if (m_maintainBuffer.GetSize () != 0 && m_maintainBuffer.Find (nextHop)) { - Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,100)), + Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0,100)), &DsrRouting::SendRerrWhenBreaksLinkToNextHop,this,nextHop,protocol); } } @@ -1411,7 +1413,7 @@ DsrRouting::Send (Ptr packet, } } // Try to send packet from *previously* queued entries from send buffer if any - Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,100)), + Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0,100)), &DsrRouting::SendPacketFromBuffer,this,sourceRoute,nextHop,protocol); } } @@ -1544,7 +1546,7 @@ DsrRouting::PriorityScheduler (uint32_t priority, bool continueWithFirst) { NS_LOG_DEBUG ("Packet sent by Dsr. Calling PriorityScheduler after some time"); //packet was successfully sent down. call scheduler after some time - Simulator::Schedule (MicroSeconds (UniformVariable ().GetInteger (0, 1000)), + Simulator::Schedule (MicroSeconds (m_uniformRandomVariable->GetInteger (0, 1000)), &DsrRouting::PriorityScheduler,this, i, false); } else @@ -1683,7 +1685,7 @@ DsrRouting::SendPacketFromBuffer (DsrOptionSRHeader const &sourceRoute, Ipv4Addr if (m_sendBuffer.GetSize () != 0 && m_sendBuffer.Find (destination)) { NS_LOG_DEBUG ("Schedule sending the next packet in send buffer"); - Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,100)), + Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0,100)), &DsrRouting::SendPacketFromBuffer,this,sourceRoute,nextHop,protocol); } } @@ -1783,7 +1785,7 @@ DsrRouting::SendPacketFromBuffer (DsrOptionSRHeader const &sourceRoute, Ipv4Addr if (m_errorBuffer.GetSize () != 0 && m_errorBuffer.Find (destination)) { NS_LOG_DEBUG ("Schedule sending the next packet in send buffer"); - Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,100)), + Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0,100)), &DsrRouting::SendPacketFromBuffer,this,sourceRoute,nextHop,protocol); } } @@ -1941,7 +1943,7 @@ DsrRouting::CancelPacketTimerNextHop (Ipv4Address nextHop, uint8_t protocol) if (m_maintainBuffer.GetSize () && m_maintainBuffer.Find (nextHop)) { NS_LOG_INFO ("Cancel the packet timer for next maintenance entry"); - Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0,100)), + Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0,100)), &DsrRouting::CancelPacketTimerNextHop,this,nextHop,protocol); } } @@ -2219,6 +2221,14 @@ DsrRouting::PassiveScheduleTimerExpire (MaintainBuffEntry & mb, } } +int64_t +DsrRouting::AssignStreams (int64_t stream) +{ + NS_LOG_FUNCTION (this << stream); + m_uniformRandomVariable->SetStream (stream); + return 1; +} + void DsrRouting::NetworkScheduleTimerExpire (MaintainBuffEntry & mb, uint8_t protocol) @@ -2729,7 +2739,7 @@ DsrRouting::ScheduleInterRequest (Ptr packet) * This is a forwarding case when sending route requests, a random delay time [0, m_broadcastJitter] * used before forwarding as link-layer broadcast */ - Simulator::Schedule (MilliSeconds (UniformVariable ().GetInteger (0, m_broadcastJitter)), &DsrRouting::SendRequest, this, + Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0, m_broadcastJitter)), &DsrRouting::SendRequest, this, packet, m_mainAddress); } @@ -2843,7 +2853,7 @@ DsrRouting::ScheduleCachedReply (Ptr packet, double hops) { NS_LOG_FUNCTION (this << packet << source << destination); - Simulator::Schedule (Time (2 * m_nodeTraversalTime * (hops - 1 + UniformVariable ().GetValue (0,1))), &DsrRouting::SendReply, this, packet, source, destination, route); + Simulator::Schedule (Time (2 * m_nodeTraversalTime * (hops - 1 + m_uniformRandomVariable->GetValue (0,1))), &DsrRouting::SendReply, this, packet, source, destination, route); } void diff --git a/src/dsr/model/dsr-routing.h b/src/dsr/model/dsr-routing.h index f12ec5e86..7e42f9534 100644 --- a/src/dsr/model/dsr-routing.h +++ b/src/dsr/model/dsr-routing.h @@ -53,6 +53,7 @@ #include "ns3/ipv4-header.h" #include "ns3/ipv4-address.h" #include "ns3/traced-callback.h" +#include "ns3/random-variable-stream.h" #include "ns3/ipv4-route.h" #include "ns3/timer.h" #include "ns3/net-device.h" @@ -465,6 +466,16 @@ public: // / Handle route discovery timer void RouteRequestTimerExpire (Ptr packet, std::vector address, uint32_t requestId, uint8_t protocol); + /** + * 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: /* * * This function will notify other components connected to the node that a new stack member is now connected @@ -634,6 +645,9 @@ private: std::vector m_clearList; // / The node that is clear to send packet to std::vector m_addresses; // / The bind ipv4 addresses with next hop, src, destination address in sequence + + /// Provides uniform random variables. + Ptr m_uniformRandomVariable; }; } /* namespace dsr */ } /* namespace ns3 */