User Manual, Developers Guide and API Documentation

Backoff.hpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * WiMeMac                                                                    *
00003  * This file is part of openWNS (open Wireless Network Simulator)
00004  * _____________________________________________________________________________
00005  *
00006  * Copyright (C) 2004-2011
00007  * Chair of Communication Networks (ComNets)
00008  * Kopernikusstr. 5, D-52074 Aachen, Germany
00009  * phone: ++49-241-80-27910,
00010  * fax: ++49-241-80-22242
00011  * email: info@openwns.org
00012  * www: http://www.openwns.org
00013  * _____________________________________________________________________________
00014  *
00015  * openWNS is free software; you can redistribute it and/or modify it under the
00016  * terms of the GNU Lesser General Public License version 2 as published by the
00017  * Free Software Foundation;
00018  *
00019  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00020  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00021  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00022  * details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00026  *
00027  ******************************************************************************/
00028 
00029 #ifndef WIMEMAC_LOWERMAC_TIMING_BACKOFF_HPP
00030 #define WIMEMAC_LOWERMAC_TIMING_BACKOFF_HPP
00031 
00032 #include <WIMEMAC/convergence/IChannelState.hpp>
00033 #include <WIMEMAC/convergence/IRxStartEnd.hpp>
00034 
00035 #include <WNS/Observer.hpp>
00036 
00037 #include <WNS/events/MemberFunction.hpp>
00038 #include <WNS/logger/Logger.hpp>
00039 #include <WNS/distribution/Uniform.hpp>
00040 #include <WNS/simulator/Time.hpp>
00041 #include <WNS/events/CanTimeout.hpp>
00042 
00043 namespace wimemac { namespace lowerMAC { namespace timing {
00044 
00045     class BackoffObserver
00046     {
00047     public:
00048         virtual
00049         ~BackoffObserver()
00050         {}
00051 
00052         virtual void backoffExpired() = 0;
00053     };
00054 
00061     class Backoff :
00062         public wns::events::CanTimeout,
00063         public wns::Observer<wimemac::convergence::IChannelState>,
00064         public wns::Observer<wimemac::convergence::IRxStartEnd>
00065     {
00066     public:
00067 
00068         Backoff(BackoffObserver* backoffObserver,
00069                 const wns::pyconfig::View& config);
00070 
00071         ~Backoff();
00072 
00074         bool
00075         transmissionRequest(int transmissionCounter);
00076 
00077         // observer RxStartEnd
00078         void
00079         onRxStart(wns::simulator::Time expRxTime);
00080         void
00081         onRxEnd();
00082         void
00083         onRxError();
00084 
00086         void
00087         onChannelBusy();
00088 
00090         void
00091         onChannelIdle();
00092 
00093         int getCurrentCW() const
00094         {
00095             return(cw);
00096         }
00097 
00100         wns::simulator::Time
00101         finishedAt() const;
00102 
00104         void
00105         registerEOBObserver(BackoffObserver * observer);
00106 
00107         void
00108         OnDRPreservationChange(bool isDRPreservationOn_);
00109     private:
00110 
00111         void startNewBackoffCountdown(wns::simulator::Time ifsDuration);
00112 
00114         void onTimeout();
00115 
00116         void waitForTimer(const wns::simulator::Time& waitDuration);
00117 
00118         void channelBusyDelay();
00119 
00120         BackoffObserver* backoffObserver;
00121         std::vector<BackoffObserver*> eobObserver;
00122 
00123         const wns::simulator::Time slotDuration;
00124         const wns::simulator::Time aifsDuration;
00125         const wns::simulator::Time eifsDuration;
00126 
00127         bool backoffFinished;
00128         bool transmissionWaiting;
00129         bool duringAIFS;
00130         bool rxError;
00131 
00132         bool isDRPreservationOn;
00133         bool wasChannelLastSensedBusyDuringDRP;
00134 
00135         const int cwMin;
00136         const int cwMax;
00137         int cw;
00138         wns::distribution::Uniform uniform;
00139         wns::logger::Logger logger;
00140         wns::simulator::Time aifsStart;
00141         bool channelIsBusy;
00142 
00143     protected:
00144         // For testing purpose this methods and variable is protected and may be
00145         // set by a special version of the backoff
00146         int counter;
00147     };
00148 } // timing
00149 } // lowerMAC
00150 } // wimemac
00151 
00152 #endif //  WIMEMAC_SCHEDULER_BACKOFF_HPP

Generated on Sun May 27 03:32:11 2012 for openWNS by  doxygen 1.5.5