A Discrete-Event Network Simulator
API
uan-test.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2009 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
19 */
20
21#include "ns3/uan-net-device.h"
22#include "ns3/uan-channel.h"
23#include "ns3/uan-mac-aloha.h"
24#include "ns3/uan-phy-gen.h"
25#include "ns3/uan-transducer-hd.h"
26#include "ns3/uan-prop-model-ideal.h"
27#include "ns3/constant-position-mobility-model.h"
28#include "ns3/simulator.h"
29#include "ns3/test.h"
30#include "ns3/node.h"
31#include "ns3/object-factory.h"
32#include "ns3/pointer.h"
33#include "ns3/callback.h"
34
35using namespace ns3;
36
43class UanTest : public TestCase
44{
45public:
46 UanTest ();
47
48 virtual void DoRun (void);
49private:
61 bool DoPhyTests ();
73 uint32_t DoOnePhyTest (Time t1, Time t2, uint32_t r1, uint32_t r2, Ptr<UanPropModel> prop, uint16_t mode1 = 0, uint16_t mode2 = 0);
82 bool RxPacket (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender);
88 void SendOnePacket (Ptr<UanNetDevice> dev, uint16_t mode);
91
92};
93
94
96{
97
98}
99
100bool
102 [[maybe_unused]] uint16_t mode,
103 [[maybe_unused]] const Address &sender)
104{
105 m_bytesRx += pkt->GetSize ();
106 return true;
107}
108void
110{
111 Ptr<Packet> pkt = Create<Packet> (17);
112 dev->SetTxModeIndex (mode);
113 dev->Send (pkt, dev->GetBroadcast (), 0);
114
115}
118{
119
120
122 Ptr<Node> node = CreateObject<Node> ();
123 Ptr<UanNetDevice> dev = CreateObject<UanNetDevice> ();
124 Ptr<UanMacAloha> mac = CreateObject<UanMacAloha> ();
125 Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
126
127 Ptr<UanTransducerHd> trans = CreateObject<UanTransducerHd> ();
128
129 mobility->SetPosition (pos);
130 node->AggregateObject (mobility);
131 mac->SetAddress (Mac8Address::Allocate ());
132
133 dev->SetPhy (phy);
134 dev->SetMac (mac);
135 dev->SetChannel (chan);
136 dev->SetTransducer (trans);
137 node->AddDevice (dev);
138
139 return dev;
140}
141
142
145 Time txTime2,
146 uint32_t r1,
147 uint32_t r2,
149 uint16_t mode1,
150 uint16_t mode2)
151{
152
153 Ptr<UanChannel> channel = CreateObject<UanChannel> ();
154 channel->SetAttribute ("PropagationModel", PointerValue (prop));
155
156 Ptr<UanNetDevice> dev0 = CreateNode (Vector (r1,50,50), channel);
157 Ptr<UanNetDevice> dev1 = CreateNode (Vector (0,50,50), channel);
158 Ptr<UanNetDevice> dev2 = CreateNode (Vector (r1 + r2, 50, 50), channel);
159
160 dev0->SetReceiveCallback (MakeCallback (&UanTest::RxPacket, this));
161
162 Simulator::Schedule (txTime1, &UanTest::SendOnePacket, this, dev1, mode1);
163 Simulator::Schedule (txTime2, &UanTest::SendOnePacket, this, dev2, mode2);
164
165 m_bytesRx = 0;
166 Simulator::Stop (Seconds (20.0));
168 Simulator::Destroy ();
169
170 return m_bytesRx;
171}
172
173
174bool
176{
177 // Phy Gen / Default PER / Default SINR
178 UanModesList mList;
179 UanTxMode mode = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 10000, 4000, 2, "TestMode");
180 mList.AppendMode (UanTxMode (mode));
181 Ptr<UanPhyPerGenDefault> perDef = CreateObject<UanPhyPerGenDefault> ();
182 Ptr<UanPhyCalcSinrDefault> sinrDef = CreateObject<UanPhyCalcSinrDefault> ();
183 m_phyFac.SetTypeId ("ns3::UanPhyGen");
184 m_phyFac.Set ("PerModel", PointerValue (perDef));
185 m_phyFac.Set ("SinrModel", PointerValue (sinrDef));
186 m_phyFac.Set ("SupportedModes", UanModesListValue (mList));
187
188 Ptr<UanPropModelIdeal> prop = CreateObject<UanPropModelIdeal> ();
189
190 // No collision (Get 2 packets)
191 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (3.001), 50, 50, prop),
192 34, "Should have received 34 bytes from 2 disjoint packets");
193
194 // Collision (Lose both packets)
195 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop),
196 0, "Expected collision resulting in loss of both packets");
197
198
199 // Phy Gen / FH-FSK SINR check
200
201 Ptr<UanPhyCalcSinrFhFsk> sinrFhfsk = CreateObject <UanPhyCalcSinrFhFsk> ();
202 m_phyFac.Set ("PerModel", PointerValue (perDef));
203 m_phyFac.Set ("SinrModel", PointerValue (sinrFhfsk));
204 m_phyFac.Set ("SupportedModes", UanModesListValue (mList));
205
206#ifdef UAN_PROP_BH_INSTALLED
207 Ptr<UanPropModelBh> prop = CreateObject<UanPropModelBh> ();
208#endif // UAN_PROP_BH_INSTALLED
209
210 // No collision (Get 2 packets)
211 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (3.001), 50, 50, prop),
212 34, "Should have received 34 bytes from 2 disjoint packets");
213
214 // Should correctly receive first arriving packet
215 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (1.0126), 50, 50, prop),
216 17, "Should have received 17 bytes from first arriving packet");
217
218 // Packets should collide and both be lost
219 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (1.0 + 7.01 * (13.0 / 80.0)), 50, 50, prop),
220 0, "Packets should collide, but received data");
221
222 // Phy Dual
223 UanTxMode mode00 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 10000, 4000, 2, "TestMode00");
224 UanTxMode mode10 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 11000, 4000, 2, "TestMode10");
225 UanTxMode mode20 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 15000, 4000, 2, "TestMode20");
226 UanTxMode mode01 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 10000, 4000, 2, "TestMode01");
227 UanTxMode mode11 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 11000, 4000, 2, "TestMode11");
228 UanTxMode mode21 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 15000, 4000, 2, "TestMode21");
229
230 UanModesList m0;
231 m0.AppendMode (mode00);
232 m0.AppendMode (mode10);
233 m0.AppendMode (mode20);
235 m1.AppendMode (mode01);
236 m1.AppendMode (mode11);
237 m1.AppendMode (mode21);
238
240 m_phyFac.SetTypeId ("ns3::UanPhyDual");
241 m_phyFac.Set ("SupportedModesPhy1", UanModesListValue (m0));
242 m_phyFac.Set ("SupportedModesPhy2", UanModesListValue (m1));
243
244 // No collision (Get 2 packets)
245 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (3.01), 50, 50, prop),
246 34, "Expected no collision");
247
248 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop, 0, 0),
249 0, "Expected collision with both packets lost");
250
251 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop, 0, 2),
252 17, "Expected collision with only one packets lost");
253
254 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop, 0, 5),
255 34, "Expected no collision");
256
257 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop, 2, 3),
258 34, "Expected no collision");
259
260 return false;
261}
262
263void
265{
266
267 Ptr<UanPhyPerUmodem> per = CreateObject<UanPhyPerUmodem> ();
268 Ptr<Packet> pkt = Create<Packet> (1000);
269 double error = per->CalcPer (pkt, 9, UanPhyGen::GetDefaultModes ()[0]);
270 NS_TEST_ASSERT_MSG_EQ_TOL (error, 0.539, 0.001, "Got PER outside of tolerance");
271
272#ifdef UAN_PROP_BH_INSTALLED
273 // Correct DB lookup for BH prop.
274 Ptr<UanPropModelBh> propBh = CreateObject<UanPropModelBh> ();
275 BellhopResp resp = propBh->GetResp (10000, 50, 50, 1000);
276
277 NS_TEST_ASSERT_MSG_EQ_TOL (resp.GetPathLossDb (), -44.1753, 0.001, "Got BH Pathloss outside of tolerance");
278
279 NS_TEST_ASSERT_MSG_EQ_TOL (resp.GetPdp ().GetTap (4).GetAmp (), 0.14159, 0.001, "Got BH arrival outside of tolerance");
280
281#endif // UAN_PROP_BH_INSTALLED
282
283 DoPhyTests ();
284}
285
293{
294public:
295 UanTestSuite ();
296};
297
299 : TestSuite ("devices-uan", UNIT)
300{
301 AddTestCase (new UanTest, TestCase::QUICK);
302}
303
305
void Run(ObjectFactory &factory, uint32_t pop, uint32_t total, uint32_t runs, Ptr< RandomVariableStream > eventStream, bool calRev)
Perform the runs for a single scheduler type.
Uan Test.
Definition: uan-test.cc:44
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: uan-test.cc:264
bool RxPacket(Ptr< NetDevice > dev, Ptr< const Packet > pkt, uint16_t mode, const Address &sender)
Receive packet function.
Definition: uan-test.cc:101
Ptr< UanNetDevice > CreateNode(Vector pos, Ptr< UanChannel > chan)
Create node function.
Definition: uan-test.cc:117
void SendOnePacket(Ptr< UanNetDevice > dev, uint16_t mode)
Send one packet function.
Definition: uan-test.cc:109
uint32_t DoOnePhyTest(Time t1, Time t2, uint32_t r1, uint32_t r2, Ptr< UanPropModel > prop, uint16_t mode1=0, uint16_t mode2=0)
Do one Phy test function.
Definition: uan-test.cc:144
uint32_t m_bytesRx
byes received
Definition: uan-test.cc:90
ObjectFactory m_phyFac
Phy.
Definition: uan-test.cc:89
UanTest()
Definition: uan-test.cc:95
bool DoPhyTests()
Phy test function.
Definition: uan-test.cc:175
Uan Test Suite.
Definition: uan-test.cc:293
a polymophic address class
Definition: address.h:91
Instantiate subclasses of ns3::Object.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
Container for UanTxModes.
Definition: uan-tx-mode.h:258
void AppendMode(UanTxMode mode)
Add mode to this list.
Definition: uan-tx-mode.cc:232
AttributeValue implementation for UanModesList.
Base class for UAN Phy models.
Definition: uan-phy.h:179
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:42
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:192
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition: test.h:323
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
const double m1
First component modulus, 232 - 209.
Definition: rng-stream.cc:58
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
channel
Definition: third.py:83
mac
Definition: third.py:87
mobility
Definition: third.py:98
phy
Definition: third.py:84
static UanTestSuite g_uanTestSuite
the test suite
Definition: uan-test.cc:304