A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
29/**
30 * \ingroup flame-test
31 *
32 * \brief Built-in self test for FlameHeader
33 */
35{
37 : TestCase("FlameHeader roundtrip serialization")
38 {
39 }
40
41 void DoRun() override;
42};
43
44void
46{
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);
56 packet->RemoveHeader(b);
57 NS_TEST_ASSERT_MSG_EQ(b, a, "FlameHeader roundtrip serialization works");
58}
59
60//-----------------------------------------------------------------------------
61
62/**
63 * \ingroup flame-test
64 *
65 * \brief Unit test for FlameRtable
66 */
68{
69 public:
71 void DoRun() override;
72
73 private:
74 /// Test Add apth and lookup path;
75 void TestLookup();
76
77 /// Test add path and try to lookup after entry has expired
78 void TestAddPath();
79 /// Test add path and try to lookup after entry has expired
80 void TestExpire();
81
82 private:
83 Mac48Address dst; ///< destination address
84 Mac48Address hop; ///< hop address
85 uint32_t iface; ///< interface
86 uint8_t cost; ///< cost
87 uint16_t seqnum; ///< sequence number
89};
90
91/// Test instance
93
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
104void
106{
108
110 NS_TEST_EXPECT_MSG_EQ((table->Lookup(dst) == correct), true, "Routing table lookup works");
111}
112
113void
115{
117}
118
119void
121{
122 // this is assumed to be called when path records are already expired
125 false,
126 "Routing table records expirations works");
127}
128
129void
131{
132 table = CreateObject<FlameRtable>();
133
137
140}
141
142/**
143 * \ingroup flame-test
144 *
145 * \brief Flame Test Suite
146 */
148{
149 public:
151};
152
154 : TestSuite("devices-mesh-flame", Type::UNIT)
155{
156 AddTestCase(new FlameHeaderTest, TestCase::Duration::QUICK);
157 AddTestCase(new FlameRtableTest, TestCase::Duration::QUICK);
158}
159
160static FlameTestSuite g_flameTestSuite; ///< the test suite
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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
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:145
#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:252
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
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