![]() |
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-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 <WNS/ldk/fun/FUN.hpp> 00029 #include <WNS/ldk/Layer.hpp> 00030 #include <WNS/ldk/buffer/Buffer.hpp> 00031 #include <WNS/probe/bus/utils.hpp> 00032 00033 using namespace wns::ldk::buffer; 00034 using namespace wns::ldk::buffer::sizecalculators; 00035 00036 // Size calculation stategies 00037 unsigned long int 00038 PerPDU::operator()(const CompoundPtr& /* pdu */) const 00039 { 00040 return 1; 00041 } 00042 STATIC_FACTORY_REGISTER(PerPDU, SizeCalculator, "PDU"); 00043 00044 unsigned long int 00045 PerBit::operator()(const CompoundPtr& compound) const 00046 { 00047 return compound->getLengthInBits(); 00048 } 00049 STATIC_FACTORY_REGISTER(PerBit, SizeCalculator, "Bit"); 00050 00051 00052 00053 Buffer::Buffer(fun::FUN* _fun, const pyconfig::View& _config) : 00054 events::PeriodicTimeout(), 00055 totalPDUs(0), 00056 droppedPDUs(0), 00057 droppedPDUWindow(_config.get<double>("droppedPDUWindowDuration")), 00058 probeDroppedPDUInterval(_config.get<double>("probeDroppedPDUInterval")), 00059 logger(_config.get("logger")), 00060 probingEnabled(_config.get<bool>("probingEnabled")) 00061 { 00062 // read the localIDs from the config 00063 wns::probe::bus::ContextProviderCollection localContext(_fun->getLayer()->getContextProviderCollection()); 00064 for (int ii = 0; ii<_config.len("localIDs.keys()"); ++ii) 00065 { 00066 std::string key = _config.get<std::string>("localIDs.keys()",ii); 00067 unsigned long int value = _config.get<unsigned long int>("localIDs.values()",ii); 00068 localContext.addProvider( wns::probe::bus::contextprovider::Constant(key, value) ); 00069 } 00070 00071 std::string sizeProbeName = _config.get<std::string>("sizeProbeName"); 00072 std::string lossProbeName = _config.get<std::string>("lossRatioProbeName"); 00073 lossRatioProbeBus = wns::probe::bus::ContextCollectorPtr(new wns::probe::bus::ContextCollector(localContext, lossProbeName)); 00074 sizeProbeBus = wns::probe::bus::ContextCollectorPtr(new wns::probe::bus::ContextCollector(localContext, sizeProbeName)); 00075 } 00076 00077 Buffer::~Buffer() 00078 { 00079 } 00080 00081 void 00082 Buffer::onFunCreated() 00083 { 00084 // is not called. Whyever!? 00085 } 00086 00087 void 00088 Buffer::increaseTotalPDUs() 00089 { 00090 // start on first seen compound 00091 if (probingEnabled) 00092 { 00093 // start on first seen compound 00094 if ((this->hasPeriodicTimeoutSet() == false) && (probeDroppedPDUInterval>0.0)) 00095 { 00096 MESSAGE_SINGLE(NORMAL, logger,"Buffer::increaseTotalPDUs: startPeriodicTimeout(every "<<probeDroppedPDUInterval<<"s)"); 00097 this->startPeriodicTimeout(this->probeDroppedPDUInterval); 00098 } 00099 } 00100 ++this->totalPDUs; 00101 } 00102 00103 00104 void 00105 Buffer::increaseDroppedPDUs(int size) 00106 { 00107 ++this->droppedPDUs; 00108 this->droppedPDUWindow.put(size); 00109 } 00110 00111 void 00112 Buffer::periodically() 00113 { 00114 if (this->lossRatioProbeBus) 00115 { 00116 this->lossRatioProbeBus->put(this->droppedPDUWindow.getPerSecond()); 00117 } 00118 } 00119 00120 void 00121 Buffer::probe() 00122 { 00123 if(this->sizeProbeBus) 00124 { 00125 this->sizeProbeBus->put(((double) getSize()) / getMaxSize()); 00126 } 00127 } // probe 00128 00129 00130
1.5.5