![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #ifndef WNS_SCHEDULER_SCHEDULERTYPES_HPP 00029 #define WNS_SCHEDULER_SCHEDULERTYPES_HPP 00030 00031 00032 #include <WNS/service/dll/StationTypes.hpp> 00033 #include <WNS/service/phy/ofdma/Pattern.hpp> 00034 #include <WNS/service/phy/phymode/PhyModeInterface.hpp> 00035 #include <WNS/ldk/Command.hpp> 00036 #include <WNS/ldk/Compound.hpp> 00037 #include <WNS/ldk/FunctionalUnit.hpp> 00038 #include <WNS/ldk/Classifier.hpp> 00039 #include <WNS/node/Node.hpp> 00040 #include <WNS/PowerRatio.hpp> 00041 #include <WNS/CandI.hpp> 00042 #include <WNS/Enum.hpp> 00043 #include <WNS/SmartPtr.hpp> 00044 00045 #include <map> 00046 #include <vector> 00047 #include <set> 00048 #include <list> 00049 #include <string> 00050 #include <sstream> 00051 00052 namespace wns { namespace scheduler { 00053 class MapInfoEntry; // forward declaration 00054 namespace strategy { 00055 class StrategyInput; 00056 class StrategyInterface; 00057 } 00058 00059 class UserID: 00060 public wns::IOutputStreamable 00061 { 00062 public: 00063 explicit UserID() { node_ = NULL; isBroadcast_ = false; }; 00064 00065 UserID(const UserID& other) { node_ = other.node_; isBroadcast_ = other.isBroadcast_; } 00066 00067 explicit UserID(wns::node::Interface* node) { node_ = node; isBroadcast_ = false; }; 00068 00069 virtual ~UserID() {}; 00070 00071 bool 00072 isValid() const 00073 { 00074 if (!isBroadcast() && node_ != NULL) 00075 { 00076 return true; 00077 } 00078 if (isBroadcast() && node_ == NULL) 00079 { 00080 return true; 00081 } 00082 return false; 00083 } 00084 00085 void 00086 setBroadcast() 00087 { 00088 isBroadcast_ = true; 00089 } 00090 00091 bool 00092 isBroadcast() const 00093 { 00094 return isBroadcast_; 00095 } 00096 00097 std::string 00098 getName() const 00099 { 00100 if (node_ != NULL) 00101 { 00102 return node_->getName(); 00103 } 00104 else 00105 { 00106 if (isBroadcast()) 00107 { 00108 return "Broadcast"; 00109 } 00110 } 00111 return "Unknown"; 00112 } 00113 00114 wns::node::Interface* 00115 getNode() const 00116 { 00117 assure(!isBroadcast(), "You asked for a Node of a broadcast user. This is invalid. Use isBroadcast() to check prior to your code"); 00118 assure(isValid(), "UserID is invalid. You cannot ask for the node here. Use isValid() to check prior to your code"); 00119 return node_; 00120 } 00121 00122 int 00123 getNodeID() const 00124 { 00125 assure(!isBroadcast(), "You asked for a NodeID of a broadcast user. This is invalid. Use isBroadcast() to check prior to your code"); 00126 assure(isValid(), "UserID is invalid. You cannot ask for the NodeID here. Use isValid() to check prior to your code"); 00127 return node_->getNodeID(); 00128 } 00129 00130 bool 00131 operator== (const UserID& other) const 00132 { 00133 return ( (node_ == other.node_) && (isBroadcast() == other.isBroadcast())); 00134 } 00135 00136 bool 00137 operator!= (const UserID& other) const 00138 { 00139 return !((*this) == other); 00140 } 00141 00142 bool 00143 operator< (const UserID& other) const 00144 { 00145 if (node_ == other.node_) 00146 { 00147 return isBroadcast() != other.isBroadcast(); 00148 } 00149 else 00150 { 00151 return (node_ < other.node_); 00152 } 00153 } 00154 00155 void 00156 operator= (const UserID& other) 00157 { 00158 node_ = other.node_; 00159 isBroadcast_ = other.isBroadcast_; 00160 } 00161 00162 wns::probe::bus::ContextProviderCollection& 00163 getContextProviderCollection() const 00164 { 00165 assure(!isBroadcast(), "You asked for a ContextProviderCollection of a broadcast user. This is invalid. Use isBroadcast() to check prior to your code"); 00166 assure(isValid(), "UserID is invalid. You cannot ask for the ContextProviderCollection here. Use isValid() to check prior to your code"); 00167 return node_->getContextProviderCollection(); 00168 } 00169 00170 private: 00171 00172 virtual std::string 00173 doToString() const 00174 { 00175 return getName(); 00176 } 00177 00178 wns::node::Interface* node_; 00179 00180 bool isBroadcast_; 00181 }; 00182 00183 const simTimeType slotLengthRoundingTolerance = 1e-12; 00184 const int subChannelNotFound = -1; 00185 00186 typedef int Symbols; 00187 typedef int Bits; 00188 00190 typedef enum { 00191 PowerControlDLMaster, 00192 PowerControlULMaster, 00193 PowerControlULSlave 00194 } PowerControlType; 00195 // wns::scheduler::PowerControlType 00196 00198 // wns::scheduler::SchedulerSpot 00199 ENUM_BEGIN(SchedulerSpot); 00200 ENUM(DLMaster, 1); 00201 ENUM(ULMaster, 2); 00202 ENUM(ULSlave, 3); 00203 ENUM_END(); 00204 // wns::scheduler::SchedulerSpot::DLMaster() 00205 // wns::scheduler::SchedulerSpot::toString() 00207 typedef int SchedulerSpotType; 00208 // allow switch-case statements: 00209 static const SchedulerSpotType SchedulerSpotDLMaster=wns::scheduler::SchedulerSpot::DLMaster(); 00210 static const SchedulerSpotType SchedulerSpotULMaster=wns::scheduler::SchedulerSpot::ULMaster(); 00211 static const SchedulerSpotType SchedulerSpotULSlave=wns::scheduler::SchedulerSpot::ULSlave(); 00212 00214 ENUM_BEGIN(TaskBSorUT); 00215 ENUM(TaskBaseStation, 1); 00216 ENUM(TaskUserTerminal, 2); 00217 ENUM_END(); 00218 // wns::scheduler::TaskBSorUT::TaskBaseStation() 00219 // wns::scheduler::TaskBSorUT::toString() 00221 typedef int TaskBSorUTType; 00222 00223 typedef std::list<wns::ldk::CompoundPtr> CompoundList; 00224 typedef wns::ldk::ClassificationID ConnectionID; 00225 typedef std::vector<ConnectionID> ConnectionVector; 00226 typedef std::list <ConnectionID> ConnectionList; 00227 typedef std::set <ConnectionID> ConnectionSet; 00228 typedef std::set <UserID> UserSet; 00230 typedef std::map <UserID, wns::CandI> Group; 00231 typedef std::vector<bool> UsableSubChannelVector; 00232 00233 inline std::string 00234 printBoolVector(const std::vector<bool>& boolVector) { 00235 std::stringstream s; 00236 for (std::vector<bool>::const_iterator iter = boolVector.begin(); iter != boolVector.end(); ++iter) 00237 { 00238 s << (*iter) ? 1:0; 00239 } 00240 return s.str(); 00241 } 00242 00243 inline std::string 00244 printGroup(const wns::scheduler::Group& group) { 00245 std::stringstream s; 00246 s << "Group("; 00247 for (Group::const_iterator iter = group.begin(); iter != group.end(); ) 00248 { 00249 s << iter->first.getName(); 00250 if (++iter != group.end()) s << ","; 00251 } 00252 s << ")"; 00253 return s.str(); 00254 } 00255 00256 inline std::string 00257 printUserSet(const wns::scheduler::UserSet& userSet) { 00258 std::stringstream s; 00259 s << "UserSet("; 00260 for (UserSet::const_iterator iter = userSet.begin(); iter != userSet.end(); ) 00261 { 00262 s << iter->getName(); 00263 if (++iter != userSet.end()) s << ","; 00264 } 00265 s << ")"; 00266 return s.str(); 00267 } 00268 00269 inline std::string 00270 printConnectionVector(const wns::scheduler::ConnectionVector& connectionVector) { 00271 std::stringstream s; 00272 s << "ConnectionVector("; 00273 for (ConnectionVector::const_iterator iter = connectionVector.begin(); iter != connectionVector.end(); ) 00274 { 00275 s << (*iter); 00276 if (++iter != connectionVector.end()) s << ","; 00277 } 00278 s << ")"; 00279 return s.str(); 00280 } 00281 00282 inline std::string 00283 printConnectionList(const wns::scheduler::ConnectionList& connectionList) { 00284 std::stringstream s; 00285 s << "ConnectionList("; 00286 for (ConnectionList::const_iterator iter = connectionList.begin(); iter != connectionList.end(); ) 00287 { 00288 s << (*iter); 00289 if (++iter != connectionList.end()) s << ","; 00290 } 00291 s << ")"; 00292 return s.str(); 00293 } 00294 00295 inline std::string 00296 printConnectionSet(const wns::scheduler::ConnectionSet& connectionSet) { 00297 std::stringstream s; 00298 s << "ConnectionSet("; 00299 for (ConnectionSet::const_iterator iter = connectionSet.begin(); iter != connectionSet.end(); ) 00300 { 00301 s << (*iter); 00302 if (++iter != connectionSet.end()) s << ","; 00303 } 00304 s << ")"; 00305 return s.str(); 00306 } 00307 00309 inline std::ostream& 00310 operator<< (std::ostream& s, const wns::scheduler::Group& group) { 00311 s << "Group("; 00312 for (Group::const_iterator iter = group.begin(); iter != group.end(); ) 00313 { 00314 s << iter->first.getName(); 00315 if (++iter != group.end()) s << ","; 00316 } 00317 s << ")"; 00318 return s; 00319 } 00320 00323 struct PowerCapabilities 00324 { 00325 PowerCapabilities() : 00326 maxPerSubband(), 00327 nominalPerSubband(), 00328 maxOverall() 00329 {} 00330 00331 explicit 00332 PowerCapabilities(const wns::pyconfig::View& config) : 00333 maxOverall(config.get<wns::Power>("maxOverall")), 00334 maxPerSubband(config.get<wns::Power>("maxPerSubband")), 00335 nominalPerSubband(config.get<wns::Power>("nominalPerSubband")) 00336 {} 00337 00339 wns::Power maxOverall; 00341 wns::Power maxPerSubband; 00343 wns::Power nominalPerSubband; 00344 }; // PowerCapabilities 00345 00348 struct PowerAllocation { 00349 wns::Power txPowerPerSubband; 00350 UserID user; 00351 unsigned long int maxNumSubbands; 00352 double resourceShare; 00353 00354 PowerAllocation() : 00355 txPowerPerSubband(), 00356 user(), 00357 maxNumSubbands(), 00358 resourceShare() 00359 {} 00360 00361 std::string 00362 toString() const 00363 { 00364 std::stringstream ss; 00365 ss << user.getName() << ": " << maxNumSubbands << " simultaneously with " << txPowerPerSubband << " each." << std::endl; 00366 return ss.str(); 00367 } 00368 }; // PowerAllocation 00369 00370 typedef std::map<UserID, PowerAllocation> PowerMap; 00371 typedef std::map<UserID, wns::service::phy::ofdma::PatternPtr> AntennaPatternsPerUser; 00372 00373 class Grouping 00374 : virtual public wns::RefCountable 00375 { 00376 public: 00377 Grouping() {}; 00378 00379 ~Grouping() {}; 00380 00381 std::string getDebugOutput() { 00382 std::stringstream ss; 00383 for (unsigned int i = 0; i < groups.size(); ++i) { 00384 ss << "Group" << i << "("; 00385 for (Group::iterator iter = groups[i].begin(); 00386 iter != groups[i].end(); 00387 ++iter) 00388 ss << (*iter).first.getName() << " @ " 00389 << (*iter).second.C / (*iter).second.I << ", )" << std::endl; 00390 } 00391 return ss.str(); 00392 } 00393 00394 wns::Ratio shareOfPowerPerStreams(unsigned int groupNumber){ 00395 00396 return shareOfPowerPerStreams( groups.at(groupNumber) ); 00397 00398 } 00399 00400 wns::Ratio shareOfPowerPerStreams(Group group){ 00401 // transmitting multiple streams the available Tx power 00402 // is shared among all streams 00403 assure( !group.empty() , "group does not exists"); 00404 00405 unsigned int concurrentStreams = group.size(); 00406 return wns::Ratio().from_factor(1.0 / concurrentStreams); 00407 } 00408 00409 wns::Ratio eirpReductionOfPower(unsigned int groupNumber){ 00410 00411 return eirpReductionOfPower( groups.at(groupNumber) ); 00412 00413 } 00414 00415 wns::Ratio eirpReductionOfPower(Group group){ 00416 // in EIRP limited spectrum, the maximum adaptive 00417 // antenna gain of the sum of all patterns have to be 00418 // normalised to one 00419 assure( !group.empty() , "group does not exists"); 00420 00421 wns::service::phy::ofdma::SumPattern sumPattern; 00422 assure(sumPattern.getSize() == 0, "new sum pattern is not empty"); 00423 00424 for (Group::iterator itr = group.begin(); 00425 itr != group.end(); 00426 itr++) { 00427 wns::service::phy::ofdma::PatternPtr patternOfUser = patterns[itr->first]; 00428 // In case of no beamforming, adding the invalid 00429 // pattern would fail, therefore we avoid it 00434 if (patternOfUser != wns::service::phy::ofdma::PatternPtr()) 00435 sumPattern.add(patternOfUser); 00436 } 00437 // again, for no beamforming we return the standard factor 00438 if (sumPattern.getSize() == 0) 00439 return wns::Ratio().from_factor( 1 ); 00440 00441 return wns::Ratio().from_factor( 1 / sumPattern.getMaxGain().get_factor() ); 00442 } 00443 00444 AntennaPatternsPerUser patterns; 00445 std::vector<Group> groups; 00446 std::map<UserID, int> userGroupNumber; // what group is user in 00447 }; // Grouping 00448 // a copy of the original structure is bad for memory/time 00449 typedef SmartPtr<Grouping> GroupingPtr; 00450 00452 struct QueueStatus { 00453 QueueStatus() 00454 { 00455 numOfBits = 0; 00456 numOfCompounds = 0; 00457 } 00458 00459 unsigned int numOfBits; 00460 unsigned int numOfCompounds; 00461 }; 00463 typedef wns::container::Registry<ConnectionID, QueueStatus> QueueStatusContainer; 00464 00466 class ChannelQualityOnOneSubChannel 00467 { 00468 public: 00469 ChannelQualityOnOneSubChannel(): 00470 pathloss(), 00471 interference(), 00472 carrier() 00473 { 00474 sdma.iIntra = wns::Power(); 00475 } 00476 00477 ChannelQualityOnOneSubChannel(wns::Ratio _pathloss, 00478 wns::Power _interference, 00479 wns::Power _carrier, 00480 wns::Power _iIntra = wns::Power::from_mW(0.0)): 00481 pathloss(_pathloss), 00482 interference(_interference), 00483 carrier(_carrier) 00484 { 00485 sdma.iIntra = _iIntra; 00486 } 00487 00489 wns::Power carrier; 00491 wns::Ratio pathloss; 00493 wns::Power interference; 00494 struct { 00495 // estimated intra-cell interference 00496 wns::Power iIntra; 00497 } sdma; 00498 }; // ChannelQualityOnOneSubChannel 00499 00500 //typedef std::vector<ChannelQualityOnOneSubChannel> ChannelsQualitiesOnAllSubBand; // index is real(OFDMA) subchannel number 00501 class ChannelQualitiesOnAllSubBands 00502 : virtual public wns::RefCountable, 00503 public std::vector<ChannelQualityOnOneSubChannel> 00504 { 00505 public: 00506 ChannelQualitiesOnAllSubBands() {}; 00507 ~ChannelQualitiesOnAllSubBands() {}; 00508 }; 00510 typedef SmartPtr<ChannelQualitiesOnAllSubBands> ChannelQualitiesOnAllSubBandsPtr; 00511 00512 //typedef std::map<UserID, ChannelsQualitiesOnAllSubBand*> ChannelQualitiesOfAllUsers; 00513 class ChannelQualitiesOfAllUsers 00514 : virtual public wns::RefCountable, 00515 public std::map<UserID, ChannelQualitiesOnAllSubBandsPtr> 00516 { 00517 public: 00518 ChannelQualitiesOfAllUsers() {}; 00519 ~ChannelQualitiesOfAllUsers() {}; 00520 virtual bool knowsUser(UserID user) { 00521 return (find(user) != end()); } 00522 }; 00523 typedef SmartPtr<ChannelQualitiesOfAllUsers> ChannelQualitiesOfAllUsersPtr; 00524 00526 class BetterChannelQuality 00527 { 00528 public: 00530 bool operator()(wns::scheduler::ChannelQualityOnOneSubChannel a, wns::scheduler::ChannelQualityOnOneSubChannel b) 00531 { 00532 if (a.pathloss == wns::Ratio()) { 00533 return false; 00534 } 00535 if (b.pathloss == wns::Ratio()) { // undefined 00536 return true; // a is better if b is undefined 00537 } 00538 return a.pathloss.get_factor() * a.interference.get_mW() 00539 < b.pathloss.get_factor() * b.interference.get_mW(); 00540 } 00541 }; 00542 00544 class BetterChannelCapacity 00545 { 00546 public: 00548 bool operator()(double a, double b) 00549 { 00550 if (a == 0.0) { 00551 return false; 00552 } 00553 if (b == 0.0) { // undefined 00554 return true; // a is better if b is undefined 00555 } 00556 00557 return a>b; 00558 } 00559 }; 00560 00561 }} // namespace wns::scheduler 00562 #endif // WNS_SCHEDULER_SCHEDULERTYPES_HPP 00563 00564
1.5.5