A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
power-rate-adaptation-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Universidad de la República - Uruguay
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Matías Richart <mrichart@fing.edu.uy>
18 */
19
20#include "ns3/adhoc-wifi-mac.h"
21#include "ns3/constant-position-mobility-model.h"
22#include "ns3/fcfs-wifi-queue-scheduler.h"
23#include "ns3/frame-exchange-manager.h"
24#include "ns3/interference-helper.h"
25#include "ns3/node.h"
26#include "ns3/simulator.h"
27#include "ns3/test.h"
28#include "ns3/wifi-default-ack-manager.h"
29#include "ns3/wifi-default-protection-manager.h"
30#include "ns3/wifi-net-device.h"
31#include "ns3/yans-wifi-channel.h"
32#include "ns3/yans-wifi-phy.h"
33
34using namespace ns3;
35
36/**
37 * \ingroup wifi-test
38 * \ingroup tests
39 *
40 * \brief Power Rate Adaptation Test
41 */
43{
44 public:
46
47 void DoRun() override;
48
49 private:
50 /// Test parf function
51 void TestParf();
52 /// Test aparf function
53 void TestAparf();
54 /// Test rrpaa function
55 void TestRrpaa();
56 /**
57 * Configure nde function
58 * \returns the node
59 */
61
63};
64
66 : TestCase("PowerRateAdaptation")
67{
68}
69
72{
73 /*
74 * Create and configure node.
75 */
76 Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice>();
77 Ptr<Node> node = CreateObject<Node>();
78 node->AddDevice(dev);
79
80 /*
81 * Create channel model. Is is necessary to configure correctly the phy layer.
82 */
83 Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel>();
84
85 /*
86 * Create mobility model. Is needed by the phy layer for transmission.
87 */
88 Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel>();
89
90 /*
91 * Create and configure phy layer.
92 */
93 Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy>();
94 Ptr<InterferenceHelper> interferenceHelper = CreateObject<InterferenceHelper>();
95 phy->SetInterferenceHelper(interferenceHelper);
96 dev->SetPhy(phy);
97 phy->SetChannel(channel);
98 phy->SetDevice(dev);
99 phy->SetMobility(mobility);
100 phy->ConfigureStandard(WIFI_STANDARD_80211a);
101
102 /*
103 * Configure power control parameters.
104 */
105 phy->SetNTxPower(18);
106 phy->SetTxPowerStart(0);
107 phy->SetTxPowerEnd(17);
108
109 /*
110 * Create manager.
111 */
113 dev->SetRemoteStationManager(manager);
114
115 /*
116 * Create mac layer. We use Adhoc because association is not needed to get supported rates.
117 */
118 Ptr<AdhocWifiMac> mac = CreateObject<AdhocWifiMac>();
119 mac->SetDevice(dev);
120 mac->SetAddress(Mac48Address::Allocate());
121 dev->SetMac(mac);
122 mac->ConfigureStandard(WIFI_STANDARD_80211a);
123 mac->SetMacQueueScheduler(CreateObject<FcfsWifiQueueScheduler>());
124 Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager();
125
126 Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager>();
127 protectionManager->SetWifiMac(mac);
128 fem->SetProtectionManager(protectionManager);
129
130 Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager>();
131 ackManager->SetWifiMac(mac);
132 fem->SetAckManager(ackManager);
133
134 return node;
135}
136
137void
139{
140 m_manager.SetTypeId("ns3::ParfWifiManager");
141 Ptr<Node> node = ConfigureNode();
142 Ptr<WifiNetDevice> dev = DynamicCast<WifiNetDevice>(node->GetDevice(0));
143 Ptr<WifiRemoteStationManager> manager = dev->GetRemoteStationManager();
144
145 /*
146 * Configure thresholds for rate and power control.
147 */
148 manager->SetAttribute("AttemptThreshold", UintegerValue(15));
149 manager->SetAttribute("SuccessThreshold", UintegerValue(10));
150
151 /*
152 * Create a dummy packet to simulate transmission.
153 */
154 Mac48Address remoteAddress = Mac48Address::Allocate();
155 WifiMacHeader packetHeader;
156 packetHeader.SetAddr1(remoteAddress);
157 packetHeader.SetType(WIFI_MAC_DATA);
158 packetHeader.SetQosTid(0);
159 Ptr<Packet> packet = Create<Packet>(10);
160 Ptr<WifiMpdu> mpdu = Create<WifiMpdu>(packet, packetHeader);
161 WifiMode ackMode;
162
163 /*
164 * To initialize the manager we need to generate a transmission.
165 */
166 Ptr<Packet> p = Create<Packet>();
167 dev->Send(p, remoteAddress, 1);
168
169 //-----------------------------------------------------------------------------------------------------
170
171 /*
172 * Parf initiates with maximal rate and power.
173 */
174 WifiTxVector txVector =
175 manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
176 WifiMode mode = txVector.GetMode();
177 int power = (int)txVector.GetTxPowerLevel();
178
180 54000000,
181 "PARF: Initial data rate wrong");
182 NS_TEST_ASSERT_MSG_EQ(power, 17, "PARF: Initial power level wrong");
183
184 //-----------------------------------------------------------------------------------------------------
185
186 /*
187 * After 10 consecutive successful transmissions parf increase rate or decrease power.
188 * As we are at maximal rate, the power should be decreased. recoveryPower=true.
189 */
190 for (int i = 0; i < 10; i++)
191 {
192 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
193 }
194
195 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
196 mode = txVector.GetMode();
197 power = (int)txVector.GetTxPowerLevel();
198
200 54000000,
201 "PARF: Incorrect vale of data rate");
202 NS_TEST_ASSERT_MSG_EQ(power, 16, "PARF: Incorrect value of power level");
203
204 //-----------------------------------------------------------------------------------------------------
205
206 /*
207 * As we are using recovery power, one failure make power increase.
208 *
209 */
210 manager->ReportDataFailed(mpdu);
211
212 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
213 mode = txVector.GetMode();
214 power = (int)txVector.GetTxPowerLevel();
215
217 54000000,
218 "PARF: Incorrect vale of data rate");
219 NS_TEST_ASSERT_MSG_EQ(power, 17, "PARF: Incorrect value of power level");
220
221 //-----------------------------------------------------------------------------------------------------
222
223 /*
224 * After 15 transmissions attempts parf increase rate or decrease power.
225 * As we are at maximal rate, the power should be decreased. recoveryPower=true.
226 */
227 for (int i = 0; i < 7; i++)
228 {
229 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
230 manager->ReportDataFailed(mpdu);
231 }
232 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
233
234 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
235 mode = txVector.GetMode();
236 power = (int)txVector.GetTxPowerLevel();
237
239 54000000,
240 "PARF: Incorrect vale of data rate");
241 NS_TEST_ASSERT_MSG_EQ(power, 16, "PARF: Incorrect value of power level");
242
243 //-----------------------------------------------------------------------------------------------------
244
245 /*
246 * As we are using recovery power, one failure make power increase. recoveryPower=false.
247 */
248
249 manager->ReportDataFailed(mpdu);
250
251 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
252 mode = txVector.GetMode();
253 power = (int)txVector.GetTxPowerLevel();
254
256 54000000,
257 "PARF: Incorrect vale of data rate");
258 NS_TEST_ASSERT_MSG_EQ(power, 17, "PARF: Incorrect value of power level");
259
260 //-----------------------------------------------------------------------------------------------------
261
262 /*
263 * After two consecutive fails the rate is decreased or the power increased.
264 * As we are at maximal power, the rate should be decreased.
265 */
266 manager->ReportDataFailed(mpdu);
267 manager->ReportDataFailed(mpdu);
268
269 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
270 mode = txVector.GetMode();
271 power = (int)txVector.GetTxPowerLevel();
272
274 48000000,
275 "PARF: Incorrect vale of data rate");
276 NS_TEST_ASSERT_MSG_EQ(power, 17, "PARF: Incorrect value of power level");
277
278 //-----------------------------------------------------------------------------------------------------
279
280 /*
281 * After 10 consecutive successful transmissions parf increase rate or decrease power.
282 * As we are not at maximal rate, the rate is increased again. recoveryRate=true.
283 */
284 for (int i = 0; i < 10; i++)
285 {
286 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
287 }
288
289 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
290 mode = txVector.GetMode();
291 power = (int)txVector.GetTxPowerLevel();
292
294 54000000,
295 "PARF: Incorrect vale of data rate");
296 NS_TEST_ASSERT_MSG_EQ(power, 17, "PARF: Incorrect value of power level");
297
298 //-----------------------------------------------------------------------------------------------------
299
300 /*
301 * As we are using recovery rate, one failure make rate decrease. recoveryRate=false.
302 */
303
304 manager->ReportDataFailed(mpdu);
305
306 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
307 mode = txVector.GetMode();
308 power = (int)txVector.GetTxPowerLevel();
309
311 48000000,
312 "PARF: Incorrect vale of data rate");
313 NS_TEST_ASSERT_MSG_EQ(power, 17, "PARF: Incorrect value of power level");
314
315 //-----------------------------------------------------------------------------------------------------
316
317 /*
318 * After 10 consecutive successful transmissions parf increase rate or decrease power.
319 * As we are not at maximal rate, the rate is increased again. recoveryRate=true.
320 */
321 for (int i = 0; i < 10; i++)
322 {
323 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
324 }
325
326 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
327 mode = txVector.GetMode();
328 power = (int)txVector.GetTxPowerLevel();
329
331 54000000,
332 "PARF: Incorrect vale of data rate");
333 NS_TEST_ASSERT_MSG_EQ(power, 17, "PARF: Incorrect value of power level");
334
335 //-----------------------------------------------------------------------------------------------------
336
337 /*
338 * After 10 consecutive successful transmissions parf increase rate or decrease power.
339 * As we are at maximal rate, the power is decreased. recoveryRate=false, recoveryPower=true.
340 */
341 for (int i = 0; i < 10; i++)
342 {
343 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
344 }
345
346 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
347 mode = txVector.GetMode();
348 power = (int)txVector.GetTxPowerLevel();
349
351 54000000,
352 "PARF: Incorrect vale of data rate");
353 NS_TEST_ASSERT_MSG_EQ(power, 16, "PARF: Incorrect value of power level");
354
355 //-----------------------------------------------------------------------------------------------------
356
357 /*
358 * One successful transmissions after a power decrease make recoverPower=false.
359 * So we need two consecutive failures to increase power again.
360 */
361 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
362
363 for (int i = 0; i < 2; i++)
364 {
365 manager->ReportDataFailed(mpdu);
366 }
367
368 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
369 mode = txVector.GetMode();
370 power = (int)txVector.GetTxPowerLevel();
371
373 54000000,
374 "PARF: Incorrect vale of data rate");
375 NS_TEST_ASSERT_MSG_EQ(power, 17, "PARF: Incorrect value of power level");
376
378}
379
380void
382{
383 m_manager.SetTypeId("ns3::AparfWifiManager");
384 Ptr<Node> node = ConfigureNode();
385 Ptr<WifiNetDevice> dev = DynamicCast<WifiNetDevice>(node->GetDevice(0));
386 Ptr<WifiRemoteStationManager> manager = dev->GetRemoteStationManager();
387
388 /*
389 * Configure thresholds for rate and power control.
390 */
391 manager->SetAttribute("SuccessThreshold1", UintegerValue(3));
392 manager->SetAttribute("SuccessThreshold2", UintegerValue(10));
393 manager->SetAttribute("FailThreshold", UintegerValue(1));
394 manager->SetAttribute("PowerThreshold", UintegerValue(10));
395
396 /*
397 * Create a dummy packet to simulate transmission.
398 */
399 Mac48Address remoteAddress = Mac48Address::Allocate();
400 WifiMacHeader packetHeader;
401 packetHeader.SetAddr1(remoteAddress);
402 packetHeader.SetType(WIFI_MAC_DATA);
403 packetHeader.SetQosTid(0);
404 Ptr<Packet> packet = Create<Packet>(10);
405 Ptr<WifiMpdu> mpdu = Create<WifiMpdu>(packet, packetHeader);
406 WifiMode ackMode;
407
408 /*
409 * To initialize the manager we need to generate a transmission.
410 */
411 Ptr<Packet> p = Create<Packet>();
412 dev->Send(p, remoteAddress, 1);
413
414 //-----------------------------------------------------------------------------------------------------
415
416 /*
417 * Aparf initiates with maximal rate and power.
418 */
419 WifiTxVector txVector =
420 manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
421 WifiMode mode = txVector.GetMode();
422 int power = (int)txVector.GetTxPowerLevel();
423
425 54000000,
426 "APARF: Initial data rate wrong");
427 NS_TEST_ASSERT_MSG_EQ(power, 17, "APARF: Initial power level wrong");
428
429 //-----------------------------------------------------------------------------------------------------
430
431 /*
432 * As Aparf starts in state High, after 3 consecutive successful transmissions aparf increase
433 * rate or decrease power. As we are at maximal rate, the power should be decreased. Change to
434 * state Spread.
435 */
436 for (int i = 0; i < 3; i++)
437 {
438 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
439 }
440
441 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
442 mode = txVector.GetMode();
443 power = (int)txVector.GetTxPowerLevel();
444
446 54000000,
447 "APARF: Incorrect vale of data rate");
448 NS_TEST_ASSERT_MSG_EQ(power, 16, "APARF: Incorrect value of power level");
449
450 //-----------------------------------------------------------------------------------------------------
451
452 /*
453 * One failure make the power to be increased again.
454 * Change to state Low.
455 */
456 manager->ReportDataFailed(mpdu);
457
458 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
459 mode = txVector.GetMode();
460 power = (int)txVector.GetTxPowerLevel();
461
463 54000000,
464 "APARF: Incorrect vale of data rate");
465 NS_TEST_ASSERT_MSG_EQ(power, 17, "APARF: Incorrect value of power level");
466
467 //-----------------------------------------------------------------------------------------------------
468
469 /*
470 * As we are in state Low we need 10 successful transmissions to increase rate or decrease
471 * power. As we are at maximal rate, the power should be decreased. Change to state Spread.
472 */
473 for (int i = 0; i < 10; i++)
474 {
475 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
476 }
477
478 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
479 mode = txVector.GetMode();
480 power = (int)txVector.GetTxPowerLevel();
481
483 54000000,
484 "APARF: Incorrect vale of data rate");
485 NS_TEST_ASSERT_MSG_EQ(power, 16, "APARF: Incorrect value of power level");
486
487 //-----------------------------------------------------------------------------------------------------
488
489 /*
490 * One more successful transmission make to change to state High.
491 * Two more successful transmissions make power decrease.
492 */
493
494 for (int i = 0; i < 3; i++)
495 {
496 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
497 }
498
499 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
500 mode = txVector.GetMode();
501 power = (int)txVector.GetTxPowerLevel();
502
504 54000000,
505 "APARF: Incorrect vale of data rate");
506 NS_TEST_ASSERT_MSG_EQ(power, 15, "APARF: Incorrect value of power level");
507
508 //-----------------------------------------------------------------------------------------------------
509
510 /*
511 * As we are in state High we need 3 successful transmissions to increase rate or decrease
512 * power. After 16*3 successful transmissions power is decreased to zero.
513 */
514 for (int i = 0; i < 16 * 3; i++)
515 {
516 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
517 }
518
519 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
520 mode = txVector.GetMode();
521 power = (int)txVector.GetTxPowerLevel();
522
524 54000000,
525 "APARF: Incorrect vale of data rate");
526 NS_TEST_ASSERT_MSG_EQ(power, 0, "APARF: Incorrect value of power level");
527
528 //-----------------------------------------------------------------------------------------------------
529
530 /*
531 * After one fail the rate is decreased or the power increased.
532 * As we are at minimal power, the power should be increased.
533 */
534 manager->ReportDataFailed(mpdu);
535
536 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
537 mode = txVector.GetMode();
538 power = (int)txVector.GetTxPowerLevel();
539
541 54000000,
542 "Incorrect vale of data rate");
543 NS_TEST_ASSERT_MSG_EQ(power, 1, "Incorrect value of power level");
544
545 //-----------------------------------------------------------------------------------------------------
546
547 /*
548 * After one fail the rate is decreased or the power increased.
549 * After 16 failed transmissions power is increase to 17.
550 */
551 for (int i = 0; i < 16; i++)
552 {
553 manager->ReportDataFailed(mpdu);
554 }
555
556 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
557 mode = txVector.GetMode();
558 power = (int)txVector.GetTxPowerLevel();
559
561 54000000,
562 "APARF: Incorrect vale of data rate");
563 NS_TEST_ASSERT_MSG_EQ(power, 17, "APARF: Incorrect value of power level");
564
565 //-----------------------------------------------------------------------------------------------------
566
567 /*
568 * After one fail the rate is decreased or the power increased.
569 * As we are at maximal power, the rate should be decreased.
570 * Set critical rate to 54 Mbps.
571 */
572 manager->ReportDataFailed(mpdu);
573
574 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
575 mode = txVector.GetMode();
576 power = (int)txVector.GetTxPowerLevel();
577
579 48000000,
580 "Incorrect vale of data rate");
581 NS_TEST_ASSERT_MSG_EQ(power, 17, "Incorrect value of power level");
582
583 //-----------------------------------------------------------------------------------------------------
584
585 /*
586 * As we are in state High we need 3 successful transmissions to increase rate or decrease
587 * power. As rate critical is set, after 3 successful transmissions power is decreased.
588 */
589 for (int i = 0; i < 3; i++)
590 {
591 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
592 }
593
594 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
595 mode = txVector.GetMode();
596 power = (int)txVector.GetTxPowerLevel();
597
599 48000000,
600 "APARF: Incorrect vale of data rate");
601 NS_TEST_ASSERT_MSG_EQ(power, 16, "APARF: Incorrect value of power level");
602
603 //-----------------------------------------------------------------------------------------------------
604
605 /*
606 * As we are in state High we need 3 successful transmissions to increase rate or decrease
607 * power. After 10 power changes critical rate is reset. So after 10*3 successful transmissions
608 * critical rate is set to 0. And 3 successful transmissions more will make power increase to
609 * maximum and rate increase to the critical rate.
610 */
611 for (int i = 0; i < 9 * 3; i++)
612 {
613 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
614 }
615
616 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
617 mode = txVector.GetMode();
618 power = (int)txVector.GetTxPowerLevel();
619
621 48000000,
622 "APARF: Incorrect vale of data rate");
623 NS_TEST_ASSERT_MSG_EQ(power, 7, "APARF: Incorrect value of power level");
624
625 for (int i = 0; i < 3; i++)
626 {
627 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
628 }
629
630 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
631 mode = txVector.GetMode();
632 power = (int)txVector.GetTxPowerLevel();
633
635 54000000,
636 "APARF: Incorrect vale of data rate");
637 NS_TEST_ASSERT_MSG_EQ(power, 17, "APARF: Incorrect value of power level");
638
640}
641
642void
644{
645 m_manager.SetTypeId("ns3::RrpaaWifiManager");
646 Ptr<Node> node = ConfigureNode();
647 Ptr<WifiNetDevice> dev = DynamicCast<WifiNetDevice>(node->GetDevice(0));
648 Ptr<WifiRemoteStationManager> manager = dev->GetRemoteStationManager();
649
650 /*
651 * Configure constants for rate and power control.
652 */
653 manager->SetAttribute("Basic", BooleanValue(true));
654 manager->SetAttribute("Alpha", DoubleValue(1.25));
655 manager->SetAttribute("Beta", DoubleValue(2));
656 manager->SetAttribute("Tau", DoubleValue(0.015));
657 /*
658 * Constants for the Probabilistic Decision Table.
659 * We set both to 1 to avoid random behaviour in tests.
660 */
661 manager->SetAttribute("Gamma", DoubleValue(1));
662 manager->SetAttribute("Delta", DoubleValue(1));
663
664 /*
665 * Create a dummy packet to simulate transmission.
666 */
667 Mac48Address remoteAddress = Mac48Address::Allocate();
668 WifiMacHeader packetHeader;
669 packetHeader.SetAddr1(remoteAddress);
670 packetHeader.SetType(WIFI_MAC_DATA);
671 packetHeader.SetQosTid(0);
672 Ptr<Packet> packet = Create<Packet>(10);
673 Ptr<WifiMpdu> mpdu = Create<WifiMpdu>(packet, packetHeader);
674 WifiMode ackMode;
675
676 /*
677 * To initialize the manager we need to generate a transmission.
678 */
679 Ptr<Packet> p = Create<Packet>();
680 dev->Send(p, remoteAddress, 1);
681
682 /**
683 * This will be the thresholds table.
684 * The parameters of the table are:
685 * - Estimation Window Size (EWND)
686 * - Maximum Tolerable Loss Probability Threshold (MTL)
687 * - Opportunistic Rate Increase (and Power Decrease) Probability Threshold (ORI)
688 *
689 * We also calculate the needed success and failures to generate
690 * a rate or power change:
691 * Rate Increase or Power Decrease limits (RI-PD)
692 * Rate Decrease or Power Increase limits (RD-PI)
693 * Power Decrease limits (PD)
694 *
695 * Mode EWND MTL ORI RI-PD RD-PI PD
696 * succ fails succ fails
697 * OfdmRate6Mbps 8 1 0.19861 7 8 2
698 * OfdmRate9Mbps 11 0.397219 0.14556 10 5 7 2
699 * OfdmRate12Mbps 15 0.291121 0.189753 13 5 11 3
700 * OfdmRate18Mbps 21 0.379507 0.13624 19 8 14 3
701 * OfdmRate24Mbps 27 0.27248 0.174216 23 8 20 5
702 * OfdmRate36Mbps 37 0.348432 0.120773 33 13 25 5
703 * OfdmRate48Mbps 45 0.241546 0.0523952 43 11 35 3
704 * OfdmRate54Mbps 50 0.10479 0 50 6 45 5
705 *
706 */
707
708 //-----------------------------------------------------------------------------------------------------
709
710 /*
711 * RRPAA initiates with minimal rate and maximal power.
712 */
713 WifiTxVector txVector =
714 manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
715 WifiMode mode = txVector.GetMode();
716 int power = (int)txVector.GetTxPowerLevel();
717
719 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
720 6000000,
721 "RRPAA: Initial data rate wrong"); // 802.11a minimal rate is 6Mbps
722 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Initial power level wrong");
723
724 //-----------------------------------------------------------------------------------------------------
725
726 /*
727 * As RRPAA starts with the 6Mbps rate, 7 successful transmissions are needed for RRPAA to
728 * increase rate. 1/8 = 0.125
729 */
730
731 /**
732 * Test that 6 is not enough.
733 */
734 for (int i = 0; i < 6; i++)
735 {
736 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
737 }
738
739 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
740 mode = txVector.GetMode();
741 power = (int)txVector.GetTxPowerLevel();
742
744 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
745 6000000,
746 "RRPAA: Incorrect vale of data rate");
747 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
748
749 /**
750 * Test that 7 is enough.
751 */
752 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
753
754 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
755 mode = txVector.GetMode();
756 power = (int)txVector.GetTxPowerLevel();
757
759 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
760 9000000,
761 "RRPAA: Incorrect vale of data rate");
762 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
763
764 //-----------------------------------------------------------------------------------------------------
765
766 /*
767 * 5 failures are needed to make the rate decrease again.
768 * 5/11 = 0.45
769 */
770 for (int i = 0; i < 4; i++)
771 {
772 manager->ReportDataFailed(mpdu);
773 }
774
775 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
776 mode = txVector.GetMode();
777 power = (int)txVector.GetTxPowerLevel();
778
780 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
781 9000000,
782 "RRPAA: Incorrect vale of data rate");
783 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
784
785 manager->ReportDataFailed(mpdu);
786
787 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
788 mode = txVector.GetMode();
789 power = (int)txVector.GetTxPowerLevel();
790
792 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
793 6000000,
794 "RRPAA: Incorrect vale of data rate");
795 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
796
797 //-----------------------------------------------------------------------------------------------------
798
799 /**
800 * Increase rate until maximal rate.
801 */
802
803 for (int i = 0; i < 7; i++)
804 {
805 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
806 }
807
808 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
809 mode = txVector.GetMode();
810 power = (int)txVector.GetTxPowerLevel();
811
813 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
814 9000000,
815 "RRPAA: Incorrect vale of data rate");
816 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
817
818 for (int i = 0; i < 10; i++)
819 {
820 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
821 }
822
823 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
824 mode = txVector.GetMode();
825 power = (int)txVector.GetTxPowerLevel();
826
828 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
829 12000000,
830 "RRPAA: Incorrect vale of data rate");
831 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
832
833 for (int i = 0; i < 13; i++)
834 {
835 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
836 }
837
838 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
839 mode = txVector.GetMode();
840 power = (int)txVector.GetTxPowerLevel();
841
843 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
844 18000000,
845 "RRPAA: Incorrect vale of data rate");
846 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
847
848 for (int i = 0; i < 19; i++)
849 {
850 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
851 }
852
853 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
854 mode = txVector.GetMode();
855 power = (int)txVector.GetTxPowerLevel();
856
858 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
859 24000000,
860 "RRPAA: Incorrect vale of data rate");
861 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
862
863 for (int i = 0; i < 23; i++)
864 {
865 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
866 }
867
868 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
869 mode = txVector.GetMode();
870 power = (int)txVector.GetTxPowerLevel();
871
873 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
874 36000000,
875 "RRPAA: Incorrect vale of data rate");
876 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
877
878 for (int i = 0; i < 33; i++)
879 {
880 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
881 }
882
883 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
884 mode = txVector.GetMode();
885 power = (int)txVector.GetTxPowerLevel();
886
888 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
889 48000000,
890 "RRPAA: Incorrect vale of data rate");
891 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
892
893 for (int i = 0; i < 43; i++)
894 {
895 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
896 }
897
898 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
899 mode = txVector.GetMode();
900 power = (int)txVector.GetTxPowerLevel();
901
903 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
904 54000000,
905 "RRPAA: Incorrect vale of data rate");
906 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
907
908 //-----------------------------------------------------------------------------------------------------
909
910 /**
911 * Now we need more successful transmissions to make power decrease.
912 * As we are at maximal rate, the power is decreased when it is sure that the failures
913 * will not generate a rate decrease.
914 */
915
916 for (int i = 0; i < 49; i++)
917 {
918 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
919 }
920
921 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
922 mode = txVector.GetMode();
923 power = (int)txVector.GetTxPowerLevel();
924
926 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
927 54000000,
928 "RRPAA: Incorrect vale of data rate");
929 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
930
931 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
932
933 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
934 mode = txVector.GetMode();
935 power = (int)txVector.GetTxPowerLevel();
936
938 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
939 54000000,
940 "RRPAA: Incorrect vale of data rate");
941 NS_TEST_ASSERT_MSG_EQ(power, 16, "RRPAA: Incorrect value of power level");
942
943 //-----------------------------------------------------------------------------------------------------
944
945 /**
946 * As rate hasn't change the same amount of success are needed.
947 * After 16*45 successful transmissions power is decreased to zero.
948 */
949
950 for (int i = 0; i < 16 * 50; i++)
951 {
952 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
953 }
954
955 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
956 mode = txVector.GetMode();
957 power = (int)txVector.GetTxPowerLevel();
958
960 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
961 54000000,
962 "RRPAA: Incorrect vale of data rate");
963 NS_TEST_ASSERT_MSG_EQ(power, 0, "RRPAA: Incorrect value of power level");
964
965 //-----------------------------------------------------------------------------------------------------
966
967 /**
968 * After 6 failures the power should be increased.
969 */
970
971 for (int i = 0; i < 6; i++)
972 {
973 manager->ReportDataFailed(mpdu);
974 }
975
976 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
977 mode = txVector.GetMode();
978 power = (int)txVector.GetTxPowerLevel();
979
981 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
982 54000000,
983 "RRPAA: Incorrect vale of data rate");
984 NS_TEST_ASSERT_MSG_EQ(power, 1, "RRPAA: Incorrect value of power level");
985
986 //-----------------------------------------------------------------------------------------------------
987
988 /*
989 * After 16*6 failed transmissions power is increase to 17.
990 */
991
992 for (int i = 0; i < 16 * 6; i++)
993 {
994 manager->ReportDataFailed(mpdu);
995 }
996
997 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
998 mode = txVector.GetMode();
999 power = (int)txVector.GetTxPowerLevel();
1000
1002 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
1003 54000000,
1004 "RRPAA: Incorrect vale of data rate");
1005 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
1006
1007 //-----------------------------------------------------------------------------------------------------
1008
1009 /*
1010 * After 6 more failures the rate should be decreased.
1011 */
1012
1013 for (int i = 0; i < 6; i++)
1014 {
1015 manager->ReportDataFailed(mpdu);
1016 }
1017
1018 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
1019 mode = txVector.GetMode();
1020 power = (int)txVector.GetTxPowerLevel();
1021
1023 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
1024 48000000,
1025 "RRPAA: Incorrect vale of data rate");
1026 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
1027
1028 /*
1029 * Now 11 failures are needed to decrease rate again.
1030 */
1031
1032 for (int i = 0; i < 11; i++)
1033 {
1034 manager->ReportDataFailed(mpdu);
1035 }
1036
1037 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
1038 mode = txVector.GetMode();
1039 power = (int)txVector.GetTxPowerLevel();
1040
1042 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
1043 36000000,
1044 "RRPAA: Incorrect vale of data rate");
1045 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
1046
1047 //-----------------------------------------------------------------------------------------------------
1048
1049 /*
1050 * Test power decrement when loss probability is between MTL and ORI.
1051 * As we are at rate 36 Mbps we need at least 25 successful transmissions
1052 * and 5 failures.
1053 */
1054
1055 for (int i = 0; i < 25; i++)
1056 {
1057 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
1058 }
1059
1060 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
1061 mode = txVector.GetMode();
1062 power = (int)txVector.GetTxPowerLevel();
1063
1065 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
1066 36000000,
1067 "RRPAA: Incorrect vale of data rate");
1068 NS_TEST_ASSERT_MSG_EQ(power, 17, "RRPAA: Incorrect value of power level");
1069
1070 for (int i = 0; i < 5; i++)
1071 {
1072 manager->ReportDataFailed(mpdu);
1073 }
1074
1075 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
1076 mode = txVector.GetMode();
1077 power = (int)txVector.GetTxPowerLevel();
1078
1080 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
1081 36000000,
1082 "RRPAA: Incorrect vale of data rate");
1083 NS_TEST_ASSERT_MSG_EQ(power, 16, "RRPAA: Incorrect value of power level");
1084
1085 for (int i = 0; i < 5; i++)
1086 {
1087 manager->ReportDataFailed(mpdu);
1088 }
1089
1090 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
1091 mode = txVector.GetMode();
1092 power = (int)txVector.GetTxPowerLevel();
1093
1095 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
1096 36000000,
1097 "RRPAA: Incorrect vale of data rate");
1098 NS_TEST_ASSERT_MSG_EQ(power, 16, "RRPAA: Incorrect value of power level");
1099
1100 for (int i = 0; i < 25; i++)
1101 {
1102 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
1103 }
1104
1105 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
1106 mode = txVector.GetMode();
1107 power = (int)txVector.GetTxPowerLevel();
1108
1110 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
1111 36000000,
1112 "RRPAA: Incorrect vale of data rate");
1113 NS_TEST_ASSERT_MSG_EQ(power, 15, "RRPAA: Incorrect value of power level");
1114
1115 //-----------------------------------------------------------------------------------------------------
1116
1117 /*
1118 * Repeat the previous test until power 0 is reached.
1119 */
1120
1121 for (int i = 0; i < 16; i++)
1122 {
1123 for (int j = 0; j < 25; j++)
1124 {
1125 manager->ReportDataOk(mpdu, 0, ackMode, 0, txVector);
1126 }
1127
1128 for (int j = 0; j < 5; j++)
1129 {
1130 manager->ReportDataFailed(mpdu);
1131 }
1132 }
1133
1134 txVector = manager->GetDataTxVector(packetHeader, dev->GetPhy()->GetChannelWidth());
1135 mode = txVector.GetMode();
1136 power = (int)txVector.GetTxPowerLevel();
1137
1139 mode.GetDataRate(txVector.GetChannelWidth(), txVector.GetGuardInterval(), 1),
1140 36000000,
1141 "RRPAA: Incorrect vale of data rate");
1142 NS_TEST_ASSERT_MSG_EQ(power, 0, "RRPAA: Incorrect value of power level");
1143
1144 Simulator::Stop(Seconds(10.0));
1145
1148}
1149
1150void
1152{
1153 TestParf();
1154 TestAparf();
1155 TestRrpaa();
1156}
1157
1158/**
1159 * \ingroup wifi-test
1160 * \ingroup tests
1161 *
1162 * \brief Power Rate Adaptation Test Suite
1163 */
1165{
1166 public:
1168};
1169
1171 : TestSuite("wifi-power-rate-adaptation", Type::UNIT)
1172{
1173 AddTestCase(new PowerRateAdaptationTest, TestCase::Duration::QUICK);
1174}
1175
Power Rate Adaptation Test.
void TestParf()
Test parf function.
void TestAparf()
Test aparf function.
Ptr< Node > ConfigureNode()
Configure nde function.
void DoRun() 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:42
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address Allocate()
Allocate a new Mac48Address.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() 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.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
Hold an unsigned integer type.
Definition: uinteger.h:45
Implements the IEEE 802.11 MAC header.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
virtual 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:51
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
hold a list of per-remote-station state.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint16_t GetGuardInterval() const
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() const
uint16_t GetChannelWidth() 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:145
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
@ WIFI_STANDARD_80211a
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ WIFI_MAC_DATA
static PowerRateAdaptationTestSuite g_powerRateAdaptationTestSuite
the test suite