xref: /original-bsd/sys/netiso/tp_pcb.h (revision de3f5c4e)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)tp_pcb.h	7.9 (Berkeley) 05/06/91
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_pcb.h,v 5.2 88/11/18 17:09:32 nhall Exp $
40  * $Source: /usr/argo/sys/netiso/RCS/tp_pcb.h,v $
41  *
42  *
43  * This file defines the transport protocol control block (tpcb).
44  * and a bunch of #define values that are used in the tpcb.
45  */
46 
47 #ifndef  __TP_PCB__
48 #define  __TP_PCB__
49 
50 #include "../netiso/tp_param.h"
51 #include "../netiso/tp_timer.h"
52 #include "../netiso/tp_user.h"
53 #ifndef sblock
54 #include "socketvar.h"
55 #endif sblock
56 
57 /* NOTE: the code depends on REF_CLOSED > REF_OPEN > the rest, and
58  * on REF_FREE being zero
59  *
60  * Possible improvement:
61  * think about merging the tp_ref w/ the tpcb and doing a search
62  * through the tpcb list, from tpb. This would slow down lookup
63  * during data transfer
64  * It would be a little nicer also to have something based on the
65  * clock (like top n bits of the reference is part of the clock, to
66  * minimize the likelihood  of reuse after a crash)
67  * also, need to keep the timer servicing part to a minimum (although
68  * the cost of this is probably independent of whether the timers are
69  * in the pcb or in an array..
70  * Last, would have to make the number of timers a function of the amount of
71  * mbufs available, plus some for the frozen references.
72  *
73  * Possible improvement:
74  * Might not need the ref_state stuff either...
75  * REF_FREE could correspond to tp_state == CLOSED or nonexistend tpcb,
76  * REF_OPEN to tp_state anywhere from AK_WAIT or CR_SENT to CLOSING
77  * REF_OPENING could correspond to LISTENING, because that's the
78  * way it's used, not because the correspondence is exact.
79  * REF_CLOSED could correspond to REFWAIT
80  */
81 #define REF_FROZEN 3	/* has ref timer only */
82 #define REF_OPEN 2		/* has timers, possibly active */
83 #define REF_OPENING 1	/* in use (has a pcb) but no timers */
84 #define REF_FREE 0		/* free to reallocate */
85 
86 #define N_CTIMERS 		4
87 #define N_ETIMERS 		2
88 
89 struct tp_ref {
90 	u_char	 			tpr_state; /* values REF_FROZEN, etc. above */
91 	struct Ccallout 	tpr_callout[N_CTIMERS]; /* C timers */
92 	struct Ecallout		tpr_calltodo;			/* list of active E timers */
93 	struct tp_pcb 		*tpr_pcb;	/* back ptr to PCB */
94 };
95 
96 struct tp_param {
97 	/* PER system stuff (one static structure instead of a bunch of names) */
98 	unsigned 	tpp_configed:1;			/* Has TP been initialized? */
99 };
100 
101 
102 /*
103  * retransmission control and performance measurement
104  */
105 struct tp_rtc {
106 	struct tp_rtc	*tprt_next; /* ptr to next rtc structure in the list */
107 	SeqNum 			tprt_seq;	/* seq # of this TPDU */
108 	int				tprt_eot;	/* Will this TPDU have the eot bit set? */
109 	int				tprt_octets;/* # octets in this TPDU */
110 	struct mbuf		*tprt_data; /* ptr to the octets of data */
111 };
112 
113 struct nl_protosw {
114 	int		nlp_afamily;			/* address family */
115 	int		(*nlp_putnetaddr)();	/* puts addresses in nl pcb */
116 	int		(*nlp_getnetaddr)();	/* gets addresses from nl pcb */
117 	int		(*nlp_cmpnetaddr)();	/* compares address in pcb with sockaddr */
118 	int		(*nlp_putsufx)();		/* puts transport suffixes in nl pcb */
119 	int		(*nlp_getsufx)();		/* gets transport suffixes from nl pcb */
120 	int		(*nlp_recycle_suffix)();/* clears suffix from nl pcb */
121 	int		(*nlp_mtu)();			/* figures out mtu based on nl used */
122 	int		(*nlp_pcbbind)();		/* bind to pcb for net level */
123 	int		(*nlp_pcbconn)();		/* connect for net level */
124 	int		(*nlp_pcbdisc)();		/* disconnect net level */
125 	int		(*nlp_pcbdetach)();		/* detach net level pcb */
126 	int		(*nlp_pcballoc)();		/* allocate a net level pcb */
127 	int		(*nlp_output)();		/* prepare a packet to give to nl */
128 	int		(*nlp_dgoutput)();		/* prepare a packet to give to nl */
129 	int		(*nlp_ctloutput)();		/* hook for network set/get options */
130 	caddr_t	nlp_pcblist;			/* list of xx_pcb's for connections */
131 };
132 
133 
134 struct tp_pcb {
135 	struct tp_pcb		*tp_next;
136 	struct tp_pcb		*tp_prev;
137 	struct tp_pcb		*tp_nextlisten; /* chain all listeners */
138 	u_short 			tp_state;		/* state of fsm */
139 	short 				tp_retrans;		/* # times can still retrans */
140 	struct tp_ref 		*tp_refp;		/* rest of pcb	*/
141 	caddr_t				tp_npcb;		/* to lower layer pcb */
142 	struct nl_protosw	*tp_nlproto;	/* lower-layer dependent routines */
143 	struct socket 		*tp_sock;		/* back ptr */
144 
145 
146 	RefNum				tp_lref;	 	/* local reference */
147 	RefNum 				tp_fref;		/* foreign reference */
148 
149 	u_int				tp_seqmask;		/* mask for seq space */
150 	u_int				tp_seqbit;		/* bit for seq number wraparound */
151 	u_int				tp_seqhalf;		/* half the seq space */
152 
153 	/* credit & sequencing info for SENDING */
154 	u_short 			tp_fcredit;		/* current remote credit in # packets */
155 
156 	u_short				tp_cong_win;	/* congestion window : set to 1 on
157 										 * source quench
158 										 * Minimizes the amount of retrans-
159 										 * missions (independently of the
160 										 * retrans strategy).  Increased
161 										 * by one for each good ack received.
162 										 * Minimizes the amount sent in a
163 										 * regular tp_send() also.
164 										 */
165 	u_int   tp_ackrcvd; /* ACKs received since the send window was updated */
166 	SeqNum              tp_last_retrans;
167 	SeqNum              tp_retrans_hiwat;
168 	SeqNum				tp_snduna;		/* seq # of lowest unacked DT */
169 	struct tp_rtc		*tp_snduna_rtc;	/* lowest unacked stuff sent so far */
170 	SeqNum				tp_sndhiwat;	/* highest seq # sent so far */
171 
172 	struct tp_rtc		*tp_sndhiwat_rtc;	/* last stuff sent so far */
173 	int					tp_Nwindow;		/* for perf. measurement */
174 	struct mbuf			*tp_ucddata;	/* user connect/disconnect data */
175 
176 	/* credit & sequencing info for RECEIVING */
177 	SeqNum	 			tp_sent_lcdt;	/* cdt according to last ack sent */
178 	SeqNum	 			tp_sent_uwe;	/* uwe according to last ack sent */
179 	SeqNum	 			tp_sent_rcvnxt;	/* rcvnxt according to last ack sent
180 										 * needed for perf measurements only
181 										 */
182 	u_short				tp_lcredit;		/* current local credit in # packets */
183 	SeqNum				tp_rcvnxt;		/* next DT seq # expect to recv */
184 	struct tp_rtc		*tp_rcvnxt_rtc;	/* unacked stuff recvd out of order */
185 
186 	/* receiver congestion state stuff ...  */
187 	u_int               tp_win_recv;
188 
189 	/* receive window as a scaled int (8 bit fraction part) */
190 
191 	struct cong_sample {
192 		ushort  cs_size; 				/* current window size */
193 		ushort  cs_received;   			/* PDUs received in this sample */
194 		ushort  cs_ce_set;    /* PDUs received in this sample with CE bit set */
195 	} tp_cong_sample;
196 
197 
198 	/* parameters per-connection controllable by user */
199 	struct tp_conn_param _tp_param;
200 
201 #define	tp_Nretrans _tp_param.p_Nretrans
202 #define	tp_dr_ticks _tp_param.p_dr_ticks
203 #define	tp_cc_ticks _tp_param.p_cc_ticks
204 #define	tp_dt_ticks _tp_param.p_dt_ticks
205 #define	tp_xpd_ticks _tp_param.p_x_ticks
206 #define	tp_cr_ticks _tp_param.p_cr_ticks
207 #define	tp_keepalive_ticks _tp_param.p_keepalive_ticks
208 #define	tp_sendack_ticks _tp_param.p_sendack_ticks
209 #define	tp_refer_ticks _tp_param.p_ref_ticks
210 #define	tp_inact_ticks _tp_param.p_inact_ticks
211 #define	tp_xtd_format _tp_param.p_xtd_format
212 #define	tp_xpd_service _tp_param.p_xpd_service
213 #define	tp_ack_strat _tp_param.p_ack_strat
214 #define	tp_rx_strat _tp_param.p_rx_strat
215 #define	tp_use_checksum _tp_param.p_use_checksum
216 #define	tp_use_efc _tp_param.p_use_efc
217 #define	tp_use_nxpd _tp_param.p_use_nxpd
218 #define	tp_use_rcc _tp_param.p_use_rcc
219 #define	tp_tpdusize _tp_param.p_tpdusize
220 #define	tp_class _tp_param.p_class
221 #define	tp_winsize _tp_param.p_winsize
222 #define	tp_no_disc_indications _tp_param.p_no_disc_indications
223 #define	tp_dont_change_params _tp_param.p_dont_change_params
224 #define	tp_netservice _tp_param.p_netservice
225 #define	tp_version _tp_param.p_version
226 
227 	int tp_l_tpdusize;
228 		/* whereas tp_tpdusize is log2(the negotiated max size)
229 		 * l_tpdusize is the size we'll use when sending, in # chars
230 		 */
231 
232 	struct timeval	tp_rtv;					/* max round-trip time variance */
233 	struct timeval	tp_rtt; 					/* smoothed round-trip time */
234 	struct timeval 	tp_rttemit[ TP_RTT_NUM + 1 ];
235 					/* times that the last TP_RTT_NUM DT_TPDUs were emitted */
236 	unsigned
237 		tp_sendfcc:1,			/* shall next ack include FCC parameter? */
238 		tp_trace:1,				/* is this pcb being traced? (not used yet) */
239 		tp_perf_on:1,			/* 0/1 -> performance measuring on  */
240 		tp_reneged:1,			/* have we reneged on cdt since last ack? */
241 		tp_decbit:3,			/* dec bit was set, we're in reneg mode  */
242 		tp_cebit_off:1,			/* the real DEC bit algorithms not in use */
243 		tp_flags:8,				/* values: */
244 #define TPF_CONN_DATA_OUT	TPFLAG_CONN_DATA_OUT
245 #define TPF_CONN_DATA_IN	TPFLAG_CONN_DATA_IN
246 #define TPF_DISC_DATA_IN	TPFLAG_DISC_DATA_IN
247 #define TPF_DISC_DATA_OUT	TPFLAG_DISC_DATA_OUT
248 #define TPF_XPD_PRESENT 	TPFLAG_XPD_PRESENT
249 #define TPF_NLQOS_PDN	 	TPFLAG_NLQOS_PDN
250 #define TPF_PEER_ON_SAMENET	TPFLAG_PEER_ON_SAMENET
251 
252 #define PEER_IS_LOCAL(t) \
253 			(((t)->tp_flags & TPF_PEER_ON_SAME_NET)==TPF_PEER_ON_SAME_NET)
254 #define USES_PDN(t)	\
255 			(((t)->tp_flags & TPF_NLQOS_PDN)==TPF_NLQOS_PDN)
256 
257 		tp_unused:16;
258 
259 
260 #ifdef TP_PERF_MEAS
261 	/* performance stats - see tp_stat.h */
262 	struct tp_pmeas		*tp_p_meas;
263 	struct mbuf			*tp_p_mbuf;
264 #endif TP_PERF_MEAS
265 	/* addressing */
266 	u_short				tp_domain;		/* domain (INET, ISO) */
267 	/* for compatibility with the *old* way and with INET, be sure that
268 	 * that lsuffix and fsuffix are aligned to a short addr.
269 	 * having them follow the u_short *suffixlen should suffice (choke)
270 	 */
271 	u_short				tp_fsuffixlen;	/* foreign suffix */
272 	char				tp_fsuffix[MAX_TSAP_SEL_LEN];
273 	u_short				tp_lsuffixlen;	/* local suffix */
274 	char				tp_lsuffix[MAX_TSAP_SEL_LEN];
275 #define SHORT_LSUFXP(tpcb) ((short *)((tpcb)->tp_lsuffix))
276 #define SHORT_FSUFXP(tpcb) ((short *)((tpcb)->tp_fsuffix))
277 
278 	u_char 				tp_vers;		/* protocol version */
279 	u_char 				tp_peer_acktime; /* used to compute DT retrans time */
280 
281 	struct sockbuf		tp_Xsnd;		/* for expedited data */
282 /*	struct sockbuf		tp_Xrcv;		/* for expedited data */
283 #define tp_Xrcv tp_sock->so_rcv
284 	SeqNum				tp_Xsndnxt;	/* next XPD seq # to send */
285 	SeqNum				tp_Xuna;		/* seq # of unacked XPD */
286 	SeqNum				tp_Xrcvnxt;	/* next XPD seq # expect to recv */
287 
288 	/* AK subsequencing */
289 	u_short				tp_s_subseq;	/* next subseq to send */
290 	u_short				tp_r_subseq;	/* highest recv subseq */
291 
292 };
293 
294 u_int	tp_start_win;
295 
296 #define ROUND(scaled_int) (((scaled_int) >> 8) + (((scaled_int) & 0x80) ? 1:0))
297 
298 /* to round off a scaled int with an 8 bit fraction part */
299 
300 #define CONG_INIT_SAMPLE(pcb) \
301 	pcb->tp_cong_sample.cs_received = \
302     pcb->tp_cong_sample.cs_ce_set = 0; \
303     pcb->tp_cong_sample.cs_size = MAX(pcb->tp_lcredit, 1) << 1;
304 
305 #define CONG_UPDATE_SAMPLE(pcb, ce_bit) \
306     pcb->tp_cong_sample.cs_received++; \
307     if (ce_bit) { \
308         pcb->tp_cong_sample.cs_ce_set++; \
309     } \
310     if (pcb->tp_cong_sample.cs_size <= pcb->tp_cong_sample.cs_received) { \
311         if ((pcb->tp_cong_sample.cs_ce_set << 1) >=  \
312                     pcb->tp_cong_sample.cs_size ) { \
313             pcb->tp_win_recv -= pcb->tp_win_recv >> 3; /* multiply by .875 */ \
314             pcb->tp_win_recv = MAX(1 << 8, pcb->tp_win_recv); \
315         } \
316         else { \
317             pcb->tp_win_recv += (1 << 8); /* add one to the scaled int */ \
318         } \
319         pcb->tp_lcredit = ROUND(pcb->tp_win_recv); \
320         CONG_INIT_SAMPLE(pcb); \
321     }
322 
323 #define CONG_ACK(pcb, seq) \
324 { int   newacks = SEQ_SUB(pcb, seq, pcb->tp_snduna); \
325 	if (newacks > 0) { \
326 		pcb->tp_ackrcvd += newacks; \
327 		if (pcb->tp_ackrcvd >= MIN(pcb->tp_fcredit, pcb->tp_cong_win)) { \
328 			++pcb->tp_cong_win; \
329 			pcb->tp_ackrcvd = 0; \
330 		} \
331 	} \
332 }
333 
334 #ifdef KERNEL
335 extern struct timeval 	time;
336 extern struct tp_ref 	*tp_ref;
337 extern struct tp_param	tp_param;
338 extern struct nl_protosw  nl_protosw[];
339 extern struct tp_pcb	*tp_listeners;
340 extern struct tp_pcb	*tp_intercepts;
341 #endif
342 
343 #define	sototpcb(so) 	((struct tp_pcb *)(so->so_tpcb))
344 #define	sototpref(so)	((struct tp_ref *)((so)->so_tpcb->tp_ref))
345 #define	tpcbtoso(tp)	((struct socket *)((tp)->tp_sock))
346 #define	tpcbtoref(tp)	((struct tp_ref *)((tp)->tp_ref))
347 
348 #endif  __TP_PCB__
349