|
|
| 28 |
#include "ns3/assert.h" |
28 |
#include "ns3/assert.h" |
| 29 |
#include "ns3/log.h" |
29 |
#include "ns3/log.h" |
| 30 |
#include "ns3/double.h" |
30 |
#include "ns3/double.h" |
|
|
31 |
#include "ns3/pointer.h" |
| 32 |
#include "ns3/trace-source-accessor.h" |
| 31 |
#include "ampdu-tag.h" |
33 |
#include "ampdu-tag.h" |
| 32 |
#include <cmath> |
34 |
#include <cmath> |
|
|
35 |
#include <fstream> |
| 36 |
|
| 33 |
|
37 |
|
| 34 |
namespace ns3 { |
38 |
namespace ns3 { |
| 35 |
|
39 |
|
|
|
| 44 |
.SetParent<WifiPhy> () |
48 |
.SetParent<WifiPhy> () |
| 45 |
.SetGroupName ("Wifi") |
49 |
.SetGroupName ("Wifi") |
| 46 |
.AddConstructor<YansWifiPhy> () |
50 |
.AddConstructor<YansWifiPhy> () |
|
|
51 |
.AddTraceSource ("MonitorSnifferTxwDuration", |
| 52 |
"Trace source simulating the capability of a wifi device " |
| 53 |
"in monitor mode to sniff all frames being transmitted", |
| 54 |
MakeTraceSourceAccessor (&YansWifiPhy::m_phyMonitorSniffTxTracewDuration), |
| 55 |
"ns3::YansWifiPhy::MonitorSnifferTxTracedCallbackwDuration") |
| 56 |
.AddTraceSource ("MonitorSnifferRxwDuration", |
| 57 |
"Trace source simulating the capability of a wifi device " |
| 58 |
"in monitor mode to sniff all frames being transmitted", |
| 59 |
MakeTraceSourceAccessor (&YansWifiPhy::m_phyMonitorSniffRxTracewDuration), |
| 60 |
"ns3::YansWifiPhy::MonitorSnifferRxTracedCallbackwDuration") |
| 47 |
; |
61 |
; |
| 48 |
return tid; |
62 |
return tid; |
| 49 |
} |
63 |
} |
| 50 |
|
64 |
|
| 51 |
YansWifiPhy::YansWifiPhy () |
65 |
YansWifiPhy::YansWifiPhy () |
| 52 |
{ |
66 |
{ |
|
|
67 |
std::cout << "YansWifiPhy" << std::endl; |
| 53 |
NS_LOG_FUNCTION (this); |
68 |
NS_LOG_FUNCTION (this); |
|
|
69 |
m_firstWrite = true; |
| 54 |
} |
70 |
} |
| 55 |
|
71 |
|
| 56 |
YansWifiPhy::~YansWifiPhy () |
72 |
YansWifiPhy::~YansWifiPhy () |
|
|
| 508 |
aMpdu.type = mpdutype; |
524 |
aMpdu.type = mpdutype; |
| 509 |
aMpdu.mpduRefNumber = m_txMpduReferenceNumber; |
525 |
aMpdu.mpduRefNumber = m_txMpduReferenceNumber; |
| 510 |
NotifyMonitorSniffTx (packet, (uint16_t)GetFrequency (), GetChannelNumber (), dataRate500KbpsUnits, preamble, txVector, aMpdu); |
526 |
NotifyMonitorSniffTx (packet, (uint16_t)GetFrequency (), GetChannelNumber (), dataRate500KbpsUnits, preamble, txVector, aMpdu); |
|
|
527 |
NotifyMonitorSniffTxwDuration (packet, this->GetDevice()->GetNode()->GetId(), GetChannelNumber (), dataRate500KbpsUnits, preamble, txVector, aMpdu, txDuration); |
| 511 |
m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector, preamble); |
528 |
m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector, preamble); |
| 512 |
m_channel->Send (this, packet, GetPowerDbm (txVector.GetTxPowerLevel ()) + GetTxGain (), txVector, preamble, mpdutype, txDuration); |
529 |
m_channel->Send (this, packet, GetPowerDbm (txVector.GetTxPowerLevel ()) + GetTxGain (), txVector, preamble, mpdutype, txDuration); |
| 513 |
} |
530 |
} |
|
|
| 531 |
NS_ASSERT (IsStateRx ()); |
548 |
NS_ASSERT (IsStateRx ()); |
| 532 |
NS_ASSERT (event->GetEndTime () == Simulator::Now ()); |
549 |
NS_ASSERT (event->GetEndTime () == Simulator::Now ()); |
| 533 |
|
550 |
|
|
|
551 |
std::ofstream RssiThroughputTraceFile; |
| 552 |
|
| 534 |
struct InterferenceHelper::SnrPer snrPer; |
553 |
struct InterferenceHelper::SnrPer snrPer; |
| 535 |
snrPer = m_interference.CalculatePlcpPayloadSnrPer (event); |
554 |
snrPer = m_interference.CalculatePlcpPayloadSnrPer (event); |
| 536 |
m_interference.NotifyRxEnd (); |
555 |
m_interference.NotifyRxEnd (); |
|
|
| 555 |
struct signalNoiseDbm signalNoise; |
574 |
struct signalNoiseDbm signalNoise; |
| 556 |
signalNoise.signal = RatioToDb (event->GetRxPowerW ()) + 30; |
575 |
signalNoise.signal = RatioToDb (event->GetRxPowerW ()) + 30; |
| 557 |
signalNoise.noise = RatioToDb (event->GetRxPowerW () / snrPer.snr) - GetRxNoiseFigure () + 30; |
576 |
signalNoise.noise = RatioToDb (event->GetRxPowerW () / snrPer.snr) - GetRxNoiseFigure () + 30; |
|
|
577 |
NS_LOG_DEBUG ("linear rxpower=" << event->GetRxPowerW() << " linear noise " << event->GetRxPowerW () / snrPer.snr); |
| 578 |
NS_LOG_DEBUG ("db rxpower=" << signalNoise.signal << " db noise " << signalNoise.noise); |
| 579 |
if (preamble >= 4) { |
| 580 |
std::string filename = "RssiVsThroughputminstrelap3sta2.txt"; |
| 581 |
if (m_firstWrite == true) |
| 582 |
{ |
| 583 |
RssiThroughputTraceFile.open (filename.c_str()); |
| 584 |
if (!RssiThroughputTraceFile.is_open ()) |
| 585 |
{ |
| 586 |
NS_LOG_ERROR ("Can't open file " << filename.c_str ()); |
| 587 |
return; |
| 588 |
} |
| 589 |
m_firstWrite = false; |
| 590 |
RssiThroughputTraceFile.close (); |
| 591 |
} |
| 592 |
else { |
| 593 |
RssiThroughputTraceFile.open (filename.c_str (), std::ios_base::app); |
| 594 |
if (!RssiThroughputTraceFile.is_open ()) |
| 595 |
{ |
| 596 |
NS_LOG_ERROR ("Can't open file " << filename.c_str ()); |
| 597 |
return; |
| 598 |
} |
| 599 |
RssiThroughputTraceFile<< signalNoise.signal << " " << (event->GetPayloadMode ().GetDataRate (event->GetTxVector ())) << std::endl; |
| 600 |
} |
| 601 |
// std::cout << signalNoise.signal << " " << (event->GetPayloadMode ().GetDataRate (event->GetTxVector ())) << std::endl; |
| 602 |
RssiThroughputTraceFile.close (); |
| 603 |
} |
| 558 |
struct mpduInfo aMpdu; |
604 |
struct mpduInfo aMpdu; |
| 559 |
aMpdu.type = mpdutype; |
605 |
aMpdu.type = mpdutype; |
| 560 |
aMpdu.mpduRefNumber = m_rxMpduReferenceNumber; |
606 |
aMpdu.mpduRefNumber = m_rxMpduReferenceNumber; |
| 561 |
NotifyMonitorSniffRx (packet, (uint16_t)GetFrequency (), GetChannelNumber (), dataRate500KbpsUnits, event->GetPreambleType (), event->GetTxVector (), aMpdu, signalNoise); |
607 |
NotifyMonitorSniffRx (packet, (uint16_t)GetFrequency (), GetChannelNumber (), dataRate500KbpsUnits, event->GetPreambleType (), event->GetTxVector (), aMpdu, signalNoise); |
|
|
608 |
Time txDuration = CalculateTxDuration (packet->GetSize (), event->GetTxVector (), preamble, GetFrequency (), mpdutype, 1); |
| 609 |
NS_ASSERT (txDuration > NanoSeconds (0)); |
| 610 |
NotifyMonitorSniffRxwDuration (packet, this->GetDevice()->GetNode()->GetId(), GetChannelNumber (), dataRate500KbpsUnits, preamble, event->GetTxVector (), aMpdu, txDuration); |
| 562 |
m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (), event->GetPreambleType ()); |
611 |
m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (), event->GetPreambleType ()); |
| 563 |
} |
612 |
} |
| 564 |
else |
613 |
else |
|
|
| 579 |
} |
628 |
} |
| 580 |
} |
629 |
} |
| 581 |
|
630 |
|
|
|
631 |
void |
| 632 |
YansWifiPhy::NotifyMonitorSniffTxwDuration (Ptr<const Packet> packet, uint32_t id, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu, Time txDuration) |
| 633 |
{ |
| 634 |
m_phyMonitorSniffTxTracewDuration (packet, id, channelNumber, rate, preamble, txVector, aMpdu, txDuration); |
| 635 |
} |
| 636 |
|
| 637 |
void |
| 638 |
YansWifiPhy::NotifyMonitorSniffRxwDuration (Ptr<const Packet> packet, uint32_t id, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu, Time txDuration) |
| 639 |
{ |
| 640 |
m_phyMonitorSniffRxTracewDuration (packet, id, channelNumber, rate, preamble, txVector, aMpdu, txDuration); |
| 641 |
} |
| 642 |
|
| 643 |
|
| 582 |
} //namespace ns3 |
644 |
} //namespace ns3 |