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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
|
/* -*- 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[] =
"@(#) /home/ctk21/cvsroot//hssstcp/ns/ns-2.1b9/tcp/tcp-fack.cc,v 1.2 2002/08/12 10:43:58 ctk21 Exp (PSC)";
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "ip.h"
#include "tcp.h"
#include "flags.h"
#include "scoreboard.h"
#include "random.h"
#include "tcp-fack.h"
#include "template.h"
static class FackTcpClass : public TclClass {
public:
FackTcpClass() : TclClass("Agent/TCP/Fack") {}
TclObject* create(int, const char*const*) {
return (new FackTcpAgent());
}
} class_fack;
FackTcpAgent::FackTcpAgent() : timeout_(FALSE), wintrim_(0),
wintrimmult_(.5), rampdown_(0), fack_(-1), retran_data_(0),
ss_div4_(0) // What about fastrecov_ and scb_
{
bind_bool("ss-div4_", &ss_div4_);
bind_bool("rampdown_", &rampdown_);
scb_ = new ScoreBoard(new ScoreBoardNode[SBSIZE],SBSIZE);
}
FackTcpAgent::~FackTcpAgent(){
delete [] scb_;
}
int FackTcpAgent::window()
{
int win;
win = int((cwnd_ < wnd_ ? (double) cwnd_ : (double) wnd_) + wintrim_);
return (win);
}
void FackTcpAgent::reset ()
{
scb_->ClearScoreBoard();
TcpAgent::reset ();
}
/*
* Process a dupack.
*/
void FackTcpAgent::oldack(Packet* pkt)
{
hdr_tcp *tcph = hdr_tcp::access(pkt);
last_ack_ = tcph->seqno();
highest_ack_ = last_ack_;
fack_ = max(fack_,highest_ack_);
/*
* There are conditions under which certain versions of TCP (e.g., tcp-fs)
* retract maxseq_. The following line of code helps in those cases. For
* versions of TCP, it is a NOP.
*/
maxseq_ = max(int(maxseq_), int(highest_ack_));
if (t_seqno_ < last_ack_ + 1)
t_seqno_ = last_ack_ + 1;
newtimer(pkt);
if (rtt_active_ && tcph->seqno() >= rtt_seq_) {
rtt_active_ = 0;
t_backoff_ = 1;
}
/* with timestamp option */
double tao = Scheduler::instance().clock() - tcph->ts_echo();
rtt_update(tao);
if (ts_resetRTO_) {
// From Andrei Gurtov
// FACK has not been updated to make sure the ECN works
// correctly in this case - Sally.
t_backoff_ = 1;
}
/* update average window */
awnd_ *= 1.0 - wnd_th_;
awnd_ += wnd_th_ * cwnd_;
/* if the connection is done, call finish() */
if ((highest_ack_ >= curseq_-1) && !closed_) {
closed_ = 1;
finish();
}
}
int FackTcpAgent::maxsack(Packet *pkt)
{
hdr_tcp *tcph = hdr_tcp::access(pkt);
int maxsack=-1, sack_index;
for (sack_index=0; sack_index < tcph->sa_length(); sack_index++) {
if (tcph->sa_right(sack_index) > maxsack)
maxsack = tcph->sa_right(sack_index);
}
return (maxsack-1);
}
void FackTcpAgent::recv_newack_helper(Packet *pkt) {
newack(pkt);
opencwnd();
/* if the connection is done, call finish() */
if ((highest_ack_ >= curseq_-1) && !closed_) {
closed_ = 1;
finish();
}
}
void FackTcpAgent::recv(Packet *pkt, Handler*)
{
hdr_tcp *tcph = hdr_tcp::access(pkt);
int ms;
#ifdef notdef
if (pkt->type_ != PT_ACK) {
Tcl::instance().evalf("%s error \"received non-ack\"",
name());
Packet::free(pkt);
return;
}
#endif
ts_peer_ = tcph->ts();
if (hdr_flags::access(pkt)->ecnecho() && ecn_)
ecn(tcph->seqno());
recv_helper(pkt);
if (!fastrecov_) { // Not in fast recovery
if ((int)tcph->seqno() > last_ack_ && tcph->sa_length() == 0) {
/*
* regular ACK not in fast recovery... normal
*/
recv_newack_helper(pkt);
fack_ = last_ack_;
timeout_ = FALSE;
scb_->ClearScoreBoard();
retran_data_ = 0;
wintrim_ = 0;
} else if ((int)tcph->seqno() < last_ack_) {
// Do nothing; ack may have been misordered
} else {
retran_data_ -= scb_->UpdateScoreBoard (highest_ack_, tcph);
oldack(pkt);
ms = maxsack(pkt);
if (ms > fack_)
fack_ = ms;
if (fack_ >= t_seqno_)
t_seqno_ = fack_ + 1;
dupacks_ = (fack_ - last_ack_) - 1;
/*
* a duplicate ACK
*/
if (dupacks_ >= numdupacks_) {
/*
* Assume we dropped just one packet.
* Retransmit last ack + 1
* and try to resume the sequence.
*/
recover_ = t_seqno_;
last_cwnd_action_ = CWND_ACTION_DUPACK;
if ((ss_div4_ == 1) && (cwnd_ <= ssthresh_ + .5)) {
cwnd_ /= 2;
wintrimmult_ = .75;
} else {
wintrimmult_ = .5;
}
slowdown(CLOSE_SSTHRESH_HALF|CLOSE_CWND_RESTART);
if (rampdown_) {
wintrim_ = (t_seqno_ - fack_ - 1) * wintrimmult_;
}
reset_rtx_timer(1,0);
fastrecov_ = TRUE;
scb_->MarkRetran (last_ack_+1, t_seqno_);
retran_data_++;
output(last_ack_ + 1, TCP_REASON_DUPACK);
}
}
if (dupacks_ == 0)
send_much(FALSE, 0, maxburst_);
} else {
// we are in fast recovery
oldack(pkt);
ms = maxsack(pkt);
if (ms > fack_) {
if (rampdown_) {
wintrim_ -= ((float)ms - (float)fack_)* wintrimmult_;
if (wintrim_< 0)
wintrim_ = 0;
}
fack_ = ms;
}
if (fack_ >= t_seqno_)
t_seqno_ = fack_ + 1;
retran_data_ -= scb_->UpdateScoreBoard (highest_ack_, tcph);
// If the retransmission was lost again, timeout_ forced to TRUE
// if timeout_ TRUE, this shuts off send()
timeout_ |= scb_->CheckSndNxt (tcph);
opencwnd();
if (retran_data_ < 0) {
printf("Error, retran_data_ < 0");
}
if ((int)tcph->sa_length() == 0 && (last_ack_ >= recover_)) {
// No SACK blocks indicates fast recovery is over
fastrecov_ = FALSE;
timeout_ = FALSE;
scb_->ClearScoreBoard();
retran_data_ = 0;
wintrim_ = 0;
dupacks_ = 0;
}
send_much(FALSE, 0, maxburst_);
}
Packet::free(pkt);
#ifdef notyet
if (trace_)
plot();
#endif
}
void FackTcpAgent::timeout(int tno)
{
if (tno == TCP_TIMER_RTX) {
if (highest_ack_ == maxseq_ && !slow_start_restart_) {
/*
* TCP option:
* If no outstanding data, then don't do anything.
*/
return;
};
// Do not clear fastrecov_ or alter recover_ variable
timeout_ = FALSE;
if (highest_ack_ > last_ack_)
last_ack_ = highest_ack_;
#ifdef DEBUGSACK1A
printf ("timeout. highest_ack: %d seqno: %d\n",
highest_ack_, t_seqno_);
#endif
retran_data_ = 0;
last_cwnd_action_ = CWND_ACTION_TIMEOUT;
/* if there is no outstanding data, don't cut down ssthresh_ */
if (highest_ack_ == maxseq_ && restart_bugfix_)
slowdown(CLOSE_CWND_INIT);
else {
// close down to 1 segment
slowdown(CLOSE_SSTHRESH_HALF|CLOSE_CWND_RESTART);
}
scb_->ClearScoreBoard();
/* if there is no outstanding data, don't back off rtx timer */
if (highest_ack_ == maxseq_)
reset_rtx_timer(TCP_REASON_TIMEOUT,0);
else
reset_rtx_timer(TCP_REASON_TIMEOUT,1);
fack_ = last_ack_;
t_seqno_ = last_ack_ + 1;
send_much(0, TCP_REASON_TIMEOUT);
} else {
TcpAgent::timeout(tno);
}
}
void FackTcpAgent::send_much(int force, int reason, int maxburst)
{
register int found, npacket = 0;
send_idle_helper();
int win = window();
int xmit_seqno;
if (!force && delsnd_timer_.status() == TIMER_PENDING)
return;
/*
* If TCP_TIMER_BURSTSND is pending, cancel it. The timer is
* set again, if necessary, after the maxburst pakts have been
* sent out.
*/
if (burstsnd_timer_.status() == TIMER_PENDING)
burstsnd_timer_.cancel();
found = 1;
/*
* as long as the pipe is open and there is app data to send...
*/
while (( t_seqno_ <= fack_ + win - retran_data_) && (!timeout_)) {
if (overhead_ == 0 || force) {
found = 0;
xmit_seqno = scb_->GetNextRetran ();
#ifdef DEBUGSACK1A
printf("highest_ack: %d xmit_seqno: %d timeout: %d seqno: %d fack: % d win: %d retran_data: %d\n",
highest_ack_, xmit_seqno, timeout_, t_seqno_, fack_, win, retran_data_);
#endif
if (xmit_seqno == -1) { // no retransmissions to send
/*
* if there is no more application data to send,
* do nothing
*/
if (t_seqno_ >= curseq_)
return;
/* if window-limited */
if (fastrecov_ &&
t_seqno_>highest_ack_+int(wnd_))
break;
found = 1;
xmit_seqno = t_seqno_++;
#ifdef DEBUGSACK1A
printf("sending %d fastrecovery: %d win %d\n",
xmit_seqno, fastrecov_, win);
#endif
} else {
found = 1;
scb_->MarkRetran (xmit_seqno, t_seqno_);
retran_data_++;
win = window();
}
if (found) {
output(xmit_seqno, reason);
if (t_seqno_ <= xmit_seqno) {
printf("Hit a strange case 2.\n");
t_seqno_ = xmit_seqno + 1;
}
npacket++;
}
} else if (!(delsnd_timer_.status() == TIMER_PENDING)) {
/*
* Set a delayed send timeout.
*/
delsnd_timer_.resched(Random::uniform(overhead_));
return;
}
if (maxburst && npacket == maxburst)
break;
} /* while */
/* call helper function */
send_helper(maxburst);
}
/*
* open up the congestion window -- Hack hack hack
*/
void FackTcpAgent::opencwnd()
{
TcpAgent::opencwnd();
// if maxcwnd_ is set (nonzero), make it the cwnd limit
if (maxcwnd_ && (int (cwnd_) > maxcwnd_))
cwnd_ = maxcwnd_;
}
void FackTcpAgent::plot()
{
#ifdef notyet
double t = Scheduler::instance().clock();
sprintf(trace_->buffer(), "t %g %d rtt %g\n",
t, class_, t_rtt_ * tcp_tick_);
trace_->dump();
sprintf(trace_->buffer(), "t %g %d dev %g\n",
t, class_, t_rttvar_ * tcp_tick_);
trace_->dump();
sprintf(trace_->buffer(), "t %g %d win %f\n", t, class_, cwnd_);
trace_->dump();
sprintf(trace_->buffer(), "t %g %d bck %d\n", t, class_, t_backoff_);
trace_->dump();
#endif
}
|