summaryrefslogtreecommitdiffstats
path: root/usr.sbin/atm/scspd/scsp_var.h
blob: fbbddc74e5e335fa38330246a0af1c7fe712fc47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/*
 *
 * ===================================
 * HARP  |  Host ATM Research Platform
 * ===================================
 *
 *
 * This Host ATM Research Platform ("HARP") file (the "Software") is
 * made available by Network Computing Services, Inc. ("NetworkCS")
 * "AS IS".  NetworkCS does not provide maintenance, improvements or
 * support of any kind.
 *
 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
 * In no event shall NetworkCS be responsible for any damages, including
 * but not limited to consequential damages, arising from or relating to
 * any use of the Software or related support.
 *
 * Copyright 1994-1998 Network Computing Services, Inc.
 *
 * Copies of this Software may be made, however, the above copyright
 * notice must be reproduced on all copies.
 *
 *	@(#) $FreeBSD$
 *
 */

/*
 * Server Cache Synchronization Protocol (SCSP) Support
 * ----------------------------------------------------
 *
 * SCSP message formats
 *
 */

#ifndef _SCSP_SCSP_VAR_H
#define _SCSP_SCSP_VAR_H


/*
 * Protocol constants
 */
#define	SCSP_Open_Interval	30
#define	SCSP_HELLO_Interval	3
#define	SCSP_HELLO_DF		3
#define	SCSP_CAReXmitInterval	3
#define	SCSP_CSUSReXmitInterval	3
#define	SCSP_CSA_HOP_CNT	3
#define	SCSP_CSUReXmitInterval	2
#define	SCSP_CSUReXmitMax	5


/*
 * Operational constants
 */
#define SCSPD_CONFIG	"/etc/scspd.conf"
#define	SCSPD_DIR	"/tmp"
#define SCSPD_DUMP	"/tmp/scspd.dump"
#define SCSP_HASHSZ	19
#define	SCSPD_SOCK_NAME	"SCSPD"


/*
 * HELLO finite state machine states
 */
#define	SCSP_HFSM_DOWN		0
#define	SCSP_HFSM_WAITING	1
#define	SCSP_HFSM_UNI_DIR	2
#define	SCSP_HFSM_BI_DIR	3
#define	SCSP_HFSM_STATE_CNT	SCSP_HFSM_BI_DIR + 1


/*
 * HELLO finite state machine events
 */
#define	SCSP_HFSM_VC_ESTAB	0
#define	SCSP_HFSM_VC_CLOSED	1
#define	SCSP_HFSM_HELLO_T	2
#define	SCSP_HFSM_RCV_T		3
#define	SCSP_HFSM_RCVD		4
#define	SCSP_HFSM_EVENT_CNT	SCSP_HFSM_RCVD + 1


/*
 * Cache Alignment finite state machine states
 */
#define	SCSP_CAFSM_DOWN		0
#define	SCSP_CAFSM_NEG		1
#define	SCSP_CAFSM_MASTER	2
#define	SCSP_CAFSM_SLAVE	3
#define	SCSP_CAFSM_UPDATE	4
#define	SCSP_CAFSM_ALIGNED	5
#define	SCSP_CAFSM_STATE_CNT	SCSP_CAFSM_ALIGNED + 1


/*
 * Cache Alignment finite state machine events
 */
#define	SCSP_CAFSM_HELLO_UP	0
#define	SCSP_CAFSM_HELLO_DOWN	1
#define	SCSP_CAFSM_CA_MSG	2
#define	SCSP_CAFSM_CSUS_MSG	3
#define	SCSP_CAFSM_CSU_REQ	4
#define	SCSP_CAFSM_CSU_REPLY	5
#define	SCSP_CAFSM_CA_T		6
#define	SCSP_CAFSM_CSUS_T	7
#define	SCSP_CAFSM_CSU_T	8
#define	SCSP_CAFSM_CACHE_UPD	9
#define	SCSP_CAFSM_CACHE_RSP	10
#define	SCSP_CAFSM_EVENT_CNT	SCSP_CAFSM_CACHE_RSP + 1


/*
 * Client Interface finite state machine states
 */
#define	SCSP_CIFSM_NULL		0
#define	SCSP_CIFSM_SUM		1
#define	SCSP_CIFSM_UPD		2
#define	SCSP_CIFSM_ALIGN	3
#define	SCSP_CIFSM_STATE_CNT		SCSP_CIFSM_ALIGN + 1


/*
 * Client Interface finite state machine events
 */
