User Manual, Developers Guide and API Documentation

Backoff.hpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * Glue                                                                       *
00003  * __________________________________________________________________________ *
00004  *                                                                            *
00005  * Copyright (C) 2005-2006                                                    *
00006  * Lehrstuhl fuer Kommunikationsnetze (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 #ifndef GLUE_MAC_BACKOFF_HPP
00014 #define GLUE_MAC_BACKOFF_HPP
00015 
00016 #include <WNS/service/phy/copper/CarrierSensing.hpp>
00017 #include <WNS/Observer.hpp>
00018 
00019 #include <WNS/events/MemberFunction.hpp>
00020 #include <WNS/logger/Logger.hpp>
00021 #include <WNS/distribution/Uniform.hpp>
00022 #include <WNS/simulator/Time.hpp>
00023 #include <WNS/events/scheduler/IEvent.hpp>
00024 
00025 namespace glue { namespace mac {
00026 
00027     class BackoffObserver
00028     {
00029     public:
00030         virtual
00031         ~BackoffObserver()
00032         {}
00033 
00034         virtual void
00035         backoffExpired() = 0;
00036 
00037         // FIXME: should not be here
00038         virtual void
00039         onCarrierIdle()
00040         {}
00041     };
00042 
00046     class Backoff :
00047         public wns::Observer<wns::service::phy::copper::CarrierSensing>
00048     {
00049         typedef wns::events::MemberFunction<Backoff> LocalSignal;
00050 
00051     public:
00052         explicit
00053         Backoff(
00054             BackoffObserver* backoffObserver,
00055             wns::simulator::Time sifsLength,
00056             wns::simulator::Time slotLength,
00057             wns::simulator::Time ackLength,
00058             const wns::logger::Logger& _logger);
00059 
00060         virtual ~Backoff();
00061 
00062         virtual void    transmissionRequest(bool isRetransmission = false);
00063 
00064         virtual void    timerExpired();
00065 
00066         virtual void    onCarrierIdle();
00067 
00068         virtual void    onCarrierBusy();
00069 
00070         virtual void    onCollision();
00071 
00072         virtual bool    isCarrierIdle() const;
00073 
00074     private:
00075         void startNewBackoffCountdown(wns::simulator::Time ifsLength);
00076 
00077         void waitForTimer(wns::simulator::Time& waitLength);
00078 
00079         enum State {
00080             idle,
00081             inSIFS,
00082             inSlotCountdown,
00083             finished,
00084             waitingForCarrierIdle
00085         };
00086 
00087         enum CarrierSensingResult {
00088             carrierIdle,
00089             carrierBusy,
00090             carrierError
00091         };
00092 
00093         enum tTransmissionState {
00094             none,
00095             pending,
00096             transmitting
00097         };
00098 
00099         BackoffObserver* backoffObserver;
00100 
00101         wns::simulator::Time sifsLength;
00102         wns::simulator::Time slotLength;
00103         wns::simulator::Time ackLength;
00104         wns::simulator::Time difsLength;
00105         wns::simulator::Time eifsLength;
00106 
00107         State state;
00108         tTransmissionState transmissionState;
00109 
00110         int cwMin;
00111         int cwMax;
00112         int cw;
00113         wns::distribution::Uniform uniform;
00114         wns::events::scheduler::IEventPtr currentSignal;
00115         wns::logger::Logger logger;
00116         CarrierSensingResult carrierSenseResult;
00117 
00118         // For testing purpose this method and variable is protected and may be
00119         // set by a special version of the backoff
00120     protected:
00121         int counter;
00122         
00123     };
00124 } // mac
00125 } // glue
00126 
00127 #endif // GLUE_MAC_BACKOFF_HPP

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