#include <GenericRadioModel.h>
Public Member Functions | |
GenericRadioModel () | |
virtual | ~GenericRadioModel () |
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 length, double bitrate) |
virtual double | dB2fraction (double dB) |
Protected Attributes | |
double | snirThreshold |
long | headerLengthBits |
double | bandwidth |
IModulation * | modulation |
GenericRadioModel::GenericRadioModel | ( | ) |
GenericRadioModel::~GenericRadioModel | ( | ) | [virtual] |
void GenericRadioModel::initializeFrom | ( | cModule * | radioModule | ) | [virtual] |
Allows parameters to be read from the module parameters of a module that contains this object.
Implements IRadioModel.
00038 { 00039 snirThreshold = dB2fraction(radioModule->par("snirThreshold")); 00040 headerLengthBits = radioModule->par("headerLengthBits"); 00041 bandwidth = radioModule->par("bandwidth"); 00042 00043 const char *modulationName = radioModule->par("modulation"); 00044 if (strcmp(modulationName, "null")==0) 00045 modulation = new NullModulation(); 00046 else if (strcmp(modulationName, "BPSK")==0) 00047 modulation = new BPSKModulation(); 00048 else if (strcmp(modulationName, "16-QAM")==0) 00049 modulation = new QAM16Modulation(); 00050 else if (strcmp(modulationName, "256-QAM")==0) 00051 modulation = new QAM256Modulation(); 00052 else 00053 opp_error("unrecognized modulation '%s'", modulationName); 00054 }
double GenericRadioModel::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.
00058 { 00059 return (airframe->getBitLength()+headerLengthBits) / airframe->getBitrate(); 00060 }
bool GenericRadioModel::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.
00064 { 00065 // calculate snirMin 00066 double snirMin = receivedList.begin()->snr; 00067 for (SnrList::const_iterator iter = receivedList.begin(); iter != receivedList.end(); iter++) 00068 if (iter->snr < snirMin) 00069 snirMin = iter->snr; 00070 00071 if (snirMin <= snirThreshold) 00072 { 00073 // if snir is too low for the packet to be recognized 00074 EV << "COLLISION! Packet got lost\n"; 00075 return false; 00076 } 00077 else if (isPacketOK(snirMin, airframe->getBitLength()+headerLengthBits, airframe->getBitrate())) 00078 { 00079 EV << "packet was received correctly, it is now handed to upper layer...\n"; 00080 return true; 00081 } 00082 else 00083 { 00084 EV << "Packet has BIT ERRORS! It is lost!\n"; 00085 return false; 00086 } 00087 }
bool GenericRadioModel::isPacketOK | ( | double | snirMin, | |
int | length, | |||
double | bitrate | |||
) | [protected, virtual] |
Referenced by isReceivedCorrectly().
00091 { 00092 double ber = modulation->calculateBER(snirMin, bandwidth, bitrate); 00093 00094 if (ber==0.0) 00095 return true; 00096 00097 double probNoError = pow(1.0 - ber, length); // probability of no bit error 00098 00099 if (dblrand() > probNoError) 00100 return false; // error in MPDU 00101 else 00102 return true; // no error 00103 }
double GenericRadioModel::dB2fraction | ( | double | dB | ) | [protected, virtual] |
double GenericRadioModel::snirThreshold [protected] |
Referenced by initializeFrom(), and isReceivedCorrectly().
long GenericRadioModel::headerLengthBits [protected] |
Referenced by calculateDuration(), initializeFrom(), and isReceivedCorrectly().
double GenericRadioModel::bandwidth [protected] |
Referenced by initializeFrom(), and isPacketOK().
IModulation* GenericRadioModel::modulation [protected] |
Referenced by GenericRadioModel(), initializeFrom(), isPacketOK(), and ~GenericRadioModel().