A Discrete-Event Network Simulator
API
three-gpp-http-variables.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Magister Solutions
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Budiarto Herman <budiarto.herman@magister.fi>
18 *
19 */
20
22
23#include <ns3/double.h>
24#include <ns3/log.h>
25#include <ns3/uinteger.h>
26
27#include <math.h>
28
29NS_LOG_COMPONENT_DEFINE("ThreeGppHttpVariables");
30
31namespace ns3
32{
33
34NS_OBJECT_ENSURE_REGISTERED(ThreeGppHttpVariables);
35
37{
38 NS_LOG_FUNCTION(this);
39 m_mtuSizeRng = CreateObject<UniformRandomVariable>();
40 m_requestSizeRng = CreateObject<ConstantRandomVariable>();
41 m_mainObjectGenerationDelayRng = CreateObject<ConstantRandomVariable>();
42 m_mainObjectSizeRng = CreateObject<LogNormalRandomVariable>();
43 m_embeddedObjectGenerationDelayRng = CreateObject<ConstantRandomVariable>();
44 m_embeddedObjectSizeRng = CreateObject<LogNormalRandomVariable>();
45 m_numOfEmbeddedObjectsRng = CreateObject<ParetoRandomVariable>();
46 m_readingTimeRng = CreateObject<ExponentialRandomVariable>();
47 m_parsingTimeRng = CreateObject<ExponentialRandomVariable>();
48}
49
50// static
53{
54 static TypeId tid =
55 TypeId("ns3::ThreeGppHttpVariables")
57 .AddConstructor<ThreeGppHttpVariables>()
58
59 // REQUEST SIZE
60 .AddAttribute("RequestSize",
61 "The constant size of HTTP request packet (in bytes).",
62 UintegerValue(328),
64 MakeUintegerChecker<uint32_t>())
65
66 // MAIN OBJECT GENERATION DELAY
67 .AddAttribute("MainObjectGenerationDelay",
68 "The constant time needed by HTTP server "
69 "to generate a main object as a response.",
73
74 // MAIN OBJECT SIZE
75 .AddAttribute("MainObjectSizeMean",
76 "The mean of main object sizes (in bytes).",
77 UintegerValue(10710),
79 MakeUintegerChecker<uint32_t>())
80 .AddAttribute("MainObjectSizeStdDev",
81 "The standard deviation of main object sizes (in bytes).",
82 UintegerValue(25032),
84 MakeUintegerChecker<uint32_t>())
85 .AddAttribute("MainObjectSizeMin",
86 "The minimum value of main object sizes (in bytes).",
87 UintegerValue(100),
89 MakeUintegerChecker<uint32_t>(22))
90 .AddAttribute("MainObjectSizeMax",
91 "The maximum value of main object sizes (in bytes).",
92 UintegerValue(2000000), // 2 MB
94 MakeUintegerChecker<uint32_t>())
95
96 // EMBEDDED OBJECT GENERATION DELAY
97 .AddAttribute(
98 "EmbeddedObjectGenerationDelay",
99 "The constant time needed by HTTP server "
100 "to generate an embedded object as a response.",
104
105 // EMBEDDED OBJECT SIZE
106 .AddAttribute("EmbeddedObjectSizeMean",
107 "The mean of embedded object sizes (in bytes).",
108 UintegerValue(7758),
110 MakeUintegerChecker<uint32_t>())
111 .AddAttribute("EmbeddedObjectSizeStdDev",
112 "The standard deviation of embedded object sizes (in bytes).",
113 UintegerValue(126168),
115 MakeUintegerChecker<uint32_t>())
116 .AddAttribute("EmbeddedObjectSizeMin",
117 "The minimum value of embedded object sizes (in bytes).",
118 UintegerValue(50),
120 MakeUintegerChecker<uint32_t>(22))
121 .AddAttribute("EmbeddedObjectSizeMax",
122 "The maximum value of embedded object sizes (in bytes).",
123 UintegerValue(2000000), // 2 MB
125 MakeUintegerChecker<uint32_t>())
126
127 // NUMBER OF EMBEDDED OBJECTS PER PAGE
128 .AddAttribute("NumOfEmbeddedObjectsMax",
129 "The upper bound parameter of Pareto distribution for "
130 "the number of embedded objects per web page. The actual "
131 "maximum value is this value subtracted by the scale parameter.",
132 UintegerValue(55),
134 MakeUintegerChecker<uint32_t>())
135 .AddAttribute("NumOfEmbeddedObjectsShape",
136 "The shape parameter of Pareto distribution for "
137 "the number of embedded objects per web page.",
138 DoubleValue(1.1),
140 MakeDoubleChecker<double>())
141 .AddAttribute(
142 "NumOfEmbeddedObjectsScale",
143 "The scale parameter of Pareto distribution for "
144 "the number of embedded objects per web page.",
145 UintegerValue(2),
147 MakeUintegerChecker<uint32_t>())
148
149 // READING TIME
150 .AddAttribute("ReadingTimeMean",
151 "The mean of reading time.",
152 TimeValue(Seconds(30)),
155
156 // PARSING TIME
157 .AddAttribute("ParsingTimeMean",
158 "The mean of parsing time.",
162
163 // MTU SIZE
164 .AddAttribute("LowMtuSize",
165 "The lower MTU size.",
166 UintegerValue(536),
168 MakeUintegerChecker<uint32_t>(0))
169 .AddAttribute("HighMtuSize",
170 "The higher MTU size.",
171 UintegerValue(1460),
173 MakeUintegerChecker<uint32_t>(0))
174 .AddAttribute("HighMtuProbability",
175 "The probability that higher MTU size is used.",
176 DoubleValue(0.76),
178 MakeDoubleChecker<double>(0, 1));
179 return tid;
180}
181
184{
185 const double r = m_mtuSizeRng->GetValue();
186 NS_ASSERT(r >= 0.0);
187 NS_ASSERT(r < 1.0);
188 if (r < m_highMtuProbability)
189 {
190 return m_highMtu; // 1500 bytes if including TCP header.
191 }
192 else
193 {
194 return m_lowMtu; // 576 bytes if including TCP header.
195 }
196}
197
200{
202}
203
204Time
206{
208}
209
212{
213 // Validate parameters.
215 {
216 NS_FATAL_ERROR("`MainObjectSizeMax` attribute "
217 << " must be greater than"
218 << " the `MainObjectSizeMin` attribute.");
219 }
220
221 /*
222 * Repeatedly draw one new random value until it falls in the interval
223 * [min, max). The previous validation ensures this process does not loop
224 * indefinitely.
225 */
227 do
228 {
229 value = m_mainObjectSizeRng->GetInteger();
231
232 return value;
233}
234
235Time
237{
239}
240
243{
244 // Validate parameters.
246 {
247 NS_FATAL_ERROR("`EmbeddedObjectSizeMax` attribute "
248 << " must be greater than"
249 << " the `EmbeddedObjectSizeMin` attribute.");
250 }
251
252 /*
253 * Repeatedly draw one new random value until it falls in the interval
254 * [min, max). The previous validation ensures this process does not loop
255 * indefinitely.
256 */
258 do
259 {
260 value = m_embeddedObjectSizeRng->GetInteger();
262
263 return value;
264}
265
268{
269 // Validate parameters.
270 const uint32_t upperBound = static_cast<uint32_t>(m_numOfEmbeddedObjectsRng->GetBound());
271 if (upperBound <= m_numOfEmbeddedObjectsScale)
272 {
273 NS_FATAL_ERROR("`NumOfEmbeddedObjectsMax` attribute "
274 << " must be greater than"
275 << " the `NumOfEmbeddedObjectsScale` attribute.");
276 }
277
278 /*
279 * Repeatedly draw one new random value until it falls in the interval
280 * [scale, upperBound). The previous validation ensures this process does
281 * not loop indefinitely.
282 */
284 do
285 {
286 value = m_numOfEmbeddedObjectsRng->GetInteger();
287 } while ((value < m_numOfEmbeddedObjectsScale) || (value >= upperBound));
288
289 /*
290 * Normalize the random value with the scale parameter. The returned value
291 * shall now be within the interval [0, (upperBound - scale)).
292 */
294}
295
296Time
298{
300}
301
302Time
304{
306}
307
308int64_t
310{
311 NS_LOG_FUNCTION(this << stream);
312
313 m_mtuSizeRng->SetStream(stream);
314 m_requestSizeRng->SetStream(stream + 1);
316 m_mainObjectSizeRng->SetStream(stream + 3);
318 m_embeddedObjectSizeRng->SetStream(stream + 5);
319 m_numOfEmbeddedObjectsRng->SetStream(stream + 6);
320 m_readingTimeRng->SetStream(stream + 7);
321 m_parsingTimeRng->SetStream(stream + 8);
322
323 return 9;
324}
325
326void
328{
329 NS_LOG_FUNCTION(this);
332}
333
334// SETTER METHODS /////////////////////////////////////////////////////////////
335
336void
338{
339 NS_LOG_FUNCTION(this << constant);
340 m_requestSizeRng->SetAttribute("Constant", DoubleValue(static_cast<double>(constant)));
341}
342
343void
345{
346 NS_LOG_FUNCTION(this << constant.As(Time::S));
348}
349
350void
352{
353 NS_LOG_FUNCTION(this);
354 const double a1 = std::pow(m_mainObjectSizeStdDev, 2.0);
355 const double a2 = std::pow(m_mainObjectSizeMean, 2.0);
356 const double a = std::log(1.0 + (a1 / a2));
357 const double mu = std::log(m_mainObjectSizeMean) - (0.5 * a);
358 const double sigma = std::sqrt(a);
359 NS_LOG_DEBUG(this << " Mu= " << mu << " Sigma= " << sigma << ".");
360 m_mainObjectSizeRng->SetAttribute("Mu", DoubleValue(mu));
361 m_mainObjectSizeRng->SetAttribute("Sigma", DoubleValue(sigma));
362}
363
364void
366{
367 NS_LOG_FUNCTION(this);
368 const double a1 = std::pow(m_embeddedObjectSizeStdDev, 2.0);
369 const double a2 = std::pow(m_embeddedObjectSizeMean, 2.0);
370 const double a = std::log(1.0 + (a1 / a2));
371 const double mu = std::log(m_embeddedObjectSizeMean) - (0.5 * a);
372 const double sigma = std::sqrt(a);
373 NS_LOG_DEBUG(this << " Mu= " << mu << " Sigma= " << sigma << ".");
374 m_embeddedObjectSizeRng->SetAttribute("Mu", DoubleValue(mu));
375 m_embeddedObjectSizeRng->SetAttribute("Sigma", DoubleValue(sigma));
376}
377
378void
380{
381 NS_LOG_FUNCTION(this << mean);
382 NS_ASSERT_MSG(mean > 0, "Mean must be greater than zero.");
384
385 if (IsInitialized())
386 {
388 }
389}
390
391void
393{
394 NS_LOG_FUNCTION(this << stdDev);
395 m_mainObjectSizeStdDev = stdDev;
396
397 if (IsInitialized())
398 {
400 }
401}
402
403void
405{
406 NS_LOG_FUNCTION(this << constant.As(Time::S));
408 DoubleValue(constant.GetSeconds()));
409}
410
411void
413{
414 NS_LOG_FUNCTION(this << mean);
415 NS_ASSERT_MSG(mean > 0, "Mean must be greater than zero.");
417
418 if (IsInitialized())
419 {
421 }
422}
423
424void
426{
427 NS_LOG_FUNCTION(this << stdDev);
429
430 if (IsInitialized())
431 {
433 }
434}
435
436void
438{
439 NS_LOG_FUNCTION(this << max);
440 m_numOfEmbeddedObjectsRng->SetAttribute("Bound", DoubleValue(static_cast<double>(max)));
441}
442
443void
445{
446 NS_LOG_FUNCTION(this << shape);
447 NS_ASSERT_MSG(std::fabs(shape - 1.0) > 0.000001, "Shape parameter must not equal to 1.0.");
448 m_numOfEmbeddedObjectsRng->SetAttribute("Shape", DoubleValue(shape));
449}
450
451void
453{
454 NS_LOG_FUNCTION(this << scale);
455 NS_ASSERT_MSG(scale > 0, "Scale parameter must be greater than zero.");
457 m_numOfEmbeddedObjectsRng->SetAttribute("Scale", DoubleValue(scale));
458}
459
460void
462{
463 NS_LOG_FUNCTION(this << mean.As(Time::S));
465}
466
467void
469{
470 NS_LOG_FUNCTION(this << mean.As(Time::S));
472}
473
474} // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
double GetValue(double constant)
Get the next random value, as a double equal to the argument.
uint32_t GetInteger(uint32_t constant)
Get the next random value, as an integer equal to the argument.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
double GetValue(double mean, double bound)
Get the next random value, as a double from the exponential distribution with the specified mean and ...
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:200
A base class which provides memory management and object aggregation.
Definition: object.h:89
bool IsInitialized() const
Check if the object has been initialized.
Definition: object.cc:212
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
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)
void SetNumOfEmbeddedObjectsMax(uint32_t max)
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...
uint32_t m_lowMtu
Lower MTU size.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:417
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
@ S
second
Definition: nstime.h:116
AttributeValue implementation for Time.
Definition: nstime.h:1423
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Hold an unsigned integer type.
Definition: uinteger.h:45
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1424
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:160
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
log2() macro definition; to deal with Bug 1467.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:535
value
Definition: second.py:41