Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BasicSnrEval Class Reference

#include <BasicSnrEval.h>

Inheritance diagram for BasicSnrEval:

ChannelAccess BasicModule INotifiable SnrEval GilbertElliotSnr SnrEval80211 List of all members.

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


Protected Member Functions

virtual void initialize (int)
 Initialization of the module and some variables.
void handleMessage (cMessage *)
 Called every time a message arrives.
virtual double calcDuration (cMessage *)
 This function calculates the duration of the AirFrame.
virtual int channelNumber () 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.

void bufferMsg (AirFrame *frame)
 Buffers message for 'transmission time'.
AirFrameunbufferMsg (cMessage *msg)
 Unbuffers a message after 'transmission time'.
void sendUp (AirFrame *, SnrList &)
 Sends a message to the upper layer.
void sendDown (AirFrame *msg)
 Sends a message to the channel.
virtual AirFrameencapsMsg (cMessage *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 AirFramecreateCapsulePkt ()
 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


Member Function Documentation

void BasicSnrEval::bufferMsg AirFrame frame  )  [protected]
 

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..

00118                                                     : add explicit simtime_t atTime arg?
00119 {
00120     // set timer to indicate transmission is complete
00121     TransmComplete *endRxTimer = new TransmComplete(NULL);
00122     endRxTimer->setContextPointer(frame);
00123     frame->setContextPointer(endRxTimer);
00124     // NOTE: use arrivalTime instead of simTime, because we might be calling this
00125     // function during a channel change, when we're picking up ongoing transmissions
00126     // on the channel -- and then the message's arrival time is in the past!
00127     scheduleAt(frame->arrivalTime() + frame->getDuration(), endRxTimer);
00128 }

double BasicSnrEval::calcDuration cMessage *  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.

00158 {
00159     double duration;
00160     duration = (double) af->length() / (double) bitrate;
00161     return duration;
00162 }

virtual int BasicSnrEval::channelNumber  )  const [inline, protected, virtual]
 

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

Reimplemented in SnrEval.

00142 {return 0;}

virtual AirFrame* BasicSnrEval::createCapsulePkt  )  [inline, protected, virtual]
 

Create a new AirFrame.

00159                                          {
00160         return new AirFrame();
00161     };

AirFrame * BasicSnrEval::encapsMsg cMessage *  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.

00137 {
00138     AirFrame *frame = createCapsulePkt();
00139     frame->setName(msg->name());
00140     frame->setPSend(transmitterPower);
00141     frame->setLength(headerLength);
00142     frame->setChannelNumber(channelNumber());
00143     frame->encapsulate(msg);
00144     frame->setDuration(calcDuration(frame));
00145     frame->setSenderPos(myPosition());
00146     return frame;
00147 }

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.

00242 {
00243     coreEV << "in handleLowerMsgEnd\n";
00244 
00245     // We need to create a "dummy" snr list that we can pass together
00246     // with the message to the decider module so that also the
00247     // BasicSnrEval is able to work.
00248     SnrList snrList;
00249 
00250     // However you can take this as a reference how to create your own
00251     // snr entries.
00252 
00253     // Everytime you want to add something to the snr information list
00254     // it has to look like this:
00255     // 1. create a list entry and fill the fields
00256     SnrListEntry listEntry;
00257     listEntry.time = simTime();
00258     listEntry.snr = 3;          //just a senseless example
00259 
00260     // 2. add an entry to the SnrList
00261     snrList.push_back(listEntry);
00262 
00263     // 3. pass the message together with the list to the decider
00264     sendUp(frame, snrList);
00265 }

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.

00293 {
00294     coreEV << "in handleLowerMsgStart, receiving frame " << frame->name() << endl;
00295 
00296     //calculate the receive power
00297 
00298     // calculate snr information, like snr=pSend/noise or whatever....
00299 
00300     // if receive power is actually high enough to be able to read the
00301     // message and no other message is currently being received, store
00302     // the snr information for the message someweher where you can find
00303     // it in handleLowerMsgEnd
00304 }

void BasicSnrEval::handleMessage cMessage *  msg  )  [protected]
 

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.

00078 {
00079     if (msg->arrivalGateId() == uppergateIn)
00080     {
00081         AirFrame *frame = encapsMsg(msg);
00082         handleUpperMsg(frame);
00083     }
00084     else if (msg->isSelfMessage())
00085     {
00086         if (dynamic_cast<TransmComplete *>(msg) != 0)
00087         {
00088             coreEV << "frame is completely received now\n";
00089 
00090             // unbuffer the message
00091             AirFrame *frame = unbufferMsg(msg);
00092 
00093             handleLowerMsgEnd(frame);
00094         }
00095         else
00096             handleSelfMsg(msg);
00097     }
00098     else if (check_and_cast<AirFrame *>(msg)->getChannelNumber() == channelNumber())
00099     {
00100         // must be an AirFrame
00101         AirFrame *frame = (AirFrame *) msg;
00102         handleLowerMsgStart(frame);
00103         bufferMsg(frame);
00104     }
00105     else
00106     {
00107         EV << "listening to different channel when receiving message -- dropping it\n";
00108         delete msg;
00109     }
00110 }

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.

00097 {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.

00220 {
00221     sendDown(frame);
00222 }

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.

00041 {
00042     ChannelAccess::initialize(stage);
00043 
00044     coreEV << "Initializing BasicSnrEval, stage=" << stage << endl;
00045 
00046     if (stage == 0)
00047     {
00048         uppergateIn = findGate("uppergateIn");
00049         uppergateOut = findGate("uppergateOut");
00050 
00051         headerLength = par("headerLength");
00052         bitrate = par("bitrate");
00053 
00054         transmitterPower = par("transmitterPower");
00055 
00056         // transmitter power CANNOT be greater than in ChannelControl
00057         if (transmitterPower > (double) (cc->par("pMax")))
00058             error("transmitterPower cannot be bigger than pMax in ChannelControl!");
00059     }
00060 }

void BasicSnrEval::sendDown AirFrame msg  )  [protected]
 

Sends a message to the channel.

See also:
sendToChannel
00191 {
00192     sendToChannel(msg);
00193 }

void BasicSnrEval::sendUp AirFrame msg,
SnrList list
[protected]
 

Sends a message to the upper layer.

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

Parameters:
msg AirFrame to pass to the decider
list Snr list to attach as control info
to be called within handleLowerMsgEnd.
00174 {
00175     // create ControlInfo
00176     SnrControlInfo *cInfo = new SnrControlInfo;
00177     // attach the list to cInfo
00178     cInfo->setSnrList(list);
00179     // attach the cInfo to the AirFrame
00180     msg->setControlInfo(cInfo);
00181 
00182     send(msg, uppergateOut);
00183 }

AirFrame * BasicSnrEval::unbufferMsg cMessage *  msg  )  [protected]
 

Unbuffers a message after 'transmission time'.

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

00200 {
00201     AirFrame *frame = (AirFrame *) msg->contextPointer();
00202     //delete the self message
00203     delete msg;
00204 
00205     return frame;
00206 }


Member Data Documentation

double BasicSnrEval::bitrate [protected]
 

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

int BasicSnrEval::headerLength [protected]
 

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

double BasicSnrEval::transmitterPower [protected]
 

power used to transmit messages

int BasicSnrEval::uppergateIn [protected]
 

int BasicSnrEval::uppergateOut [protected]
 

gate id


The documentation for this class was generated from the following files:
Generated on Thu Oct 19 18:22:21 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.0