A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
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: Leonard Tracy <lentracy@gmail.com>
18 */
19
20#include "ns3/callback.h"
21#include "ns3/constant-position-mobility-model.h"
22#include "ns3/node.h"
23#include "ns3/object-factory.h"
24#include "ns3/pointer.h"
25#include "ns3/simulator.h"
26#include "ns3/test.h"
27#include "ns3/uan-channel.h"
28#include "ns3/uan-mac-aloha.h"
29#include "ns3/uan-net-device.h"
30#include "ns3/uan-phy-gen.h"
31#include "ns3/uan-prop-model-ideal.h"
32#include "ns3/uan-transducer-hd.h"
33
34using namespace ns3;
35
36/**
37 * \ingroup uan-test
38 * \ingroup tests
39 *
40 * \brief Uan Test
41 */
42class UanTest : public TestCase
43{
44 public:
45 UanTest();
46
47 void DoRun() override;
48
49 private:
50 /**
51 * Create node function
52 * \param pos the position of the device
53 * \param chan the communication channel
54 * \returns the UAN device
55 */
57 /**
58 * Phy test function
59 * \returns true if successful
60 */
61 bool DoPhyTests();
62 /**
63 * Do one Phy test function
64 * \param t1 the time to send first packet
65 * \param t2 the time to send the second packet
66 * \param r1 first distance constant
67 * \param r2 second distance constant
68 * \param prop the propagation model
69 * \param mode1 the send mode for device 1
70 * \param mode2 the send mode for device 2
71 * \returns number of bytes received
72 */
74 Time t2,
75 uint32_t r1,
76 uint32_t r2,
78 uint16_t mode1 = 0,
79 uint16_t mode2 = 0);
80 /**
81 * Receive packet function
82 * \param dev the device
83 * \param pkt the packet
84 * \param mode the receive mode
85 * \param sender the address of the sender
86 * \returns true if successful
87 */
88 bool RxPacket(Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address& sender);
89 /**
90 * Send one packet function
91 * \param dev the device
92 * \param mode the transmit mode
93 */
94 void SendOnePacket(Ptr<UanNetDevice> dev, uint16_t mode);
96 uint32_t m_bytesRx; ///< byes received
97};
98
100 : TestCase("UAN")
101{
102}
103
104bool
107 uint16_t /* mode */,
108 const Address& /* sender */)
109{
110 m_bytesRx += pkt->GetSize();
111 return true;
112}
113
114void
116{
117 Ptr<Packet> pkt = Create<Packet>(17);
118 dev->SetTxModeIndex(mode);
119 dev->Send(pkt, dev->GetBroadcast(), 0);
120}
121
124{
126 Ptr<Node> node = CreateObject<Node>();
127 Ptr<UanNetDevice> dev = CreateObject<UanNetDevice>();
128 Ptr<UanMacAloha> mac = CreateObject<UanMacAloha>();
129 Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel>();
130
131 Ptr<UanTransducerHd> trans = CreateObject<UanTransducerHd>();
132
133 mobility->SetPosition(pos);
134 node->AggregateObject(mobility);
135 mac->SetAddress(Mac8Address::Allocate());
136
137 dev->SetPhy(phy);
138 dev->SetMac(mac);
139 dev->SetChannel(chan);
140 dev->SetTransducer(trans);
141 node->AddDevice(dev);
142
143 return dev;
144}
145
148 Time txTime2,
149 uint32_t r1,
150 uint32_t r2,
152 uint16_t mode1,
153 uint16_t mode2)
154{
155 Ptr<UanChannel> channel = CreateObject<UanChannel>();
156 channel->SetAttribute("PropagationModel", PointerValue(prop));
157
158 Ptr<UanNetDevice> dev0 = CreateNode(Vector(r1, 50, 50), channel);
159 Ptr<UanNetDevice> dev1 = CreateNode(Vector(0, 50, 50), channel);
160 Ptr<UanNetDevice> dev2 = CreateNode(Vector(r1 + r2, 50, 50), channel);
161
162 dev0->SetReceiveCallback(MakeCallback(&UanTest::RxPacket, this));
163
164 Simulator::Schedule(txTime1, &UanTest::SendOnePacket, this, dev1, mode1);
165 Simulator::Schedule(txTime2, &UanTest::SendOnePacket, this, dev2, mode2);
166
167 m_bytesRx = 0;
171
172 return m_bytesRx;
173}
174
175bool
177{
178 // Phy Gen / Default PER / Default SINR
179 UanModesList mList;
180 UanTxMode mode =
181 UanTxModeFactory::CreateMode(UanTxMode::FSK, 80, 80, 10000, 4000, 2, "TestMode");
182 mList.AppendMode(UanTxMode(mode));
183 Ptr<UanPhyPerGenDefault> perDef = CreateObject<UanPhyPerGenDefault>();
184 Ptr<UanPhyCalcSinrDefault> sinrDef = CreateObject<UanPhyCalcSinrDefault>();
185 m_phyFac.SetTypeId("ns3::UanPhyGen");
186 m_phyFac.Set("PerModel", PointerValue(perDef));
187 m_phyFac.Set("SinrModel", PointerValue(sinrDef));
188 m_phyFac.Set("SupportedModes", UanModesListValue(mList));
189
190 Ptr<UanPropModelIdeal> prop = CreateObject<UanPropModelIdeal>();
191
192 // No collision (Get 2 packets)
194 34,
195 "Should have received 34 bytes from 2 disjoint packets");
196
197 // Collision (Lose both packets)
199 0,
200 "Expected collision resulting in loss of both packets");
201
202 // Phy Gen / FH-FSK SINR check
203
204 Ptr<UanPhyCalcSinrFhFsk> sinrFhfsk = CreateObject<UanPhyCalcSinrFhFsk>();
205 m_phyFac.Set("PerModel", PointerValue(perDef));
206 m_phyFac.Set("SinrModel", PointerValue(sinrFhfsk));
207 m_phyFac.Set("SupportedModes", UanModesListValue(mList));
208
209#ifdef UAN_PROP_BH_INSTALLED
210 Ptr<UanPropModelBh> prop = CreateObject<UanPropModelBh>();
211#endif // UAN_PROP_BH_INSTALLED
212
213 // No collision (Get 2 packets)
215 34,
216 "Should have received 34 bytes from 2 disjoint packets");
217
218 // Should correctly receive first arriving packet
220 17,
221 "Should have received 17 bytes from first arriving packet");
222
223 // Packets should collide and both be lost
225 DoOnePhyTest(Seconds(1.0), Seconds(1.0 + 7.01 * (13.0 / 80.0)), 50, 50, prop),
226 0,
227 "Packets should collide, but received data");
228
229 // Phy Dual
230 UanTxMode mode00 =
231 UanTxModeFactory::CreateMode(UanTxMode::FSK, 80, 80, 10000, 4000, 2, "TestMode00");
232 UanTxMode mode10 =
233 UanTxModeFactory::CreateMode(UanTxMode::FSK, 80, 80, 11000, 4000, 2, "TestMode10");
234 UanTxMode mode20 =
235 UanTxModeFactory::CreateMode(UanTxMode::FSK, 80, 80, 15000, 4000, 2, "TestMode20");
236 UanTxMode mode01 =
237 UanTxModeFactory::CreateMode(UanTxMode::FSK, 80, 80, 10000, 4000, 2, "TestMode01");
238 UanTxMode mode11 =
239 UanTxModeFactory::CreateMode(UanTxMode::FSK, 80, 80, 11000, 4000, 2, "TestMode11");
240 UanTxMode mode21 =
241 UanTxModeFactory::CreateMode(UanTxMode::FSK, 80, 80, 15000, 4000, 2, "TestMode21");
242
243 UanModesList m0;
244 m0.AppendMode(mode00);
245 m0.AppendMode(mode10);
246 m0.AppendMode(mode20);
248 m1.AppendMode(mode01);
249 m1.AppendMode(mode11);
250 m1.AppendMode(mode21);
251
253 m_phyFac.SetTypeId("ns3::UanPhyDual");
254 m_phyFac.Set("SupportedModesPhy1", UanModesListValue(m0));
255 m_phyFac.Set("SupportedModesPhy2", UanModesListValue(m1));
256
257 // No collision (Get 2 packets)
259 34,
260 "Expected no collision");
261
263 DoOnePhyTest(Seconds(1.0), Seconds(2.99), 50, 50, prop, 0, 0),
264 0,
265 "Expected collision with both packets lost");
266
268 DoOnePhyTest(Seconds(1.0), Seconds(2.99), 50, 50, prop, 0, 2),
269 17,
270 "Expected collision with only one packets lost");
271
273 DoOnePhyTest(Seconds(1.0), Seconds(2.99), 50, 50, prop, 0, 5),
274 34,
275 "Expected no collision");
276
278 DoOnePhyTest(Seconds(1.0), Seconds(2.99), 50, 50, prop, 2, 3),
279 34,
280 "Expected no collision");
281
282 return false;
283}
284
285void
287{
288 Ptr<UanPhyPerUmodem> per = CreateObject<UanPhyPerUmodem>();
289 Ptr<Packet> pkt = Create<Packet>(1000);
290 double error = per->CalcPer(pkt, 9, UanPhyGen::GetDefaultModes()[0]);
291 NS_TEST_ASSERT_MSG_EQ_TOL(error, 0.539, 0.001, "Got PER outside of tolerance");
292
293#ifdef UAN_PROP_BH_INSTALLED
294 // Correct DB lookup for BH prop.
295 Ptr<UanPropModelBh> propBh = CreateObject<UanPropModelBh>();
296 BellhopResp resp = propBh->GetResp(10000, 50, 50, 1000);
297
298 NS_TEST_ASSERT_MSG_EQ_TOL(resp.GetPathLossDb(),
299 -44.1753,
300 0.001,
301 "Got BH Pathloss outside of tolerance");
302
303 NS_TEST_ASSERT_MSG_EQ_TOL(resp.GetPdp().GetTap(4).GetAmp(),
304 0.14159,
305 0.001,
306 "Got BH arrival outside of tolerance");
307
308#endif // UAN_PROP_BH_INSTALLED
309
310 DoPhyTests();
311}
312
313/**
314 * \ingroup uan-test
315 * \ingroup tests
316 *
317 * \brief Uan Test Suite
318 */
320{
321 public:
322 UanTestSuite();
323};
324
326 : TestSuite("devices-uan", Type::UNIT)
327{
328 AddTestCase(new UanTest, TestCase::Duration::QUICK);
329}
330
331static UanTestSuite g_uanTestSuite; ///< the test suite
Uan Test.
Definition: uan-test.cc:43
bool RxPacket(Ptr< NetDevice > dev, Ptr< const Packet > pkt, uint16_t mode, const Address &sender)
Receive packet function.
Definition: uan-test.cc:105
Ptr< UanNetDevice > CreateNode(Vector pos, Ptr< UanChannel > chan)
Create node function.
Definition: uan-test.cc:123
void SendOnePacket(Ptr< UanNetDevice > dev, uint16_t mode)
Send one packet function.
Definition: uan-test.cc:115
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:147
uint32_t m_bytesRx
byes received
Definition: uan-test.cc:96
ObjectFactory m_phyFac
Phy.
Definition: uan-test.cc:95
UanTest()
Definition: uan-test.cc:99
void DoRun() override
Implementation to actually run this TestCase.
Definition: uan-test.cc:286
bool DoPhyTests()
Phy test function.
Definition: uan-test.cc:176
Uan Test Suite.
Definition: uan-test.cc:320
a polymophic address class
Definition: address.h:101
static Mac8Address Allocate()
Allocates Mac8Address from 0-254.
Definition: mac8-address.cc:94
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
AttributeValue implementation for Pointer.
Definition: pointer.h:48
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
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
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
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Container for UanTxModes.
Definition: uan-tx-mode.h:259
void AppendMode(UanTxMode mode)
Add mode to this list.
Definition: uan-tx-mode.cc:230
AttributeValue implementation for UanModesList.
Definition: uan-tx-mode.h:314
static UanModesList GetDefaultModes()
Get the default transmission modes.
Definition: uan-phy-gen.cc:567
Base class for UAN Phy models.
Definition: uan-phy.h:178
static UanTxMode CreateMode(UanTxMode::ModulationType type, uint32_t dataRateBps, uint32_t phyRateSps, uint32_t cfHz, uint32_t bwHz, uint32_t constSize, std::string name)
Definition: uan-tx-mode.cc:132
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:43
@ FSK
Frequency shift keying.
Definition: uan-tx-mode.h:55
#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:200
#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:338
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
const double m1
First component modulus, 232 - 209.
Definition: rng-stream.cc:60
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:706
static UanTestSuite g_uanTestSuite
the test suite
Definition: uan-test.cc:331