![]() |
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. 16, 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 <TCP/SlowStart.hpp> 00029 00030 00031 using namespace tcp; 00032 00033 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00034 SlowStart, 00035 SlowStartStrategy, 00036 "tcp.SlowStart", 00037 wns::PyConfigViewCreator 00038 ); 00039 00040 00041 SlowStart::SlowStart(const wns::pyconfig::View& _pyco): 00042 pyco(_pyco), 00043 cwnd(pyco.get<int>("congestionWindow")), 00044 ssthresh(pyco.get<unsigned long int>("ssthresh")), 00045 logger(pyco.get("logger")), 00046 timeout(pyco.get<simTimeType>("retransmissionTimeout")) 00047 { 00048 } 00049 00050 00051 SlowStart::~SlowStart() 00052 { 00053 } 00054 00055 00056 void 00057 SlowStart::onSegmentLoss(segmentLoss reason, unsigned long int /*_ackNR*/) 00058 { 00059 MESSAGE_SINGLE(NORMAL, logger, "onSegmentLoss called. Reason: " << printReason(reason)); 00060 00061 switch(reason) 00062 { 00063 case TIMEOUT: 00064 reCalcThreshold(); 00065 setWindowSize(1); 00066 break; 00067 00068 case DUPLICATE_ACK: 00069 reCalcThreshold(); 00070 setWindowSize(cwnd/2); 00071 break; 00072 00073 default: 00074 break; 00075 } 00076 } 00077 00078 00079 void 00080 SlowStart::onRTTSample() 00081 { 00082 } 00083 00084 00085 unsigned long int 00086 SlowStart::getWindowSize() 00087 { 00088 return cwnd; 00089 } 00090 00091 00092 simTimeType 00093 SlowStart::getRetransmissionTimeout() 00094 { 00095 MESSAGE_SINGLE(NORMAL, logger, "Timeout for retransmission: " << timeout); 00096 return this->timeout; 00097 } 00098 00099 00100 void 00101 SlowStart::onSegmentAcknowledged() 00102 { 00103 cwnd++; 00104 MESSAGE_SINGLE(NORMAL, logger, "Segment acknowledged. Window size: " << cwnd); 00105 } 00106 00107 00108 void 00109 SlowStart::setWindowSize(unsigned long int new_cwnd) 00110 { 00111 MESSAGE_SINGLE(NORMAL, logger, "Setting window size: " << new_cwnd << "(old value: " << cwnd << ")"); 00112 cwnd = new_cwnd; 00113 } 00114 00115 00116 bool 00117 SlowStart::duplicateACKThresholdReached(unsigned long int /*_ackNR*/) 00118 { 00119 // threshold for fast retransmit; implemented in tahoe congestion avoidance 00120 assure(false, "SlowStart::duplicateACKThresholdReached should never be called!"); 00121 return false; 00122 } 00123 00124 00125 void 00126 SlowStart::clearDuplicateACKCounter() 00127 {// nothing to do 00128 } 00129 00130 00131 unsigned long int 00132 SlowStart::getSlowStartThreshold() 00133 { 00134 MESSAGE_SINGLE(NORMAL, logger, "SlowStart threshold: " << ssthresh); 00135 return this->ssthresh; 00136 } 00137 00138 00139 void 00140 SlowStart::reCalcThreshold() 00141 { 00142 unsigned long int prior_ssthresh __attribute__ ((unused)) = ssthresh; 00143 this->ssthresh = max(getWindowSize()>>1, 2); 00144 MESSAGE_SINGLE(NORMAL, logger, "Recalculate SlowStart threshold: " << ssthresh << "(old value: " << prior_ssthresh << ")."); 00145 } 00146 00147 00148 std::string 00149 SlowStart::printReason(segmentLoss reason) 00150 { 00151 switch(reason){ 00152 case TIMEOUT: 00153 return "TIMEOUT"; 00154 break; 00155 case DUPLICATE_ACK: 00156 return "DUPLICATE_ACK"; 00157 break; 00158 default: 00159 assure(false, "Unknown segment loss!"); 00160 return ""; 00161 break; 00162 } 00163 } 00164 00165 00166 unsigned long int 00167 SlowStart::max(unsigned long int x, unsigned long int y) 00168 { 00169 return (x<y) ? y : x; 00170 }
1.5.5