A Discrete-Event Network Simulator
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
26using namespace ns3;
27using namespace flame;
28
36{
38 : TestCase("FlameHeader roundtrip serialization")
39 {
40 }
41
42 void DoRun() override;
43};
44
45void
47{
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);
57 packet->RemoveHeader(b);
58 NS_TEST_ASSERT_MSG_EQ(b, a, "FlameHeader roundtrip serialization works");
59}
60
61//-----------------------------------------------------------------------------
62
70{
71 public:
73 void DoRun() override;
74
75 private:
77 void TestLookup();
78
80 void TestAddPath();
82 void TestExpire();
83
84 private:
88 uint8_t cost;
89 uint16_t seqnum;
91};
92
95
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
106void
108{
110
112 NS_TEST_EXPECT_MSG_EQ((table->Lookup(dst) == correct), true, "Routing table lookup works");
113}
114
115void
117{
119}
120
121void
123{
124 // this is assumed to be called when path records are already expired
127 false,
128 "Routing table records expirations works");
129}
130
131void
133{
134 table = CreateObject<FlameRtable>();
135
136 Simulator::Schedule(Seconds(0), &FlameRtableTest::TestLookup, this);
137 Simulator::Schedule(Seconds(1), &FlameRtableTest::TestAddPath, this);
138 Simulator::Schedule(Seconds(122), &FlameRtableTest::TestExpire, this);
139
140 Simulator::Run();
141 Simulator::Destroy();
142}
143
151{
152 public:
154};
155
157 : TestSuite("devices-mesh-flame", UNIT)
158{
159 AddTestCase(new FlameHeaderTest, TestCase::QUICK);
160 AddTestCase(new FlameRtableTest, TestCase::QUICK);
161}
162
Unit test for FlameRtable.
uint32_t iface
interface
void DoRun() override
Implementation to actually run this TestCase.
void TestExpire()
Test add path and try to lookup after entry has expired.
uint16_t seqnum
sequence number
void TestAddPath()
Test add path and try to lookup after entry has expired.
Mac48Address hop
hop address
void TestLookup()
Test Add apth and lookup path;.
Mac48Address dst
destination address
Ptr< FlameRtable > table
table
Flame Test Suite.
an EUI-48 address
Definition: mac48-address.h:46
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:294
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
void SetOrigSrc(Mac48Address OrigSrc)
Set origin source function.
void AddCost(uint8_t cost)
Add cost value.
void SetOrigDst(Mac48Address dst)
Set origin destination address.
void SetProtocol(uint16_t protocol)
Set protocol value.
void SetSeqno(uint16_t seqno)
Set sequence number value.
LookupResult Lookup(Mac48Address destination)
Lookup path to destination.
Definition: flame-rtable.cc:94
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
static FlameRtableTest g_FlameRtableTest
Test instance.
static FlameTestSuite g_flameTestSuite
the test suite
#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
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Built-in self test for FlameHeader.
void DoRun() override
Implementation to actually run this TestCase.
Route lookup result, return type of LookupXXX methods.
Definition: flame-rtable.h:48