A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
aodv-id-cache-test-suite.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 IITP RAS
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
* Based on
18
* NS-2 AODV model developed by the CMU/MONARCH group and optimized and
19
* tuned by Samir Das and Mahesh Marina, University of Cincinnati;
20
*
21
* AODV-UU implementation by Erik Nordström of Uppsala University
22
* https://web.archive.org/web/20100527072022/http://core.it.uu.se/core/index.php/AODV-UU
23
*
24
* Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
25
* Pavel Boyko <boyko@iitp.ru>
26
*/
27
#include "ns3/aodv-id-cache.h"
28
#include "ns3/test.h"
29
30
namespace
ns3
31
{
32
namespace
aodv
33
{
34
46
class
IdCacheTest
:
public
TestCase
47
{
48
public
:
49
IdCacheTest
()
50
:
TestCase
(
"Id Cache"
),
51
cache
(
Seconds
(10))
52
{
53
}
54
55
void
DoRun
()
override
;
56
57
private
:
59
void
CheckTimeout1
();
61
void
CheckTimeout2
();
63
void
CheckTimeout3
();
64
66
IdCache
cache
;
67
};
68
69
void
70
IdCacheTest::DoRun
()
71
{
72
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetLifeTime
(),
Seconds
(10),
"Lifetime"
);
73
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 3),
74
false
,
75
"Unknown ID & address"
);
76
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 4),
false
,
"Unknown ID"
);
77
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"4.3.2.1"
), 3),
false
,
"Unknown address"
);
78
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 3),
true
,
"Known address & ID"
);
79
cache
.
SetLifetime
(
Seconds
(15));
80
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetLifeTime
(),
Seconds
(15),
"New lifetime"
);
81
cache
.
IsDuplicate
(
Ipv4Address
(
"1.1.1.1"
), 4);
82
cache
.
IsDuplicate
(
Ipv4Address
(
"1.1.1.1"
), 4);
83
cache
.
IsDuplicate
(
Ipv4Address
(
"2.2.2.2"
), 5);
84
cache
.
IsDuplicate
(
Ipv4Address
(
"3.3.3.3"
), 6);
85
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 6,
"trivial"
);
86
87
Simulator::Schedule
(
Seconds
(5), &
IdCacheTest::CheckTimeout1
,
this
);
88
Simulator::Schedule
(
Seconds
(11), &
IdCacheTest::CheckTimeout2
,
this
);
89
Simulator::Schedule
(
Seconds
(30), &
IdCacheTest::CheckTimeout3
,
this
);
90
Simulator::Run
();
91
Simulator::Destroy
();
92
}
93
94
void
95
IdCacheTest::CheckTimeout1
()
96
{
97
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 6,
"Nothing expire"
);
98
}
99
100
void
101
IdCacheTest::CheckTimeout2
()
102
{
103
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 3,
"3 records left"
);
104
}
105
106
void
107
IdCacheTest::CheckTimeout3
()
108
{
109
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 0,
"All records expire"
);
110
}
111
117
class
IdCacheTestSuite
:
public
TestSuite
118
{
119
public
:
120
IdCacheTestSuite
()
121
:
TestSuite
(
"aodv-routing-id-cache"
,
UNIT
)
122
{
123
AddTestCase
(
new
IdCacheTest
,
TestCase::QUICK
);
124
}
125
}
g_idCacheTestSuite
;
126
127
}
// namespace aodv
128
}
// namespace ns3
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:42
ns3::Simulator::Schedule
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition:
simulator.h:571
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:142
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:178
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::QUICK
@ QUICK
Fast test.
Definition:
test.h:1065
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition:
test.h:1265
ns3::aodv::IdCache
Unique packets identification cache used for simple duplicate detection.
Definition:
aodv-id-cache.h:46
ns3::aodv::IdCache::SetLifetime
void SetLifetime(Time lifetime)
Set lifetime for future added entries.
Definition:
aodv-id-cache.h:75
ns3::aodv::IdCache::GetLifeTime
Time GetLifeTime() const
Return lifetime for existing entries in cache.
Definition:
aodv-id-cache.h:84
ns3::aodv::IdCache::IsDuplicate
bool IsDuplicate(Ipv4Address addr, uint32_t id)
Check that entry (addr, id) exists in cache.
Definition:
aodv-id-cache.cc:36
ns3::aodv::IdCache::GetSize
uint32_t GetSize()
Definition:
aodv-id-cache.cc:58
ns3::aodv::IdCacheTest
Unit test for id cache.
Definition:
aodv-id-cache-test-suite.cc:47
ns3::aodv::IdCacheTest::cache
IdCache cache
ID cache.
Definition:
aodv-id-cache-test-suite.cc:66
ns3::aodv::IdCacheTest::CheckTimeout3
void CheckTimeout3()
Timeout test function #3.
Definition:
aodv-id-cache-test-suite.cc:107
ns3::aodv::IdCacheTest::CheckTimeout2
void CheckTimeout2()
Timeout test function #2.
Definition:
aodv-id-cache-test-suite.cc:101
ns3::aodv::IdCacheTest::CheckTimeout1
void CheckTimeout1()
Timeout test function #1.
Definition:
aodv-id-cache-test-suite.cc:95
ns3::aodv::IdCacheTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
aodv-id-cache-test-suite.cc:70
ns3::aodv::IdCacheTest::IdCacheTest
IdCacheTest()
Definition:
aodv-id-cache-test-suite.cc:49
ns3::aodv::IdCacheTestSuite
Id Cache Test Suite.
Definition:
aodv-id-cache-test-suite.cc:118
ns3::aodv::IdCacheTestSuite::IdCacheTestSuite
IdCacheTestSuite()
Definition:
aodv-id-cache-test-suite.cc:120
ns3::aodv::g_idCacheTestSuite
ns3::aodv::IdCacheTestSuite g_idCacheTestSuite
the test suite
NS_TEST_EXPECT_MSG_EQ
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition:
test.h:251
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1326
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
aodv
test
aodv-id-cache-test-suite.cc
Generated on Sun Mar 3 2024 17:10:53 for ns-3 by
1.9.1