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