A Discrete-Event Network Simulator
API
tx-duration-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 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 #include <ns3/object.h>
22 #include <ns3/log.h>
23 #include <ns3/test.h>
24 #include <iostream>
25 #include "ns3/interference-helper.h"
26 #include "ns3/yans-wifi-phy.h"
27 
28 using namespace ns3;
29 
30 NS_LOG_COMPONENT_DEFINE ("InterferenceHelperTxDurationTest");
31 
32 static const double CHANNEL_1_MHZ = 2412.0; // a 2.4 GHz center frequency (MHz)
33 static const double CHANNEL_36_MHZ = 5180.0; // a 5 GHz center frequency (MHz)
34 
35 class TxDurationTest : public TestCase
36 {
37 public:
38  TxDurationTest ();
39  virtual ~TxDurationTest ();
40  virtual void DoRun (void);
41 
42 private:
53  bool CheckPayloadDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble, uint32_t knownDurationMicroSeconds);
54 
66  bool CheckTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble, double knownDurationMicroSeconds);
67 
68 };
69 
70 
72  : TestCase ("Wifi TX Duration")
73 {
74 }
75 
76 
78 {
79 }
80 
81 bool
82 TxDurationTest::CheckPayloadDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble, uint32_t knownDurationMicroSeconds)
83 {
84  WifiTxVector txVector;
85  txVector.SetMode (payloadMode);
86  double testedFrequency = CHANNEL_1_MHZ;
87  Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
88  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_OFDM ||
89  payloadMode.GetModulationClass () == WIFI_MOD_CLASS_HT)
90  {
91  testedFrequency = CHANNEL_36_MHZ;
92  }
93  double calculatedDurationMicroSeconds = (double)phy->GetPayloadDuration (size, txVector, preamble, testedFrequency, 0, 0).GetMicroSeconds();;
94  if (calculatedDurationMicroSeconds != knownDurationMicroSeconds)
95  {
96  std::cerr << " size=" << size
97  << " mode=" << payloadMode
98  << " known=" << knownDurationMicroSeconds
99  << " calculated=" << calculatedDurationMicroSeconds
100  << std::endl;
101  return false;
102  }
103  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_HT)
104  {
105  // Durations vary depending on frequency; test also 2.4 GHz (bug 1971)
106  testedFrequency = CHANNEL_1_MHZ;
107  calculatedDurationMicroSeconds = (double)phy->GetPayloadDuration (size, txVector, preamble, testedFrequency, 0, 0).GetMicroSeconds();;
108  if (calculatedDurationMicroSeconds != knownDurationMicroSeconds + 6)
109  {
110  std::cerr << " size=" << size
111  << " mode=" << payloadMode
112  << " known=" << knownDurationMicroSeconds
113  << " calculated=" << calculatedDurationMicroSeconds
114  << std::endl;
115  return false;
116  }
117  }
118  return true;
119 }
120 
121 bool
122 TxDurationTest::CheckTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble, double knownDurationMicroSeconds)
123 {
124  WifiTxVector txVector;
125  txVector.SetMode (payloadMode);
126  txVector.SetNss(1);
127  txVector.SetStbc(0);
128  txVector.SetNess(0);
129  double testedFrequency = CHANNEL_1_MHZ;
130  Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
131  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_OFDM ||
132  payloadMode.GetModulationClass () == WIFI_MOD_CLASS_HT)
133  {
134  testedFrequency = CHANNEL_36_MHZ;
135  }
136  double calculatedDurationMicroSeconds = ((double)phy->CalculateTxDuration (size, txVector, preamble, testedFrequency, 0, 0).GetNanoSeconds ())/1000;
137  if (calculatedDurationMicroSeconds != knownDurationMicroSeconds)
138  {
139  std::cerr << " size=" << size
140  << " mode=" << payloadMode
141  << " preamble=" << preamble
142  << " known=" << knownDurationMicroSeconds
143  << " calculated=" << calculatedDurationMicroSeconds
144  << std::endl;
145  return false;
146  }
147  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_HT)
148  {
149  // Durations vary depending on frequency; test also 2.4 GHz (bug 1971)
150  testedFrequency = CHANNEL_1_MHZ;
151  calculatedDurationMicroSeconds = ((double)phy->CalculateTxDuration (size, txVector, preamble, testedFrequency, 0, 0).GetNanoSeconds ())/1000;
152  if (calculatedDurationMicroSeconds != knownDurationMicroSeconds + 6)
153  {
154  std::cerr << " size=" << size
155  << " mode=" << payloadMode
156  << " preamble=" << preamble
157  << " known=" << knownDurationMicroSeconds
158  << " calculated=" << calculatedDurationMicroSeconds
159  << std::endl;
160  return false;
161  }
162  }
163  return true;
164 }
165 
166 void
168 {
169  bool retval = true;
170 
171 
172  // IEEE Std 802.11-2007 Table 18-2 "Example of LENGTH calculations for CCK"
173  retval = retval
174  && CheckPayloadDuration (1023, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 744)
175  && CheckPayloadDuration (1024, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 745)
176  && CheckPayloadDuration (1025, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 746)
177  && CheckPayloadDuration (1026, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 747);
178 
179  NS_TEST_EXPECT_MSG_EQ (retval, true, "an 802.11b CCK duration failed");
180 
181  // Similar, but we add PLCP preamble and header durations
182  // and we test different rates.
183  // The payload durations for modes other than 11mbb have been
184  // calculated by hand according to IEEE Std 802.11-2007 18.2.3.5
185  retval = retval
186  && CheckTxDuration (1023, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_SHORT, 744 + 96)
187  && CheckTxDuration (1024, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_SHORT, 745 + 96)
188  && CheckTxDuration (1025, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_SHORT, 746 + 96)
189  && CheckTxDuration (1026, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_SHORT, 747 + 96)
190  && CheckTxDuration (1023, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 744 + 192)
191  && CheckTxDuration (1024, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 745 + 192)
192  && CheckTxDuration (1025, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 746 + 192)
193  && CheckTxDuration (1026, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 747 + 192)
194  && CheckTxDuration (1023, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_SHORT, 1488 + 96)
195  && CheckTxDuration (1024, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_SHORT, 1490 + 96)
196  && CheckTxDuration (1025, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_SHORT, 1491 + 96)
197  && CheckTxDuration (1026, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_SHORT, 1493 + 96)
198  && CheckTxDuration (1023, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_LONG, 1488 + 192)
199  && CheckTxDuration (1024, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_LONG, 1490 + 192)
200  && CheckTxDuration (1025, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_LONG, 1491 + 192)
201  && CheckTxDuration (1026, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_LONG, 1493 + 192)
202  && CheckTxDuration (1023, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_SHORT, 4092 + 96)
203  && CheckTxDuration (1024, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_SHORT, 4096 + 96)
204  && CheckTxDuration (1025, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_SHORT, 4100 + 96)
205  && CheckTxDuration (1026, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_SHORT, 4104 + 96)
206  && CheckTxDuration (1023, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_LONG, 4092 + 192)
207  && CheckTxDuration (1024, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_LONG, 4096 + 192)
208  && CheckTxDuration (1025, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_LONG, 4100 + 192)
209  && CheckTxDuration (1026, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_LONG, 4104 + 192)
210  && CheckTxDuration (1023, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_SHORT, 8184 + 96)
211  && CheckTxDuration (1024, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_SHORT, 8192 + 96)
212  && CheckTxDuration (1025, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_SHORT, 8200 + 96)
213  && CheckTxDuration (1026, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_SHORT, 8208 + 96)
214  && CheckTxDuration (1023, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 8184 + 192)
215  && CheckTxDuration (1024, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 8192 + 192)
216  && CheckTxDuration (1025, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 8200 + 192)
217  && CheckTxDuration (1026, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 8208 + 192);
218 
219 
220  // values from http://mailman.isi.edu/pipermail/ns-developers/2009-July/006226.html
221  retval = retval && CheckTxDuration (14, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 304);
222 
223  NS_TEST_EXPECT_MSG_EQ (retval, true, "an 802.11b duration failed");
224 
225  // values from
226  // http://www.oreillynet.com/pub/a/wireless/2003/08/08/wireless_throughput.html
227  retval = retval
228  && CheckTxDuration (1536, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 1310)
229  && CheckTxDuration (76, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 248)
230  && CheckTxDuration (14, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 203)
231  && CheckTxDuration (1536, WifiPhy::GetOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 248)
232  && CheckTxDuration (76, WifiPhy::GetOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 32)
233  && CheckTxDuration (14, WifiPhy::GetOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 24);
234 
235  NS_TEST_EXPECT_MSG_EQ (retval, true, "an 802.11a duration failed");
236 
237  // 802.11g durations are same as 802.11a durations but with 6 us signal extension
238  retval = retval
239  && CheckTxDuration (1536, WifiPhy::GetErpOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 254)
240  && CheckTxDuration (76, WifiPhy::GetErpOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 38)
241  && CheckTxDuration (14, WifiPhy::GetErpOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 30);
242 
243  NS_TEST_EXPECT_MSG_EQ (retval, true, "an 802.11g duration failed");
244 
245  //802.11n durations
246  retval = retval
247  && CheckTxDuration (1536,WifiPhy::GetOfdmRate65MbpsBW20MHz (), WIFI_PREAMBLE_HT_MF,228)
248  && CheckTxDuration (76, WifiPhy::GetOfdmRate65MbpsBW20MHz (), WIFI_PREAMBLE_HT_MF,48)
249  && CheckTxDuration (14, WifiPhy::GetOfdmRate65MbpsBW20MHz (), WIFI_PREAMBLE_HT_MF,40)
250  && CheckTxDuration (1536,WifiPhy::GetOfdmRate65MbpsBW20MHz (), WIFI_PREAMBLE_HT_GF,220)
251  && CheckTxDuration (76, WifiPhy::GetOfdmRate65MbpsBW20MHz (), WIFI_PREAMBLE_HT_GF,40)
252  && CheckTxDuration (14, WifiPhy::GetOfdmRate65MbpsBW20MHz (), WIFI_PREAMBLE_HT_GF,32)
253  && CheckTxDuration (1536,WifiPhy::GetOfdmRate7_2MbpsBW20MHz (), WIFI_PREAMBLE_HT_MF,1746)
254  && CheckTxDuration (76, WifiPhy::GetOfdmRate7_2MbpsBW20MHz (), WIFI_PREAMBLE_HT_MF,126)
255  && CheckTxDuration (14, WifiPhy::GetOfdmRate7_2MbpsBW20MHz (), WIFI_PREAMBLE_HT_MF,57.6)
256  && CheckTxDuration (1536,WifiPhy::GetOfdmRate7_2MbpsBW20MHz (), WIFI_PREAMBLE_HT_GF,1738)
257  && CheckTxDuration (76, WifiPhy::GetOfdmRate7_2MbpsBW20MHz (), WIFI_PREAMBLE_HT_GF,118)
258  && CheckTxDuration (14, WifiPhy::GetOfdmRate7_2MbpsBW20MHz (), WIFI_PREAMBLE_HT_GF,49.6)
259  && CheckTxDuration (1536, WifiPhy::GetOfdmRate65MbpsBW20MHzShGi (), WIFI_PREAMBLE_HT_MF,226.8)
260  && CheckTxDuration (76, WifiPhy::GetOfdmRate65MbpsBW20MHzShGi (), WIFI_PREAMBLE_HT_MF,46.8)
261  && CheckTxDuration (14, WifiPhy::GetOfdmRate65MbpsBW20MHzShGi (), WIFI_PREAMBLE_HT_MF,39.6)
262  && CheckTxDuration (1536, WifiPhy::GetOfdmRate65MbpsBW20MHzShGi (), WIFI_PREAMBLE_HT_GF,218.8)
263  && CheckTxDuration (76, WifiPhy::GetOfdmRate65MbpsBW20MHzShGi (), WIFI_PREAMBLE_HT_GF,38.8)
264  && CheckTxDuration (14, WifiPhy::GetOfdmRate65MbpsBW20MHzShGi (), WIFI_PREAMBLE_HT_GF,31.6)
265  && CheckTxDuration (1536,WifiPhy::GetOfdmRate135MbpsBW40MHz (), WIFI_PREAMBLE_HT_MF,128)
266  && CheckTxDuration (76,WifiPhy::GetOfdmRate135MbpsBW40MHz (), WIFI_PREAMBLE_HT_MF,44)
267  && CheckTxDuration (14,WifiPhy::GetOfdmRate135MbpsBW40MHz (), WIFI_PREAMBLE_HT_MF,40)
268  && CheckTxDuration (1536,WifiPhy::GetOfdmRate135MbpsBW40MHz (), WIFI_PREAMBLE_HT_GF,120)
269  && CheckTxDuration (76,WifiPhy::GetOfdmRate135MbpsBW40MHz (), WIFI_PREAMBLE_HT_GF,36)
270  && CheckTxDuration (14,WifiPhy::GetOfdmRate135MbpsBW40MHz (), WIFI_PREAMBLE_HT_GF,32)
271  && CheckTxDuration (1536,WifiPhy::GetOfdmRate150MbpsBW40MHz (), WIFI_PREAMBLE_HT_MF,118.8)
272  && CheckTxDuration (76,WifiPhy::GetOfdmRate150MbpsBW40MHz (), WIFI_PREAMBLE_HT_MF,43.2)
273  && CheckTxDuration (14,WifiPhy::GetOfdmRate150MbpsBW40MHz (), WIFI_PREAMBLE_HT_MF,39.6)
274  && CheckTxDuration (1536,WifiPhy::GetOfdmRate150MbpsBW40MHz (), WIFI_PREAMBLE_HT_GF,110.8)
275  && CheckTxDuration (76,WifiPhy::GetOfdmRate150MbpsBW40MHz (), WIFI_PREAMBLE_HT_GF,35.2)
276  && CheckTxDuration (14,WifiPhy::GetOfdmRate150MbpsBW40MHz (), WIFI_PREAMBLE_HT_GF,31.6);
277 
278  NS_TEST_EXPECT_MSG_EQ (retval, true, "an 802.11n duration failed");
279 }
280 
282 {
283 public:
285 };
286 
288  : TestSuite ("devices-wifi-tx-duration", UNIT)
289 {
290  AddTestCase (new TxDurationTest, TestCase::QUICK);
291 }
292 
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
static TxDurationTestSuite g_txDurationTestSuite
A suite of tests to run.
Definition: test.h:1276
enum WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:115
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetStbc(bool stbc)
Sets if STBC is being used.
#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:273
encapsulates test code
Definition: test.h:1108
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:93
virtual void DoRun(void)
Implementation to actually run this TestCase.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:29
virtual ~TxDurationTest()
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:342
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:190
HT PHY (Clause 20)
Definition: wifi-mode.h:56
Time CalculateTxDuration(uint32_t size, WifiTxVector txvector, enum WifiPreamble preamble, double frequency, uint8_t packetType, uint8_t incFlag)
Definition: wifi-phy.cc:577
void SetNss(uint8_t nss)
Sets the number of Nss refer to IEEE 802.11n Table 20-28 for explanation and range.
static const double CHANNEL_1_MHZ
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool CheckPayloadDuration(uint32_t size, WifiMode payloadMode, WifiPreamble preamble, uint32_t knownDurationMicroSeconds)
Check if the payload tx duration returned by InterferenceHelper corresponds to a known value of the p...
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:346
OFDM PHY (Clause 17)
Definition: wifi-mode.h:54
static const double CHANNEL_36_MHZ
bool CheckTxDuration(uint32_t size, WifiMode payloadMode, WifiPreamble preamble, double knownDurationMicroSeconds)
Check if the overall tx duration returned by InterferenceHelper corresponds to a known value of the p...
void SetNess(uint8_t ness)
Sets the Ness number refer to IEEE 802.11n Table 20-6 for explanation.
Time GetPayloadDuration(uint32_t size, WifiTxVector txvector, WifiPreamble preamble, double frequency, uint8_t packetType, uint8_t incFlag)
Definition: wifi-phy.cc:383