User Manual, Developers Guide and API Documentation

InterferenceCache.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-2007
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 <DLL/services/management/InterferenceCache.hpp>
00029 #include <DLL/Layer2.hpp>
00030 #include <DLL/StationManager.hpp>
00031 
00032 #include <WNS/node/Interface.hpp>
00033 #include <WNS/service/dll/StationTypes.hpp>
00034 #include <WNS/Average.hpp>
00035 
00036 #include <cmath>
00037 
00038 
00039 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00040     dll::services::management::InterferenceCache,
00041     wns::ldk::ManagementServiceInterface,
00042     "dll.services.management.InterferenceCache",
00043     wns::ldk::MSRConfigCreator);
00044 
00045 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00046     dll::services::management::InterferenceCache::ConstantValue,
00047     dll::services::management::InterferenceCache::NotFoundStrategy,
00048     "dll.services.management.InterferenceCache.ConstantValue",
00049     wns::ldk::PyConfigCreator);
00050 
00051 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00052     dll::services::management::InterferenceCache::Complain,
00053     dll::services::management::InterferenceCache::NotFoundStrategy,
00054     "dll.services.management.InterferenceCache.Complain",
00055     wns::ldk::PyConfigCreator);
00056 
00057 using namespace dll::services::management;
00058 
00059 InterferenceCache::ConstantValue::ConstantValue(const wns::pyconfig::View& config)
00060 {
00061     averageCarrier = config.get<wns::Power>("averageCarrier");
00062     averageInterference = config.get<wns::Power>("averageInterference");
00063     deviationCarrier = config.get<wns::Power>("deviationCarrier");
00064     deviationInterference = config.get<wns::Power>("deviationInterference");
00065     averagePathloss = config.get<wns::Ratio>("averagePathloss");
00066 }
00067 
00068 
00069 InterferenceCache::InterferenceCache( wns::ldk::ManagementServiceRegistry* msr, const wns::pyconfig::View& config )
00070     : wns::ldk::ManagementService( msr ),
00071       alphaLocal_(config.get<double>("alphaLocal")),
00072       alphaRemote_(config.get<double>("alphaRemote")),
00073       initialized_(false),
00074       serviceName_(config.get<std::string>("serviceName")),
00075       logger(config.get("logger"))
00076 {
00077 
00078     wns::pyconfig::View notFoundView(config, "notFoundStrategy");
00079 
00080     notFoundStrategy.reset
00081         (wns::StaticFactory< wns::ldk::PyConfigCreator<dll::services::management::InterferenceCache::NotFoundStrategy> >
00082          ::creator(notFoundView.get<std::string>("__plugin__"))->create(notFoundView));
00083 
00084     MESSAGE_SINGLE(NORMAL, logger, "Created InterferenceCache Service");
00085 
00086 
00087 }
00088 
00089 void InterferenceCache::storeMeasurements( wns::node::Interface* node, wns::service::phy::power::PowerMeasurementPtr rxPowerMeasurement, ValueOrigin origin, int subBand )
00090 {
00091     userSubbands_[node->getNodeID()].insert(subBand);
00092 
00093     wns::Power carrier = rxPowerMeasurement->getRxPower();
00094     wns::Power interference = rxPowerMeasurement->getOmniInterferencePower();
00095     wns::Ratio pathloss = rxPowerMeasurement->getLoss();
00096     InterferenceCacheKey key(node, subBand);
00097     double alpha;
00098     if (origin == Local)
00099         alpha = alphaLocal_;
00100     else
00101         alpha = alphaRemote_;
00102 
00103     Node2Power::iterator n2cait =
00104         node2CarrierAverage_.find( key );
00105     if ( n2cait == node2CarrierAverage_.end() )
00106         node2CarrierAverage_[key] = carrier;
00107     else
00108         node2CarrierAverage_[key] =
00109             node2CarrierAverage_[key] * (1.0 - alpha) + carrier * alpha;
00110     Node2Double::iterator n2caseit =
00111         node2CarrierSqExp_.find( key );
00112     if ( n2caseit == node2CarrierSqExp_.end() )
00113         node2CarrierSqExp_[key] = carrier.get_mW() * carrier.get_mW();
00114     else
00115         node2CarrierSqExp_[key] =
00116             (1.0 - alpha) * node2CarrierSqExp_[key] +  carrier.get_mW() * carrier.get_mW() * alpha;
00117     Node2Power::iterator n2iait =
00118         node2InterferenceAverage_.find( key );
00119     if ( n2iait == node2InterferenceAverage_.end() )
00120         node2InterferenceAverage_[key] = interference;
00121     else
00122         node2InterferenceAverage_[key] =
00123              node2InterferenceAverage_[key] * (1.0 - alpha) + interference * alpha;
00124 
00125     Node2Double::iterator n2iaseit =
00126         node2InterferenceSqExp_.find( key );
00127     if ( n2iaseit == node2InterferenceSqExp_.end() )
00128         node2InterferenceSqExp_[key] = interference.get_mW() * interference.get_mW();
00129     else
00130         node2InterferenceSqExp_[key] =
00131              node2InterferenceSqExp_[key] * (1.0 - alpha) + interference.get_mW() * interference.get_mW() * alpha ;
00132     Node2Double::iterator n2pit =
00133         node2pathloss.find( key );
00134     if ( n2pit == node2pathloss.end() )
00135         node2pathloss[key] = pathloss.get_factor();
00136     else
00137         node2pathloss[key] = (1.0 - alpha) * node2pathloss[key] + alpha * pathloss.get_factor();
00138 
00139     MESSAGE_BEGIN(VERBOSE, logger, m, "Storing C for ");
00140     m << node->getName() << ": " << carrier << ". (origin=" << ( origin==Local ? "Local" : "Remote" ) << ")";
00141     MESSAGE_END();
00142     MESSAGE_BEGIN(VERBOSE, logger, m, "Storing I for ");
00143     m << node->getName() << ": " << interference << ". (origin=" << ( origin==Local ? "Local" : "Remote" ) << ")";
00144     MESSAGE_END();
00145     MESSAGE_BEGIN(VERBOSE, logger, m, "Storing Pathloss for ");
00146     m << node->getName() << ": " << pathloss << ". (origin=" << ( origin==Local ? "Local" : "Remote" ) << ")";
00147     MESSAGE_END();
00148 }
00149 
00150 void InterferenceCache::storeCarrier( wns::node::Interface* node, const wns::Power& carrier, ValueOrigin origin, int subBand )
00151 {
00152     InterferenceCacheKey key(node, subBand);
00153 
00154     double alpha;
00155     if (origin == Local)
00156         alpha = alphaLocal_;
00157     else
00158         alpha = alphaRemote_;
00159 
00160     Node2Power::iterator n2cait =
00161         node2CarrierAverage_.find( key );
00162     if ( n2cait == node2CarrierAverage_.end() )
00163         node2CarrierAverage_[key] = carrier;
00164     else
00165         node2CarrierAverage_[key] =
00166             node2CarrierAverage_[key] * (1.0 - alpha) + carrier * alpha;
00167 
00168     Node2Double::iterator n2caseit =
00169         node2CarrierSqExp_.find( key );
00170     if ( n2caseit == node2CarrierSqExp_.end() )
00171         node2CarrierSqExp_[key] = carrier.get_mW() * carrier.get_mW();
00172     else
00173         node2CarrierSqExp_[key] =
00174             (1.0 - alpha) * node2CarrierSqExp_[key] +  carrier.get_mW() * carrier.get_mW() * alpha;
00175 
00176     MESSAGE_BEGIN(VERBOSE, logger, m, "Storing C for ");
00177     m << node->getName() << ": " << carrier << ". (origin=" << ( origin==Local ? "Local" : "Remote" ) << ")";
00178     MESSAGE_END();
00179 }
00180 
00181 void InterferenceCache::storeInterference( wns::node::Interface* node, const wns::Power& interference, ValueOrigin origin, int subBand )
00182 {
00183     InterferenceCacheKey key(node, subBand);
00184 
00185     double alpha;
00186     if (origin == Local)
00187         alpha = alphaLocal_;
00188     else
00189         alpha = alphaRemote_;
00190 
00191     Node2Power::iterator n2iait =
00192         node2InterferenceAverage_.find( key );
00193     if ( n2iait == node2InterferenceAverage_.end() )
00194         node2InterferenceAverage_[key] = interference;
00195     else
00196         node2InterferenceAverage_[key] =
00197              node2InterferenceAverage_[key] * (1.0 - alpha) + interference * alpha;
00198 
00199     Node2Double::iterator n2iaseit =
00200         node2InterferenceSqExp_.find( key );
00201     if ( n2iaseit == node2InterferenceSqExp_.end() )
00202         node2InterferenceSqExp_[key] = interference.get_mW() * interference.get_mW();
00203     else
00204         node2InterferenceSqExp_[key] =
00205              node2InterferenceSqExp_[key] * (1.0 - alpha) + interference.get_mW() * interference.get_mW() * alpha ;
00206 
00207     MESSAGE_BEGIN(VERBOSE, logger, m, "Storing I for ");
00208     m << node->getName() << ": " << interference << ". (origin=" << ( origin==Local ? "Local" : "Remote" ) << ")";
00209     MESSAGE_END();
00210 }
00211 
00212 void InterferenceCache::storePathloss( wns::node::Interface* node, const wns::Ratio& pathloss, ValueOrigin origin, int subBand )
00213 {
00214     InterferenceCacheKey key(node, subBand);
00215 
00216     double alpha;
00217     if (origin == Local)
00218         alpha = alphaLocal_;
00219     else
00220         alpha = alphaRemote_;
00221 
00222     Node2Double::iterator n2pit =
00223         node2pathloss.find( key );
00224     if ( n2pit == node2pathloss.end() )
00225         node2pathloss[key] = pathloss.get_factor();
00226     else
00227         node2pathloss[key] = (1.0 - alpha) * node2pathloss[key] + alpha * pathloss.get_factor();
00228 
00229     MESSAGE_BEGIN(VERBOSE, logger, m, "Storing Pathloss for ");
00230     m << node->getName() << ": " << pathloss << ". (origin=" << ( origin==Local ? "Local" : "Remote" ) << ")";
00231     MESSAGE_END();
00232 }
00233 
00234 wns::Power InterferenceCache::getAveragedCarrier( wns::node::Interface* node, int subBand ) const
00235 {
00236     InterferenceCacheKey key(node, subBand);
00237 
00238     Node2Power::const_iterator it = node2CarrierAverage_.find( key );
00239     if ( it == node2CarrierAverage_.end() )
00240         return notFoundStrategy->notFoundAverageCarrier();
00241     MESSAGE_SINGLE(VERBOSE,logger,"Getting C for " << node->getName() <<": " << it->second );
00242     return it->second;
00243 }
00244 
00245 wns::Power InterferenceCache::getAveragedInterference( wns::node::Interface* node, int subBand ) const
00246 {
00247     InterferenceCacheKey key(node, subBand);
00248 
00249     Node2Power::const_iterator it = node2InterferenceAverage_.find( key );
00250     if ( it == node2InterferenceAverage_.end() )
00251         return notFoundStrategy->notFoundAverageInterference();
00252     MESSAGE_SINGLE(VERBOSE,logger,"Getting I for " << node->getName() <<": " << it->second );
00253     return it->second;
00254 }
00255 
00256 wns::Ratio InterferenceCache::getAveragedPathloss( wns::node::Interface* node, int subBand ) const
00257 {
00258     InterferenceCacheKey key(node, subBand);
00259 
00260     Node2Double::const_iterator itpl = node2pathloss.find(key);
00261 
00262     if ( itpl == node2pathloss.end() )
00263         return notFoundStrategy->notFoundAveragePathloss();
00264 
00265     return wns::Ratio::from_factor(itpl->second);
00266 }
00267 
00268 wns::Power InterferenceCache::getPerSCAveragedCarrier( wns::node::Interface* node) const
00269 {
00270     if (userSubbands_.find(node->getNodeID()) == userSubbands_.end())
00271     {
00272         MESSAGE_SINGLE(NORMAL,logger,"No average carrier known for " << node->getName());
00273         return notFoundStrategy->notFoundAverageCarrier();
00274     }
00275 
00276     std::set<int> subBands = userSubbands_.find(node->getNodeID())->second;
00277     std::set<int>::iterator it;
00278     wns::Average<double> mean;
00279     for(it = subBands.begin(); it != subBands.end(); it++)
00280     {
00281         InterferenceCacheKey key(node, *it);
00282         assure(node2CarrierAverage_.find(key) != node2CarrierAverage_.end(), "No average interference found.");
00283         mean.put(node2CarrierAverage_.find(key)->second.get_mW());
00284     }
00285     MESSAGE_SINGLE(NORMAL,logger,"Getting C for " << node->getName() <<": " << wns::Power::from_mW(mean.get())
00286          << " average over " << subBands.size() << " resources.");
00287 
00288     return wns::Power::from_mW(mean.get());
00289 }
00290 
00291 wns::Power InterferenceCache::getPerSCAveragedInterference( wns::node::Interface* node) const
00292 {
00293     if (userSubbands_.find(node->getNodeID()) == userSubbands_.end())
00294     {
00295         MESSAGE_SINGLE(NORMAL,logger,"No average interference known for " << node->getName());
00296         return notFoundStrategy->notFoundAverageInterference();
00297     }
00298 
00299     std::set<int> subBands = userSubbands_.find(node->getNodeID())->second;
00300     std::set<int>::iterator it;
00301     wns::Average<double> mean;
00302     for(it = subBands.begin(); it != subBands.end(); it++)
00303     {
00304         InterferenceCacheKey key(node, *it);
00305         assure(node2InterferenceAverage_.find(key) != node2InterferenceAverage_.end(), "No average interference found.");
00306         mean.put(node2InterferenceAverage_.find(key)->second.get_mW());
00307     }
00308     MESSAGE_SINGLE(NORMAL,logger,"Getting I for " << node->getName() <<": " << wns::Power::from_mW(mean.get())
00309          << " average over " << subBands.size() << " resources.");
00310 
00311     return wns::Power::from_mW(mean.get());
00312 
00313 }
00314 
00315 wns::Ratio InterferenceCache::getPerSCAveragedPathloss( wns::node::Interface* node) const
00316 {
00317     if (userSubbands_.find(node->getNodeID()) == userSubbands_.end())
00318     {
00319         MESSAGE_SINGLE(NORMAL,logger,"No average pathloss known for " << node->getName());
00320         return notFoundStrategy->notFoundAveragePathloss();
00321     }
00322 
00323     std::set<int> subBands = userSubbands_.find(node->getNodeID())->second;
00324     std::set<int>::iterator it;
00325     wns::Average<double> mean;
00326     for(it = subBands.begin(); it != subBands.end(); it++)
00327     {
00328         InterferenceCacheKey key(node, *it);
00329         assure(node2pathloss.find(key) != node2pathloss.end(), "No average pathloss found.");
00330         mean.put(node2pathloss.find(key)->second);
00331     }
00332     MESSAGE_SINGLE(NORMAL,logger,"Getting PL for " << node->getName() <<": " << wns::Ratio::from_factor(mean.get())
00333          << " average over " << subBands.size() << " resources.");
00334 
00335     return wns::Ratio::from_factor(mean.get());
00336 
00337 }
00338 
00339 wns::Ratio 
00340 InterferenceCache::getAverageEmittedInterferencePathloss(wns::node::Interface* node) const
00341 {
00342     dll::Layer2* layer = getMSR()->getLayer<dll::Layer2*>();
00343     
00344     if(layer->getStationType() != wns::service::dll::StationTypes::AP())
00345         return wns::Ratio();
00346 
00347     if(initialized_ && remoteBSCaches_.size() == 0)
00348         return wns::Ratio();
00349 
00350     if(!initialized_)
00351     {
00352         initialized_ = true;
00353         dll::NodeList nl = layer->getStationManager()->getNodeList();
00354 
00355         dll::NodeList::iterator it;
00356         for(it = nl.begin(); it != nl.end(); it++)
00357         {
00358             /* Only include APs*/
00359             dll::ILayer2* aLayer = layer->getStationManager()->getStationByNode(*it);
00360             if(aLayer->getStationType() == wns::service::dll::StationTypes::AP())
00361             {
00362                 /* Do not include us */
00363                 if(*it != layer->getNode())
00364                 {
00365                     remoteBSCaches_.push_back(
00366                         aLayer->getManagementService<dll::services::management::InterferenceCache>(serviceName_));
00367                 }
00368             }
00369         }
00370     }
00371 
00372     std::list<InterferenceCache*>::iterator iter;
00373     double sum = 0;
00374     for(iter = remoteBSCaches_.begin(); iter != remoteBSCaches_.end(); iter++)
00375     {
00376         sum += 1.0 / (*iter)->getAveragedPathloss(node).get_factor();
00377     }
00378     wns::Ratio result = wns::Ratio::from_factor(1.0 / sum);
00379 
00380     return result;
00381 }
00382 
00383 void
00384 InterferenceCache::onMSRCreated()
00385 {
00386 }
00387 
00388 wns::Power InterferenceCache::getCarrierDeviation( wns::node::Interface* node, int subBand ) const
00389 {
00390     InterferenceCacheKey key(node, subBand);
00391 
00392     Node2Double::const_iterator itsq = node2CarrierSqExp_.find( key );
00393     if ( itsq == node2CarrierSqExp_.end() )
00394         return notFoundStrategy->notFoundDeviationCarrier();
00395 
00396     Node2Power::const_iterator itp = node2CarrierAverage_.find( key );
00397     if ( itp == node2CarrierAverage_.end() )
00398         return notFoundStrategy->notFoundDeviationCarrier();
00399 
00400     return wns::Power::from_mW( sqrt( itsq->second -
00401         itp->second.get_mW() * itp->second.get_mW() ) );
00402 }
00403 
00404 wns::Power InterferenceCache::getInterferenceDeviation( wns::node::Interface* node, int subBand ) const
00405 {
00406     InterferenceCacheKey key(node, subBand);
00407 
00408     Node2Double::const_iterator itsq = node2InterferenceSqExp_.find( key );
00409     if ( itsq == node2InterferenceSqExp_.end() )
00410         return notFoundStrategy->notFoundDeviationInterference();
00411 
00412     Node2Power::const_iterator itp = node2InterferenceAverage_.find( key );
00413     if ( itp == node2InterferenceAverage_.end() )
00414         return notFoundStrategy->notFoundDeviationInterference();
00415 
00416     return wns::Power::from_mW( sqrt( itsq->second -
00417         itp->second.get_mW() * itp->second.get_mW() ) );
00418 }
00419 

Generated on Sat Feb 11 03:31:32 2012 for openWNS by  doxygen 1.5.5