![]() |
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/DSADrivenRR.hpp> 00029 #include <WNS/scheduler/SchedulerTypes.hpp> 00030 00031 #include <vector> 00032 #include <map> 00033 #include <algorithm> 00034 #include <iostream> 00035 00036 using namespace std; 00037 using namespace wns::scheduler; 00038 using namespace wns::scheduler::strategy; 00039 using namespace wns::scheduler::strategy::staticpriority; 00040 00041 STATIC_FACTORY_REGISTER_WITH_CREATOR(DSADrivenRR, 00042 SubStrategyInterface, 00043 "DSADrivenRR", 00044 wns::PyConfigViewCreator); 00045 00046 00047 DSADrivenRR::DSADrivenRR(const wns::pyconfig::View& config) 00048 : SubStrategy(config) 00049 { 00050 } 00051 00052 DSADrivenRR::~DSADrivenRR() 00053 { 00054 } 00055 00056 void 00057 DSADrivenRR::initialize() 00058 { 00059 } 00060 00061 wns::scheduler::ConnectionID 00062 DSADrivenRR::getNextConnection(const ConnectionSet ¤tConnections, ConnectionID cid) const 00063 { 00064 wns::scheduler::ConnectionSet::iterator iter = 00065 currentConnections.upper_bound(cid); 00066 00067 if(iter != currentConnections.end()) 00068 { 00069 return *iter; 00070 } 00071 else 00072 { 00073 return *currentConnections.begin(); 00074 } 00075 } 00076 00077 wns::scheduler::MapInfoCollectionPtr 00078 DSADrivenRR::doStartSubScheduling(SchedulerStatePtr schedulerState, 00079 wns::scheduler::SchedulingMapPtr schedulingMap) 00080 { 00081 MapInfoCollectionPtr mapInfoCollection = 00082 MapInfoCollectionPtr(new wns::scheduler::MapInfoCollection); // result datastructure 00083 ConnectionSet ¤tConnections = schedulerState->currentState->activeConnections; 00084 00085 if (currentConnections.empty()) 00086 return mapInfoCollection; // nothing to do 00087 00088 wns::scheduler::ConnectionID currentConnection = 00089 getNextConnection(currentConnections,lastServedConnection); 00090 00091 MESSAGE_SINGLE(NORMAL, logger, "doStartSubScheduling(" 00092 << printConnectionSet(currentConnections) << ") start with cid=" 00093 << currentConnection); 00094 00095 wns::scheduler::ConnectionID firstConnection = currentConnection; 00096 00097 // Assure the connection we start with gets only served once 00098 // to avoid infinite loop 00099 bool first = true; 00100 00101 while(first || currentConnection != firstConnection) 00102 { 00103 first = false; 00104 int pduCounter = 0; 00105 00106 bool spaceLeft = true; 00107 while(colleagues.queue->queueHasPDUs(currentConnection) 00108 && spaceLeft) 00109 { 00110 spaceLeft = scheduleCid(schedulerState, 00111 schedulingMap, 00112 currentConnection, 00113 pduCounter, 00114 99999, // Infinite block size allowed 00115 mapInfoCollection); 00116 if(spaceLeft) 00117 { 00118 // This is the last connection that actually got resources in this frame 00119 lastServedConnection = currentConnection; 00120 } 00121 MESSAGE_SINGLE(NORMAL, logger, "doStartSubScheduling(): Test " 00122 << spaceLeft << " " << (colleagues.queue->queueHasPDUs(currentConnection)) 00123 << " " << currentConnection); 00124 } 00125 00126 MESSAGE_SINGLE(NORMAL, logger, "doStartSubScheduling(): Scheduled " 00127 << pduCounter << " PDUs for connection " << currentConnection); 00128 00129 currentConnections.erase(currentConnection); 00130 if(currentConnections.size() == 0) 00131 { 00132 break; // all queues empty 00133 } 00134 00135 currentConnection = getNextConnection(currentConnections,currentConnection); 00136 00137 MESSAGE_SINGLE(NORMAL, logger, "doStartSubScheduling(): next connection=" 00138 << currentConnection); 00139 } 00140 00141 MESSAGE_SINGLE(NORMAL, logger, "doStartSubScheduling(): " 00142 << "Finished scheduling. Last served connection was " << lastServedConnection); 00143 00144 return mapInfoCollection; 00145 } // doStartSubScheduling 00146
1.5.5