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 everythng 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)

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.
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'.
AirFrame * unbufferMsg (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.
void sendDelayedUp (AirFrame *, double, SnrList &)
 Sends a message to the upper layer; waits delay seconds before sending.
void sendDelayedDown (AirFrame *msg, double)
 Sends a message to the channel; waits delay seconds before sending.
AirFrame * encapsMsg (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 AirFrame * createCapsulePkt ()
 Create a new AirFrame.

Protected Attributes

double bitrate
 a parameter that has to be read in from omnetpp.ini
int headerLength
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..

00114 {
00115     // set timer to indicate transmission is complete
00116     TransmComplete *timer = new TransmComplete(NULL);
00117     timer->setContextPointer(frame);
00118     scheduleAt(simTime() + (frame->getDuration()), timer);
00119 }

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.

00149 {
00150     double duration;
00151     duration = (double) af->length() / (double) bitrate;
00152     return duration;
00153 }

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

Create a new AirFrame.

00161                                          {
00162         return new AirFrame();
00163     };

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

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.

00128 {
00129     AirFrame *frame = createCapsulePkt();
00130     frame->setName(msg->name());
00131     frame->setPSend(transmitterPower);
00132     frame->setLength(headerLength);
00133     //FIXME frame->setChannelId(((MacPkt*)msg)->getChannelId()); --MF generally lacks support for channels, that will have to be rectified
00134     frame->encapsulate(msg);
00135     frame->setDuration(calcDuration(frame));
00136     frame->setSenderPos(myPosition());
00137     return frame;
00138 }

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.

00256 {
00257     coreEV << "in handleLowerMsgEnd\n";
00258 
00259     // We need to create a "dummy" snr list that we can pass together
00260     // with the message to the decider module so that also the
00261     // BasicSnrEval is able to work.
00262     SnrList snrList;
00263 
00264     // However you can take this as a reference how to create your own
00265     // snr entries.
00266 
00267     // Everytime you want to add something to the snr information list
00268     // it has to look like this:
00269     // 1. create a list entry and fill the fields
00270     SnrListEntry listEntry;
00271     listEntry.time = simTime();
00272     listEntry.snr = 3;          //just a senseless example
00273 
00274     // 2. add an entry to the SnrList
00275     snrList.push_back(listEntry);
00276 
00277     // 3. pass the message together with the list to the decider
00278     sendUp(frame, snrList);
00279 }

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.

00307 {
00308     coreEV << "in handleLowerMsgStart, receiving frame " << frame->name() << endl;
00309 
00310     //calculate the receive power
00311 
00312     // calculate snr information, like snr=pSend/noise or whatever....
00313 
00314     // if receive power is actually high enough to be able to read the
00315     // message and no other message is currently being received, store
00316     // the snr information for the message someweher where you can find
00317     // it in handleLowerMsgEnd
00318 }

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
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
00099     {
00100         // msg must come from channel
00101         AirFrame *frame = (AirFrame *) msg;
00102         handleLowerMsgStart(frame);
00103         bufferMsg(frame);
00104     }
00105 }

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.

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

00234 {
00235     sendDown(frame);
00236 }

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 BasiSnrEval, 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("tranmitterPower cannot be bigger than pMax in ChannelControl!");
00059     }
00060 }

void BasicSnrEval::sendDelayedDown AirFrame *  msg,
double  delay
[protected]
 

Sends a message to the channel; waits delay seconds before sending.

Just calls sentToChannel from ChannelAccess.

See also:
sendToChannel
00183 {
00184     sendToChannel((cMessage *) msg, delay);
00185 }

void BasicSnrEval::sendDelayedUp AirFrame *  msg,
double  delay,
SnrList list
[protected]
 

Sends a message to the upper layer; waits delay seconds before sending.

Attach control info to the message and send message to the upper layer. Wait delay seconds before sending.

Parameters:
msg AirFrame to pass to the decider
list Snr list to attach as control info
delay Delay the message should be sent with in seconds
to be called within handleLowerMsgEnd.
00198 {
00199     // create ControlInfo
00200     SnrControlInfo *cInfo = new SnrControlInfo;
00201     // attach the list to cInfo
00202     cInfo->setSnrList(list);
00203     // attach the cInfo to the AirFrame
00204     msg->setControlInfo(cInfo);
00205 
00206     sendDelayed((cMessage *) msg, delay, uppergateOut);
00207 }

void BasicSnrEval::sendDown AirFrame *  msg  )  [protected]
 

Sends a message to the channel.

Convenience function which calls sendToChannel with delay set to 0.0.

See also:
sendToChannel
00173 {
00174     sendToChannel((cMessage *) msg, 0.0);
00175 }

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

Sends a message to the upper layer.

Convenience function which calls sendDelayedUp with delay set to 0.0.

See also:
sendDelayedUp
00162 {
00163     sendDelayedUp(msg, 0.0, list);
00164 }

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

00214 {
00215     AirFrame *frame = (AirFrame *) msg->contextPointer();
00216     //delete the self message
00217     delete msg;
00218 
00219     return frame;
00220 }


Member Data Documentation

double BasicSnrEval::bitrate [protected]
 

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

int BasicSnrEval::headerLength [protected]
 

brief 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 Sat Apr 1 20:52:21 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.1