A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/wifi-phy.h"
27 
28 NS_LOG_COMPONENT_DEFINE ("InterferenceHelperTxDurationTest");
29 
30 namespace ns3 {
31 
32 class TxDurationTest : public TestCase
33 {
34 public:
35  TxDurationTest ();
36  virtual ~TxDurationTest ();
37  virtual void DoRun (void);
38 
39 private:
50  bool CheckPayloadDuration (uint32_t size, WifiMode payloadMode, uint32_t knownDurationMicroSeconds);
51 
63  bool CheckTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble, double knownDurationMicroSeconds);
64 
65 };
66 
67 
69  : TestCase ("Wifi TX Duration")
70 {
71 }
72 
73 
75 {
76 }
77 
78 bool
79 TxDurationTest::CheckPayloadDuration (uint32_t size, WifiMode payloadMode, uint32_t knownDurationMicroSeconds)
80 {
81  WifiTxVector txVector;
82  txVector.SetMode (payloadMode);
83  uint32_t calculatedDurationMicroSeconds = WifiPhy::GetPayloadDurationMicroSeconds (size, txVector);
84  if (calculatedDurationMicroSeconds != knownDurationMicroSeconds)
85  {
86  std::cerr << " size=" << size
87  << " mode=" << payloadMode
88  << " known=" << knownDurationMicroSeconds
89  << " calculated=" << calculatedDurationMicroSeconds
90  << std::endl;
91  return false;
92  }
93  return true;
94 }
95 
96 bool
97 TxDurationTest::CheckTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble, double knownDurationMicroSeconds)
98 {
99  WifiTxVector txVector;
100  txVector.SetMode (payloadMode);
101  txVector.SetNss(1);
102  txVector.SetStbc(0);
103  txVector.SetNess(0);
104  double calculatedDurationMicroSeconds = WifiPhy::CalculateTxDuration (size, txVector, preamble).GetMicroSeconds ();
105  if (calculatedDurationMicroSeconds != knownDurationMicroSeconds)
106  {
107  std::cerr << " size=" << size
108  << " mode=" << payloadMode
109  << " preamble=" << preamble
110  << " known=" << knownDurationMicroSeconds
111  << " calculated=" << calculatedDurationMicroSeconds
112  << std::endl;
113  return false;
114  }
115  return true;
116 }
117 
118 void
120 {
121  bool retval = true;
122 
123 
124  // IEEE Std 802.11-2007 Table 18-2 "Example of LENGTH calculations for CCK"
125  retval = retval
130 
131 
132  // Similar, but we add PLCP preamble and header durations
133  // and we test different rates.
134  // The payload durations for modes other than 11mbb have been
135  // calculated by hand according to IEEE Std 802.11-2007 18.2.3.5
136  retval = retval
169 
170  // values from http://mailman.isi.edu/pipermail/ns-developers/2009-July/006226.html
171  retval = retval && CheckTxDuration (14, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 304);
172 
173  // values from
174  // http://www.oreillynet.com/pub/a/wireless/2003/08/08/wireless_throughput.html
175  retval = retval
182 
183  // 802.11g durations are same as 802.11a durations but with 6 us signal extension
184  retval = retval
188 
189  //802.11n durations
190  retval = retval
194  //should be 218.8, 38,8 and 31.6 but microseconds are only represented as integers will have to change Time to change that
198 }
199 
201 {
202 public:
204 };
205 
207  : TestSuite ("devices-wifi-tx-duration", UNIT)
208 {
210 }
211 
213 } // namespace ns3
214 
static WifiMode GetDsssRate11Mbps()
Return a WifiMode for DSSS at 11Mbps.
Definition: wifi-phy.cc:547
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
static WifiMode GetDsssRate1Mbps()
Return a WifiMode for DSSS at 1Mbps.
Definition: wifi-phy.cc:505
A suite of tests to run.
Definition: test.h:1025
void SetStbc(bool stbc)
Sets if STBC is being used.
static WifiMode GetOfdmRate54Mbps()
Return a WifiMode for ODFM at 54Mbps.
Definition: wifi-phy.cc:761
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...
encapsulates test code
Definition: test.h:849
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:91
static WifiMode GetErpOfdmRate54Mbps()
Return a WifiMode for ERP-ODFM at 54Mbps.
Definition: wifi-phy.cc:654
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:29
static double GetPayloadDurationMicroSeconds(uint32_t size, WifiTxVector txvector)
Definition: wifi-phy.cc:333
int64_t GetMicroSeconds(void) const
Definition: nstime.h:291
static WifiMode GetOfdmRate65MbpsBW20MHzShGi()
Return a WifiMode for ODFM at 65Mbps with 20MHz channel spacing.
Definition: wifi-phy.cc:1157
void SetNss(uint8_t nss)
Sets the number of Nss refer to IEEE802.11n Table 20-28 for explanation and range.
NS_LOG_COMPONENT_DEFINE("InterferenceHelperTxDurationTest")
static WifiMode GetOfdmRate65MbpsBW20MHz()
Return a WifiMode for ODFM at 65Mbps with 20MHz channel spacing.
Definition: wifi-phy.cc:1170
static WifiMode GetDsssRate5_5Mbps()
Return a WifiMode for DSSS at 5.5Mbps.
Definition: wifi-phy.cc:534
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Fast test.
Definition: test.h:857
static TxDurationTestSuite g_txDurationTestSuite
bool CheckPayloadDuration(uint32_t size, WifiMode payloadMode, uint32_t knownDurationMicroSeconds)
Check if the payload tx duration returned by InterferenceHelper corresponds to a known value of the p...
virtual void DoRun(void)
Implementation to actually run this TestCase.
static Time CalculateTxDuration(uint32_t size, WifiTxVector txvector, enum WifiPreamble preamble)
Definition: wifi-phy.cc:440
void SetNess(uint8_t ness)
Sets the Ness number refer to IEEE802.11n Table 20-6 for explanation.
static WifiMode GetDsssRate2Mbps()
Return a WifiMode for DSSS at 2Mbps.
Definition: wifi-phy.cc:518