123195Smckusick /* 223195Smckusick * Copyright (c) 1982 Regents of the University of California. 323195Smckusick * All rights reserved. The Berkeley software License Agreement 423195Smckusick * specifies the terms and conditions for redistribution. 523195Smckusick * 6*24820Skarels * @(#)tcp_timer.h 6.4 (Berkeley) 09/16/85 723195Smckusick */ 85125Swnj 95125Swnj /* 105125Swnj * Definitions of the TCP timers. These timers are counted 115125Swnj * down PR_SLOWHZ times a second. 125125Swnj */ 139860Ssam #define TCPT_NTIMERS 4 145125Swnj 155125Swnj #define TCPT_REXMT 0 /* retransmit */ 165165Swnj #define TCPT_PERSIST 1 /* retransmit persistance */ 175165Swnj #define TCPT_KEEP 2 /* keep alive */ 185165Swnj #define TCPT_2MSL 3 /* 2*msl quiet time timer */ 195125Swnj 205165Swnj /* 215165Swnj * The TCPT_REXMT timer is used to force retransmissions. 225165Swnj * The TCP has the TCPT_REXMT timer set whenever segments 235165Swnj * have been sent for which ACKs are expected but not yet 245165Swnj * received. If an ACK is received which advances tp->snd_una, 255165Swnj * then the retransmit timer is cleared (if there are no more 265165Swnj * outstanding segments) or reset to the base value (if there 275165Swnj * are more ACKs expected). Whenever the retransmit timer goes off, 28*24820Skarels * we retransmit one unacknowledged segment, and do a backoff 29*24820Skarels * on the retransmit timer. 305165Swnj * 315165Swnj * The TCPT_PERSIST timer is used to keep window size information 327041Swnj * flowing even if the window goes shut. If all previous transmissions 337041Swnj * have been acknowledged (so that there are no retransmissions in progress), 34*24820Skarels * and the window is too small to bother sending anything, then we start 35*24820Skarels * the TCPT_PERSIST timer. When it expires, if the window is nonzero, 36*24820Skarels * we go to transmit state. Otherwise, at intervals send a single byte 37*24820Skarels * into the peer's window to force him to update our window information. 38*24820Skarels * We do this at most as often as TCPT_PERSMIN time intervals, 39*24820Skarels * but no more frequently than the current estimate of round-trip 40*24820Skarels * packet time. The TCPT_PERSIST timer is cleared whenever we receive 41*24820Skarels * a window update from the peer. 425165Swnj * 435165Swnj * The TCPT_KEEP timer is used to keep connections alive. If an 445165Swnj * connection is idle (no segments received) for TCPTV_KEEP amount of time, 455165Swnj * but not yet established, then we drop the connection. If the connection 465165Swnj * is established, then we force the peer to send us a segment by sending: 475165Swnj * <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK> 485165Swnj * This segment is (deliberately) outside the window, and should elicit 495165Swnj * an ack segment in response from the peer. If, despite the TCPT_KEEP 505165Swnj * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE 515165Swnj * amount of time, then we drop the connection. 525165Swnj */ 535165Swnj 545245Sroot #define TCP_TTL 15 /* time to live for TCP segs */ 555125Swnj /* 565165Swnj * Time constants. 575125Swnj */ 58*24820Skarels #define TCPTV_MSL ( 15*PR_SLOWHZ) /* max seg lifetime */ 5918647Skarels #define TCPTV_SRTTBASE 0 /* base roundtrip time; 6018647Skarels if 0, no idea yet */ 617041Swnj #define TCPTV_KEEP ( 45*PR_SLOWHZ) /* keep alive - 45 secs */ 625165Swnj #define TCPTV_PERSMIN ( 5*PR_SLOWHZ) /* retransmit persistance */ 635125Swnj 647041Swnj #define TCPTV_MAXIDLE ( 8*TCPTV_KEEP) /* maximum allowable idle 655165Swnj time before drop conn */ 665125Swnj 675165Swnj #define TCPTV_MIN ( 1*PR_SLOWHZ) /* minimum allowable value */ 685392Swnj #define TCPTV_MAX ( 30*PR_SLOWHZ) /* maximum allowable value */ 695125Swnj 705392Swnj #define TCP_LINGERTIME 120 /* linger at most 2 minutes */ 715392Swnj 72*24820Skarels #define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ 735691Swnj 745125Swnj #ifdef TCPTIMERS 755125Swnj char *tcptimers[] = 769860Ssam { "REXMT", "PERSIST", "KEEP", "2MSL" }; 775125Swnj #endif 785165Swnj 795165Swnj /* 805165Swnj * Retransmission smoothing constants. 815165Swnj * Smoothed round trip time is updated by 825165Swnj * tp->t_srtt = (tcp_alpha * tp->t_srtt) + ((1 - tcp_alpha) * tp->t_rtt) 835165Swnj * each time a new value of tp->t_rtt is available. The initial 845165Swnj * retransmit timeout is then based on 855165Swnj * tp->t_timer[TCPT_REXMT] = tcp_beta * tp->t_srtt; 865165Swnj * limited, however to be at least TCPTV_REXMTLO and at most TCPTV_REXMTHI. 875165Swnj */ 885165Swnj float tcp_alpha, tcp_beta; 895165Swnj 905165Swnj /* 915165Swnj * Initial values of tcp_alpha and tcp_beta. 925165Swnj * These are conservative: averaging over a long 935165Swnj * period of time, and allowing for large individual deviations from 945165Swnj * tp->t_srtt. 955165Swnj */ 965165Swnj #define TCP_ALPHA 0.9 975165Swnj #define TCP_BETA 2.0 985165Swnj 995165Swnj /* 1005165Swnj * Force a time value to be in a certain range. 1015165Swnj */ 1025245Sroot #define TCPT_RANGESET(tv, value, tvmin, tvmax) { \ 1035165Swnj (tv) = (value); \ 1045165Swnj if ((tv) < (tvmin)) \ 1055165Swnj (tv) = (tvmin); \ 1065165Swnj if ((tv) > (tvmax)) \ 1075245Sroot (tv) = (tvmax); \ 1085245Sroot } 109