Improve the accuracy of 802.11a tx duration calculations.
authorFederico Maguolo <federico.maguolo@dei.unipd.it>
Fri, 23 Nov 2007 10:23:55 +0100
changeset 2166 00b5eb43dba2
parent 2165 6acd0dca66f9
child 2167 3b0f18764163
Improve the accuracy of 802.11a tx duration calculations.
src/devices/wifi/mac-parameters.cc
src/devices/wifi/wifi-default-parameters.cc
src/devices/wifi/wifi-default-parameters.h
src/devices/wifi/wifi-phy-standard.h
src/devices/wifi/wifi-phy.cc
src/devices/wifi/wifi-phy.h
src/devices/wifi/wscript
--- a/src/devices/wifi/mac-parameters.cc	Fri Nov 23 11:36:16 2007 +0100
+++ b/src/devices/wifi/mac-parameters.cc	Fri Nov 23 10:23:55 2007 +0100
@@ -32,8 +32,8 @@
   m_maxSlrc = WifiDefaultParameters::GetMaxSlrc ();
 
   // ensure something not too stupid is set by default.
-  NS_ASSERT (WifiDefaultParameters::GetPhyStandard () == WifiDefaultParameters::PHY_STANDARD_80211a ||
-             WifiDefaultParameters::GetPhyStandard () == WifiDefaultParameters::PHY_STANDARD_holland);
+  NS_ASSERT (WifiDefaultParameters::GetPhyStandard () == WIFI_PHY_STANDARD_80211a ||
+             WifiDefaultParameters::GetPhyStandard () == WIFI_PHY_STANDARD_holland);
   uint32_t ctsAckSize = (2 + 2 + 6) * 8; // bits
   double dataRate = (6e6 / 2); // mb/s
   Time delay = Seconds (ctsAckSize / dataRate);
