![]() |
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/TahoeCongAvoid.hpp> 00029 00030 00031 using namespace tcp; 00032 00033 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00034 TahoeCongAvoid, 00035 CongestionAvoidanceStrategy, 00036 "tcp.TahoeCongAvoid", 00037 wns::PyConfigViewCreator 00038 ); 00039 00040 00041 TahoeCongAvoid::TahoeCongAvoid(const wns::pyconfig::View& _pyco): 00042 pyco(_pyco), 00043 cwnd(pyco.get<unsigned long int>("congestionWindow")), 00044 cwnd_cnt(pyco.get<unsigned long int>("congestionWindowCounter")), 00045 logger(pyco.get("logger")), 00046 timeout(pyco.get<simTimeType>("retransmissionTimeout")), 00047 ndup(pyco.get<int>("numberDupACKs")), 00048 countDuplicateACKs() 00049 { 00050 countDuplicateACKs.clear(); 00051 } 00052 00053 TahoeCongAvoid::~TahoeCongAvoid() 00054 { 00055 countDuplicateACKs.clear(); 00056 } 00057 00058 void 00059 TahoeCongAvoid::onSegmentLoss(segmentLoss reason, unsigned long int _ackNR) 00060 { 00061 MESSAGE_SINGLE(NORMAL, logger, "onSegmentLoss called. Reason: " << printReason(reason)); 00062 00063 switch(reason) 00064 { 00065 case(TIMEOUT): 00066 countDuplicateACKs.clear(); 00067 setWindowSize(1); 00068 00069 break; 00070 00071 case(DUPLICATE_ACK): 00072 if(!countDuplicateACKs.knows(_ackNR)) 00073 { 00074 // increase if ndup duplicate acks occure 00075 // _in a row_ 00076 countDuplicateACKs.clear(); 00077 // 1st dup ack is 2nd ack of same nr in a row 00078 countDuplicateACKs.insert(_ackNR, 2); 00079 } 00080 else 00081 { 00082 int tmp = countDuplicateACKs.find(_ackNR); 00083 if(tmp < ndup) 00084 { 00085 tmp++; 00086 countDuplicateACKs.update(_ackNR, tmp); 00087 } 00088 else 00089 { 00090 unsigned long int curr_cwnd = getWindowSize(); 00091 setWindowSize(curr_cwnd/2); 00092 } 00093 } 00094 00095 break; 00096 00097 default: 00098 break; 00099 } 00100 } 00101 00102 00103 void 00104 TahoeCongAvoid::onRTTSample() 00105 { 00106 } 00107 00108 unsigned long int 00109 TahoeCongAvoid::getWindowSize() 00110 { 00111 return cwnd; 00112 } 00113 00114 simTimeType 00115 TahoeCongAvoid::getRetransmissionTimeout() 00116 { 00117 MESSAGE_SINGLE(NORMAL, logger, "Retransmission timeout: " << timeout); 00118 return this->timeout; 00119 } 00120 00121 void 00122 TahoeCongAvoid::onSegmentAcknowledged() 00123 { 00124 countDuplicateACKs.clear(); 00125 00126 if (cwnd_cnt >= cwnd) 00127 { 00128 cwnd++; 00129 cwnd_cnt = 0; 00130 } 00131 else 00132 { 00133 cwnd_cnt++; 00134 } 00135 MESSAGE_SINGLE(NORMAL, logger, "Segment acknowledged. Window size: " << cwnd); 00136 } 00137 00138 void 00139 TahoeCongAvoid::setWindowSize(unsigned long int new_cwnd) 00140 { 00141 MESSAGE_SINGLE(NORMAL, logger, "Setting window size: " << new_cwnd << "(old value: " << cwnd << ")"); 00142 cwnd = new_cwnd; 00143 } 00144 00145 00146 std::string 00147 TahoeCongAvoid::printReason(segmentLoss reason) 00148 { 00149 switch(reason) 00150 { 00151 case TIMEOUT: 00152 return "TIMEOUT"; 00153 break; 00154 case DUPLICATE_ACK: 00155 return "DUPLICATE_ACK"; 00156 break; 00157 default: 00158 assure(false, "Unknown segment loss!"); 00159 return ""; 00160 break; 00161 } 00162 } 00163 00164 00165 bool 00166 TahoeCongAvoid::duplicateACKThresholdReached(unsigned long int _ackNR) 00167 { 00168 if(countDuplicateACKs.knows(_ackNR)) 00169 return countDuplicateACKs.find(_ackNR) == ndup; 00170 else 00171 return false; 00172 } 00173 00174 00175 void 00176 TahoeCongAvoid::clearDuplicateACKCounter() 00177 { 00178 countDuplicateACKs.clear(); 00179 }
1.5.5