A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
mesh
test
flame
flame-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
* Author: Pavel Boyko <boyko@iitp.ru>
19
*/
20
21
#include "ns3/test.h"
22
#include "ns3/packet.h"
23
#include "ns3/simulator.h"
24
#include "ns3/flame-header.h"
25
#include "ns3/flame-rtable.h"
26
27
using namespace
ns3
;
28
using namespace
flame;
29
36
struct
FlameHeaderTest
:
public
TestCase
37
{
38
FlameHeaderTest
() :
39
TestCase
(
"FlameHeader roundtrip serialization"
)
40
{
41
}
42
void
DoRun ();
43
};
44
45
void
46
FlameHeaderTest::DoRun
()
47
{
48
FlameHeader
a;
49
a.
AddCost
(123);
50
a.
SetSeqno
(456);
51
a.
SetOrigDst
(
Mac48Address
(
"11:22:33:44:55:66"
));
52
a.
SetOrigSrc
(
Mac48Address
(
"00:11:22:33:44:55"
));
53
a.
SetProtocol
(0x806);
54
Ptr<Packet>
packet = Create<Packet> ();
55
packet->
AddHeader
(a);
56
FlameHeader
b;
57
packet->
RemoveHeader
(b);
58
NS_TEST_ASSERT_MSG_EQ
(b, a,
"FlameHeader roundtrip serialization works"
);
59
}
60
61
//-----------------------------------------------------------------------------
62
69
class
FlameRtableTest
:
public
TestCase
70
{
71
public
:
72
FlameRtableTest
();
73
void
DoRun ();
74
75
private
:
77
void
TestLookup ();
78
80
void
TestAddPath ();
82
void
TestExpire ();
83
84
private
:
85
Mac48Address
dst
;
86
Mac48Address
hop
;
87
uint32_t
iface
;
88
uint8_t
cost
;
89
uint16_t
seqnum
;
90
Ptr<FlameRtable>
table
;
91
};
92
94
static
FlameRtableTest
g_FlameRtableTest
;
95
96
FlameRtableTest::FlameRtableTest
() :
97
TestCase
(
"FlameRtable"
),
98
dst (
"01:00:00:01:00:01"
),
99
hop (
"01:00:00:01:00:03"
),
100
iface (8010),
101
cost (10),
102
seqnum (1)
103
{
104
}
105
106
void
107
FlameRtableTest::TestLookup
()
108
{
109
FlameRtable::LookupResult
correct (
hop
,
iface
,
cost
,
seqnum
);
110
111
table
->
AddPath
(
dst
,
hop
,
iface
,
cost
,
seqnum
);
112
NS_TEST_EXPECT_MSG_EQ
((
table
->
Lookup
(
dst
) == correct),
true
,
"Routing table lookup works"
);
113
}
114
115
void
116
FlameRtableTest::TestAddPath
()
117
{
118
table
->
AddPath
(
dst
,
hop
,
iface
,
cost
,
seqnum
);
119
}
120
121
void
122
FlameRtableTest::TestExpire
()
123
{
124
// this is assumed to be called when path records are already expired
125
FlameRtable::LookupResult
correct (
hop
,
iface
,
cost
,
seqnum
);
126
NS_TEST_EXPECT_MSG_EQ
(
table
->
Lookup
(
dst
).
IsValid
(),
false
,
"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
142
149
class
FlameTestSuite
:
public
TestSuite
150
{
151
public
:
152
FlameTestSuite
();
153
};
154
155
FlameTestSuite::FlameTestSuite
()
156
:
TestSuite
(
"devices-mesh-flame"
, UNIT)
157
{
158
AddTestCase
(
new
FlameHeaderTest
, TestCase::QUICK);
159
AddTestCase
(
new
FlameRtableTest
, TestCase::QUICK);
160
}
161
162
static
FlameTestSuite
g_flameTestSuite
;
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition:
packet.cc:280
ns3::Ptr< Packet >
ns3::flame::FlameHeader::SetSeqno
void SetSeqno(uint16_t seqno)
Set sequence number value.
Definition:
flame-header.cc:103
FlameRtableTest
Unit test for FlameRtable.
Definition:
flame-test-suite.cc:69
ns3::flame::FlameHeader::SetOrigDst
void SetOrigDst(Mac48Address dst)
Set origin destination address.
Definition:
flame-header.cc:113
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:65
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1342
g_flameTestSuite
static FlameTestSuite g_flameTestSuite
the test suite
Definition:
flame-test-suite.cc:162
FlameHeaderTest::FlameHeaderTest
FlameHeaderTest()
Definition:
flame-test-suite.cc:38
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:285
FlameRtableTest::iface
uint32_t iface
interface
Definition:
flame-test-suite.cc:87
ns3::TestCase
encapsulates test code
Definition:
test.h:1155
FlameHeaderTest
Built-in self test for FlameHeader.
Definition:
flame-test-suite.cc:36
ns3::flame::FlameHeader::SetProtocol
void SetProtocol(uint16_t protocol)
Set protocol value.
Definition:
flame-header.cc:133
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
FlameRtableTest::TestExpire
void TestExpire()
Test add path and try to lookup after entry has expired.
Definition:
flame-test-suite.cc:122
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:168
FlameRtableTest::cost
uint8_t cost
cost
Definition:
flame-test-suite.cc:88
ns3::flame::FlameHeader::AddCost
void AddCost(uint8_t cost)
Add cost value.
Definition:
flame-header.cc:93
FlameHeaderTest::DoRun
void DoRun()
Implementation to actually run this TestCase.
Definition:
flame-test-suite.cc:46
FlameRtableTest::table
Ptr< FlameRtable > table
table
Definition:
flame-test-suite.cc:90
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
FlameRtableTest::dst
Mac48Address dst
destination address
Definition:
flame-test-suite.cc:85
ns3::flame::FlameRtable::LookupResult
Route lookup result, return type of LookupXXX methods.
Definition:
flame-rtable.h:45
FlameRtableTest::hop
Mac48Address hop
hop address
Definition:
flame-test-suite.cc:86
ns3::flame::FlameHeader::SetOrigSrc
void SetOrigSrc(Mac48Address OrigSrc)
Set origin source function.
Definition:
flame-header.cc:123
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:43
FlameRtableTest::seqnum
uint16_t seqnum
sequence number
Definition:
flame-test-suite.cc:89
FlameTestSuite
Flame Test Suite.
Definition:
flame-test-suite.cc:149
FlameTestSuite::FlameTestSuite
FlameTestSuite()
Definition:
flame-test-suite.cc:155
FlameRtableTest::TestAddPath
void TestAddPath()
Test add path and try to lookup after entry has expired.
Definition:
flame-test-suite.cc:116
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1014
FlameRtableTest::FlameRtableTest
FlameRtableTest()
Definition:
flame-test-suite.cc:96
FlameRtableTest::TestLookup
void TestLookup()
Test Add apth and lookup path;.
Definition:
flame-test-suite.cc:107
ns3::flame::FlameRtable::LookupResult::IsValid
bool IsValid() const
Definition:
flame-rtable.cc:110
FlameRtableTest::DoRun
void DoRun()
Implementation to actually run this TestCase.
Definition:
flame-test-suite.cc:130
ns3::flame::FlameRtable::Lookup
LookupResult Lookup(Mac48Address destination)
Lookup path to destination.
Definition:
flame-rtable.cc:88
ns3::flame::FlameHeader
Flame header.
Definition:
flame-header.h:37
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition:
packet.cc:256
g_FlameRtableTest
static FlameRtableTest g_FlameRtableTest
Test instance.
Definition:
flame-test-suite.cc:94
Generated on Wed Nov 7 2018 10:02:05 for ns-3 by
1.8.14