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
aodv-id-cache-test-suite.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 IITP RAS
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Based on
19
* NS-2 AODV model developed by the CMU/MONARCH group and optimized and
20
* tuned by Samir Das and Mahesh Marina, University of Cincinnati;
21
*
22
* AODV-UU implementation by Erik Nordström of Uppsala University
23
* http://core.it.uu.se/core/index.php/AODV-UU
24
*
25
* Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
26
* Pavel Boyko <boyko@iitp.ru>
27
*/
28
#include "ns3/aodv-id-cache.h"
29
#include "ns3/test.h"
30
31
namespace
ns3
32
{
33
namespace
aodv
34
{
35
36
//-----------------------------------------------------------------------------
37
// Tests
38
//-----------------------------------------------------------------------------
40
struct
IdCacheTest
:
public
TestCase
41
{
42
IdCacheTest
() :
TestCase
(
"Id Cache"
),
cache
(
Seconds
(10))
43
{}
44
virtual
void
DoRun
();
45
void
CheckTimeout1
();
46
void
CheckTimeout2
();
47
void
CheckTimeout3
();
48
49
IdCache
cache
;
50
};
51
52
void
53
IdCacheTest::DoRun
()
54
{
55
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetLifeTime
(),
Seconds
(10),
"Lifetime"
);
56
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 3),
false
,
"Unknown ID & address"
);
57
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 4),
false
,
"Unknown ID"
);
58
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"4.3.2.1"
), 3),
false
,
"Unknown address"
);
59
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 3),
true
,
"Known address & ID"
);
60
cache
.
SetLifetime
(
Seconds
(15));
61
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetLifeTime
(),
Seconds
(15),
"New lifetime"
);
62
cache
.
IsDuplicate
(
Ipv4Address
(
"1.1.1.1"
), 4);
63
cache
.
IsDuplicate
(
Ipv4Address
(
"1.1.1.1"
), 4);
64
cache
.
IsDuplicate
(
Ipv4Address
(
"2.2.2.2"
), 5);
65
cache
.
IsDuplicate
(
Ipv4Address
(
"3.3.3.3"
), 6);
66
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 6,
"trivial"
);
67
68
Simulator::Schedule
(
Seconds
(5), &
IdCacheTest::CheckTimeout1
,
this
);
69
Simulator::Schedule (
Seconds
(11), &
IdCacheTest::CheckTimeout2
,
this
);
70
Simulator::Schedule (
Seconds
(30), &
IdCacheTest::CheckTimeout3
,
this
);
71
Simulator::Run
();
72
Simulator::Destroy
();
73
}
74
75
void
76
IdCacheTest::CheckTimeout1
()
77
{
78
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 6,
"Nothing expire"
);
79
}
80
81
void
82
IdCacheTest::CheckTimeout2
()
83
{
84
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 3,
"3 records left"
);
85
}
86
87
void
88
IdCacheTest::CheckTimeout3
()
89
{
90
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 0,
"All records expire"
);
91
}
92
//-----------------------------------------------------------------------------
93
class
IdCacheTestSuite
:
public
TestSuite
94
{
95
public
:
96
IdCacheTestSuite
() :
TestSuite
(
"routing-id-cache"
,
UNIT
)
97
{
98
AddTestCase
(
new
IdCacheTest
);
99
}
100
}
g_idCacheTestSuite
;
101
102
}
103
}
src
aodv
test
aodv-id-cache-test-suite.cc
Generated on Fri Dec 21 2012 19:00:30 for ns-3 by
1.8.1.2