![]() |
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. 16, 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 <CONSTANZE/SubGenerator.hpp> 00029 #include <CONSTANZE/Generator.hpp> 00030 #include <CONSTANZE/ConstanzePDU.hpp> 00031 #include <CONSTANZE/Binding.hpp> 00032 #include <CONSTANZE/ConstanzeComponent.hpp> 00033 00034 #include <WNS/module/Base.hpp> 00035 #include <WNS/distribution/Distribution.hpp> 00036 #include <WNS/distribution/ForwardRecurrenceTime.hpp> 00037 //#include <WNS/ldk/helper/FakePDU.hpp> 00038 #include <WNS/node/Node.hpp> 00039 00040 using namespace constanze; 00041 00042 /*************************** Generator *******************************/ 00043 00044 SubGenerator::SubGenerator(constanze::GeneratorBase* _master, const wns::pyconfig::View& config) : 00045 CanTimeout(), 00046 interArrivalTimeDistribution(NULL), 00047 packetSizeDistribution(NULL), 00048 log(config.get("logger")), 00049 master(_master), 00050 //binding(_binding), 00051 rateScale(1.0) 00052 { 00053 wns::pyconfig::View iatConfig(config, "iat"); 00054 std::string iatName = iatConfig.get<std::string>("__plugin__"); 00055 interArrivalTimeDistribution = 00056 wns::distribution::DistributionFactory::creator(iatName)->create(iatConfig); 00057 00058 wns::pyconfig::View packetConfig(config, "packetSize"); 00059 std::string psName = packetConfig.get<std::string>("__plugin__"); 00060 packetSizeDistribution = 00061 wns::distribution::DistributionFactory::creator(psName)->create(packetConfig); 00062 00063 MESSAGE_BEGIN(NORMAL, log, m, "New SubGenerator: "); 00064 m << "iat=" << *interArrivalTimeDistribution 00065 << ", packetSize=" << *packetSizeDistribution; 00066 MESSAGE_END(); 00067 //assure(binding,"undefined binding"); 00068 assure(master,"undefined master reference"); 00069 } 00070 00071 SubGenerator::SubGenerator(constanze::GeneratorBase* _master, wns::logger::Logger& _log, wns::distribution::Distribution* _interArrivalTimeDistribution, wns::distribution::Distribution* _packetSizeDistribution, double _rateScale): 00072 CanTimeout(), 00073 interArrivalTimeDistribution(_interArrivalTimeDistribution), 00074 packetSizeDistribution(_packetSizeDistribution), 00075 log(_log), 00076 master(_master), 00077 //binding(_binding), 00078 rateScale(_rateScale) 00079 { 00080 // Idee: change log name to +".SubGenerator[chain]" 00081 MESSAGE_BEGIN(NORMAL, log, m, "New SubGenerator: "); 00082 if (interArrivalTimeDistribution && packetSizeDistribution) { // not NULL 00083 m << "iat=" << *interArrivalTimeDistribution 00084 << ", packetSize=" << *packetSizeDistribution; 00085 } else { 00086 m << "Empty"; 00087 } 00088 MESSAGE_END(); 00089 //assure(binding,"undefined binding"); 00090 assure(master,"undefined master reference"); 00091 } 00092 00093 SubGenerator::~SubGenerator() 00094 { 00095 if (hasTimeoutSet()) cancelTimeout(); 00096 } 00097 00098 00099 void SubGenerator::reconfigLogger(wns::logger::Logger& _log) 00100 { 00101 // previous value of log is a valid logger 00102 // but carries the name of its parent GeneratorMMPP 00103 // now the name should be .SubGen[0] 00104 log = _log; 00105 } 00106 00107 void SubGenerator::reconfig(wns::distribution::Distribution* _interArrivalTimeDistribution, wns::distribution::Distribution* _packetSizeDistribution) 00108 { 00109 interArrivalTimeDistribution = _interArrivalTimeDistribution; 00110 packetSizeDistribution = _packetSizeDistribution; 00111 assure (interArrivalTimeDistribution && packetSizeDistribution, "Empty distribution(s)"); 00112 MESSAGE_BEGIN(NORMAL, log, m, "SubGenerator::reconfig(): "); 00113 m << "iat=" << *interArrivalTimeDistribution 00114 << ", packetSize=" << *packetSizeDistribution; 00115 MESSAGE_END(); 00116 if (hasTimeoutSet()) cancelTimeout(); 00117 // new timeout for the new traffic: 00118 double iat = (*interArrivalTimeDistribution)(); 00119 double firstiat = wns::distribution::forwardRecurrenceTime(iat); 00120 setTimeout(firstiat); 00121 } 00122 00123 void SubGenerator::onTimeout() { 00124 // next event time 00125 assure (interArrivalTimeDistribution && packetSizeDistribution, "Empty distribution(s)"); 00126 double iat = (*interArrivalTimeDistribution)(); 00127 iat /= rateScale; 00128 int packetSize = static_cast<int>((*packetSizeDistribution)()); 00129 MESSAGE_BEGIN(VERBOSE, log, m, "SubGenerator::onTimeout(): "); 00130 m << "iat=" << iat << ", packetSize=" << packetSize; 00131 MESSAGE_END(); 00132 // some empty packet 00133 //wns::osi::PDUPtr pdu(new wns::ldk::helper::FakePDU(Bit(packetSize))); 00134 wns::osi::PDUPtr pdu(new ConstanzePDU(Bit(packetSize))); 00135 MESSAGE_SINGLE(NORMAL, log, "SubGenerator: Generated " << pdu->getLengthInBits()/8 << " bytes (" << pdu->getLengthInBits() << " bits)."); 00136 // towards downstack direction 00137 master->countPackets(packetSize); 00138 master->sendData(pdu); 00139 // next event 00140 setTimeout(iat); 00141 MESSAGE_SINGLE(VERBOSE, log, "Next packet will be generated at t=" << wns::simulator::getEventScheduler()->getTime() + iat); 00142 } // onTimeout() 00143 00144 void SubGenerator::start() 00145 { 00146 assure (interArrivalTimeDistribution && packetSizeDistribution, "Empty distribution(s)"); 00147 // statistically correct is to have a forwardRecurrenceTime: 00148 double iat = (*interArrivalTimeDistribution)(); 00149 double firstiat = wns::distribution::forwardRecurrenceTime(iat); 00150 setTimeout(firstiat); 00151 //setTimeout(0.0); // first packet generated at once. 00152 } 00153 00154 void SubGenerator::stop() 00155 { 00156 cancelTimeout(); 00157 } 00158 00159 00160
1.5.5