replace header mode with preamble mode

This commit is contained in:
Mathieu Lacage
2007-10-09 11:07:05 +02:00
parent dee939e78c
commit 497bb74d5a
8 changed files with 83 additions and 37 deletions

View File

@@ -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;
}

View File

@@ -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<NetDevice> device, ReceiveCallback callback)
}
void
WifiChannel::Send (Ptr<NetDevice> sender, const Packet &packet, double txPowerDbm,
WifiMode wifiMode, WifiMode headerMode) const
WifiMode wifiMode, WifiPreamble preamble) const
{
Ptr<MobilityModel> senderMobility = sender->GetNode ()->QueryInterface<MobilityModel> (MobilityModel::iid);
uint32_t j = 0;
@@ -73,7 +73,7 @@ WifiChannel::Send (Ptr<NetDevice> 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

View File

@@ -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<void,Packet,double,WifiMode,WifiMode> ReceiveCallback;
typedef Callback<void,Packet,double,WifiMode,WifiPreamble> ReceiveCallback;
WifiChannel ();
virtual ~WifiChannel ();
@@ -47,17 +48,17 @@ public:
void Add (Ptr<NetDevice> device, ReceiveCallback callback);
void Send (Ptr<NetDevice> sender, const Packet &packet, double txPowerDbm,
WifiMode wifiMode, WifiMode headerMode) const;
WifiMode wifiMode, WifiPreamble preamble) const;
private:
typedef std::vector<std::pair<Ptr<NetDevice>, 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;

View File

@@ -62,6 +62,7 @@ WifiMode::GetUid (void) const
return m_uid;
}
WifiMode::WifiMode ()
: m_uid (0)
{}
WifiMode::WifiMode (uint32_t uid)
: m_uid (uid)

View File

@@ -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;
};

View File

@@ -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<RxEvent> event = Create<RxEvent> (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<const RxEvent> 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<RxEvent> event)
m_endSyncLogger (true);
NotifySyncEndOk ();
SwitchFromSync ();
m_syncOkCallback (packet, snr, event->GetPayloadMode (), event->GetHeaderMode ());
m_syncOkCallback (packet, snr, event->GetPayloadMode (), event->GetPreambleType ());
}
else
{

View File

@@ -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<void,Packet const , double, WifiMode, WifiMode> SyncOkCallback;
typedef Callback<void,Packet const , double, WifiMode, enum WifiPreamble> SyncOkCallback;
typedef Callback<void,Packet const , double> SyncErrorCallback;
WifiPhy (Ptr<WifiNetDevice> 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;

View File

@@ -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 */