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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Pavel Boyko <boyko@iitp.ru>
7 */
8
9#include "ns3/flame-header.h"
10#include "ns3/flame-rtable.h"
11#include "ns3/packet.h"
12#include "ns3/simulator.h"
13#include "ns3/test.h"
14
15using namespace ns3;
16using namespace flame;
17
18/**
19 * \ingroup flame-test
20 *
21 * \brief Built-in self test for FlameHeader
22 */
24{
26 : TestCase("FlameHeader roundtrip serialization")
27 {
28 }
29
30 void DoRun() override;
31};
32
33void
35{
37 a.AddCost(123);
38 a.SetSeqno(456);
39 a.SetOrigDst(Mac48Address("11:22:33:44:55:66"));
40 a.SetOrigSrc(Mac48Address("00:11:22:33:44:55"));
41 a.SetProtocol(0x806);
42 Ptr<Packet> packet = Create<Packet>();
43 packet->AddHeader(a);
45 packet->RemoveHeader(b);
46 NS_TEST_ASSERT_MSG_EQ(b, a, "FlameHeader roundtrip serialization works");
47}
48
49//-----------------------------------------------------------------------------
50
51/**
52 * \ingroup flame-test
53 *
54 * \brief Unit test for FlameRtable
55 */
57{
58 public:
60 void DoRun() override;
61
62 private:
63 /// Test Add apth and lookup path;
64 void TestLookup();
65
66 /// Test add path and try to lookup after entry has expired
67 void TestAddPath();
68 /// Test add path and try to lookup after entry has expired
69 void TestExpire();
70
71 private:
72 Mac48Address dst; ///< destination address
73 Mac48Address hop; ///< hop address
74 uint32_t iface; ///< interface
75 uint8_t cost; ///< cost
76 uint16_t seqnum; ///< sequence number
78};
79
80/// Test instance
82
84 : TestCase("FlameRtable"),
85 dst("01:00:00:01:00:01"),
86 hop("01:00:00:01:00:03"),
87 iface(8010),
88 cost(10),
89 seqnum(1)
90{
91}
92
93void
95{
97
98 table->AddPath(dst, hop, iface, cost, seqnum);
99 NS_TEST_EXPECT_MSG_EQ((table->Lookup(dst) == correct), true, "Routing table lookup works");
100}
101
102void
107
108void
110{
111 // this is assumed to be called when path records are already expired
113 NS_TEST_EXPECT_MSG_EQ(table->Lookup(dst).IsValid(),
114 false,
115 "Routing table records expirations works");
116}
117
118void
130
131/**
132 * \ingroup flame-test
133 *
134 * \brief Flame Test Suite
135 */
137{
138 public:
140};
141
143 : TestSuite("devices-mesh-flame", Type::UNIT)
144{
145 AddTestCase(new FlameHeaderTest, TestCase::Duration::QUICK);
146 AddTestCase(new FlameRtableTest, TestCase::Duration::QUICK);
147}
148
149static 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
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
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.
static FlameRtableTest g_FlameRtableTest
Test instance.
static FlameTestSuite g_flameTestSuite
the test suite
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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:134
#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:241
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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.