User Manual, Developers Guide and API Documentation

Fixed.cpp

Go to the documentation of this file.
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/Fixed.hpp>
00029 #include <WNS/scheduler/SchedulerTypes.hpp>
00030 
00031 using namespace wns::scheduler;
00032 using namespace wns::scheduler::strategy;
00033 using namespace wns::scheduler::strategy::dsastrategy;
00034 
00035 // Used for sorting of resources
00036 bool 
00037 FreqFirst::operator()(DSAResult a, DSAResult b) const
00038 {
00039     /*if(a.spatialLayer != b.spatialLayer)
00040     {
00041         return a.spatialLayer < b.spatialLayer;
00042     }
00043     else
00044     {*/
00045         if(a.timeSlot != b.timeSlot)
00046         {
00047             return a.timeSlot < b.timeSlot;
00048         }
00049         else
00050         {
00051             return a.subChannel < b.subChannel;
00052         }
00053     //}
00054 }
00055 
00056 
00057 STATIC_FACTORY_REGISTER_WITH_CREATOR(Fixed,
00058                                      DSAStrategyInterface,
00059                                      "Fixed",
00060                                      wns::PyConfigViewCreator);
00061 
00062 Fixed::Fixed(const wns::pyconfig::View& config)
00063     : DSAStrategy(config)
00064 {
00065 }
00066 
00067 Fixed::~Fixed()
00068 {
00069 }
00070 
00071 // call this before each timeSlot/frame
00072 void
00073 Fixed::initialize(SchedulerStatePtr schedulerState,
00074                          SchedulingMapPtr schedulingMap)
00075 {
00076     DSAStrategy::initialize(schedulerState,schedulingMap); // must always initialize base class too
00077 
00078     int maxSubChannel = schedulerState->currentState->strategyInput->getFChannels();
00079     int numberOfTimeSlots = schedulerState->currentState->strategyInput->getNumberOfTimeSlots();
00080     int maxSpatialLayers = schedulerState->currentState->strategyInput->getMaxSpatialLayers();
00081 
00082     int numberOfPriorities = colleagues.registry->getNumberOfPriorities();
00083 
00084     std::set<wns::scheduler::UserID> userIDs;
00085     unsigned int numberOfUsers = 0;
00086     unsigned int numberOfResources = maxSubChannel * numberOfTimeSlots;// * maxSpatialLayers;
00087     sortedResources_.clear();
00088     spatialLayer_.clear();
00089     resAmount_.clear();
00090     resStart_.clear();
00091 
00092     bool sdma = maxSpatialLayers > 1 && schedulerState->currentState->strategyInput->beamforming;
00093     GroupingPtr grouping = schedulerState->currentState->getGrouping();
00094     if (sdma && grouping != GroupingPtr()) 
00095     {
00096         //with SDMA resources are equally shared between groups
00097         numberOfUsers = grouping->groups.size();
00098         for (unsigned int i = 0; i < grouping->groups.size(); ++i)
00099         {
00100             int spatialLayer = 0;
00101             for (Group::iterator iter = grouping->groups[i].begin(); iter != grouping->groups[i].end(); ++iter)
00102             {
00103                 wns::scheduler::UserID user = (*iter).first;
00104                 userIDs.insert(user);
00105                 spatialLayer_[user.getNodeID()] = spatialLayer;
00106                     ++spatialLayer;
00107             }
00108        }
00109        MESSAGE_SINGLE(NORMAL, logger, "initialize: Distributing " 
00110             << numberOfUsers << " groups on " << numberOfResources << " resources."
00111             << " isDL.isTx: "<<schedulerState->isDL<<"."<<schedulerState->isTx<<" ;with users "<<userIDs.size());
00112     } else {
00113         wns::scheduler::ConnectionSet conns;
00114         for(int prio = 0; prio < numberOfPriorities; prio++)
00115         {
00116             wns::scheduler::ConnectionSet c = 
00117                 colleagues.registry->getConnectionsForPriority(prio);
00118 
00119             wns::scheduler::ConnectionSet::iterator it;
00120             for(it = c.begin(); it != c.end(); it++)
00121                 conns.insert(*it);
00122         }
00123         
00124         wns::scheduler::ConnectionSet::iterator it;
00125 
00126         for(it = conns.begin(); it != conns.end(); it++)
00127         {
00128             wns::scheduler::UserID user = colleagues.registry->getUserForCID(*it);
00129             if(!user.isBroadcast())
00130             {
00131                     userIDs.insert(user);
00132                     spatialLayer_[user.getNodeID()] = 0;
00133             }
00134         }
00135         numberOfUsers = userIDs.size();
00136         MESSAGE_SINGLE(NORMAL, logger, "initialize: Distributing "
00137             << numberOfUsers << " users on " << numberOfResources << " resources.");
00138     }
00139 
00140     if(numberOfUsers == 0)
00141         return;
00142 
00143     for(int i = 0; i < maxSubChannel; i++)
00144     {
00145         for(int j = 0; j < numberOfTimeSlots; j++)
00146         {
00147                 DSAResult res;
00148                 res.subChannel = i;
00149                 res.timeSlot = j;
00150                 sortedResources_.insert(res);
00151         }
00152     }
00153 
00154     int usersMore = numberOfResources % numberOfUsers;
00155     int usersLess = numberOfUsers - usersMore;
00156     int resourcesMore = int(numberOfResources / numberOfUsers) + 1;
00157     int resourcesLess = int(numberOfResources / numberOfUsers);
00158 
00159     MESSAGE_SINGLE(NORMAL, logger, "initialize: " 
00160         << usersLess << " users/groups get " << resourcesLess << ", "
00161         << usersMore << " users/groups get " << resourcesMore << " resources");
00162 
00163     assure(resourcesLess > 0, "Not enough resources for all users");
00164     assure(usersMore * resourcesMore + usersLess * resourcesLess == numberOfResources,
00165         "Mismatched resource distribution");
00166 
00167     std::set<wns::scheduler::UserID>::iterator uIt;
00168     std::set<DSAResult, FreqFirst>::iterator itr;
00169     int plus = 0;
00170     //with SDMA user corresponds to group
00171     int user = 0;
00172     int counter = 0;
00173     uIt = userIDs.begin();
00174 
00175     for(itr = sortedResources_.begin(); itr != sortedResources_.end(); itr++)
00176     {
00177         if(counter == resourcesLess + plus|| itr == sortedResources_.begin())
00178         {
00179             resStart_[(*uIt).getNodeID()] = itr;
00180             resAmount_[(*uIt).getNodeID()] = resourcesLess + plus;
00181 
00182             MESSAGE_SINGLE(NORMAL, logger, "initialize: User " 
00183                 << (*uIt).getNodeID() << " starts at " 
00184                 << itr->subChannel << "."
00185                 << itr->timeSlot << "."
00186                 << spatialLayer_[(*uIt).getNodeID()]
00187                 << " and gets " << resourcesLess + plus << " resources");
00188 
00189             counter = 0;
00190             uIt++;
00191             user++;
00192             //user of the same group have the same resources seperated by spatialLayers
00193             while (uIt != userIDs.end() && (spatialLayer_[(*uIt).getNodeID()] != 0))
00194             { 
00195                 resStart_[(*uIt).getNodeID()] = itr;
00196                 resAmount_[(*uIt).getNodeID()] = resourcesLess + plus;
00197                 MESSAGE_SINGLE(NORMAL, logger, "initialize: User "
00198                 << (*uIt).getNodeID() << " starts at "
00199                 << itr->subChannel << "."
00200                 << itr->timeSlot << "."
00201                 << spatialLayer_[(*uIt).getNodeID()]
00202                 << " and gets " << resourcesLess + plus << " resources");
00203                 uIt++;
00204             }
00205         }
00206         if(plus == 0 && user == usersLess)
00207         {
00208             plus++;
00209             counter++;
00210         }
00211     counter++;
00212     }
00213 }
00214 
00215 DSAResult
00216 Fixed::getSubChannelWithDSA(RequestForResource& request,
00217                                    SchedulerStatePtr schedulerState,
00218                                    SchedulingMapPtr schedulingMap)
00219 {
00220     assure(request.user.isBroadcast() || resStart_.find(request.user.getNodeID()) != resStart_.end(),
00221         "No resources for user " + request.user.getName());
00222 
00223     // Give the broadcast channel the first resource
00224     if(request.user.isBroadcast())
00225     { 
00226         assure(channelIsUsable(0, 
00227                                 0,
00228                                 0,
00229                                 request, 
00230                                 schedulerState, 
00231                                 schedulingMap), "First resource not available for broadcast");
00232         MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(): Granting resource: 0.0.0"
00233             << " to " << request.toString());
00234         DSAResult dsaResult;
00235         dsaResult.subChannel = 0;
00236         dsaResult.timeSlot = 0;
00237         dsaResult.spatialLayer = 0;
00238         return dsaResult;
00239     }
00240 
00241     assure(resAmount_.find(request.user.getNodeID()) != resAmount_.end(),
00242         "Unknown resource amount for user " + request.user.getNodeID());
00243 
00244     int max = resAmount_[request.user.getNodeID()];
00245     std::set<DSAResult>::iterator it;
00246     int i = 0;
00247     bool found = false;
00248     for(it = resStart_[request.user.getNodeID()]; i < max && !found; it++)
00249     {
00250         i++;
00251         found = channelIsUsable(it->subChannel, 
00252                                 it->timeSlot,
00253                                 spatialLayer_[request.user.getNodeID()],
00254                                 request, 
00255                                 schedulerState, 
00256                                 schedulingMap);
00257     }
00258 
00259     if(!found)
00260     {
00261         MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(): no free subchannel");
00262         DSAResult dsaResult;
00263         return dsaResult;
00264     }
00265     else
00266     {
00267         it--;
00268         MESSAGE_SINGLE(NORMAL, logger, "getSubChannelWithDSA(): Granting resource: "
00269             << it->subChannel << "." << it->timeSlot << "." 
00270             << spatialLayer_[request.user.getNodeID()]<< " to " << request.toString());
00271         DSAResult dsaResult;
00272         dsaResult.subChannel = it->subChannel;
00273         dsaResult.timeSlot = it->timeSlot;
00274         dsaResult.spatialLayer = spatialLayer_[request.user.getNodeID()];
00275         return dsaResult;
00276     }
00277 } // getSubChannelWithDSA

Generated on Sun May 27 03:31:38 2012 for openWNS by  doxygen 1.5.5