91 |
91 |
92 WifiPhy::~WifiPhy () |
92 WifiPhy::~WifiPhy () |
93 { |
93 { |
94 NS_LOG_FUNCTION (this); |
94 NS_LOG_FUNCTION (this); |
95 } |
95 } |
|
96 |
|
97 |
|
98 WifiMode |
|
99 WifiPhy::GetPlcpHeaderMode (WifiMode payloadMode, WifiPreamble preamble) |
|
100 { |
|
101 switch (payloadMode.GetModulationClass ()) |
|
102 { |
|
103 case WIFI_MOD_CLASS_OFDM: |
|
104 { |
|
105 switch (payloadMode.GetBandwidth ()) |
|
106 { |
|
107 case 5000000: |
|
108 return WifiPhy::GetOfdmRate1_5MbpsBW5MHz (); |
|
109 case 10000000: |
|
110 return WifiPhy::GetOfdmRate3MbpsBW10MHz (); |
|
111 default: |
|
112 // IEEE Std 802.11-2007, 17.3.2 |
|
113 // actually this is only the first part of the PlcpHeader, |
|
114 // because the last 16 bits of the PlcpHeader are using the |
|
115 // same mode of the payload |
|
116 return WifiPhy::GetOfdmRate6Mbps (); |
|
117 } |
|
118 } |
|
119 |
|
120 case WIFI_MOD_CLASS_ERP_OFDM: |
|
121 return WifiPhy::GetErpOfdmRate6Mbps (); |
|
122 |
|
123 case WIFI_MOD_CLASS_DSSS: |
|
124 if (preamble == WIFI_PREAMBLE_LONG) |
|
125 { |
|
126 // IEEE Std 802.11-2007, sections 15.2.3 and 18.2.2.1 |
|
127 return WifiPhy::GetDsssRate1Mbps (); |
|
128 } |
|
129 else // WIFI_PREAMBLE_SHORT |
|
130 { |
|
131 // IEEE Std 802.11-2007, section 18.2.2.2 |
|
132 return WifiPhy::GetDsssRate2Mbps (); |
|
133 } |
|
134 |
|
135 default: |
|
136 NS_FATAL_ERROR ("unsupported modulation class"); |
|
137 return WifiMode (); |
|
138 } |
|
139 } |
|
140 |
|
141 uint32_t |
|
142 WifiPhy::GetPlcpHeaderDurationMicroSeconds (WifiMode payloadMode, WifiPreamble preamble) |
|
143 { |
|
144 switch (payloadMode.GetModulationClass ()) |
|
145 { |
|
146 case WIFI_MOD_CLASS_OFDM: |
|
147 { |
|
148 switch (payloadMode.GetBandwidth ()) |
|
149 { |
|
150 case 20000000: |
|
151 default: |
|
152 // IEEE Std 802.11-2007, section 17.3.3 and figure 17-4 |
|
153 // also section 17.3.2.3, table 17-4 |
|
154 // We return the duration of the SIGNAL field only, since the |
|
155 // SERVICE field (which strictly speaking belongs to the PLCP |
|
156 // header, see section 17.3.2 and figure 17-1) is sent using the |
|
157 // payload mode. |
|
158 return 4; |
|
159 case 10000000: |
|
160 // IEEE Std 802.11-2007, section 17.3.2.3, table 17-4 |
|
161 return 8; |
|
162 case 5000000: |
|
163 // IEEE Std 802.11-2007, section 17.3.2.3, table 17-4 |
|
164 return 16; |
|
165 } |
|
166 } |
|
167 |
|
168 case WIFI_MOD_CLASS_ERP_OFDM: |
|
169 return 16; |
|
170 |
|
171 case WIFI_MOD_CLASS_DSSS: |
|
172 if (preamble == WIFI_PREAMBLE_SHORT) |
|
173 { |
|
174 // IEEE Std 802.11-2007, section 18.2.2.2 and figure 18-2 |
|
175 return 24; |
|
176 } |
|
177 else // WIFI_PREAMBLE_LONG |
|
178 { |
|
179 // IEEE Std 802.11-2007, sections 18.2.2.1 and figure 18-1 |
|
180 return 48; |
|
181 } |
|
182 |
|
183 default: |
|
184 NS_FATAL_ERROR ("unsupported modulation class"); |
|
185 return 0; |
|
186 } |
|
187 } |
|
188 |
|
189 uint32_t |
|
190 WifiPhy::GetPlcpPreambleDurationMicroSeconds (WifiMode payloadMode, WifiPreamble preamble) |
|
191 { |
|
192 switch (payloadMode.GetModulationClass ()) |
|
193 { |
|
194 case WIFI_MOD_CLASS_OFDM: |
|
195 { |
|
196 switch (payloadMode.GetBandwidth ()) |
|
197 { |
|
198 case 20000000: |
|
199 default: |
|
200 // IEEE Std 802.11-2007, section 17.3.3, figure 17-4 |
|
201 // also section 17.3.2.3, table 17-4 |
|
202 return 16; |
|
203 case 10000000: |
|
204 // IEEE Std 802.11-2007, section 17.3.3, table 17-4 |
|
205 // also section 17.3.2.3, table 17-4 |
|
206 return 32; |
|
207 case 5000000: |
|
208 // IEEE Std 802.11-2007, section 17.3.3 |
|
209 // also section 17.3.2.3, table 17-4 |
|
210 return 64; |
|
211 } |
|
212 } |
|
213 |
|
214 case WIFI_MOD_CLASS_ERP_OFDM: |
|
215 return 4; |
|
216 |
|
217 case WIFI_MOD_CLASS_DSSS: |
|
218 if (preamble == WIFI_PREAMBLE_SHORT) |
|
219 { |
|
220 // IEEE Std 802.11-2007, section 18.2.2.2 and figure 18-2 |
|
221 return 72; |
|
222 } |
|
223 else // WIFI_PREAMBLE_LONG |
|
224 { |
|
225 // IEEE Std 802.11-2007, sections 18.2.2.1 and figure 18-1 |
|
226 return 144; |
|
227 } |
|
228 |
|
229 default: |
|
230 NS_FATAL_ERROR ("unsupported modulation class"); |
|
231 return 0; |
|
232 } |
|
233 } |
|
234 |
|
235 uint32_t |
|
236 WifiPhy::GetPayloadDurationMicroSeconds (uint32_t size, WifiMode payloadMode) |
|
237 { |
|
238 NS_LOG_FUNCTION (size << payloadMode); |
|
239 |
|
240 switch (payloadMode.GetModulationClass ()) |
|
241 { |
|
242 case WIFI_MOD_CLASS_OFDM: |
|
243 case WIFI_MOD_CLASS_ERP_OFDM: |
|
244 { |
|
245 // IEEE Std 802.11-2007, section 17.3.2.3, table 17-4 |
|
246 // corresponds to T_{SYM} in the table |
|
247 uint32_t symbolDurationUs; |
|
248 |
|
249 switch (payloadMode.GetBandwidth ()) |
|
250 { |
|
251 case 20000000: |
|
252 default: |
|
253 symbolDurationUs = 4; |
|
254 break; |
|
255 case 10000000: |
|
256 symbolDurationUs = 8; |
|
257 break; |
|
258 case 5000000: |
|
259 symbolDurationUs = 16; |
|
260 break; |
|
261 } |
|
262 |
|
263 // IEEE Std 802.11-2007, section 17.3.2.2, table 17-3 |
|
264 // corresponds to N_{DBPS} in the table |
|
265 double numDataBitsPerSymbol = payloadMode.GetDataRate () * symbolDurationUs / 1e6; |
|
266 |
|
267 // IEEE Std 802.11-2007, section 17.3.5.3, equation (17-11) |
|
268 uint32_t numSymbols = lrint (ceil ((16 + size * 8.0 + 6.0) / numDataBitsPerSymbol)); |
|
269 |
|
270 // Add signal extension for ERP PHY |
|
271 if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_ERP_OFDM) |
|
272 { |
|
273 return numSymbols * symbolDurationUs + 6; |
|
274 } |
|
275 else |
|
276 { |
|
277 return numSymbols * symbolDurationUs; |
|
278 } |
|
279 } |
|
280 |
|
281 case WIFI_MOD_CLASS_DSSS: |
|
282 // IEEE Std 802.11-2007, section 18.2.3.5 |
|
283 NS_LOG_LOGIC (" size=" << size |
|
284 << " mode=" << payloadMode |
|
285 << " rate=" << payloadMode.GetDataRate () ); |
|
286 return lrint (ceil ((size * 8.0) / (payloadMode.GetDataRate () / 1.0e6))); |
|
287 |
|
288 default: |
|
289 NS_FATAL_ERROR ("unsupported modulation class"); |
|
290 return 0; |
|
291 } |
|
292 } |
|
293 |
|
294 Time |
|
295 WifiPhy::CalculateTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble) |
|
296 { |
|
297 uint32_t duration = GetPlcpPreambleDurationMicroSeconds (payloadMode, preamble) |
|
298 + GetPlcpHeaderDurationMicroSeconds (payloadMode, preamble) |
|
299 + GetPayloadDurationMicroSeconds (size, payloadMode); |
|
300 return MicroSeconds (duration); |
|
301 } |
|
302 |
96 |
303 |
97 void |
304 void |
98 WifiPhy::NotifyTxBegin (Ptr<const Packet> packet) |
305 WifiPhy::NotifyTxBegin (Ptr<const Packet> packet) |
99 { |
306 { |
100 m_phyTxBeginTrace (packet); |
307 m_phyTxBeginTrace (packet); |