![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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/timing/DCF.hpp> 00030 00031 #include <WNS/ldk/Layer.hpp> 00032 #include <WNS/ldk/arq/ARQ.hpp> 00033 #include <WNS/service/phy/ofdma/Notification.hpp> 00034 #include <WNS/container/UntypedRegistry.hpp> 00035 00036 #include <DLL/UpperConvergence.hpp> 00037 00038 using namespace wifimac::lowerMAC::timing; 00039 00040 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00041 wifimac::lowerMAC::timing::DCF, 00042 wns::ldk::FunctionalUnit, 00043 "wifimac.lowerMAC.timing.DCF", 00044 wns::ldk::FUNConfigCreator); 00045 00046 DCF::DCF(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config_) : 00047 wns::ldk::fu::Plain<DCF, wns::ldk::EmptyCommand>(fun), 00048 csName(config_.get<std::string>("csName")), 00049 rxStartEndName(config_.get<std::string>("rxStartEndName")), 00050 arqCommandName(config_.get<std::string>("arqCommandName")), 00051 backoffDisabled(config_.get<bool>("myConfig.backoffDisabled")), 00052 backoff(this, config_), 00053 sendNow(false), 00054 logger(config_.get("logger")) 00055 { 00056 00057 } // DCF::DCF 00058 00059 00060 DCF::~DCF() 00061 { 00062 } // DCF::~DCF 00063 00064 void DCF::onFUNCreated() 00065 { 00066 if(not backoffDisabled) 00067 { 00068 // backoff observes the channel state 00069 backoff.wns::Observer<wifimac::convergence::IChannelState>::startObserving 00070 (getFUN()->findFriend<wifimac::convergence::ChannelStateNotification*>(csName)); 00071 00072 // backoff gets notified of failed receptions 00073 backoff.wns::Observer<wifimac::convergence::IRxStartEnd>::startObserving 00074 (getFUN()->findFriend<wifimac::convergence::RxStartEndNotification*>(rxStartEndName)); 00075 } 00076 } // DCF::onFUNCreated 00077 00078 void 00079 DCF::doSendData(const wns::ldk::CompoundPtr& compound) 00080 { 00081 assure(sendNow, 00082 "called doSendData, but sendNow is false"); 00083 sendNow = false; 00084 00085 assure(getConnector()->hasAcceptor(compound), 00086 "lower FU is not accepting"); 00087 00088 getConnector()->getAcceptor(compound)->sendData(compound); 00089 00090 } 00091 00092 void 00093 DCF::doOnData(const wns::ldk::CompoundPtr& compound) 00094 { 00095 // simply forward to the upper FU 00096 getDeliverer()->getAcceptor(compound)->onData(compound); 00097 } 00098 00099 bool 00100 DCF::doIsAccepting(const wns::ldk::CompoundPtr& compound) const 00101 { 00102 assure(not backoffDisabled, 00103 "Backoff was disabled, hence no frames can be accepted"); 00104 00105 if(sendNow and getConnector()->hasAcceptor(compound)) 00106 { 00107 return true; 00108 } 00109 if(getFUN()->getCommandReader(arqCommandName)->commandIsActivated(compound->getCommandPool())) 00110 { 00111 int numTransmissions = getFUN()->getCommandReader(arqCommandName)-> 00112 readCommand<wns::ldk::arq::ARQCommand>(compound->getCommandPool())->localTransmissionCounter; 00113 MESSAGE_SINGLE(NORMAL, logger, "Compound w activated arq command, transmission number " << numTransmissions); 00114 sendNow = backoff.transmissionRequest(numTransmissions); 00115 } 00116 else 00117 { 00118 MESSAGE_SINGLE(NORMAL, logger, "Compound w/o activated arq command -> assume first transmission"); 00119 sendNow = backoff.transmissionRequest(1); 00120 } 00121 00122 MESSAGE_SINGLE(NORMAL, logger, "backoff asked, sendNow is " << sendNow); 00123 00124 return(sendNow and getConnector()->hasAcceptor(compound)); 00125 } 00126 00127 void 00128 DCF::doWakeup() 00129 { 00130 getReceptor()->wakeup(); 00131 } 00132 00133 00134 void DCF::backoffExpired() 00135 { 00136 MESSAGE_SINGLE(NORMAL, logger, "Backoff expired, send wakeup"); 00137 this->sendNow = true; 00138 getReceptor()->wakeup(); 00139 }
1.5.5