A Discrete-Event Network Simulator
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 * 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
30namespace ns3
31{
32namespace aodv
33{
34
35/**
36 * \defgroup aodv-test AODV module tests
37 * \ingroup aodv
38 * \ingroup tests
39 */
40
41/**
42 * \ingroup aodv-test
43 *
44 * \brief Unit test for id cache
45 */
46class IdCacheTest : public TestCase
47{
48 public:
50 : TestCase("Id Cache"),
51 cache(Seconds(10))
52 {
53 }
54
55 void DoRun() override;
56
57 private:
58 /// Timeout test function #1
59 void CheckTimeout1();
60 /// Timeout test function #2
61 void CheckTimeout2();
62 /// Timeout test function #3
63 void CheckTimeout3();
64
65 /// ID cache
67};
68
69void
71{
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");
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
92}
93
94void
96{
97 NS_TEST_EXPECT_MSG_EQ(cache.GetSize(), 6, "Nothing expire");
98}
99
100void
102{
103 NS_TEST_EXPECT_MSG_EQ(cache.GetSize(), 3, "3 records left");
104}
105
106void
108{
109 NS_TEST_EXPECT_MSG_EQ(cache.GetSize(), 0, "All records expire");
110}
111
112/**
113 * \ingroup aodv-test
114 *
115 * \brief Id Cache Test Suite
116 */
118{
119 public:
121 : TestSuite("aodv-routing-id-cache", Type::UNIT)
122 {
124 }
125} g_idCacheTestSuite; ///< the test suite
126
127} // namespace aodv
128} // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
Unique packets identification cache used for simple duplicate detection.
Definition: aodv-id-cache.h:46
void SetLifetime(Time lifetime)
Set lifetime for future added entries.
Definition: aodv-id-cache.h:75
Time GetLifeTime() const
Return lifetime for existing entries in cache.
Definition: aodv-id-cache.h:84
bool IsDuplicate(Ipv4Address addr, uint32_t id)
Check that entry (addr, id) exists in cache.
Unit test for id cache.
void CheckTimeout3()
Timeout test function #3.
void CheckTimeout2()
Timeout test function #2.
void CheckTimeout1()
Timeout test function #1.
void DoRun() override
Implementation to actually run this TestCase.
ns3::aodv::IdCacheTestSuite g_idCacheTestSuite
the test suite
#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:252
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.