This documentation is not the
Latest Release
.
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
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
class
IdCacheTest
:
public
TestCase
41
{
42
public
:
43
IdCacheTest
() :
TestCase
(
"Id Cache"
),
cache
(
Seconds
(10))
44
{}
45
virtual
void
DoRun
();
46
47
private
:
48
void
CheckTimeout1
();
49
void
CheckTimeout2
();
50
void
CheckTimeout3
();
51
52
IdCache
cache
;
53
};
54
55
void
56
IdCacheTest::DoRun
()
57
{
58
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetLifeTime
(),
Seconds
(10),
"Lifetime"
);
59
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 3),
false
,
"Unknown ID & address"
);
60
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 4),
false
,
"Unknown ID"
);
61
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"4.3.2.1"
), 3),
false
,
"Unknown address"
);
62
NS_TEST_EXPECT_MSG_EQ
(
cache
.
IsDuplicate
(
Ipv4Address
(
"1.2.3.4"
), 3),
true
,
"Known address & ID"
);
63
cache
.
SetLifetime
(
Seconds
(15));
64
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetLifeTime
(),
Seconds
(15),
"New lifetime"
);
65
cache
.
IsDuplicate
(
Ipv4Address
(
"1.1.1.1"
), 4);
66
cache
.
IsDuplicate
(
Ipv4Address
(
"1.1.1.1"
), 4);
67
cache
.
IsDuplicate
(
Ipv4Address
(
"2.2.2.2"
), 5);
68
cache
.
IsDuplicate
(
Ipv4Address
(
"3.3.3.3"
), 6);
69
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 6,
"trivial"
);
70
71
Simulator::Schedule
(
Seconds
(5), &
IdCacheTest::CheckTimeout1
,
this
);
72
Simulator::Schedule
(
Seconds
(11), &
IdCacheTest::CheckTimeout2
,
this
);
73
Simulator::Schedule
(
Seconds
(30), &
IdCacheTest::CheckTimeout3
,
this
);
74
Simulator::Run
();
75
Simulator::Destroy
();
76
}
77
78
void
79
IdCacheTest::CheckTimeout1
()
80
{
81
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 6,
"Nothing expire"
);
82
}
83
84
void
85
IdCacheTest::CheckTimeout2
()
86
{
87
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 3,
"3 records left"
);
88
}
89
90
void
91
IdCacheTest::CheckTimeout3
()
92
{
93
NS_TEST_EXPECT_MSG_EQ
(
cache
.
GetSize
(), 0,
"All records expire"
);
94
}
95
//-----------------------------------------------------------------------------
96
class
IdCacheTestSuite
:
public
TestSuite
97
{
98
public
:
99
IdCacheTestSuite
() :
TestSuite
(
"aodv-routing-id-cache"
,
UNIT
)
100
{
101
AddTestCase
(
new
IdCacheTest
,
TestCase::QUICK
);
102
}
103
}
g_idCacheTestSuite
;
104
105
}
106
}
ns3::aodv::IdCacheTest::cache
IdCache cache
Definition:
aodv-id-cache-test-suite.cc:52
ns3::aodv::IdCacheTest::CheckTimeout1
void CheckTimeout1()
Definition:
aodv-id-cache-test-suite.cc:79
ns3::TestCase::QUICK
Fast test.
Definition:
test.h:1152
ns3::aodv::IdCache
Unique packets identification cache used for simple duplicate detection.
Definition:
aodv-id-cache.h:45
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1333
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition:
simulator.cc:200
ns3::aodv::IdCacheTest::IdCacheTest
IdCacheTest()
Definition:
aodv-id-cache-test-suite.cc:43
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:278
ns3::aodv::IdCacheTest
Unit test for id cache.
Definition:
aodv-id-cache-test-suite.cc:40
ns3::TestCase
encapsulates test code
Definition:
test.h:1147
ns3::TestSuite::UNIT
This test suite implements a Unit Test.
Definition:
test.h:1343
ns3::aodv::g_idCacheTestSuite
ns3::aodv::IdCacheTestSuite g_idCacheTestSuite
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition:
simulator.h:1216
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition:
test.cc:297
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:164
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::aodv::IdCache::GetSize
uint32_t GetSize()
Return number of entries in cache.
Definition:
aodv-id-cache.cc:56
ns3::aodv::IdCacheTestSuite::IdCacheTestSuite
IdCacheTestSuite()
Definition:
aodv-id-cache-test-suite.cc:99
ns3::aodv::IdCache::GetLifeTime
Time GetLifeTime() const
Return lifetime for existing entries in cache.
Definition:
aodv-id-cache.h:59
ns3::aodv::IdCache::SetLifetime
void SetLifetime(Time lifetime)
Set lifetime for future added entries.
Definition:
aodv-id-cache.h:57
ns3::aodv::IdCacheTest::CheckTimeout2
void CheckTimeout2()
Definition:
aodv-id-cache-test-suite.cc:85
ns3::aodv::IdCacheTestSuite
Definition:
aodv-id-cache-test-suite.cc:96
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:40
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:895
ns3::aodv::IdCache::IsDuplicate
bool IsDuplicate(Ipv4Address addr, uint32_t id)
Check that entry (addr, id) exists in cache. Add entry, if it doesn't exist.
Definition:
aodv-id-cache.cc:36
ns3::aodv::IdCacheTest::CheckTimeout3
void CheckTimeout3()
Definition:
aodv-id-cache-test-suite.cc:91
ns3::aodv::IdCacheTest::DoRun
virtual void DoRun()
Implementation to actually run this TestCase.
Definition:
aodv-id-cache-test-suite.cc:56
src
aodv
test
aodv-id-cache-test-suite.cc
Generated on Wed Nov 11 2015 20:00:25 for ns-3 by
1.8.9.1