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