![]() |
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/probe/TickTack.hpp> 00029 #include <WNS/probe/bus/ContextProviderCollection.hpp> 00030 #include <WNS/ldk/Layer.hpp> 00031 00032 using namespace wns::ldk; 00033 using namespace wns::ldk::probe; 00034 00035 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00036 Tick, 00037 FunctionalUnit, 00038 "wns.probe.Tick", 00039 FUNConfigCreator); 00040 00041 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00042 Tack, 00043 FunctionalUnit, 00044 "wns.probe.Tack", 00045 FUNConfigCreator); 00046 00047 Tick::Tick(fun::FUN* fuNet, const wns::pyconfig::View& config) : 00048 fu::Plain<Tick, TickTackCommand>(fuNet), 00049 probeName_(config.get<std::string>("commandName")), 00050 probeOutgoing_(config.get<bool>("probeOutgoing")), 00051 logger_(config.get("logger")) 00052 { 00053 wns::probe::bus::ContextProviderCollection* cpcParent = 00054 &fuNet->getLayer()->getContextProviderCollection(); 00055 00056 wns::probe::bus::ContextProviderCollection cpc(cpcParent); 00057 00058 outSizeProbe_ = wns::probe::bus::ContextCollectorPtr( 00059 new wns::probe::bus::ContextCollector(cpc, probeName_ + ".start.compoundSize")); 00060 } 00061 00062 Tick::~Tick() 00063 { 00064 } 00065 00066 void 00067 Tick::onFUNCreated() 00068 { 00069 } // onFUNCreated 00070 00071 void 00072 Tick::doSendData(const CompoundPtr& compound) 00073 { 00074 if(probeOutgoing_) 00075 writeCommand(compound); 00076 00077 getConnector()->getAcceptor(compound)->sendData(compound); 00078 } 00079 00080 void 00081 Tick::doOnData(const CompoundPtr& compound) 00082 { 00083 if(!probeOutgoing_) 00084 writeCommand(compound); 00085 00086 getDeliverer()->getAcceptor(compound)->onData(compound); 00087 } 00088 00089 void 00090 Tick::writeCommand(const CompoundPtr& compound) 00091 { 00092 activateCommand(compound->getCommandPool()); 00093 00094 MESSAGE_BEGIN(NORMAL, logger_, m, getFUN()->getName()); 00095 m << " passing through Tick probing " << probeName_; 00096 m << " direction " << (probeOutgoing_?"outgoing":"incoming"); 00097 MESSAGE_END(); 00098 00099 outSizeProbe_->put(compound, compound->getLengthInBits()); 00100 } 00101 00102 void 00103 Tick::probeOutgoing() 00104 { 00105 probeOutgoing_ = true; 00106 } 00107 00108 void 00109 Tick::probeIncoming() 00110 { 00111 probeOutgoing_ = false; 00112 } 00113 00114 00115 00116 00117 Tack::Tack(fun::FUN* fuNet, const wns::pyconfig::View& config) : 00118 fu::Plain<Tack>(fuNet), 00119 probeName_(config.get<std::string>("probeAndCommandName")), 00120 probeOutgoing_(config.get<bool>("probeOutgoing")), 00121 commandReader_(NULL), 00122 fun_(fuNet), 00123 logger_(config.get("logger")) 00124 { 00125 wns::probe::bus::ContextProviderCollection* cpcParent = 00126 &fuNet->getLayer()->getContextProviderCollection(); 00127 00128 wns::probe::bus::ContextProviderCollection cpc(cpcParent); 00129 00130 delayProbe_ = wns::probe::bus::ContextCollectorPtr( 00131 new wns::probe::bus::ContextCollector(cpc, probeName_ + ".delay")); 00132 00133 inSizeProbe_ = wns::probe::bus::ContextCollectorPtr( 00134 new wns::probe::bus::ContextCollector(cpc, probeName_ + ".stop.compoundSize")); 00135 } 00136 00137 Tack::~Tack() 00138 { 00139 } 00140 00141 void 00142 Tack::onFUNCreated() 00143 { 00144 commandReader_ = fun_->getCommandReader(probeName_); 00145 assure(commandReader_ != NULL, "Cannot find command reader: " + probeName_); 00146 } // onFUNCreated 00147 00148 void 00149 Tack::doSendData(const CompoundPtr& compound) 00150 { 00151 if(probeOutgoing_) 00152 probeIfNotProbed(compound); 00153 00154 getConnector()->getAcceptor(compound)->sendData(compound); 00155 } 00156 00157 void 00158 Tack::doOnData(const CompoundPtr& compound) 00159 { 00160 if(!probeOutgoing_) 00161 probeIfNotProbed(compound); 00162 00163 getDeliverer()->getAcceptor(compound)->onData(compound); 00164 } 00165 00166 void 00167 Tack::probeOutgoing() 00168 { 00169 probeOutgoing_ = true; 00170 } 00171 00172 void 00173 Tack::probeIncoming() 00174 { 00175 probeOutgoing_ = false; 00176 } 00177 00178 void 00179 Tack::probeIfNotProbed(const CompoundPtr& compound) 00180 { 00181 assure(commandReader_ != NULL, "Need command reader: " + probeName_); 00182 assure(commandReader_->commandIsActivated(compound->getCommandPool()), 00183 "Command " + probeName_ + " not activated."); 00184 00185 TickTackCommand* command; 00186 command = commandReader_->readCommand<TickTackCommand>(compound->getCommandPool()); 00187 if(command->magic.probed == false) 00188 { 00189 command->magic.probed = true; 00190 wns::simulator::Time now = wns::simulator::getEventScheduler()->getTime(); 00191 delayProbe_->put(compound, now - command->magic.tickTime); 00192 inSizeProbe_->put(compound, compound->getLengthInBits()); 00193 00194 MESSAGE_BEGIN(NORMAL, logger_, m, getFUN()->getName()); 00195 m << " probing delay " << probeName_ << ": "; 00196 m << now - command->magic.tickTime; 00197 m << " and size: " << compound->getLengthInBits(); 00198 MESSAGE_END(); 00199 } 00200 } 00201 00202
1.5.5