wifi: (fixes #2420) Remove code duplication between Wifi and Wave modules

This commit is contained in:
Sébastien Deronne
2016-06-10 21:45:45 +02:00
parent 5caef0cd19
commit 5b4d08da67
4 changed files with 55 additions and 396 deletions

View File

@@ -64,6 +64,7 @@ Bugs fixed
- Bug 2406 - Poor 802.11g performance in ad-hoc mode
- Bug 2414 - UdpSocket doesn't call NotifyConnectionFailed
- Bug 2419 - BsmApplication should use RecvFrom and not SocketAddressTag
- Bug 2420 - Remove code duplication between Wifi and Wave modules
- Bug 2425 - UdpSocketImpl simplification
- Bug 2427 - 802.11ac selects wrong slot duration
- Bug 2433 - Bic does not copy private parameters

View File

@@ -86,394 +86,6 @@ AsciiPhyReceiveSinkWithoutContext (
*stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
}
static void
PcapSniffTxEvent (
Ptr<PcapFileWrapper> file,
Ptr<const Packet> packet,
uint16_t channelFreqMhz,
uint16_t channelNumber,
uint32_t rate,
WifiPreamble preamble,
WifiTxVector txVector,
struct mpduInfo aMpdu)
{
uint32_t dlt = file->GetDataLinkType ();
switch (dlt)
{
case PcapHelper::DLT_IEEE802_11:
file->Write (Simulator::Now (), packet);
return;
case PcapHelper::DLT_PRISM_HEADER:
{
NS_FATAL_ERROR ("PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
return;
}
case PcapHelper::DLT_IEEE802_11_RADIO:
{
Ptr<Packet> p = packet->Copy ();
RadiotapHeader header;
uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
header.SetTsft (Simulator::Now ().GetMicroSeconds ());
//Our capture includes the FCS, so we set the flag to say so.
frameFlags |= RadiotapHeader::FRAME_FLAG_FCS_INCLUDED;
if (preamble == WIFI_PREAMBLE_SHORT)
{
frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_PREAMBLE;
}
if (txVector.IsShortGuardInterval ())
{
frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_GUARD;
}
header.SetFrameFlags (frameFlags);
header.SetRate (rate);
uint16_t channelFlags = 0;
switch (rate)
{
case 2: //1Mbps
case 4: //2Mbps
case 10: //5Mbps
case 22: //11Mbps
channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
break;
default:
channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
break;
}
if (channelFreqMhz < 2500)
{
channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ;
}
else
{
channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ;
}
header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
{
uint8_t mcsRate = 0;
uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
mcsKnown |= RadiotapHeader::MCS_KNOWN_INDEX;
mcsRate = rate - 128;
mcsKnown |= RadiotapHeader::MCS_KNOWN_BANDWIDTH;
if (txVector.GetChannelWidth () == 40)
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_BANDWIDTH_40;
}
mcsKnown |= RadiotapHeader::MCS_KNOWN_GUARD_INTERVAL;
if (txVector.IsShortGuardInterval ())
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_GUARD_INTERVAL;
}
mcsKnown |= RadiotapHeader::MCS_KNOWN_HT_FORMAT;
if (preamble == WIFI_PREAMBLE_HT_GF)
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_HT_GREENFIELD;
}
mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
if (txVector.GetNess () & 0x01) //bit 1
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_NESS_BIT_0;
}
if (txVector.GetNess () & 0x02) //bit 2
{
mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS_BIT_1;
}
mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
if (txVector.IsStbc ())
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_STBC_STREAMS;
}
header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
}
if (txVector.IsAggregation ())
{
uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
/* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
AmpduSubframeHeader hdr;
uint32_t extractedLength;
p->RemoveHeader (hdr);
extractedLength = hdr.GetLength ();
p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
{
ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
}
header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
}
if (preamble == WIFI_PREAMBLE_VHT)
{
uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
uint8_t vhtBandwidth = 0;
uint8_t vhtMcsNss[4] = {0,0,0,0};
uint8_t vhtCoding = 0;
uint8_t vhtGroupId = 0;
uint16_t vhtPartialAid = 0;
vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
if (txVector.IsStbc ())
{
vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
}
vhtKnown |= RadiotapHeader::VHT_KNOWN_GUARD_INTERVAL;
if (txVector.IsShortGuardInterval ())
{
vhtFlags |= RadiotapHeader::VHT_FLAGS_GUARD_INTERVAL;
}
vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
vhtKnown |= RadiotapHeader::VHT_KNOWN_BANDWIDTH;
//not all bandwidth values are currently supported
if (txVector.GetChannelWidth () == 40)
{
vhtBandwidth = 1;
}
else if (txVector.GetChannelWidth () == 80)
{
vhtBandwidth = 4;
}
else if (txVector.GetChannelWidth () == 160)
{
vhtBandwidth = 11;
}
//only SU PPDUs are currently supported
vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
}
p->AddHeader (header);
file->Write (Simulator::Now (), p);
return;
}
default:
NS_ABORT_MSG ("PcapSniffTxEvent(): Unexpected data link type " << dlt);
}
}
static void
PcapSniffRxEvent (
Ptr<PcapFileWrapper> file,
Ptr<const Packet> packet,
uint16_t channelFreqMhz,
uint16_t channelNumber,
uint32_t rate,
WifiPreamble preamble,
WifiTxVector txVector,
struct mpduInfo aMpdu,
struct signalNoiseDbm signalNoise)
{
uint32_t dlt = file->GetDataLinkType ();
switch (dlt)
{
case PcapHelper::DLT_IEEE802_11:
file->Write (Simulator::Now (), packet);
return;
case PcapHelper::DLT_PRISM_HEADER:
{
NS_FATAL_ERROR ("PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
return;
}
case PcapHelper::DLT_IEEE802_11_RADIO:
{
Ptr<Packet> p = packet->Copy ();
RadiotapHeader header;
uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
header.SetTsft (Simulator::Now ().GetMicroSeconds ());
//Our capture includes the FCS, so we set the flag to say so.
frameFlags |= RadiotapHeader::FRAME_FLAG_FCS_INCLUDED;
if (preamble == WIFI_PREAMBLE_SHORT)
{
frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_PREAMBLE;
}
if (txVector.IsShortGuardInterval ())
{
frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_GUARD;
}
header.SetFrameFlags (frameFlags);
header.SetRate (rate);
uint16_t channelFlags = 0;
switch (rate)
{
case 2: //1Mbps
case 4: //2Mbps
case 10: //5Mbps
case 22: //11Mbps
channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
break;
default:
channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
break;
}
if (channelFreqMhz < 2500)
{
channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ;
}
else
{
channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ;
}
header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
header.SetAntennaSignalPower (signalNoise.signal);
header.SetAntennaNoisePower (signalNoise.noise);
if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
{
uint8_t mcsRate = 0;
uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
mcsKnown |= RadiotapHeader::MCS_KNOWN_INDEX;
mcsRate = rate - 128;
mcsKnown |= RadiotapHeader::MCS_KNOWN_BANDWIDTH;
if (txVector.GetChannelWidth () == 40)
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_BANDWIDTH_40;
}
mcsKnown |= RadiotapHeader::MCS_KNOWN_GUARD_INTERVAL;
if (txVector.IsShortGuardInterval ())
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_GUARD_INTERVAL;
}
mcsKnown |= RadiotapHeader::MCS_KNOWN_HT_FORMAT;
if (preamble == WIFI_PREAMBLE_HT_GF)
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_HT_GREENFIELD;
}
mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
if (txVector.GetNess () & 0x01) //bit 1
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_NESS_BIT_0;
}
if (txVector.GetNess () & 0x02) //bit 2
{
mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS_BIT_1;
}
mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
if (txVector.IsStbc ())
{
mcsFlags |= RadiotapHeader::MCS_FLAGS_STBC_STREAMS;
}
header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
}
if (txVector.IsAggregation ())
{
uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_DELIMITER_CRC_KNOWN;
ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
/* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
AmpduSubframeHeader hdr;
uint32_t extractedLength;
p->RemoveHeader (hdr);
extractedLength = hdr.GetLength ();
p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
{
ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
}
header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
}
if (preamble == WIFI_PREAMBLE_VHT)
{
uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
uint8_t vhtBandwidth = 0;
uint8_t vhtMcsNss[4] = {0,0,0,0};
uint8_t vhtCoding = 0;
uint8_t vhtGroupId = 0;
uint16_t vhtPartialAid = 0;
vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
if (txVector.IsStbc ())
{
vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
}
vhtKnown |= RadiotapHeader::VHT_KNOWN_GUARD_INTERVAL;
if (txVector.IsShortGuardInterval ())
{
vhtFlags |= RadiotapHeader::VHT_FLAGS_GUARD_INTERVAL;
}
vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
vhtKnown |= RadiotapHeader::VHT_KNOWN_BANDWIDTH;
//not all bandwidth values are currently supported
if (txVector.GetChannelWidth () == 40)
{
vhtBandwidth = 1;
}
else if (txVector.GetChannelWidth () == 80)
{
vhtBandwidth = 4;
}
else if (txVector.GetChannelWidth () == 160)
{
vhtBandwidth = 11;
}
//only SU PPDUs are currently supported
vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
}
p->AddHeader (header);
file->Write (Simulator::Now (), p);
return;
}
default:
NS_ABORT_MSG ("PcapSniffRxEvent(): Unexpected data link type " << dlt);
}
}
/****************************** YansWavePhyHelper ***********************************/
YansWavePhyHelper
@@ -520,8 +132,8 @@ YansWavePhyHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bo
for (i = phys.begin (); i != phys.end (); ++i)
{
Ptr<WifiPhy> phy = (*i);
phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&PcapSniffTxEvent, file));
phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&PcapSniffRxEvent, file));
phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&YansWavePhyHelper::PcapSniffTxEvent, file));
phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&YansWavePhyHelper::PcapSniffRxEvent, file));
}
}

