diff -r d5e55601a7ab src/applications/model/onoff-application.cc --- a/src/applications/model/onoff-application.cc Sat Jan 14 08:22:50 2017 -0800 +++ b/src/applications/model/onoff-application.cc Sun Jan 15 16:36:18 2017 -0800 @@ -41,6 +41,7 @@ #include "ns3/udp-socket-factory.h" #include "ns3/string.h" #include "ns3/pointer.h" +#include "ns3/boolean.h" namespace ns3 { @@ -59,6 +60,22 @@ DataRateValue (DataRate ("500kb/s")), MakeDataRateAccessor (&OnOffApplication::m_cbrRate), MakeDataRateChecker ()) + .AddAttribute ("RandomSize", "An optional random variable that replaces the use of fixed PacketSize variable", + StringValue ("ns3::ConstantRandomVariable[Constant=512.0]"), + MakePointerAccessor (&OnOffApplication::m_randomSize), + MakePointerChecker ()) + .AddAttribute ("UseRandomSize", "Flag for whether packet distribution or fixed packet size is used", + BooleanValue (false), + MakeBooleanAccessor (&OnOffApplication::m_useRandomSize), + MakeBooleanChecker ()) + .AddAttribute ("RandomInterval", "An optional random variable that replaces the use of fixed DataRate", + StringValue ("ns3::ConstantRandomVariable[Constant=512.0]"), + MakePointerAccessor (&OnOffApplication::m_randomInterval), + MakePointerChecker ()) + .AddAttribute ("UseRandomInterval", "Flag for whether interval distribution or fixed DataRate is used", + BooleanValue (false), + MakeBooleanAccessor (&OnOffApplication::m_useRandomInterval), + MakeBooleanChecker ()) .AddAttribute ("PacketSize", "The size of packets sent in on state", UintegerValue (512), MakeUintegerAccessor (&OnOffApplication::m_pktSize), @@ -129,7 +146,9 @@ NS_LOG_FUNCTION (this << stream); m_onTime->SetStream (stream); m_offTime->SetStream (stream + 1); - return 2; + m_randomInterval->SetStream (stream + 2); + m_randomSize->SetStream (stream + 3); + return 4; } void @@ -235,8 +254,21 @@ { uint32_t bits = m_pktSize * 8 - m_residualBits; NS_LOG_LOGIC ("bits = " << bits); - Time nextTime (Seconds (bits / - static_cast(m_cbrRate.GetBitRate ()))); // Time till next packet + Time nextTime; + // Time till next packet + if (m_useRandomInterval) + { + nextTime = Seconds (m_randomInterval->GetValue ()); + NS_ASSERT_MSG (nextTime.IsPositive (), + "Packet interval is unexpectedly zero or negative. " + "Please verify the configuration of " + "`ns3::OnOffApplication::RandomInterval` " + "random variable."); + } + else + { + nextTime = Seconds (bits / static_cast(m_cbrRate.GetBitRate ())); + } NS_LOG_LOGIC ("nextTime = " << nextTime); m_sendEvent = Simulator::Schedule (nextTime, &OnOffApplication::SendPacket, this); @@ -271,7 +303,20 @@ NS_LOG_FUNCTION (this); NS_ASSERT (m_sendEvent.IsExpired ()); - Ptr packet = Create (m_pktSize); + uint32_t packetSize; + if (m_useRandomSize) + { + packetSize = m_randomSize->GetInteger (); + NS_ASSERT_MSG (packetSize > 0, "Packet size was unexpectedly zero. " + "Please verify the configuration of " + "`ns3::OnOffApplication::RandomSize` " + "random variable."); + } + else + { + packetSize = m_pktSize; + } + Ptr packet = Create (packetSize); m_txTrace (packet); m_socket->Send (packet); m_totBytes += m_pktSize; diff -r d5e55601a7ab src/applications/model/onoff-application.h --- a/src/applications/model/onoff-application.h Sat Jan 14 08:22:50 2017 -0800 +++ b/src/applications/model/onoff-application.h Sun Jan 15 16:36:18 2017 -0800 @@ -151,6 +151,10 @@ Ptr m_socket; //!< Associated socket Address m_peer; //!< Peer address bool m_connected; //!< True if connected + Ptr m_randomSize; //!< rng for packet size distribution + bool m_useRandomSize; //!< boolean to use packet distribution + Ptr m_randomInterval; //!< rng for interarrival time + bool m_useRandomInterval; //!< boolean to use interval distribution Ptr m_onTime; //!< rng for On Time Ptr m_offTime; //!< rng for Off Time DataRate m_cbrRate; //!< Rate that data is generated