![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * WiMeMac * 00003 * This file is part of openWNS (open Wireless Network Simulator) 00004 * _____________________________________________________________________________ 00005 * 00006 * Copyright (C) 2004-2011 00007 * Chair of Communication Networks (ComNets) 00008 * Kopernikusstr. 5, 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 <WIMEMAC/management/BeaconBuilder.hpp> 00030 #include <DLL/Layer2.hpp> 00031 00032 00033 00034 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00035 wimemac::management::BeaconBuilder, 00036 wns::ldk::FunctionalUnit, 00037 "wimemac.management.BeaconBuilder", 00038 wns::ldk::FUNConfigCreator ); 00039 00040 using namespace wimemac::management; 00041 00042 BeaconBuilder::BeaconBuilder( wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config_ ) : 00043 wns::ldk::fu::Plain<BeaconBuilder, BeaconCommand>(fun), 00044 logger(config_.get("logger")), 00045 currentBeacon(), 00046 beaconPhyMode(config_.getView("beaconPhyMode")), 00047 managerName(config_.get<std::string>("managerName")), 00048 MASProbe(new wns::probe::bus::ContextCollector(wns::probe::bus::ContextProviderCollection(&fun->getLayer()->getContextProviderCollection()), "wimemac.bb.numberOfMAS")), 00049 allocatedMASProbe(new wns::probe::bus::ContextCollector(wns::probe::bus::ContextProviderCollection(&fun->getLayer()->getContextProviderCollection()), "wimemac.allocatedMAS")) 00050 { 00051 friends.keyReader = fun->getProxy()->getCommandReader("upperConvergence"); 00052 BeaconEvaluator::SetLogger(logger); 00053 00054 } 00055 00056 BeaconBuilder::~BeaconBuilder() 00057 { 00058 // Write allocated MASs into text probe 00059 std::stringstream outputStr; 00060 outputStr << " STA ID: " << tmpID << " allocated MASs: [ "; 00061 bool hasMASallocated = false; 00062 00063 Vector drpMap_ = getAllocatedMASs(); 00064 for (int i = 0; i < drpMap_.size(); i++) 00065 { 00066 if (drpMap_[i] == true) 00067 { 00068 outputStr << i << ", "; 00069 hasMASallocated = true; 00070 } 00071 } 00072 outputStr << "]"; 00073 if (hasMASallocated) allocatedMASProbe->put(0.0, boost::make_tuple("wimemac.allocatedMAS", outputStr.str())); 00074 } 00075 00076 void 00077 BeaconBuilder::doOnData( const wns::ldk::CompoundPtr& compound ) 00078 { 00079 00080 wns::ldk::CommandPool* commandPool = compound->getCommandPool(); 00081 00082 wns::service::dll::UnicastAddress iam 00083 = getFUN()->findFriend<dll::UpperConvergence*>("upperConvergence")->getMACAddress(); 00084 00085 dll::UpperCommand* uc = 00086 friends.keyReader->readCommand<dll::UpperCommand>(commandPool); 00087 wns::service::dll::UnicastAddress tx = uc->peer.sourceMACAddress; 00088 00089 //evaluate beacon, only Beacon Command is necessary 00090 if(tx != iam) 00091 { 00092 BeaconEvaluator::BeaconExamination(tx, iam, getCommand(compound->getCommandPool()),logger); 00093 } 00094 } 00095 00096 bool 00097 BeaconBuilder::doIsAccepting( const wns::ldk::CompoundPtr& ) const 00098 { 00099 } 00100 00101 void 00102 BeaconBuilder::doSendData( const wns::ldk::CompoundPtr& compound ) 00103 { 00104 if(!getConnector()->hasAcceptor(compound)){ 00105 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: can't send Beacon!"); 00106 00107 } 00108 else{ 00109 getConnector()->getAcceptor(compound)->sendData(compound); 00110 //MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: Beacon sent, waiting for Phy to finish!"); 00111 } 00112 } 00113 00114 void 00115 BeaconBuilder::onFUNCreated() 00116 { 00117 friends.queueInterface= 00118 getFUN()->findFriend<wimemac::helper::IDRPQueueInterface*>("DRPScheduler"); 00119 00120 friends.Upper = 00121 getFUN()->findFriend<dll::UpperConvergence*>("upperConvergence"); 00122 00123 friends.manager = getFUN()->findFriend<wimemac::lowerMAC::Manager*>(managerName); 00124 tmpID = friends.manager->getMACAddress(); 00125 00126 BeaconEvaluator::setFriend(friends.queueInterface); 00127 BeaconEvaluator::setManagerFriend(friends.manager); 00128 00129 } 00130 00131 void 00132 BeaconBuilder::doWakeup() 00133 { 00134 00135 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: Wakeup called!"); 00136 00137 //Evaluate PER for established connections 00138 evaluatePERforConnections(); 00139 00140 //Inform DRPmapManager about a new BP start 00141 DRPmapManager->onBPStarted(); 00142 friends.manager->onBPStart(BPDuration); 00143 00144 //Check DRPmapManager if pattern is validated 00145 if(DRPmapManager->isPatternValidated() == true) 00146 { 00147 //Evaluate unestablished connection patterns 00148 BeaconEvaluator::EvaluateConnection(); 00149 //create new drp maps if nessecary 00150 BeaconEvaluator::CreateDRPMaps(); 00151 } 00152 else MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: There might be an ongoing change in the DRPmap -> wait another SF before creating a new drp pattern or evaluating a reservation map!"); 00153 00154 //Create beacon compound and send beacon 00155 doSendData(CreateBeacon()); 00156 00157 } 00158 00159 bool 00160 BeaconBuilder::isBeacon(const wns::ldk::CommandPool* commandPool) const 00161 { 00162 return getFUN()->getCommandReader("BeaconCommand")->commandIsActivated(commandPool); 00163 } 00164 00165 void 00166 BeaconBuilder::calculateSizes(const wns::ldk::CommandPool* commandPool, Bit& commandPoolSize, Bit& sduSize) const 00167 { 00168 commandPoolSize = 0; 00169 sduSize = 8*8; // Beacon Parameter size 00170 sduSize += 8*(1+1+1+ ceil(NumberOfBPSlots/4) + 2*NumberOfBPSlots); // mandatory BPOIE 00171 00172 if(getCommand(commandPool)->HasAvailabilityIE()) 00173 { 00174 // add size for DRP Availability IE 00175 sduSize += 8*34; // assume maximum size; Actually it differs between 2-34 octets 00176 } 00177 if(getCommand(commandPool)->HasDRPIE()) 00178 { 00179 // add size for DRP IE(s) 00180 sduSize += 8*10 * getCommand(commandPool)->GetDRPIESize(); // assume 1 DRP allocation per DRP IE. Each DRP Allocation adds 4 octets 00181 } 00182 if(getCommand(commandPool)->HasProbeIE()) 00183 { 00184 // add size for Probe IE 00185 sduSize += 5*8; 00186 } 00187 } 00188 00189 wns::ldk::CompoundPtr 00190 BeaconBuilder::CreateBeacon() 00191 { 00192 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: Create beacon"); 00193 00194 wns::ldk::CompoundPtr compound = friends.manager->createCompound(friends.manager->getMACAddress(), wns::service::dll::UnicastAddress(), BEACON, true, 0.0); 00195 friends.manager->setPhyMode(compound->getCommandPool(), beaconPhyMode); 00196 00197 BeaconCommand* bc = activateCommand(compound->getCommandPool()); 00198 00199 //ask for established and new drp connections 00200 if(BeaconEvaluator::CreateDRPIE(getCommand(compound->getCommandPool()))) 00201 { 00202 //DRPIE is included 00203 getCommand(compound->getCommandPool())->peer.HasDRPIE = true; 00204 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: insert a DRPIE ");//at least one DRPIE inserted 00205 } 00206 if(BeaconEvaluator::CreateBPOIE(getCommand(compound->getCommandPool()))) 00207 { 00208 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: insert a Beacon Period Occupancy IE "); 00209 } 00210 00211 // attach DRP Availability IE to beacon if it's requested by a Probe IE 00212 if(requestedProbes.drpAvailability > 0) 00213 { 00214 Vector drpAvailability_ (256, false); 00215 DRPmapManager->GetGlobalPattern(drpAvailability_); 00216 00217 requestedProbes.drpAvailability--; 00218 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: insert a DRP Availability IE | replying to probe the next " << requestedProbes.drpAvailability << " following beacons"); 00219 00220 // Switch values so that available slots are marked as true 00221 for (int i = 0; i < 256; i++) 00222 { 00223 assure(i < drpAvailability_.size(), "Vector boundary exeeded; loop error!"); 00224 drpAvailability_[i] = !(drpAvailability_[i]); 00225 } 00226 00227 getCommand(compound->getCommandPool())->peer.availabilityBitmap = drpAvailability_; 00228 getCommand(compound->getCommandPool())->peer.HasAvailabilityIE = true; 00229 00230 } 00231 00232 if(BeaconEvaluator::CreateProbeIE(getCommand(compound->getCommandPool()))) 00233 { 00234 //Probe IE is included 00235 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: insert a Probe IE "); //for one or more IEs and receivers 00236 } 00237 00238 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: Beacon has a size of : " << compound->getLengthInBits()); 00239 return compound; 00240 } 00241 00242 void 00243 BeaconBuilder::BuildDTPmap() 00244 { 00245 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: BP is over and now build a new DTP map!"); 00246 int numberOfMASReserved = BeaconEvaluator::CollectDRPmaps(BPDuration); 00247 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: Reserved Slots : " << numberOfMASReserved); 00248 MASProbe->put(numberOfMASReserved); 00249 00250 //to do: it's a workaround to catch the BP end signal, this function call is at the wrong position here 00251 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: BP is over and now find possible parallel users!"); 00252 00253 friends.manager->UpdateDRPMap(DRPmapManager->GetGlobalHardDRPmap()); 00254 } 00255 00256 void 00257 BeaconBuilder::prepareDRPConnection(wns::service::dll::UnicastAddress rx, int CompoundspSF, int BitspSF, int MaxCompoundSize) 00258 { 00259 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: prepareDRPConnection!"); 00260 wimemac::convergence::PhyMode defPhyMode_ = friends.manager->getDefaultPhyMode(); 00261 BeaconEvaluator::CreateDRPManager(rx,CompoundspSF,BitspSF,MaxCompoundSize, defPhyMode_); 00262 } 00263 00264 void 00265 BeaconBuilder::updateDRPConnection(wns::service::dll::UnicastAddress rx, int CompoundspSF, int BitspSF, int MaxCompoundSize) 00266 { 00267 MESSAGE_SINGLE(NORMAL, logger, "BeaconBuilder: updateDRPConnection!"); 00268 BeaconEvaluator::UpdateDRPManager(rx,CompoundspSF,BitspSF,MaxCompoundSize); 00269 } 00270
1.5.5