![]() |
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/helper/HopContextWindowProbe.hpp> 00030 #include <WIFIMAC/pathselection/ForwardingCommand.hpp> 00031 00032 #include <WNS/ldk/Layer.hpp> 00033 #include <WNS/StaticFactory.hpp> 00034 #include <WNS/probe/IDProviderRegistry.hpp> 00035 #include <WNS/probe/utils.hpp> 00036 00037 using namespace wifimac::helper; 00038 00039 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00040 HopContextWindowProbe, 00041 wns::ldk::probe::Probe, 00042 "wifimac.helper.HopContextWindowProbe", 00043 wns::ldk::FUNConfigCreator); 00044 00045 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00046 HopContextWindowProbe, 00047 wns::ldk::FunctionalUnit, 00048 "wifimac.helper.HopContextWindowProbe", 00049 wns::ldk::FUNConfigCreator); 00050 00051 HopContextWindowProbe::HopContextWindowProbe(wns::ldk::fun::FUN* fuNet, const wns::pyconfig::View& config) : 00052 wns::ldk::probe::bus::Window(fuNet, config), 00053 config_(config), 00054 forwardingReader(NULL), 00055 windowSize(config_.get<simTimeType>("windowSize")), 00056 { 00057 // read the localIDs from the config 00058 localIDs(&fuNet->getLayer()->getContextProviderCollection()); 00059 for (int ii = 0; ii<config_.len("localIDs.keys()"); ++ii) 00060 { 00061 std::string key = config_.get<std::string>("localIDs.keys()",ii); 00062 unsigned long int value = config_.get<unsigned long int>("localIDs.values()",ii); 00063 localIDs.addProvider(wns::probe::bus::contextprovider::Constant(key, value)); 00064 } 00065 } 00066 00067 HopContextWindowProbe::~HopContextWindowProbe() 00068 { 00069 forwardingReader = NULL; 00070 } 00071 00072 void 00073 HopContextWindowProbe::onFUNCreated() 00074 { 00075 // Obtain MACg Command Reader 00076 forwardingReader = getFUN()->getCommandReader(config_.get<std::string>("forwardingCommandName")); 00077 00078 if(!config_.isNone("managerName") 00079 { 00080 // If the probe is above the transceiver-split, there will be no manager[name] 00081 friends.manager = getFUN()->findFriend<wifimac::multiradio::Manager*>(config_.get<std::string>("managerName")); 00082 assure(friends.manager, "Management entity not found"); 00083 } 00084 } 00085 00086 void 00087 HopContextWindowProbe::processIncoming(const wns::ldk::CompoundPtr& compount) 00088 { 00089 // How many Hops has this Compound traveled? 00090 unsigned int numHops = 00091 (forwardingReader->readCommand<wifimac::pathselection::ForwardingCommand>(compound->getCommandPool())) 00092 ->magic.hopCount; 00093 00094 Bit commandPoolSize; 00095 Bit dataSize; 00096 this->getFUN()->calculateSizes(compound->getCommandPool(), commandPoolSize, dataSize, this); 00097 const long int compoundLength = commandPoolSize + dataSize; 00098 00099 this->putIntoBitsIncomming(numHops, compoundLength); 00100 this->putIntoCompoundsIncomming(numHops, 1); 00101 00102 wns::ldk::probe::WindowCommand* command = this->getCommand(compound->getCommandPool()); 00103 wifimac::helper::HopContextWindowProbe* peerFU = dynamic_cast<wifimac::helper::HopContextWindowProbe*>(command->magic.probingFU); 00104 assure(peerFU != NULL, "Expected wifimac::helper::HopContextWindowProbe as peer!"); 00105 00106 peerFU->putIntoBitsAggregated(numHops, compoundLength); 00107 peerFU->putIntoCompoundsAggregated(numHops, 1); 00108 00109 // Now do the general (base class stuff) 00110 this->wns::ldk::probe::bus::Window::processIncoming(compound); 00111 } 00112 00113 wns::SlidingWindow* 00114 HopContextWindowProbe::getProbe(SlidingWindowMap& probeHolder, PutterMap& putterHolder, std::string id, unsigned int numHops) 00115 { 00116 if (! probeHolder.knows(numHops)) 00117 { 00118 assure(!probePutter.knows(numHops), "probePutter already knows " << numHops << " hops, but probeHolder does not"); 00119 00120 // A yet unseen numHops occured --> create Sliding Window and 00121 // associated Putter 00122 probeHolder.insert(numHops, new wns::SlidingWindow(windowSize)); 00123 wns::probe::bus::ContextProviderCollection hopWiseLocalIDs(localIDs); 00124 hopWiseLocalIDs.addProvider(wns::probe::bus::contextprovider::Constant("MAC.HopCount", numHops)); 00125 probePutter.insert(numHops, new wns::probe::bus::collector(hopWiseLocalIDs, config_, id)); 00126 } 00127 assure(probeHolder.knows(numHops), "probeContainer for " << numHops << " hops not found!"); 00128 return(probeHolder.find(numHops)); 00129 } 00130 00131 void 00132 HopContextWindowProbe::putIntoBitsIncomming(unsigned int numHops, double value) 00133 { 00134 getProbe(this->bitsIncommingProbeHolder, 00135 this->bitsIncommingPutterHolder, 00136 "incommingBitHopContextWindowProbeName", 00137 numHops)->put(value); 00138 } 00139 00140 void 00141 HopContextWindowProbe::putIntoBitsAggregated(unsigned int numHops, double value) 00142 { 00143 getProbe(this->bitsAggregatedProbeHolder, 00144 this->bitsAggregatedPutterHolder, 00145 "aggregatedBitHopContextWindowProbeName", 00146 numHops)->put(value); 00147 } 00148 00149 void 00150 HopContextWindowProbe::putIntoCompoundsIncomming(unsigned int numHops, double value) 00151 { 00152 getProbe(this->compoundsIncommingProbeHolder, 00153 this->compoundsIncommingPutterHolder, 00154 "incommingCompoundHopContextWindowProbeName", 00155 numHops)->put(value); 00156 } 00157 00158 void 00159 HopContextWindowProbe::putIntoCompoundsAggregated(unsigned int numHops, double value) 00160 { 00161 getProbe(this->compoundsAggregatedProbeHolder, 00162 this->compoundsAggregatedPutterHolder, 00163 "aggregatedCompoundHopContextWindowProbeName", 00164 numHops)->put(value); 00165 } 00166 00167 void 00168 HopContextWindowProbe::periodically() 00169 { 00170 if(!config_.isNone("managerName") 00171 { 00172 friends.manager->setSpecificContext(); 00173 } 00174 00175 assure(bitsIncoming.size() == compoundsIncoming.size(), 00176 "Different number of different hop-counts for bitsIncoming and compoundsIncomming"); 00177 storeProbes(bitsIncoming, bitsIncomingPutter); 00178 storeProbes(compoundsIncoming, compoundsIncomingOutter); 00179 00180 assure(bitsAggregated.size() == compoundsAggregated.size(), 00181 "Different number of different hop-counts for bitsAggregated and compoundsAggregated"); 00182 storeProbes(bitsAggregated, bitsAggregatesPutter); 00183 storeProbes(compoundsAggregated, compoundsAggregatedPutter); 00184 00185 // Call base class function 00186 this->wns::ldk::probe::Window::periodically(); 00187 } 00188 00189 void 00190 HopContextWindowProbe::storeProbes(SlidingWindowMap& probeHolder, PutterMap& putterHolder) 00191 { 00192 assure(probeHolder.size() == putterHolder.size(), "Number of sliding windows and putters is not equal"); 00193 for(SlidingWindowMap::const_iterator probeItr = probeHolder.begin(); probeItr != probeHolder.end(); ++probeItr) 00194 { 00195 unsigned int numHops = itr->first; 00196 assure(putterHolder.knows(numHops), "putterHolder does not know " << numHops << " hops, but probeHolder does"); 00197 putterHolder.find(numHops)->put(itr->second.getPerSecond()); 00198 } 00199 }
1.5.5