xref: /original-bsd/sys/netiso/tp_seq.h (revision fdf395da)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)tp_seq.h	8.1 (Berkeley) 06/10/93
8  */
9 
10 /***********************************************************
11 		Copyright IBM Corporation 1987
12 
13                       All Rights Reserved
14 
15 Permission to use, copy, modify, and distribute this software and its
16 documentation for any purpose and without fee is hereby granted,
17 provided that the above copyright notice appear in all copies and that
18 both that copyright notice and this permission notice appear in
19 supporting documentation, and that the name of IBM not be
20 used in advertising or publicity pertaining to distribution of the
21 software without specific, written prior permission.
22 
23 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29 SOFTWARE.
30 
31 ******************************************************************/
32 
33 /*
34  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
35  */
36 /*
37  * ARGO TP
38  *
39  * $Header: tp_seq.h,v 5.1 88/10/12 12:20:59 root Exp $
40  * $Source: /usr/argo/sys/netiso/RCS/tp_seq.h,v $
41  *
42  * These macros perform sequence number arithmetic modulo (2**7 or 2**31).
43  * The relevant fields in the tpcb are:
44  *  	tp_seqmask : the mask of bits that define the sequence space.
45  *  	tp_seqbit  : 1 + tp_seqmask
46  *  	tp_seqhalf : tp_seqbit / 2 or half the sequence space (rounded up)
47  * Not exactly fast, but at least it's maintainable.
48  */
49 
50 #ifndef __TP_SEQ__
51 #define __TP_SEQ__
52 
53 #define SEQ(tpcb,x) \
54 	((x) & (tpcb)->tp_seqmask)
55 
56 #define SEQ_GT(tpcb, seq, operand ) \
57 ( ((int)((seq)-(operand)) > 0)\
58 ? ((int)((seq)-(operand)) < (int)(tpcb)->tp_seqhalf)\
59 : !(-((int)(seq)-(operand)) < (int)(tpcb)->tp_seqhalf))
60 
61 #define SEQ_GEQ(tpcb, seq, operand ) \
62 ( ((int)((seq)-(operand)) >= 0)\
63 ? ((int)((seq)-(operand)) < (int)(tpcb)->tp_seqhalf)\
64 : !((-((int)(seq)-(operand))) < (int)(tpcb)->tp_seqhalf))
65 
66 #define SEQ_LEQ(tpcb, seq, operand ) \
67 ( ((int)((seq)-(operand)) <= 0)\
68 ? ((-(int)((seq)-(operand))) < (int)(tpcb)->tp_seqhalf)\
69 : !(((int)(seq)-(operand)) < (int)(tpcb)->tp_seqhalf))
70 
71 #define SEQ_LT(tpcb, seq, operand ) \
72 ( ((int)((seq)-(operand)) < 0)\
73 ? ((-(int)((seq)-(operand))) < (int)(tpcb)->tp_seqhalf)\
74 : !(((int)(seq)-(operand)) < (int)(tpcb)->tp_seqhalf))
75 
76 #define SEQ_MIN(tpcb, a, b) ( SEQ_GT(tpcb, a, b) ? b : a)
77 
78 #define SEQ_MAX(tpcb, a, b) ( SEQ_GT(tpcb, a, b) ? a : b)
79 
80 #define SEQ_INC(tpcb, Seq) ((++Seq), ((Seq) &= (tpcb)->tp_seqmask))
81 
82 #define SEQ_DEC(tpcb, Seq)\
83 	((Seq) = (((Seq)+(unsigned)((int)(tpcb)->tp_seqbit - 1))&(tpcb)->tp_seqmask))
84 
85 /* (amt) had better be less than the seq bit ! */
86 
87 #define SEQ_SUB(tpcb, Seq, amt)\
88 	(((Seq) + (unsigned)((int)(tpcb)->tp_seqbit - amt)) & (tpcb)->tp_seqmask)
89 #define SEQ_ADD(tpcb, Seq, amt) (((Seq) + (unsigned)amt) & (tpcb)->tp_seqmask)
90 
91 
92 #define IN_RWINDOW(tpcb, seq, lwe, uwe)\
93 	( SEQ_GEQ(tpcb, seq, lwe) && SEQ_LT(tpcb, seq, uwe) )
94 
95 #define IN_SWINDOW(tpcb, seq, lwe, uwe)\
96 	( SEQ_GT(tpcb, seq, lwe) && SEQ_LEQ(tpcb, seq, uwe) )
97 
98 #endif /* __TP_SEQ__ */
99