@@ -43,8 +43,8 @@
 void 
 MacParameters::Initialize (Time ctsDelay, Time ackDelay)
 {
-  NS_ASSERT (WifiDefaultParameters::GetPhyStandard () == WifiDefaultParameters::PHY_STANDARD_80211a ||
-             WifiDefaultParameters::GetPhyStandard () == WifiDefaultParameters::PHY_STANDARD_holland);
+  NS_ASSERT (WifiDefaultParameters::GetPhyStandard () == WIFI_PHY_STANDARD_80211a ||
+             WifiDefaultParameters::GetPhyStandard () == WIFI_PHY_STANDARD_holland);
 
   // these values are really 802.11a specific
   m_sifs = MicroSeconds (16);
--- a/src/devices/wifi/wifi-default-parameters.cc	Fri Nov 23 11:36:16 2007 +0100
+++ b/src/devices/wifi/wifi-default-parameters.cc	Fri Nov 23 10:23:55 2007 +0100
@@ -25,11 +25,11 @@
 
 namespace WifiDefaultParameters {
 
-static EnumDefaultValue<enum PhyStandard> g_phyStandard
+static EnumDefaultValue<enum WifiPhyStandard> g_phyStandard
 ("WifiPhyStandard", 
  "Describe the set of physical-layer tx modes and parameters",
- PHY_STANDARD_80211a, "80211a",
- PHY_STANDARD_holland, "holland",
+ WIFI_PHY_STANDARD_80211a, "80211a",
+ WIFI_PHY_STANDARD_holland, "holland",
  0, (void*)0);
 
 static NumericDefaultValue<uint32_t> g_maxSsrc
@@ -189,7 +189,7 @@
 {
   return g_apBeaconInterval.GetValue ();
 }
-enum PhyStandard 
+enum WifiPhyStandard 
 GetPhyStandard (void)
 {
   return g_phyStandard.GetValue ();
--- a/src/devices/wifi/wifi-default-parameters.h	Fri Nov 23 11:36:16 2007 +0100
+++ b/src/devices/wifi/wifi-default-parameters.h	Fri Nov 23 10:23:55 2007 +0100
@@ -23,15 +23,13 @@
 #include <stdint.h>
 #include "ns3/nstime.h"
 #include "ssid.h"
+#include "wifi-phy-standard.h"
 
 namespace ns3 {
 
 namespace WifiDefaultParameters {
 
-enum PhyStandard {
-  PHY_STANDARD_80211a,
-  PHY_STANDARD_holland,
-};
+
 enum RateControlAlgorithm {
   CONSTANT_RATE,
   ARF,
@@ -54,7 +52,7 @@
 uint32_t GetRtsCtsThreshold (void);
 uint32_t GetFragmentationThreshold (void);
 Time GetApBeaconInterval (void);
-enum PhyStandard GetPhyStandard (void);
+enum WifiPhyStandard GetPhyStandard (void);
 enum RateControlAlgorithm GetRateControlAlgorithm (void);
 enum PhyModeParameter GetConstantDataRate (void);
 enum PhyModeParameter GetConstantCtlRate (void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/wifi/wifi-phy-standard.h	Fri Nov 23 10:23:55 2007 +0100
@@ -0,0 +1,32 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as 
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef WIFI_PHY_STANDARD_H
+#define WIFI_PHY_STANDARD_H
+
+namespace ns3 {
+
+enum WifiPhyStandard {
+  WIFI_PHY_STANDARD_80211a,
+  WIFI_PHY_STANDARD_holland
+};
+
+} // namespace ns3
+
+#endif /* WIFI_PHY_STANDARD_H */
--- a/src/devices/wifi/wifi-phy.cc	Fri Nov 23 11:36:16 2007 +0100
+++ b/src/devices/wifi/wifi-phy.cc	Fri Nov 23 10:23:55 2007 +0100
@@ -192,13 +192,14 @@
     m_previousStateChangeTime (Seconds (0)),
     m_device (device),
     m_endSyncEvent (),
-    m_random (0.0, 1.0)
+    m_random (0.0, 1.0),
+    m_standard (WifiDefaultParameters::GetPhyStandard ())
 {
-  switch (WifiDefaultParameters::GetPhyStandard ()) {
-  case WifiDefaultParameters::PHY_STANDARD_80211a:
+  switch (m_standard) {
+  case WIFI_PHY_STANDARD_80211a:
     Configure80211a ();
     break;
-  case WifiDefaultParameters::PHY_STANDARD_holland:
+  case WIFI_PHY_STANDARD_holland:
     ConfigureHolland ();
     break;
   default:
@@ -407,11 +408,11 @@
 void
 WifiPhy::Configure80211aParameters (void)
 {
-  m_plcpLongPreambleDelayUs = 20;
-  m_plcpShortPreambleDelayUs = 20;
+  m_plcpLongPreambleDelayUs = 16;
+  m_plcpShortPreambleDelayUs = 16;
   m_longPlcpHeaderMode = g_6mba;
   m_shortPlcpHeaderMode = g_6mba;
-  m_plcpHeaderLength = 4 + 1 + 12 + 1 + 6 + 16 + 6;
+  m_plcpHeaderLength = 4 + 1 + 12 + 1 + 6;
   /* 4095 bytes at a 6Mb/s rate with a 1/2 coding rate. */
   m_maxPacketDuration = Seconds (4095.0*8.0/6000000.0*(1.0/2.0));
 }
@@ -539,18 +540,19 @@
 WifiPhy::CalculateTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble) const
 {
   uint64_t delay = 0;
-  switch (preamble) {
-  case WIFI_PREAMBLE_LONG:
+  switch (m_standard) {
+  case WIFI_PHY_STANDARD_80211a:
+  case WIFI_PHY_STANDARD_holland: {
     delay += m_plcpLongPreambleDelayUs;
-    delay += m_plcpHeaderLength * 1000000 / m_longPlcpHeaderMode.GetDataRate ();
-    break;
-  case WIFI_PREAMBLE_SHORT:
-    delay += m_plcpShortPreambleDelayUs;
-    delay += m_plcpHeaderLength * 1000000 / m_shortPlcpHeaderMode.GetDataRate ();
+    // symbol duration is 4us
+    delay += 4;
+    delay += lrint (ceil ((size * 8 + 16 + 6) / payloadMode.GetDataRate () / 4e-6) * 4);
+  } break;
+  default:
+    // quiet compiler.
+    NS_ASSERT (false);
     break;
   }
-  uint64_t nbits = size * 8;
-  delay += nbits * 1000000 / payloadMode.GetDataRate ();
   return MicroSeconds (delay);
 }
 
--- a/src/devices/wifi/wifi-phy.h	Fri Nov 23 11:36:16 2007 +0100
+++ b/src/devices/wifi/wifi-phy.h	Fri Nov 23 10:23:55 2007 +0100
@@ -34,6 +34,7 @@
 #include "ns3/random-variable.h"
 #include "wifi-mode.h"
 #include "wifi-preamble.h"
+#include "wifi-phy-standard.h"
 
 
 namespace ns3 {
@@ -338,6 +339,7 @@
   Events m_events;
   UniformVariable m_random;
   CallbackTraceSource<Time,Time,enum WifiPhy::State> m_stateLogger;
+  WifiPhyStandard m_standard;
 };
 
 } // namespace ns3
--- a/src/devices/wifi/wscript	Fri Nov 23 11:36:16 2007 +0100
+++ b/src/devices/wifi/wscript	Fri Nov 23 10:23:55 2007 +0100
@@ -43,5 +43,6 @@
         'wifi-mode.h',
         'ssid.h',
         'wifi-preamble.h',
+	'wifi-phy-standard.h',
         'wifi-phy.h',
         ]