A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
aodv-id-cache-test-suite.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 IITP RAS
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Based on
7
* NS-2 AODV model developed by the CMU/MONARCH group and optimized and
8
* tuned by Samir Das and Mahesh Marina, University of Cincinnati;
9
*
10
* AODV-UU implementation by Erik Nordström of Uppsala University
11
* https://web.archive.org/web/20100527072022/http://core.it.uu.se/core/index.php/AODV-UU
12
*
13
* Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
14
* Pavel Boyko <boyko@iitp.ru>
15
*/
16
#include "ns3/aodv-id-cache.h"
17
#include "ns3/test.h"
18
19
namespace
ns3
20
{
21
namespace
aodv
22
{
23
24
/**
25
* @defgroup aodv-test AODV module tests
26
* @ingroup aodv
27
* @ingroup tests
28
*/
29
30
/**
31
* @ingroup aodv-test
32
*
33
* @brief Unit test for id cache
34
*/
35
class
IdCacheTest
:
public
TestCase
36
{
37
public
:
38
IdCacheTest
()
39
:
TestCase
(
"Id Cache"
),
40
cache
(
Seconds
(10))
41
{
42
}
43
44
void
DoRun
()
override
;
45
46
private
:
47
/// Timeout test function #1
48
void
CheckTimeout1
();
49
/// Timeout test function #2
50
void
CheckTimeout2
();
51
/// Timeout test function #3
52
void
CheckTimeout3
();
53
54
/// ID cache
55
IdCache
cache
;
56
};
57
58
void
59
IdCacheTest::DoRun
()
60
{
61
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetLifeTime
(),
Seconds
(10),
"Lifetime"
);
62
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 3),
63
false
,
64
"Unknown ID & address"
);
65
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 4),
false
,
"Unknown ID"
);
66
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"4.3.2.1"
), 3),
false
,
"Unknown address"
);
67
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 3),
true
,
"Known address & ID"
);
68
cache
.
SetLifetime
(
Seconds
(15));
69
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetLifeTime
(),
Seconds
(15),
"New lifetime"
);
70
cache
.
IsDuplicate
(
Ipv4Address
(
"1.1.1.1"
), 4);
71
cache
.
IsDuplicate
(
Ipv4Address
(
"1.1.1.1"
), 4);
72
cache
.
IsDuplicate
(
Ipv4Address
(
"2.2.2.2"
), 5);
73
cache
.
IsDuplicate
(
Ipv4Address
(
"3.3.3.3"
), 6);
74
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 6,
"trivial"
);
75
76
Simulator::Schedule
(
Seconds
(5), &
IdCacheTest::CheckTimeout1
,
this
);
77
Simulator::Schedule
(
Seconds
(11), &
IdCacheTest::CheckTimeout2
,
this
);
78
Simulator::Schedule
(
Seconds
(30), &
IdCacheTest::CheckTimeout3
,
this
);
79
Simulator::Run
();
80
Simulator::Destroy
();
81
}
82
83
void
84
IdCacheTest::CheckTimeout1
()
85
{
86
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 6,
"Nothing expire"
);
87
}
88
89
void
90
IdCacheTest::CheckTimeout2
()
91
{
92
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 3,
"3 records left"
);
93
}
94
95
void
96
IdCacheTest::CheckTimeout3
()
97
{
98
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 0,
"All records expire"
);
99
}
100
101
/**
102
* @ingroup aodv-test
103
*
104
* @brief Id Cache Test Suite
105
*/
106
class
IdCacheTestSuite
:
public
TestSuite
107
{
108
public
:
109
IdCacheTestSuite
()
110
:
TestSuite
(
"aodv-routing-id-cache"
,
Type
::
UNIT
)
111
{
112
AddTestCase
(
new
IdCacheTest
,
TestCase::Duration::QUICK
);
113
}
114
}
g_idCacheTestSuite
;
///< the test suite
115
116
}
// namespace aodv
117
}
// namespace ns3
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Simulator::Schedule
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition
simulator.h:560
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestCase::Duration::QUICK
@ QUICK
Fast test.
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
ns3::aodv::IdCache
Unique packets identification cache used for simple duplicate detection.
Definition
aodv-id-cache.h:35
ns3::aodv::IdCache::SetLifetime
void SetLifetime(Time lifetime)
Set lifetime for future added entries.
Definition
aodv-id-cache.h:64
ns3::aodv::IdCache::GetLifeTime
Time GetLifeTime() const
Return lifetime for existing entries in cache.
Definition
aodv-id-cache.h:73
ns3::aodv::IdCache::IsDuplicate
bool IsDuplicate(Ipv4Address addr, uint32_t id)
Check that entry (addr, id) exists in cache.
Definition
aodv-id-cache.cc:25
ns3::aodv::IdCache::GetSize
uint32_t GetSize()
Definition
aodv-id-cache.cc:47
ns3::aodv::IdCacheTest
Unit test for id cache.
Definition
aodv-id-cache-test-suite.cc:36
ns3::aodv::IdCacheTest::cache
IdCache cache
ID cache.
Definition
aodv-id-cache-test-suite.cc:55
ns3::aodv::IdCacheTest::CheckTimeout3
void CheckTimeout3()
Timeout test function #3.
Definition
aodv-id-cache-test-suite.cc:96
ns3::aodv::IdCacheTest::CheckTimeout2
void CheckTimeout2()
Timeout test function #2.
Definition
aodv-id-cache-test-suite.cc:90
ns3::aodv::IdCacheTest::CheckTimeout1
void CheckTimeout1()
Timeout test function #1.
Definition
aodv-id-cache-test-suite.cc:84
ns3::aodv::IdCacheTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
aodv-id-cache-test-suite.cc:59
ns3::aodv::IdCacheTest::IdCacheTest
IdCacheTest()
Definition
aodv-id-cache-test-suite.cc:38
ns3::aodv::IdCacheTestSuite
Id Cache Test Suite.
Definition
aodv-id-cache-test-suite.cc:107
ns3::aodv::IdCacheTestSuite::IdCacheTestSuite
IdCacheTestSuite()
Definition
aodv-id-cache-test-suite.cc:109
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:241
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
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 Tue Dec 10 2024 18:20:36 for ns-3 by
1.11.0