User Manual, Developers Guide and API Documentation

WaitingForACKsBufferFull.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * WNS (Wireless Network Simulator)                                           *
00003  * __________________________________________________________________________ *
00004  *                                                                            *
00005  * Copyright (C) 2004-2006                                                    *
00006  * Chair of Communication Networks (ComNets)                                  *
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany                                 *
00008  * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242                   *
00009  * email: wns@comnets.rwth-aachen.de                                          *
00010  * www: http://wns.comnets.rwth-aachen.de                                     *
00011  ******************************************************************************/
00012 
00013 #include "WaitingForACKsBufferFull.hpp"
00014 #include "ReadyForTransmissionBufferPartlyFilled.hpp"
00015 #include "ReadyForTransmissionBufferEmpty.hpp"
00016 
00017 #include <WNS/Assure.hpp>
00018 #include <WNS/Exception.hpp>
00019 
00020 using namespace glue::arqfsm::selectiverepeat;
00021 using namespace wns::ldk;
00022 
00023 STATIC_FACTORY_REGISTER_WITH_CREATOR(WaitingForACKsBufferFull,
00024                      StateInterface,
00025                      "glue_arqfsm_selectiverepeat_WaitingForACKsBufferFull",
00026                      wns::fsm::FSMConfigCreator);
00027 
00028 StateInterface*
00029 WaitingForACKsBufferFull::onSendData(const CompoundPtr&)
00030 {
00031     assure(false, "onSendData may not be called in state WaitingForACKsBufferFull.");
00032     return this;
00033 } // onSendData
00034 
00035 
00036 StateInterface*
00037 WaitingForACKsBufferFull::onACK(int sequenceNumber)
00038 {
00039     MESSAGE_BEGIN(NORMAL, vars().logger, m, getFUNName());
00040     m << " Received ACK frame "
00041       << sequenceNumber;
00042     MESSAGE_END();
00043 
00044     if (sequenceNumber < 0 || sequenceNumber >= vars().sequenceNumberSize)
00045         throw wns::Exception("Sequence number out of bounds");
00046 
00047     CompoundPtr compound = vars().sentCompounds[sequenceNumber];
00048 
00049     if (compound)
00050     {
00051         FSMFU* fsmfu = dynamic_cast<FSMFU*>(getFU());
00052         if (fsmfu->hasTimeoutSet(compound))
00053             fsmfu->cancelTimeout(compound);
00054 
00055         vars().pendingCompoundsQueue.remove(compound);
00056 
00057         vars().sentCompounds[sequenceNumber] = CompoundPtr();
00058     }
00059 
00060     while (!vars().sentCompounds[vars().lowerBoundNS])
00061     {
00062         vars().lowerBoundNS = (vars().lowerBoundNS + 1) % vars().sequenceNumberSize;
00063 
00064         --vars().levelSendBuffer;
00065 
00066         if (vars().levelSendBuffer == 0)
00067         {
00068             sendWakeup();
00069             return getFSM()->createState<ReadyForTransmissionBufferEmpty>();
00070         }
00071     }
00072 
00073     if (vars().levelSendBuffer < vars().windowSize)
00074     {
00075         sendWakeup();
00076         return getFSM()->createState<ReadyForTransmissionBufferPartlyFilled>();
00077     }
00078 
00079     return this;
00080 } // onACK
00081 
00082 
00083 StateInterface*
00084 WaitingForACKsBufferFull::onWakeup()
00085 {
00086     tryToSendACKs();
00087     tryToSendIs();
00088     return this;
00089 } // onWakeup
00090 
00091 
00092 void
00093 WaitingForACKsBufferFull::onIsAccepting(bool& accepting) const
00094 {
00095     accepting = false;
00096 } // onIsAccepting
00097 
00098 
00099 StateInterface*
00100 WaitingForACKsBufferFull::onTimeout(const wns::ldk::CompoundPtr& compound)
00101 {
00102     if (std::find(vars().pendingCompoundsQueue.begin(),
00103               vars().pendingCompoundsQueue.end(),
00104               compound)
00105         == vars().pendingCompoundsQueue.end())
00106     {
00107         vars().pendingCompoundsQueue.push_back(compound);
00108     }
00109 
00110     tryToSendIs();
00111 
00112     return this;
00113 } // onTimeout
00114 
00115 

Generated on Sat May 26 03:31:56 2012 for openWNS by  doxygen 1.5.5