#define	SCSP_CIFSM_CA_DOWN	0
#define	SCSP_CIFSM_CA_SUMM	1
#define	SCSP_CIFSM_CA_UPD	2
#define	SCSP_CIFSM_CA_ALIGN	3
#define	SCSP_CIFSM_SOL_RSP	4
#define	SCSP_CIFSM_UPD_REQ	5
#define	SCSP_CIFSM_UPD_RSP	6
#define	SCSP_CIFSM_CSU_REQ	7
#define	SCSP_CIFSM_CSU_REPLY	8
#define	SCSP_CIFSM_CSU_SOL	9
#define	SCSP_CIFSM_EVENT_CNT	SCSP_CIFSM_CSU_SOL + 1


/*
 * Server connection states (not part of any FSM)
 */
#define	SCSP_SS_NULL	0
#define	SCSP_SS_CFG	1
#define	SCSP_SS_ACTIVE	2


/*
 * Hash a cache key
 *
 *	key	pointer to an Scsp_ckey structure
 */
#define SCSP_HASH(key)	scsp_hash((key))


/*
 * Add a cache summary entry to a client's cache summary
 *
 *	cpp	pointer to a server control block
 *	key	pointer to an Scsp_cse structure
 */
#define SCSP_ADD(cpp, key)					\
{								\
	Scsp_cse	**c;					\
	c = &(cpp)->ss_cache[SCSP_HASH(&(key)->sc_key)];	\
	LINK2TAIL((key), Scsp_cse, *c, sc_next);		\
}


/*
 * Delete a cache summary entry from a client's cache summary
 *
 *	cpp	pointer to a server control block
 *	s	pointer to an Scsp_cse structure
 */
#define SCSP_DELETE(cpp, s)				\
{							\
	Scsp_cse	**c;				\
	c = &(cpp)->ss_cache[SCSP_HASH(&(s)->sc_key)];	\
	UNLINK((s), Scsp_cse, *c, sc_next);		\
}


/*
 * Search a client's cache summary for a given key
 *
 *	cpp	pointer to a server control block
 *	key	pointer to an Scsp_ckey structure to find
 *	s	Scsp_cse structure pointer to be set
 */
#define SCSP_LOOKUP(cpp, key, s)				\
{								\
	for ((s) = (cpp)->ss_cache[SCSP_HASH(key)];		\
			(s);					\
			(s) = (s)->sc_next) {			\
		if (scsp_cmp_key((key), &(s)->sc_key) == 0)	\
			break;					\
	}							\
}


/*
 * SCSP pending connection control block
 *
 * The pending connection block is used to keep track of server
 * connections which are open but haven't been identified yet.
 */
struct scsp_pending {
	struct scsp_pending	*sp_next;
	int			sp_sock;
};
typedef	struct scsp_pending	Scsp_pending;


/*
 * SCSP Server instance control block
 */
struct scsp_server {
	struct scsp_server	*ss_next;	/* Server chain */
	char		*ss_name;		/* Server name */
	char		ss_intf[IFNAMSIZ];	/* Interface */
	Atm_media	ss_media;	/* Physical comm medium */
	char		ss_state;	/* Server connection state */
	u_long		ss_pid;		/* Protocol ID */
	int		ss_id_len;	/* ID length */
	int		ss_ckey_len;	/* Cache key length */
	u_long		ss_sgid;	/* Server group ID */
	u_long		ss_fid;		/* Family ID */
	int		ss_sock;	/* Socket to client */
	int		ss_dcs_lsock;	/* DCS listen socket */
	Scsp_id		ss_lsid;	/* Local Server ID */
	Atm_addr	ss_addr;	/* Local ATM addr */
	Atm_addr	ss_subaddr;	/* Local ATM subaddr */
	int		ss_mtu;		/* Interface MTU */
	int		ss_mark;
	struct scsp_dcs	*ss_dcs;	/* Ptr to list of DCSs */
	struct scsp_cse	*ss_cache[SCSP_HASHSZ];	/* Client's cache */
};
typedef	struct scsp_server	Scsp_server;


/*
 * SCSP client cache summary entry control block
 */
struct scsp_cse {
	struct scsp_cse	*sc_next;	/* Next on chain */
	long		sc_seq;		/* CSA sequence no */
	Scsp_ckey	sc_key;		/* Cache key */
	Scsp_id		sc_oid;		/* Origin ID */
};
typedef	struct scsp_cse	Scsp_cse;


/*
 * CSU Request retransmission control block
 */
struct scsp_csu_rexmt {
	struct scsp_csu_rexmt	*sr_next;	/* Next rexmit block */
	struct scsp_dcs		*sr_dcs;	/* DCS block */
	Scsp_csa		*sr_csa;	/* CSAs for rexmit */
	Harp_timer		sr_t;		/* Rexmit timer */
};
typedef	struct scsp_csu_rexmt	Scsp_csu_rexmt;


