![]() |
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 <APPLICATIONS/session/server/CBR.hpp> 00029 00030 using namespace applications::session::server; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::server::CBR, 00033 applications::session::Session, 00034 "server.CBR", wns::PyConfigViewCreator); 00035 00036 CBR::CBR(const wns::pyconfig::View& _pyco) : 00037 Session(_pyco), 00038 packetSizeDistribution(NULL), 00039 bitRateDistribution(NULL) 00040 { 00041 wns::pyconfig::View pSDConfig(_pyco, "packetSize"); 00042 std::string pSDName = pSDConfig.get<std::string>("__plugin__"); 00043 packetSizeDistribution = wns::distribution::DistributionFactory::creator(pSDName)->create(pSDConfig); 00044 00045 wns::pyconfig::View bRDConfig(_pyco, "bitRate"); 00046 std::string bRDName = bRDConfig.get<std::string>("__plugin__"); 00047 bitRateDistribution = wns::distribution::DistributionFactory::creator(bRDName)->create(bRDConfig); 00048 00049 settlingTime = _pyco.get<wns::simulator::Time>("settlingTime"); 00050 00051 /* only for probing */ 00052 sessionType = cbr; 00053 00054 state = idle; 00055 00056 packetFrom = "server.CBR"; 00057 } 00058 00059 CBR::~CBR() 00060 { 00061 if(packetSizeDistribution != NULL) 00062 delete packetSizeDistribution; 00063 packetSizeDistribution = NULL; 00064 00065 if(bitRateDistribution != NULL) 00066 delete bitRateDistribution; 00067 bitRateDistribution = NULL; 00068 } 00069 00070 void 00071 CBR::onData(const wns::osi::PDUPtr& _pdu) 00072 { 00073 assureType(_pdu.getPtr(), applications::session::PDU*); 00074 00075 receivedPacketNumber = static_cast<applications::session::PDU*>(_pdu.getPtr())->getPacketNumber(); 00076 00077 applications::session::Session::incomingProbesCalculation(_pdu); 00078 00079 MESSAGE_SINGLE(NORMAL, logger, "APPL: Received packetNumber " << receivedPacketNumber << "."); 00080 00081 if((receivedPacketNumber == 1) && (state != sessionended)) 00082 { 00083 state = running; 00084 00085 firstPacketDelay = packetDelay; 00086 } 00087 00088 /* start immediately sending packets */ 00089 onTimeout(statetimeout); 00090 } 00091 00092 void 00093 CBR::onTimeout(const Timeout& _t) 00094 { 00095 if(_t == statetimeout) 00096 { 00097 packetSize = static_cast<int>((*packetSizeDistribution)()); 00098 bitRate = (*bitRateDistribution)(); 00099 iat = (double(packetSize) / double(bitRate)); 00100 00101 MESSAGE_BEGIN(NORMAL, logger, m, "APPL: Sending PDU with: "); 00102 m << "iat = " << iat; 00103 m << ", packetSize = " << packetSize; 00104 m << ", bitRate = " << bitRate; 00105 MESSAGE_END(); 00106 00107 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00108 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00109 00110 packetNumber = 1; 00111 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00112 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending packetNumber " << packetNumber << "."); 00113 00114 wns::osi::PDUPtr pdu(applicationPDU); 00115 applications::session::Session::outgoingProbesCalculation(pdu); 00116 00117 connection->sendData(pdu); 00118 00119 state = idle; 00120 } 00121 else if(_t == probetimeout) 00122 { 00123 applications::session::Session::onTimeout(_t); 00124 } 00125 else 00126 { 00127 assure(false, "APPL: Unknown timout type = " << _t); 00128 } 00129 }
1.5.5