A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
three-gpp-http-variables.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Magister Solutions
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Budiarto Herman <budiarto.herman@magister.fi>
7 *
8 */
9
11
12#include "ns3/double.h"
13#include "ns3/log.h"
14#include "ns3/uinteger.h"
15
16#include <math.h>
17
18NS_LOG_COMPONENT_DEFINE("ThreeGppHttpVariables");
19
20namespace ns3
21{
22
23NS_OBJECT_ENSURE_REGISTERED(ThreeGppHttpVariables);
24
38
39// static
42{
43 static TypeId tid =
44 TypeId("ns3::ThreeGppHttpVariables")
46 .AddConstructor<ThreeGppHttpVariables>()
47
48 // REQUEST SIZE
49 .AddAttribute("RequestSize",
50 "The constant size of HTTP request packet (in bytes).",
51 UintegerValue(328),
54
55 // MAIN OBJECT GENERATION DELAY
56 .AddAttribute("MainObjectGenerationDelay",
57 "The constant time needed by HTTP server "
58 "to generate a main object as a response.",
62
63 // MAIN OBJECT SIZE
64 .AddAttribute("MainObjectSizeMean",
65 "The mean of main object sizes (in bytes).",
66 UintegerValue(10710),
69 .AddAttribute("MainObjectSizeStdDev",
70 "The standard deviation of main object sizes (in bytes).",
71 UintegerValue(25032),
74 .AddAttribute("MainObjectSizeMin",
75 "The minimum value of main object sizes (in bytes).",
76 UintegerValue(100),
79 .AddAttribute("MainObjectSizeMax",
80 "The maximum value of main object sizes (in bytes).",
81 UintegerValue(2000000), // 2 MB
84
85 // EMBEDDED OBJECT GENERATION DELAY
86 .AddAttribute(
87 "EmbeddedObjectGenerationDelay",
88 "The constant time needed by HTTP server "
89 "to generate an embedded object as a response.",
93
94 // EMBEDDED OBJECT SIZE
95 .AddAttribute("EmbeddedObjectSizeMean",
96 "The mean of embedded object sizes (in bytes).",
97 UintegerValue(7758),
100 .AddAttribute("EmbeddedObjectSizeStdDev",
101 "The standard deviation of embedded object sizes (in bytes).",
102 UintegerValue(126168),
105 .AddAttribute("EmbeddedObjectSizeMin",
106 "The minimum value of embedded object sizes (in bytes).",
107 UintegerValue(50),
110 .AddAttribute("EmbeddedObjectSizeMax",
111 "The maximum value of embedded object sizes (in bytes).",
112 UintegerValue(2000000), // 2 MB
115
116 // NUMBER OF EMBEDDED OBJECTS PER PAGE
117 .AddAttribute("NumOfEmbeddedObjectsMax",
118 "The upper bound parameter of Pareto distribution for "
119 "the number of embedded objects per web page. The actual "
120 "maximum value is this value subtracted by the scale parameter.",
121 UintegerValue(55),
124 .AddAttribute("NumOfEmbeddedObjectsShape",
125 "The shape parameter of Pareto distribution for "
126 "the number of embedded objects per web page.",
127 DoubleValue(1.1),
130 .AddAttribute(
131 "NumOfEmbeddedObjectsScale",
132 "The scale parameter of Pareto distribution for "
133 "the number of embedded objects per web page.",
134 UintegerValue(2),
137
138 // READING TIME
139 .AddAttribute("ReadingTimeMean",
140 "The mean of reading time.",
141 TimeValue(Seconds(30)),
144
145 // PARSING TIME
146 .AddAttribute("ParsingTimeMean",
147 "The mean of parsing time.",
151
152 // MTU SIZE
153 .AddAttribute("LowMtuSize",
154 "The lower MTU size.",
155 UintegerValue(536),
158 .AddAttribute("HighMtuSize",
159 "The higher MTU size.",
160 UintegerValue(1460),
163 .AddAttribute("HighMtuProbability",
164 "The probability that higher MTU size is used.",
165 DoubleValue(0.76),
168 return tid;
169}
170
173{
174 const double r = m_mtuSizeRng->GetValue();
175 NS_ASSERT(r >= 0.0);
176 NS_ASSERT(r < 1.0);
177 if (r < m_highMtuProbability)
178 {
179 return m_highMtu; // 1500 bytes if including TCP header.
180 }
181 else
182 {
183 return m_lowMtu; // 576 bytes if including TCP header.
184 }
185}
186
189{
190 return m_requestSizeRng->GetInteger();
191}
192
193Time
198
201{
202 // Validate parameters.
204 {
205 NS_FATAL_ERROR("`MainObjectSizeMax` attribute must be greater than the `MainObjectSizeMin` "
206 "attribute.");
207 }
208
209 /*
210 * Repeatedly draw one new random value until it falls in the interval
211 * [min, max). The previous validation ensures this process does not loop
212 * indefinitely.
213 */
214 uint32_t value;
215 do
216 {
217 value = m_mainObjectSizeRng->GetInteger();
218 } while ((value < m_mainObjectSizeMin) || (value >= m_mainObjectSizeMax));
219
220 return value;
221}
222
223Time
228
231{
232 // Validate parameters.
234 {
235 NS_FATAL_ERROR("`EmbeddedObjectSizeMax` attribute must be greater than the "
236 "`EmbeddedObjectSizeMin` attribute.");
237 }
238
239 /*
240 * Repeatedly draw one new random value until it falls in the interval
241 * [min, max). The previous validation ensures this process does not loop
242 * indefinitely.
243 */
244 uint32_t value;
245 do
246 {
247 value = m_embeddedObjectSizeRng->GetInteger();
248 } while ((value < m_embeddedObjectSizeMin) || (value >= m_embeddedObjectSizeMax));
249
250 return value;
251}
252
255{
256 // Validate parameters.
257 const auto upperBound = static_cast<uint32_t>(m_numOfEmbeddedObjectsRng->GetBound());
258 if (upperBound <= m_numOfEmbeddedObjectsScale)
259 {
260 NS_FATAL_ERROR("`NumOfEmbeddedObjectsMax` attribute must be greater than the "
261 "`NumOfEmbeddedObjectsScale` attribute.");
262 }
263
264 /*
265 * Repeatedly draw one new random value until it falls in the interval
266 * [scale, upperBound). The previous validation ensures this process does
267 * not loop indefinitely.
268 */
269 uint32_t value;
270 do
271 {
272 value = m_numOfEmbeddedObjectsRng->GetInteger();
273 } while ((value < m_numOfEmbeddedObjectsScale) || (value >= upperBound));
274
275 /*
276 * Normalize the random value with the scale parameter. The returned value
277 * shall now be within the interval [0, (upperBound - scale)).
278 */
279 return (value - m_numOfEmbeddedObjectsScale);
280}
281
282Time
287
288Time
293
294int64_t
296{
297 NS_LOG_FUNCTION(this << stream);
298 auto currentStream = stream;
299 m_mtuSizeRng->SetStream(currentStream++);
300 m_requestSizeRng->SetStream(currentStream++);
301 m_mainObjectGenerationDelayRng->SetStream(currentStream++);
302 m_mainObjectSizeRng->SetStream(currentStream++);
303 m_embeddedObjectGenerationDelayRng->SetStream(currentStream++);
304 m_embeddedObjectSizeRng->SetStream(currentStream++);
305 m_numOfEmbeddedObjectsRng->SetStream(currentStream++);
306 m_readingTimeRng->SetStream(currentStream++);
307 m_parsingTimeRng->SetStream(currentStream++);
308 return (currentStream - stream);
309}
310
311void
318
319// SETTER METHODS /////////////////////////////////////////////////////////////
320
321void
323{
324 NS_LOG_FUNCTION(this << constant);
325 m_requestSizeRng->SetAttribute("Constant", DoubleValue(static_cast<double>(constant)));
326}
327
328void
330{
331 NS_LOG_FUNCTION(this << constant.As(Time::S));
332 m_mainObjectGenerationDelayRng->SetAttribute("Constant", DoubleValue(constant.GetSeconds()));
333}
334
335void
337{
338 NS_LOG_FUNCTION(this);
339 const double a1 = std::pow(m_mainObjectSizeStdDev, 2.0);
340 const double a2 = std::pow(m_mainObjectSizeMean, 2.0);
341 const double a = std::log(1.0 + (a1 / a2));
342 const double mu = std::log(m_mainObjectSizeMean) - (0.5 * a);
343 const double sigma = std::sqrt(a);
344 NS_LOG_DEBUG(this << " Mu= " << mu << " Sigma= " << sigma << ".");
345 m_mainObjectSizeRng->SetAttribute("Mu", DoubleValue(mu));
346 m_mainObjectSizeRng->SetAttribute("Sigma", DoubleValue(sigma));
347}
348
349void
351{
352 NS_LOG_FUNCTION(this);
353 const double a1 = std::pow(m_embeddedObjectSizeStdDev, 2.0);
354 const double a2 = std::pow(m_embeddedObjectSizeMean, 2.0);
355 const double a = std::log(1.0 + (a1 / a2));
356 const double mu = std::log(m_embeddedObjectSizeMean) - (0.5 * a);
357 const double sigma = std::sqrt(a);
358 NS_LOG_DEBUG(this << " Mu= " << mu << " Sigma= " << sigma << ".");
359 m_embeddedObjectSizeRng->SetAttribute("Mu", DoubleValue(mu));
360 m_embeddedObjectSizeRng->SetAttribute("Sigma", DoubleValue(sigma));
361}
362
363void
365{
366 NS_LOG_FUNCTION(this << mean);
367 NS_ASSERT_MSG(mean > 0, "Mean must be greater than zero.");
369
370 if (IsInitialized())
371 {
373 }
374}
375
376void
378{
379 NS_LOG_FUNCTION(this << stdDev);
380 m_mainObjectSizeStdDev = stdDev;
381
382 if (IsInitialized())
383 {
385 }
386}
387
388void
390{
391 NS_LOG_FUNCTION(this << constant.As(Time::S));
392 m_embeddedObjectGenerationDelayRng->SetAttribute("Constant",
393 DoubleValue(constant.GetSeconds()));
394}
395
396void
398{
399 NS_LOG_FUNCTION(this << mean);
400 NS_ASSERT_MSG(mean > 0, "Mean must be greater than zero.");
402
403 if (IsInitialized())
404 {
406 }
407}
408
409void
420
421void
423{
424 NS_LOG_FUNCTION(this << max);
425 m_numOfEmbeddedObjectsRng->SetAttribute("Bound", DoubleValue(static_cast<double>(max)));
426}
427
428void
430{
431 NS_LOG_FUNCTION(this << shape);
432 NS_ASSERT_MSG(std::fabs(shape - 1.0) > 0.000001, "Shape parameter must not equal to 1.0.");
433 m_numOfEmbeddedObjectsRng->SetAttribute("Shape", DoubleValue(shape));
434}
435
436void
438{
439 NS_LOG_FUNCTION(this << scale);
440 NS_ASSERT_MSG(scale > 0, "Scale parameter must be greater than zero.");
442 m_numOfEmbeddedObjectsRng->SetAttribute("Scale", DoubleValue(scale));
443}
444
445void
447{
448 NS_LOG_FUNCTION(this << mean.As(Time::S));
449 m_readingTimeRng->SetAttribute("Mean", DoubleValue(mean.GetSeconds()));
450}
451
452void
454{
455 NS_LOG_FUNCTION(this << mean.As(Time::S));
456 m_parsingTimeRng->SetAttribute("Mean", DoubleValue(mean.GetSeconds()));
457}
458
459} // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
A base class which provides memory management and object aggregation.
Definition object.h:78
bool IsInitialized() const
Check if the object has been initialized.
Definition object.cc:240
uint32_t m_mainObjectSizeMax
Upper bound parameter for m_mainObjectSizeRng;.
Ptr< ExponentialRandomVariable > m_parsingTimeRng
Random variable for determining the length of parsing time (in seconds).
uint32_t m_mainObjectSizeMin
Lower bound parameter for m_mainObjectSizeRng;.
Ptr< LogNormalRandomVariable > m_embeddedObjectSizeRng
Random variable for determining embedded object size (in bytes).
uint32_t m_numOfEmbeddedObjectsScale
Scale parameter for m_numOfEmbeddedObjectsRng.
void SetMainObjectGenerationDelay(Time constant)
static TypeId GetTypeId()
Returns the object TypeId.
Ptr< ConstantRandomVariable > m_requestSizeRng
Random variable for determining request size (in bytes).
void SetEmbeddedObjectGenerationDelay(Time constant)
uint32_t GetMtuSize()
Draws a random value of maximum transmission unit (MTU) size in bytes.
uint32_t m_mainObjectSizeMean
Mean parameter for m_mainObjectSizeRng;.
void DoInitialize() override
Initialize() implementation.
Time GetEmbeddedObjectGenerationDelay()
Returns the constant length of time needed by an HTTP server to generate an embedded object.
void UpdateMainObjectMuAndSigma()
Upon and after object initialization, update random variable Mu and Sigma based on changes to attribu...
void SetMainObjectSizeStdDev(uint32_t stdDev)
Ptr< LogNormalRandomVariable > m_mainObjectSizeRng
Random variable for determining main object size (in bytes).
uint32_t m_embeddedObjectSizeMax
Upper bound parameter for m_embeddedObjectSizeRng.
void SetNumOfEmbeddedObjectsScale(uint32_t scale)
Ptr< ExponentialRandomVariable > m_readingTimeRng
Random variable for determining the length of reading time (in seconds).
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< ConstantRandomVariable > m_mainObjectGenerationDelayRng
Random variable for determining the delay needed to generate a main object (in seconds).
Time GetReadingTime()
Draws a random length of time which is spent by a hypothetical human user (HTTP client) to read a web...
Time GetMainObjectGenerationDelay()
Returns the constant length of time needed by an HTTP server to generate a main object.
uint32_t GetRequestSize()
Returns the constant HTTP request size in bytes.
uint32_t GetMainObjectSize()
Draws a random main object size (in bytes) to be sent by an HTTP server.
uint32_t m_mainObjectSizeStdDev
Standard deviation parameter for m_mainObjectSizeRng;.
Ptr< ParetoRandomVariable > m_numOfEmbeddedObjectsRng
Random variable for determining the number of embedded objects.
void SetEmbeddedObjectSizeMean(uint32_t mean)
uint32_t GetEmbeddedObjectSize()
Draws a random embedded object size (in bytes) to be sent by an HTTP server.
void SetEmbeddedObjectSizeStdDev(uint32_t stdDev)
double m_highMtuProbability
High MTU size probability.
uint32_t m_embeddedObjectSizeMean
Mean parameter for m_embeddedObjectSizeRng.
uint32_t m_embeddedObjectSizeStdDev
Standard deviation parameter for m_embeddedObjectSizeRng.
void UpdateEmbeddedObjectMuAndSigma()
Upon and after object initialization, update random variable Mu and Sigma based on changes to attribu...
void SetNumOfEmbeddedObjectsShape(double shape)
uint32_t m_highMtu
Higher MTU size.
uint32_t GetNumOfEmbeddedObjects()
Draws a random integer indicating the number of embedded objects in a main object.
uint32_t m_embeddedObjectSizeMin
Lower bound parameter for m_embeddedObjectSizeRng.
Ptr< ConstantRandomVariable > m_embeddedObjectGenerationDelayRng
Random variable for determining the delay needed to generate an embedded object (in seconds).
void SetRequestSize(uint32_t constant)
ThreeGppHttpVariables()
Create a new instance with default configuration of random distributions.
Ptr< UniformRandomVariable > m_mtuSizeRng
Random variable for determining MTU size (in bytes).
Time GetParsingTime()
Draws a random length of time which simulate the small delay caused by HTTP client looking for any em...
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:403
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
@ S
second
Definition nstime.h:105
AttributeValue implementation for Time.
Definition nstime.h:1432
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition double.h:32
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition nstime.h:1433
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1453
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition uinteger.h:35
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1357
log2() macro definition; to deal with Bug 1467 .
Every class exported by the ns3 library is enclosed in the ns3 namespace.