/*
 * SCSP DCS control block
 */
struct scsp_dcs {
	struct scsp_dcs	*sd_next;	/* DCS chain */
	Scsp_server	*sd_server;	/* Local server */
	Scsp_id		sd_dcsid;	/* DCS ID */
	Atm_addr	sd_addr;	/* DCS ATM address */
	Atm_addr	sd_subaddr;	/* DCS ATM subaddress */
	int		sd_sock;	/* Socket to DCS */
	Harp_timer	sd_open_t;	/* Open VCC retry timer */
	int		sd_hello_state;	/* Hello FSM state */
	int		sd_hello_int;	/* Hello interval */
	int		sd_hello_df;	/* Hello dead factor */
	int		sd_hello_rcvd;	/* Hello msg received */
	Harp_timer	sd_hello_h_t;	/* Hello timer */
	Harp_timer	sd_hello_rcv_t;	/* Hello receive timer */
	int		sd_ca_state;	/* CA FSM state */
	long		sd_ca_seq;	/* CA sequence number */
	int		sd_ca_rexmt_int;	/* CA rexmit interval */
	Scsp_msg	*sd_ca_rexmt_msg;	/* Saved CA msg */
	Scsp_cse	*sd_ca_csas;		/* CSAS still to send */
	Harp_timer	sd_ca_rexmt_t;		/* CA rexmit timer */
	int		sd_csus_rexmt_int;	/* CSUS rexmit int */
	Scsp_csa	*sd_crl;		/* Cache req list */
	Scsp_msg	*sd_csus_rexmt_msg;	/* Saved CSUS msg */
	Harp_timer	sd_csus_rexmt_t;	/* CSUS rexmit timer */
	int		sd_hops;		/* CSA hop count */
	Scsp_csa	*sd_csu_ack_pend;	/* CSUs to be ACKed */
	Scsp_csa	*sd_csu_ack;		/* CSUs ACKed */
	int		sd_csu_rexmt_int;	/* CSU Req rxmt time */
	int		sd_csu_rexmt_max;	/* CSU Req rxmt limit */
	Scsp_csu_rexmt	*sd_csu_rexmt;		/* CSU Req rxmt queue */
	int		sd_client_state;	/* Client I/F state */
};
typedef	struct scsp_dcs	Scsp_dcs;

/*
 * Trace options
 */
#define	SCSP_TRACE_HFSM		1	/* Trace the Hello FSM */
#define	SCSP_TRACE_CAFSM	2	/* Trace the CA FSM */
#define	SCSP_TRACE_CFSM		4	/* Trace the server I/F FSM */
#define	SCSP_TRACE_HELLO_MSG	8	/* Trace Hello protocol msgs */
#define	SCSP_TRACE_CA_MSG	16	/* Trace CA protocol msgs */
#define	SCSP_TRACE_IF_MSG	32	/* Trace server I/F msgs */


/*
 * Global variables
 */
extern char		*prog;
extern FILE		*cfg_file;
extern int		parse_line;
extern char		*scsp_config_file;
extern FILE		*scsp_log_file;
extern int		scsp_log_syslog;
extern Scsp_server	*scsp_server_head;
extern Scsp_pending	*scsp_pending_head;
extern int		scsp_max_socket;
extern int		scsp_debug_mode;
extern int		scsp_trace_mode;
extern FILE		*scsp_trace_file;


/*
 * Executable functions
 */
/* scsp_cafsm.c */
extern int	scsp_cafsm(Scsp_dcs *, int, void *);

/* scsp_config.c */
extern int	scsp_config(char *);
extern int	start_dcs(void);
extern int	finish_dcs(void);
extern int	set_dcs_addr(char *, char *);
extern int	set_dcs_ca_rexmit(int);
extern int	set_dcs_csus_rexmit(int);
extern int	set_dcs_csu_rexmit(int);
extern int	set_dcs_csu_rexmit_max(int);
extern int	set_dcs_hello_df(int);
extern int	set_dcs_hello_int(int);
extern int	set_dcs_hops(int);
extern int	set_dcs_id(char *);
extern int	set_intf(char *);
extern int	set_protocol(int);
extern int	set_server_group(int);
extern int	start_server(char *);
extern int	finish_server(void);
extern int	set_log_file(char *);

/* scsp_config_lex.c */
extern int	yylex(void);

/* scsp_config_parse.y */
#if __STDC__
extern void	parse_error(const char *, ...);
#else
extern void	parse_error(char *, va_alist);
#endif

/* scsp_hfsm.c */
extern int	scsp_hfsm(Scsp_dcs *, int, Scsp_msg *);

