src/devices/mesh/dot11s/airtime-metric.cc
author Kirill Andreev <andreev@iitp.ru>
Thu, 25 Feb 2010 14:57:20 +0100
changeset 6069 c21754b56036
parent 6064 ddec96840ebd
child 6071 6a25c600c450
permissions -rw-r--r--
change airtime metric to work with new wifi remote station manager
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"
5132
aee541a30256 Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents: 5129
diff changeset
    24
namespace ns3 {
aee541a30256 Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents: 5129
diff changeset
    25
namespace dot11s {
5042
Kirill Andreev <andreev@iitp.ru>
parents: 5040
diff changeset
    26
NS_OBJECT_ENSURE_REGISTERED (AirtimeLinkMetricCalculator);
5040
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    27
TypeId
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    28
AirtimeLinkMetricCalculator::GetTypeId ()
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    29
{
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    30
  static TypeId tid = TypeId ("ns3::dot11s::AirtimeLinkMetricCalculator")
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    31
    .SetParent<Object> ()
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    32
    .AddConstructor<AirtimeLinkMetricCalculator> ()
5165
08d3bef3b477 Stupid fixes
Kirill Andreev <andreev@iitp.ru>
parents: 5156
diff changeset
    33
    .AddAttribute ( "TestLength",
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    34
                    "Rate should be estimated using test length.",
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    35
                     UintegerValue (1024),
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    36
                     MakeUintegerAccessor (
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    37
                         &AirtimeLinkMetricCalculator::SetTestLength),
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    38
                     MakeUintegerChecker<uint16_t> (1)
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    39
                  )
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    40
    .AddAttribute ( "Dot11MetricTid",
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    41
                    "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
    42
                    UintegerValue (0),
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    43
                    MakeUintegerAccessor (
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    44
                        &AirtimeLinkMetricCalculator::SetHeaderTid),
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    45
                    MakeUintegerChecker<uint8_t> (0)
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    46
                  )
5165
08d3bef3b477 Stupid fixes
Kirill Andreev <andreev@iitp.ru>
parents: 5156
diff changeset
    47
    .AddAttribute ( "Dot11sMeshHeaderLength",
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    48
                    "Length of the mesh header",
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    49
                    UintegerValue (6),
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    50
                    MakeUintegerAccessor (
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    51
                        &AirtimeLinkMetricCalculator::m_meshHeaderLength),
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    52
                    MakeUintegerChecker<uint16_t> (0)
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    53
                  )
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    54
                  ;
5040
6af8b7fab76a Airtime metric fixed
Kirill Andreev <andreev@iitp.ru>
parents: 5035
diff changeset
    55
  return tid;
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    56
}
5828
9959ba75ba25 Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents: 5446
diff changeset
    57
AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator () :
9959ba75ba25 Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents: 5446
diff changeset
    58
  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
    59
{
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    60
}
5828
9959ba75ba25 Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents: 5446
diff changeset
    61
void
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    62
AirtimeLinkMetricCalculator::SetHeaderTid (uint8_t tid)
5828
9959ba75ba25 Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents: 5446
diff changeset
    63
{
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    64
  m_testHeader.SetDsFrom ();
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    65
  m_testHeader.SetDsTo ();
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    66
  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
    67
}
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    68
void
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    69
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
    70
{
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    71
  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
    72
}
4946
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    73
uint32_t
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    74
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
    75
{
5063
97b947e83640 Faker's code review response
Pavel Boyko <boyko@iitp.ru>
parents: 5042
diff changeset
    76
  /* 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
    77
   *
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    78
   * airtime = (O + Bt/r) /  (1 - frame error rate), where
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    79
   * 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
    80
   *       access protocol frames, etc.
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    81
   * 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
    82
   * r  -- the current bitrate of the packet,
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5063
diff changeset
    83
   *
5063
97b947e83640 Faker's code review response
Pavel Boyko <boyko@iitp.ru>
parents: 5042
diff changeset
    84
   * 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
    85
   */
6069
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    86
  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
    87
  //obtain current rate:
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    88
  WifiMode mode = mac->GetStationManager ()->GetDataMode (peerAddress, &m_testHeader, m_testFrame, m_testFrame->GetSize ());
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    89
  //obtain frame error rate:
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    90
  double failAvg = mac->GetStationManager ()->Lookup (peerAddress, &m_testHeader)->m_state->m_info.GetFrameErrorRate ();
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    91
  NS_ASSERT (failAvg < 1.0);
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    92
  //calculate metric
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    93
  uint32_t metric = (uint32_t)((double)(/*Overhead + payload*/
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    94
      mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    95
      mac->GetWifiPhy () ->CalculateTxDuration (m_testFrame->GetSize (), mode, WIFI_PREAMBLE_LONG)
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    96
      ).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    97
  std::cout << "pure overhead is " << (uint32_t)((double)(/*Overhead + payload*/
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    98
      mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs ()
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
    99
      ).GetMicroSeconds ()/10.24) << "\n";
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
   100
  std::cout << "mode is:" << mode.GetDataRate () << "\n";
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
   101
  std::cout << "Metric is :" << metric << "\n";
c21754b56036 change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents: 6064
diff changeset
   102
  return metric;
4946
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
   103
}
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
   104
} //namespace dot11s
f97e16db1d79 Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
   105
} //namespace ns3