View File

@@ -248,8 +248,8 @@ YansWifiPhyHelper::Create (Ptr<Node> node, Ptr<NetDevice> device) const
return phy;
}
static void
PcapSniffTxEvent (
void
YansWifiPhyHelper::PcapSniffTxEvent (
Ptr<PcapFileWrapper> file,
Ptr<const Packet> packet,
uint16_t channelFreqMhz,
@@ -440,8 +440,8 @@ PcapSniffTxEvent (
}
}
static void
PcapSniffRxEvent (
void
YansWifiPhyHelper::PcapSniffRxEvent (
Ptr<PcapFileWrapper> file,
Ptr<const Packet> packet,
uint16_t channelFreqMhz,
@@ -692,8 +692,8 @@ YansWifiPhyHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bo
Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&PcapSniffTxEvent, file));
phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&PcapSniffRxEvent, file));
phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&YansWifiPhyHelper::PcapSniffTxEvent, file));
phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&YansWifiPhyHelper::PcapSniffRxEvent, file));
}
void

View File

@@ -255,6 +255,52 @@ public:
*/
uint32_t GetPcapDataLinkType (void) const;
protected:
/**
* \param file the pcap file wrapper
* \param packet the packet
* \param channelFreqMhz the channel frequency
* \param channelNumber the channel number
* \param rate the PHY bitrate
* \param preamble the preamble type
* \param txVector the TXVECTOR
* \param aMpdu the A-MPDU information
*
* Handle tx pcap.
*/
static void PcapSniffTxEvent (Ptr<PcapFileWrapper> file,
Ptr<const Packet> packet,
uint16_t channelFreqMhz,
uint16_t channelNumber,
uint32_t rate,
WifiPreamble preamble,
WifiTxVector txVector,
struct mpduInfo aMpdu);
/**
* \param file the pcap file wrapper
* \param packet the packet
* \param channelFreqMhz the channel frequency
* \param channelNumber the channel number
* \param rate the PHY bitrate
* \param preamble the preamble type
* \param txVector the TXVECTOR
* \param aMpdu the A-MPDU information
* \param signalNoise the rx signal and noise information
*
* Handle rx pcap.
*/
static void PcapSniffRxEvent (Ptr<PcapFileWrapper> file,
Ptr<const Packet> packet,
uint16_t channelFreqMhz,
uint16_t channelNumber,
uint32_t rate,
WifiPreamble preamble,
WifiTxVector txVector,
struct mpduInfo aMpdu,
struct signalNoiseDbm signalNoise);
private:
/**
* \param node the node on which we wish to create a wifi PHY