User Manual, Developers Guide and API Documentation

CBR.cpp

Go to the documentation of this file.
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/client/CBR.hpp>
00029 
00030 using namespace applications::session::client;
00031 
00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::client::CBR,
00033                      applications::session::Session,
00034                      "client.CBR", wns::PyConfigViewCreator);
00035 
00036 CBR::CBR(const wns::pyconfig::View& _pyco) :
00037   session::client::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   state = running;
00050 
00051   settlingTime = _pyco.get<wns::simulator::Time>("settlingTime");
00052 
00053   /* Delay before session starts, otherwise all sessions will start at the same time. */
00054   sessionDelay = (*sessionDelayDistribution)();
00055   MESSAGE_SINGLE(NORMAL, logger, "APPL: Delay before session starts: " << sessionDelay << ".\n");
00056 
00057   setTimeout(connectiontimeout, sessionDelay);
00058   setTimeout(probetimeout, windowSize);
00059 
00060   /* only for probing */
00061   sessionType = cbr;
00062 }
00063 
00064 CBR::~CBR()
00065 {
00066   if(packetSizeDistribution != NULL)
00067     delete packetSizeDistribution;
00068   packetSizeDistribution = NULL;
00069 
00070   if(bitRateDistribution != NULL)
00071     delete bitRateDistribution;
00072   bitRateDistribution = NULL;
00073 }
00074 
00075 void
00076 CBR::onData(const wns::osi::PDUPtr& _pdu)
00077 {
00078   state = running;
00079 
00080   assureType(_pdu.getPtr(), applications::session::PDU*);
00081 
00082   receivedPacketNumber = static_cast<applications::session::PDU*>(_pdu.getPtr())->getPacketNumber();
00083 
00084   MESSAGE_SINGLE(NORMAL, logger, "APPL: Received packetNumber " << receivedPacketNumber << ".");
00085 
00086   applications::session::Session::incomingProbesCalculation(_pdu);
00087 
00088   lastPacket = static_cast<applications::session::PDU*>(_pdu.getPtr())->getLastPacket();
00089 
00090   state = idle;
00091 }
00092 
00093 void
00094 CBR::onTimeout(const Timeout& _t)
00095 {
00096   if(_t == statetimeout)
00097     {
00098       packetSize = (*packetSizeDistribution)();
00099       bitRate = (*bitRateDistribution)();
00100       iat = (double(packetSize) / double(bitRate));
00101 
00102       MESSAGE_BEGIN(NORMAL, logger, m, "APPL: New running Client CBR Session: ");
00103       m << "iat = " << iat;
00104       m << ", packetSize = " << packetSize;
00105       m << ", bitRate = " << bitRate;
00106       MESSAGE_END();
00107 
00108       applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco);
00109 
00110       applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime());
00111 
00112       packetNumber = 1;
00113       applicationPDU->setPacketNumber(packetNumber, packetFrom);
00114       MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << " from " << packetFrom << ".");
00115 
00116       wns::osi::PDUPtr pdu(applicationPDU);
00117 
00118       MESSAGE_SINGLE(NORMAL, logger, "APPL: Generated pdu with " << packetSize << " bits.");
00119 
00120       applications::session::Session::outgoingProbesCalculation(pdu);
00121 
00122       connection->sendData(pdu);
00123 
00124       state = idle;
00125     }
00126   else if(_t == connectiontimeout)
00127     {
00128       packetFrom = "client.CBR" + packetFromID;
00129 
00130       /* Open connection */
00131       binding->initBinding();
00132     }
00133   else if(_t == probetimeout)
00134     {
00135       applications::session::Session::onTimeout(_t);
00136     }
00137   else
00138     {
00139       assure(false, "APPL: Unknown timout type =" << _t);
00140     }
00141 }
00142 
00143 

Generated on Sun May 27 03:32:15 2012 for openWNS by  doxygen 1.5.5