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 InterferenceHelperTxDurationTest : public TestCase |
|
33 { |
|
34 public: |
|
35 InterferenceHelperTxDurationTest (); |
|
36 virtual ~InterferenceHelperTxDurationTest (); |
|
37 virtual void DoRun (void); |
|
38 |
|
39 private: |
|
40 /** |
|
41 * Check if the payload tx duration returned by InterferenceHelper |
|
42 * corresponds to a known value of the pay |
|
43 * |
|
44 * @param size size of payload in octets (includes everything after the PLCP header) |
|
45 * @param payloadMode the WifiMode used |
|
46 * @param knownPlcpLengthFieldValue the known value of the Length field in the PLCP header |
|
47 * |
|
48 * @return true if values correspond, false otherwise |
|
49 */ |
|
50 bool CheckPayloadDuration (uint32_t size, WifiMode payloadMode, uint32_t knownDurationMicroSeconds); |
|
51 |
|
52 /** |
|
53 * Check if the overall tx duration returned by InterferenceHelper |
|
54 * corresponds to a known value of the pay |
|
55 * |
|
56 * @param size size of payload in octets (includes everything after the PLCP header) |
|
57 * @param payloadMode the WifiMode used |
|
58 * @param preamble the WifiPreamble used |
|
59 * @param knownPlcpLengthFieldValue the known value of the Length field in the PLCP header |
|
60 * |
|
61 * @return true if values correspond, false otherwise |
|
62 */ |
|
63 bool CheckTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble, uint32_t knownDurationMicroSeconds); |
|
64 |
|
65 }; |
|
66 |
|
67 |
|
68 InterferenceHelperTxDurationTest::InterferenceHelperTxDurationTest () |
|
69 : TestCase ("InterferenceHelper TX Duration") |
|
70 { |
|
71 } |
|
72 |
|
73 |
|
74 InterferenceHelperTxDurationTest::~InterferenceHelperTxDurationTest () |
|
75 { |
|
76 } |
|
77 |
|
78 bool |
|
79 InterferenceHelperTxDurationTest::CheckPayloadDuration (uint32_t size, WifiMode payloadMode, uint32_t knownDurationMicroSeconds) |
|
80 { |
|
81 uint32_t calculatedDurationMicroSeconds = InterferenceHelper::GetPayloadDurationMicroSeconds (size, payloadMode); |
|
82 if (calculatedDurationMicroSeconds != knownDurationMicroSeconds) |
|
83 { |
|
84 std::cerr << " size=" << size |
|
85 << " mode=" << payloadMode |
|
86 << " known=" << knownDurationMicroSeconds |
|
87 << " calculated=" << calculatedDurationMicroSeconds |
|
88 << std::endl; |
|
89 return false; |
|
90 } |
|
91 return true; |
|
92 } |
|
93 |
|
94 bool |
|
95 InterferenceHelperTxDurationTest::CheckTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble, uint32_t knownDurationMicroSeconds) |
|
96 { |
|
97 uint32_t calculatedDurationMicroSeconds = InterferenceHelper::CalculateTxDuration (size, payloadMode, preamble).GetMicroSeconds (); |
|
98 if (calculatedDurationMicroSeconds != knownDurationMicroSeconds) |
|
99 { |
|
100 std::cerr << " size=" << size |
|
101 << " mode=" << payloadMode |
|
102 << " preamble=" << preamble |
|
103 << " known=" << knownDurationMicroSeconds |
|
104 << " calculated=" << calculatedDurationMicroSeconds |
|
105 << std::endl; |
|
106 return false; |
|
107 } |
|
108 return true; |
|
109 } |
|
110 |
|
111 void |
|
112 InterferenceHelperTxDurationTest::DoRun (void) |
|
113 { |
|
114 bool retval = true; |
|
115 |
|
116 // IEEE Std 802.11-2007 Table 18-2 "Example of LENGTH calculations for CCK" |
|
117 retval = retval |
|
118 && CheckPayloadDuration (1023, WifiPhy::GetDsssRate11Mbps (), 744) |
|
119 && CheckPayloadDuration (1024, WifiPhy::GetDsssRate11Mbps (), 745) |
|
120 && CheckPayloadDuration (1025, WifiPhy::GetDsssRate11Mbps (), 746) |
|
121 && CheckPayloadDuration (1026, WifiPhy::GetDsssRate11Mbps (), 747); |
|
122 |
|
123 |
|
124 // Similar, but we add PLCP preamble and header durations |
|
125 // and we test different rates. |
|
126 // The payload durations for modes other than 11mbb have been |
|
127 // calculated by hand according to IEEE Std 802.11-2007 18.2.3.5 |
|
128 retval = retval |
|
129 && CheckTxDuration (1023, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_SHORT, 744 + 96) |
|
130 && CheckTxDuration (1024, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_SHORT, 745 + 96) |
|
131 && CheckTxDuration (1025, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_SHORT, 746 + 96) |
|
132 && CheckTxDuration (1026, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_SHORT, 747 + 96) |
|
133 && CheckTxDuration (1023, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 744 + 192) |
|
134 && CheckTxDuration (1024, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 745 + 192) |
|
135 && CheckTxDuration (1025, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 746 + 192) |
|
136 && CheckTxDuration (1026, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 747 + 192) |
|
137 && CheckTxDuration (1023, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_SHORT, 1488 + 96) |
|
138 && CheckTxDuration (1024, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_SHORT, 1490 + 96) |
|
139 && CheckTxDuration (1025, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_SHORT, 1491 + 96) |
|
140 && CheckTxDuration (1026, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_SHORT, 1493 + 96) |
|
141 && CheckTxDuration (1023, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_LONG, 1488 + 192) |
|
142 && CheckTxDuration (1024, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_LONG, 1490 + 192) |
|
143 && CheckTxDuration (1025, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_LONG, 1491 + 192) |
|
144 && CheckTxDuration (1026, WifiPhy::GetDsssRate5_5Mbps (), WIFI_PREAMBLE_LONG, 1493 + 192) |
|
145 && CheckTxDuration (1023, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_SHORT, 4092 + 96) |
|
146 && CheckTxDuration (1024, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_SHORT, 4096 + 96) |
|
147 && CheckTxDuration (1025, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_SHORT, 4100 + 96) |
|
148 && CheckTxDuration (1026, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_SHORT, 4104 + 96) |
|
149 && CheckTxDuration (1023, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_LONG, 4092 + 192) |
|
150 && CheckTxDuration (1024, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_LONG, 4096 + 192) |
|
151 && CheckTxDuration (1025, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_LONG, 4100 + 192) |
|
152 && CheckTxDuration (1026, WifiPhy::GetDsssRate2Mbps (), WIFI_PREAMBLE_LONG, 4104 + 192) |
|
153 && CheckTxDuration (1023, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_SHORT, 8184 + 96) |
|
154 && CheckTxDuration (1024, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_SHORT, 8192 + 96) |
|
155 && CheckTxDuration (1025, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_SHORT, 8200 + 96) |
|
156 && CheckTxDuration (1026, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_SHORT, 8208 + 96) |
|
157 && CheckTxDuration (1023, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 8184 + 192) |
|
158 && CheckTxDuration (1024, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 8192 + 192) |
|
159 && CheckTxDuration (1025, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 8200 + 192) |
|
160 && CheckTxDuration (1026, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 8208 + 192); |
|
161 |
|
162 // values from http://mailman.isi.edu/pipermail/ns-developers/2009-July/006226.html |
|
163 retval = retval && CheckTxDuration (14, WifiPhy::GetDsssRate1Mbps (), WIFI_PREAMBLE_LONG, 304); |
|
164 |
|
165 // values from |
|
166 // http://www.oreillynet.com/pub/a/wireless/2003/08/08/wireless_throughput.html |
|
167 retval = retval |
|
168 && CheckTxDuration (1536, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 1310) |
|
169 && CheckTxDuration (76, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 248) |
|
170 && CheckTxDuration (14, WifiPhy::GetDsssRate11Mbps (), WIFI_PREAMBLE_LONG, 203) |
|
171 && CheckTxDuration (1536, WifiPhy::GetOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 248) |
|
172 && CheckTxDuration (76, WifiPhy::GetOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 32) |
|
173 && CheckTxDuration (14, WifiPhy::GetOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 24); |
|
174 |
|
175 // 802.11g durations are same as 802.11a durations but with 6 us signal extension |
|
176 retval = retval |
|
177 && CheckTxDuration (1536, WifiPhy::GetErpOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 254) |
|
178 && CheckTxDuration (76, WifiPhy::GetErpOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 38) |
|
179 && CheckTxDuration (14, WifiPhy::GetErpOfdmRate54Mbps (), WIFI_PREAMBLE_LONG, 30); |
|
180 } |
|
181 |
|
182 class TxDurationTestSuite : public TestSuite |
|
183 { |
|
184 public: |
|
185 TxDurationTestSuite (); |
|
186 }; |
|
187 |
|
188 TxDurationTestSuite::TxDurationTestSuite () |
|
189 : TestSuite ("devices-wifi-tx-duration", UNIT) |
|
190 { |
|
191 AddTestCase (new InterferenceHelperTxDurationTest); |
|
192 } |
|
193 |
|
194 static TxDurationTestSuite g_txDurationTestSuite; |
|
195 } //namespace ns3 |
|
196 |
|