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
bool
error
;
77
78
Mac48Address
dst
;
79
Mac48Address
hop
;
80
uint32_t
iface
;
81
uint8_t
cost
;
82
uint16_t
seqnum
;
83
Ptr<FlameRtable>
table
;
84
};
85
87
static
FlameRtableTest
g_FlameRtableTest
;
88
89
FlameRtableTest::FlameRtableTest
() :
90
TestCase
(
"FlameRtable"
),
91
error (false),
92
dst (
"01:00:00:01:00:01"
),
93
hop (
"01:00:00:01:00:03"
),
94
iface (8010),
95
cost (10),
96
seqnum (1)
97
{
98
}
99
100
void
101
FlameRtableTest::TestLookup
()
102
{
103
FlameRtable::LookupResult
correct (
hop
,
iface
,
cost
,
seqnum
);
104
105
table
->
AddPath
(
dst
,
hop
,
iface
,
cost
,
seqnum
);
106
NS_TEST_EXPECT_MSG_EQ
((
table
->
Lookup
(
dst
) == correct),
true
,
"Routing table lookup works"
);
107
}
108
109
void
110
FlameRtableTest::TestAddPath
()
111
{
112
table
->
AddPath
(
dst
,
hop
,
iface
,
cost
,
seqnum
);
113
}
114
115
void
116
FlameRtableTest::TestExpire
()
117
{
118
// this is assumed to be called when path records are already expired
119
FlameRtable::LookupResult
correct (
hop
,
iface
,
cost
,
seqnum
);
120
NS_TEST_EXPECT_MSG_EQ
(
table
->
Lookup
(
dst
).
IsValid
(),
false
,
"Routing table records expirations works"
);
121
}
122
123
void
124
FlameRtableTest::DoRun
()
125
{
126
table
= CreateObject<FlameRtable> ();
127
128
Simulator::Schedule
(
Seconds
(0), &
FlameRtableTest::TestLookup
,
this
);
129
Simulator::Schedule (
Seconds
(1), &
FlameRtableTest::TestAddPath
,
this
);
130
Simulator::Schedule (
Seconds
(122), &
FlameRtableTest::TestExpire
,
this
);
131
132
Simulator::Run
();
133
Simulator::Destroy
();
134
}
135
136
137
//-----------------------------------------------------------------------------
138
139
class
FlameTestSuite
:
public
TestSuite
140
{
141
public
:
142
FlameTestSuite
();
143
};
144
145
FlameTestSuite::FlameTestSuite
()
146
:
TestSuite
(
"devices-mesh-flame"
, UNIT)
147
{
148
AddTestCase
(
new
FlameHeaderTest
);
149
AddTestCase
(
new
FlameRtableTest
);
150
}
151
152
static
FlameTestSuite
g_flameTestSuite
;
153
154
}
155
}
src
mesh
test
flame
flame-test-suite.cc
Generated on Tue Oct 9 2012 16:45:42 for ns-3 by
1.8.1.2