User Manual, Developers Guide and API Documentation

ARF.cpp

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 #include <WIFIMAC/lowerMAC/rateAdaptationStrategies/ARF.hpp>
00030 #include <WIFIMAC/management/VirtualCapabilityInformationBase.hpp>
00031 
00032 #include <algorithm>
00033 
00034 using namespace wifimac::lowerMAC::rateAdaptationStrategies;
00035 
00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(ARF, IRateAdaptationStrategy, "ARF", IRateAdaptationStrategyCreator);
00037 
00038 ARF::ARF(
00039     const wns::pyconfig::View& _config,
00040     wns::service::dll::UnicastAddress _receiver,
00041     wifimac::management::PERInformationBase* _per,
00042     wifimac::management::SINRInformationBase* _sinr,
00043     wifimac::lowerMAC::Manager* _manager,
00044     wifimac::convergence::PhyUser* _phyUser,
00045     wns::logger::Logger* _logger):
00046     IRateAdaptationStrategy(_config, _receiver, _per, _sinr, _manager, _phyUser, _logger),
00047     myReceiver(_receiver),
00048     per(_per),
00049     arfTimer(_config.get<wns::simulator::Time>("arfTimer")),
00050     exponentialBackoff(_config.get<bool>("exponentialBackoff")),
00051     initialSuccessThreshold(_config.get<int>("initialSuccessThreshold")),
00052     maxSuccessThreshold(_config.get<int>("maxSuccessThreshold")),
00053     successThreshold(_config.get<int>("initialSuccessThreshold")),
00054     probePacket(false),
00055     logger(_logger),
00056     timeout(false)
00057 {
00058     friends.phyUser = _phyUser;
00059     curPhyMode = _config.getView("initialPhyMode");
00060 }
00061 
00062 wifimac::convergence::PhyMode
00063 ARF::getPhyMode(size_t numTransmissions, const wns::Ratio /*lqm*/) const
00064 {
00065     return(this->getPhyMode(numTransmissions));
00066 }
00067 
00068 wifimac::convergence::PhyMode
00069 ARF::getPhyMode(size_t numTransmissions) const
00070 {
00071     wifimac::convergence::PhyMode pm = curPhyMode;
00072 
00073     if(timeout)
00074     {
00075         friends.phyUser->getPhyModeProvider()->mcsUp(pm);
00076         return pm;
00077     }
00078 
00079     if((probePacket and numTransmissions == 2) or (numTransmissions >= 3))
00080     {
00081         // last one was a probe packet, but did not succeed
00082         friends.phyUser->getPhyModeProvider()->mcsDown(pm);
00083         return pm;
00084     }
00085 
00086     if(per->getSuccessfull(myReceiver) == successThreshold)
00087     {
00088         friends.phyUser->getPhyModeProvider()->mcsUp(pm);
00089         return pm;
00090     }
00091 
00092     return pm;
00093 }
00094 
00095 void
00096 ARF::setCurrentPhyMode(wifimac::convergence::PhyMode pm)
00097 {
00098     timeout = false;
00099 
00100     wifimac::convergence::PhyMode pmDown = curPhyMode;
00101     friends.phyUser->getPhyModeProvider()->mcsDown(pmDown);
00102 
00103     wifimac::convergence::PhyMode pmUp = curPhyMode;
00104     friends.phyUser->getPhyModeProvider()->mcsUp(pmUp);
00105 
00106     if(curPhyMode == pm)
00107     {
00108         probePacket = false;
00109         return;
00110     }
00111     else
00112     {
00113         assure(pm == pmDown or pm == pmUp,
00114                "pm " << pm << " is neither " << pmDown << " nor " << pmUp);
00115 
00116         if(this->hasTimeoutSet())
00117         {
00118             this->cancelTimeout();
00119         }
00120 
00121         if(pm == pmDown)
00122         {
00123             this->setTimeout(arfTimer);
00124 
00125             if(probePacket)
00126             {
00127                 // last one was a probe packet, but did not succeed
00128                 probePacket = false;
00129                 MESSAGE_SINGLE(NORMAL, *logger, "Last probe packet to " << myReceiver << " did not succeed, going down to MCS "<< pm);
00130                 if(exponentialBackoff and successThreshold < maxSuccessThreshold)
00131                 {
00132                     successThreshold = successThreshold*2;
00133                     MESSAGE_SINGLE(NORMAL, *logger, "Set successThreshold to " << successThreshold);
00134                 }
00135             }
00136             else
00137             {
00138                 MESSAGE_SINGLE(NORMAL, *logger, "Failed transmissions to " << myReceiver << " , going down to MCS "<< pm);
00139                 if(exponentialBackoff)
00140                 {
00141                     successThreshold = successThreshold / 2;
00142                     if(successThreshold < initialSuccessThreshold)
00143                     {
00144                         successThreshold = initialSuccessThreshold;
00145                     }
00146                     MESSAGE_SINGLE(NORMAL, *logger, "Set successThreshold to " << successThreshold);
00147                 }
00148             }
00149         }
00150         else
00151         {
00152             probePacket = true;
00153             MESSAGE_SINGLE(NORMAL, *logger, per->getSuccessfull(myReceiver) << " successfull transmissions to " << myReceiver << ", sending probe packet with " << pm);
00154         }
00155 
00156         per->reset(myReceiver);
00157         curPhyMode = pm;
00158 
00159     }
00160 }
00161 
00162 void
00163 ARF::onTimeout()
00164 {
00165     timeout = true;
00166     MESSAGE_SINGLE(NORMAL, *logger, "Timeout, set mcs up to " << curPhyMode);
00167 }

Generated on Mon May 21 03:32:14 2012 for openWNS by  doxygen 1.5.5