xref: /csrg-svn/sys/netinet/tcp_timer.h (revision 5165)
1*5165Swnj /*	tcp_timer.h	4.2	81/12/02	*/
25125Swnj 
35125Swnj /*
45125Swnj  * Definitions of the TCP timers.  These timers are counted
55125Swnj  * down PR_SLOWHZ times a second.
65125Swnj  */
75125Swnj #define	TCPT_NTIMERS	4
85125Swnj 
95125Swnj #define	TCPT_REXMT	0		/* retransmit */
10*5165Swnj #define	TCPT_PERSIST	1		/* retransmit persistance */
11*5165Swnj #define	TCPT_KEEP	2		/* keep alive */
12*5165Swnj #define	TCPT_2MSL	3		/* 2*msl quiet time timer */
135125Swnj 
14*5165Swnj /*
15*5165Swnj  * The TCPT_REXMT timer is used to force retransmissions.
16*5165Swnj  * The TCP has the TCPT_REXMT timer set whenever segments
17*5165Swnj  * have been sent for which ACKs are expected but not yet
18*5165Swnj  * received.  If an ACK is received which advances tp->snd_una,
19*5165Swnj  * then the retransmit timer is cleared (if there are no more
20*5165Swnj  * outstanding segments) or reset to the base value (if there
21*5165Swnj  * are more ACKs expected).  Whenever the retransmit timer goes off,
22*5165Swnj  * we retransmit all unacknowledged segments, and do an exponential
23*5165Swnj  * backoff on the retransmit timer.
24*5165Swnj  *
25*5165Swnj  * The TCPT_PERSIST timer is used to keep window size information
26*5165Swnj  * flowing even if the window goes shut.  If an output is attempted when there
27*5165Swnj  * is data ready to transmit, but nothing gets sent because the window
28*5165Swnj  * is shut, then we start the TCPT_PERSIST timer, and at intervals
29*5165Swnj  * send a single byte into the peers window to force him to update
30*5165Swnj  * our window information.  We do this at most as often as TCPT_PERSMIN
31*5165Swnj  * time intervals, but no more frequently than the current estimate of
32*5165Swnj  * round-trip packet time.  The TCPT_PERSIST timer is cleared whenever
33*5165Swnj  * we receive a window update from the peer.
34*5165Swnj  *
35*5165Swnj  * The TCPT_KEEP timer is used to keep connections alive.  If an
36*5165Swnj  * connection is idle (no segments received) for TCPTV_KEEP amount of time,
37*5165Swnj  * but not yet established, then we drop the connection.  If the connection
38*5165Swnj  * is established, then we force the peer to send us a segment by sending:
39*5165Swnj  *	<SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
40*5165Swnj  * This segment is (deliberately) outside the window, and should elicit
41*5165Swnj  * an ack segment in response from the peer.  If, despite the TCPT_KEEP
42*5165Swnj  * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE
43*5165Swnj  * amount of time, then we drop the connection.
44*5165Swnj  */
45*5165Swnj 
465125Swnj #define	TCP_TTL		60		/* time to live for TCP segs */
475125Swnj /*
48*5165Swnj  * Time constants.
495125Swnj  */
50*5165Swnj #define	TCPTV_MSL	(120*PR_SLOWHZ)		/* max seg lifetime */
51*5165Swnj #define	TCPTV_SRTTBASE	(  1*PR_SLOWHZ)		/* base roundtrip time */
52*5165Swnj #define	TCPTV_KEEP	(240*PR_SLOWHZ)		/* keep alive - 4 mins */
53*5165Swnj #define	TCPTV_PERSMIN	(  5*PR_SLOWHZ)		/* retransmit persistance */
545125Swnj 
55*5165Swnj #define	TCPTV_MAXIDLE	(  4*TCPTV_KEEP)	/* maximum allowable idle
56*5165Swnj 						   time before drop conn */
575125Swnj 
58*5165Swnj #define	TCPTV_MIN	(  1*PR_SLOWHZ)		/* minimum allowable value */
59*5165Swnj #define	TCPTV_MAX	(480*PR_SLOWHZ)		/* maximum allowable value */
605125Swnj 
615125Swnj #ifdef	TCPTIMERS
625125Swnj char *tcptimers[] =
63*5165Swnj     { "REXMT", "KEEP", "PERSIST", "2MSL" };
645125Swnj #endif
65*5165Swnj 
66*5165Swnj /*
67*5165Swnj  * Retransmission smoothing constants.
68*5165Swnj  * Smoothed round trip time is updated by
69*5165Swnj  *    tp->t_srtt = (tcp_alpha * tp->t_srtt) + ((1 - tcp_alpha) * tp->t_rtt)
70*5165Swnj  * each time a new value of tp->t_rtt is available.  The initial
71*5165Swnj  * retransmit timeout is then based on
72*5165Swnj  *    tp->t_timer[TCPT_REXMT] = tcp_beta * tp->t_srtt;
73*5165Swnj  * limited, however to be at least TCPTV_REXMTLO and at most TCPTV_REXMTHI.
74*5165Swnj  */
75*5165Swnj float	tcp_alpha, tcp_beta;
76*5165Swnj 
77*5165Swnj /*
78*5165Swnj  * Initial values of tcp_alpha and tcp_beta.
79*5165Swnj  * These are conservative: averaging over a long
80*5165Swnj  * period of time, and allowing for large individual deviations from
81*5165Swnj  * tp->t_srtt.
82*5165Swnj  */
83*5165Swnj #define	TCP_ALPHA	0.9
84*5165Swnj #define	TCP_BETA	2.0
85*5165Swnj 
86*5165Swnj /*
87*5165Swnj  * Force a time value to be in a certain range.
88*5165Swnj  */
89*5165Swnj #define	TCPT_RANGESET(tv, value, tvmin, tvmax) \
90*5165Swnj 	(tv) = (value); \
91*5165Swnj 	if ((tv) < (tvmin)) \
92*5165Swnj 		(tv) = (tvmin); \
93*5165Swnj 	if ((tv) > (tvmax)) \
94*5165Swnj 		(tv) = (tvmax);
95