1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
/*
* Copyright (c) 1990, 1997 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Lawrence Berkeley Laboratory,
* Berkeley, CA. The name of the University may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /cvsroot/nsnam/ns-2/tcp/tcp-reno.cc,v 1.43 2006/06/14 18:05:30 sallyfloyd Exp $ (LBL)";
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "ip.h"
#include "tcp.h"
#include "flags.h"
static class RenoTcpClass : public TclClass {
public:
RenoTcpClass() : TclClass("Agent/TCP/Reno") {}
TclObject* create(int, const char*const*) {
return (new RenoTcpAgent());
}
} class_reno;
int RenoTcpAgent::window()
{
//
// reno: inflate the window by dupwnd_
// dupwnd_ will be non-zero during fast recovery,
// at which time it contains the number of dup acks
//
int win = int(cwnd_) + dupwnd_;
if (frto_ == 2) {
// First ack after RTO has arrived.
// Open window to allow two new segments out with F-RTO.
win = force_wnd(2);
}
if (win > int(wnd_))
win = int(wnd_);
return (win);
}
double RenoTcpAgent::windowd()
{
//
// reno: inflate the window by dupwnd_
// dupwnd_ will be non-zero during fast recovery,
// at which time it contains the number of dup acks
//
double win = cwnd_ + dupwnd_;
if (win > wnd_)
win = wnd_;
return (win);
}
RenoTcpAgent::RenoTcpAgent() : TcpAgent(), dupwnd_(0)
{
}
void RenoTcpAgent::recv(Packet *pkt, Handler*)
{
hdr_tcp *tcph = hdr_tcp::access(pkt);
int valid_ack = 0;
if (qs_approved_ == 1 && tcph->seqno() > last_ack_)
endQuickStart();
if (qs_requested_ == 1)
processQuickStart(pkt);
#ifdef notdef
if (pkt->type_ != PT_ACK) {
fprintf(stderr,
"ns: confiuration error: tcp received non-ack\n");
exit(1);
}
#endif
/* W.N.: check if this is from a previous incarnation */
if (tcph->ts() < lastreset_) {
// Remove packet and do nothing
Packet::free(pkt);
return;
}
++nackpack_;
ts_peer_ = tcph->ts();
if (hdr_flags::access(pkt)->ecnecho() && ecn_)
ecn(tcph->seqno());
recv_helper(pkt);
recv_frto_helper(pkt);
if (tcph->seqno() > last_ack_) {
if (last_cwnd_action_ == CWND_ACTION_DUPACK)
last_cwnd_action_ = CWND_ACTION_EXITED;
dupwnd_ = 0;
recv_newack_helper(pkt);
if (last_ack_ == 0 && delay_growth_) {
cwnd_ = initial_window();
}
} else if (tcph->seqno() == last_ack_) {
if (hdr_flags::access(pkt)->eln_ && eln_) {
tcp_eln(pkt);
return;
}
if (++dupacks_ == numdupacks_) {
dupack_action();
if (!exitFastRetrans_)
dupwnd_ = numdupacks_;
} else if (dupacks_ > numdupacks_ && (!exitFastRetrans_
|| last_cwnd_action_ == CWND_ACTION_DUPACK )) {
++dupwnd_; // fast recovery
} else if (dupacks_ < numdupacks_ && singledup_ ) {
send_one();
}
}
if (tcph->seqno() >= last_ack_)
// Check if ACK is valid. Suggestion by Mark Allman.
valid_ack = 1;
Packet::free(pkt);
#ifdef notyet
if (trace_)
plot();
#endif
/*
* Try to send more data
*/
if (valid_ack || aggressive_maxburst_)
if (dupacks_ == 0 || dupacks_ > numdupacks_ - 1)
send_much(0, 0, maxburst_);
}
int
RenoTcpAgent::allow_fast_retransmit(int last_cwnd_action_)
{
return (last_cwnd_action_ == CWND_ACTION_DUPACK);
}
/*
* Dupack-action: what to do on a DUP ACK. After the initial check
* of 'recover' below, this function implements the following truth
* table:
*
* bugfix ecn last-cwnd == ecn action
*
* 0 0 0 reno_action
* 0 0 1 reno_action [impossible]
* 0 1 0 reno_action
* 0 1 1 retransmit, return
* 1 0 0 nothing
* 1 0 1 nothing [impossible]
* 1 1 0 nothing
* 1 1 1 retransmit, return
*/
void
RenoTcpAgent::dupack_action()
{
int recovered = (highest_ack_ > recover_);
int allowFastRetransmit = allow_fast_retransmit(last_cwnd_action_);
if (recovered || (!bug_fix_ && !ecn_) || allowFastRetransmit
|| (bugfix_ss_ && highest_ack_ == 0)) {
// (highest_ack_ == 0) added to allow Fast Retransmit
// when the first data packet is dropped.
// From bugreport from Mark Allman.
goto reno_action;
}
if (ecn_ && last_cwnd_action_ == CWND_ACTION_ECN) {
last_cwnd_action_ = CWND_ACTION_DUPACK;
/*
* What if there is a DUPACK action followed closely by ECN
* followed closely by a DUPACK action?
* The optimal thing to do would be to remember all
* congestion actions from the most recent window
* of data. Otherwise "bugfix" might not prevent
* all unnecessary Fast Retransmits.
*/
reset_rtx_timer(1,0);
output(last_ack_ + 1, TCP_REASON_DUPACK);
dupwnd_ = numdupacks_;
return;
}
if (bug_fix_) {
/*
* The line below, for "bug_fix_" true, avoids
* problems with multiple fast retransmits in one
* window of data.
*/
return;
}
reno_action:
// we are now going to fast-retransmit and will trace that event
trace_event("RENO_FAST_RETX");
recover_ = maxseq_;
last_cwnd_action_ = CWND_ACTION_DUPACK;
slowdown(CLOSE_SSTHRESH_HALF|CLOSE_CWND_HALF);
reset_rtx_timer(1,0);
output(last_ack_ + 1, TCP_REASON_DUPACK); // from top
dupwnd_ = numdupacks_;
return;
}
void RenoTcpAgent::timeout(int tno)
{
if (tno == TCP_TIMER_RTX) {
dupwnd_ = 0;
dupacks_ = 0;
if (bug_fix_) recover_ = maxseq_;
TcpAgent::timeout(tno);
} else {
timeout_nonrtx(tno);
}
}
|