![]() |
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/GeneratorPP.hpp> 00029 #include <CONSTANZE/Generator.hpp> 00030 #include <CONSTANZE/Binding.hpp> 00031 #include <CONSTANZE/ConstanzeComponent.hpp> 00032 00033 #include <WNS/module/Base.hpp> 00034 #include <WNS/distribution/Distribution.hpp> 00035 #include <WNS/distribution/ForwardRecurrenceTime.hpp> 00036 #include <WNS/node/Node.hpp> 00037 00038 using namespace constanze; 00039 00040 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00041 constanze::GeneratorPP, 00042 constanze::GeneratorBase, 00043 "PointProcess", 00044 wns::PyConfigViewCreator); 00045 00046 00047 GeneratorPP::GeneratorPP(const wns::pyconfig::View& config) : 00048 GeneratorBase(config), 00049 CanTimeout(), 00050 interArrivalTimeDistribution(NULL), 00051 packetSizeDistribution(NULL), 00052 correctFRT(true) 00053 { 00054 wns::pyconfig::View iatConfig(pyco, "iat"); 00055 std::string iatName = iatConfig.get<std::string>("__plugin__"); 00056 interArrivalTimeDistribution = 00057 wns::distribution::DistributionFactory::creator(iatName)->create(iatConfig); 00058 00059 wns::pyconfig::View packetConfig(pyco, "packetSize"); 00060 std::string psName = packetConfig.get<std::string>("__plugin__"); 00061 packetSizeDistribution = 00062 wns::distribution::DistributionFactory::creator(psName)->create(packetConfig); 00063 if (config.knows("correctFRT") && !config.isNone("correctFRT")) { 00064 correctFRT = config.get<bool>("correctFRT"); 00065 } 00066 00067 00068 MESSAGE_BEGIN(NORMAL, log, m, "New GeneratorPP: "); 00069 m << "iat=" << *interArrivalTimeDistribution 00070 << ", packetSize=" << *packetSizeDistribution; 00071 MESSAGE_END(); 00072 } 00073 00074 00075 GeneratorPP::~GeneratorPP() 00076 { 00077 if (hasTimeoutSet()) cancelTimeout(); 00078 if (packetSizeDistribution != NULL) delete packetSizeDistribution; packetSizeDistribution = NULL; 00079 if (interArrivalTimeDistribution != NULL) delete interArrivalTimeDistribution; interArrivalTimeDistribution = NULL; 00080 } 00081 00082 void 00083 GeneratorPP::onTimeout() { 00084 // next event time 00085 double iat = (*interArrivalTimeDistribution)(); 00086 int packetSize = static_cast<int>((*packetSizeDistribution)()); 00087 countPackets(packetSize); 00088 00089 // some empty packet 00090 //wns::osi::PDUPtr pdu(new wns::ldk::helper::FakePDU(Bit(packetSize))); 00091 wns::osi::PDUPtr pdu(new ConstanzePDU(Bit(packetSize))); 00092 00093 MESSAGE_SINGLE(NORMAL, log, "Generated " << pdu->getLengthInBits()/8 << " bytes (" << pdu->getLengthInBits() << " bits)."); 00094 00095 // towards downstack direction 00096 sendData(pdu); 00097 00098 // next event 00099 setTimeout(iat); 00100 00101 MESSAGE_SINGLE(VERBOSE, log, "Next packet will be generated at t=" << wns::simulator::getEventScheduler()->getTime() + iat); 00102 } // onTimeout() 00103 00104 void GeneratorPP::start() 00105 { 00106 // statistically correct is to have a forwardRecurrenceTime: 00107 if (correctFRT) { 00108 double iat = (*interArrivalTimeDistribution)(); 00109 double firstiat = wns::distribution::forwardRecurrenceTime(iat); 00110 setTimeout(firstiat); 00111 MESSAGE_SINGLE(NORMAL, log, "start() after firstiat="<<firstiat<<"s"); 00112 } else { 00113 setTimeout(0.0); // first packet generated at once. 00114 MESSAGE_SINGLE(NORMAL, log, "start() now"); 00115 } 00116 } 00117 00118 void GeneratorPP::stop() 00119 { 00120 cancelTimeout(); 00121 MESSAGE_SINGLE(NORMAL, log, "stop()"); 00122 } 00123 00124 /* 00125 Local Variables: 00126 mode: c++ 00127 fill-column: 80 00128 c-basic-offset: 8 00129 c-comment-only-line-offset: 0 00130 c-tab-always-indent: t 00131 indent-tabs-mode: t 00132 tab-width: 8 00133 End: 00134 */
1.5.5