![]() |
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/Layer2.hpp> 00030 #include <WIFIMAC/helper/HopContextWindowProbe.hpp> 00031 #include <WIFIMAC/pathselection/ForwardingCommand.hpp> 00032 00033 #include <WNS/StaticFactory.hpp> 00034 #include <WNS/probe/bus/utils.hpp> 00035 00036 using namespace wifimac::helper; 00037 00038 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00039 HopContextWindowProbe, 00040 wns::ldk::probe::Probe, 00041 "wifimac.helper.HopContextWindowProbe", 00042 wns::ldk::FUNConfigCreator); 00043 00044 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00045 HopContextWindowProbe, 00046 wns::ldk::FunctionalUnit, 00047 "wifimac.helper.HopContextWindowProbe", 00048 wns::ldk::FUNConfigCreator); 00049 00050 HopContextWindowProbe::HopContextWindowProbe(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) : 00051 wns::ldk::probe::bus::Window(fun, config), 00052 config_(config), 00053 forwardingReader(NULL), 00054 windowSize(config_.get<simTimeType>("windowSize")) 00055 { 00056 // read the localContext from the config 00057 wns::probe::bus::ContextProviderCollection localContext(&fun->getLayer()->getContextProviderCollection()); 00058 for (int ii = 0; ii<config.len("localIDs.keys()"); ++ii) 00059 { 00060 std::string key = config.get<std::string>("localIDs.keys()",ii); 00061 unsigned long int value = config.get<unsigned long int>("localIDs.values()",ii); 00062 localContext.addProvider(wns::probe::bus::contextprovider::Constant(key, value)); 00063 } 00064 00065 this->hopCountedBitsIncoming = wns::probe::bus::collector(localContext, config, "incomingHopCountedBitThroughputProbeName"); 00066 this->hopCountedCompoundsIncoming = wns::probe::bus::collector(localContext, config, "incomingHopCountedCompoundThroughputProbeName"); 00067 this->hopCountedBitsAggregated = wns::probe::bus::collector(localContext, config, "aggregatedHopCountedBitThroughputProbeName"); 00068 this->hopCountedCompoundsAggregated = wns::probe::bus::collector(localContext, config, "aggregatedHopCountedCompoundThroughputProbeName"); 00069 } 00070 00071 HopContextWindowProbe::~HopContextWindowProbe() 00072 { 00073 forwardingReader = NULL; 00074 } 00075 00076 void 00077 HopContextWindowProbe::onFUNCreated() 00078 { 00079 // Obtain MACg Command Reader 00080 forwardingReader = getFUN()->getCommandReader(config_.get<std::string>("forwardingCommandName")); 00081 } 00082 00083 void 00084 HopContextWindowProbe::processIncoming(const wns::ldk::CompoundPtr& compound) 00085 { 00086 // How many Hops has this Compound traveled? 00087 unsigned int numHops = 00088 (forwardingReader->readCommand<wifimac::pathselection::ForwardingCommand>(compound->getCommandPool())) 00089 ->magic.hopCount; 00090 00091 Bit commandPoolSize; 00092 Bit dataSize; 00093 this->getFUN()->calculateSizes(compound->getCommandPool(), commandPoolSize, dataSize, this); 00094 const long int compoundLength = commandPoolSize + dataSize; 00095 00096 this->putProbe(this->bitsIncomingProbeHolder, numHops, compoundLength); 00097 this->putProbe(this->compoundsIncomingProbeHolder, numHops, 1); 00098 00099 wns::ldk::probe::bus::WindowCommand* command = this->getCommand(compound->getCommandPool()); 00100 wifimac::helper::HopContextWindowProbe* peerFU = dynamic_cast<wifimac::helper::HopContextWindowProbe*>(command->magic.probingFU); 00101 assure(peerFU != NULL, "Expected wifimac::helper::HopContextWindowProbe as peer!"); 00102 00103 // put aggregated probes at peer 00104 peerFU->putProbe(peerFU->bitsAggregatedProbeHolder, numHops, compoundLength); 00105 peerFU->putProbe(peerFU->compoundsAggregatedProbeHolder, numHops, 1); 00106 00107 // Now do the general (base class stuff) 00108 this->wns::ldk::probe::bus::Window::processIncoming(compound); 00109 } 00110 00111 void 00112 HopContextWindowProbe::putProbe(SlidingWindowMap& probeHolder, unsigned int numHops, double value) 00113 { 00114 if (! probeHolder.knows(numHops)) 00115 { 00116 // A yet unseen numHops occured --> create Sliding Window 00117 probeHolder.insert(numHops, new wns::SlidingWindow(windowSize)); 00118 } 00119 probeHolder.find(numHops)->put(value); 00120 } 00121 00122 void 00123 HopContextWindowProbe::periodically() 00124 { 00125 assure(bitsIncomingProbeHolder.size() == compoundsIncomingProbeHolder.size(), 00126 "Different number of different hop-counts for bitsIncoming and compoundsIncoming"); 00127 storeProbes(bitsIncomingProbeHolder, hopCountedBitsIncoming); 00128 storeProbes(compoundsIncomingProbeHolder, hopCountedCompoundsIncoming); 00129 00130 assure(bitsAggregatedProbeHolder.size() == compoundsAggregatedProbeHolder.size(), 00131 "Different number of different hop-counts for bitsAggregated and compoundsAggregated"); 00132 storeProbes(bitsAggregatedProbeHolder, hopCountedBitsAggregated); 00133 storeProbes(compoundsAggregatedProbeHolder, hopCountedCompoundsAggregated); 00134 00135 // Call base class function 00136 this->wns::ldk::probe::bus::Window::periodically(); 00137 } 00138 00139 void 00140 HopContextWindowProbe::storeProbes(SlidingWindowMap& probeHolder, wns::probe::bus::ContextCollectorPtr& putter) 00141 { 00142 for(SlidingWindowMap::const_iterator probeItr = probeHolder.begin(); probeItr != probeHolder.end(); ++probeItr) 00143 { 00144 unsigned int numHops = probeItr->first; 00145 00146 // set the correct hop-count context 00147 this->getFUN()->getLayer<wifimac::Layer2*>()->updateContext("MAC.WindowProbeHopCount", numHops); 00148 00149 // and put the result 00150 putter->put(probeItr->second->getPerSecond()); 00151 } 00152 }
1.5.5