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 "
206 << " must be greater than"
207 << " the `MainObjectSizeMin` attribute.");
208 }
209
210 /*
211 * Repeatedly draw one new random value until it falls in the interval
212 * [min, max). The previous validation ensures this process does not loop
213 * indefinitely.
214 */
215 uint32_t value;
216 do
217 {
218 value = m_mainObjectSizeRng->GetInteger();
219 } while ((value < m_mainObjectSizeMin) || (value >= m_mainObjectSizeMax));
220
221 return value;
222}
223
224Time
229
232{
233 // Validate parameters.
235 {
236 NS_FATAL_ERROR("`EmbeddedObjectSizeMax` attribute "
237 << " must be greater than"
238 << " the `EmbeddedObjectSizeMin` attribute.");
239 }
240
241 /*
242 * Repeatedly draw one new random value until it falls in the interval
243 * [min, max). The previous validation ensures this process does not loop
244 * indefinitely.
245 */
246 uint32_t value;
247 do
248 {
249 value = m_embeddedObjectSizeRng->GetInteger();
250 } while ((value < m_embeddedObjectSizeMin) || (value >= m_embeddedObjectSizeMax));
251
252 return value;
253}
254
257{
258 // Validate parameters.
259 const auto upperBound = static_cast<uint32_t>(m_numOfEmbeddedObjectsRng->GetBound());
260 if (upperBound <= m_numOfEmbeddedObjectsScale)
261 {
262 NS_FATAL_ERROR("`NumOfEmbeddedObjectsMax` attribute "
263 << " must be greater than"
264 << " the `NumOfEmbeddedObjectsScale` attribute.");
265 }
266
267 /*
268 * Repeatedly draw one new random value until it falls in the interval
269 * [scale, upperBound). The previous validation ensures this process does
270 * not loop indefinitely.
271 */
272 uint32_t value;
273 do
274 {
275 value = m_numOfEmbeddedObjectsRng->GetInteger();
276 } while ((value < m_numOfEmbeddedObjectsScale) || (value >= upperBound));
277
278 /*
279 * Normalize the random value with the scale parameter. The returned value
280 * shall now be within the interval [0, (upperBound - scale)).
281 */
282 return (value - m_numOfEmbeddedObjectsScale);
283}
284
285Time
290
291Time
296
297int64_t
299{
300 NS_LOG_FUNCTION(this << stream);
301
302 m_mtuSizeRng->SetStream(stream);
303 m_requestSizeRng->SetStream(stream + 1);
304 m_mainObjectGenerationDelayRng->SetStream(stream + 2);
305 m_mainObjectSizeRng->SetStream(stream + 3);
306 m_embeddedObjectGenerationDelayRng->SetStream(stream + 4);
307 m_embeddedObjectSizeRng->SetStream(stream + 5);
308 m_numOfEmbeddedObjectsRng->SetStream(stream + 6);
309 m_readingTimeRng->SetStream(stream + 7);
310 m_parsingTimeRng->SetStream(stream + 8);
311
312 return 9;
313}
314
315void
322
323// SETTER METHODS /////////////////////////////////////////////////////////////
324
325void
327{
328 NS_LOG_FUNCTION(this << constant);
329 m_requestSizeRng->SetAttribute("Constant", DoubleValue(static_cast<double>(constant)));
330}
331
332void
334{
335 NS_LOG_FUNCTION(this << constant.As(Time::S));
336 m_mainObjectGenerationDelayRng->SetAttribute("Constant", DoubleValue(constant.GetSeconds()));
337}
338
339void
341{
342 NS_LOG_FUNCTION(this);
343 const double a1 = std::pow(m_mainObjectSizeStdDev, 2.0);
344 const double a2 = std::pow(m_mainObjectSizeMean, 2.0);
345 const double a = std::log(1.0 + (a1 / a2));
346 const double mu = std::log(m_mainObjectSizeMean) - (0.5 * a);
347 const double sigma = std::sqrt(a);
348 NS_LOG_DEBUG(this << " Mu= " << mu << " Sigma= " << sigma << ".");
349 m_mainObjectSizeRng->SetAttribute("Mu", DoubleValue(mu));
350 m_mainObjectSizeRng->SetAttribute("Sigma", DoubleValue(sigma));
351}
352
353void
355{
356 NS_LOG_FUNCTION(this);
357 const double a1 = std::pow(m_embeddedObjectSizeStdDev, 2.0);
358 const double a2 = std::pow(m_embeddedObjectSizeMean, 2.0);
359 const double a = std::log(1.0 + (a1 / a2));
360 const double mu = std::log(m_embeddedObjectSizeMean) - (0.5 * a);
361 const double sigma = std::sqrt(a);
362 NS_LOG_DEBUG(this << " Mu= " << mu << " Sigma= " << sigma << ".");
363 m_embeddedObjectSizeRng->SetAttribute("Mu", DoubleValue(mu));
364 m_embeddedObjectSizeRng->SetAttribute("Sigma", DoubleValue(sigma));
365}
366
367void
369{
370 NS_LOG_FUNCTION(this << mean);
371 NS_ASSERT_MSG(mean > 0, "Mean must be greater than zero.");
373
374 if (IsInitialized())
375 {
377 }
378}
379
380void
382{
383 NS_LOG_FUNCTION(this << stdDev);
384 m_mainObjectSizeStdDev = stdDev;
385
386 if (IsInitialized())
387 {
389 }
390}
391
392void
394{
395 NS_LOG_FUNCTION(this << constant.As(Time::S));
396 m_embeddedObjectGenerationDelayRng->SetAttribute("Constant",
397 DoubleValue(constant.GetSeconds()));
398}
399
400void
402{
403 NS_LOG_FUNCTION(this << mean);
404 NS_ASSERT_MSG(mean > 0, "Mean must be greater than zero.");
406
407 if (IsInitialized())
408 {
410 }
411}
412
413void
424
425void
427{
428 NS_LOG_FUNCTION(this << max);
429 m_numOfEmbeddedObjectsRng->SetAttribute("Bound", DoubleValue(static_cast<double>(max)));
430}
431
432void
434{
435 NS_LOG_FUNCTION(this << shape);
436 NS_ASSERT_MSG(std::fabs(shape - 1.0) > 0.000001, "Shape parameter must not equal to 1.0.");
437 m_numOfEmbeddedObjectsRng->SetAttribute("Shape", DoubleValue(shape));
438}
439
440void
442{
443 NS_LOG_FUNCTION(this << scale);
444 NS_ASSERT_MSG(scale > 0, "Scale parameter must be greater than zero.");
446 m_numOfEmbeddedObjectsRng->SetAttribute("Scale", DoubleValue(scale));
447}
448
449void
451{
452 NS_LOG_FUNCTION(this << mean.As(Time::S));
453 m_readingTimeRng->SetAttribute("Mean", DoubleValue(mean.GetSeconds()));
454}
455
456void
458{
459 NS_LOG_FUNCTION(this << mean.As(Time::S));
460 m_parsingTimeRng->SetAttribute("Mean", DoubleValue(mean.GetSeconds()));
461}
462
463} // 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:404
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
a unique identifier for an interface.
Definition type-id.h:48
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
#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:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
log2() macro definition; to deal with Bug 1467 .
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416