A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
namespace
ns3 {
28
namespace
flame {
29
31
struct
FlameHeaderTest
:
public
TestCase
32
{
33
FlameHeaderTest
() :
34
TestCase
(
"FlameHeader roundtrip serialization"
)
35
{
36
}
37
void
DoRun
();
38
};
39
40
void
41
FlameHeaderTest::DoRun
()
42
{
43
FlameHeader
a;
44
a.
AddCost
(123);
45
a.
SetSeqno
(456);
46
a.
SetOrigDst
(
Mac48Address
(
"11:22:33:44:55:66"
));
47
a.
SetOrigSrc
(
Mac48Address
(
"00:11:22:33:44:55"
));
48
a.
SetProtocol
(0x806);
49
Ptr<Packet>
packet = Create<Packet> ();
50
packet->
AddHeader
(a);
51
FlameHeader
b;
52
packet->
RemoveHeader
(b);
53
NS_TEST_ASSERT_MSG_EQ
(b, a,
"FlameHeader roundtrip serialization works"
);
54
}
55
56
//-----------------------------------------------------------------------------
57
59
class
FlameRtableTest
:
public
TestCase
60
{
61
public
:
62
FlameRtableTest
();
63
void
DoRun
();
64
65
private
:
67
void
TestLookup
();
72
void
TestAddPath
();
73
void
TestExpire
();
75
private
:
76
Mac48Address
dst
;
77
Mac48Address
hop
;
78
uint32_t
iface
;
79
uint8_t
cost
;
80
uint16_t
seqnum
;
81
Ptr<FlameRtable>
table
;
82
};
83
85
static
FlameRtableTest
g_FlameRtableTest
;
86
87
FlameRtableTest::FlameRtableTest
() :
88
TestCase
(
"FlameRtable"
),
89
dst (
"01:00:00:01:00:01"
),
90
hop (
"01:00:00:01:00:03"
),
91
iface (8010),
92
cost (10),
93
seqnum (1)
94
{
95
}
96
97
void
98
FlameRtableTest::TestLookup
()
99
{
100
FlameRtable::LookupResult
correct (
hop
,
iface
,
cost
,
seqnum
);
101
102
table
->AddPath (
dst
,
hop
,
iface
,
cost
,
seqnum
);
103
NS_TEST_EXPECT_MSG_EQ
((
table
->Lookup (
dst
) == correct),
true
,
"Routing table lookup works"
);
104
}
105
106
void
107
FlameRtableTest::TestAddPath
()
108
{
109
table
->AddPath (
dst
,
hop
,
iface
,
cost
,
seqnum
);
110
}
111
112
void
113
FlameRtableTest::TestExpire
()
114
{
115
// this is assumed to be called when path records are already expired
116
FlameRtable::LookupResult
correct (
hop
,
iface
,
cost
,
seqnum
);
117
NS_TEST_EXPECT_MSG_EQ
(
table
->Lookup (
dst
).IsValid (),
false
,
"Routing table records expirations works"
);
118
}
119
120
void
121
FlameRtableTest::DoRun
()
122
{
123
table
= CreateObject<FlameRtable> ();
124
125
Simulator::Schedule
(Seconds (0), &
FlameRtableTest::TestLookup
,
this
);
126
Simulator::Schedule
(Seconds (1), &
FlameRtableTest::TestAddPath
,
this
);
127
Simulator::Schedule
(Seconds (122), &
FlameRtableTest::TestExpire
,
this
);
128
129
Simulator::Run
();
130
Simulator::Destroy
();
131
}
132
133
134
//-----------------------------------------------------------------------------
135
136
class
FlameTestSuite
:
public
TestSuite
137
{
138
public
:
139
FlameTestSuite
();
140
};
141
142
FlameTestSuite::FlameTestSuite
()
143
:
TestSuite
(
"devices-mesh-flame"
, UNIT)
144
{
145
AddTestCase
(
new
FlameHeaderTest
,
TestCase::QUICK
);
146
AddTestCase
(
new
FlameRtableTest
,
TestCase::QUICK
);
147
}
148
149
static
FlameTestSuite
g_flameTestSuite
;
150
151
}
152
}
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition:
packet.cc:268
ns3::Ptr< Packet >
ns3::flame::FlameHeader::SetSeqno
void SetSeqno(uint16_t seqno)
Definition:
flame-header.cc:103
ns3::flame::FlameHeader::SetOrigDst
void SetOrigDst(Mac48Address dst)
Definition:
flame-header.cc:113
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1025
ns3::flame::FlameRtableTest::TestAddPath
void TestAddPath()
Definition:
flame-test-suite.cc:107
ns3::Simulator::Run
static void Run(void)
Run the simulation until one of:
Definition:
simulator.cc:157
ns3::flame::FlameRtableTest
Unit test for FlameRtable.
Definition:
flame-test-suite.cc:59
ns3::TestCase
encapsulates test code
Definition:
test.h:849
ns3::Simulator::Schedule
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition:
simulator.h:824
ns3::flame::g_FlameRtableTest
static FlameRtableTest g_FlameRtableTest
Test instance.
Definition:
flame-test-suite.cc:85
ns3::flame::FlameTestSuite
Definition:
flame-test-suite.cc:136
ns3::flame::FlameHeader::SetProtocol
void SetProtocol(uint16_t protocol)
Definition:
flame-header.cc:133
ns3::flame::FlameHeaderTest
Built-in self test for FlameHeader.
Definition:
flame-test-suite.cc:31
ns3::flame::FlameRtableTest::TestLookup
void TestLookup()
Test Add apth and lookup path;.
Definition:
flame-test-suite.cc:98
ns3::flame::FlameRtableTest::dst
Mac48Address dst
Definition:
flame-test-suite.cc:76
ns3::flame::g_flameTestSuite
static FlameTestSuite g_flameTestSuite
Definition:
flame-test-suite.cc:149
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:244
ns3::flame::FlameHeader::AddCost
void AddCost(uint8_t cost)
Definition:
flame-header.cc:93
ns3::Simulator::Destroy
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition:
simulator.cc:121
ns3::flame::FlameRtableTest::table
Ptr< FlameRtable > table
Definition:
flame-test-suite.cc:81
ns3::flame::FlameRtableTest::cost
uint8_t cost
Definition:
flame-test-suite.cc:79
ns3::flame::FlameRtable::LookupResult
Route lookup result, return type of LookupXXX methods.
Definition:
flame-rtable.h:45
ns3::flame::FlameHeader::SetOrigSrc
void SetOrigSrc(Mac48Address OrigSrc)
Definition:
flame-header.cc:123
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:41
ns3::flame::FlameRtableTest::DoRun
void DoRun()
Implementation to actually run this TestCase.
Definition:
flame-test-suite.cc:121
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition:
test.cc:173
ns3::flame::FlameTestSuite::FlameTestSuite
FlameTestSuite()
Definition:
flame-test-suite.cc:142
ns3::flame::FlameHeaderTest::FlameHeaderTest
FlameHeaderTest()
Definition:
flame-test-suite.cc:33
ns3::TestCase::QUICK
Fast test.
Definition:
test.h:857
ns3::flame::FlameRtableTest::iface
uint32_t iface
Definition:
flame-test-suite.cc:78
ns3::flame::FlameRtableTest::FlameRtableTest
FlameRtableTest()
Definition:
flame-test-suite.cc:87
ns3::flame::FlameRtableTest::hop
Mac48Address hop
Definition:
flame-test-suite.cc:77
ns3::flame::FlameHeaderTest::DoRun
void DoRun()
Implementation to actually run this TestCase.
Definition:
flame-test-suite.cc:41
ns3::flame::FlameRtableTest::TestExpire
void TestExpire()
Definition:
flame-test-suite.cc:113
ns3::flame::FlameRtableTest::seqnum
uint16_t seqnum
Definition:
flame-test-suite.cc:80
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:253
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:137
src
mesh
test
flame
flame-test-suite.cc
Generated on Sat Apr 19 2014 14:07:04 for ns-3 by
1.8.6