![]() |
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 * email: info@openwns.org 00009 * www: http://www.openwns.org 00010 * _____________________________________________________________________________ 00011 * 00012 * openWNS is free software; you can redistribute it and/or modify it under the 00013 * terms of the GNU Lesser General Public License version 2 as published by the 00014 * Free Software Foundation; 00015 * 00016 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00017 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00018 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00019 * details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public License 00022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 ******************************************************************************/ 00025 #include <WIMAC/services/InterferenceCache.hpp> 00026 #include <WNS/node/Interface.hpp> 00027 #include <cmath> 00028 00029 00030 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00031 wimac::service::InterferenceCache, 00032 wns::ldk::ManagementServiceInterface, 00033 "wimac.services.InterferenceCache", 00034 wns::ldk::MSRConfigCreator); 00035 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00037 wimac::service::InterferenceCache::ConstantValue, 00038 wimac::service::InterferenceCache::NotFoundStrategy, 00039 "wimac.services.InterferenceCache.ConstantValue", 00040 wns::ldk::PyConfigCreator); 00041 00042 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00043 wimac::service::InterferenceCache::Complain, 00044 wimac::service::InterferenceCache::NotFoundStrategy, 00045 "wimac.services.InterferenceCache.Complain", 00046 wns::ldk::PyConfigCreator); 00047 00048 using namespace wimac::service; 00049 00050 InterferenceCache::ConstantValue::ConstantValue(const wns::pyconfig::View& config) 00051 { 00052 averageCarrier = config.get<wns::Power>("averageCarrier"); 00053 averageInterference = config.get<wns::Power>("averageInterference"); 00054 deviationCarrier = config.get<wns::Power>("deviationCarrier"); 00055 deviationInterference = config.get<wns::Power>("deviationInterference"); 00056 averagePathloss = config.get<wns::Ratio>("averagePathloss"); 00057 } 00058 00059 00060 InterferenceCache::InterferenceCache( wns::ldk::ManagementServiceRegistry* msr, 00061 const wns::pyconfig::View& config ): 00062 wns::ldk::ManagementService( msr ), 00063 alphaLocal_(config.get<double>("alphaLocal")), 00064 alphaRemote_(config.get<double>("alphaRemote")) 00065 { 00066 wns::pyconfig::View notFoundView(config, "notFoundStrategy"); 00067 00068 notFoundStrategy.reset 00069 (wns::StaticFactory< wns::ldk::PyConfigCreator<service::InterferenceCache::NotFoundStrategy> > 00070 ::creator(notFoundView.get<std::string>("__plugin__"))->create(notFoundView)); 00071 00072 LOG_TRACE("Created InterferenceCache Service"); 00073 } 00074 00075 void 00076 InterferenceCache::storeCarrier( 00077 wns::node::Interface* node, 00078 const wns::Power& carrier, 00079 ValueOrigin origin, 00080 int subBand ) 00081 { 00082 InterferenceCacheKey key(node, subBand); 00083 00084 double alpha; 00085 if (origin == Local) 00086 alpha = alphaLocal_; 00087 else 00088 alpha = alphaRemote_; 00089 00090 Node2Power::iterator n2cait = 00091 node2CarrierAverage_.find( key ); 00092 if ( n2cait == node2CarrierAverage_.end() ) 00093 node2CarrierAverage_[key] = carrier; 00094 else 00095 node2CarrierAverage_[key] = 00096 node2CarrierAverage_[key] * (1.0 - alpha) + carrier * alpha; 00097 00098 Node2Double::iterator n2caseit = 00099 node2CarrierSqExp_.find( key ); 00100 if ( n2caseit == node2CarrierSqExp_.end() ) 00101 node2CarrierSqExp_[key] = carrier.get_mW() * carrier.get_mW(); 00102 else 00103 node2CarrierSqExp_[key] = 00104 (1.0 - alpha) * node2CarrierSqExp_[key] + carrier.get_mW() * carrier.get_mW() * alpha; 00105 00106 LOG_TRACE("Storing C for ", 00107 node->getName(), 00108 ": ", carrier, ". (origin=", 00109 ( origin==Local ? "Local" : "Remote" ), ")"); 00110 } 00111 00112 void InterferenceCache::storeInterference( 00113 wns::node::Interface* node, 00114 const wns::Power& interference, 00115 ValueOrigin origin, 00116 int subBand ) 00117 { 00118 InterferenceCacheKey key(node, subBand); 00119 00120 double alpha; 00121 if (origin == Local) 00122 alpha = alphaLocal_; 00123 else 00124 alpha = alphaRemote_; 00125 00126 Node2Power::iterator n2iait = 00127 node2InterferenceAverage_.find( key ); 00128 if ( n2iait == node2InterferenceAverage_.end() ) 00129 node2InterferenceAverage_[key] = interference; 00130 else 00131 node2InterferenceAverage_[key] = 00132 node2InterferenceAverage_[key] * (1.0 - alpha) + interference * alpha; 00133 00134 Node2Double::iterator n2iaseit = 00135 node2InterferenceSqExp_.find( key ); 00136 if ( n2iaseit == node2InterferenceSqExp_.end() ) 00137 node2InterferenceSqExp_[key] = interference.get_mW() * interference.get_mW(); 00138 else 00139 node2InterferenceSqExp_[key] = 00140 node2InterferenceSqExp_[key] * (1.0 - alpha) + interference.get_mW() * interference.get_mW() * alpha ; 00141 00142 LOG_TRACE("Storing I for ", node->getName(), ": ", interference, ". (origin=", 00143 ( origin==Local ? "Local" : "Remote" ), ")"); 00144 } 00145 00146 void 00147 InterferenceCache::storePathloss( 00148 wns::node::Interface* node, 00149 const wns::Ratio& pathloss, 00150 ValueOrigin origin, 00151 int subBand ) 00152 { 00153 InterferenceCacheKey key(node, subBand); 00154 00155 double alpha; 00156 if (origin == Local) 00157 alpha = alphaLocal_; 00158 else 00159 alpha = alphaRemote_; 00160 00161 Node2Double::iterator n2pit = 00162 node2pathloss.find( key ); 00163 if ( n2pit == node2pathloss.end() ) 00164 node2pathloss[key] = pathloss.get_factor(); 00165 else 00166 node2pathloss[key] = (1.0 - alpha) * node2pathloss[key] + alpha * pathloss.get_factor(); 00167 00168 LOG_TRACE("Storing Pathloss for ", node->getName(), ": " , 00169 pathloss, ". (origin=", ( origin==Local ? "Local" : "Remote" ), ")"); 00170 } 00171 00172 wns::Power InterferenceCache::getAveragedCarrier( wns::node::Interface* node, int subBand ) const 00173 { 00174 InterferenceCacheKey key(node, subBand); 00175 00176 Node2Power::const_iterator it = node2CarrierAverage_.find( key ); 00177 if ( it == node2CarrierAverage_.end() ) 00178 return notFoundStrategy->notFoundAverageCarrier(); 00179 LOG_TRACE("Getting C for ", node->getName(), ": ", it->second ); 00180 return it->second; 00181 } 00182 00183 wns::Power 00184 InterferenceCache::getAveragedInterference( 00185 wns::node::Interface* node, 00186 int subBand ) const 00187 { 00188 InterferenceCacheKey key(node, subBand); 00189 00190 Node2Power::const_iterator it = node2InterferenceAverage_.find( key ); 00191 if ( it == node2InterferenceAverage_.end() ) 00192 return notFoundStrategy->notFoundAverageInterference(); 00193 LOG_INFO("Getting I for ", node->getName(), ": ", it->second ); 00194 return it->second; 00195 } 00196 00197 wns::Ratio 00198 InterferenceCache::getAveragedPathloss( 00199 wns::node::Interface* node, 00200 int subBand ) const 00201 { 00202 InterferenceCacheKey key(node, subBand); 00203 00204 Node2Double::const_iterator itpl = node2pathloss.find(key); 00205 00206 if ( itpl == node2pathloss.end() ) 00207 return notFoundStrategy->notFoundAveragePathloss(); 00208 00209 return wns::Ratio::from_factor(itpl->second); 00210 } 00211 00212 wns::Power InterferenceCache::getCarrierDeviation( 00213 wns::node::Interface* node, 00214 int subBand ) const 00215 { 00216 InterferenceCacheKey key(node, subBand); 00217 00218 Node2Double::const_iterator itsq = node2CarrierSqExp_.find( key ); 00219 if ( itsq == node2CarrierSqExp_.end() ) 00220 return notFoundStrategy->notFoundDeviationCarrier(); 00221 00222 Node2Power::const_iterator itp = node2CarrierAverage_.find( key ); 00223 if ( itp == node2CarrierAverage_.end() ) 00224 return notFoundStrategy->notFoundDeviationCarrier(); 00225 00226 return wns::Power::from_mW( sqrt( itsq->second - 00227 itp->second.get_mW() * itp->second.get_mW() ) ); 00228 } 00229 00230 wns::Power 00231 InterferenceCache::getInterferenceDeviation( 00232 wns::node::Interface* node, 00233 int subBand ) const 00234 { 00235 InterferenceCacheKey key(node, subBand); 00236 00237 Node2Double::const_iterator itsq = node2InterferenceSqExp_.find( key ); 00238 if ( itsq == node2InterferenceSqExp_.end() ) 00239 return notFoundStrategy->notFoundDeviationInterference(); 00240 00241 Node2Power::const_iterator itp = node2InterferenceAverage_.find( key ); 00242 if ( itp == node2InterferenceAverage_.end() ) 00243 return notFoundStrategy->notFoundDeviationInterference(); 00244 00245 return wns::Power::from_mW( sqrt( itsq->second - 00246 itp->second.get_mW() * itp->second.get_mW() ) ); 00247 } 00248
1.5.5