![]() |
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-2009 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 #include <WNS/scheduler/strategy/staticpriority/SubStrategyInterface.hpp> 00029 #include <WNS/scheduler/strategy/StaticPriority.hpp> 00030 #include <WNS/scheduler/strategy/Strategy.hpp> 00031 #include <WNS/scheduler/strategy/SchedulerState.hpp> 00032 #include <WNS/scheduler/SchedulingMap.hpp> 00033 #include <WNS/scheduler/SchedulerTypes.hpp> 00034 #include <WNS/pyconfig/View.hpp> 00035 00036 #include <vector> 00037 #include <map> 00038 #include <algorithm> 00039 #include <iostream> 00040 #include <set> 00041 00042 using namespace wns::scheduler; 00043 using namespace wns::scheduler::strategy; 00044 using namespace wns::scheduler::strategy::staticpriority; 00045 00046 STATIC_FACTORY_REGISTER_WITH_CREATOR(StaticPriority, 00047 StrategyInterface, 00048 "StaticPriority", 00049 wns::PyConfigViewCreator); 00050 00051 StaticPriority::StaticPriority(const wns::pyconfig::View& config): 00052 Strategy(config), 00053 numberOfPriorities(0), 00054 subStrategies(), 00055 resourceUsage(0.0) 00056 { 00057 MESSAGE_SINGLE(NORMAL, logger, "StaticPriority() instance created."); 00058 } 00059 00060 StaticPriority::~StaticPriority() 00061 { 00062 for (int priority = 0; priority<numberOfPriorities; ++priority) 00063 { 00064 if (subStrategies[priority] != NULL) 00065 { 00066 delete subStrategies[priority]; 00067 } 00068 } 00069 } 00070 00071 float 00072 StaticPriority::getResourceUsage() const 00073 { 00074 return resourceUsage; 00075 } 00076 00077 // inherited by base class Strategy to do first-time initialization: 00078 void 00079 StaticPriority::onColleaguesKnown() 00080 { 00081 Strategy::onColleaguesKnown(); // must be done in every derived method 00082 numberOfPriorities = colleagues.registry->getNumberOfPriorities(); 00083 00084 // loop over all priorities and initialize subStrategies 00085 assure(numberOfPriorities == pyConfig.len("subStrategies"), 00086 "numberOfPriorities=" << numberOfPriorities 00087 << " != "<<pyConfig.len("subStrategies")); 00088 00089 MESSAGE_SINGLE(NORMAL, logger, "StaticPriority::onColleaguesKnown(), numberOfPriorities = " << numberOfPriorities); 00090 00091 for (int priority = 0; priority<numberOfPriorities; ++priority) 00092 { 00093 wns::pyconfig::View substrategyView = pyConfig.getView("subStrategies",priority); 00094 std::string substrategyName = substrategyView.get<std::string>("__plugin__"); 00095 MESSAGE_SINGLE(NORMAL, logger, "subStrategy[" << priority << "]=" << substrategyName); 00096 wns::scheduler::strategy::staticpriority::SubStrategyInterface* substrategy = NULL; 00097 if (substrategyName.compare("NONE") != 0) 00098 { 00099 // create the subscheduling strategy for this priority: 00100 wns::scheduler::strategy::staticpriority::SubStrategyCreator* subStrategyCreator; 00101 subStrategyCreator = wns::scheduler::strategy::staticpriority::SubStrategyFactory::creator(substrategyName); 00102 substrategy = subStrategyCreator->create(substrategyView); 00103 } 00104 else 00105 { 00106 substrategy = NULL; 00107 } 00108 subStrategies.push_back(substrategy); 00109 } // for all priorities 00110 00111 SchedulerStatePtr schedulerState = getSchedulerState(); 00112 // priority is out of [0..MaxPriority-1]: 00113 for (int priority = 0; priority < numberOfPriorities; ++priority) 00114 { 00115 MESSAGE_SINGLE(NORMAL, logger, "initializing subStrategy[" << priority << "]"); 00116 wns::scheduler::strategy::staticpriority::SubStrategyInterface* substrategy = subStrategies[priority]; 00117 00118 assure(substrategy != NULL, "The substrategy[" << priority << "] is not accessible"); 00119 00120 substrategy->setColleagues(this, colleagues.queue, colleagues.registry, colleagues.harq); 00121 } 00122 } 00123 00124 StrategyResult 00125 StaticPriority::doStartScheduling(SchedulerStatePtr schedulerState, 00126 SchedulingMapPtr schedulingMap) 00127 { 00128 assure(numberOfPriorities > 0,"illegal numberOfPriorities=" << numberOfPriorities); 00129 int frameNr = schedulerState->currentState->strategyInput->getFrameNr(); 00130 MESSAGE_SINGLE(NORMAL, logger, "StaticPriority::doStartScheduling(frame=" 00131 << frameNr << "):" 00132 << " numberOfPriorities="<<numberOfPriorities); 00133 00134 colleagues.queue->frameStarts(); 00135 00136 // prepare result datastructure: 00137 MapInfoCollectionPtr mapInfoCollection = MapInfoCollectionPtr(new wns::scheduler::MapInfoCollection); 00138 StrategyResult strategyResult(schedulingMap,mapInfoCollection); 00139 this->resourceUsage=0.0; 00140 00141 MESSAGE_SINGLE(NORMAL, logger, "doStartScheduling(): userSelection. getDL=" 00142 << schedulerState->isDL << ", isTX=" 00143 << schedulerState->isTx << ", schedulerSpot=" 00144 << wns::scheduler::SchedulerSpot::toString(schedulerState->schedulerSpot)); 00145 00146 // only if (maxSpatialLayers > 1) 00147 if (groupingRequired() && !colleagues.queue->isEmpty()) 00148 { 00149 // set grouping into result output (needed later to set antennaPatterns) 00150 MESSAGE_SINGLE(NORMAL, logger, "doStartScheduling(): write grouping in strategyResult"); 00151 strategyResult.sdmaGrouping = schedulerState->currentState->getGrouping(); 00152 } 00153 00154 // priority is out of [0..MaxPriority-1]: 00155 for (int priority = 0; priority < numberOfPriorities; ++priority) 00156 { 00157 // (grouping alternative: do grouping within each priority; to be discussed; but seems to be less useful) 00158 if (subStrategies[priority] == NULL) 00159 continue; 00160 00161 bool usesHARQ = subStrategies[priority]->usesHARQ(); 00162 schedulerState->currentState->setCurrentPriority(priority); 00163 00164 MESSAGE_SINGLE(NORMAL, logger, "doStartScheduling(): now scheduling priority=" << priority); 00165 00166 // get all registered connections for the current priority 00167 ConnectionSet allConnections = colleagues.registry->getConnectionsForPriority(priority); // all 00168 MESSAGE_SINGLE(NORMAL, logger, "allConnections = "<<printConnectionSet(allConnections)); 00169 ConnectionSet reachableConnections = colleagues.registry->filterReachable(allConnections, frameNr, usesHARQ); 00170 MESSAGE_SINGLE(NORMAL, logger, "reachableConnections= "<<printConnectionSet(reachableConnections)); 00171 00172 // don't filter out unqueued cids since the subStrategy may want to update the state for every cid 00173 schedulerState->currentState->activeConnections = reachableConnections; 00174 // start SubScheduling in any case (even with empty user or cid list) 00175 // because the substrategies may need to keep and track their own state over time 00176 MapInfoCollectionPtr resultBursts = subStrategies[priority]->doStartSubScheduling(schedulerState, schedulingMap); 00177 // copy ^ of std::list<MapInfoEntryPtr> 00178 if (resultBursts->size()>0) 00179 { 00180 MESSAGE_SINGLE(NORMAL, logger, "merged " 00181 << resultBursts->size() << " entries of resultBursts=" 00182 << resultBursts.getPtr() << " into mapInfoCollection=" 00183 << mapInfoCollection.getPtr() << " (now size=" 00184 << mapInfoCollection->size() << ")"); 00185 mapInfoCollection->join(*resultBursts); // collects result bursts. Do not use merge! (sorts bySmartPtr) 00186 } 00187 } // end for (over all priorities) 00188 // READY! 00189 MESSAGE_SINGLE(NORMAL, logger, "StaticPriority: "<<schedulingMap->getNumberOfCompounds()<<" compounds scheduled"); 00190 MESSAGE_SINGLE(NORMAL, logger, schedulingMap->toString()); 00191 this->resourceUsage = schedulingMap->getResourceUsage(); 00192 00193 return strategyResult; 00194 } // doStartScheduling()
1.5.5