![]() |
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/drp/DRPManager.hpp> 00030 00031 #include <WIMEMAC/lowerMAC/Manager.hpp> 00032 00033 using namespace wimemac::drp; 00034 using wimemac::management::BeaconCommand; 00035 00036 00037 DRPManager::DRPManager(wns::service::dll::UnicastAddress TargetAddress,BeaconCommand::ReservationType InitialType, 00038 BeaconCommand::ReasonCode InitialReason, BeaconCommand::DeviceType InitialDevice, Vector DRPSlotMap, 00039 helper::IDRPQueueInterface* _QueueInterface, wns::logger::Logger logger_, wimemac::lowerMAC::Manager* manager_, int numberOfBPSlots_, bool useRateAdaptation_, double patternPEROffset_, wimemac::convergence::PhyMode DefPhyMode): 00040 00041 DRPPatternCreator(logger_, patternPEROffset_, TargetAddress), 00042 00043 reasoncode(InitialReason), 00044 reservationtype(InitialType), 00045 devicetype(InitialDevice), 00046 peerAddress(TargetAddress), 00047 DRPAllocMap(DRPSlotMap), 00048 QueueInterface(_QueueInterface), 00049 connectionstatus(false), 00050 mergeconnectionstatus(false), 00051 waitSFsForNewAvailIE(-1), 00052 hasPendingDRPMerge(false), 00053 needsAdditionalPattern(false), 00054 useRateAdaptation(useRateAdaptation_), 00055 logger(logger_) 00056 { 00057 scheduler = wns::simulator::getEventScheduler(); 00058 DRPPatternCreator::friends.manager = manager_; 00059 DRPPatternCreator::SetNumberOfBPSlots(numberOfBPSlots_); 00060 DRPPatternCreator::SetPhyMode(DefPhyMode); 00061 00062 tmpDRPMergeMap = Vector(DRPSlotMap.size(), false); 00063 } 00064 00065 DRPManager::DRPManager(wns::service::dll::UnicastAddress TargetAddress,BeaconCommand::ReservationType InitialType, 00066 BeaconCommand::ReasonCode InitialReason, BeaconCommand::DeviceType InitialDevice, Vector DRPSlotMap, 00067 helper::IDRPQueueInterface* _QueueInterface, wns::logger::Logger logger_, wimemac::lowerMAC::Manager* manager_, int numberOfBPSlots_, bool useRateAdaptation_, double patternPEROffset_): 00068 00069 DRPPatternCreator(logger_, patternPEROffset_, TargetAddress), 00070 00071 reasoncode(InitialReason), 00072 reservationtype(InitialType), 00073 devicetype(InitialDevice), 00074 peerAddress(TargetAddress), 00075 DRPAllocMap(DRPSlotMap), 00076 QueueInterface(_QueueInterface), 00077 connectionstatus(false), 00078 mergeconnectionstatus(false), 00079 waitSFsForNewAvailIE(-1), 00080 hasPendingDRPMerge(false), 00081 needsAdditionalPattern(false), 00082 useRateAdaptation(useRateAdaptation_), 00083 logger(logger_) 00084 { 00085 scheduler = wns::simulator::getEventScheduler(); 00086 DRPPatternCreator::SetNumberOfBPSlots(numberOfBPSlots_); 00087 DRPPatternCreator::friends.manager = manager_; 00088 00089 tmpDRPMergeMap = Vector(DRPSlotMap.size(), false); 00090 00091 } 00092 00093 wns::service::dll::UnicastAddress DRPManager::GetAddress() 00094 { 00095 return peerAddress; 00096 } 00097 00098 void 00099 DRPManager::SetReservationType(BeaconCommand::ReservationType DRPResType) 00100 { 00101 reservationtype = DRPResType; 00102 } 00103 00104 BeaconCommand::ReservationType 00105 DRPManager::GetReservationType() 00106 { 00107 return reservationtype; 00108 } 00109 00110 void 00111 DRPManager::SetReasonCode(BeaconCommand::ReasonCode reason) 00112 { 00113 reasoncode = reason; 00114 00115 } 00116 00117 BeaconCommand::ReasonCode 00118 DRPManager::GetReasonCode() 00119 { 00120 return reasoncode; 00121 } 00122 00123 void 00124 DRPManager::SetMergeReasonCode(BeaconCommand::ReasonCode reason) 00125 { 00126 mergereasoncode = reason; 00127 00128 } 00129 00130 BeaconCommand::ReasonCode 00131 DRPManager::GetMergeReasonCode() 00132 { 00133 return mergereasoncode; 00134 } 00135 00136 bool 00137 DRPManager::areMASsAvailable(Vector DRPGlobal) 00138 { 00139 for(int i = 0; i<DRPGlobal.size(); i++) 00140 { 00141 // MASs are available if there is space in the global MAP 00142 if(DRPGlobal[i] == true) 00143 return true; 00144 } 00145 return false; 00146 00147 } 00148 00149 void 00150 DRPManager::FindNewPattern(Vector DRPGlobal) 00151 { 00152 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00153 m << "Alloc"; 00154 MESSAGE_END(); 00155 00156 bool peerStationsIsFullyAvailable = true; 00157 00158 Vector::iterator itg; 00159 Vector::const_iterator itp; 00160 00161 00162 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00163 m << "DRPManager searches for a new reservation pattern ";MESSAGE_END(); 00164 00165 // Update DRPGlobal with DRP Availability from peer 00166 if (friends.manager->UpdateMapWithPeerAvailabilityMap( peerAddress, DRPGlobal)) 00167 { 00168 MESSAGE_SINGLE(NORMAL, logger, "FindPattern: Updated DRPGlobalMap with availabilityMap from address " << peerAddress << " to support ongoing pattern creation"); 00169 peerStationsIsFullyAvailable = false; 00170 } 00171 //else MESSAGE_SINGLE(NORMAL, logger, "FindPattern: There is no availabilityMap to update with or none of the available slots are unusable by address " << peerAddress); 00172 00173 if(DRPPatternCreator::GetPattern(DRPAllocMap,DRPGlobal, true)) 00174 { 00175 MESSAGE_SINGLE(NORMAL, logger, "FindPattern: A perfect pattern was found!"); 00176 } 00177 else 00178 MESSAGE_SINGLE(NORMAL, logger, "FindPattern: There was no perfect pattern found! Proceeding with imperfect pattern"); 00179 00180 } 00181 00182 void 00183 DRPManager::CreateAdditionalPattern(Vector DRPGlobal) 00184 { 00185 // Initialise this new pattern with reason code accept 00186 SetMergeReasonCode(BeaconCommand::Accept); 00187 bool peerStationsIsFullyAvailable = true; 00188 00189 Vector::iterator itg; 00190 Vector::const_iterator itp; 00191 00192 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00193 m << "DRPManager searches for an additional reservation pattern ";MESSAGE_END(); 00194 00195 00196 // Update DRPGlobal with DRP Availability from peer 00197 if (friends.manager->UpdateMapWithPeerAvailabilityMap( peerAddress, DRPGlobal)) 00198 { 00199 MESSAGE_SINGLE(NORMAL, logger, "AddPattern: Updated DRPGlobalMap with availabilityMap from address " << peerAddress << " to support ongoing pattern creation"); 00200 peerStationsIsFullyAvailable = false; 00201 } 00202 else MESSAGE_SINGLE(NORMAL, logger, "AddPattern: There is no availabilityMap to update with or none of the available slots are unusable by address " << peerAddress); 00203 00204 if(DRPPatternCreator::AddPattern(tmpDRPMergeMap, DRPAllocMap, DRPGlobal, true)) 00205 { 00206 MESSAGE_SINGLE(NORMAL, logger, "AddPattern: A perfect pattern was found!"); 00207 } 00208 else 00209 MESSAGE_SINGLE(NORMAL, logger, "AddPattern: There was no perfect pattern found! Proceeding with inperfect pattern"); 00210 00211 hasPendingDRPMerge = true; 00212 needsAdditionalPattern = false; 00213 00214 } 00215 00216 void 00217 DRPManager::SetPattern(Vector DRPreservation) 00218 { 00219 DRPAllocMap = DRPreservation; 00220 } 00221 00222 void 00223 DRPManager::SetMergePattern(Vector DRPreservation) 00224 { 00225 tmpDRPMergeMap = DRPreservation; 00226 } 00227 00228 Vector 00229 DRPManager::GetPattern() 00230 { 00231 return DRPAllocMap; 00232 } 00233 00234 Vector 00235 DRPManager::GetMergePattern() 00236 { 00237 return tmpDRPMergeMap; 00238 } 00239 00240 void 00241 DRPManager::ResolveConflict() 00242 { 00243 for(int i = 0; i < DRPAllocMap.size(); i++) 00244 { 00245 DRPAllocMap[i] = false; 00246 } 00247 00248 SetStatus(false); 00249 SetReasonCode(BeaconCommand::Modified); 00250 } 00251 00252 void 00253 DRPManager::ResolveMergeConflict() 00254 { 00255 for(int i = 0; i < tmpDRPMergeMap.size(); i++) 00256 { 00257 tmpDRPMergeMap[i] = false; 00258 } 00259 SetMergeStatus(false); 00260 SetMergeReasonCode(BeaconCommand::Modified); 00261 } 00262 00263 void 00264 DRPManager::SetDeviceType(BeaconCommand::DeviceType deviceType) 00265 { 00266 devicetype = deviceType; 00267 } 00268 00269 BeaconCommand::DeviceType 00270 DRPManager::GetDeviceType() 00271 { 00272 return devicetype; 00273 } 00274 00275 BeaconCommand::DeviceType GetDeviceType(); 00276 00277 void 00278 DRPManager::StartRegisterReservation(wns::simulator::Time BPDuration) 00279 { 00280 tmpDRPAllocMap = DRPAllocMap; 00281 RegisterReservation(BPDuration); 00282 } 00283 00284 void 00285 DRPManager::SetStatus(bool ConnectionStatus) 00286 { 00287 connectionstatus = ConnectionStatus; 00288 } 00289 00290 00291 bool 00292 DRPManager::GetStatus() 00293 { 00294 return connectionstatus; 00295 } 00296 00297 void 00298 DRPManager::SetMergeStatus(bool ConnectionStatus) 00299 { 00300 mergeconnectionstatus = ConnectionStatus; 00301 } 00302 00303 bool 00304 DRPManager::GetMergeStatus() 00305 { 00306 return mergeconnectionstatus; 00307 } 00308 00309 bool 00310 DRPManager::IsMapCreated() 00311 { 00312 if(find(DRPAllocMap.begin(), DRPAllocMap.end(), true) == DRPAllocMap.end()) 00313 return false; 00314 else 00315 return true; 00316 } 00317 00318 bool 00319 DRPManager::NeedsAdditionalPattern() 00320 { 00321 00322 if ((DRPPatternCreator::CalcMissingPackets(DRPAllocMap) > 0) && !hasPendingDRPMerge) 00323 return true; 00324 00325 if (needsAdditionalPattern) 00326 { // The status was set to create a new pattern 00327 00328 if (DRPPatternCreator::CalcMissingPackets(DRPAllocMap) <= 0) 00329 { 00330 // Needs additional pattern was probably set because of a MCS change. The Pattern however still suffices 00331 needsAdditionalPattern = false; 00332 return false; 00333 } 00334 00335 if (hasPendingDRPMerge) 00336 { 00337 // There is still an ongoing merge in progress -> wait until its over 00338 MESSAGE_SINGLE(NORMAL, logger, "There is still a merge in progress, waiting with pattern creation until it's over"); 00339 return false; 00340 } 00341 else return true; 00342 } 00343 else return false; 00344 } 00345 00346 bool 00347 DRPManager::HasPendingDRPMerge() 00348 { 00349 if(find(tmpDRPMergeMap.begin(), tmpDRPMergeMap.end(), true) == tmpDRPMergeMap.end()) 00350 { 00351 // If the station got an update regarding the link quality an additional drp pattern is created. 00352 // However, if the pattern is still sufficient hasPendingDRPMerge would be true, but there would 00353 // be no additional Map -> no signalling for a mergemap is required 00354 hasPendingDRPMerge = false; 00355 return false; 00356 } 00357 else 00358 return hasPendingDRPMerge; 00359 } 00360 00361 void 00362 DRPManager::AddReservation(wimemac::management::BeaconCommand::ReasonCode mergeReasonCode_, Vector mergeMap_) 00363 { 00364 hasPendingDRPMerge = true; 00365 tmpDRPMergeMap = mergeMap_; 00366 mergereasoncode = mergeReasonCode_; 00367 } 00368 00369 void 00370 DRPManager::MergePatterns() 00371 { 00372 // Merge original and additional DRP Maps 00373 Vector::iterator it1 = tmpDRPMergeMap.begin(); 00374 Vector::iterator it2 = DRPAllocMap.begin(); 00375 00376 for(it1, it2; it1!= tmpDRPMergeMap.end() || it2 != DRPAllocMap.end() ; ++it1, ++it2) 00377 { 00378 *it2 = *it1 | *it2; 00379 } 00380 MESSAGE_SINGLE(NORMAL, logger, "Merging DRP Maps"); 00381 00382 for(int i = 0; i < tmpDRPMergeMap.size(); i++) 00383 { 00384 tmpDRPMergeMap[i] = false; 00385 } 00386 00387 mergeconnectionstatus = false; 00388 hasPendingDRPMerge = false; 00389 } 00390 00391 void 00392 DRPManager::UpdatePhyModeDown(wimemac::convergence::PhyMode phyMode_) 00393 { 00394 00395 if (useRateAdaptation) 00396 { 00397 MESSAGE_SINGLE(NORMAL, logger, "Switching to a lower PhyMode with data rate " << phyMode_.getDataRate() << " Mb/s"); 00398 // Update the phymode and recalculate the traffic characteristic 00399 DRPPatternCreator::SetPhyMode(phyMode_); 00400 DRPPatternCreator::UpdateTrafficChar(); 00401 00402 // phymode was changed -> create a new pattern for drp 00403 needsAdditionalPattern = true; 00404 } 00405 else MESSAGE_SINGLE(NORMAL, logger, "Rate Adaptation is switched off!"); 00406 00407 } 00408 00409 void 00410 DRPManager::RegisterReservation(wns::simulator::Time BPDuration) 00411 { 00412 int adjacent = 0; 00413 double MASduration = 256E-6; 00414 int i = 0; 00415 00416 while(i < tmpDRPAllocMap.size()) 00417 { 00418 00419 if(tmpDRPAllocMap[i] == true) 00420 { 00421 if(adjacent == 0) 00422 { 00423 ReservationStart = i * MASduration - BPDuration; 00424 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00425 m << "Start MAS " << i << " with PhyMode " << DRPPatternCreator::getPhyMode(); 00426 MESSAGE_END(); 00427 } 00428 00429 assure(i<tmpDRPAllocMap.size(), "Vector boundary exeeded; loop error!"); 00430 tmpDRPAllocMap[i] = false; 00431 adjacent++; 00432 } 00433 else 00434 { 00435 if(adjacent != 0) 00436 { 00437 break; 00438 } 00439 } 00440 i++; 00441 } 00442 00443 if(adjacent != 0) 00444 { 00445 duration = adjacent * MASduration - 1E-12; 00446 00447 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00448 m << "The Timer-duration is set to " << duration << ". There are " << adjacent << " adjacent slots."; 00449 MESSAGE_END(); 00450 00451 adjacent = 0; 00452 wns::events::scheduler::Callable call = boost::bind(&DRPManager::Transmit, this, duration); 00453 scheduler->scheduleDelay(call, ReservationStart); 00454 00455 00456 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00457 m << "Set reservation timer " 00458 <<" Start Time: " << ReservationStart 00459 <<" Duration: " << duration; 00460 MESSAGE_END(); 00461 00462 } 00463 else 00464 { 00465 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00466 m << "There are no more MAS reserved in this superframe"; 00467 MESSAGE_END(); 00468 } 00469 if(i < tmpDRPAllocMap.size()) 00470 RegisterReservation(BPDuration); 00471 00472 00473 } 00474 00475 00476 void 00477 DRPManager::Transmit(wns::simulator::Time duration) 00478 { 00479 MESSAGE_BEGIN(NORMAL, logger, m, ""); 00480 m << "It's time to transmit for mac " << peerAddress; 00481 MESSAGE_END(); 00482 00483 //its time to transmit, signal 00484 QueueInterface->TimeToTransmit(peerAddress, duration); 00485 }
1.5.5