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