A Discrete-Event Network Simulator
API
power-rate-adaptation-test.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014 Universidad de la República - Uruguay
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: Matías Richart <mrichart@fing.edu.uy>
19 */
20
21#include "ns3/node.h"
22#include "ns3/wifi-net-device.h"
23#include "ns3/yans-wifi-channel.h"
24#include "ns3/yans-wifi-phy.h"
25#include "ns3/adhoc-wifi-mac.h"
26#include "ns3/constant-position-mobility-model.h"
27#include "ns3/simulator.h"
28#include "ns3/test.h"
29#include "ns3/frame-exchange-manager.h"
30#include "ns3/interference-helper.h"
31#include "ns3/wifi-default-protection-manager.h"
32#include "ns3/wifi-default-ack-manager.h"
33
34using namespace ns3;
35
43{
44public:
46
47 void DoRun (void) override;
48private:
50 void TestParf ();
52 void TestAparf ();
54 void TestRrpaa ();
60
62};
63
65 : TestCase ("PowerRateAdaptation")
66{
67}
68
71{
72 /*
73 * Create channel model. Is is necessary to configure correctly the phy layer.
74 */
75 Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
76
77 /*
78 * Create mac layer. We use Adhoc because association is not needed to get supported rates.
79 */
80 Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
81 Ptr<AdhocWifiMac> mac = CreateObject<AdhocWifiMac> ();
82 mac->SetDevice (dev);
83 mac->ConfigureStandard (WIFI_STANDARD_80211a);
84 Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager ();
85
86 Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
87 protectionManager->SetWifiMac (mac);
88 fem->SetProtectionManager (protectionManager);
89
90 Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
91 ackManager->SetWifiMac (mac);
92 fem->SetAckManager (ackManager);
93
94 /*
95 * Create mobility model. Is needed by the phy layer for transmission.
96 */
97 Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
98
99 /*
100 * Create and configure phy layer.
101 */
102 Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
103 Ptr<InterferenceHelper> interferenceHelper = CreateObject<InterferenceHelper> ();
104 phy->SetInterferenceHelper (interferenceHelper);
105 phy->SetChannel (channel);
106 phy->SetDevice (dev);
107 phy->SetMobility (mobility);
108 phy->ConfigureStandard (WIFI_STANDARD_80211a);
109
110 /*
111 * Configure power control parameters.
112 */
113 phy->SetNTxPower (18);
114 phy->SetTxPowerStart (0);
115 phy->SetTxPowerEnd (17);
116
117 /*
118 * Create manager.
119 */
121
122 /*
123 * Create and configure node. Add mac and phy layer and the manager.
124 */
125 Ptr<Node> node = CreateObject<Node> ();
126 mac->SetAddress (Mac48Address::Allocate ());
127 dev->SetMac (mac);
128 dev->SetPhy (phy);
129 dev->SetRemoteStationManager (manager);
130 node->AddDevice (dev);
131
132 return node;
133}
134
135void
137{
138 m_manager.SetTypeId ("ns3::ParfWifiManager");
139 Ptr<Node> node = ConfigureNode ();
140 Ptr<WifiNetDevice> dev = DynamicCast<WifiNetDevice> (node->GetDevice (0));
142
143 /*
144 * Configure thresholds for rate and power control.
145 */
146 manager->SetAttribute ("AttemptThreshold",UintegerValue (15));
147 manager->SetAttribute ("SuccessThreshold",UintegerValue (10));
148
149 /*
150 * Create a dummy packet to simulate transmission.
151 */
152 Mac48Address remoteAddress = Mac48Address::Allocate ();
153 WifiMacHeader packetHeader;
154 packetHeader.SetAddr1 (remoteAddress);
155 packetHeader.SetType (WIFI_MAC_DATA);
156 packetHeader.SetQosTid (0);
157 Ptr<Packet> packet = Create<Packet> (10);
158 Ptr<WifiMacQueueItem> mpdu = Create<WifiMacQueueItem> (packet, packetHeader);
159 WifiMode ackMode;
160
161 /*
162 * To initialize the manager we need to generate a transmission.
163 */
164 Ptr<Packet> p = Create<Packet> ();
165 dev->Send (p, remoteAddress, 1);
166
167 //-----------------------------------------------------------------------------------------------------
168
169 /*
170 * Parf initiates with maximal rate and power.
171 */
172 WifiTxVector txVector = manager->GetDataTxVector (packetHeader);
173 WifiMode mode = txVector.GetMode ();
174 int power = (int) txVector.GetTxPowerLevel ();
175
176 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "PARF: Initial data rate wrong");
177 NS_TEST_ASSERT_MSG_EQ (power, 17, "PARF: Initial power level wrong");
178
179 //-----------------------------------------------------------------------------------------------------
180
181 /*
182 * After 10 consecutive successful transmissions parf increase rate or decrease power.
183 * As we are at maximal rate, the power should be decreased. recoveryPower=true.
184 */
185 for (int i = 0; i < 10; i++)
186 {
187 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
188 }
189
190 txVector = manager->GetDataTxVector (packetHeader);
191 mode = txVector.GetMode ();
192 power = (int) txVector.GetTxPowerLevel ();
193
194 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "PARF: Incorrect vale of data rate");
195 NS_TEST_ASSERT_MSG_EQ (power, 16, "PARF: Incorrect value of power level");
196
197 //-----------------------------------------------------------------------------------------------------
198
199 /*
200 * As we are using recovery power, one failure make power increase.
201 *
202 */
203 manager->ReportDataFailed (mpdu);
204
205 txVector = manager->GetDataTxVector (packetHeader);
206 mode = txVector.GetMode ();
207 power = (int) txVector.GetTxPowerLevel ();
208
209 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "PARF: Incorrect vale of data rate");
210 NS_TEST_ASSERT_MSG_EQ (power, 17, "PARF: Incorrect value of power level");
211
212 //-----------------------------------------------------------------------------------------------------
213
214 /*
215 * After 15 transmissions attempts parf increase rate or decrease power.
216 * As we are at maximal rate, the power should be decreased. recoveryPower=true.
217 */
218 for (int i = 0; i < 7; i++)
219 {
220 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
221 manager->ReportDataFailed (mpdu);
222 }
223 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
224
225 txVector = manager->GetDataTxVector (packetHeader);
226 mode = txVector.GetMode ();
227 power = (int) txVector.GetTxPowerLevel ();
228
229 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "PARF: Incorrect vale of data rate");
230 NS_TEST_ASSERT_MSG_EQ (power, 16, "PARF: Incorrect value of power level");
231
232 //-----------------------------------------------------------------------------------------------------
233
234 /*
235 * As we are using recovery power, one failure make power increase. recoveryPower=false.
236 */
237
238 manager->ReportDataFailed (mpdu);
239
240 txVector = manager->GetDataTxVector (packetHeader);
241 mode = txVector.GetMode ();
242 power = (int) txVector.GetTxPowerLevel ();
243
244 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "PARF: Incorrect vale of data rate");
245 NS_TEST_ASSERT_MSG_EQ (power, 17, "PARF: Incorrect value of power level");
246
247 //-----------------------------------------------------------------------------------------------------
248
249 /*
250 * After two consecutive fails the rate is decreased or the power increased.
251 * As we are at maximal power, the rate should be decreased.
252 */
253 manager->ReportDataFailed (mpdu);
254 manager->ReportDataFailed (mpdu);
255
256 txVector = manager->GetDataTxVector (packetHeader);
257 mode = txVector.GetMode ();
258 power = (int) txVector.GetTxPowerLevel ();
259
260 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 48000000, "PARF: Incorrect vale of data rate");
261 NS_TEST_ASSERT_MSG_EQ (power, 17, "PARF: Incorrect value of power level");
262
263 //-----------------------------------------------------------------------------------------------------
264
265 /*
266 * After 10 consecutive successful transmissions parf increase rate or decrease power.
267 * As we are not at maximal rate, the rate is increased again. recoveryRate=true.
268 */
269 for (int i = 0; i < 10; i++)
270 {
271 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
272 }
273
274 txVector = manager->GetDataTxVector (packetHeader);
275 mode = txVector.GetMode ();
276 power = (int) txVector.GetTxPowerLevel ();
277
278 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "PARF: Incorrect vale of data rate");
279 NS_TEST_ASSERT_MSG_EQ (power, 17, "PARF: Incorrect value of power level");
280
281 //-----------------------------------------------------------------------------------------------------
282
283 /*
284 * As we are using recovery rate, one failure make rate decrease. recoveryRate=false.
285 */
286
287 manager->ReportDataFailed (mpdu);
288
289 txVector = manager->GetDataTxVector (packetHeader);
290 mode = txVector.GetMode ();
291 power = (int) txVector.GetTxPowerLevel ();
292
293 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 48000000, "PARF: Incorrect vale of data rate");
294 NS_TEST_ASSERT_MSG_EQ (power, 17, "PARF: Incorrect value of power level");
295
296 //-----------------------------------------------------------------------------------------------------
297
298 /*
299 * After 10 consecutive successful transmissions parf increase rate or decrease power.
300 * As we are not at maximal rate, the rate is increased again. recoveryRate=true.
301 */
302 for (int i = 0; i < 10; i++)
303 {
304 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
305 }
306
307 txVector = manager->GetDataTxVector (packetHeader);
308 mode = txVector.GetMode ();
309 power = (int) txVector.GetTxPowerLevel ();
310
311 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "PARF: Incorrect vale of data rate");
312 NS_TEST_ASSERT_MSG_EQ (power, 17, "PARF: Incorrect value of power level");
313
314 //-----------------------------------------------------------------------------------------------------
315
316 /*
317 * After 10 consecutive successful transmissions parf increase rate or decrease power.
318 * As we are at maximal rate, the power is decreased. recoveryRate=false, recoveryPower=true.
319 */
320 for (int i = 0; i < 10; i++)
321 {
322 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
323 }
324
325 txVector = manager->GetDataTxVector (packetHeader);
326 mode = txVector.GetMode ();
327 power = (int) txVector.GetTxPowerLevel ();
328
329 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "PARF: Incorrect vale of data rate");
330 NS_TEST_ASSERT_MSG_EQ (power, 16, "PARF: Incorrect value of power level");
331
332 //-----------------------------------------------------------------------------------------------------
333
334 /*
335 * One successful transmissions after a power decrease make recoverPower=false.
336 * So we need two consecutive failures to increase power again.
337 */
338 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
339
340 for (int i = 0; i < 2; i++)
341 {
342 manager->ReportDataFailed (mpdu);
343 }
344
345 txVector = manager->GetDataTxVector (packetHeader);
346 mode = txVector.GetMode ();
347 power = (int) txVector.GetTxPowerLevel ();
348
349 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "PARF: Incorrect vale of data rate");
350 NS_TEST_ASSERT_MSG_EQ (power, 17, "PARF: Incorrect value of power level");
351
352 Simulator::Destroy ();
353}
354
355void
357{
358 m_manager.SetTypeId ("ns3::AparfWifiManager");
359 Ptr<Node> node = ConfigureNode ();
360 Ptr<WifiNetDevice> dev = DynamicCast<WifiNetDevice> (node->GetDevice (0));
362
363 /*
364 * Configure thresholds for rate and power control.
365 */
366 manager->SetAttribute ("SuccessThreshold1",UintegerValue (3));
367 manager->SetAttribute ("SuccessThreshold2",UintegerValue (10));
368 manager->SetAttribute ("FailThreshold",UintegerValue (1));
369 manager->SetAttribute ("PowerThreshold",UintegerValue (10));
370
371 /*
372 * Create a dummy packet to simulate transmission.
373 */
374 Mac48Address remoteAddress = Mac48Address::Allocate ();
375 WifiMacHeader packetHeader;
376 packetHeader.SetAddr1 (remoteAddress);
377 packetHeader.SetType (WIFI_MAC_DATA);
378 packetHeader.SetQosTid (0);
379 Ptr<Packet> packet = Create<Packet> (10);
380 Ptr<WifiMacQueueItem> mpdu = Create<WifiMacQueueItem> (packet, packetHeader);
381 WifiMode ackMode;
382
383 /*
384 * To initialize the manager we need to generate a transmission.
385 */
386 Ptr<Packet> p = Create<Packet> ();
387 dev->Send (p, remoteAddress, 1);
388
389 //-----------------------------------------------------------------------------------------------------
390
391 /*
392 * Aparf initiates with maximal rate and power.
393 */
394 WifiTxVector txVector = manager->GetDataTxVector (packetHeader);
395 WifiMode mode = txVector.GetMode ();
396 int power = (int) txVector.GetTxPowerLevel ();
397
398 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "APARF: Initial data rate wrong");
399 NS_TEST_ASSERT_MSG_EQ (power, 17, "APARF: Initial power level wrong");
400
401 //-----------------------------------------------------------------------------------------------------
402
403 /*
404 * As Aparf starts in state High, after 3 consecutive successful transmissions aparf increase rate or decrease power.
405 * As we are at maximal rate, the power should be decreased.
406 * Change to state Spread.
407 */
408 for (int i = 0; i < 3; i++)
409 {
410 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
411 }
412
413 txVector = manager->GetDataTxVector (packetHeader);
414 mode = txVector.GetMode ();
415 power = (int) txVector.GetTxPowerLevel ();
416
417 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "APARF: Incorrect vale of data rate");
418 NS_TEST_ASSERT_MSG_EQ (power, 16, "APARF: Incorrect value of power level");
419
420 //-----------------------------------------------------------------------------------------------------
421
422 /*
423 * One failure make the power to be increased again.
424 * Change to state Low.
425 */
426 manager->ReportDataFailed (mpdu);
427
428 txVector = manager->GetDataTxVector (packetHeader);
429 mode = txVector.GetMode ();
430 power = (int) txVector.GetTxPowerLevel ();
431
432 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "APARF: Incorrect vale of data rate");
433 NS_TEST_ASSERT_MSG_EQ (power, 17, "APARF: Incorrect value of power level");
434
435 //-----------------------------------------------------------------------------------------------------
436
437 /*
438 * As we are in state Low we need 10 successful transmissions to increase rate or decrease power.
439 * As we are at maximal rate, the power should be decreased.
440 * Change to state Spread.
441 */
442 for (int i = 0; i < 10; i++)
443 {
444 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
445 }
446
447 txVector = manager->GetDataTxVector (packetHeader);
448 mode = txVector.GetMode ();
449 power = (int) txVector.GetTxPowerLevel ();
450
451 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "APARF: Incorrect vale of data rate");
452 NS_TEST_ASSERT_MSG_EQ (power, 16, "APARF: Incorrect value of power level");
453
454 //-----------------------------------------------------------------------------------------------------
455
456 /*
457 * One more successful transmission make to change to state High.
458 * Two more successful transmissions make power decrease.
459 */
460
461 for (int i = 0; i < 3; i++)
462 {
463 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
464 }
465
466 txVector = manager->GetDataTxVector (packetHeader);
467 mode = txVector.GetMode ();
468 power = (int) txVector.GetTxPowerLevel ();
469
470 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "APARF: Incorrect vale of data rate");
471 NS_TEST_ASSERT_MSG_EQ (power, 15, "APARF: Incorrect value of power level");
472
473 //-----------------------------------------------------------------------------------------------------
474
475 /*
476 * As we are in state High we need 3 successful transmissions to increase rate or decrease power.
477 * After 16*3 successful transmissions power is decreased to zero.
478 */
479 for (int i = 0; i < 16 * 3; i++)
480 {
481 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
482 }
483
484 txVector = manager->GetDataTxVector (packetHeader);
485 mode = txVector.GetMode ();
486 power = (int) txVector.GetTxPowerLevel ();
487
488 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "APARF: Incorrect vale of data rate");
489 NS_TEST_ASSERT_MSG_EQ (power, 0, "APARF: Incorrect value of power level");
490
491 //-----------------------------------------------------------------------------------------------------
492
493 /*
494 * After one fail the rate is decreased or the power increased.
495 * As we are at minimal power, the power should be increased.
496 */
497 manager->ReportDataFailed (mpdu);
498
499 txVector = manager->GetDataTxVector (packetHeader);
500 mode = txVector.GetMode ();
501 power = (int) txVector.GetTxPowerLevel ();
502
503 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "Incorrect vale of data rate");
504 NS_TEST_ASSERT_MSG_EQ (power, 1, "Incorrect value of power level");
505
506 //-----------------------------------------------------------------------------------------------------
507
508 /*
509 * After one fail the rate is decreased or the power increased.
510 * After 16 failed transmissions power is increase to 17.
511 */
512 for (int i = 0; i < 16; i++)
513 {
514 manager->ReportDataFailed (mpdu);
515 }
516
517 txVector = manager->GetDataTxVector (packetHeader);
518 mode = txVector.GetMode ();
519 power = (int) txVector.GetTxPowerLevel ();
520
521 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "APARF: Incorrect vale of data rate");
522 NS_TEST_ASSERT_MSG_EQ (power, 17, "APARF: Incorrect value of power level");
523
524 //-----------------------------------------------------------------------------------------------------
525
526 /*
527 * After one fail the rate is decreased or the power increased.
528 * As we are at maximal power, the rate should be decreased.
529 * Set critical rate to 54 Mbps.
530 */
531 manager->ReportDataFailed (mpdu);
532
533 txVector = manager->GetDataTxVector (packetHeader);
534 mode = txVector.GetMode ();
535 power = (int) txVector.GetTxPowerLevel ();
536
537 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 48000000, "Incorrect vale of data rate");
538 NS_TEST_ASSERT_MSG_EQ (power, 17, "Incorrect value of power level");
539
540 //-----------------------------------------------------------------------------------------------------
541
542 /*
543 * As we are in state High we need 3 successful transmissions to increase rate or decrease power.
544 * As rate critical is set, after 3 successful transmissions power is decreased.
545 */
546 for (int i = 0; i < 3; i++)
547 {
548 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
549 }
550
551 txVector = manager->GetDataTxVector (packetHeader);
552 mode = txVector.GetMode ();
553 power = (int) txVector.GetTxPowerLevel ();
554
555 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 48000000, "APARF: Incorrect vale of data rate");
556 NS_TEST_ASSERT_MSG_EQ (power, 16, "APARF: Incorrect value of power level");
557
558 //-----------------------------------------------------------------------------------------------------
559
560 /*
561 * As we are in state High we need 3 successful transmissions to increase rate or decrease power.
562 * After 10 power changes critical rate is reset.
563 * So after 10*3 successful transmissions critical rate is set to 0.
564 * And 3 successful transmissions more will make power increase to maximum and rate increase to the critical rate.
565 */
566 for (int i = 0; i < 9 * 3; i++)
567 {
568 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
569 }
570
571 txVector = manager->GetDataTxVector (packetHeader);
572 mode = txVector.GetMode ();
573 power = (int) txVector.GetTxPowerLevel ();
574
575 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 48000000, "APARF: Incorrect vale of data rate");
576 NS_TEST_ASSERT_MSG_EQ (power, 7, "APARF: Incorrect value of power level");
577
578 for (int i = 0; i < 3; i++)
579 {
580 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
581 }
582
583 txVector = manager->GetDataTxVector (packetHeader);
584 mode = txVector.GetMode ();
585 power = (int) txVector.GetTxPowerLevel ();
586
587 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth ()), 54000000, "APARF: Incorrect vale of data rate");
588 NS_TEST_ASSERT_MSG_EQ (power, 17, "APARF: Incorrect value of power level");
589
590 Simulator::Destroy ();
591}
592
593void
595{
596 m_manager.SetTypeId ("ns3::RrpaaWifiManager");
597 Ptr<Node> node = ConfigureNode ();
598 Ptr<WifiNetDevice> dev = DynamicCast<WifiNetDevice> (node->GetDevice (0));
600
601 /*
602 * Configure constants for rate and power control.
603 */
604 manager->SetAttribute ("Basic", BooleanValue (true));
605 manager->SetAttribute ("Alpha", DoubleValue (1.25));
606 manager->SetAttribute ("Beta", DoubleValue (2));
607 manager->SetAttribute ("Tau", DoubleValue (0.015));
608 /*
609 * Constants for the Probabilistic Decision Table.
610 * We set both to 1 to avoid random behaviour in tests.
611 */
612 manager->SetAttribute ("Gamma", DoubleValue (1));
613 manager->SetAttribute ("Delta", DoubleValue (1));
614
615 /*
616 * Create a dummy packet to simulate transmission.
617 */
618 Mac48Address remoteAddress = Mac48Address::Allocate ();
619 WifiMacHeader packetHeader;
620 packetHeader.SetAddr1 (remoteAddress);
621 packetHeader.SetType (WIFI_MAC_DATA);
622 packetHeader.SetQosTid (0);
623 Ptr<Packet> packet = Create<Packet> (10);
624 Ptr<WifiMacQueueItem> mpdu = Create<WifiMacQueueItem> (packet, packetHeader);
625 WifiMode ackMode;
626
627 /*
628 * To initialize the manager we need to generate a transmission.
629 */
630 Ptr<Packet> p = Create<Packet> ();
631 dev->Send (p, remoteAddress, 1);
632
659 //-----------------------------------------------------------------------------------------------------
660
661 /*
662 * RRPAA initiates with minimal rate and maximal power.
663 */
664 WifiTxVector txVector = manager->GetDataTxVector (packetHeader);
665 WifiMode mode = txVector.GetMode ();
666 int power = (int) txVector.GetTxPowerLevel ();
667
668 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 6000000, "RRPAA: Initial data rate wrong"); //802.11a minimal rate is 6Mbps
669 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Initial power level wrong");
670
671 //-----------------------------------------------------------------------------------------------------
672
673 /*
674 * As RRPAA starts with the 6Mbps rate, 7 successful transmissions are needed for RRPAA to increase rate.
675 * 1/8 = 0.125
676 */
677
681 for (int i = 0; i < 6; i++)
682 {
683 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
684 }
685
686 txVector = manager->GetDataTxVector (packetHeader);
687 mode = txVector.GetMode ();
688 power = (int) txVector.GetTxPowerLevel ();
689
690 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 6000000, "RRPAA: Incorrect vale of data rate");
691 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
692
696 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
697
698 txVector = manager->GetDataTxVector (packetHeader);
699 mode = txVector.GetMode ();
700 power = (int) txVector.GetTxPowerLevel ();
701
702 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 9000000, "RRPAA: Incorrect vale of data rate");
703 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
704
705 //-----------------------------------------------------------------------------------------------------
706
707 /*
708 * 5 failures are needed to make the rate decrease again.
709 * 5/11 = 0.45
710 */
711 for (int i = 0; i < 4; i++)
712 {
713 manager->ReportDataFailed (mpdu);
714 }
715
716 txVector = manager->GetDataTxVector (packetHeader);
717 mode = txVector.GetMode ();
718 power = (int) txVector.GetTxPowerLevel ();
719
720 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 9000000, "RRPAA: Incorrect vale of data rate");
721 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
722
723 manager->ReportDataFailed (mpdu);
724
725 txVector = manager->GetDataTxVector (packetHeader);
726 mode = txVector.GetMode ();
727 power = (int) txVector.GetTxPowerLevel ();
728
729 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 6000000, "RRPAA: Incorrect vale of data rate");
730 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
731
732 //-----------------------------------------------------------------------------------------------------
733
738 for (int i = 0; i < 7; i++)
739 {
740 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
741 }
742
743 txVector = manager->GetDataTxVector (packetHeader);
744 mode = txVector.GetMode ();
745 power = (int) txVector.GetTxPowerLevel ();
746
747 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 9000000, "RRPAA: Incorrect vale of data rate");
748 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
749
750 for (int i = 0; i < 10; i++)
751 {
752 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
753 }
754
755 txVector = manager->GetDataTxVector (packetHeader);
756 mode = txVector.GetMode ();
757 power = (int) txVector.GetTxPowerLevel ();
758
759 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 12000000, "RRPAA: Incorrect vale of data rate");
760 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
761
762 for (int i = 0; i < 13; i++)
763 {
764 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
765 }
766
767 txVector = manager->GetDataTxVector (packetHeader);
768 mode = txVector.GetMode ();
769 power = (int) txVector.GetTxPowerLevel ();
770
771 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 18000000, "RRPAA: Incorrect vale of data rate");
772 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
773
774 for (int i = 0; i < 19; i++)
775 {
776 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
777 }
778
779 txVector = manager->GetDataTxVector (packetHeader);
780 mode = txVector.GetMode ();
781 power = (int) txVector.GetTxPowerLevel ();
782
783 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 24000000, "RRPAA: Incorrect vale of data rate");
784 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
785
786 for (int i = 0; i < 23; i++)
787 {
788 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
789 }
790
791 txVector = manager->GetDataTxVector (packetHeader);
792 mode = txVector.GetMode ();
793 power = (int) txVector.GetTxPowerLevel ();
794
795 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 36000000, "RRPAA: Incorrect vale of data rate");
796 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
797
798 for (int i = 0; i < 33; i++)
799 {
800 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
801 }
802
803 txVector = manager->GetDataTxVector (packetHeader);
804 mode = txVector.GetMode ();
805 power = (int) txVector.GetTxPowerLevel ();
806
807 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 48000000, "RRPAA: Incorrect vale of data rate");
808 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
809
810 for (int i = 0; i < 43; i++)
811 {
812 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
813 }
814
815 txVector = manager->GetDataTxVector (packetHeader);
816 mode = txVector.GetMode ();
817 power = (int) txVector.GetTxPowerLevel ();
818
819 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 54000000, "RRPAA: Incorrect vale of data rate");
820 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
821
822 //-----------------------------------------------------------------------------------------------------
823
830 for (int i = 0; i < 49; i++)
831 {
832 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
833 }
834
835 txVector = manager->GetDataTxVector (packetHeader);
836 mode = txVector.GetMode ();
837 power = (int) txVector.GetTxPowerLevel ();
838
839 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 54000000, "RRPAA: Incorrect vale of data rate");
840 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
841
842 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
843
844 txVector = manager->GetDataTxVector (packetHeader);
845 mode = txVector.GetMode ();
846 power = (int) txVector.GetTxPowerLevel ();
847
848 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 54000000, "RRPAA: Incorrect vale of data rate");
849 NS_TEST_ASSERT_MSG_EQ (power, 16, "RRPAA: Incorrect value of power level");
850
851 //-----------------------------------------------------------------------------------------------------
852
858 for (int i = 0; i < 16 * 50; i++)
859 {
860 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
861 }
862
863 txVector = manager->GetDataTxVector (packetHeader);
864 mode = txVector.GetMode ();
865 power = (int) txVector.GetTxPowerLevel ();
866
867 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 54000000, "RRPAA: Incorrect vale of data rate");
868 NS_TEST_ASSERT_MSG_EQ (power, 0, "RRPAA: Incorrect value of power level");
869
870 //-----------------------------------------------------------------------------------------------------
871
876 for (int i = 0; i < 6; i++)
877 {
878 manager->ReportDataFailed (mpdu);
879 }
880
881 txVector = manager->GetDataTxVector (packetHeader);
882 mode = txVector.GetMode ();
883 power = (int) txVector.GetTxPowerLevel ();
884
885 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 54000000, "RRPAA: Incorrect vale of data rate");
886 NS_TEST_ASSERT_MSG_EQ (power, 1, "RRPAA: Incorrect value of power level");
887
888 //-----------------------------------------------------------------------------------------------------
889
890 /*
891 * After 16*6 failed transmissions power is increase to 17.
892 */
893
894 for (int i = 0; i < 16 * 6; i++)
895 {
896 manager->ReportDataFailed (mpdu);
897 }
898
899 txVector = manager->GetDataTxVector (packetHeader);
900 mode = txVector.GetMode ();
901 power = (int) txVector.GetTxPowerLevel ();
902
903 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 54000000, "RRPAA: Incorrect vale of data rate");
904 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
905
906 //-----------------------------------------------------------------------------------------------------
907
908 /*
909 * After 6 more failures the rate should be decreased.
910 */
911
912 for (int i = 0; i < 6; i++)
913 {
914 manager->ReportDataFailed (mpdu);
915 }
916
917 txVector = manager->GetDataTxVector (packetHeader);
918 mode = txVector.GetMode ();
919 power = (int) txVector.GetTxPowerLevel ();
920
921 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 48000000, "RRPAA: Incorrect vale of data rate");
922 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
923
924 /*
925 * Now 11 failures are needed to decrease rate again.
926 */
927
928 for (int i = 0; i < 11; i++)
929 {
930 manager->ReportDataFailed (mpdu);
931 }
932
933 txVector = manager->GetDataTxVector (packetHeader);
934 mode = txVector.GetMode ();
935 power = (int) txVector.GetTxPowerLevel ();
936
937 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 36000000, "RRPAA: Incorrect vale of data rate");
938 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
939
940 //-----------------------------------------------------------------------------------------------------
941
942 /*
943 * Test power decrement when loss probability is between MTL and ORI.
944 * As we are at rate 36 Mbps we need at least 25 successful transmissions
945 * and 5 failures.
946 */
947
948 for (int i = 0; i < 25; i++)
949 {
950 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
951 }
952
953 txVector = manager->GetDataTxVector (packetHeader);
954 mode = txVector.GetMode ();
955 power = (int) txVector.GetTxPowerLevel ();
956
957 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 36000000, "RRPAA: Incorrect vale of data rate");
958 NS_TEST_ASSERT_MSG_EQ (power, 17, "RRPAA: Incorrect value of power level");
959
960 for (int i = 0; i < 5; i++)
961 {
962 manager->ReportDataFailed (mpdu);
963 }
964
965 txVector = manager->GetDataTxVector (packetHeader);
966 mode = txVector.GetMode ();
967 power = (int) txVector.GetTxPowerLevel ();
968
969 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 36000000, "RRPAA: Incorrect vale of data rate");
970 NS_TEST_ASSERT_MSG_EQ (power, 16, "RRPAA: Incorrect value of power level");
971
972 for (int i = 0; i < 5; i++)
973 {
974 manager->ReportDataFailed (mpdu);
975 }
976
977 txVector = manager->GetDataTxVector (packetHeader);
978 mode = txVector.GetMode ();
979 power = (int) txVector.GetTxPowerLevel ();
980
981 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 36000000, "RRPAA: Incorrect vale of data rate");
982 NS_TEST_ASSERT_MSG_EQ (power, 16, "RRPAA: Incorrect value of power level");
983
984 for (int i = 0; i < 25; i++)
985 {
986 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
987 }
988
989 txVector = manager->GetDataTxVector (packetHeader);
990 mode = txVector.GetMode ();
991 power = (int) txVector.GetTxPowerLevel ();
992
993 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 36000000, "RRPAA: Incorrect vale of data rate");
994 NS_TEST_ASSERT_MSG_EQ (power, 15, "RRPAA: Incorrect value of power level");
995
996 //-----------------------------------------------------------------------------------------------------
997
998 /*
999 * Repeat the previous test until power 0 is reached.
1000 */
1001
1002 for (int i = 0; i < 16; i++)
1003 {
1004 for (int j = 0; j < 25; j++)
1005 {
1006 manager->ReportDataOk (mpdu, 0, ackMode, 0, txVector);
1007 }
1008
1009 for (int j = 0; j < 5; j++)
1010 {
1011 manager->ReportDataFailed (mpdu);
1012 }
1013 }
1014
1015 txVector = manager->GetDataTxVector (packetHeader);
1016 mode = txVector.GetMode ();
1017 power = (int) txVector.GetTxPowerLevel ();
1018
1019 NS_TEST_ASSERT_MSG_EQ (mode.GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1), 36000000, "RRPAA: Incorrect vale of data rate");
1020 NS_TEST_ASSERT_MSG_EQ (power, 0, "RRPAA: Incorrect value of power level");
1021
1022 Simulator::Stop (Seconds (10.0));
1023
1024 Simulator::Run ();
1025 Simulator::Destroy ();
1026
1027}
1028
1029void
1031{
1032
1033 TestParf ();
1034 TestAparf ();
1035 TestRrpaa ();
1036}
1037
1045{
1046public:
1048};
1049
1051 : TestSuite ("wifi-power-rate-adaptation", UNIT)
1052{
1053 AddTestCase (new PowerRateAdaptationTest, TestCase::QUICK);
1054}
1055
Power Rate Adaptation Test.
void TestParf()
Test parf function.
void TestAparf()
Test aparf function.
Ptr< Node > ConfigureNode()
Configure nde function.
void DoRun(void) override
Implementation to actually run this TestCase.
void TestRrpaa()
Test rrpaa function.
Power Rate Adaptation Test Suite.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
an EUI-48 address
Definition: mac48-address.h:44
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
Instantiate subclasses of ns3::Object.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Hold an unsigned integer type.
Definition: uinteger.h:44
Implements the IEEE 802.11 MAC header.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
represent a single transmission mode
Definition: wifi-mode.h:48
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:114
void SetMac(const Ptr< WifiMac > mac)
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
void SetRemoteStationManager(const Ptr< WifiRemoteStationManager > manager)
Ptr< WifiRemoteStationManager > GetRemoteStationManager(void) const
void SetPhy(const Ptr< WifiPhy > phy)
hold a list of per-remote-station state.
void ReportDataFailed(Ptr< const WifiMacQueueItem > mpdu)
Should be invoked whenever the AckTimeout associated to a transmission attempt expires.
WifiTxVector GetDataTxVector(const WifiMacHeader &header)
void ReportDataOk(Ptr< const WifiMacQueueItem > mpdu, double ackSnr, WifiMode ackMode, double dataSnr, WifiTxVector dataTxVector)
Should be invoked whenever we receive the ACK associated to a data packet we just sent.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
uint8_t GetTxPowerLevel(void) const
uint16_t GetChannelWidth(void) const
uint16_t GetGuardInterval(void) const
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:141
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
@ WIFI_STANDARD_80211a
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ WIFI_MAC_DATA
channel
Definition: third.py:92
mac
Definition: third.py:96
mobility
Definition: third.py:107
phy
Definition: third.py:93
static PowerRateAdaptationTestSuite g_powerRateAdaptationTestSuite
the test suite