![]() |
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/FTP.hpp> 00029 00030 using namespace applications::session::server; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::server::FTP, 00033 applications::session::Session, 00034 "server.FTP", wns::PyConfigViewCreator); 00035 00036 FTP::FTP(const wns::pyconfig::View& _pyco): 00037 Session(_pyco), 00038 request(false) 00039 { 00040 settlingTime = _pyco.get<wns::simulator::Time>("settlingTime"); 00041 00042 ftpState = waitfordatarequest; //sendftpok; 00043 state = idle; 00044 00045 /* only for probing */ 00046 sessionType = ftp; 00047 00048 packetFrom = "server.FTP"; 00049 } 00050 00051 FTP::~FTP() 00052 { 00053 } 00054 00055 void 00056 FTP::onData(const wns::osi::PDUPtr& _pdu) 00057 { 00058 assureType(_pdu.getPtr(), applications::session::PDU*); 00059 00060 receivedPacketNumber = static_cast<applications::session::PDU*>(_pdu.getPtr())->getPacketNumber(); 00061 00062 MESSAGE_SINGLE(NORMAL, logger, "APPL: Received packetNumber " << receivedPacketNumber << "."); 00063 00064 packetSize = static_cast<applications::session::PDU*>(_pdu.getPtr())->getFileLength(); 00065 00066 applications::session::Session::incomingProbesCalculation(_pdu); 00067 00068 if(receivedPacketNumber == 1 && state != sessionended) 00069 { 00070 state = running; 00071 00072 firstPacketDelay = packetDelay; 00073 } 00074 00075 lastPacket = static_cast<applications::session::PDU*>(_pdu.getPtr())->getLastPacket(); 00076 request = static_cast<applications::session::PDU*>(_pdu.getPtr())->getRequest(); 00077 00078 if(request == false) 00079 { 00080 /* Client uploaded file. Send acknowledgement massage!*/ 00081 packetSize = 16; 00082 00083 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00084 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00085 applicationPDU->setRequest(false); 00086 00087 ++packetNumber; 00088 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00089 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00090 00091 wns::osi::PDUPtr pdu(applicationPDU); 00092 applications::session::Session::outgoingProbesCalculation(pdu); 00093 00094 connection->sendData(pdu); 00095 } 00096 else if((lastPacket == false) && (state != sessionended)) 00097 { 00098 state = running; 00099 00100 onTimeout(statetimeout); 00101 } 00102 else 00103 { 00104 /* Sending last requested data and than wait till session ends! */ 00105 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00106 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00107 applicationPDU->setRequest(true); 00108 applicationPDU->setLastPacket(true); 00109 00110 ++packetNumber; 00111 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00112 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00113 00114 wns::osi::PDUPtr pdu(applicationPDU); 00115 applications::session::Session::outgoingProbesCalculation(pdu); 00116 00117 connection->sendData(pdu); 00118 } 00119 } 00120 00121 void 00122 FTP::onTimeout(const Timeout& _t) 00123 { 00124 if(_t == statetimeout) 00125 { 00126 if(ftpState == waitfordatarequest) 00127 { 00128 /* Sending requested data! */ 00129 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00130 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00131 applicationPDU->setRequest(true); 00132 00133 ++packetNumber; 00134 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00135 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00136 00137 wns::osi::PDUPtr pdu(applicationPDU); 00138 applications::session::Session::outgoingProbesCalculation(pdu); 00139 00140 connection->sendData(pdu); 00141 00142 state = idle; 00143 } 00144 else if(ftpState == sendftpok) 00145 { 00146 /* Sending FTP OK to client. */ 00147 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending FTP OK."); 00148 00149 packetSize = 648; 00150 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00151 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00152 applicationPDU->setRequest(true); 00153 00154 packetNumber = 1; 00155 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00156 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00157 00158 wns::osi::PDUPtr pdu(applicationPDU); 00159 applications::session::Session::outgoingProbesCalculation(pdu); 00160 00161 connection->sendData(pdu); 00162 00163 ftpState = sendusernameok; 00164 state = idle; 00165 } 00166 else if(ftpState == sendusernameok) 00167 { 00168 /* Sending username ok to client. */ 00169 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending username OK."); 00170 00171 packetSize = 440; 00172 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00173 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00174 applicationPDU->setRequest(true); 00175 00176 ++packetNumber; 00177 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00178 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00179 00180 wns::osi::PDUPtr pdu(applicationPDU); 00181 applications::session::Session::outgoingProbesCalculation(pdu); 00182 00183 connection->sendData(pdu); 00184 00185 ftpState = sendpasswordok; 00186 state = idle; 00187 } 00188 else if(ftpState == sendpasswordok) 00189 { 00190 /* Sending password ok.*/ 00191 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending password OK!"); 00192 00193 packetSize = 440; 00194 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00195 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00196 applicationPDU->setRequest(true); 00197 00198 ++packetNumber; 00199 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00200 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00201 00202 wns::osi::PDUPtr pdu(applicationPDU); 00203 applications::session::Session::outgoingProbesCalculation(pdu); 00204 00205 connection->sendData(pdu); 00206 00207 ftpState = waitfordatarequest; 00208 state = idle; 00209 } 00210 } 00211 else if(_t == probetimeout) 00212 { 00213 applications::session::Session::onTimeout(_t); 00214 } 00215 else 00216 { 00217 assure(false, "APPL: Unknown timout type =" << _t); 00218 } 00219 }
1.5.5