![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * WiFiMac * 00003 * This file is part of openWNS (open Wireless Network Simulator) 00004 * _____________________________________________________________________________ 00005 * 00006 * Copyright (C) 2004-2007 00007 * Chair of Communication Networks (ComNets) 00008 * Kopernikusstr. 16, 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 <WIFIMAC/convergence/PhyModeProvider.hpp> 00030 00031 #include <stdio.h> 00032 00033 using namespace wifimac::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.getSpatialStreams()[0].getMinSINR()); 00072 ++it; 00073 if(it != sinr2mcs.end()) 00074 { 00075 pm.setUniformMCS(it->second, pm.getNumberOfSpatialStreams()); 00076 } 00077 } 00078 00079 void 00080 PhyModeProvider::mcsDown(PhyMode& pm) const 00081 { 00082 std::map<wns::Ratio, MCS>::const_iterator it = sinr2mcs.find(pm.getSpatialStreams()[0].getMinSINR()); 00083 if(it != sinr2mcs.begin()) 00084 { 00085 --it; 00086 pm.setUniformMCS(it->second, pm.getNumberOfSpatialStreams()); 00087 } 00088 } 00089 00090 bool 00091 PhyModeProvider::hasLowestMCS(const PhyMode& pm) const 00092 { 00093 return(pm.getSpatialStreams()[0] == sinr2mcs.begin()->second); 00094 } 00095 00096 00097 bool 00098 PhyModeProvider::hasHighestMCS(const PhyMode& pm) const 00099 { 00100 return(pm.getSpatialStreams()[0] == (--sinr2mcs.end())->second); 00101 } 00102 00103 PhyMode 00104 PhyModeProvider::getPreamblePhyMode(PhyMode pmFrame) const 00105 { 00106 PhyMode pm = preamblePhyMode; 00107 pm.setGuardIntervalDuration(pmFrame.getGuardIntervalDuration()); 00108 // Preamble has one spatial stream only 00109 //pm.setUniformMCS(preamblePhyMode.getSpatialStreams()[0], pmFrame.getNumberOfSpatialStreams()); 00110 pm.setPreambleMode(pmFrame.getPreambleMode()); 00111 00112 return(pm); 00113 } 00114 00115 PhyMode 00116 PhyModeProvider::getDefaultPhyMode() const 00117 { 00118 PhyMode pm = defaultPhyMode; 00119 return pm; 00120 } 00121 00122 MCS 00123 PhyModeProvider::getMCS(wns::Ratio sinr) const 00124 { 00125 sinr = sinr - switchingPointOffset; 00126 00127 if(sinr < sinr2mcs.begin()->second.getMinSINR()) 00128 { 00129 return(sinr2mcs.begin()->second); 00130 } 00131 00132 if(sinr > (--sinr2mcs.end())->second.getMinSINR()) 00133 { 00134 return( (--sinr2mcs.end())->second); 00135 } 00136 00137 std::map<wns::Ratio, MCS>::const_iterator it = sinr2mcs.lower_bound(sinr); 00138 --it; 00139 return(it->second); 00140 } 00141 00142 wns::Ratio 00143 PhyModeProvider::getMinSINR() const 00144 { 00145 return(sinr2mcs.begin()->second.getMinSINR()); 00146 }
1.5.5