src/devices/wifi/interference-helper-tx-duration-test.cc
changeset 4681 8558474b6149
child 5320 0fb5a9f1a9c0
equal deleted inserted replaced
4680:a52c39181dd4 4681:8558474b6149
       
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2009 CTTC
       
     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: Nicola Baldo <nbaldo@cttc.es>
       
    19  */
       
    20 
       
    21 #include<ns3/object.h>
       
    22 #include<ns3/log.h>
       
    23 #include <ns3/test.h>
       
    24 #include<iostream>
       
    25 #include"interference-helper.h"
       
    26 #include"wifi-phy.h"
       
    27 
       
    28 NS_LOG_COMPONENT_DEFINE ("InterferenceHelperTxDurationTest");
       
    29 
       
    30 
       
    31 #ifdef RUN_SELF_TESTS
       
    32 
       
    33 
       
    34 namespace ns3 {
       
    35 
       
    36 class InterferenceHelperTxDurationTest : public Test {
       
    37 public:
       
    38   InterferenceHelperTxDurationTest ();
       
    39   virtual ~InterferenceHelperTxDurationTest ();
       
    40   virtual bool RunTests (void);
       
    41 
       
    42 private:
       
    43 
       
    44   /** 
       
    45    * Check if the payload tx duration returned by InterferenceHelper
       
    46    * corresponds to a known value of the pay
       
    47    * 
       
    48    * @param size size of payload in octets (includes everything after the PLCP header)
       
    49    * @param payloadMode the WifiMode used 
       
    50    * @param knownPlcpLengthFieldValue the known value of the Length field in the PLCP header
       
    51    * 
       
    52    * @return true if values correspond, false otherwise
       
    53    */
       
    54   bool CheckPayloadDuration(uint32_t size, WifiMode payloadMode,  uint32_t knownDurationMicroSeconds);
       
    55 
       
    56   /** 
       
    57    * Check if the overall tx duration returned by InterferenceHelper
       
    58    * corresponds to a known value of the pay
       
    59    * 
       
    60    * @param size size of payload in octets (includes everything after the PLCP header)
       
    61    * @param payloadMode the WifiMode used 
       
    62    * @param preamble the WifiPreamble used
       
    63    * @param knownPlcpLengthFieldValue the known value of the Length field in the PLCP header
       
    64    * 
       
    65    * @return true if values correspond, false otherwise
       
    66    */
       
    67   bool CheckTxDuration(uint32_t size, WifiMode payloadMode,  WifiPreamble preamble, uint32_t knownDurationMicroSeconds);
       
    68   
       
    69 };
       
    70 
       
    71 
       
    72 // we need to create one instance of InterferenceHelperTxDurationTest
       
    73 static InterferenceHelperTxDurationTest interferenceHelperTxDurationTestInstance;
       
    74 
       
    75 
       
    76 InterferenceHelperTxDurationTest::InterferenceHelperTxDurationTest ()
       
    77   : Test ("InterferenceHelperTxDuration")
       
    78 {
       
    79 }
       
    80 
       
    81 
       
    82 InterferenceHelperTxDurationTest::~InterferenceHelperTxDurationTest ()
       
    83 {
       
    84 }
       
    85 
       
    86 
       
    87 
       
    88 bool
       
    89 InterferenceHelperTxDurationTest::CheckPayloadDuration(uint32_t size, WifiMode payloadMode, uint32_t knownDurationMicroSeconds)
       
    90 {
       
    91   uint32_t calculatedDurationMicroSeconds = InterferenceHelper::GetPayloadDurationMicroSeconds (size, payloadMode);  
       
    92   if (calculatedDurationMicroSeconds != knownDurationMicroSeconds)
       
    93     {
       
    94       std::cerr << " size=" << size
       
    95                 << " mode=" << payloadMode 
       
    96                 << " known=" << knownDurationMicroSeconds
       
    97                 << " calculated=" << calculatedDurationMicroSeconds
       
    98                 << std::endl;
       
    99       return false;
       
   100     }
       
   101   return true;
       
   102 }
       
   103 
       
   104 bool
       
   105 InterferenceHelperTxDurationTest::CheckTxDuration(uint32_t size, WifiMode payloadMode, WifiPreamble preamble, uint32_t knownDurationMicroSeconds)
       
   106 {
       
   107   uint32_t calculatedDurationMicroSeconds = InterferenceHelper::CalculateTxDuration (size, payloadMode, preamble).GetMicroSeconds ();  
       
   108   if (calculatedDurationMicroSeconds != knownDurationMicroSeconds)
       
   109     {
       
   110       std::cerr << " size=" << size
       
   111                 << " mode=" << payloadMode 
       
   112                 << " preamble=" << preamble
       
   113                 << " known=" << knownDurationMicroSeconds
       
   114                 << " calculated=" << calculatedDurationMicroSeconds
       
   115                 << std::endl;
       
   116       return false;
       
   117     }
       
   118   return true;
       
   119 }
       
   120 
       
   121 bool 
       
   122 InterferenceHelperTxDurationTest::RunTests (void)
       
   123 {
       
   124   bool retval = true;
       
   125 
       
   126   // IEEE Std 802.11-2007 Table 18-2 "Example of LENGTH calculations for CCK"
       
   127   retval = retval 
       
   128     && CheckPayloadDuration (1023, WifiPhy::Get11mbb (), 744)     
       
   129     && CheckPayloadDuration (1024, WifiPhy::Get11mbb (), 745)
       
   130     && CheckPayloadDuration (1025, WifiPhy::Get11mbb (), 746)
       
   131     && CheckPayloadDuration (1026, WifiPhy::Get11mbb (), 747);
       
   132 
       
   133 
       
   134   // Similar, but we add PLCP preamble and header durations
       
   135   // and we test different rates.
       
   136   // The payload durations for modes other than 11mbb have been
       
   137   // calculated by hand according to  IEEE Std 802.11-2007 18.2.3.5 
       
   138   retval = retval 
       
   139     && CheckTxDuration (1023, WifiPhy::Get11mbb (), WIFI_PREAMBLE_SHORT, 744 + 96)     
       
   140     && CheckTxDuration (1024, WifiPhy::Get11mbb (), WIFI_PREAMBLE_SHORT, 745 + 96)
       
   141     && CheckTxDuration (1025, WifiPhy::Get11mbb (), WIFI_PREAMBLE_SHORT, 746 + 96)
       
   142     && CheckTxDuration (1026, WifiPhy::Get11mbb (), WIFI_PREAMBLE_SHORT, 747 + 96)
       
   143     && CheckTxDuration (1023, WifiPhy::Get11mbb (), WIFI_PREAMBLE_LONG, 744 + 192)     
       
   144     && CheckTxDuration (1024, WifiPhy::Get11mbb (), WIFI_PREAMBLE_LONG, 745 + 192)
       
   145     && CheckTxDuration (1025, WifiPhy::Get11mbb (), WIFI_PREAMBLE_LONG, 746 + 192)
       
   146     && CheckTxDuration (1026, WifiPhy::Get11mbb (), WIFI_PREAMBLE_LONG, 747 + 192)
       
   147     && CheckTxDuration (1023, WifiPhy::Get5_5mbb (), WIFI_PREAMBLE_SHORT, 1488 + 96)     
       
   148     && CheckTxDuration (1024, WifiPhy::Get5_5mbb (), WIFI_PREAMBLE_SHORT, 1490 + 96)
       
   149     && CheckTxDuration (1025, WifiPhy::Get5_5mbb (), WIFI_PREAMBLE_SHORT, 1491 + 96)
       
   150     && CheckTxDuration (1026, WifiPhy::Get5_5mbb (), WIFI_PREAMBLE_SHORT, 1493 + 96)
       
   151     && CheckTxDuration (1023, WifiPhy::Get5_5mbb (), WIFI_PREAMBLE_LONG, 1488 + 192)     
       
   152     && CheckTxDuration (1024, WifiPhy::Get5_5mbb (), WIFI_PREAMBLE_LONG, 1490 + 192)
       
   153     && CheckTxDuration (1025, WifiPhy::Get5_5mbb (), WIFI_PREAMBLE_LONG, 1491 + 192)
       
   154     && CheckTxDuration (1026, WifiPhy::Get5_5mbb (), WIFI_PREAMBLE_LONG, 1493 + 192)
       
   155     && CheckTxDuration (1023, WifiPhy::Get2mbb (), WIFI_PREAMBLE_SHORT, 4092 + 96)     
       
   156     && CheckTxDuration (1024, WifiPhy::Get2mbb (), WIFI_PREAMBLE_SHORT, 4096 + 96)
       
   157     && CheckTxDuration (1025, WifiPhy::Get2mbb (), WIFI_PREAMBLE_SHORT, 4100 + 96)
       
   158     && CheckTxDuration (1026, WifiPhy::Get2mbb (), WIFI_PREAMBLE_SHORT, 4104 + 96)
       
   159     && CheckTxDuration (1023, WifiPhy::Get2mbb (), WIFI_PREAMBLE_LONG, 4092 + 192)     
       
   160     && CheckTxDuration (1024, WifiPhy::Get2mbb (), WIFI_PREAMBLE_LONG, 4096 + 192)
       
   161     && CheckTxDuration (1025, WifiPhy::Get2mbb (), WIFI_PREAMBLE_LONG, 4100 + 192)
       
   162     && CheckTxDuration (1026, WifiPhy::Get2mbb (), WIFI_PREAMBLE_LONG, 4104 + 192)      
       
   163     && CheckTxDuration (1023, WifiPhy::Get1mbb (), WIFI_PREAMBLE_SHORT, 8184 + 96)     
       
   164     && CheckTxDuration (1024, WifiPhy::Get1mbb (), WIFI_PREAMBLE_SHORT, 8192 + 96)
       
   165     && CheckTxDuration (1025, WifiPhy::Get1mbb (), WIFI_PREAMBLE_SHORT, 8200 + 96)
       
   166     && CheckTxDuration (1026, WifiPhy::Get1mbb (), WIFI_PREAMBLE_SHORT, 8208 + 96)
       
   167     && CheckTxDuration (1023, WifiPhy::Get1mbb (), WIFI_PREAMBLE_LONG, 8184 + 192)     
       
   168     && CheckTxDuration (1024, WifiPhy::Get1mbb (), WIFI_PREAMBLE_LONG, 8192 + 192)
       
   169     && CheckTxDuration (1025, WifiPhy::Get1mbb (), WIFI_PREAMBLE_LONG, 8200 + 192)
       
   170     && CheckTxDuration (1026, WifiPhy::Get1mbb (), WIFI_PREAMBLE_LONG, 8208 + 192);
       
   171 
       
   172   // values from http://mailman.isi.edu/pipermail/ns-developers/2009-July/006226.html
       
   173   retval = retval && CheckTxDuration (14, WifiPhy::Get1mbb (), WIFI_PREAMBLE_LONG, 304);
       
   174 
       
   175   // values from
       
   176   // http://www.oreillynet.com/pub/a/wireless/2003/08/08/wireless_throughput.html
       
   177   retval = retval 
       
   178     && CheckTxDuration (1536, WifiPhy::Get11mbb (), WIFI_PREAMBLE_LONG, 1310)
       
   179     && CheckTxDuration (76, WifiPhy::Get11mbb (), WIFI_PREAMBLE_LONG, 248)
       
   180     && CheckTxDuration (14, WifiPhy::Get11mbb (), WIFI_PREAMBLE_LONG, 203)
       
   181     && CheckTxDuration (1536, WifiPhy::Get54mba (), WIFI_PREAMBLE_LONG, 248)
       
   182     && CheckTxDuration (76, WifiPhy::Get54mba (), WIFI_PREAMBLE_LONG, 32)
       
   183     && CheckTxDuration (14, WifiPhy::Get54mba (), WIFI_PREAMBLE_LONG, 24);
       
   184 
       
   185 
       
   186   return retval;
       
   187 }
       
   188 
       
   189 
       
   190 } //namespace ns3 
       
   191 
       
   192 
       
   193 #endif /* RUN_SELF_TESTS */