GilbertElliotSnr Class Reference

#include <GilbertElliotSnr.h>

Inheritance diagram for GilbertElliotSnr:

SnrEval BasicSnrEval ChannelAccess BasicModule INotifiable List of all members.

Detailed Description

Keeps track of the different snir levels when receiving a packet and switches between states GOOD and BAD (Gilbert-Elliot-Model).

This module has exactly the same functionality as the SnrEval module, but furthermore it puts a Gilbert-Elliot model on top of the SNIR level computation. This means that it changes between the states GOOD and BAD. If it is in state BAD a received frame will be marked as corrupted.

The Gilbert Elliot model is used to simulate outer system disturbances.

This module should be used in combination with the GilbertElliotDecider moulde which evaluates the snr levels as well as the marked frames.

Author:
Marc Loebbers


Public Member Functions

 GilbertElliotSnr ()
virtual ~GilbertElliotSnr ()

Protected Types

 GOOD
 BAD
enum  State { GOOD, BAD }
 Gilbert-Elliot state types. More...

Protected Member Functions

virtual void initialize (int)
 Initialize variables and publish the radio status.
virtual void handleSelfMsg (cMessage *)
 Handle timers.
virtual void handleLowerMsgStart (AirFrame *)
 Buffer the frame and update noise levels and snr information...
virtual void handleLowerMsgEnd (AirFrame *)
 Unbuffer the frame and update noise levels and snr information.

Protected Attributes

State state
 System state.
double meanGood
 mean value to compute the time the xystem stays in the GOOD state
double meanBad
 mean value to compute the time the xystem stays in the BAD state
cMessage * stateChange
 timer to indicate a change of state


Member Enumeration Documentation

enum GilbertElliotSnr::State [protected]

Gilbert-Elliot state types.

Enumerator:
GOOD 
BAD 
00067               {
00068       GOOD,
00069       BAD
00070     };


Constructor & Destructor Documentation

GilbertElliotSnr::GilbertElliotSnr (  ) 

00027 {
00028     stateChange = NULL;
00029 }

GilbertElliotSnr::~GilbertElliotSnr (  )  [virtual]

00032 {
00033     cancelAndDelete(stateChange);
00034 }


Member Function Documentation

void GilbertElliotSnr::handleLowerMsgEnd ( AirFrame frame  )  [protected, virtual]

Unbuffer the frame and update noise levels and snr information.

This function is called right after the transmission is over, i.e. right after unbuffering. The noise level of the channel and the snr information of the buffered messages have to be updated.

Additionally the RadioState has to be updated.

If the corresponding AirFrame was not only noise the corresponding SnrList and the AirFrame are sent to the decider.

Reimplemented from SnrEval.

00216 {
00217 
00218     //check state again:
00219     if (state == BAD)
00220         frame->setBitError(true);
00221 
00222     // check if message has to be send to the decider
00223     if (snrInfo.ptr == frame)
00224     {
00225         EV << "reception of frame over, preparing to send packet to upper layer\n";
00226         // get Packet and list out of the receive buffer:
00227         SnrList list;
00228         list = snrInfo.sList;
00229 
00230         // delete the pointer to indicate that no message is currently
00231         // being received and clear the list
00232         snrInfo.ptr = NULL;
00233         snrInfo.sList.clear();
00234 
00235         // delete the frame from the recvBuff
00236         recvBuff.erase(frame);
00237 
00238         //Don't forget to send:
00239         sendUp(frame, list);
00240         EV << "packet sent to the decider\n";
00241     }
00242     // all other messages are noise
00243     else
00244     {
00245         EV << "reception of noise message over, removing recvdPower from noiseLevel....\n";
00246         // get the rcvdPower and subtract it from the noiseLevel
00247         noiseLevel -= recvBuff[frame];
00248 
00249         // delete message from the recvBuff
00250         recvBuff.erase(frame);
00251 
00252         // update snr info for message currently being received if any
00253         if (snrInfo.ptr != NULL)
00254         {
00255             addNewSnr();
00256         }
00257 
00258         // message should be deleted
00259         delete frame;
00260         EV << "message deleted\n";
00261     }
00262 
00263     // check the RadioState and update if necessary
00264     // change to idle if noiseLevel smaller than threshold and state was
00265     // not idle before
00266     // do not change state if currently sending or receiving a message!!!
00267     if (noiseLevel < sensitivity && rs.getState() == RadioState::RECV && snrInfo.ptr == NULL)
00268     {
00269         // publish the new RadioState:
00270         EV << "new RadioState is IDLE\n";
00271         rs.setState(RadioState::IDLE);
00272         nb->fireChangeNotification(NF_RADIOSTATE_CHANGED, &rs);
00273     }
00274 }

void GilbertElliotSnr::handleLowerMsgStart ( AirFrame frame  )  [protected, virtual]

Buffer the frame and update noise levels and snr information...

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

First the receive power of the packet has to be calculated and is stored in the recvBuff. Afterwards it has to be decided whether the packet is just noise or a "real" packet that needs to be received.

The message is not treated as noise if all of the follwoing conditions apply:

  1. the power of the received signal is higher than the sensitivity.
  2. the host is currently not sending a message
  3. no other packet is already being received

If all conditions apply a new SnrList is created and the RadioState is changed to RECV. If the Gilbert Elliot model is in state BAD, the frame is marked as corrupted. The cMessage's bitError flag is used for it. If the packet is just noise the receive power is added to the noise Level of the channel. Additionally the snr information of the currently received message (if any) has to be updated as well as the RadioState.

