A Discrete-Event Network Simulator
API
wifi-error-rate-models-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 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: Tom Henderson (tomhend@u.washington.edu)
19  */
20 
21 #include "ns3/test.h"
22 #include "ns3/nist-error-rate-model.h"
23 #include "ns3/dsss-error-rate-model.h"
24 #include "ns3/wifi-phy.h"
25 #include "ns3/wifi-utils.h"
26 
27 using namespace ns3;
28 
29 double
30 FromRss (double rssDbw)
31 {
32  // SINR is based on receiver noise figure of 7 dB and thermal noise
33  // of -100.5522786 dBm in this 22 MHz bandwidth at 290K
34  double noisePowerDbw = -100.5522786 + 7;
35 
36  double sinrDb = rssDbw - noisePowerDbw;
37  // return SINR expressed as ratio
38  return pow (10.0, sinrDb / 10.0);
39 }
40 
48 {
49 public:
52 
53 private:
54  virtual void DoRun (void);
55 };
56 
58  : TestCase ("WifiErrorRateModel test case DSSS")
59 {
60 }
61 
63 {
64 }
65 
66 void
68 {
69 
70  // 1024 bytes plus headers
71  uint64_t size = (1024 + 40 + 14) * 8;
72  // Spot test some values returned from DsssErrorRateModel
73  // Values taken from sample 80211b.c program used in validation paper
74  double value;
75  // DBPSK
76  value = DsssErrorRateModel::GetDsssDbpskSuccessRate (FromRss (-105.0), size);
77  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0, 1e-13, "Not equal within tolerance");
78  value = DsssErrorRateModel::GetDsssDbpskSuccessRate (FromRss (-100.0), size);
79  NS_TEST_ASSERT_MSG_EQ_TOL (value, 1.5e-13, 1e-13, "Not equal within tolerance");
80  value = DsssErrorRateModel::GetDsssDbpskSuccessRate (FromRss (-99.0), size);
81  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.0003, 0.0001, "Not equal within tolerance");
82  value = DsssErrorRateModel::GetDsssDbpskSuccessRate (FromRss (-98.0), size);
83  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.202, 0.005, "Not equal within tolerance");
84  value = DsssErrorRateModel::GetDsssDbpskSuccessRate (FromRss (-97.0), size);
85  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.813, 0.005, "Not equal within tolerance");
86  value = DsssErrorRateModel::GetDsssDbpskSuccessRate (FromRss (-96.0), size);
87  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.984, 0.005, "Not equal within tolerance");
88  value = DsssErrorRateModel::GetDsssDbpskSuccessRate (FromRss (-95.0), size);
89  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.999, 0.001, "Not equal within tolerance");
90  value = DsssErrorRateModel::GetDsssDbpskSuccessRate (FromRss (-90.0), size);
91  NS_TEST_ASSERT_MSG_EQ_TOL (value, 1, 0.001, "Not equal within tolerance");
92 
93  // DQPSK
94  //
95  value = DsssErrorRateModel::GetDsssDqpskSuccessRate (FromRss (-96.0), size);
96  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0, 1e-13, "Not equal within tolerance");
97  value = DsssErrorRateModel::GetDsssDqpskSuccessRate (FromRss (-95.0), size);
98  NS_TEST_ASSERT_MSG_EQ_TOL (value, 4.5e-6, 1e-6, "Not equal within tolerance");
99  value = DsssErrorRateModel::GetDsssDqpskSuccessRate (FromRss (-94.0), size);
100  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.036, 0.005, "Not equal within tolerance");
101  value = DsssErrorRateModel::GetDsssDqpskSuccessRate (FromRss (-93.0), size);
102  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.519, 0.005, "Not equal within tolerance");
103  value = DsssErrorRateModel::GetDsssDqpskSuccessRate (FromRss (-92.0), size);
104  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.915, 0.005, "Not equal within tolerance");
105  value = DsssErrorRateModel::GetDsssDqpskSuccessRate (FromRss (-91.0), size);
106  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.993, 0.005, "Not equal within tolerance");
107  value = DsssErrorRateModel::GetDsssDqpskSuccessRate (FromRss (-90.0), size);
108  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.999, 0.001, "Not equal within tolerance");
109  value = DsssErrorRateModel::GetDsssDqpskSuccessRate (FromRss (-89.0), size);
110  NS_TEST_ASSERT_MSG_EQ_TOL (value, 1, 0.001, "Not equal within tolerance");
111 
112 #ifdef HAVE_GSL
113  // DQPSK_CCK5.5
114  value = DsssErrorRateModel::GetDsssDqpskCck5_5SuccessRate (FromRss (-94.0), size);
115  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0, 1e-13, "Not equal within tolerance");
116  value = DsssErrorRateModel::GetDsssDqpskCck5_5SuccessRate (FromRss (-93.0), size);
117  NS_TEST_ASSERT_MSG_EQ_TOL (value, 6.6e-14, 5e-14, "Not equal within tolerance");
118  value = DsssErrorRateModel::GetDsssDqpskCck5_5SuccessRate (FromRss (-92.0), size);
119  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.0001, 0.00005, "Not equal within tolerance");
120  value = DsssErrorRateModel::GetDsssDqpskCck5_5SuccessRate (FromRss (-91.0), size);
121  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.132, 0.005, "Not equal within tolerance");
122  value = DsssErrorRateModel::GetDsssDqpskCck5_5SuccessRate (FromRss (-90.0), size);
123  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.744, 0.005, "Not equal within tolerance");
124  value = DsssErrorRateModel::GetDsssDqpskCck5_5SuccessRate (FromRss (-89.0), size);
125  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.974, 0.005, "Not equal within tolerance");
126  value = DsssErrorRateModel::GetDsssDqpskCck5_5SuccessRate (FromRss (-88.0), size);
127  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.999, 0.001, "Not equal within tolerance");
128  value = DsssErrorRateModel::GetDsssDqpskCck5_5SuccessRate (FromRss (-87.0), size);
129  NS_TEST_ASSERT_MSG_EQ_TOL (value, 1, 0.001, "Not equal within tolerance");
130 
131  // DQPSK_CCK11
132  value = DsssErrorRateModel::GetDsssDqpskCck11SuccessRate (FromRss (-91.0), size);
133  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0, 1e-14, "Not equal within tolerance");
134  value = DsssErrorRateModel::GetDsssDqpskCck11SuccessRate (FromRss (-90.0), size);
135  NS_TEST_ASSERT_MSG_EQ_TOL (value, 4.7e-14, 1e-14, "Not equal within tolerance");
136  value = DsssErrorRateModel::GetDsssDqpskCck11SuccessRate (FromRss (-89.0), size);
137  NS_TEST_ASSERT_MSG_EQ_TOL (value, 8.85e-5, 1e-5, "Not equal within tolerance");
138  value = DsssErrorRateModel::GetDsssDqpskCck11SuccessRate (FromRss (-88.0), size);
139  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.128, 0.005, "Not equal within tolerance");
140  value = DsssErrorRateModel::GetDsssDqpskCck11SuccessRate (FromRss (-87.0), size);
141  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.739, 0.005, "Not equal within tolerance");
142  value = DsssErrorRateModel::GetDsssDqpskCck11SuccessRate (FromRss (-86.0), size);
143  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.973, 0.005, "Not equal within tolerance");
144  value = DsssErrorRateModel::GetDsssDqpskCck11SuccessRate (FromRss (-85.0), size);
145  NS_TEST_ASSERT_MSG_EQ_TOL (value, 0.999, 0.001, "Not equal within tolerance");
146  value = DsssErrorRateModel::GetDsssDqpskCck11SuccessRate (FromRss (-84.0), size);
147  NS_TEST_ASSERT_MSG_EQ_TOL (value, 1, 0.001, "Not equal within tolerance");
148 #endif
149 }
150 
158 {
159 public:
162 
163 private:
164  virtual void DoRun (void);
165 };
166 
168  : TestCase ("WifiErrorRateModel test case NIST")
169 {
170 }
171 
173 {
174 }
175 
176 void
178 {
179 
180  uint32_t FrameSize = 2000;
181  WifiTxVector txVector;
182  Ptr<NistErrorRateModel> nist = CreateObject<NistErrorRateModel> ();
183 
184  double ps; // probability of success
185  double snr; // dB
186 
187  // Spot test some values returned from NistErrorRateModel
188  // values can be generated by the example program ofdm-validation.cc
189  snr = 2.5;
190  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate6Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
191  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 2.04e-10, 1e-10, "Not equal within tolerance");
192  snr = 3.0;
193  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate6Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
194  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.020, 0.001, "Not equal within tolerance");
195  snr = 4.0;
196  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate6Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
197  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.885, 0.001, "Not equal within tolerance");
198  snr = 5.0;
199  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate6Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
200  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.997, 0.001, "Not equal within tolerance");
201 
202  snr = 6.0;
203  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate9Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
204  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.097, 0.001, "Not equal within tolerance");
205  snr = 7.0;
206  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate9Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
207  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.918, 0.001, "Not equal within tolerance");
208  snr = 8.0;
209  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate9Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
210  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.998, 0.001, "Not equal within tolerance");
211  snr = 9.0;
212  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate9Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
213  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.999, 0.001, "Not equal within tolerance");
214 
215  snr = 6.0;
216  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate12Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
217  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.0174, 0.001, "Not equal within tolerance");
218  snr = 7.0;
219  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate12Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
220  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.881, 0.001, "Not equal within tolerance");
221  snr = 8.0;
222  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate12Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
223  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.997, 0.001, "Not equal within tolerance");
224  snr = 9.0;
225  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate12Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
226  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.999, 0.001, "Not equal within tolerance");
227 
228  snr = 8.5;
229  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate18Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
230  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 2.85e-6, 1e-6, "Not equal within tolerance");
231  snr = 9.5;
232  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate18Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
233  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.623, 0.001, "Not equal within tolerance");
234  snr = 10.5;
235  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate18Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
236  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.985, 0.001, "Not equal within tolerance");
237  snr = 11.5;
238  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate18Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
239  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.999, 0.001, "Not equal within tolerance");
240 
241  snr = 12.0;
242  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate24Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
243  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 2.22e-7, 1e-7, "Not equal within tolerance");
244  snr = 13.0;
245  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate24Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
246  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.495, 0.001, "Not equal within tolerance");
247  snr = 14.0;
248  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate24Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
249  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.974, 0.001, "Not equal within tolerance");
250  snr = 15.0;
251  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate24Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
252  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.999, 0.001, "Not equal within tolerance");
253 
254  snr = 15.5;
255  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate36Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
256  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.012, 0.001, "Not equal within tolerance");
257  snr = 16.5;
258  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate36Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
259  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.818, 0.001, "Not equal within tolerance");
260  snr = 17.5;
261  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate36Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
262  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.993, 0.001, "Not equal within tolerance");
263  snr = 18.5;
264  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate36Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
265  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.999, 0.001, "Not equal within tolerance");
266 
267  snr = 20.0;
268  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate48Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
269  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 1.3e-4, 1e-4, "Not equal within tolerance");
270  snr = 21.0;
271  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate48Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
272  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.649, 0.001, "Not equal within tolerance");
273  snr = 22.0;
274  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate48Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
275  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.983, 0.001, "Not equal within tolerance");
276  snr = 23.0;
277  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate48Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
278  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.999, 0.001, "Not equal within tolerance");
279 
280  snr = 21.0;
281  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate54Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
282  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 5.44e-8, 1e-8, "Not equal within tolerance");
283  snr = 22.0;
284  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate54Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
285  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.410, 0.001, "Not equal within tolerance");
286  snr = 23.0;
287  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate54Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
288  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.958, 0.001, "Not equal within tolerance");
289  snr = 24.0;
290  ps = nist->GetChunkSuccessRate (WifiMode ("OfdmRate54Mbps"), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
291  NS_TEST_ASSERT_MSG_EQ_TOL (ps, 0.999, 0.001, "Not equal within tolerance");
292 }
293 
295 {
296 public:
297  using InterferenceHelper::InterferenceHelper;
298  using InterferenceHelper::CalculateChunkSuccessRate;
299  using InterferenceHelper::CalculateSnr;
300 };
301 
309 {
310 public:
313 
314 private:
315  virtual void DoRun (void);
316 };
317 
319  : TestCase ("WifiErrorRateModel test case MIMO")
320 {
321 }
322 
324 {
325 }
326 
327 void
329 {
330  TestInterferenceHelper interference;
331  interference.SetNoiseFigure (0);
332  WifiMode mode = WifiPhy::GetHtMcs0 ();
333  WifiTxVector txVector;
334 
335  txVector.SetMode (mode);
336  txVector.SetTxPowerLevel (0);
337  txVector.SetChannelWidth (20);
338  txVector.SetNss (1);
339  txVector.SetNTx (1);
340 
341  interference.SetNumberOfReceiveAntennas (1);
342  Ptr<NistErrorRateModel> nist = CreateObject<NistErrorRateModel> ();
343  interference.SetErrorRateModel (nist);
344 
345  // SISO: initial SNR set to 4dB
346  double initialSnr = 4.0;
347  double snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
348  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr, 0.1, "Attempt to set initial SNR to known value failed");
349  Time duration = MilliSeconds (2);
350  double chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
351  NS_TEST_ASSERT_MSG_EQ_TOL (chunkSuccess, 0.905685, 0.000001, "CSR not within tolerance for SISO");
352  double sisoChunkSuccess = chunkSuccess;
353 
354  // MIMO 2x1:2: expect no SNR gain in AWGN channel
355  txVector.SetNss (2);
356  txVector.SetNTx (2);
357  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
358  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr, 0.1, "SNR not within tolerance for 2x1:2 MIMO");
359  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
360  NS_TEST_ASSERT_MSG_EQ_TOL (chunkSuccess, 0.905685, 0.000001, "CSR not within tolerance for SISO");
361 
362  // MIMO 1x2:1: expect that SNR is increased by a factor of 3 dB (10 log 2/1) compared to SISO thanks to RX diversity
363  txVector.SetNss (1);
364  txVector.SetNTx (1);
365  interference.SetNumberOfReceiveAntennas (2);
366  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
367  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr + 3, 0.1, "SNR not within tolerance for 1x2:1 MIMO");
368  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
369  NS_TEST_ASSERT_MSG_GT (chunkSuccess, sisoChunkSuccess, "CSR not within tolerance for 1x2:1 MIMO");
370 
371  // MIMO 2x2:1: expect that SNR is increased by a factor of 3 dB (10 log 2/1) compared to SISO thanks to RX diversity
372  txVector.SetNss (1);
373  txVector.SetNTx (2);
374  interference.SetNumberOfReceiveAntennas (2);
375  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
376  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr + 3, 0.1, "SNR not equal within tolerance for 2x2:1 MIMO");
377  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
378  NS_TEST_ASSERT_MSG_GT (chunkSuccess, sisoChunkSuccess, "CSR not within tolerance for 2x2:1 MIMO");
379 
380  // MIMO 2x2:2: expect no SNR gain in AWGN channel
381  txVector.SetNss (2);
382  txVector.SetNTx (2);
383  interference.SetNumberOfReceiveAntennas (2);
384  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
385  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr, 0.1, "SNR not equal within tolerance for 2x2:2 MIMO");
386  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
387  NS_TEST_ASSERT_MSG_EQ_TOL (chunkSuccess, sisoChunkSuccess, 0.000001, "CSR not within tolerance for 2x2:2 MIMO");
388 
389  // MIMO 3x3:1: expect that SNR is increased by a factor of 4.8 dB (10 log 3/1) compared to SISO thanks to RX diversity
390  txVector.SetNss (1);
391  txVector.SetNTx (3);
392  interference.SetNumberOfReceiveAntennas (3);
393  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
394  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr + 4.8, 0.1, "SNR not within tolerance for 3x3:1 MIMO");
395  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
396  NS_TEST_ASSERT_MSG_GT (chunkSuccess, sisoChunkSuccess, "CSR not within tolerance for 3x3:1 MIMO");
397 
398  // MIMO 3x3:2: expect that SNR is increased by a factor of 1.8 dB (10 log 3/2) compared to SISO thanks to RX diversity
399  txVector.SetNss (2);
400  txVector.SetNTx (3);
401  interference.SetNumberOfReceiveAntennas (3);
402  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
403  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr + 1.8, 0.1, "SNR not within tolerance for 3x3:2 MIMO");
404  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
405  NS_TEST_ASSERT_MSG_GT (chunkSuccess, sisoChunkSuccess, "CSR not within tolerance for 3x3:2 MIMO");
406 
407  // MIMO 3x3:3: expect no SNR gain in AWGN channel
408  txVector.SetNss (3);
409  txVector.SetNTx (3);
410  interference.SetNumberOfReceiveAntennas (3);
411  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
412  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr, 0.1, "SNR not within tolerance for 3x3:3 MIMO");
413  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
414  NS_TEST_ASSERT_MSG_EQ_TOL (chunkSuccess, sisoChunkSuccess, 0.000001, "CSR not equal within tolerance for 3x3:3 MIMO");
415 
416  // MIMO 4x4:1: expect that SNR is increased by a factor of 6 dB (10 log 4/1) compared to SISO thanks to RX diversity
417  txVector.SetNss (1);
418  txVector.SetNTx (4);
419  interference.SetNumberOfReceiveAntennas (4);
420  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
421  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr + 6, 0.1, "SNR not within tolerance for 4x4:1 MIMO");
422  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
423  NS_TEST_ASSERT_MSG_GT (chunkSuccess, sisoChunkSuccess, "CSR not within tolerance for 4x4:1 MIMO");
424 
425  // MIMO 4x4:2: expect that SNR is increased by a factor of 3 dB (10 log 4/2) compared to SISO thanks to RX diversity
426  txVector.SetNss (2);
427  txVector.SetNTx (4);
428  interference.SetNumberOfReceiveAntennas (4);
429  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
430  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr + 3, 0.1, "SNR not within tolerance for 4x4:2 MIMO");
431  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
432  NS_TEST_ASSERT_MSG_GT (chunkSuccess, sisoChunkSuccess, "CSR not within tolerance for 4x4:2 MIMO");
433 
434  // MIMO 4x4:3: expect that SNR is increased by a factor of 1.2 dB (10 log 4/3) compared to SISO thanks to RX diversity
435  txVector.SetNss (3);
436  txVector.SetNTx (4);
437  interference.SetNumberOfReceiveAntennas (4);
438  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
439  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr + 1.2, 0.1, "SNR not within tolerance for 4x4:3 MIMO");
440  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
441  NS_TEST_ASSERT_MSG_GT (chunkSuccess, sisoChunkSuccess, "CSR not within tolerance for 4x4:1 MIMO");
442 
443  // MIMO 4x4:4: expect no SNR gain in AWGN channel
444  txVector.SetNss (4);
445  txVector.SetNTx (4);
446  interference.SetNumberOfReceiveAntennas (4);
447  snr = interference.CalculateSnr (0.001, 0.001 / DbToRatio (initialSnr), txVector);
448  NS_TEST_ASSERT_MSG_EQ_TOL (RatioToDb (snr), initialSnr, 0.1, "SNR not within tolerance for 4x4:4 MIMO");
449  chunkSuccess = interference.CalculateChunkSuccessRate (snr, duration, mode, txVector);
450  NS_TEST_ASSERT_MSG_EQ_TOL (chunkSuccess, sisoChunkSuccess, 0.000001, "CSR not within tolerance for 4x4:4 MIMO");
451 }
452 
460 {
461 public:
463 };
464 
466  : TestSuite ("wifi-error-rate-models", UNIT)
467 {
468  AddTestCase (new WifiErrorRateModelsTestCaseDsss, TestCase::QUICK);
469  AddTestCase (new WifiErrorRateModelsTestCaseNist, TestCase::QUICK);
470  AddTestCase (new WifiErrorRateModelsTestCaseMimo, TestCase::QUICK);
471 }
472 
474 
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetNumberOfReceiveAntennas(uint8_t rx)
Set the number of RX antennas in the receiver corresponding to this interference helper.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
static WifiErrorRateModelsTestSuite wifiErrorRateModelsTestSuite
the test suite
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
A suite of tests to run.
Definition: test.h:1343
handles interference calculations
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Set the error rate model for this interference helper.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1286
encapsulates test code
Definition: test.h:1153
double FromRss(double rssDbw)
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
double CalculateChunkSuccessRate(double snir, Time duration, WifiMode mode, WifiTxVector txVector) const
Calculate the success rate of the chunk given the SINR, duration, and Wi-Fi mode. ...
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
#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:378
void SetNss(uint8_t nss)
Sets the number of Nss refer to IEEE 802.11n Table 20-28 for explanation and range.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double CalculateSnr(Ptr< Event > event) const
Calculate the SNIR for the event (starting from now until the event end).
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetNTx(uint8_t nTx)
Sets the number of TX antennas.
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:35
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:53
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Wifi Error Rate Models Test Case MIMO.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SetNoiseFigure(double value)
Set the noise figure.
Wifi Error Rate Models Test Case Nist.
double GetChunkSuccessRate(WifiMode mode, WifiTxVector txVector, double snr, uint64_t nbits) const
A pure virtual method that must be implemented in the subclass.
Wifi Error Rate Models Test Suite.
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition: test.h:995
Wifi Error Rate Models Test Case Dsss.