INET Framework for OMNeT++/OMNEST
GenericRadioModel Class Reference

#include <GenericRadioModel.h>

Inheritance diagram for GenericRadioModel:
IRadioModel

List of all members.

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
IModulationmodulation

Detailed Description

Generic radio model. Frame duration is calculated from the bitrate and the packet length plus a physical header length. Bit error rate is calculated from the modulation scheme, signal bandwidth, bitrate and the frame length.

Definition at line 31 of file GenericRadioModel.h.


Constructor & Destructor Documentation

Definition at line 27 of file GenericRadioModel.cc.

{
    modulation = NULL;
}

Definition at line 32 of file GenericRadioModel.cc.

{
    delete modulation;
}

Member Function Documentation

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.

Definition at line 57 of file GenericRadioModel.cc.

{
    return (airframe->getBitLength()+headerLengthBits) / airframe->getBitrate();
}
double GenericRadioModel::dB2fraction ( double  dB) [protected, virtual]

Definition at line 105 of file GenericRadioModel.cc.

Referenced by initializeFrom().

{
    return pow(10.0, (dB / 10));
}
void GenericRadioModel::initializeFrom ( cModule *  radioModule) [virtual]

Allows parameters to be read from the module parameters of a module that contains this object.

Implements IRadioModel.

Definition at line 37 of file GenericRadioModel.cc.

{
    snirThreshold = dB2fraction(radioModule->par("snirThreshold"));
    headerLengthBits = radioModule->par("headerLengthBits");
    bandwidth = radioModule->par("bandwidth");

    const char *modulationName = radioModule->par("modulation");
    if (strcmp(modulationName, "null")==0)
        modulation = new NullModulation();
    else if (strcmp(modulationName, "BPSK")==0)
        modulation = new BPSKModulation();
    else if (strcmp(modulationName, "16-QAM")==0)
        modulation = new QAM16Modulation();
    else if (strcmp(modulationName, "256-QAM")==0)
        modulation = new QAM256Modulation();
    else
        opp_error("unrecognized modulation '%s'", modulationName);
}
bool GenericRadioModel::isPacketOK ( double  snirMin,
int  length,
double  bitrate 
) [protected, virtual]

Definition at line 90 of file GenericRadioModel.cc.

Referenced by isReceivedCorrectly().

{
    double ber = modulation->calculateBER(snirMin, bandwidth, bitrate);

    if (ber==0.0)
        return true;

    double probNoError = pow(1.0 - ber, length); // probability of no bit error

    if (dblrand() > probNoError)
        return false; // error in MPDU
    else
        return true; // no error
}
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.

Definition at line 63 of file GenericRadioModel.cc.

{
    // calculate snirMin
    double snirMin = receivedList.begin()->snr;
    for (SnrList::const_iterator iter = receivedList.begin(); iter != receivedList.end(); iter++)
        if (iter->snr < snirMin)
            snirMin = iter->snr;

    if (snirMin <= snirThreshold)
    {
        // if snir is too low for the packet to be recognized
        EV << "COLLISION! Packet got lost\n";
        return false;
    }
    else if (isPacketOK(snirMin, airframe->getBitLength()+headerLengthBits, airframe->getBitrate()))
    {
        EV << "packet was received correctly, it is now handed to upper layer...\n";
        return true;
    }
    else
    {
        EV << "Packet has BIT ERRORS! It is lost!\n";
        return false;
    }
}

Member Data Documentation

double GenericRadioModel::bandwidth [protected]

Definition at line 36 of file GenericRadioModel.h.

Referenced by initializeFrom(), and isPacketOK().

Definition at line 34 of file GenericRadioModel.h.

Referenced by initializeFrom(), and isReceivedCorrectly().


The documentation for this class was generated from the following files: