src/wifi/model/wifi-mode.cc
author Lalith Suresh <suresh.lalith@gmail.com>
Fri, 04 Mar 2011 01:26:54 +0000
changeset 6852 8f1a53d3f6ca
parent 6848 src/devices/wifi/model/wifi-mode.cc@1f453ad50ef3
child 7141 072fb225b714
permissions -rw-r--r--
Moves devices/* and routing/* to src/
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2034
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
     2
/*
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
     3
 * Copyright (c) 2005,2006,2007 INRIA
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
     4
 *
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as 
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
     7
 * published by the Free Software Foundation;
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
     8
 *
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    12
 * GNU General Public License for more details.
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    13
 *
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    14
 * You should have received a copy of the GNU General Public License
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    15
 * along with this program; if not, write to the Free Software
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    17
 *
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1984
diff changeset
    19
 */
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "wifi-mode.h"
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
    21
#include "ns3/simulator.h"
1887
14b4e0b7870a add missing implementations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1885
diff changeset
    22
#include "ns3/assert.h"
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
    23
#include "ns3/log.h"
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
namespace ns3 {
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
1910
1c1dd3c8c228 add operator == for WifiMode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1909
diff changeset
    27
bool operator == (const WifiMode &a, const WifiMode &b)
1c1dd3c8c228 add operator == for WifiMode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1909
diff changeset
    28
{
1c1dd3c8c228 add operator == for WifiMode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1909
diff changeset
    29
  return a.GetUid () == b.GetUid ();
1c1dd3c8c228 add operator == for WifiMode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1909
diff changeset
    30
}
1981
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    31
std::ostream & operator << (std::ostream & os, const WifiMode &mode)
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    32
{
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    33
  os << mode.GetUniqueName ();
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    34
  return os;
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    35
}
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
    36
std::istream & operator >> (std::istream &is, WifiMode &mode)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
    37
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
    38
  std::string str;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
    39
  is >> str;
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
    40
  mode = WifiModeFactory::GetFactory ()->Search (str);
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
    41
  return is;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
    42
}
1910
1c1dd3c8c228 add operator == for WifiMode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1909
diff changeset
    43
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
uint32_t 
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
WifiMode::GetBandwidth (void) const
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
{
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
  struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
  return item->bandwidth;
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
}
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
uint32_t 
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
WifiMode::GetPhyRate (void) const
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
{
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
  struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
  return item->phyRate;
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
}
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
uint32_t 
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
WifiMode::GetDataRate (void) const
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
{
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
  struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
  return item->dataRate;
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
}
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
    62
enum WifiCodeRate 
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
    63
WifiMode::GetCodeRate (void) const
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
{
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
  struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
    66
  return item->codingRate;
1909
4d1214bb8bc0 add WifiMode mandatory flag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1887
diff changeset
    67
}
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
uint8_t 
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
WifiMode::GetConstellationSize (void) const
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
{
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
  struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
  return item->constellationSize;
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
}
1981
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    74
std::string 
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    75
WifiMode::GetUniqueName (void) const
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    76
{
4331
771b9f0005d6 make ./waf check pass again.
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3879
diff changeset
    77
  // needed for ostream printing of the invalid mode
1981
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    78
  struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    79
  return item->uniqueUid;
d2fda7b87289 implement operator << and an assert
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1966
diff changeset
    80
}
1909
4d1214bb8bc0 add WifiMode mandatory flag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1887
diff changeset
    81
bool
4d1214bb8bc0 add WifiMode mandatory flag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1887
diff changeset
    82
WifiMode::IsMandatory (void) const
4d1214bb8bc0 add WifiMode mandatory flag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1887
diff changeset
    83
{
4d1214bb8bc0 add WifiMode mandatory flag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1887
diff changeset
    84
  struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
4d1214bb8bc0 add WifiMode mandatory flag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1887
diff changeset
    85
  return item->isMandatory;
4d1214bb8bc0 add WifiMode mandatory flag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1887
diff changeset
    86
}
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
uint32_t 
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
WifiMode::GetUid (void) const
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
{
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
  return m_uid;
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
}
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
    92
enum WifiModulationClass
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
    93
