|
|
| 41 |
#include "ns3/udp-socket-factory.h" |
41 |
#include "ns3/udp-socket-factory.h" |
| 42 |
#include "ns3/string.h" |
42 |
#include "ns3/string.h" |
| 43 |
#include "ns3/pointer.h" |
43 |
#include "ns3/pointer.h" |
|
|
44 |
#include "ns3/boolean.h" |
| 44 |
|
45 |
|
| 45 |
namespace ns3 { |
46 |
namespace ns3 { |
| 46 |
|
47 |
|
|
|
| 59 |
DataRateValue (DataRate ("500kb/s")), |
60 |
DataRateValue (DataRate ("500kb/s")), |
| 60 |
MakeDataRateAccessor (&OnOffApplication::m_cbrRate), |
61 |
MakeDataRateAccessor (&OnOffApplication::m_cbrRate), |
| 61 |
MakeDataRateChecker ()) |
62 |
MakeDataRateChecker ()) |
|
|
63 |
.AddAttribute ("RandomSize", "An optional random variable that replaces the use of fixed PacketSize variable", |
| 64 |
StringValue ("ns3::ConstantRandomVariable[Constant=512.0]"), |
| 65 |
MakePointerAccessor (&OnOffApplication::m_randomSize), |
| 66 |
MakePointerChecker <RandomVariableStream>()) |
| 67 |
.AddAttribute ("UseRandomSize", "Flag for whether packet distribution or fixed packet size is used", |
| 68 |
BooleanValue (false), |
| 69 |
MakeBooleanAccessor (&OnOffApplication::m_useRandomSize), |
| 70 |
MakeBooleanChecker ()) |
| 71 |
.AddAttribute ("RandomInterval", "An optional random variable that replaces the use of fixed DataRate", |
| 72 |
StringValue ("ns3::ConstantRandomVariable[Constant=512.0]"), |
| 73 |
MakePointerAccessor (&OnOffApplication::m_randomInterval), |
| 74 |
MakePointerChecker <RandomVariableStream>()) |
| 75 |
.AddAttribute ("UseRandomInterval", "Flag for whether interval distribution or fixed DataRate is used", |
| 76 |
BooleanValue (false), |
| 77 |
MakeBooleanAccessor (&OnOffApplication::m_useRandomInterval), |
| 78 |
MakeBooleanChecker ()) |
| 62 |
.AddAttribute ("PacketSize", "The size of packets sent in on state", |
79 |
.AddAttribute ("PacketSize", "The size of packets sent in on state", |
| 63 |
UintegerValue (512), |
80 |
UintegerValue (512), |
| 64 |
MakeUintegerAccessor (&OnOffApplication::m_pktSize), |
81 |
MakeUintegerAccessor (&OnOffApplication::m_pktSize), |
|
|
| 129 |
NS_LOG_FUNCTION (this << stream); |
146 |
NS_LOG_FUNCTION (this << stream); |
| 130 |
m_onTime->SetStream (stream); |
147 |
m_onTime->SetStream (stream); |
| 131 |
m_offTime->SetStream (stream + 1); |
148 |
m_offTime->SetStream (stream + 1); |
| 132 |
return 2; |
149 |
m_randomInterval->SetStream (stream + 2); |
|
|
150 |
m_randomSize->SetStream (stream + 3); |
| 151 |
return 4; |
| 133 |
} |
152 |
} |
| 134 |
|
153 |
|
| 135 |
void |
154 |
void |
|
|
| 235 |
{ |
254 |
{ |
| 236 |
uint32_t bits = m_pktSize * 8 - m_residualBits; |
255 |
uint32_t bits = m_pktSize * 8 - m_residualBits; |
| 237 |
NS_LOG_LOGIC ("bits = " << bits); |
256 |
NS_LOG_LOGIC ("bits = " << bits); |
| 238 |
Time nextTime (Seconds (bits / |
257 |
Time nextTime; |
| 239 |
static_cast<double>(m_cbrRate.GetBitRate ()))); // Time till next packet |
258 |
// Time till next packet |
|
|
259 |
if (m_useRandomInterval) |
| 260 |
{ |
| 261 |
nextTime = Seconds (m_randomInterval->GetValue ()); |
| 262 |
NS_ASSERT_MSG (nextTime.IsPositive (), |
| 263 |
"Packet interval is unexpectedly zero or negative. " |
| 264 |
"Please verify the configuration of " |
| 265 |
"`ns3::OnOffApplication::RandomInterval` " |
| 266 |
"random variable."); |
| 267 |
} |
| 268 |
else |
| 269 |
{ |
| 270 |
nextTime = Seconds (bits / static_cast<double>(m_cbrRate.GetBitRate ())); |
| 271 |
} |
| 240 |
NS_LOG_LOGIC ("nextTime = " << nextTime); |
272 |
NS_LOG_LOGIC ("nextTime = " << nextTime); |
| 241 |
m_sendEvent = Simulator::Schedule (nextTime, |
273 |
m_sendEvent = Simulator::Schedule (nextTime, |
| 242 |
&OnOffApplication::SendPacket, this); |
274 |
&OnOffApplication::SendPacket, this); |
|
|
| 271 |
NS_LOG_FUNCTION (this); |
303 |
NS_LOG_FUNCTION (this); |
| 272 |
|
304 |
|
| 273 |
NS_ASSERT (m_sendEvent.IsExpired ()); |
305 |
NS_ASSERT (m_sendEvent.IsExpired ()); |
| 274 |
Ptr<Packet> packet = Create<Packet> (m_pktSize); |
306 |
uint32_t packetSize; |
|
|
307 |
if (m_useRandomSize) |
| 308 |
{ |
| 309 |
packetSize = m_randomSize->GetInteger (); |
| 310 |
NS_ASSERT_MSG (packetSize > 0, "Packet size was unexpectedly zero. " |
| 311 |
"Please verify the configuration of " |
| 312 |
"`ns3::OnOffApplication::RandomSize` " |
| 313 |
"random variable."); |
| 314 |
} |
| 315 |
else |
| 316 |
{ |
| 317 |
packetSize = m_pktSize; |
| 318 |
} |
| 319 |
Ptr<Packet> packet = Create<Packet> (packetSize); |
| 275 |
m_txTrace (packet); |
320 |
m_txTrace (packet); |
| 276 |
m_socket->Send (packet); |
321 |
m_socket->Send (packet); |
| 277 |
m_totBytes += m_pktSize; |
322 |
m_totBytes += m_pktSize; |