A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-error-model-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tom Henderson <thomas.r.henderson@boeing.com>
7 */
8#include "ns3/callback.h"
9#include "ns3/constant-position-mobility-model.h"
10#include "ns3/log.h"
11#include "ns3/lr-wpan-error-model.h"
12#include "ns3/lr-wpan-mac.h"
13#include "ns3/lr-wpan-net-device.h"
14#include "ns3/mac16-address.h"
15#include "ns3/net-device.h"
16#include "ns3/node.h"
17#include "ns3/packet.h"
18#include "ns3/propagation-loss-model.h"
19#include "ns3/rng-seed-manager.h"
20#include "ns3/simulator.h"
21#include "ns3/single-model-spectrum-channel.h"
22#include "ns3/test.h"
23
24using namespace ns3;
25using namespace ns3::lrwpan;
26
27NS_LOG_COMPONENT_DEFINE("lr-wpan-error-model-test");
28
29/**
30 * @ingroup lr-wpan-test
31 * @ingroup tests
32 *
33 * @brief LrWpan Error Vs Distance Test
34 */
36{
37 public:
40
41 /**
42 * @brief Get the number of received packets.
43 * @returns The number of received packets.
44 */
46 {
47 return m_received;
48 }
49
50 private:
51 void DoRun() override;
52
53 /**
54 * @brief Function to be called when a packet is received.
55 * @param params MCPS params.
56 * @param p The packet.
57 */
59 uint32_t m_received; //!< The number of received packets.
60};
61
62/**
63 * @ingroup lr-wpan-test
64 * @ingroup tests
65 *
66 * @brief LrWpan Error model Test
67 */
69{
70 public:
73
74 private:
75 void DoRun() override;
76};
77
79 : TestCase("IEEE 802.15.4 distance error model test"),
80 m_received(0)
81{
82}
83
87
88void
93
94void
96{
97 // Set the random seed and run number for this test
100
105
106 // Make random variable stream assignment deterministic
107 dev0->AssignStreams(0);
108 dev1->AssignStreams(10);
109
110 dev0->SetAddress(Mac16Address("00:01"));
111 dev1->SetAddress(Mac16Address("00:02"));
114 channel->AddPropagationLossModel(model);
115 dev0->SetChannel(channel);
116 dev1->SetChannel(channel);
117 n0->AddDevice(dev0);
118 n1->AddDevice(dev1);
120 dev0->GetPhy()->SetMobility(mob0);
122 dev1->GetPhy()->SetMobility(mob1);
123
126 dev1->GetMac()->SetMcpsDataIndicationCallback(cb0);
127
129 params.m_srcAddrMode = SHORT_ADDR;
130 params.m_dstAddrMode = SHORT_ADDR;
131 params.m_dstPanId = 0;
132 params.m_dstAddr = Mac16Address("00:02");
133 params.m_msduHandle = 0;
134 params.m_txOptions = 0;
135
136 Ptr<Packet> p;
137 mob0->SetPosition(Vector(0, 0, 0));
138 mob1->SetPosition(Vector(95, 0, 0));
139 for (int i = 0; i < 1000; i++)
140 {
141 p = Create<Packet>(20);
142 Simulator::Schedule(Seconds(i), &LrWpanMac::McpsDataRequest, dev0->GetMac(), params, p);
143 }
144
146
147 // Test that we received fewer packets than 1000, at distance less than 100 m
148 // with default Tx power of 0 dBm using the default maximum sensitivity (-106.58 dBm).
150 990,
151 "Not enough packets received, distance model failure");
153 1000,
154 "Too many packets received, distance model failure");
155
157}
158
159// ==============================================================================
161 : TestCase("Test the 802.15.4 error model")
162{
163}
164
168
169void
171{
173
174 // Test a few values
175 double snr = 5;
176 double ber = 1.0 - model->GetChunkSuccessRate(pow(10.0, snr / 10.0), 1);
177 NS_TEST_ASSERT_MSG_EQ_TOL(ber, 7.38e-14, 0.01e-14, "Model fails for SNR = " << snr);
178 snr = 2;
179 ber = 1.0 - model->GetChunkSuccessRate(pow(10.0, snr / 10.0), 1);
180 NS_TEST_ASSERT_MSG_EQ_TOL(ber, 5.13e-7, 0.01e-7, "Model fails for SNR = " << snr);
181 snr = -1;
182 ber = 1.0 - model->GetChunkSuccessRate(pow(10.0, snr / 10.0), 1);
183 NS_TEST_ASSERT_MSG_EQ_TOL(ber, 0.00114, 0.00001, "Model fails for SNR = " << snr);
184 snr = -4;
185 ber = 1.0 - model->GetChunkSuccessRate(pow(10.0, snr / 10.0), 1);
186 NS_TEST_ASSERT_MSG_EQ_TOL(ber, 0.0391, 0.0001, "Model fails for SNR = " << snr);
187 snr = -7;
188 ber = 1.0 - model->GetChunkSuccessRate(pow(10.0, snr / 10.0), 1);
189 NS_TEST_ASSERT_MSG_EQ_TOL(ber, 0.175, 0.001, "Model fails for SNR = " << snr);
190}
191
192/**
193 * @ingroup lr-wpan-test
194 * @ingroup tests
195 *
196 * @brief LrWpan Error model TestSuite
197 */
199{
200 public:
202};
203
210
212 g_lrWpanErrorModelTestSuite; //!< Static variable for test initialization
LrWpan Error Vs Distance Test.
void Callback(McpsDataIndicationParams params, Ptr< Packet > p)
Function to be called when a packet is received.
uint32_t GetReceived() const
Get the number of received packets.
uint32_t m_received
The number of received packets.
void DoRun() override
Implementation to actually run this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
LrWpan Error model TestSuite.
This class can contain 16 bit addresses.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void Run()
Run the simulation.
Definition simulator.cc:161
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
void McpsDataRequest(McpsDataRequestParams params, Ptr< Packet > p) override
IEEE 802.15.4-2006, section 7.1.1.1 MCPS-DATA.request Request to transfer a MSDU.
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:690
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
Callback< void, McpsDataIndicationParams, Ptr< Packet > > McpsDataIndicationCallback
This callback is called after a Mcps has successfully received a frame and wants to deliver it to the...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:454
#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:326
#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report and abort if not.
Definition test.h:739
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not.
Definition test.h:904
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
static LrWpanErrorModelTestSuite g_lrWpanErrorModelTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.