![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * WiMeMac * 00003 * This file is part of openWNS (open Wireless Network Simulator) 00004 * _____________________________________________________________________________ 00005 * 00006 * Copyright (C) 2004-2011 00007 * Chair of Communication Networks (ComNets) 00008 * Kopernikusstr. 5, D-52074 Aachen, Germany 00009 * phone: ++49-241-80-27910, 00010 * fax: ++49-241-80-22242 00011 * email: info@openwns.org 00012 * www: http://www.openwns.org 00013 * _____________________________________________________________________________ 00014 * 00015 * openWNS is free software; you can redistribute it and/or modify it under the 00016 * terms of the GNU Lesser General Public License version 2 as published by the 00017 * Free Software Foundation; 00018 * 00019 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00020 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00021 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00022 * details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License 00025 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00026 * 00027 ******************************************************************************/ 00028 00029 #include <WIMEMAC/convergence/PhyModeProvider.hpp> 00030 00031 #include <stdio.h> 00032 00033 using namespace wimemac::convergence; 00034 00035 PhyModeProvider::PhyModeProvider(const wns::pyconfig::View& config) : 00036 switchingPointOffset(config.get<wns::Ratio>("switchingPointOffset")) 00037 { 00038 assure(config.get<int>("len(MCSs)") > 0, "There must be at least one MCS!"); 00039 00040 char bf[15]; 00041 00042 for (int id=0; id < config.get<int>("len(MCSs)"); ++id) 00043 { 00044 sprintf(bf, "MCSs[%d]", id); 00045 wns::pyconfig::View configview = config.getView(bf); 00046 MCS mcs(configview); 00047 assure(sinr2mcs.find(mcs.getMinSINR()) == sinr2mcs.end(), 00048 "Cannot have two MCS with the same minSINR " << mcs.getMinSINR()); 00049 sinr2mcs[mcs.getMinSINR()] = mcs; 00050 } 00051 00052 unsigned int index = 0; 00053 for(std::map<wns::Ratio, MCS>::iterator it = sinr2mcs.begin(); 00054 it != sinr2mcs.end(); 00055 ++it) 00056 { 00057 it->second.setIndex(index); 00058 ++index; 00059 } 00060 00061 wns::pyconfig::View configPreamble = config.getView("phyModePreamble"); 00062 preamblePhyMode = PhyMode(configPreamble); 00063 00064 wns::pyconfig::View configPhyMode = config.getView("defaultPhyMode"); 00065 defaultPhyMode = PhyMode(configPhyMode); 00066 } 00067 00068 void 00069 PhyModeProvider::mcsUp(PhyMode& pm) const 00070 { 00071 std::map<wns::Ratio, MCS>::const_iterator it = sinr2mcs.find(pm.getMCS().getMinSINR()); 00072 ++it; 00073 if(it != sinr2mcs.end()) 00074 { 00075 pm.setMCS(it->second); 00076 } 00077 } 00078 00079 void 00080 PhyModeProvider::mcsDown(PhyMode& pm) const 00081 { 00082 std::map<wns::Ratio, MCS>::const_iterator it = sinr2mcs.find(pm.getMinSINR()); 00083 if(it != sinr2mcs.begin()) 00084 { 00085 --it; 00086 pm.setMCS(it->second); 00087 } 00088 } 00089 00090 bool 00091 PhyModeProvider::hasLowestMCS(const PhyMode& pm) const 00092 { 00093 return(pm.getMCS() == sinr2mcs.begin()->second); 00094 } 00095 00096 00097 bool 00098 PhyModeProvider::hasHighestMCS(const PhyMode& pm) const 00099 { 00100 return(pm.getMCS() == (--sinr2mcs.end())->second); 00101 } 00102 00103 PhyMode 00104 PhyModeProvider::getPreamblePhyMode(PhyMode pmFrame) const 00105 { 00106 PhyMode pm = preamblePhyMode; 00107 pm.setGuardIntervalDuration(pmFrame.getGuardIntervalDuration()); 00108 pm.setNumberOfSpatialStreams(pmFrame.getNumberOfSpatialStreams()); 00109 pm.setPreambleMode(pmFrame.getPreambleMode()); 00110 00111 return(pm); 00112 } 00113 00114 PhyMode 00115 PhyModeProvider::getPreamblePhyMode() const 00116 { 00117 PhyMode pm = preamblePhyMode; 00118 return(pm); 00119 } 00120 00121 00122 00123 00124 PhyMode 00125 PhyModeProvider::getDefaultPhyMode() const 00126 { 00127 PhyMode pm = defaultPhyMode; 00128 return pm; 00129 } 00130 00131 MCS 00132 PhyModeProvider::getMCS(wns::Ratio sinr) const 00133 { 00134 sinr = sinr - switchingPointOffset; 00135 00136 if(sinr < sinr2mcs.begin()->second.getMinSINR()) 00137 { 00138 return(sinr2mcs.begin()->second); 00139 } 00140 00141 if(sinr > (--sinr2mcs.end())->second.getMinSINR()) 00142 { 00143 return( (--sinr2mcs.end())->second); 00144 } 00145 00146 std::map<wns::Ratio, MCS>::const_iterator it = sinr2mcs.lower_bound(sinr); 00147 --it; 00148 return(it->second); 00149 } 00150 00151 wns::Ratio 00152 PhyModeProvider::getMinSINR() const 00153 { 00154 return(sinr2mcs.begin()->second.getMinSINR()); 00155 }
1.5.5