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