00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "wifi-phy.h"
00022 #include "wifi-mode.h"
00023 #include "wifi-channel.h"
00024 #include "wifi-preamble.h"
00025 #include "ns3/simulator.h"
00026 #include "ns3/packet.h"
00027 #include "ns3/random-variable.h"
00028 #include "ns3/assert.h"
00029 #include "ns3/log.h"
00030 #include "ns3/double.h"
00031 #include "ns3/integer.h"
00032 #include "ns3/uinteger.h"
00033 #include "ns3/enum.h"
00034 #include "ns3/trace-source-accessor.h"
00035 #include <math.h>
00036
00037 NS_LOG_COMPONENT_DEFINE ("WifiPhy");
00038
00039 namespace ns3 {
00040
00041
00042
00043
00044
00045 WifiPhyListener::~WifiPhyListener ()
00046 {}
00047
00048
00049
00050
00051
00052 WifiPhyTxTag::WifiPhyTxTag ()
00053 {}
00054 WifiPhyTxTag::WifiPhyTxTag (WifiPreamble wifiPreamble, WifiMode wifiMode, uint8_t powerId, double powerDbm, Time duration)
00055 : m_wifiPreamble(wifiPreamble),
00056 m_wifiMode(wifiMode),
00057 m_powerId(powerId),
00058 m_powerDbm(powerDbm),
00059 m_duration(duration)
00060 {
00061 }
00062 WifiPreamble
00063 WifiPhyTxTag::GetWifiPreamble () const
00064 {
00065 return m_wifiPreamble;
00066 }
00067 WifiMode
00068 WifiPhyTxTag::GetWifiMode () const
00069 {
00070 return m_wifiMode;
00071 }
00072 uint8_t
00073 WifiPhyTxTag::GetPowerId () const
00074 {
00075 return m_powerId;
00076 }
00077 double
00078 WifiPhyTxTag::GetPowerDbm () const
00079 {
00080 return m_powerDbm;
00081 }
00082 Time
00083 WifiPhyTxTag::GetDuration () const
00084 {
00085 return m_duration;
00086 }
00087 TypeId
00088 WifiPhyTxTag::GetTypeId ()
00089 {
00090 static TypeId tid = TypeId ("ns3::WifiPhyTxTag")
00091 .SetParent<Tag> ()
00092 .AddConstructor<WifiPhyTxTag> ()
00093 .AddAttribute ("WifiPreamble",
00094 "Packet wifi preamble type used in transmission.",
00095 EmptyAttributeValue (),
00096 MakeIntegerAccessor (&WifiPhyTxTag::GetWifiPreamble),
00097 MakeIntegerChecker<int> ())
00098 .AddAttribute ("WifiMode",
00099 "Transmission mode of the packet.",
00100 EmptyAttributeValue (),
00101 MakeWifiModeAccessor (&WifiPhyTxTag::GetWifiMode),
00102 MakeWifiModeChecker ())
00103 .AddAttribute ("PowerId",
00104 "Transmission power level id of the packet.",
00105 EmptyAttributeValue (),
00106 MakeUintegerAccessor (&WifiPhyTxTag::GetPowerId),
00107 MakeUintegerChecker<uint8_t> ())
00108 .AddAttribute ("PowerDbm",
00109 "Transmission power level of the packet in dBm.",
00110 EmptyAttributeValue (),
00111 MakeDoubleAccessor (&WifiPhyTxTag::GetPowerDbm),
00112 MakeDoubleChecker<double> ())
00113 .AddAttribute ("Duration",
00114 "Transmission duration of the packet.",
00115 EmptyAttributeValue (),
00116 MakeTimeAccessor (&WifiPhyTxTag::GetDuration),
00117 MakeTimeChecker ())
00118 ;
00119 return tid;
00120 }
00121 TypeId
00122 WifiPhyTxTag::GetInstanceTypeId () const
00123 {
00124 return GetTypeId();
00125 }
00126 uint32_t
00127 WifiPhyTxTag::GetSerializedSize () const
00128 {
00129 return sizeof(m_wifiPreamble)
00130 + sizeof(m_wifiMode)
00131 + sizeof(m_powerId)
00132 + sizeof(m_powerDbm)
00133 + sizeof(m_duration);
00134 }
00135 void
00136 WifiPhyTxTag::Serialize (TagBuffer i) const
00137 {
00138 i.Write ((uint8_t *)&m_wifiPreamble, sizeof(m_wifiPreamble));
00139 i.Write ((uint8_t *)&m_wifiMode, sizeof(m_wifiMode));
00140 i.Write ((uint8_t *)&m_powerId, sizeof(m_powerId));
00141 i.Write ((uint8_t *)&m_powerDbm, sizeof(m_powerDbm));
00142 i.Write ((uint8_t *)&m_duration, sizeof(m_duration));
00143 }
00144 void
00145 WifiPhyTxTag::Deserialize (TagBuffer i)
00146 {
00147 i.Read ((uint8_t *)&m_wifiPreamble, sizeof(m_wifiPreamble));
00148 i.Read ((uint8_t *)&m_wifiMode, sizeof(m_wifiMode));
00149 i.Read ((uint8_t *)&m_powerId, sizeof(m_powerId));
00150 i.Read ((uint8_t *)&m_powerDbm, sizeof(m_powerDbm));
00151 i.Read ((uint8_t *)&m_duration, sizeof(m_duration));
00152 }
00153 void
00154 WifiPhyTxTag::Print (std::ostream &os) const
00155 {
00156 os << "wifiPreamble=" << m_wifiPreamble
00157 << ", wifiMode=" << m_wifiMode
00158 << ", powerId=" << m_powerId
00159 << ", powerDbm=" << m_powerDbm
00160 << ", duration=" << m_duration;
00161 }
00162
00163
00164
00165
00166
00167 WifiPhyRxTag::WifiPhyRxTag ()
00168 {}
00169 WifiPhyRxTag::WifiPhyRxTag (double powerDbm, double snr, double per)
00170 : m_powerDbm(powerDbm),
00171 m_snr(snr),
00172 m_per(per)
00173 {
00174 }
00175 double
00176 WifiPhyRxTag::GetPowerDbm () const
00177 {
00178 return m_powerDbm;
00179 }
00180 double
00181 WifiPhyRxTag::GetSnr () const
00182 {
00183 return m_snr;
00184 }
00185 double
00186 WifiPhyRxTag::GetPer () const
00187 {
00188 return m_per;
00189 }
00190 TypeId
00191 WifiPhyRxTag::GetTypeId ()
00192 {
00193 static TypeId tid = TypeId ("ns3::WifiPhyRxTag")
00194 .SetParent<Tag> ()
00195 .AddConstructor<WifiPhyRxTag> ()
00196 .AddAttribute ("PowerDbm",
00197 "Reception power of the packet in dBm.",
00198 EmptyAttributeValue (),
00199 MakeDoubleAccessor (&WifiPhyRxTag::GetPowerDbm),
00200 MakeDoubleChecker<double> ())
00201 .AddAttribute ("Snr",
00202 "Reception signal-to-noise-ratio (SNR) of the packet.",
00203 EmptyAttributeValue (),
00204 MakeDoubleAccessor (&WifiPhyRxTag::GetSnr),
00205 MakeDoubleChecker<double> ())
00206 .AddAttribute ("Per",
00207 "Reception packet-error-rate (PER) of the packet.",
00208 EmptyAttributeValue (),
00209 MakeDoubleAccessor (&WifiPhyRxTag::GetPer),
00210 MakeDoubleChecker<double> ())
00211 ;
00212 return tid;
00213 }
00214 TypeId
00215 WifiPhyRxTag::GetInstanceTypeId () const
00216 {
00217 return GetTypeId();
00218 }
00219 uint32_t
00220 WifiPhyRxTag::GetSerializedSize () const
00221 {
00222 return sizeof(m_powerDbm)
00223 + sizeof(m_snr)
00224 + sizeof(m_per);
00225 }
00226 void
00227 WifiPhyRxTag::Serialize (TagBuffer i) const
00228 {
00229 i.Write ((uint8_t *)&m_powerDbm, sizeof(m_powerDbm));
00230 i.Write ((uint8_t *)&m_snr, sizeof(m_snr));
00231 i.Write ((uint8_t *)&m_per, sizeof(m_per));
00232 }
00233 void
00234 WifiPhyRxTag::Deserialize (TagBuffer i)
00235 {
00236 i.Read ((uint8_t *)&m_powerDbm, sizeof(m_powerDbm));
00237 i.Read ((uint8_t *)&m_snr, sizeof(m_snr));
00238 i.Read ((uint8_t *)&m_per, sizeof(m_per));
00239 }
00240 void
00241 WifiPhyRxTag::Print (std::ostream &os) const
00242 {
00243 os << "powerDbm=" << m_powerDbm
00244 << ", snr=" << m_snr
00245 << ", per=" << m_per;
00246 }
00247
00248
00249
00250
00251
00252 NS_OBJECT_ENSURE_REGISTERED (WifiPhy);
00253
00254 TypeId
00255 WifiPhy::GetTypeId (void)
00256 {
00257 static TypeId tid = TypeId ("ns3::WifiPhy")
00258 .SetParent<Object> ()
00259 ;
00260 return tid;
00261 }
00262
00263 WifiPhy::WifiPhy ()
00264 {
00265 NS_LOG_FUNCTION (this);
00266 }
00267
00268 WifiPhy::~WifiPhy ()
00269 {
00270 NS_LOG_FUNCTION (this);
00271 }
00272
00273 WifiMode
00274 WifiPhy::Get6mba (void)
00275 {
00276 static WifiMode mode = WifiModeFactory::CreateBpsk ("wifia-6mbs",
00277 true,
00278 20000000, 6000000, 12000000);
00279 return mode;
00280 }
00281 WifiMode
00282 WifiPhy::Get9mba (void)
00283 {
00284 static WifiMode mode = WifiModeFactory::CreateBpsk ("wifia-9mbs",
00285 false,
00286 20000000, 9000000, 12000000);
00287 return mode;
00288 }
00289 WifiMode
00290 WifiPhy::Get12mba (void)
00291 {
00292 static WifiMode mode = WifiModeFactory::CreateBpsk ("wifia-12mbs",
00293 true,
00294 20000000, 12000000, 24000000);
00295 return mode;
00296 }
00297 WifiMode
00298 WifiPhy::Get18mba (void)
00299 {
00300 static WifiMode mode = WifiModeFactory::CreateBpsk ("wifia-18mbs",
00301 false,
00302 20000000, 18000000, 24000000);
00303 return mode;
00304 }
00305 WifiMode
00306 WifiPhy::Get24mba (void)
00307 {
00308 static WifiMode mode = WifiModeFactory::CreateBpsk ("wifia-24mbs",
00309 true,
00310 20000000, 24000000, 48000000);
00311 return mode;
00312 }
00313 WifiMode
00314 WifiPhy::Get36mba (void)
00315 {
00316 static WifiMode mode = WifiModeFactory::CreateBpsk ("wifia-36mbs",
00317 false,
00318 20000000, 36000000, 48000000);
00319 return mode;
00320 }
00321
00322 WifiMode
00323 WifiPhy::Get48mba (void)
00324 {
00325 static WifiMode mode = WifiModeFactory::CreateBpsk ("wifia-48mbs",
00326 false,
00327 20000000, 48000000, 72000000);
00328 return mode;
00329 }
00330
00331 WifiMode
00332 WifiPhy::Get54mba (void)
00333 {
00334 static WifiMode mode = WifiModeFactory::CreateBpsk ("wifia-54mbs",
00335 false,
00336 20000000, 54000000, 72000000);
00337 return mode;
00338 }
00339
00340 const char*
00341 WifiPhy::StateToString (enum State state)
00342 {
00343 switch (state) {
00344 case IDLE:
00345 return "IDLE";
00346 case CCA_BUSY:
00347 return "CCA_BUSY";
00348 case SYNCING:
00349 return "SYNCING";
00350 case RX:
00351 return "RX";
00352 case TX:
00353 return "TX";
00354 default:
00355 NS_ASSERT (false);
00356 }
00357 return "INVALID";
00358 }
00359
00360 const char*
00361 WifiPhy::RxErrorReasonToString (enum RxErrorReason rxErrorReason)
00362 {
00363 switch(rxErrorReason)
00364 {
00365 case RXERROR_BAD_SIGNAL:
00366 return "RXERROR_BAD_SIGNAL";
00367 case RXERROR_ALREADY_RXING:
00368 return "RXERROR_ALREADY_RXING";
00369 case RXERROR_IN_TX:
00370 return "RXERROR_IN_TX";
00371 case RXERROR_LOW_SIGNAL:
00372 return "RXERROR_LOW_SIGNAL";
00373 default:
00374 NS_ASSERT (false);
00375 }
00376 return "INVALID";
00377 }
00378
00379 }
00380
00381 namespace {
00382
00383 static class Constructor
00384 {
00385 public:
00386 Constructor () {
00387 ns3::WifiPhy::Get6mba ();
00388 ns3::WifiPhy::Get9mba ();
00389 ns3::WifiPhy::Get12mba ();
00390 ns3::WifiPhy::Get18mba ();
00391 ns3::WifiPhy::Get24mba ();
00392 ns3::WifiPhy::Get36mba ();
00393 ns3::WifiPhy::Get48mba ();
00394 ns3::WifiPhy::Get54mba ();
00395 }
00396 } g_constructor;
00397 }