![]() |
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/dsastrategy/LinearFFirst.hpp> 00029 #include <WNS/scheduler/strategy/dsastrategy/DSAStrategy.hpp> 00030 #include <WNS/scheduler/strategy/dsastrategy/DSAStrategyInterface.hpp> 00031 #include <WNS/scheduler/SchedulerTypes.hpp> 00032 #include <vector> 00033 #include <iostream> 00034 #include <algorithm> 00035 00036 using namespace wns::scheduler; 00037 using namespace wns::scheduler::strategy; 00038 using namespace wns::scheduler::strategy::dsastrategy; 00039 00040 STATIC_FACTORY_REGISTER_WITH_CREATOR(LinearFFirst, 00041 DSAStrategyInterface, 00042 "LinearFFirst", 00043 wns::PyConfigViewCreator); 00044 00045 LinearFFirst::LinearFFirst(const wns::pyconfig::View& config) 00046 : DSAStrategy(config), 00047 randomDist(NULL), 00048 useRandomChannelAtBeginning(false), 00049 lastUsedSubChannel(0), 00050 lastUsedTimeSlot(0), 00051 lastUsedBeam(0) 00052 { 00053 useRandomChannelAtBeginning = config.get<bool>("useRandomChannelAtBeginning"); 00054 if (useRandomChannelAtBeginning) 00055 randomDist = new wns::distribution::StandardUniform(); 00056 } 00057 00058 LinearFFirst::~LinearFFirst() 00059 { 00060 if (randomDist!=NULL) delete randomDist; 00061 } 00062 00063 // call this before each timeSlot/frame 00064 void 00065 LinearFFirst::initialize(SchedulerStatePtr schedulerState, 00066 SchedulingMapPtr schedulingMap) 00067 { 00068 DSAStrategy::initialize(schedulerState,schedulingMap); // must always initialize base class too 00069 lastUsedSubChannel = 0; 00070 lastUsedTimeSlot = 0; 00071 // with beamforming/grouping it might be useful to remember lastUsedSubChannel[userID] separately 00072 // ^ this would form a new strategy "BFOptimizedLinearFFirst" or "LinearFFirstForBeamForming" 00073 if (useRandomChannelAtBeginning) 00074 { 00075 int maxSubChannel = schedulingMap->subChannels.size(); 00076 double random = (*randomDist)(); 00077 lastUsedSubChannel = random*maxSubChannel; 00078 } 00079 } 00080 00081 DSAResult 00082 LinearFFirst::getSubChannelWithDSA(RequestForResource& request, 00083 SchedulerStatePtr schedulerState, 00084 SchedulingMapPtr schedulingMap) 00085 { 00086 DSAResult dsaResult; 00087 //simTimeType requestedCompoundDuration = getCompoundDuration(request); 00088 //MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA("<<request.toString()<<"): d="<<requestedCompoundDuration<<"s"); 00089 int subChannel = lastUsedSubChannel; 00090 int timeSlot = lastUsedTimeSlot; 00091 int spatialLayer = lastUsedBeam; 00092 int maxSubChannel = schedulerState->currentState->strategyInput->getFChannels(); 00093 int numberOfTimeSlots = schedulerState->currentState->strategyInput->getNumberOfTimeSlots(); 00094 int maxSpatialLayers = schedulerState->currentState->strategyInput->getMaxSpatialLayers(); 00095 //with SDMA recheck used resource blocks for additional beams before occuping free resources 00096 if (maxSpatialLayers>1) //beamforming == True && isValidGrouping == True 00097 { 00098 subChannel = 0; 00099 timeSlot = 0; 00100 spatialLayer = 0; 00101 lastUsedSubChannel = maxSubChannel; 00102 lastUsedTimeSlot = numberOfTimeSlots; 00103 } 00104 assure(subChannel<maxSubChannel,"invalid subChannel="<<subChannel); 00105 MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA("<<request.toString()<<"): lastSC="<<lastUsedSubChannel<<" maxSpatialLayer: "<<maxSpatialLayers<<" numberOfTimeSlots: "<<numberOfTimeSlots<<" maxSubchannels: "<<maxSubChannel); 00106 bool found = false; 00107 bool giveUp = false; 00108 while(!found && !giveUp) { 00109 if (channelIsUsable(subChannel, timeSlot, spatialLayer, request, schedulerState, schedulingMap)) 00110 { // PDU fits in 00111 found=true; break; 00112 } 00113 if (++spatialLayer>=maxSpatialLayers) 00114 { // all spatialLayers full; take next timeSlot 00115 spatialLayer=0; 00116 if (++timeSlot>=numberOfTimeSlots) 00117 { // all timeSlots full; take next subChannel 00118 timeSlot=0; 00119 if (++subChannel>=maxSubChannel) 00120 { // wraparound 00121 subChannel=0; 00122 } 00123 } 00124 } 00125 if (subChannel == lastUsedSubChannel && timeSlot == lastUsedTimeSlot) 00126 { // one complete round already done 00127 giveUp=true; break; 00128 } 00129 } // while 00130 if (giveUp) { 00131 MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(): no free subchannel"); 00132 return dsaResult; // empty with subChannel=DSAsubChannelNotFound 00133 } else { 00134 MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(): (subChannel.timeSlot.spatialLayer) = ("<<timeSlot<<"."<<subChannel<<"."<<spatialLayer<<")"); 00135 lastUsedSubChannel = subChannel; 00136 lastUsedTimeSlot = timeSlot; 00137 lastUsedBeam = spatialLayer; 00138 dsaResult.subChannel = subChannel; 00139 dsaResult.timeSlot = timeSlot; 00140 dsaResult.spatialLayer = spatialLayer; 00141 return dsaResult; 00142 } 00143 } // getSubChannelWithDSA
1.5.5