#include <Ieee80211RadioModel.h>
Public Member Functions | |
virtual void | initializeFrom (cModule *radioModule) |
virtual double | calculateDuration (AirFrame *airframe) |
virtual bool | isReceivedCorrectly (AirFrame *airframe, const SnrList &receivedList) |
Protected Member Functions | |
virtual bool | isPacketOK (double snirMin, int lengthMPDU, double bitrate) |
virtual double | dB2fraction (double dB) |
Protected Attributes | |
double | snirThreshold |
void Ieee80211RadioModel::initializeFrom | ( | cModule * | radioModule | ) | [virtual] |
Allows parameters to be read from the module parameters of a module that contains this object.
Implements IRadioModel.
00029 { 00030 snirThreshold = dB2fraction(radioModule->par("snirThreshold")); 00031 }
double Ieee80211RadioModel::calculateDuration | ( | AirFrame * | ) | [virtual] |
Should be defined to calculate the duration of the AirFrame. Usually the duration is just the frame length divided by the bitrate. However, in some cases, notably IEEE 802.11, the header has a different modulation (and thus a different bitrate) than the rest of the message.
Implements IRadioModel.
00034 { 00035 // The physical layer header is sent with 1Mbit/s and the rest with the frame's bitrate 00036 return airframe->getBitLength()/airframe->getBitrate() + PHY_HEADER_LENGTH/BITRATE_HEADER; 00037 }
bool Ieee80211RadioModel::isReceivedCorrectly | ( | AirFrame * | airframe, | |
const SnrList & | receivedList | |||
) | [virtual] |
Should be defined to calculate whether the frame has been received correctly. Input is the signal-noise ratio over the duration of the frame. The calculation may take into account the modulation scheme, possible error correction code, etc.
Implements IRadioModel.
00041 { 00042 // calculate snirMin 00043 double snirMin = receivedList.begin()->snr; 00044 for (SnrList::const_iterator iter = receivedList.begin(); iter != receivedList.end(); iter++) 00045 if (iter->snr < snirMin) 00046 snirMin = iter->snr; 00047 00048 cPacket *frame = airframe->getEncapsulatedMsg(); 00049 EV << "packet (" << frame->getClassName() << ")" << frame->getName() << " (" << frame->info() << ") snrMin=" << snirMin << endl; 00050 00051 if (snirMin <= snirThreshold) 00052 { 00053 // if snir is too low for the packet to be recognized 00054 EV << "COLLISION! Packet got lost\n"; 00055 return false; 00056 } 00057 else if (isPacketOK(snirMin, airframe->getEncapsulatedMsg()->getBitLength(), airframe->getBitrate())) 00058 { 00059 EV << "packet was received correctly, it is now handed to upper layer...\n"; 00060 return true; 00061 } 00062 else 00063 { 00064 EV << "Packet has BIT ERRORS! It is lost!\n"; 00065 return false; 00066 } 00067 }
bool Ieee80211RadioModel::isPacketOK | ( | double | snirMin, | |
int | lengthMPDU, | |||
double | bitrate | |||
) | [protected, virtual] |
Referenced by isReceivedCorrectly().
00071 { 00072 double berHeader, berMPDU; 00073 00074 berHeader = 0.5 * exp(-snirMin * BANDWIDTH / BITRATE_HEADER); 00075 00076 // if PSK modulation 00077 if (bitrate == 1E+6 || bitrate == 2E+6) 00078 berMPDU = 0.5 * exp(-snirMin * BANDWIDTH / bitrate); 00079 // if CCK modulation (modeled with 16-QAM) 00080 else if (bitrate == 5.5E+6) 00081 berMPDU = 0.5 * (1 - 1 / sqrt(pow(2.0, 4))) * erfc(snirMin * BANDWIDTH / bitrate); 00082 else // CCK, modelled with 256-QAM 00083 berMPDU = 0.25 * (1 - 1 / sqrt(pow(2.0, 8))) * erfc(snirMin * BANDWIDTH / bitrate); 00084 00085 // probability of no bit error in the PLCP header 00086 double headerNoError = pow(1.0 - berHeader, HEADER_WITHOUT_PREAMBLE); 00087 00088 // probability of no bit error in the MPDU 00089 double MpduNoError = pow(1.0 - berMPDU, lengthMPDU); 00090 EV << "berHeader: " << berHeader << " berMPDU: " << berMPDU << endl; 00091 double rand = dblrand(); 00092 00093 if (rand > headerNoError) 00094 return false; // error in header 00095 else if (dblrand() > MpduNoError) 00096 return false; // error in MPDU 00097 else 00098 return true; // no error 00099 }
double Ieee80211RadioModel::dB2fraction | ( | double | dB | ) | [protected, virtual] |
double Ieee80211RadioModel::snirThreshold [protected] |
Referenced by initializeFrom(), and isReceivedCorrectly().