WifiMode::GetModulationClass () const
4681
8558474b6149 made InterferenceHelper::CalculateTxDuration () static
Nicola Baldo <nbaldo@cttc.es>
parents: 4470
diff changeset
    94
{
8558474b6149 made InterferenceHelper::CalculateTxDuration () static
Nicola Baldo <nbaldo@cttc.es>
parents: 4470
diff changeset
    95
  struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
    96
  return item->modClass;
4681
8558474b6149 made InterferenceHelper::CalculateTxDuration () static
Nicola Baldo <nbaldo@cttc.es>
parents: 4470
diff changeset
    97
}
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
WifiMode::WifiMode ()
1920
1d4864775cf8 replace header mode with preamble mode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1910
diff changeset
    99
  : m_uid (0)
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
{}
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
WifiMode::WifiMode (uint32_t uid)
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
  : m_uid (uid)
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
{}
3879
3a887a06b795 add a string-based constructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2675
diff changeset
   104
WifiMode::WifiMode (std::string name)
3a887a06b795 add a string-based constructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2675
diff changeset
   105
{
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   106
  *this = WifiModeFactory::GetFactory ()->Search (name);
3879
3a887a06b795 add a string-based constructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2675
diff changeset
   107
}
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
2582
3e28107b870f rename old VALUE leftovers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2524
diff changeset
   109
ATTRIBUTE_HELPER_CPP (WifiMode);
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   110
1887
14b4e0b7870a add missing implementations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1885
diff changeset
   111
WifiModeFactory::WifiModeFactory ()
14b4e0b7870a add missing implementations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1885
diff changeset
   112
{}
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
5901
a24cd8dce646 bug 767: Incorrect modulation for 802.11a modes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4713
diff changeset
   114
a24cd8dce646 bug 767: Incorrect modulation for 802.11a modes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4713
diff changeset
   115
