A Discrete-Event Network Simulator
API
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 using namespace ns3;
28 using namespace flame;
29 
31 struct FlameHeaderTest : public TestCase
32 {
34  TestCase ("FlameHeader roundtrip serialization")
35  {
36  }
37  void DoRun ();
38 };
39 
40 void
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 ();
68 
69  // Test add path and try to lookup after entry has expired
70  void TestAddPath ();
71  void TestExpire ();
72 
73 private:
76  uint32_t iface;
77  uint8_t cost;
78  uint16_t seqnum;
80 };
81 
84 
86  TestCase ("FlameRtable"),
87  dst ("01:00:00:01:00:01"),
88  hop ("01:00:00:01:00:03"),
89  iface (8010),
90  cost (10),
91  seqnum (1)
92 {
93 }
94 
95 void
97 {
99 
101  NS_TEST_EXPECT_MSG_EQ ((table->Lookup (dst) == correct), true, "Routing table lookup works");
102 }
103 
104 void
106 {
108 }
109 
110 void
112 {
113  // this is assumed to be called when path records are already expired
115  NS_TEST_EXPECT_MSG_EQ (table->Lookup (dst).IsValid (), false, "Routing table records expirations works");
116 }
117 
118 void
120 {
121  table = CreateObject<FlameRtable> ();
122 
123  Simulator::Schedule (Seconds (0), &FlameRtableTest::TestLookup, this);
124  Simulator::Schedule (Seconds (1), &FlameRtableTest::TestAddPath, this);
125  Simulator::Schedule (Seconds (122), &FlameRtableTest::TestExpire, this);
126 
127  Simulator::Run ();
128  Simulator::Destroy ();
129 }
130 
131 
132 //-----------------------------------------------------------------------------
133 
134 class FlameTestSuite : public TestSuite
135 {
136 public:
137  FlameTestSuite ();
138 };
139 
141  : TestSuite ("devices-mesh-flame", UNIT)
142 {
143  AddTestCase (new FlameHeaderTest, TestCase::QUICK);
144  AddTestCase (new FlameRtableTest, TestCase::QUICK);
145 }
146 
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
void SetSeqno(uint16_t seqno)
Unit test for FlameRtable.
void SetOrigDst(Mac48Address dst)
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:65
A suite of tests to run.
Definition: test.h:1333
static FlameTestSuite g_flameTestSuite
#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:278
encapsulates test code
Definition: test.h:1147
Built-in self test for FlameHeader.
void SetProtocol(uint16_t protocol)
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
#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:161
void AddCost(uint8_t cost)
Definition: flame-header.cc:93
void DoRun()
Implementation to actually run this TestCase.
Ptr< FlameRtable > table
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Mac48Address dst
Route lookup result, return type of LookupXXX methods.
Definition: flame-rtable.h:45
Mac48Address hop
void SetOrigSrc(Mac48Address OrigSrc)
an EUI-48 address
Definition: mac48-address.h:43
bool IsValid() const
True for valid route.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void TestLookup()
Test Add apth and lookup path;.
void DoRun()
Implementation to actually run this TestCase.
LookupResult Lookup(Mac48Address destination)
Lookup path to destination.
Definition: flame-rtable.cc:88
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257
static FlameRtableTest g_FlameRtableTest
Test instance.