A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
rtt-test.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation;
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
*
16
*/
17
18
#include "ns3/test.h"
19
#include "ns3/core-module.h"
20
#include "ns3/internet-module.h"
21
#include "ns3/rtt-estimator.h"
22
#include "ns3/log.h"
23
24
NS_LOG_COMPONENT_DEFINE
(
"RttTestSuite"
);
25
26
using namespace
ns3;
27
28
class
RttTestCase
:
public
TestCase
29
{
30
public
:
31
RttTestCase
(
double
mean,
32
double
variance,
33
double
gain);
34
35
private
:
36
virtual
void
DoRun (
void
);
37
virtual
void
DoTeardown (
void
);
38
39
double
m_mean
;
40
double
m_variance
;
41
double
m_gain
;
42
43
};
44
45
RttTestCase::RttTestCase
(
double
mean,
46
double
variance,
47
double
gain)
48
:
TestCase
(
"Rtt Estimate Test"
),
49
m_mean (mean),
50
m_variance (variance),
51
m_gain (gain)
52
{
53
}
54
55
void
56
RttTestCase::DoRun
(
void
)
57
{
58
Config::SetDefault
(
"ns3::RttEstimator::InitialEstimation"
,
TimeValue
(
MilliSeconds
(
m_mean
)));
59
Config::SetDefault
(
"ns3::RttMeanDeviation::Gain"
,
DoubleValue
(
m_gain
));
60
Config::SetDefault
(
"ns3::RttEstimator::MinRTO"
,
TimeValue
(
Seconds
(0)));
61
62
Ptr<RttMeanDeviation>
rtt = CreateObject<RttMeanDeviation> ();
63
Ptr<NormalRandomVariable>
nv = CreateObject<NormalRandomVariable> ();
64
nv->
SetAttribute
(
"Mean"
,
DoubleValue
(
m_mean
));
65
nv->SetAttribute (
"Variance"
,
DoubleValue
(
m_variance
));
66
67
NS_TEST_EXPECT_MSG_EQ
(
m_mean
, rtt->
GetCurrentEstimate
().
GetMilliSeconds
(),
"Initial estimate should match mean"
);
68
69
double
a, v, g;
70
a = v =
m_mean
;
71
g =
m_gain
;
72
73
for
(uint32_t i = 0; i < 10000; ++i)
74
{
75
int
measurement = nv->GetInteger ();
76
rtt->
Measurement
(Time::FromInteger (measurement, Time::MS));
77
double
err = (measurement - a);
78
a = a + g * err;
79
v = v + g * (std::abs (err) - v);
80
}
81
82
//5% tolerance
83
double
tolerance =
m_mean
* .05;
84
85
NS_TEST_ASSERT_MSG_EQ_TOL
(
m_mean
, rtt->
GetCurrentEstimate
().
GetMilliSeconds
(), tolerance,
"Unexpected estimate"
);
86
87
int
expectedTimeout = (int)a + 4 * (
int
)v;
88
89
NS_TEST_EXPECT_MSG_EQ
(rtt->
RetransmitTimeout
().
GetMilliSeconds
(), expectedTimeout,
"Timeout values do not match"
);
90
}
91
void
92
RttTestCase::DoTeardown
(
void
)
93
{
94
}
95
96
97
static
class
RttTestSuite
:
public
TestSuite
98
{
99
public
:
100
RttTestSuite
()
101
:
TestSuite
(
"rtt"
,
UNIT
)
102
{
103
AddTestCase
(
new
RttTestCase
(150.0, 10.0, .1), TestCase::QUICK);
104
AddTestCase
(
new
RttTestCase
(5000.0, 5.0, .5), TestCase::QUICK);
105
AddTestCase
(
new
RttTestCase
(200.0, 25.0, .7), TestCase::QUICK);
106
}
107
108
}
g_tcpTestSuite
;
src
internet
test
rtt-test.cc
Generated on Tue May 14 2013 11:08:24 for ns-3 by
1.8.1.2