User Manual, Developers Guide and API Documentation

SINRInformationBase.cpp

Go to the documentation of this file.
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/management/SINRInformationBase.hpp>
00030 
00031 using namespace wifimac::management;
00032 
00033 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00034     wifimac::management::SINRInformationBase,
00035     wns::ldk::ManagementServiceInterface,
00036     "wifimac.management.SINRInformationBase",
00037     wns::ldk::MSRConfigCreator);
00038 
00039 SINRInformationBase::SINRInformationBase( wns::ldk::ManagementServiceRegistry* msr, const wns::pyconfig::View& config):
00040     wns::ldk::ManagementService(msr),
00041     logger(config.get("logger")),
00042     windowSize(config.get<simTimeType>("windowSize"))
00043 {
00044 
00045 }
00046 
00047 void
00048 SINRInformationBase::onMSRCreated()
00049 {
00050     MESSAGE_SINGLE(NORMAL, logger, "Created.");
00051 }
00052 
00053 void
00054 SINRInformationBase::putMeasurement(const wns::service::dll::UnicastAddress tx,
00055                                     const wns::Ratio sinr,
00056                                     const wns::simulator::Time estimatedValidity)
00057 {
00058     assure(tx.isValid(), "Address is not valid");
00059 
00060     if(!measuredSINRHolder.knows(tx))
00061     {
00062         measuredSINRHolder.insert(tx, new wns::SlidingWindow(windowSize));
00063     }
00064     measuredSINRHolder.find(tx)->put(sinr.get_dB());
00065 
00066     if(estimatedValidity > 0.0)
00067     {
00068         if(not lastMeasurement.knows(tx))
00069         {
00070             lastMeasurement.insert(tx, new ratioTimePair);
00071         }
00072         lastMeasurement.find(tx)->first = sinr;
00073         lastMeasurement.find(tx)->second = wns::simulator::getEventScheduler()->getTime() + estimatedValidity;
00074     }
00075 }
00076 
00077 bool
00078 SINRInformationBase::knowsMeasuredSINR(const wns::service::dll::UnicastAddress tx)
00079 {
00080     assure(tx.isValid(), "Address is not valid");
00081 
00082     if(lastMeasurement.knows(tx) and
00083        (lastMeasurement.find(tx)->second > wns::simulator::getEventScheduler()->getTime()))
00084     {
00085         return true;
00086     }
00087 
00088     if(measuredSINRHolder.knows(tx))
00089     {
00090         return(measuredSINRHolder.find(tx)->getNumSamples() > 0);
00091     }
00092     else
00093     {
00094         return(false);
00095     }
00096 }
00097 
00098 wns::Ratio
00099 SINRInformationBase::getMeasuredSINR(const wns::service::dll::UnicastAddress tx)
00100 {
00101     assure(this->knowsMeasuredSINR(tx), "SINR for transmitter " << tx << " not known");
00102 
00103     if(lastMeasurement.knows(tx) and
00104        (lastMeasurement.find(tx)->second > wns::simulator::getEventScheduler()->getTime()))
00105     {
00106         return lastMeasurement.find(tx)->first;
00107     }
00108     return(wns::Ratio::from_dB(measuredSINRHolder.find(tx)->getAbsolute() / measuredSINRHolder.find(tx)->getNumSamples()));
00109 }
00110 
00111 void
00112 SINRInformationBase::putPeerSINR(const wns::service::dll::UnicastAddress peer,
00113                                  const wns::Ratio sinr,
00114                                  const wns::simulator::Time estimatedValidity)
00115 {
00116     assure(peer.isValid(), "Address is not valid");
00117 
00118     if(!peerSINRHolder.knows(peer))
00119     {
00120         peerSINRHolder.insert(peer, new wns::Ratio(sinr));
00121     }
00122     else
00123     {
00124         *(peerSINRHolder.find(peer)) = sinr;
00125     }
00126 
00127     if(estimatedValidity > 0.0)
00128     {
00129         if(not lastPeerMeasurement.knows(peer))
00130         {
00131             lastPeerMeasurement.insert(peer, new ratioTimePair);
00132         }
00133         lastPeerMeasurement.find(peer)->first = sinr;
00134         lastPeerMeasurement.find(peer)->second = wns::simulator::getEventScheduler()->getTime() + estimatedValidity;
00135     }
00136 }
00137 
00138 bool
00139 SINRInformationBase::knowsPeerSINR(const wns::service::dll::UnicastAddress peer)
00140 {
00141     assure(peer.isValid(), "Address is not valid");
00142 
00143     if(fakePeerMeasurement.knows(peer) and
00144        (fakePeerMeasurement.find(peer)->second == wns::simulator::getEventScheduler()->getTime()))
00145     {
00146         return true;
00147     }
00148 
00149     if(lastPeerMeasurement.knows(peer) and
00150        (lastPeerMeasurement.find(peer)->second > wns::simulator::getEventScheduler()->getTime()))
00151     {
00152         return true;
00153     }
00154 
00155     return(peerSINRHolder.knows(peer));
00156 }
00157 
00158 wns::Ratio
00159 SINRInformationBase::getPeerSINR(const wns::service::dll::UnicastAddress peer)
00160 {
00161     assure(this->knowsPeerSINR(peer), "peerSINR for " << peer << " is not known");
00162 
00163     if(fakePeerMeasurement.knows(peer) and
00164        (fakePeerMeasurement.find(peer)->second == wns::simulator::getEventScheduler()->getTime()))
00165     {
00166         return fakePeerMeasurement.find(peer)->first;
00167     }
00168 
00169     if(lastPeerMeasurement.knows(peer) and
00170        (lastPeerMeasurement.find(peer)->second > wns::simulator::getEventScheduler()->getTime()))
00171     {
00172         return lastPeerMeasurement.find(peer)->first;
00173     }
00174 
00175     return(*(peerSINRHolder.find(peer)));
00176 }
00177 
00178 void
00179 SINRInformationBase::putFakePeerSINR(const wns::service::dll::UnicastAddress peer,
00180                                      const wns::Ratio sinr)
00181 {
00182     if(not fakePeerMeasurement.knows(peer))
00183     {
00184         fakePeerMeasurement.insert(peer, new ratioTimePair);
00185     }
00186     fakePeerMeasurement.find(peer)->first = sinr;
00187     fakePeerMeasurement.find(peer)->second = wns::simulator::getEventScheduler()->getTime();
00188 
00189 
00190 }
00191 

Generated on Fri May 25 03:32:13 2012 for openWNS by  doxygen 1.5.5