diff --git a/src/devices/wifi/mac-parameters.cc b/src/devices/wifi/mac-parameters.cc index 911929822..6e47e4d25 100644 --- a/src/devices/wifi/mac-parameters.cc +++ b/src/devices/wifi/mac-parameters.cc @@ -24,6 +24,7 @@ #include "mac-parameters.h" #include "wifi-phy.h" #include "wifi-mac-header.h" +#include "wifi-preamble.h" namespace ns3 { @@ -50,13 +51,13 @@ MacParameters::Initialize80211a (WifiPhy const*phy) WifiMacHeader hdr; hdr.SetType (WIFI_MAC_CTL_CTS); m_ctsTimeout = m_sifs; - m_ctsTimeout += phy->CalculateTxDuration (hdr.GetSize (), phy->GetMode (0), phy->GetMode (0)); + m_ctsTimeout += phy->CalculateTxDuration (hdr.GetSize (), phy->GetMode (0), WIFI_PREAMBLE_LONG); m_ctsTimeout += m_maxPropagationDelay * Scalar (2); m_ctsTimeout += m_slot; hdr.SetType (WIFI_MAC_CTL_ACK); m_ackTimeout = m_sifs; - m_ackTimeout += phy->CalculateTxDuration (hdr.GetSize (), phy->GetMode (0), phy->GetMode (0)); + m_ackTimeout += phy->CalculateTxDuration (hdr.GetSize (), phy->GetMode (0), WIFI_PREAMBLE_LONG); m_ackTimeout += m_maxPropagationDelay * Scalar (2); m_ackTimeout += m_slot; } diff --git a/src/devices/wifi/wifi-channel.cc b/src/devices/wifi/wifi-channel.cc index 078dfd4b1..e6b7ac41f 100644 --- a/src/devices/wifi/wifi-channel.cc +++ b/src/devices/wifi/wifi-channel.cc @@ -30,11 +30,11 @@ namespace ns3 { WifiChannel::ReceiveData::ReceiveData (const Packet &packet, double rxPowerDbm, - WifiMode txMode, WifiMode headerMode) + WifiMode txMode, WifiPreamble preamble) : m_packet (packet), m_rxPowerDbm (rxPowerDbm), m_wifiMode (txMode), - m_headerMode (headerMode) + m_preamble (preamble) {} @@ -61,7 +61,7 @@ WifiChannel::Add (Ptr device, ReceiveCallback callback) } void WifiChannel::Send (Ptr sender, const Packet &packet, double txPowerDbm, - WifiMode wifiMode, WifiMode headerMode) const + WifiMode wifiMode, WifiPreamble preamble) const { Ptr senderMobility = sender->GetNode ()->QueryInterface (MobilityModel::iid); uint32_t j = 0; @@ -73,7 +73,7 @@ WifiChannel::Send (Ptr sender, const Packet &packet, double txPowerDb double distance = senderMobility->GetDistanceFrom (receiverMobility); Time delay = m_delay->GetDelay (distance); double rxPowerDbm = m_loss->GetRxPower (txPowerDbm, distance); - struct ReceiveData data = ReceiveData (packet, rxPowerDbm, wifiMode, headerMode); + struct ReceiveData data = ReceiveData (packet, rxPowerDbm, wifiMode, preamble); Simulator::Schedule (delay, &WifiChannel::Receive, this, j, data); } @@ -85,7 +85,7 @@ void WifiChannel::Receive (uint32_t i, const struct ReceiveData &data) const { - m_deviceList[i].second (data.m_packet, data.m_rxPowerDbm, data.m_wifiMode, data.m_headerMode); + m_deviceList[i].second (data.m_packet, data.m_rxPowerDbm, data.m_wifiMode, data.m_preamble); } uint32_t diff --git a/src/devices/wifi/wifi-channel.h b/src/devices/wifi/wifi-channel.h index 2a3aef1d9..7b101dff5 100644 --- a/src/devices/wifi/wifi-channel.h +++ b/src/devices/wifi/wifi-channel.h @@ -25,6 +25,7 @@ #include "ns3/packet.h" #include "ns3/channel.h" #include "wifi-mode.h" +#include "wifi-preamble.h" namespace ns3 { @@ -35,7 +36,7 @@ class PropagationDelayModel; class WifiChannel : public Channel { public: - typedef Callback ReceiveCallback; + typedef Callback ReceiveCallback; WifiChannel (); virtual ~WifiChannel (); @@ -47,17 +48,17 @@ public: void Add (Ptr device, ReceiveCallback callback); void Send (Ptr sender, const Packet &packet, double txPowerDbm, - WifiMode wifiMode, WifiMode headerMode) const; + WifiMode wifiMode, WifiPreamble preamble) const; private: typedef std::vector, ReceiveCallback> > DeviceList; struct ReceiveData { ReceiveData (const Packet &packet, double rxPowerDbm, - WifiMode txMode, WifiMode headerMode); + WifiMode txMode, WifiPreamble preamble); Packet m_packet; double m_rxPowerDbm; WifiMode m_wifiMode; - WifiMode m_headerMode; + WifiPreamble m_preamble; }; void Receive (uint32_t i, const struct ReceiveData &data) const; diff --git a/src/devices/wifi/wifi-mode.cc b/src/devices/wifi/wifi-mode.cc index ef4f5ce44..d1a5fb6a1 100644 --- a/src/devices/wifi/wifi-mode.cc +++ b/src/devices/wifi/wifi-mode.cc @@ -62,6 +62,7 @@ WifiMode::GetUid (void) const return m_uid; } WifiMode::WifiMode () + : m_uid (0) {} WifiMode::WifiMode (uint32_t uid) : m_uid (uid) diff --git a/src/devices/wifi/wifi-mode.h b/src/devices/wifi/wifi-mode.h index 94ecd12dd..247c40273 100644 --- a/src/devices/wifi/wifi-mode.h +++ b/src/devices/wifi/wifi-mode.h @@ -63,9 +63,11 @@ class WifiMode * should have different uids. */ uint32_t GetUid (void) const; + + // create an invalid WifiMode. + WifiMode (); private: friend class WifiModeFactory; - WifiMode (); WifiMode (uint32_t uid); uint32_t m_uid; }; diff --git a/src/devices/wifi/wifi-phy.cc b/src/devices/wifi/wifi-phy.cc index 401163dc0..9466b1dff 100644 --- a/src/devices/wifi/wifi-phy.cc +++ b/src/devices/wifi/wifi-phy.cc @@ -23,6 +23,7 @@ #include "wifi-mode.h" #include "wifi-channel.h" #include "wifi-net-device.h" +#include "wifi-preamble.h" #include "ns3/simulator.h" #include "ns3/packet.h" #include "ns3/random-variable.h" @@ -103,11 +104,11 @@ WifiPhyListener::~WifiPhyListener () class RxEvent { public: RxEvent (uint32_t size, WifiMode payloadMode, - WifiMode headerMode, + enum WifiPreamble preamble, Time duration, double rxPower) : m_size (size), m_payloadMode (payloadMode), - m_headerMode (headerMode), + m_preamble (preamble), m_startTime (Simulator::Now ()), m_endTime (m_startTime + duration), m_rxPowerW (rxPower), @@ -151,14 +152,14 @@ public: WifiMode GetPayloadMode (void) const { return m_payloadMode; } - WifiMode GetHeaderMode (void) const { - return m_headerMode; + enum WifiPreamble GetPreambleType (void) const { + return m_preamble; } private: uint32_t m_size; WifiMode m_payloadMode; - WifiMode m_headerMode; + enum WifiPreamble m_preamble; Time m_startTime; Time m_endTime; double m_rxPowerW; @@ -246,15 +247,15 @@ void WifiPhy::ReceivePacket (Packet const packet, double rxPowerW, WifiMode txMode, - WifiMode headerMode) + enum WifiPreamble preamble) { - Time rxDuration = CalculateTxDuration (packet.GetSize (), txMode, headerMode); + Time rxDuration = CalculateTxDuration (packet.GetSize (), txMode, preamble); Time endRx = Simulator::Now () + rxDuration; m_startRxLogger (rxDuration, rxPowerW); Ptr event = Create (packet.GetSize (), txMode, - headerMode, + preamble, rxDuration, rxPowerW); AppendEvent (event); @@ -335,7 +336,7 @@ WifiPhy::ReceivePacket (Packet const packet, event->Unref (); } void -WifiPhy::SendPacket (Packet const packet, WifiMode txMode, WifiMode headerMode, uint8_t txPower) +WifiPhy::SendPacket (Packet const packet, WifiMode txMode, WifiPreamble preamble, uint8_t txPower) { /* Transmission can happen if: * - we are syncing on a packet. It is the responsability of the @@ -349,11 +350,11 @@ WifiPhy::SendPacket (Packet const packet, WifiMode txMode, WifiMode headerMode, m_endSyncEvent.Cancel (); } - Time txDuration = CalculateTxDuration (packet.GetSize (), txMode, headerMode); + Time txDuration = CalculateTxDuration (packet.GetSize (), txMode, preamble); m_startTxLogger (txDuration, txMode.GetPhyRate (), GetPowerDbm (txPower)); NotifyTxStart (txDuration); SwitchToTx (txDuration); - m_channel->Send (m_device, packet, GetPowerDbm (txPower) + m_txGainDbm, txMode, headerMode); + m_channel->Send (m_device, packet, GetPowerDbm (txPower) + m_txGainDbm, txMode, preamble); } void @@ -423,7 +424,10 @@ WifiPhy::CalculateSnr (WifiMode txMode, double ber) const void WifiPhy::Configure80211a (void) { - m_plcpPreambleDelayUs = 20; + m_plcpLongPreambleDelayUs = 20; + m_plcpShortPreambleDelayUs = 20; + m_longPlcpHeaderMode = g_6mba; + m_shortPlcpHeaderMode = g_6mba; m_plcpHeaderLength = 4 + 1 + 12 + 1 + 6 + 16 + 6; /* 4095 bytes at a 6Mb/s rate with a 1/2 coding rate. */ m_maxPacketDuration = Seconds (4095.0*8.0/6000000.0*(1.0/2.0)); @@ -517,10 +521,19 @@ WifiPhy::GetDelayUntilIdle (void) Time -WifiPhy::CalculateTxDuration (uint32_t size, WifiMode payloadMode, WifiMode headerMode) const +WifiPhy::CalculateTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble) const { - uint64_t delay = m_plcpPreambleDelayUs; - delay += m_plcpHeaderLength * 1000000 / headerMode.GetDataRate (); + uint64_t delay = 0; + switch (preamble) { + case WIFI_PREAMBLE_LONG: + delay += m_plcpLongPreambleDelayUs; + delay += m_plcpHeaderLength * 1000000 / m_longPlcpHeaderMode.GetDataRate (); + break; + case WIFI_PREAMBLE_SHORT: + delay += m_plcpShortPreambleDelayUs; + delay += m_plcpHeaderLength * 1000000 / m_shortPlcpHeaderMode.GetDataRate (); + break; + } uint64_t nbits = size * 8; delay += nbits * 1000000 / payloadMode.GetDataRate (); return MicroSeconds (delay); @@ -1079,13 +1092,24 @@ WifiPhy::CalculatePer (Ptr event, NiChanges *ni) const double psr = 1.0; /* Packet Success Rate */ NiChanges::iterator j = ni->begin (); Time previous = (*j).GetTime (); - Time plcpHeaderStart = (*j).GetTime () + MicroSeconds (m_plcpPreambleDelayUs); + uint64_t plcpPreambleDelayUs; + WifiMode payloadMode = event->GetPayloadMode (); + WifiMode headerMode; + switch (event->GetPreambleType ()) { + case WIFI_PREAMBLE_LONG: + plcpPreambleDelayUs = m_plcpLongPreambleDelayUs; + headerMode = m_longPlcpHeaderMode; + break; + case WIFI_PREAMBLE_SHORT: + plcpPreambleDelayUs = m_plcpShortPreambleDelayUs; + headerMode = m_shortPlcpHeaderMode; + break; + } + Time plcpHeaderStart = (*j).GetTime () + MicroSeconds (plcpPreambleDelayUs); Time plcpPayloadStart = plcpHeaderStart + - Seconds (m_plcpHeaderLength / event->GetHeaderMode ().GetDataRate ()); + Seconds (m_plcpHeaderLength / headerMode.GetDataRate ()); double noiseInterferenceW = (*j).GetDelta (); double powerW = event->GetRxPowerW (); - WifiMode payloadMode = event->GetPayloadMode (); - WifiMode headerMode = event->GetHeaderMode (); j++; while (ni->end () != j) @@ -1186,7 +1210,7 @@ WifiPhy::EndSync (Packet const packet, Ptr event) m_endSyncLogger (true); NotifySyncEndOk (); SwitchFromSync (); - m_syncOkCallback (packet, snr, event->GetPayloadMode (), event->GetHeaderMode ()); + m_syncOkCallback (packet, snr, event->GetPayloadMode (), event->GetPreambleType ()); } else { diff --git a/src/devices/wifi/wifi-phy.h b/src/devices/wifi/wifi-phy.h index 360b9b472..50fb6f868 100644 --- a/src/devices/wifi/wifi-phy.h +++ b/src/devices/wifi/wifi-phy.h @@ -33,6 +33,7 @@ #include "ns3/ptr.h" #include "ns3/random-variable.h" #include "wifi-mode.h" +#include "wifi-preamble.h" namespace ns3 { @@ -71,7 +72,7 @@ public: class WifiPhy { public: - typedef Callback SyncOkCallback; + typedef Callback SyncOkCallback; typedef Callback SyncErrorCallback; WifiPhy (Ptr device); @@ -82,7 +83,7 @@ public: void SetReceiveOkCallback (SyncOkCallback callback); void SetReceiveErrorCallback (SyncErrorCallback callback); - void SendPacket (Packet const packet, WifiMode mode, WifiMode headerMode, uint8_t txPower); + void SendPacket (Packet const packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPower); void RegisterListener (WifiPhyListener *listener); @@ -94,7 +95,7 @@ public: Time GetStateDuration (void); Time GetDelayUntilIdle (void); - Time CalculateTxDuration (uint32_t size, WifiMode payloadMode, WifiMode headerMode) const; + Time CalculateTxDuration (uint32_t size, WifiMode payloadMode, enum WifiPreamble preamble) const; void Configure80211a (void); void SetEdThresholdDbm (double rxThreshold); @@ -179,10 +180,13 @@ private: void ReceivePacket (Packet packet, double rxPowerW, WifiMode mode, - WifiMode headerMode); + WifiPreamble preamble); private: uint64_t m_txPrepareDelayUs; - uint64_t m_plcpPreambleDelayUs; + uint64_t m_plcpLongPreambleDelayUs; + uint64_t m_plcpShortPreambleDelayUs; + WifiMode m_longPlcpHeaderMode; + WifiMode m_shortPlcpHeaderMode; uint32_t m_plcpHeaderLength; Time m_maxPacketDuration; diff --git a/src/devices/wifi/wifi-preamble.h b/src/devices/wifi/wifi-preamble.h new file mode 100644 index 000000000..bf7ad557f --- /dev/null +++ b/src/devices/wifi/wifi-preamble.h @@ -0,0 +1,13 @@ +#ifndef WIFI_PREAMBLE_H +#define WIFI_PREAMBLE_H + +namespace ns3 { + +enum WifiPreamble { + WIFI_PREAMBLE_LONG, + WIFI_PREAMBLE_SHORT +}; + +} // namespace ns3 + +#endif /* WIFI_PREAMBLE_H */