![]() |
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/Email.hpp> 00029 00030 using namespace applications::session::server; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::server::Email, 00033 applications::session::Session, 00034 "server.Email", wns::PyConfigViewCreator); 00035 00036 Email::Email(const wns::pyconfig::View& _pyco) : 00037 Session(_pyco), 00038 emailSizeChoiceDistribution(NULL), 00039 largeEmailSizeDistribution(NULL), 00040 smallEmailSizeDistribution(NULL), 00041 lastEmailSent(false), 00042 request(false) 00043 { 00044 wns::pyconfig::View nOEConfig(_pyco, "numberOfEmails"); 00045 std::string nOEName = nOEConfig.get<std::string>("__plugin__"); 00046 numberOfEmailsDistribution = wns::distribution::DistributionFactory::creator(nOEName)->create(nOEConfig); 00047 00048 wns::pyconfig::View eSCConfig(_pyco, "emailChoice"); 00049 std::string eSCName = eSCConfig.get<std::string>("__plugin__"); 00050 emailSizeChoiceDistribution = wns::distribution::DistributionFactory::creator(eSCName)->create(eSCConfig); 00051 00052 wns::pyconfig::View lESConfig(_pyco, "largeEmailSize"); 00053 std::string lESName = lESConfig.get<std::string>("__plugin__"); 00054 largeEmailSizeDistribution = wns::distribution::DistributionFactory::creator(lESName)->create(lESConfig); 00055 00056 wns::pyconfig::View sESConfig(_pyco, "smallEmailSize"); 00057 std::string sESName = sESConfig.get<std::string>("__plugin__"); 00058 smallEmailSizeDistribution = wns::distribution::DistributionFactory::creator(sESName)->create(sESConfig); 00059 00060 settlingTime = _pyco.get<wns::simulator::Time>("settlingTime"); 00061 00062 emailState = sendemail; //sendpop3ok; If session is started with POP3! 00063 state = idle; 00064 00065 numberOfEmails = (*numberOfEmailsDistribution)(); 00066 00067 MESSAGE_BEGIN(NORMAL, logger, m, "APPL: Number of emails client has to receive is "); 00068 m << numberOfEmails << "."; 00069 MESSAGE_END(); 00070 00071 /* only for probing */ 00072 sessionType = email; 00073 00074 packetFrom = "server.Email"; 00075 } 00076 00077 Email::~Email() 00078 { 00079 if (numberOfEmailsDistribution != NULL) 00080 delete numberOfEmailsDistribution; 00081 numberOfEmailsDistribution = NULL; 00082 00083 if(emailSizeChoiceDistribution != NULL) 00084 delete emailSizeChoiceDistribution; 00085 emailSizeChoiceDistribution = NULL; 00086 00087 if(smallEmailSizeDistribution !=NULL) 00088 delete smallEmailSizeDistribution; 00089 smallEmailSizeDistribution = NULL; 00090 00091 if(largeEmailSizeDistribution != NULL) 00092 delete largeEmailSizeDistribution; 00093 largeEmailSizeDistribution = NULL; 00094 } 00095 00096 void 00097 Email::onData(const wns::osi::PDUPtr& _pdu) 00098 { 00099 assureType(_pdu.getPtr(), applications::session::PDU*); 00100 00101 receivedPacketNumber = static_cast<applications::session::PDU*>(_pdu.getPtr())->getPacketNumber(); 00102 00103 MESSAGE_SINGLE(NORMAL, logger, "APPL: receivedPacketNumber = " << receivedPacketNumber << "."); 00104 00105 request = static_cast<applications::session::PDU*>(_pdu.getPtr())->getRequest(); 00106 lastPacket = static_cast<applications::session::PDU*>(_pdu.getPtr())->getLastPacket(); 00107 00108 applications::session::Session::incomingProbesCalculation(_pdu); 00109 00110 if((receivedPacketNumber == 1) && (state != sessionended)) 00111 { 00112 state = running; 00113 00114 firstPacketDelay = packetDelay; 00115 } 00116 00117 if(lastPacket == true) 00118 { 00119 /* Wait till session ends if all emails received AND all emails were sent. */ 00120 00121 MESSAGE_SINGLE(NORMAL, logger, "APPL: All emails were sent and received. Now wait till session ends."); 00122 } 00123 else if(lastEmailSent == true && request == true) 00124 { 00125 /* Client received all emails. Now client wants to send emails.*/ 00126 // onTimeout(sendtimeout); 00127 } 00128 else if(lastEmailSent == false && request == true && state != sessionended) 00129 { 00130 state = running; 00131 00132 onTimeout(receivetimeout); 00133 } 00134 } 00135 00136 void 00137 Email::onTimeout(const Timeout& _t) 00138 { 00139 if(_t == receivetimeout) 00140 { 00141 if(emailState == sendemail) 00142 { 00143 /* Request for email received. Now sending email.*/ 00144 double emailSizeChoice = (*emailSizeChoiceDistribution)(); 00145 if(emailSizeChoice <= 0.8) 00146 { 00147 double distributedValue = (*smallEmailSizeDistribution)(); 00148 /* The distributed value is in Kbyte, so it has to be converted to bit! */ 00149 packetSize = distributedValue * 8.0 * 1024.0;; 00150 } 00151 else 00152 { 00153 double distributedValue = (*largeEmailSizeDistribution)(); 00154 /* The distributed value is in Kbyte, so it has to be converted to bit! */ 00155 packetSize = distributedValue * 8.0 * 1024.0; 00156 } 00157 00158 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00159 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00160 00161 ++packetNumber; 00162 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00163 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00164 00165 state = idle; 00166 00167 if(numberOfEmails == 1) 00168 { 00169 /* sending last email */ 00170 applicationPDU->setLastPacket(true); 00171 wns::osi::PDUPtr pdu(applicationPDU); 00172 applications::session::Session::outgoingProbesCalculation(pdu); 00173 00174 connection->sendData(pdu); 00175 00176 lastEmailSent = true; 00177 } 00178 else 00179 { 00180 numberOfEmails = numberOfEmails - 1; 00181 wns::osi::PDUPtr pdu(applicationPDU); 00182 applications::session::Session::outgoingProbesCalculation(pdu); 00183 00184 connection->sendData(pdu); 00185 } 00186 } 00187 else if(emailState == sendpop3ok) 00188 { 00189 /* Sending response POP3 OK.*/ 00190 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending POP3 OK!"); 00191 00192 packetSize = 648; 00193 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00194 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00195 00196 ++packetNumber; 00197 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00198 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00199 00200 wns::osi::PDUPtr pdu(applicationPDU); 00201 applications::session::Session::outgoingProbesCalculation(pdu); 00202 00203 connection->sendData(pdu); 00204 00205 emailState = sendusernameok; 00206 state = idle; 00207 } 00208 else if(emailState == sendusernameok) 00209 { 00210 /* Username received. Sending username OK.*/ 00211 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending username OK!"); 00212 00213 packetSize = 440; 00214 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00215 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00216 00217 ++packetNumber; 00218 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00219 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00220 00221 wns::osi::PDUPtr pdu(applicationPDU); 00222 applications::session::Session::outgoingProbesCalculation(pdu); 00223 00224 connection->sendData(pdu); 00225 00226 emailState = sendpasswordok; 00227 state = idle; 00228 } 00229 else if(emailState == sendpasswordok) 00230 { 00231 /* Password received. Sending password OK.*/ 00232 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending password OK!"); 00233 00234 packetSize = 440; 00235 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00236 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00237 00238 ++packetNumber; 00239 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00240 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00241 00242 wns::osi::PDUPtr pdu(applicationPDU); 00243 applications::session::Session::outgoingProbesCalculation(pdu); 00244 00245 connection->sendData(pdu); 00246 00247 emailState = sendemail; 00248 state = idle; 00249 } 00250 } 00251 else if(_t == sendtimeout) 00252 { 00253 /* Now sending SMTP OK. */ 00254 MESSAGE_SINGLE(NORMAL, logger, "APPL: Sending SMTP OK"); 00255 00256 packetSize = 648; 00257 applications::session::PDU* applicationPDU = new applications::session::PDU(Bit(packetSize), pyco); 00258 applicationPDU->setCreationTime(wns::simulator::getEventScheduler()->getTime()); 00259 00260 packetNumber = 1; 00261 applicationPDU->setPacketNumber(packetNumber, packetFrom); 00262 MESSAGE_SINGLE(NORMAL, logger, "APPL: PacketNumber = " << packetNumber << "."); 00263 00264 applicationPDU->setLastPacket(true); 00265 00266 wns::osi::PDUPtr pdu(applicationPDU); 00267 applications::session::Session::outgoingProbesCalculation(pdu); 00268 00269 connection->sendData(pdu); 00270 state = idle; 00271 } 00272 else if(_t == probetimeout) 00273 { 00274 applications::session::Session::onTimeout(_t); 00275 } 00276 else 00277 { 00278 assure(false, "APPL: Unknown timout type =" << _t); 00279 } 00280 }
1.5.5