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
flame-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
* Author: Pavel Boyko <boyko@iitp.ru>
7
*/
8
9
#include "ns3/flame-header.h"
10
#include "ns3/flame-rtable.h"
11
#include "ns3/packet.h"
12
#include "ns3/simulator.h"
13
#include "ns3/test.h"
14
15
using namespace
ns3
;
16
using namespace
flame;
17
18
/**
19
* \ingroup flame-test
20
*
21
* \brief Built-in self test for FlameHeader
22
*/
23
struct
FlameHeaderTest
:
public
TestCase
24
{
25
FlameHeaderTest
()
26
:
TestCase
(
"FlameHeader roundtrip serialization"
)
27
{
28
}
29
30
void
DoRun
()
override
;
31
};
32
33
void
34
FlameHeaderTest::DoRun
()
35
{
36
FlameHeader
a;
37
a.
AddCost
(123);
38
a.
SetSeqno
(456);
39
a.
SetOrigDst
(
Mac48Address
(
"11:22:33:44:55:66"
));
40
a.
SetOrigSrc
(
Mac48Address
(
"00:11:22:33:44:55"
));
41
a.
SetProtocol
(0x806);
42
Ptr<Packet>
packet =
Create<Packet>
();
43
packet->AddHeader(a);
44
FlameHeader
b;
45
packet->RemoveHeader(b);
46
NS_TEST_ASSERT_MSG_EQ
(b, a,
"FlameHeader roundtrip serialization works"
);
47
}
48
49
//-----------------------------------------------------------------------------
50
51
/**
52
* \ingroup flame-test
53
*
54
* \brief Unit test for FlameRtable
55
*/
56
class
FlameRtableTest
:
public
TestCase
57
{
58
public
:
59
FlameRtableTest
();
60
void
DoRun
()
override
;
61
62
private
:
63
/// Test Add apth and lookup path;
64
void
TestLookup
();
65
66
/// Test add path and try to lookup after entry has expired
67
void
TestAddPath
();
68
/// Test add path and try to lookup after entry has expired
69
void
TestExpire
();
70
71
private
:
72
Mac48Address
dst
;
///< destination address
73
Mac48Address
hop
;
///< hop address
74
uint32_t
iface
;
///< interface
75
uint8_t
cost
;
///< cost
76
uint16_t
seqnum
;
///< sequence number
77
Ptr<FlameRtable>
table
;
///< table
78
};
79
80
/// Test instance
81
static
FlameRtableTest
g_FlameRtableTest
;
82
83
FlameRtableTest::FlameRtableTest
()
84
:
TestCase
(
"FlameRtable"
),
85
dst(
"01:00:00:01:00:01"
),
86
hop(
"01:00:00:01:00:03"
),
87
iface(8010),
88
cost(10),
89
seqnum(1)
90
{
91
}
92
93
void
94
FlameRtableTest::TestLookup
()
95
{
96
FlameRtable::LookupResult
correct(
hop
,
iface
,
cost
,
seqnum
);
97
98
table
->AddPath(
dst
,
hop
,
iface
,
cost
,
seqnum
);
99
NS_TEST_EXPECT_MSG_EQ
((
table
->Lookup(
dst
) == correct),
true
,
"Routing table lookup works"
);
100
}
101
102
void
103
FlameRtableTest::TestAddPath
()
104
{
105
table
->AddPath(
dst
,
hop
,
iface
,
cost
,
seqnum
);
106
}
107
108
void
109
FlameRtableTest::TestExpire
()
110
{
111
// this is assumed to be called when path records are already expired
112
FlameRtable::LookupResult
correct(
hop
,
iface
,
cost
,
seqnum
);
113
NS_TEST_EXPECT_MSG_EQ
(
table
->Lookup(
dst
).IsValid(),
114
false
,
115
"Routing table records expirations works"
);
116
}
117
118
void
119
FlameRtableTest::DoRun
()
120
{
121
table
=
CreateObject<FlameRtable>
();
122
123
Simulator::Schedule
(
Seconds
(0), &
FlameRtableTest::TestLookup
,
this
);
124
Simulator::Schedule
(
Seconds
(1), &
FlameRtableTest::TestAddPath
,
this
);
125
Simulator::Schedule
(
Seconds
(122), &
FlameRtableTest::TestExpire
,
this
);
126
127
Simulator::Run
();
128
Simulator::Destroy
();
129
}
130
131
/**
132
* \ingroup flame-test
133
*
134
* \brief Flame Test Suite
135
*/
136
class
FlameTestSuite
:
public
TestSuite
137
{
138
public
:
139
FlameTestSuite
();
140
};
141
142
FlameTestSuite::FlameTestSuite
()
143
:
TestSuite
(
"devices-mesh-flame"
,
Type
::UNIT)
144
{
145
AddTestCase
(
new
FlameHeaderTest
, TestCase::Duration::QUICK);
146
AddTestCase
(
new
FlameRtableTest
, TestCase::Duration::QUICK);
147
}
148
149
static
FlameTestSuite
g_flameTestSuite
;
///< the test suite
FlameRtableTest
Unit test for FlameRtable.
Definition
flame-test-suite.cc:57
FlameRtableTest::iface
uint32_t iface
interface
Definition
flame-test-suite.cc:74
FlameRtableTest::cost
uint8_t cost
cost
Definition
flame-test-suite.cc:75
FlameRtableTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
flame-test-suite.cc:119
FlameRtableTest::TestExpire
void TestExpire()
Test add path and try to lookup after entry has expired.
Definition
flame-test-suite.cc:109
FlameRtableTest::seqnum
uint16_t seqnum
sequence number
Definition
flame-test-suite.cc:76
FlameRtableTest::TestAddPath
void TestAddPath()
Test add path and try to lookup after entry has expired.
Definition
flame-test-suite.cc:103
FlameRtableTest::hop
Mac48Address hop
hop address
Definition
flame-test-suite.cc:73
FlameRtableTest::TestLookup
void TestLookup()
Test Add apth and lookup path;.
Definition
flame-test-suite.cc:94
FlameRtableTest::dst
Mac48Address dst
destination address
Definition
flame-test-suite.cc:72
FlameRtableTest::FlameRtableTest
FlameRtableTest()
Definition
flame-test-suite.cc:83
FlameRtableTest::table
Ptr< FlameRtable > table
table
Definition
flame-test-suite.cc:77
FlameTestSuite
Flame Test Suite.
Definition
flame-test-suite.cc:137
FlameTestSuite::FlameTestSuite
FlameTestSuite()
Definition
flame-test-suite.cc:142
ns3::Mac48Address
an EUI-48 address
Definition
mac48-address.h:35
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
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::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::flame::FlameHeader
Flame header.
Definition
flame-header.h:29
ns3::flame::FlameHeader::SetOrigSrc
void SetOrigSrc(Mac48Address OrigSrc)
Set origin source function.
Definition
flame-header.cc:130
ns3::flame::FlameHeader::AddCost
void AddCost(uint8_t cost)
Add cost value.
Definition
flame-header.cc:94
ns3::flame::FlameHeader::SetOrigDst
void SetOrigDst(Mac48Address dst)
Set origin destination address.
Definition
flame-header.cc:118
ns3::flame::FlameHeader::SetProtocol
void SetProtocol(uint16_t protocol)
Set protocol value.
Definition
flame-header.cc:142
ns3::flame::FlameHeader::SetSeqno
void SetSeqno(uint16_t seqno)
Set sequence number value.
Definition
flame-header.cc:106
uint32_t
g_FlameRtableTest
static FlameRtableTest g_FlameRtableTest
Test instance.
Definition
flame-test-suite.cc:81
g_flameTestSuite
static FlameTestSuite g_flameTestSuite
the test suite
Definition
flame-test-suite.cc:149
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
NS_TEST_ASSERT_MSG_EQ
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition
test.h:134
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:1308
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
FlameHeaderTest
Built-in self test for FlameHeader.
Definition
flame-test-suite.cc:24
FlameHeaderTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
flame-test-suite.cc:34
FlameHeaderTest::FlameHeaderTest
FlameHeaderTest()
Definition
flame-test-suite.cc:25
ns3::flame::FlameRtable::LookupResult
Route lookup result, return type of LookupXXX methods.
Definition
flame-rtable.h:37
src
mesh
test
flame
flame-test-suite.cc
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0