![]() |
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/client/WWW.hpp> 00029 00030 using namespace applications::session::client; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::client::WWW, 00033 applications::session::Session, 00034 "client.WWW", wns::PyConfigViewCreator); 00035 00036 WWW::WWW(const wns::pyconfig::View& _pyco) : 00037 Session(_pyco), 00038 readingTimeDistribution(NULL), 00039 parsingTimeDistribution(NULL), 00040 embeddedObjectsPerPageDistribution(NULL), 00041 readingTime(0.0), 00042 parsingTime(0.0), 00043 mainObject(true) 00044 { 00045 wns::pyconfig::View rTDConfig(_pyco, "readingTime"); 00046 std::string rTDName = rTDConfig.get<std::string>("__plugin__"); 00047 readingTimeDistribution = wns::distribution::DistributionFactory::creator(rTDName)->create(rTDConfig); 00048 00049 wns::pyconfig::View pTDConfig(_pyco, "parsingTime"); 00050 std::string pTDName = pTDConfig.get<std::string>("__plugin__"); 00051 parsingTimeDistribution = wns::distribution::DistributionFactory::creator(pTDName)->create(pTDConfig); 00052 00053 wns::pyconfig::View eOPPConfig(_pyco, "embeddedObjectsPerPage"); 00054 std::string eOPPName = eOPPConfig.get<std::string>("__plugin__"); 00055 embeddedObjectsPerPageDistribution = wns::distribution::DistributionFactory::creator(eOPPName)->create(eOPPConfig); 00056 00057 embeddedObjectsPerPage = (*embeddedObjectsPerPageDistribution)(); 00058 00059 MESSAGE_SINGLE(NORMAL, logger, "APPL: Number of embedded objects per page = " << embeddedObjectsPerPage << "."); 00060 00061 settlingTime = _pyco.get<wns::simulator::Time>("settlingTime"); 00062 00063 state = running; 00064 00065 /* only for probing */ 00066 sessionType = www; 00067 00068 sessionDelay = (*sessionDelayDistribution)(); 00069 MESSAGE_SINGLE(NORMAL, logger, "APPL: Delay before session starts: " << sessionDelay << ".\n"); 00070 00071 setTimeout(connectiontimeout, sessionDelay); 00072 setTimeout(probetimeout, windowSize); 00073 } 00074 00075 WWW::~WWW() 00076 { 00077 if (readingTimeDistribution != NULL) 00078 delete readingTimeDistribution; 00079 readingTimeDistribution = NULL; 00080 00081 if (parsingTimeDistribution != NULL) 00082 delete parsingTimeDistribution; 00083 parsingTimeDistribution = NULL; 00084 00085 if(embeddedObjectsPerPageDistribution != NULL) 00086 delete embeddedObjectsPerPageDistribution; 00087 embeddedObjectsPerPageDistribution = NULL; 00088 } 00089 00090 void 00091 WWW::onData(const wns::osi::PDUPtr& _pdu) 00092 { 00093 assureType(_pdu.getPtr(), applications::session::PDU*); 00094 00095 receivedPacketNumber = static_cast<applications::session::PDU*>(_pdu.getPtr())->getPacketNumber(); 00096 00097 MESSAGE_SINGLE(NORMAL, logger, "APPL: receivedPacketNumber = " << receivedPacketNumber << "."); 00098 00099 applications::session::Session::incomingProbesCalculation(_pdu); 00100 00101 lastPacket = static_cast<applications::session::PDU*>(_pdu.getPtr())->getLastPacket(); 00102 00103 if(receivedPacketNumber == 1 && state != sessionended) 00104 { 00105 state = running; 00106 00107 onTimeout(receivetimeout); 00108 } 00109 else if(lastPacket == false && state != sessionended) 00110 { 00111 state = running; 00112 00113 /* Embedded object received. First read the page and than transit to an other page.*/ 00114 readingTime = (*readingTimeDistribution)(); 00115 00116 MESSAGE_SINGLE(NORMAL, logger, "APPL: Embedded object received. Readingtime = " << readingTime << "."); 00117 00118 setTimeout(statetimeout, readingTime); 00119 } 00120 else 00121 { 00122 /* Last object received. First read the page and than wait till session ends. */ 00123 readingTime = (*readingTimeDistribution)(); 00124 MESSAGE_SINGLE(NORMAL, logger, "APPL: Last embedded object received. Readingtime = " << readingTime << "."); 00125 } 00126 } 00127 00128 void 00129 WWW::onTimeout(const Timeout& _t) 00130 { 00131 if(_t == statetimeout) 00132 { 00133 if(mainObject == false) 00134 { 00135 state = idle; 00136 00137 /* Requesting embedded objects. */ 00138 MESSAGE_SINGLE(NORMAL, logger, "APPL: Requesting embedded object."); 00139 embeddedObjectsPerPage = embeddedObjectsPerPage - 1; 00140 00141 /* Acording to "IEEE 802.16m Evaluation Methodology Document(2009), Page 109, section 10.1" 00142 the HTTP request packet has a constant size of 350 bytes(=2800 bit). */ 00143 packetSize = 2800; 00144 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00145 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00146 00147 ++packetNumber; 00148 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00149 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00150 00151 if(embeddedObjectsPerPage == 0) 00152 { 00153 state = sessionended; 00154 00155 /* Requesting LAST embeddedObject. */ 00156 applicationPDU->setLastPacket(true); 00157 } 00158 wns::osi::PDUPtr pdu(applicationPDU); 00159 applications::session::Session::outgoingProbesCalculation(pdu); 00160 00161 connection->sendData(pdu); 00162 } 00163 else 00164 { 00165 /* Requesting main object. */ 00166 MESSAGE_SINGLE(NORMAL, logger, "APPL: Requesting main object."); 00167 00168 /* Acording to "IEEE 802.16m Evaluation Methodology Document(2009), Page 109, section 10.1" 00169 the HTTP request packet has a constant size of 350 bytes(=2800 bit). */ 00170 packetSize = 2800; 00171 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00172 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00173 applicationPDU->setRequest(true); 00174 00175 packetNumber = 1; 00176 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00177 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00178 00179 wns::osi::PDUPtr pdu(applicationPDU); 00180 applications::session::Session::outgoingProbesCalculation(pdu); 00181 00182 connection->sendData(pdu); 00183 00184 mainObject = false; 00185 00186 state = idle; 00187 } 00188 } 00189 else if(_t == receivetimeout) 00190 { 00191 /* Main object received. After a parsingtime for the main page the embedded objects will be requested. */ 00192 parsingTime = (*parsingTimeDistribution)(); 00193 00194 MESSAGE_SINGLE(NORMAL, logger, "APPL: Main object received."); 00195 00196 setTimeout(statetimeout, parsingTime); 00197 } 00198 else if(_t == connectiontimeout) 00199 { 00200 packetFrom = "client.WWW"; 00201 00202 /* Open connection */ 00203 binding->initBinding(); 00204 } 00205 else if(_t == probetimeout) 00206 { 00207 applications::session::Session::onTimeout(_t); 00208 } 00209 else 00210 { 00211 assure(false, "APPL: Unknown timout type =" << _t); 00212 } 00213 } 00214
1.5.5