![]() |
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/convergence/NetworkStateProbe.hpp> 00030 00031 #include <WNS/probe/bus/utils.hpp> 00032 00033 using namespace wifimac::convergence; 00034 00035 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00036 wifimac::convergence::NetworkStateProbe, 00037 wns::ldk::FunctionalUnit, 00038 "wifimac.convergence.NetworkStateProbe", 00039 wns::ldk::FUNConfigCreator); 00040 00041 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00042 wifimac::convergence::NetworkStateProbe, 00043 wns::ldk::probe::Probe, 00044 "wifimac.convergence.NetworkStateProbe", 00045 wns::ldk::FUNConfigCreator); 00046 00047 NetworkStateProbe::NetworkStateProbe(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) : 00048 wns::ldk::fu::Plain<NetworkStateProbe, NetworkStateProbeCommand>(fun), 00049 wns::ldk::probe::Probe(), 00050 00051 logger(config.get("logger")), 00052 txDurationProviderCommandName(config.get<std::string>("txDurationProviderCommandName")), 00053 localNetworkState(), 00054 isTx(), 00055 curTxCompound(), 00056 curFrameTxDuration(0.0) 00057 { 00058 // read the localContext from the config 00059 wns::probe::bus::ContextProviderCollection localContext(&fun->getLayer()->getContextProviderCollection()); 00060 for (int ii = 0; ii<config.len("localIDs.keys()"); ++ii) 00061 { 00062 std::string key = config.get<std::string>("localIDs.keys()",ii); 00063 unsigned long int value = config.get<unsigned long int>("localIDs.values()",ii); 00064 localContext.addProvider(wns::probe::bus::contextprovider::Constant(key, value)); 00065 MESSAGE_SINGLE(VERBOSE, logger, "Using Local IDName '"<<key<<"' with value: "<<value); 00066 } 00067 00068 // Add context to distinguish tx and rx 00069 isTx = new wns::probe::bus::contextprovider::Variable("MAC.isOwnTransmission", 0); 00070 localContext.addProvider(wns::probe::bus::contextprovider::Container(isTx)); 00071 00072 this->localNetworkState = wns::probe::bus::collector(localContext, config, "localNetworkStateProbeName"); 00073 } 00074 00075 NetworkStateProbe::~NetworkStateProbe() 00076 { 00077 delete isTx; 00078 } 00079 00080 void 00081 NetworkStateProbe::processOutgoing(const wns::ldk::CompoundPtr& compound) 00082 { 00083 if(hasTimeoutSet()) 00084 { 00085 cancelTimeout(); 00086 onTimeout(); 00087 } 00088 00089 curTxCompound = compound; 00090 curFrameTxDuration = getFUN()->getCommandReader(txDurationProviderCommandName)-> 00091 readCommand<wifimac::convergence::TxDurationProviderCommand>(compound->getCommandPool())->getDuration(); 00092 00093 setTimeout(curFrameTxDuration); 00094 } 00095 00096 void 00097 NetworkStateProbe::onTimeout() 00098 { 00099 isTx->set(1); 00100 this->localNetworkState->put(curTxCompound, curFrameTxDuration); 00101 00102 curTxCompound = wns::ldk::CompoundPtr(); 00103 curFrameTxDuration = 0.0; 00104 } 00105 00106 00107 void 00108 NetworkStateProbe::processIncoming(const wns::ldk::CompoundPtr& compound) 00109 { 00110 wns::simulator::Time frameTxDuration = getFUN()->getCommandReader(txDurationProviderCommandName)-> 00111 readCommand<wifimac::convergence::TxDurationProviderCommand>(compound->getCommandPool())->getDuration(); 00112 00113 isTx->set(0); 00114 this->localNetworkState->put(compound, frameTxDuration); 00115 } 00116
1.5.5