INET Framework for OMNeT++/OMNEST
BasicSnrEval Class Reference

The basic class for all snrEval modules. More...

#include <BasicSnrEval.h>

Inheritance diagram for BasicSnrEval:
ChannelAccess BasicModule INotifiable SnrEval GilbertElliotSnr SnrEval80211

List of all members.

Protected Member Functions

virtual void initialize (int)
 Initialization of the module and some variables.
virtual void handleMessage (cMessage *)
 Called every time a message arrives.
virtual double calcDuration (cPacket *)
 This function calculates the duration of the AirFrame.
virtual int getChannelNumber () const
 Returns the channel we're listening on. This version always returns 0 (single radio channel supported)
Handle Messages

Functions to redefine by the programmer

virtual void handleUpperMsg (AirFrame *)
 Fill the header fields, redefine for your own needs...
virtual void handleSelfMsg (cMessage *msg)
 Handle self messages such as timer...
virtual void handleLowerMsgStart (AirFrame *)
 Calculate Snr Information before buffering.
virtual void handleLowerMsgEnd (AirFrame *)
 Calculate SnrInfo after buffering and add the PhySnrList to the message.
Convenience Functions

Functions for convenience - NOT to be modified

These are functions taking care of message encapsulation and message sending. Normally you should not need to alter these but should use them to handle message encasulation and sending. They will wirte all necessary information into packet headers and add or strip the appropriate headers for each layer.

virtual void bufferMsg (AirFrame *frame)
 Buffers message for 'transmission time'.
virtual AirFrame * unbufferMsg (cMessage *msg)
 Unbuffers a message after 'transmission time'.
virtual void sendUp (AirFrame *, SnrList &)
 Sends a message to the upper layer.
virtual void sendDown (AirFrame *msg)
 Sends a message to the channel.
virtual AirFrame * encapsMsg (cPacket *msg)
 Encapsulates a MAC frame into an Air Frame.
Abstraction layer

Factory function to create AirFrame into which a MAC frame is encapsulated.

SnrEval authors should be able to use their own SnrEval packets. The framework does not need to know about them, but must be able to produce new ones. Both goals can be reached by using a factory method.

Overwrite this function in derived classes to use your own AirFrames

virtual AirFrame * createCapsulePkt ()
 Create a new AirFrame.

Protected Attributes

double bitrate
 a parameter that has to be read in from omnetpp.ini
int headerLength
 a parameter that has to be read in from omnetpp.ini
double transmitterPower
 power used to transmit messages
int uppergateOut
 gate id
int uppergateIn

Detailed Description

The basic class for all snrEval modules.

The BasicSnrEval module provides functionality like en- and decapsulation of messages. If you use the standard message formats everything should work fine. Before a packet is sent some information, e.g. transmission power, can be written to the AirFrame header. If you write your own snrEval, just subclass and redefine the handleUpperMsg function (see description of the function). After receiving a message it can be processed in handleLowerMsgStart. Then it is buffered for the time the transmission would last in reality, and then can be handled again. Again you can redefine the 1. handleLowerMsgStart and 2. handleLowerMsgEnd for your own needs (see description). So, the call of these functions represent the following events: 1. received a message (i.e. transmission startet) 2. message will be handed on to the upper layer (i.e. transmission time is over)

This supports a single radio channel only

Author:
Marc Loebbers

Member Function Documentation

void BasicSnrEval::bufferMsg ( AirFrame *  frame) [protected, virtual]

Buffers message for 'transmission time'.

The packet is put in a buffer for the time the transmission would last in reality. A timer indicates when the transmission is complete. So, look at unbufferMsg to see what happens when the transmission is complete..

Referenced by SnrEval::changeChannel(), and handleMessage().

{
    // set timer to indicate transmission is complete
    TransmComplete *endRxTimer = new TransmComplete(NULL);
    endRxTimer->setContextPointer(frame);
    frame->setContextPointer(endRxTimer);
    // NOTE: use arrivalTime instead of simTime, because we might be calling this
    // function during a channel change, when we're picking up ongoing transmissions
    // on the channel -- and then the message's arrival time is in the past!
    scheduleAt(frame->getArrivalTime() + frame->getDuration(), endRxTimer);
}
double BasicSnrEval::calcDuration ( cPacket *  af) [protected, virtual]

This function calculates the duration of the AirFrame.

Usually the duration is just the frame length divided by the bitrate. However there may be cases (like 802.11) where the header has a different modulation (and thus a different bitrate) than the rest of the message.

Just redefine this function in such a case!

Reimplemented in SnrEval80211.

Referenced by encapsMsg().

