src/mesh/model/dot11s/airtime-metric.cc
author Ghada Badawy <gbadawy@gmail.com>
Tue, 13 Aug 2013 22:05:25 -0700
changeset 10139 17a71cd49da3
parent 7386 2310ed220a61
child 10218 97da49da2d6c
permissions -rw-r--r--
partial 802.11n support
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4947
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
     2
/*
4947
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
     3
 * Copyright (c) 2009 IITP RAS
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
     4
 *
4947
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
     7
 * published by the Free Software Foundation;
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
     8
 *
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    12
 * GNU General Public License for more details.
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    13
 *
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    14
 * You should have received a copy of the GNU General Public License
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    15
 * along with this program; if not, write to the Free Software
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    17
 *
4947
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    18
 * Authors: Kirill Andreev <andreev@iitp.ru>
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    19
 */
c665ebbe99a7 Bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 4946
diff changeset
    20
4946
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    21
#include "airtime-metric.h"
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    22
#include "ns3/wifi-remote-station-manager.h"
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    23
#include "ns3/wifi-mode.h"
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents: 7386
diff changeset
    24
#include "ns3/wifi-tx-vector.h"
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents: 7386
diff changeset
    25
5132
aee541a30256 Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents: 5129
diff changeset
    26
namespace ns3 {
aee541a30256 Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents: 5129
diff changeset
    27
namespace dot11s {
5042
Kirill Andreev <andreev@iitp.ru>
parents: 5040
diff changeset
    28
NS_OBJECT_ENSURE_REGISTERED (AirtimeLinkMetricCalculator);
5040
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    29
TypeId
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    30
AirtimeLinkMetricCalculator::GetTypeId ()
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    31
{
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    32
  static TypeId tid = TypeId ("ns3::dot11s::AirtimeLinkMetricCalculator")
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    33
    .SetParent<Object> ()
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    34
    .AddConstructor<AirtimeLinkMetricCalculator> ()
5165
08d3bef3b477 Stupid fixes
Kirill Andreev <andreev@iitp.ru>
parents: 5156
diff changeset
    35
    .AddAttribute ( "TestLength",
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    36
                    "Rate should be estimated using test length.",
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    37
                    UintegerValue (1024),
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    38
                    MakeUintegerAccessor (
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    39
                      &AirtimeLinkMetricCalculator::SetTestLength),
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    40
                    MakeUintegerChecker<uint16_t> (1)
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    41
                    )
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    42
    .AddAttribute ( "Dot11MetricTid",
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    43
                    "TID used to calculate metric (data rate)",
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    44
                    UintegerValue (0),
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    45
                    MakeUintegerAccessor (
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    46
                      &AirtimeLinkMetricCalculator::SetHeaderTid),
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    47
                    MakeUintegerChecker<uint8_t> (0)
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    48
                    )
5165
08d3bef3b477 Stupid fixes
Kirill Andreev <andreev@iitp.ru>
parents: 5156
diff changeset
    49
    .AddAttribute ( "Dot11sMeshHeaderLength",
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    50
                    "Length of the mesh header",
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    51
                    UintegerValue (6),
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    52
                    MakeUintegerAccessor (
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    53
                      &AirtimeLinkMetricCalculator::m_meshHeaderLength),
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    54
                    MakeUintegerChecker<uint16_t> (0)
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    55
                    )
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    56
  ;
5040
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    57
  return tid;
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    58
}
5828
9959ba75ba25 Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents: 5446
diff changeset
    59
AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator () :
9959ba75ba25 Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents: 5446
diff changeset
    60
  m_overheadNanosec (0)
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    61
{
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    62
}
5828
9959ba75ba25 Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents: 5446
diff changeset
    63
void
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    64
AirtimeLinkMetricCalculator::SetHeaderTid (uint8_t tid)
5828
9959ba75ba25 Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents: 5446
diff changeset
    65
{
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    66
  m_testHeader.SetDsFrom ();
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    67
  m_testHeader.SetDsTo ();
6098
b0e661ced163 Mesh: fixed valgrind errors
Kirill Andreev <andreev@iitp.ru>
parents: 6082
diff changeset
    68
  m_testHeader.SetTypeData ();
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    69
  m_testHeader.SetQosTid (tid);
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    70
}
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    71
void
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    72
AirtimeLinkMetricCalculator::SetTestLength (uint16_t testLength)
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    73
{
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    74
  m_testFrame = Create<Packet> (testLength + 6 /*Mesh header*/ + 36 /*802.11 header*/);
5828
9959ba75ba25 Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents: 5446
diff changeset
    75
}
4946
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    76
uint32_t
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    77
AirtimeLinkMetricCalculator::CalculateMetric (Mac48Address peerAddress, Ptr<MeshWifiInterfaceMac> mac)
4946
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    78
{
5063
97b947e83640 Faker's code review response
Pavel Boyko <boyko@iitp.ru>
parents: 5042
diff changeset
    79
  /* Airtime link metric is defined in 11B.10 of 802.11s Draft D3.0 as:
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    80
   *
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    81
   * airtime = (O + Bt/r) /  (1 - frame error rate), where
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    82
   * o  -- the PHY dependent channel access which includes frame headers, training sequences,
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    83
   *       access protocol frames, etc.
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    84
   * bt -- the test packet length in bits (8192 by default),
5063
97b947e83640 Faker's code review response
Pavel Boyko <boyko@iitp.ru>
parents: 5042
diff changeset
    85
   * r  -- the current bitrate of the packet,
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    86
   *
5063
97b947e83640 Faker's code review response
Pavel Boyko <boyko@iitp.ru>
parents: 5042
diff changeset
    87
   * Final result is expressed in units of 0.01 Time Unit = 10.24 us (as required by 802.11s draft)
97b947e83640 Faker's code review response
Pavel Boyko <boyko@iitp.ru>
parents: 5042
diff changeset
    88
   */
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    89
  NS_ASSERT (!peerAddress.IsGroup ());
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    90
  //obtain current rate:
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents: 7386
diff changeset
    91
  WifiMode mode = mac->GetWifiRemoteStationManager ()->GetDataTxVector (peerAddress, &m_testHeader, m_testFrame, m_testFrame->GetSize ()).GetMode();
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    92
  //obtain frame error rate:
6673
ec22aa763e2d Bug 978: Consolidate Wi-Fi MAC high functionality
Dean Armstrong <deanarm@gmail.com>
parents: 6098
diff changeset
    93
  double failAvg = mac->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate ();
7298
46338d126f2f Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents: 6882
diff changeset
    94
  if (failAvg == 1)
46338d126f2f Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents: 6882
diff changeset
    95
    {
46338d126f2f Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents: 6882
diff changeset
    96
      // Retrun max metric value when frame error rate equals to 1
46338d126f2f Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents: 6882
diff changeset
    97
      return (uint32_t)0xffffffff;
46338d126f2f Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents: 6882
diff changeset
    98
    }
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    99
  NS_ASSERT (failAvg < 1.0);
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents: 7386
diff changeset
   100
  WifiTxVector txVector;
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents: 7386
diff changeset
   101
  txVector.SetMode (mode);
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
   102
  //calculate metric
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   103
  uint32_t metric = (uint32_t)((double)( /*Overhead + payload*/
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   104
                                 mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents: 7386
diff changeset
   105
                                 mac->GetWifiPhy ()->CalculateTxDuration (m_testFrame->GetSize (), txVector, WIFI_PREAMBLE_LONG)
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   106
                                 ).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
   107
  return metric;
4946
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
   108
}
7386
2310ed220a61 standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents: 7298
diff changeset
   109
} // namespace dot11s
2310ed220a61 standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents: 7298
diff changeset
   110
} // namespace ns3