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 * 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
19namespace ns3
20{
21namespace 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 */
35class IdCacheTest : public TestCase
36{
37 public:
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
56};
57
58void
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
81}
82
83void
85{
86 NS_TEST_EXPECT_MSG_EQ(cache.GetSize(), 6, "Nothing expire");
87}
88
89void
91{
92 NS_TEST_EXPECT_MSG_EQ(cache.GetSize(), 3, "3 records left");
93}
94
95void
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 */
107{
108 public:
110 : TestSuite("aodv-routing-id-cache", Type::UNIT)
111 {
113 }
114} g_idCacheTestSuite; ///< the test suite
115
116} // namespace aodv
117} // namespace ns3
Ipv4 addresses are stored in host order in this class.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:561
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
@ QUICK
Fast test.
Definition test.h:1055
TestCase(const TestCase &)=delete
Type
Type of test.
Definition test.h:1274
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:490
static constexpr auto UNIT
Definition test.h:1291
Unique packets identification cache used for simple duplicate detection.
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:241
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Every class exported by the ns3 library is enclosed in the ns3 namespace.