xref: /csrg-svn/sys/netinet/tcp_timer.h (revision 5245)
1*5245Sroot /*	tcp_timer.h	4.3	81/12/12	*/
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 */
105165Swnj #define	TCPT_PERSIST	1		/* retransmit persistance */
115165Swnj #define	TCPT_KEEP	2		/* keep alive */
125165Swnj #define	TCPT_2MSL	3		/* 2*msl quiet time timer */
135125Swnj 
145165Swnj /*
155165Swnj  * The TCPT_REXMT timer is used to force retransmissions.
165165Swnj  * The TCP has the TCPT_REXMT timer set whenever segments
175165Swnj  * have been sent for which ACKs are expected but not yet
185165Swnj  * received.  If an ACK is received which advances tp->snd_una,
195165Swnj  * then the retransmit timer is cleared (if there are no more
205165Swnj  * outstanding segments) or reset to the base value (if there
215165Swnj  * are more ACKs expected).  Whenever the retransmit timer goes off,
225165Swnj  * we retransmit all unacknowledged segments, and do an exponential
235165Swnj  * backoff on the retransmit timer.
245165Swnj  *
255165Swnj  * The TCPT_PERSIST timer is used to keep window size information
265165Swnj  * flowing even if the window goes shut.  If an output is attempted when there
275165Swnj  * is data ready to transmit, but nothing gets sent because the window
285165Swnj  * is shut, then we start the TCPT_PERSIST timer, and at intervals
295165Swnj  * send a single byte into the peers window to force him to update
305165Swnj  * our window information.  We do this at most as often as TCPT_PERSMIN
315165Swnj  * time intervals, but no more frequently than the current estimate of
325165Swnj  * round-trip packet time.  The TCPT_PERSIST timer is cleared whenever
335165Swnj  * we receive a window update from the peer.
345165Swnj  *
355165Swnj  * The TCPT_KEEP timer is used to keep connections alive.  If an
365165Swnj  * connection is idle (no segments received) for TCPTV_KEEP amount of time,
375165Swnj  * but not yet established, then we drop the connection.  If the connection
385165Swnj  * is established, then we force the peer to send us a segment by sending:
395165Swnj  *	<SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
405165Swnj  * This segment is (deliberately) outside the window, and should elicit
415165Swnj  * an ack segment in response from the peer.  If, despite the TCPT_KEEP
425165Swnj  * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE
435165Swnj  * amount of time, then we drop the connection.
445165Swnj  */
455165Swnj 
46*5245Sroot #define	TCP_TTL		15		/* time to live for TCP segs */
475125Swnj /*
485165Swnj  * Time constants.
495125Swnj  */
50*5245Sroot #define	TCPTV_MSL	( 30*PR_SLOWHZ)		/* max seg lifetime */
515165Swnj #define	TCPTV_SRTTBASE	(  1*PR_SLOWHZ)		/* base roundtrip time */
52*5245Sroot #define	TCPTV_KEEP	( 60*PR_SLOWHZ)		/* keep alive - 1 min */
535165Swnj #define	TCPTV_PERSMIN	(  5*PR_SLOWHZ)		/* retransmit persistance */
545125Swnj 
555165Swnj #define	TCPTV_MAXIDLE	(  4*TCPTV_KEEP)	/* maximum allowable idle
565165Swnj 						   time before drop conn */
575125Swnj 
585165Swnj #define	TCPTV_MIN	(  1*PR_SLOWHZ)		/* minimum allowable value */
59*5245Sroot #define	TCPTV_MAX	(120*PR_SLOWHZ)		/* maximum allowable value */
605125Swnj 
615125Swnj #ifdef	TCPTIMERS
625125Swnj char *tcptimers[] =
635165Swnj     { "REXMT", "KEEP", "PERSIST", "2MSL" };
645125Swnj #endif
655165Swnj 
665165Swnj /*
675165Swnj  * Retransmission smoothing constants.
685165Swnj  * Smoothed round trip time is updated by
695165Swnj  *    tp->t_srtt = (tcp_alpha * tp->t_srtt) + ((1 - tcp_alpha) * tp->t_rtt)
705165Swnj  * each time a new value of tp->t_rtt is available.  The initial
715165Swnj  * retransmit timeout is then based on
725165Swnj  *    tp->t_timer[TCPT_REXMT] = tcp_beta * tp->t_srtt;
735165Swnj  * limited, however to be at least TCPTV_REXMTLO and at most TCPTV_REXMTHI.
745165Swnj  */
755165Swnj float	tcp_alpha, tcp_beta;
765165Swnj 
775165Swnj /*
785165Swnj  * Initial values of tcp_alpha and tcp_beta.
795165Swnj  * These are conservative: averaging over a long
805165Swnj  * period of time, and allowing for large individual deviations from
815165Swnj  * tp->t_srtt.
825165Swnj  */
835165Swnj #define	TCP_ALPHA	0.9
845165Swnj #define	TCP_BETA	2.0
855165Swnj 
865165Swnj /*
875165Swnj  * Force a time value to be in a certain range.
885165Swnj  */
89*5245Sroot #define	TCPT_RANGESET(tv, value, tvmin, tvmax) { \
905165Swnj 	(tv) = (value); \
915165Swnj 	if ((tv) < (tvmin)) \
925165Swnj 		(tv) = (tvmin); \
935165Swnj 	if ((tv) > (tvmax)) \
94*5245Sroot 		(tv) = (tvmax); \
95*5245Sroot }
96