/* scsp_if.c */
extern int	scsp_cfsm(Scsp_dcs *, int, Scsp_msg *, Scsp_if_msg *);

/* scsp_input.c */
extern void	scsp_free_msg(Scsp_msg *);
extern Scsp_msg	*scsp_parse_msg(char *, int);

/* scsp_log.c */
#if __STDC__
extern void	scsp_log(const int, const char *, ...);
extern void	scsp_trace(const char *, ...);
#else
extern void	scsp_log(int, char *, va_alist);
extern void	scsp_trace(const char *, va_alist);
#endif
extern void	scsp_open_trace();
extern void	scsp_trace_msg(Scsp_dcs *, Scsp_msg *, int);
extern void	scsp_mem_err(char *);

/* scsp_msg.c */
extern void	scsp_csus_ack(Scsp_dcs *, Scsp_msg *);
extern int	scsp_send_ca(Scsp_dcs *);
extern int	scsp_send_csus(Scsp_dcs *);
extern int	scsp_send_csu_req(Scsp_dcs *, Scsp_csa *);
extern int	scsp_send_csu_reply(Scsp_dcs *, Scsp_csa *);
extern int	scsp_send_hello(Scsp_dcs *);

/* scsp_output.c */
extern int	scsp_format_msg(Scsp_dcs *, Scsp_msg *, char **);
extern int	scsp_send_msg(Scsp_dcs *, Scsp_msg *);

/* scsp_print.c */
extern char	*format_hfsm_state(int);
extern char	*format_hfsm_event(int);
extern char	*format_cafsm_state(int);
extern char	*format_cafsm_event(int);
extern char	*format_cifsm_state(int);
extern char	*format_cifsm_event(int);
extern void	print_scsp_cse(FILE *, Scsp_cse *);
extern void	print_scsp_msg(FILE *, Scsp_msg *);
extern void	print_scsp_if_msg(FILE *, Scsp_if_msg *);
extern void	print_scsp_pending(FILE *, Scsp_pending *);
extern void	print_scsp_server(FILE *, Scsp_server *);
extern void	print_scsp_dcs(FILE *, Scsp_dcs *);
extern void	print_scsp_dump();

/* scsp_socket.c */
extern Scsp_dcs *	scsp_find_dcs(int);
extern Scsp_server *	scsp_find_server(int);
extern int		scsp_dcs_connect(Scsp_dcs *);
extern int		scsp_dcs_listen(Scsp_server *);
extern Scsp_dcs *	scsp_dcs_accept(Scsp_server *);
extern int		scsp_dcs_read(Scsp_dcs *);
extern int		scsp_server_listen();
extern int		scsp_server_accept(int);
extern Scsp_if_msg *	scsp_if_sock_read(int);
extern int		scsp_if_sock_write(int, Scsp_if_msg *);
extern int		scsp_server_read(Scsp_server *);
extern int		scsp_send_cache_ind(Scsp_server *);
extern int		scsp_pending_read(Scsp_pending *);

/* scsp_subr.c */
extern int		scsp_hash(Scsp_ckey *);
extern int		scsp_cmp_id(Scsp_id *, Scsp_id *);
extern int		scsp_cmp_key(Scsp_ckey *, Scsp_ckey *);
extern int		scsp_is_atmarp_server(char *);
extern Scsp_cse *	scsp_dup_cse(Scsp_cse *);
extern Scsp_csa *	scsp_dup_csa(Scsp_csa *);
extern Scsp_csa *	scsp_cse2csas(Scsp_cse *);
extern void		scsp_dcs_cleanup(Scsp_dcs *);
extern void		scsp_dcs_delete(Scsp_dcs *);
extern void		scsp_server_shutdown(Scsp_server *);
extern void		scsp_server_delete(Scsp_server *);
extern int		scsp_get_server_info(Scsp_server *);
extern void		scsp_process_ca(Scsp_dcs *, Scsp_ca *);
extern void		scsp_process_cache_rsp(Scsp_server *, Scsp_if_msg *);
extern int		scsp_propagate_csa( Scsp_dcs *, Scsp_csa *);
extern void		scsp_update_cache( Scsp_dcs *, Scsp_csa *);
extern void		scsp_reconfigure();

/* scsp_timer.c */
extern void	scsp_open_timeout(Harp_timer *);
extern void	scsp_hello_timeout(Harp_timer *);
extern void	scsp_hello_rcv_timeout(Harp_timer *);
extern void	scsp_ca_retran_timeout(Harp_timer *);
extern void	scsp_csus_retran_timeout(Harp_timer *);
extern void	scsp_csu_req_retran_timeout(Harp_timer *);



#endif	/* _SCSP_SCSP_VAR_H */
OpenPOWER on IntegriCloud