User Manual, Developers Guide and API Documentation

Backoff.hpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * WiFiMac                                                                    *
00003  * This file is part of openWNS (open Wireless Network Simulator)
00004  * _____________________________________________________________________________
00005  *
00006  * Copyright (C) 2004-2007
00007  * Chair of Communication Networks (ComNets)
00008  * Kopernikusstr. 16, 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 WIFIMAC_LOWERMAC_TIMING_BACKOFF_HPP
00030 #define WIFIMAC_LOWERMAC_TIMING_BACKOFF_HPP
00031 
00032 #include <WIFIMAC/convergence/IChannelState.hpp>
00033 #include <WIFIMAC/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 wifimac { 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<wifimac::convergence::IChannelState>,
00064         public wns::Observer<wifimac::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     private:
00107 
00108         void startNewBackoffCountdown(wns::simulator::Time ifsDuration);
00109 
00111         void onTimeout();
00112 
00113         void waitForTimer(const wns::simulator::Time& waitDuration);
00114 
00115         void channelBusyDelay();
00116 
00117         BackoffObserver* backoffObserver;
00118         std::vector<BackoffObserver*> eobObserver;
00119 
00120         const wns::simulator::Time slotDuration;
00121         const wns::simulator::Time aifsDuration;
00122         const wns::simulator::Time eifsDuration;
00123 
00124         bool backoffFinished;
00125         bool transmissionWaiting;
00126         bool duringAIFS;
00127         bool rxError;
00128 
00129         const int cwMin;
00130         const int cwMax;
00131         int cw;
00132         wns::distribution::Uniform uniform;
00133         wns::logger::Logger logger;
00134         wns::simulator::Time aifsStart;
00135         bool channelIsBusy;
00136 
00137     protected:
00138         // For testing purpose this methods and variable is protected and may be
00139         // set by a special version of the backoff
00140         int counter;
00141     };
00142 } // timing
00143 } // lowerMAC
00144 } // wifimac
00145 
00146 #endif //  WIFIMAC_SCHEDULER_BACKOFF_HPP

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