![]() |
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/FTP.hpp> 00029 00030 using namespace applications::session::client; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::client::FTP, 00033 applications::session::Session, 00034 "client.FTP", wns::PyConfigViewCreator); 00035 00036 FTP::FTP(const wns::pyconfig::View& _pyco) : 00037 Session(_pyco), 00038 amountOfDataDistribution(NULL), 00039 readingTimeDistribution(NULL), 00040 numberOfFiles(2), 00041 filePacketSize(0), 00042 request(true) 00043 { 00044 wns::pyconfig::View aDDConfig(_pyco, "amountOfData"); 00045 std::string aDDName = aDDConfig.get<std::string>("__plugin__"); 00046 amountOfDataDistribution = wns::distribution::DistributionFactory::creator(aDDName)->create(aDDConfig); 00047 00048 wns::pyconfig::View rTDConfig(_pyco, "readingTime"); 00049 std::string rTDName = rTDConfig.get<std::string>("__plugin__"); 00050 readingTimeDistribution = wns::distribution::DistributionFactory::creator(rTDName)->create(rTDConfig); 00051 00052 ftpState = waitforpasswordok;//requestftpok; 00053 00054 settlingTime = _pyco.get<wns::simulator::Time>("settlingTime"); 00055 00056 sessionDelay = (*sessionDelayDistribution)(); 00057 MESSAGE_SINGLE(NORMAL, logger, "APPL: Delay before session starts: " << sessionDelay << ".\n"); 00058 00059 setTimeout(connectiontimeout, sessionDelay); 00060 setTimeout(probetimeout, windowSize); 00061 00062 state = running; 00063 00064 /* only for probing */ 00065 sessionType = ftp; 00066 } 00067 00068 FTP::~FTP() 00069 { 00070 if(amountOfDataDistribution != NULL) 00071 delete amountOfDataDistribution; 00072 amountOfDataDistribution = NULL; 00073 00074 if(readingTimeDistribution != NULL) 00075 delete readingTimeDistribution; 00076 readingTimeDistribution = NULL; 00077 } 00078 00079 void 00080 FTP::onData(const wns::osi::PDUPtr& _pdu) 00081 { 00082 assureType(_pdu.getPtr(), applications::session::PDU*); 00083 00084 receivedPacketNumber = static_cast<applications::session::PDU*>(_pdu.getPtr())->getPacketNumber(); 00085 00086 MESSAGE_SINGLE(NORMAL, logger, "APPL: Received packetNumber " << receivedPacketNumber << "."); 00087 00088 applications::session::Session::incomingProbesCalculation(_pdu); 00089 00090 lastPacket = static_cast<applications::session::PDU*>(_pdu.getPtr())->getLastPacket(); 00091 request = static_cast<applications::session::PDU*>(_pdu.getPtr())->getRequest(); 00092 00093 if(request == false) 00094 { 00095 MESSAGE_SINGLE(NORMAL, logger, "APPL: Acknowledgement about upload received!"); 00096 } 00097 else if((lastPacket == false) && (state != sessionended)) 00098 { 00099 onTimeout(statetimeout); 00100 00101 state = running; 00102 } 00103 else 00104 { 00105 /* Last file received. First read this file and than wait till session ends. */ 00106 00107 MESSAGE_SINGLE(NORMAL, logger, "APPL: Received last requested file."); 00108 00109 wns::simulator::Time readingTime = (*readingTimeDistribution)(); 00110 } 00111 } 00112 00113 void 00114 FTP::onTimeout(const Timeout& _t) 00115 { 00116 if(_t == statetimeout) 00117 { 00118 if(ftpState == requestdata) 00119 { 00120 /* Uploaded one file. Now sending request for data. */ 00121 packetSize = 1600; 00122 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00123 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00124 applicationPDU->setRequest(true); 00125 00126 ++packetNumber; 00127 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00128 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00129 00130 double distributedValue = (*amountOfDataDistribution)(); 00131 /* The distributed value is in Mbyte, so it has to be converted to bit! */ 00132 filePacketSize = distributedValue * 8.0 * 1024.0 * 1024.0; 00133 00134 MESSAGE_SINGLE(NORMAL, logger, "APPL: Requesting file with a size of " << filePacketSize << " bits."); 00135 00136 applicationPDU->setFileLength(filePacketSize); 00137 00138 if(numberOfFiles == 1) 00139 { 00140 /* Sending request for last data. */ 00141 applicationPDU->setLastPacket(true); 00142 } 00143 00144 wns::osi::PDUPtr pdu(applicationPDU); 00145 applications::session::Session::outgoingProbesCalculation(pdu); 00146 00147 numberOfFiles = numberOfFiles - 1; 00148 00149 connection->sendData(pdu); 00150 00151 ftpState = reading; 00152 state = idle; 00153 } 00154 else if(ftpState == reading) 00155 { 00156 /* Data received. Now reading it */ 00157 wns::simulator::Time readingTime = (*readingTimeDistribution)(); 00158 00159 MESSAGE_SINGLE(NORMAL, logger, "APPL: Received requested file."); 00160 00161 setTimeout(statetimeout, readingTime); 00162 00163 ftpState = requestdata; 00164 state = running; 00165 } 00166 else if(ftpState == waitforpasswordok) 00167 { 00168 double distributedValue = (*amountOfDataDistribution)(); 00169 /* The distributed value is in Mbyte, so it has to be converted to bit! */ 00170 packetSize = distributedValue * 8.0 * 1024.0 * 1024.0; 00171 00172 MESSAGE_SINGLE(NORMAL, logger, "APPL: Uploading file with packetSize = " << packetSize); 00173 00174 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00175 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00176 00177 ++packetNumber; 00178 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00179 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00180 00181 wns::osi::PDUPtr pdu(applicationPDU); 00182 applications::session::Session::outgoingProbesCalculation(pdu); 00183 00184 connection->sendData(pdu); 00185 00186 ftpState = requestdata; 00187 state = idle; 00188 00189 onTimeout(statetimeout); 00190 } 00191 else if(ftpState == waitforusernameok) 00192 { 00193 MESSAGE_SINGLE(NORMAL, logger, "APPL: Username ok received. Now sending password ok request."); 00194 00195 /* Received username OK. Sending request for password OK. */ 00196 packetSize = 240; 00197 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00198 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00199 applicationPDU->setRequest(true); 00200 00201 ++packetNumber; 00202 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00203 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00204 00205 wns::osi::PDUPtr pdu(applicationPDU); 00206 applications::session::Session::outgoingProbesCalculation(pdu); 00207 00208 connection->sendData(pdu); 00209 00210 ftpState = waitforpasswordok; 00211 state = idle; 00212 } 00213 else if(ftpState == waitforftpok) 00214 { 00215 MESSAGE_SINGLE(NORMAL, logger, "APPL: FTP OK received. Now sending username ok request."); 00216 00217 /* Received FTP OK. Sending request for username OK. */ 00218 packetSize = 240; 00219 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00220 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00221 applicationPDU->setRequest(true); 00222 00223 ++packetNumber; 00224 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00225 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00226 00227 wns::osi::PDUPtr pdu(applicationPDU); 00228 applications::session::Session::outgoingProbesCalculation(pdu); 00229 00230 connection->sendData(pdu); 00231 00232 ftpState = waitforusernameok; 00233 state = idle; 00234 } 00235 else if(ftpState == requestftpok) 00236 { 00237 /* Sending request for FTP OK. */ 00238 MESSAGE_SINGLE(NORMAL, logger, "APPL: Start sending FTP OK request."); 00239 00240 packetSize = 648; 00241 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00242 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00243 applicationPDU->setRequest(true); 00244 00245 packetNumber = 1; 00246 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00247 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00248 00249 wns::osi::PDUPtr pdu(applicationPDU); 00250 applications::session::Session::outgoingProbesCalculation(pdu); 00251 00252 connection->sendData(pdu); 00253 00254 ftpState = waitforftpok; 00255 state = idle; 00256 } 00257 } 00258 else if(_t == connectiontimeout) 00259 { 00260 packetFrom = "client.FTP"; 00261 00262 /* Open connection */ 00263 binding->initBinding(); 00264 } 00265 else if(_t == probetimeout) 00266 { 00267 applications::session::Session::onTimeout(_t); 00268 } 00269 else 00270 { 00271 assure(false, "APPL: Unknown timout type =" << _t); 00272 } 00273 } 00274
1.5.5