{
    double duration;
    duration = (double) af->getBitLength() / (double) bitrate;
    return duration;
}
virtual AirFrame* BasicSnrEval::createCapsulePkt ( ) [inline, protected, virtual]

Create a new AirFrame.

Referenced by encapsMsg().

                                         {
        return new AirFrame();
    };
AirFrame * BasicSnrEval::encapsMsg ( cPacket *  msg) [protected, virtual]

Encapsulates a MAC frame into an Air Frame.

This function encapsulates messages from the upper layer into an AirFrame, copies the type and channel fields, adds the headerLength, sets the pSend (transmitterPower) and returns the AirFrame.

Referenced by handleMessage().

{
    AirFrame *frame = createCapsulePkt();
    frame->setName(msg->getName());
    frame->setPSend(transmitterPower);
    frame->setBitLength(headerLength);
    frame->setChannelNumber(getChannelNumber());
    frame->encapsulate(msg);
    frame->setDuration(calcDuration(frame));
    frame->setSenderPos(getMyPosition());
    return frame;
}
virtual int BasicSnrEval::getChannelNumber ( ) const [inline, protected, virtual]

Returns the channel we're listening on. This version always returns 0 (single radio channel supported)

Reimplemented in SnrEval.

Referenced by encapsMsg(), and handleMessage().

{return 0;}
void BasicSnrEval::handleLowerMsgEnd ( AirFrame *  frame) [protected, virtual]

Calculate SnrInfo after buffering and add the PhySnrList to the message.

Redefine this function if you want to process messages from the channel before they are forwarded to upper layers

This function is called right before a packet is handed on to the upper layer, i.e. right after unbufferMsg. Again you can caluculate some more SNR information if you want.

You have to copy / create the SnrList related to the message and pass it to sendUp() if you want to pass the message to the decider.

Do not forget to send the message to the upper layer with sendUp()

For a "real" implementaion take a look at SnrEval

See also:
SnrList, SnrEval

Reimplemented in GilbertElliotSnr, and SnrEval.

Referenced by handleMessage().

{
    coreEV << "in handleLowerMsgEnd\n";

    // We need to create a "dummy" snr list that we can pass together
    // with the message to the decider module so that also the
    // BasicSnrEval is able to work.
    SnrList snrList;

    // However you can take this as a reference how to create your own
    // snr entries.

    // Everytime you want to add something to the snr information list
    // it has to look like this:
    // 1. create a list entry and fill the fields
    SnrListEntry listEntry;
    listEntry.time = simTime();
    listEntry.snr = 3;          //just a senseless example

    // 2. add an entry to the SnrList
    snrList.push_back(listEntry);

    // 3. pass the message together with the list to the decider
    sendUp(frame, snrList);
}
void BasicSnrEval::handleLowerMsgStart ( AirFrame *  frame) [protected, virtual]

Calculate Snr Information before buffering.

Redefine this function if you want to process messages from the channel before they are forwarded to upper layers

This function is called right after a message is received, i.e. right before it is buffered for 'transmission time'.

Here you should decide whether the message is "really" received or whether it's receive power is so low that it is just treated as noise.

If the energy of the message is high enough to really receive it you should create an snr list (SnrList) to be able to store sn(i)r information for that message. Every time a new message arrives you can add a new snr value together with a timestamp to that list. Make sure to store a pointer to the mesage together with the snr information to be able to retrieve it later.

In this function also an initial SNR value can be calculated for this message.

Please take a look at SnrEval to see a "real" example.

See also:
SnrList, SnrEval

Reimplemented in GilbertElliotSnr, and SnrEval.

Referenced by handleMessage().

{
    coreEV << "in handleLowerMsgStart, receiving frame " << frame->getName() << endl;

    //calculate the receive power

    // calculate snr information, like snr=pSend/noise or whatever....

    // if receive power is actually high enough to be able to read the
    // message and no other message is currently being received, store
    // the snr information for the message someweher where you can find
    // it in handleLowerMsgEnd
}
void BasicSnrEval::handleMessage ( cMessage *  msg) [protected, virtual]

Called every time a message arrives.

The basic handle message function.

Depending on the gate a message arrives handleMessage just calls different handle*Msg functions to further process the message.

Messages from the channel are also buffered here in order to simulate a transmission delay

You should not make any changes in this function but implement all your functionality into the handle*Msg functions called from here.

See also:
handleUpperMsg, handleLowerMsgStart, handleLowerMsgEnd, handleSelfMsg

Reimplemented in SnrEval.

