![]() |
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/convergence/PreambleGenerator.hpp> 00030 #include <DLL/Layer2.hpp> 00031 00032 using namespace wifimac::convergence; 00033 00034 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00035 wifimac::convergence::PreambleGenerator, 00036 wns::ldk::FunctionalUnit, 00037 "wifimac.convergence.PreambleGenerator", 00038 wns::ldk::FUNConfigCreator); 00039 00040 PreambleGenerator::PreambleGenerator(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config_) : 00041 wns::ldk::fu::Plain<PreambleGenerator, PreambleGeneratorCommand>(fun), 00042 phyUserName(config_.get<std::string>("phyUserName")), 00043 protocolCalculatorName(config_.get<std::string>("protocolCalculatorName")), 00044 managerName(config_.get<std::string>("managerName")), 00045 logger(config_.get("logger")), 00046 pendingCompound(), 00047 pendingPreamble() 00048 { 00049 MESSAGE_SINGLE(NORMAL, this->logger, "created"); 00050 friends.manager = NULL; 00051 friends.phyUser = NULL; 00052 protocolCalculator = NULL; 00053 } 00054 00055 PreambleGenerator::~PreambleGenerator() 00056 { 00057 00058 } 00059 00060 void 00061 PreambleGenerator::onFUNCreated() 00062 { 00063 MESSAGE_SINGLE(NORMAL, this->logger, "onFUNCreated() started"); 00064 00065 friends.phyUser = getFUN()->findFriend<wifimac::convergence::PhyUser*>(phyUserName); 00066 friends.manager = getFUN()->findFriend<wifimac::lowerMAC::Manager*>(managerName); 00067 protocolCalculator = getFUN()->getLayer<dll::ILayer2*>()->getManagementService<wifimac::management::ProtocolCalculator>(protocolCalculatorName); 00068 friends.manager = getFUN()->findFriend<wifimac::lowerMAC::Manager*>(managerName); 00069 } 00070 00071 void 00072 PreambleGenerator::processIncoming(const wns::ldk::CompoundPtr& compound) 00073 { 00074 if(friends.manager->getFrameType(compound->getCommandPool()) == PREAMBLE) 00075 { 00076 MESSAGE_SINGLE(NORMAL, this->logger, "Received PREAMBLE -> drop"); 00077 } 00078 else 00079 { 00080 // deliver frame 00081 getDeliverer()->getAcceptor(compound)->onData(compound); 00082 } 00083 } 00084 00085 void 00086 PreambleGenerator::processOutgoing(const wns::ldk::CompoundPtr& compound) 00087 { 00088 // compute transmission duration of the frame, dependent on the mcs 00089 wifimac::convergence::PhyMode phyMode = 00090 friends.manager->getPhyMode(compound->getCommandPool()); 00091 wns::simulator::Time frameTxDuration = 00092 protocolCalculator->getDuration()->MPDU_PPDU(compound->getLengthInBits(), phyMode) - 00093 protocolCalculator->getDuration()->preamble(phyMode); 00094 00095 // First we generate a preamble 00096 this->pendingPreamble = compound->copy(); 00097 friends.manager->setFrameType(this->pendingPreamble->getCommandPool(), 00098 PREAMBLE); 00099 friends.manager->setPhyMode(this->pendingPreamble->getCommandPool(), 00100 friends.phyUser->getPhyModeProvider()->getPreamblePhyMode(phyMode)); 00101 friends.manager->setFrameExchangeDuration(this->pendingPreamble->getCommandPool(), 00102 frameTxDuration); 00103 PreambleGeneratorCommand* preambleCommand = activateCommand(this->pendingPreamble->getCommandPool()); 00104 preambleCommand->peer.frameId = compound->getBirthmark(); 00105 00106 MESSAGE_SINGLE(NORMAL, logger, "Outgoing preamble with frame tx duration " << frameTxDuration); 00107 00108 this->pendingCompound = compound; 00109 } 00110 00111 const wns::ldk::CompoundPtr 00112 PreambleGenerator::hasSomethingToSend() const 00113 { 00114 if(this->pendingPreamble) 00115 { 00116 assure(this->pendingCompound, "Pending preamble but no pending compound"); 00117 return(this->pendingPreamble); 00118 } 00119 return(this->pendingCompound); 00120 } 00121 00122 wns::ldk::CompoundPtr 00123 PreambleGenerator::getSomethingToSend() 00124 { 00125 assure(this->pendingCompound, "Called getSomethingToSend without pending compound"); 00126 00127 wns::ldk::CompoundPtr myFrame; 00128 if(this->pendingPreamble) 00129 { 00130 assure(this->pendingCompound, "Pending preamble but no pending compound"); 00131 myFrame = this->pendingPreamble; 00132 this->pendingPreamble = wns::ldk::CompoundPtr(); 00133 MESSAGE_SINGLE(NORMAL, logger, "Sending preamble"); 00134 } 00135 else 00136 { 00137 myFrame = this->pendingCompound; 00138 this->pendingCompound = wns::ldk::CompoundPtr(); 00139 MESSAGE_SINGLE(NORMAL, logger, "Sending psdu"); 00140 } 00141 return(myFrame); 00142 } 00143 00144 bool 00145 PreambleGenerator::hasCapacity() const 00146 { 00147 return(this->pendingCompound == wns::ldk::CompoundPtr()); 00148 } 00149 00150 void 00151 PreambleGenerator::calculateSizes(const wns::ldk::CommandPool* commandPool, Bit& commandPoolSize, Bit& dataSize) const 00152 { 00153 if(friends.manager->getFrameType(commandPool) == PREAMBLE) 00154 { 00155 commandPoolSize = 0; 00156 dataSize = 0; 00157 } 00158 else 00159 { 00160 getFUN()->getProxy()->calculateSizes(commandPool, commandPoolSize, dataSize, this); 00161 } 00162 }
1.5.5