Reimplemented from SnrEval.

00136 {
00137     // Calculate the receive power of the message
00138 
00139     // calculate distance
00140     const Coord& myPos = myPosition();
00141     const Coord& framePos = frame->getSenderPos();
00142     double distance = myPos.distance(framePos);
00143 
00144     // receive power
00145     double rcvdPower = calcRcvdPower(frame->getPSend(), distance);
00146 
00147     if (state == BAD)
00148         frame->setBitError(true);
00149 
00150     // store the receive power in the recvBuff
00151     recvBuff[frame] = rcvdPower;
00152 
00153     // if receive power is bigger than sensitivity and if not sending
00154     // and currently not receiving another message
00155     if (rcvdPower >= sensitivity && rs.getState() != RadioState::TRANSMIT && snrInfo.ptr == NULL)
00156     {
00157         EV << "receiving frame\n";
00158 
00159         // Put frame and related SnrList in receive buffer
00160         SnrList snrList;        //defined in SnrList.h!!
00161         snrInfo.ptr = frame;
00162         snrInfo.rcvdPower = rcvdPower;
00163         snrInfo.sList = snrList;
00164 
00165         // add initial snr value
00166         addNewSnr();
00167 
00168         if (rs.getState() != RadioState::RECV)
00169         {
00170             // publish new RadioState
00171             rs.setState(RadioState::RECV);
00172             EV << "publish new RadioState:RECV\n";
00173             nb->fireChangeNotification(NF_RADIOSTATE_CHANGED, &rs);
00174         }
00175     }
00176     // receive power is to low or another message is being send or received
00177     else
00178     {
00179         EV << "frame is just noise\n";
00180         //add receive power to the noise level
00181         noiseLevel += rcvdPower;
00182 
00183         // if a message is being received add a new snr value
00184         if (snrInfo.ptr != NULL)
00185         {
00186             // update snr info for currently being received message
00187             EV << "add new snr value to snr list of message being received\n";
00188             addNewSnr();
00189         }
00190 
00191         // update the RadioState if the noiseLevel exceeded the threshold
00192         // and the radio is currently not in receive or in send mode
00193         if (noiseLevel >= sensitivity && rs.getState() == RadioState::IDLE)
00194         {
00195             // publish new RadioState
00196             rs.setState(RadioState::RECV);
00197             EV << "publish new RadioState:RECV\n";
00198             nb->fireChangeNotification(NF_RADIOSTATE_CHANGED, &rs);
00199         }
00200     }
00201 }

void GilbertElliotSnr::handleSelfMsg ( cMessage *  msg  )  [protected, virtual]

Handle timers.

If the selfMsg is the time to indicate a transmission is over, the RadioState has to be changed based on the noise level on the channel. If the noise level is bigger than the sensitivity switch to receive mode otherwise to idle mode.

If the timer indicates a change of state in the Gilbert-Elliot model, the state variable has to be changed.

Reimplemented from SnrEval.

00067 {
00068     if (msg->kind() == TRANSM_OVER)
00069     {
00070 
00071         if (noiseLevel < sensitivity)
00072         {
00073             // set the RadioState to IDLE
00074             rs.setState(RadioState::IDLE);
00075             EV << "transmission over, switch to idle mode (state:IDLE)\n";
00076             nb->fireChangeNotification(NF_RADIOSTATE_CHANGED, &rs);
00077         }
00078         else
00079         {
00080             // set the RadioState to RECV
00081             rs.setState(RadioState::RECV);
00082             EV << "transmission over but noise level to high, switch to recv mode (state:RECV)\n";
00083             nb->fireChangeNotification(NF_RADIOSTATE_CHANGED, &rs);
00084         }
00085 
00086         // delete the timer
00087         delete msg;
00088     }
00089     else if (msg == stateChange)
00090     {
00091         EV << "GilbertElliot state changed!\n";
00092         if (state == GOOD)
00093         {
00094             state = BAD;
00095             for (RecvBuff::iterator it = recvBuff.begin(); it != recvBuff.end(); it++)
00096                 (it->first)->setBitError(true);
00097             scheduleAt(simTime() + exponential(meanBad, 0), stateChange);
00098         }
00099         else if (state == BAD)
00100         {
00101             state = GOOD;
00102             scheduleAt(simTime() + exponential(meanGood, 0), stateChange);
00103         }
00104     }
00105     else
00106         error("Internal error: unknown self-message `%s'", msg->name());
00107 }

void GilbertElliotSnr::initialize ( int  stage  )  [protected, virtual]

Initialize variables and publish the radio status.

All values not present in the ned file will be read from the ChannelControl module or assigned default values.

Reimplemented from SnrEval.

00041 {
00042     SnrEval::initialize(stage);
00043 
00044     if (stage == 0)
00045     {
00046         meanGood = par("meanGood");
00047         meanBad = par("meanBad");
00048         stateChange = new cMessage();
00049         stateChange->setKind(38);
00050         state = GOOD;
00051         scheduleAt(simTime() + exponential(meanGood, 0), stateChange);
00052         EV << "GE state will change at: " << stateChange->arrivalTime() << endl;
00053     }
00054 }


Member Data Documentation

double GilbertElliotSnr::meanBad [protected]

mean value to compute the time the xystem stays in the BAD state

double GilbertElliotSnr::meanGood [protected]

mean value to compute the time the xystem stays in the GOOD state

State GilbertElliotSnr::state [protected]

System state.

cMessage* GilbertElliotSnr::stateChange [protected]

timer to indicate a change of state


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:20:19 2007 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.7