{
    if (msg->getArrivalGateId() == uppergateIn)
    {
        AirFrame *frame = encapsMsg(PK(msg));
        handleUpperMsg(frame);
    }
    else if (msg->isSelfMessage())
    {
        if (dynamic_cast<TransmComplete *>(msg) != 0)
        {
            coreEV << "frame is completely received now\n";

            // unbuffer the message
            AirFrame *frame = unbufferMsg(msg);

            handleLowerMsgEnd(frame);
        }
        else
            handleSelfMsg(msg);
    }
    else if (check_and_cast<AirFrame *>(msg)->getChannelNumber() == getChannelNumber())
    {
        // must be an AirFrame
        AirFrame *frame = (AirFrame *) msg;
        handleLowerMsgStart(frame);
        bufferMsg(frame);
    }
    else
    {
        EV << "listening to different channel when receiving message -- dropping it\n";
        delete msg;
    }
}
virtual void BasicSnrEval::handleSelfMsg ( cMessage *  msg) [inline, protected, virtual]

Handle self messages such as timer...

Define this function if you want to process timer or other kinds of self messages

Reimplemented in GilbertElliotSnr, and SnrEval.

Referenced by handleMessage().

{delete msg;};
void BasicSnrEval::handleUpperMsg ( AirFrame *  frame) [protected, virtual]

Fill the header fields, redefine for your own needs...

Redefine this function if you want to process messages from upper layers before they are send to the channel.

The MAC frame is already encapsulated in an AirFrame and all standard header fields are set.

To forward the message to lower layers after processing it please use sendDown. It will take care of decapsulation and anything else needed

Reimplemented in SnrEval.

Referenced by handleMessage().

{
    sendDown(frame);
}
void BasicSnrEval::initialize ( int  stage) [protected, virtual]

Initialization of the module and some variables.

First we have to initialize the module from which we derived ours, in this case ChannelAccess.

Then we have to intialize the gates and - if necessary - some own variables.

If you want to use your own AirFrames you have to redefine createCapsulePkt function.

Reimplemented from ChannelAccess.

Reimplemented in GilbertElliotSnr, SnrEval, and SnrEval80211.

{
    ChannelAccess::initialize(stage);

    coreEV << "Initializing BasicSnrEval, stage=" << stage << endl;

    if (stage == 0)
    {
        gate("radioIn")->setDeliverOnReceptionStart(true);

        uppergateIn = findGate("uppergateIn");
        uppergateOut = findGate("uppergateOut");

        headerLength = par("headerLength");
        bitrate = par("bitrate");

        transmitterPower = par("transmitterPower");

        // transmitter power CANNOT be greater than in ChannelControl
        if (transmitterPower > (double) (cc->par("pMax")))
            error("transmitterPower cannot be bigger than pMax in ChannelControl!");
    }
}
void BasicSnrEval::sendDown ( AirFrame *  msg) [protected, virtual]

Sends a message to the channel.

See also:
sendToChannel

Referenced by SnrEval::handleUpperMsg(), and handleUpperMsg().

{
    sendToChannel(msg);
}
void BasicSnrEval::sendUp ( AirFrame *  msg,
SnrList list 
) [protected, virtual]

Sends a message to the upper layer.

Attach control info to the message and send message to the upper layer.

Parameters:
msgAirFrame to pass to the decider
listSnr list to attach as control info

to be called within handleLowerMsgEnd.

Referenced by SnrEval::handleLowerMsgEnd(), GilbertElliotSnr::handleLowerMsgEnd(), and handleLowerMsgEnd().

{
    // create ControlInfo
    SnrControlInfo *cInfo = new SnrControlInfo;
    // attach the list to cInfo
    cInfo->setSnrList(list);
    // attach the cInfo to the AirFrame
    msg->setControlInfo(cInfo);

    send(msg, uppergateOut);
}
AirFrame * BasicSnrEval::unbufferMsg ( cMessage *  msg) [protected, virtual]

Unbuffers a message after 'transmission time'.

Get the context pointer to the now completely received AirFrame and delete the self message

Referenced by handleMessage().

{
    AirFrame *frame = (AirFrame *) msg->getContextPointer();
    //delete the self message
    delete msg;

    return frame;
}

Member Data Documentation

double BasicSnrEval::bitrate [protected]

a parameter that has to be read in from omnetpp.ini

Referenced by SnrEval80211::calcDuration(), calcDuration(), SnrEval80211::initialize(), initialize(), and SnrEval::setBitrate().

int BasicSnrEval::headerLength [protected]

a parameter that has to be read in from omnetpp.ini

Referenced by SnrEval80211::calcDuration(), encapsMsg(), SnrEval80211::initialize(), and initialize().

double BasicSnrEval::transmitterPower [protected]

power used to transmit messages

Referenced by encapsMsg(), and initialize().

int BasicSnrEval::uppergateOut [protected]

gate id

Referenced by initialize(), and sendUp().


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