![]() |
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 00030 #include <WIMEMAC/drp/DRPmap.hpp> 00031 00032 00033 00034 using namespace wimemac::drp; 00035 00036 DRPmap::DRPmap(int globalMASpSF) 00037 00038 { 00039 globalSoftDRPmap.assign(globalMASpSF,false); 00040 globalHardDRPmap.assign(globalMASpSF,false); 00041 globalEraseDRPmap.assign(globalMASpSF,false); 00042 00043 mMaxLostBeacons = 3; 00044 numberOfBPSlots = 1; 00045 isPatternValid = true; 00046 00047 // Initialise with empty reservation maps 00048 Vector empty_(globalMASpSF,false); 00049 globalHardDRPmapVec.push_back(empty_); 00050 globalSoftDRPmapVec.push_back(empty_); 00051 globalEraseDRPmapVec.push_back(empty_); 00052 } 00053 00054 00055 void 00056 DRPmap::SetLogger(wns::logger::Logger _logger) 00057 { 00058 logger = _logger; 00059 } 00060 00061 void 00062 DRPmap::UpdateHardDRPmap(Vector UpdateHard, wns::logger::Logger _logger) 00063 { 00064 logger = _logger; 00065 for(int i = 0; i < UpdateHard.size(); i++) 00066 { 00067 if(UpdateHard[i] == true && globalEraseDRPmap[i] == true) 00068 UpdateHard[i] = false; 00069 00070 } 00071 // Update mapVector 00072 UpdateDRPmap(UpdateHard, globalHardDRPmapVec.back()); 00073 // Update current used hard reservation map 00074 UpdateDRPmap(UpdateHard, globalHardDRPmap); 00075 00076 } 00077 00078 void 00079 DRPmap::UpdateSoftDRPmap(Vector UpdateSoft, wns::logger::Logger _logger) 00080 { 00081 logger = _logger; 00082 // Update mapVector 00083 UpdateDRPmap(UpdateSoft, globalSoftDRPmapVec.back()); 00084 // Update current used soft reservation map 00085 UpdateDRPmap(UpdateSoft, globalSoftDRPmap); 00086 } 00087 00088 void 00089 DRPmap::onBPStarted() 00090 { 00091 isPatternValid = true; 00092 00093 // Fill globalDRPmaps with reservations received during the last mMaxLostBeacons beacons 00094 for (int i = 0; i < globalHardDRPmap.size(); i++) 00095 { 00096 bool hardSlot = false; 00097 int hardCount = 0; 00098 for(int k = 0; k < globalHardDRPmapVec.size(); k++) 00099 { 00100 assure(i < (globalHardDRPmapVec[k]).size(), "Vector boundary exeeded; loop error!"); 00101 if ((globalHardDRPmapVec[k])[i] == true) hardCount += 1; 00102 } 00103 if(hardCount >= 1) hardSlot = true; 00104 00105 bool softSlot = false; 00106 int softCount = 0; 00107 for(int l = 0; l < globalSoftDRPmapVec.size(); l++) 00108 { 00109 assure(i < (globalHardDRPmapVec[l]).size(), "Vector boundary exeeded; loop error!"); 00110 if ((globalSoftDRPmapVec[l])[i] == true) softCount += 1; 00111 } 00112 if(softCount >= 1) softSlot = true; 00113 00114 bool eraseSlot = false; 00115 int eraseCount = 0; 00116 for(int k = 0; k < globalEraseDRPmapVec.size(); k++) 00117 { 00118 assure(i < (globalEraseDRPmapVec[k]).size(), "Vector boundary exeeded; loop error!"); 00119 if ((globalEraseDRPmapVec[k])[i] == true) eraseCount += 1; 00120 } 00121 if(hardCount >= 1) hardSlot = true; 00122 00123 globalHardDRPmap[i] = hardSlot; 00124 globalSoftDRPmap[i] = softSlot; 00125 globalEraseDRPmap[i] = eraseSlot; 00126 00127 if(globalEraseDRPmap[i] == true && (globalHardDRPmap[i] == true || globalSoftDRPmap[i] == true)) 00128 { 00129 globalHardDRPmap[i] == false; 00130 globalSoftDRPmap[i] == false; 00131 } 00132 00133 } 00134 00135 // Put new empty vector into queue for the next beacons reservations 00136 Vector empty_(globalHardDRPmap.size(), false); 00137 globalHardDRPmapVec.push_back(empty_); 00138 globalSoftDRPmapVec.push_back(empty_); 00139 globalEraseDRPmapVec.push_back(empty_); 00140 // Refill last drpmap in vector with BP slots 00141 setBPSlots(numberOfBPSlots); 00142 00143 if( globalHardDRPmapVec.size() > mMaxLostBeacons) 00144 globalHardDRPmapVec.pop_front(); 00145 if( globalSoftDRPmapVec.size() > mMaxLostBeacons) 00146 globalSoftDRPmapVec.pop_front(); 00147 if( globalEraseDRPmapVec.size() > mMaxLostBeacons) 00148 globalEraseDRPmapVec.pop_front(); 00149 00150 00151 } 00152 00153 bool 00154 DRPmap::isPatternValidated() 00155 { 00156 return isPatternValid; 00157 } 00158 00159 void 00160 DRPmap::setBPSlots(int numberOfBPSlots_) 00161 { 00162 numberOfBPSlots = numberOfBPSlots_; 00163 00164 for (int i = 0; i < numberOfBPSlots; i++) 00165 { 00166 (globalHardDRPmapVec.back())[i] = true; 00167 (globalSoftDRPmapVec.back())[i] = true; 00168 } 00169 } 00170 00171 Vector 00172 DRPmap::GetGlobalHardDRPmap() 00173 { 00174 GetPattern(logger); 00175 return globalHardDRPmap; 00176 } 00177 00178 void 00179 DRPmap::UpdateDRPmap(Vector UpdateMap, Vector& UpdatedMap) 00180 { 00181 Vector::iterator it1 = UpdateMap.begin(); 00182 Vector::iterator it2 = UpdatedMap.begin(); 00183 00184 for(it1, it2; it1!=UpdateMap.end() || it2 != UpdatedMap.end() ; ++it1, ++it2) 00185 { 00186 *it2 = *it1 | *it2; 00187 } 00188 MESSAGE_SINGLE(NORMAL, logger, "Update DRPMap"); 00189 } 00190 00191 bool 00192 DRPmap::PossiblePattern(Vector CompareDRPMap) 00193 { 00194 Vector::iterator it1 = globalHardDRPmap.begin(); 00195 Vector::iterator it2 = globalSoftDRPmap.begin(); 00196 Vector::iterator it3 = CompareDRPMap.begin(); 00197 00198 for(it1, it2, it3; it1!=globalHardDRPmap.end() || it2 != globalSoftDRPmap.end() || it3 != CompareDRPMap.end() ; ++it1, ++it2,++it3) 00199 { 00200 if((*it1 || *it2) && *it3 == true) 00201 return false; 00202 } 00203 return true; 00204 } 00205 00206 void 00207 DRPmap::GetPattern(wns::logger::Logger _logger) 00208 { 00209 logger = _logger; 00210 for(int i = 0; i< 256; i++) 00211 { 00212 00213 assure(i < globalHardDRPmap.size(), "Vector boundary exeeded; loop error!"); 00214 if((globalHardDRPmap[i]) == true) 00215 MESSAGE_SINGLE(NORMAL, logger, "Get Pattern Slot Nr "<<i << " is occupied"); 00216 } 00217 } 00218 00219 void 00220 DRPmap::GetGlobalPattern(Vector& GlobalPattern) 00221 { 00222 DRPmap::GetPattern(logger); 00223 for(int i = 0; i<globalHardDRPmap.size() ; i++) 00224 { 00225 GlobalPattern[i] = globalHardDRPmap[i] || globalSoftDRPmap[i]; 00226 } 00227 00228 } 00229 00230 bool 00231 DRPmap::IsSpaceInGlobalPattern() 00232 { 00233 for(int i = 0; i<globalHardDRPmap.size() ; i++) 00234 { 00235 if(globalHardDRPmap[i] == false && globalSoftDRPmap[i] == false) 00236 return true; 00237 } 00238 return false; 00239 }
1.5.5