WifiMode 
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   116
WifiModeFactory::CreateWifiMode (std::string uniqueName,
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   117
                                 enum WifiModulationClass modClass,
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   118
                                 bool isMandatory,
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   119
                                 uint32_t bandwidth,
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   120
                                 uint32_t dataRate,
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   121
                                 enum WifiCodeRate codingRate,
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   122
                                 uint8_t constellationSize)
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
{
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
  WifiModeFactory *factory = GetFactory ();
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
  uint32_t uid = factory->AllocateUid (uniqueName);
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
  WifiModeItem *item = factory->Get (uid);
1984
c00b259986bd initialize uniqueUid field
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1981
diff changeset
   127
  item->uniqueUid = uniqueName;
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   128
  item->modClass = modClass;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   129
  // The modulation class for this WifiMode must be valid.
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   130
  NS_ASSERT (modClass != WIFI_MOD_CLASS_UNKNOWN);
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   131
4470
51b5c1a272d3 802.11b PHY support
Gary Pei <guangyu.pei@boeing.com>
parents: 4331
diff changeset
   132
  item->bandwidth = bandwidth;
51b5c1a272d3 802.11b PHY support
Gary Pei <guangyu.pei@boeing.com>
parents: 4331
diff changeset
   133
  item->dataRate = dataRate;
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   134
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   135
  item->codingRate = codingRate;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   136
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   137
  switch (codingRate) {
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   138
  case WIFI_CODE_RATE_3_4:
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   139
    item->phyRate = dataRate * 4 / 3;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   140
    break;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   141
  case WIFI_CODE_RATE_2_3:
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   142
    item->phyRate = dataRate * 3 / 2;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   143
    break;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   144
  case WIFI_CODE_RATE_1_2:
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   145
    item->phyRate = dataRate * 2 / 1;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   146
    break;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   147
  case WIFI_CODE_RATE_UNDEFINED:
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   148
  default:
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   149
    item->phyRate = dataRate;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   150
    break;
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   151
  }
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   152
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   153
  // Check for compatibility between modulation class and coding
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   154
  // rate. If modulation class is DSSS then coding rate must be
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   155
  // undefined, and vice versa. I could have done this with an
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   156
  // assertion, but it seems better to always give the error (i.e.,
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   157
  // not only in non-optimised builds) and the cycles that extra test
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   158
  // here costs are only suffered at simulation setup.
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   159
  if ((codingRate == WIFI_CODE_RATE_UNDEFINED) != (modClass == WIFI_MOD_CLASS_DSSS))
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   160
    {
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   161
      NS_FATAL_ERROR ("Error in creation of WifiMode named " << uniqueName << std::endl
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   162
                      << "Code rate must be WIFI_CODE_RATE_UNDEFINED iff Modulation Class is WIFI_MOD_CLASS_DSSS");
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   163
    }
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   164
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   165
  item->constellationSize = constellationSize;
4470
51b5c1a272d3 802.11b PHY support
Gary Pei <guangyu.pei@boeing.com>
parents: 4331
diff changeset
   166
  item->isMandatory = isMandatory;
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   167
4470
51b5c1a272d3 802.11b PHY support
Gary Pei <guangyu.pei@boeing.com>
parents: 4331
diff changeset
   168
  return WifiMode (uid);
51b5c1a272d3 802.11b PHY support
Gary Pei <guangyu.pei@boeing.com>
parents: 4331
diff changeset
   169
}
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   170
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   171
WifiMode
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   172
WifiModeFactory::Search (std::string name)
4470
51b5c1a272d3 802.11b PHY support
Gary Pei <guangyu.pei@boeing.com>
parents: 4331
diff changeset
   173
{
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   174
  WifiModeItemList::const_iterator i;
4713
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   175
  uint32_t j = 0;
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   176
  for (i = m_itemList.begin (); i != m_itemList.end (); i++)
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   177
    {
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   178
      if (i->uniqueUid == name)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   179
	{
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   180
          return WifiMode (j);
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   181
	}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   182
      j++;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   183
    }
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   184
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   185
  // If we get here then a matching WifiMode was not found above. This
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   186
  // is a fatal problem, but we try to be helpful by displaying the
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   187
  // list of WifiModes that are supported.
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   188
  NS_LOG_UNCOND ("Could not find match for WifiMode named \""
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   189
                  << name << "\". Valid options are:");
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   190
  for (i = m_itemList.begin (); i != m_itemList.end (); i++)
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   191
    {
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   192
      NS_LOG_UNCOND ("  " << i->uniqueUid);
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   193
    }
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   194
  // Empty fatal error to die. We've already unconditionally logged
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   195
  // the helpful information.
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   196
  NS_FATAL_ERROR ("");
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   197
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   198
  // This next line is unreachable because of the fatal error
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   199
  // immediately above, and that is fortunate, because we have no idea
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   200
  // what is in WifiMode (0), but we do know it is not what our caller
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   201
  // has requested by name. It's here only because it's the safest
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   202
  // thing that'll give valid code.
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   203
  return WifiMode (0);
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   204
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   205
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
uint32_t
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
WifiModeFactory::AllocateUid (std::string uniqueUid)
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
{
4713
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   209
  uint32_t j = 0;
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
  for (WifiModeItemList::const_iterator i = m_itemList.begin ();
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
       i != m_itemList.end (); i++)
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
    {
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
      if (i->uniqueUid == uniqueUid)
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
	{
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
	  return j;
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
	}
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
      j++;
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
    }
4713
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   219
  uint32_t uid = m_itemList.size ();
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   220
  m_itemList.push_back (WifiModeItem ());
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
  return uid;
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
}
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
1887
14b4e0b7870a add missing implementations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1885
diff changeset
   224
struct WifiModeFactory::WifiModeItem *
14b4e0b7870a add missing implementations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1885
diff changeset
   225
WifiModeFactory::Get (uint32_t uid)
14b4e0b7870a add missing implementations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1885
diff changeset
   226
{
4713
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   227
  NS_ASSERT (uid < m_itemList.size ());
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   228
  return &m_itemList[uid];
1887
14b4e0b7870a add missing implementations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1885
diff changeset
   229
}
14b4e0b7870a add missing implementations
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1885
diff changeset
   230
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231
WifiModeFactory *
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   232
WifiModeFactory::GetFactory (void)
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   233
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   234
  static bool isFirstTime = true;
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   235
  static WifiModeFactory factory;
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   236
  if (isFirstTime)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   237
    {
4713
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   238
      uint32_t uid = factory.AllocateUid ("Invalid-WifiMode");
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   239
      WifiModeItem *item = factory.Get (uid);
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   240
      item->uniqueUid = "Invalid-WifiMode";
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   241
      item->bandwidth = 0;
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   242
      item->dataRate = 0;
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   243
      item->phyRate = 0;
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   244
      item->modClass = WIFI_MOD_CLASS_UNKNOWN;
4713
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   245
      item->constellationSize = 0;
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 5901
diff changeset
   246
      item->codingRate = WIFI_CODE_RATE_UNDEFINED;
4713
3fdb8f60a863 bug 654: avoid segfault with ConfigStore loading
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4681
diff changeset
   247
      item->isMandatory = false;
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   248
      isFirstTime = false;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2034
diff changeset
   249
    }
1885
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
  return &factory;
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   251
}
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
9ccfbfb25477 get a few more files to compile
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
} // namespace ns3