A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
flame-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
* Author: Pavel Boyko <boyko@iitp.ru>
18
*/
19
20
#include "ns3/flame-header.h"
21
#include "ns3/flame-rtable.h"
22
#include "ns3/packet.h"
23
#include "ns3/simulator.h"
24
#include "ns3/test.h"
25
26
using namespace
ns3
;
27
using namespace
flame;
28
34
struct
FlameHeaderTest
:
public
TestCase
35
{
36
FlameHeaderTest
()
37
:
TestCase
(
"FlameHeader roundtrip serialization"
)
38
{
39
}
40
41
void
DoRun()
override
;
42
};
43
44
void
45
FlameHeaderTest::DoRun
()
46
{
47
FlameHeader
a;
48
a.
AddCost
(123);
49
a.
SetSeqno
(456);
50
a.
SetOrigDst
(
Mac48Address
(
"11:22:33:44:55:66"
));
51
a.
SetOrigSrc
(
Mac48Address
(
"00:11:22:33:44:55"
));
52
a.
SetProtocol
(0x806);
53
Ptr<Packet>
packet = Create<Packet>();
54
packet->
AddHeader
(a);
55
FlameHeader
b;
56
packet->
RemoveHeader
(b);
57
NS_TEST_ASSERT_MSG_EQ
(b, a,
"FlameHeader roundtrip serialization works"
);
58
}
59
60
//-----------------------------------------------------------------------------
61
67
class
FlameRtableTest
:
public
TestCase
68
{
69
public
:
70
FlameRtableTest
();
71
void
DoRun()
override
;
72
73
private
:
75
void
TestLookup();
76
78
void
TestAddPath();
80
void
TestExpire();
81
82
private
:
83
Mac48Address
dst
;
84
Mac48Address
hop
;
85
uint32_t
iface
;
86
uint8_t
cost
;
87
uint16_t
seqnum
;
88
Ptr<FlameRtable>
table
;
89
};
90
92
static
FlameRtableTest
g_FlameRtableTest
;
93
94
FlameRtableTest::FlameRtableTest
()
95
:
TestCase
(
"FlameRtable"
),
96
dst(
"01:00:00:01:00:01"
),
97
hop(
"01:00:00:01:00:03"
),
98
iface(8010),
99
cost(10),
100
seqnum(1)
101
{
102
}
103
104
void
105
FlameRtableTest::TestLookup
()
106
{
107
FlameRtable::LookupResult
correct(
hop
,
iface
,
cost
,
seqnum
);
108
109
table
->
AddPath
(
dst
,
hop
,
iface
,
cost
,
seqnum
);
110
NS_TEST_EXPECT_MSG_EQ
((
table
->
Lookup
(
dst
) == correct),
true
,
"Routing table lookup works"
);
111
}
112
113
void
114
FlameRtableTest::TestAddPath
()
115
{
116
table
->
AddPath
(
dst
,
hop
,
iface
,
cost
,
seqnum
);
117
}
118
119
void
120
FlameRtableTest::TestExpire
()
121
{
122
// this is assumed to be called when path records are already expired
123
FlameRtable::LookupResult
correct(
hop
,
iface
,
cost
,
seqnum
);
124
NS_TEST_EXPECT_MSG_EQ
(
table
->
Lookup
(
dst
).
IsValid
(),
125
false
,
126
"Routing table records expirations works"
);
127
}
128
129
void
130
FlameRtableTest::DoRun
()
131
{
132
table
= CreateObject<FlameRtable>();
133
134
Simulator::Schedule(
Seconds
(0), &
FlameRtableTest::TestLookup
,
this
);
135
Simulator::Schedule(
Seconds
(1), &
FlameRtableTest::TestAddPath
,
this
);
136
Simulator::Schedule(
Seconds
(122), &
FlameRtableTest::TestExpire
,
this
);
137
138
Simulator::Run();
139
Simulator::Destroy();
140
}
141
147
class
FlameTestSuite
:
public
TestSuite
148
{
149
public
:
150
FlameTestSuite
();
151
};
152
153
FlameTestSuite::FlameTestSuite
()
154
:
TestSuite
(
"devices-mesh-flame"
, UNIT)
155
{
156
AddTestCase
(
new
FlameHeaderTest
, TestCase::QUICK);
157
AddTestCase
(
new
FlameRtableTest
, TestCase::QUICK);
158
}
159
160
static
FlameTestSuite
g_flameTestSuite
;
FlameRtableTest
Unit test for FlameRtable.
Definition:
flame-test-suite.cc:68
FlameRtableTest::iface
uint32_t iface
interface
Definition:
flame-test-suite.cc:85
FlameRtableTest::cost
uint8_t cost
cost
Definition:
flame-test-suite.cc:86
FlameRtableTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
flame-test-suite.cc:130
FlameRtableTest::TestExpire
void TestExpire()
Test add path and try to lookup after entry has expired.
Definition:
flame-test-suite.cc:120
FlameRtableTest::seqnum
uint16_t seqnum
sequence number
Definition:
flame-test-suite.cc:87
FlameRtableTest::TestAddPath
void TestAddPath()
Test add path and try to lookup after entry has expired.
Definition:
flame-test-suite.cc:114
FlameRtableTest::hop
Mac48Address hop
hop address
Definition:
flame-test-suite.cc:84
FlameRtableTest::TestLookup
void TestLookup()
Test Add apth and lookup path;.
Definition:
flame-test-suite.cc:105
FlameRtableTest::dst
Mac48Address dst
destination address
Definition:
flame-test-suite.cc:83
FlameRtableTest::FlameRtableTest
FlameRtableTest()
Definition:
flame-test-suite.cc:94
FlameRtableTest::table
Ptr< FlameRtable > table
table
Definition:
flame-test-suite.cc:88
FlameTestSuite
Flame Test Suite.
Definition:
flame-test-suite.cc:148
FlameTestSuite::FlameTestSuite
FlameTestSuite()
Definition:
flame-test-suite.cc:153
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:46
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition:
packet.cc:294
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition:
packet.cc:268
ns3::Ptr< Packet >
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
ns3::flame::FlameHeader
Flame header.
Definition:
flame-header.h:40
ns3::flame::FlameHeader::SetOrigSrc
void SetOrigSrc(Mac48Address OrigSrc)
Set origin source function.
Definition:
flame-header.cc:141
ns3::flame::FlameHeader::AddCost
void AddCost(uint8_t cost)
Add cost value.
Definition:
flame-header.cc:105
ns3::flame::FlameHeader::SetOrigDst
void SetOrigDst(Mac48Address dst)
Set origin destination address.
Definition:
flame-header.cc:129
ns3::flame::FlameHeader::SetProtocol
void SetProtocol(uint16_t protocol)
Set protocol value.
Definition:
flame-header.cc:153
ns3::flame::FlameHeader::SetSeqno
void SetSeqno(uint16_t seqno)
Set sequence number value.
Definition:
flame-header.cc:117
ns3::flame::FlameRtable::Lookup
LookupResult Lookup(Mac48Address destination)
Lookup path to destination.
Definition:
flame-rtable.cc:94
ns3::flame::FlameRtable::AddPath
void AddPath(const Mac48Address destination, const Mac48Address retransmitter, const uint32_t interface, const uint8_t cost, const uint16_t seqnum)
Add path.
Definition:
flame-rtable.cc:67
g_FlameRtableTest
static FlameRtableTest g_FlameRtableTest
Test instance.
Definition:
flame-test-suite.cc:92
g_flameTestSuite
static FlameTestSuite g_flameTestSuite
the test suite
Definition:
flame-test-suite.cc:160
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:144
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:251
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1326
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:35
FlameHeaderTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
flame-test-suite.cc:45
FlameHeaderTest::FlameHeaderTest
FlameHeaderTest()
Definition:
flame-test-suite.cc:36
ns3::flame::FlameRtable::LookupResult
Route lookup result, return type of LookupXXX methods.
Definition:
flame-rtable.h:48
ns3::flame::FlameRtable::LookupResult::IsValid
bool IsValid() const
Definition:
flame-rtable.cc:121
src
mesh
test
flame
flame-test-suite.cc
Generated on Sun Mar 3 2024 17:11:05 for ns-3 by
1.9.1