decls.h 2.91 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1 2 3 4 5 6
/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2000-2002 University of Utah and the Flux Group.
 * All rights reserved.
 */

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * Shared for defintions for frisbee client/server code.
 */

#include "log.h"

/*
 * We operate in terms of this blocksize (in bytes). 
 */
#define BLOCKSIZE	1024

/*
 * Each chunk is this many blocks.
 */
#define CHUNKSIZE	1024

/*
 * The number of chunk buffers in the client.
 */
26
#define MAXCHUNKBUFS	64
27 28 29

/*
 * The number of read-ahead chunks that the client will request
30
 * at a time. No point in requesting too far ahead either, since they
31 32 33 34 35
 * are uncompressed/written at a fraction of the network transfer speed.
 * Also, with multiple clients at different stages, each requesting blocks
 * it is likely that there will be plenty more chunks ready or in progress.
 */
#define MAXREADAHEAD	2
36
#define MAXINPROGRESS	8
37 38 39 40 41

/*
 * Timeout (in usecs) for packet receive. The idletimer number is how
 * many PKT timeouts we allow before requesting more data from the server.
 * That is, if we go TIMEOUT usecs without getting a packet, then ask for
42
 * more.
43 44
 */
#define PKTRCV_TIMEOUT		30000
45
#define CLIENT_IDLETIMER_COUNT	3
46 47
#define TIMEOUT_HZ		(1000000 / PKTRCV_TIMEOUT)
#define TIMEOUT_HALFHZ		(TIMEOUT_HZ / 2)
48 49 50

/*
 * Timeout (in seconds!) server will hang around with no active clients.
51
 * Make it zero to never exit. 
52
 */
53
#define SERVER_INACTIVE_SECONDS	(60 * 30)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

/*
 * The number of disk read blocks in a single read on the server.
 * Must be an even divisor of CHUNKSIZE.
 */
#define MAXREADBLOCKS	32

/*
 * Packet defs.
 */
typedef struct {
	struct {
		int		type;
		int		subtype;
		int		datalen; /* Useful amount of data in packet */
		unsigned int	srcip;   /* Filled in by network level. */
	} hdr;
	union {
		/*
		 * Join/leave the Team. Send a randomized ID, and receive
74 75 76
		 * the number of blocks in the file. This is strictly
		 * informational; the info is reported in the log file.
		 * We must return the number of chunks in the file though.
77 78 79 80 81
		 */
		union {
			unsigned int	clientid;
			int		blockcount;
		} join;
82 83 84 85 86
		
		struct {
			unsigned int	clientid;
			int		elapsed;	/* Stats only */
		} leave;
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

		/*
		 * A data block, indexed by chunk,block.
		 */
		struct {
			int		chunk;
			int		block;
			char		buf[BLOCKSIZE];
		} block;

		/*
		 * A request for a data block, indexed by chunk,block.
		 */
		struct {
			int		chunk;
			int		block;
			int		count;	/* Number of blocks */
		} request;
	} msg;
} Packet_t;
#define PKTTYPE_REQUEST		1
#define PKTTYPE_REPLY		2

#define PKTSUBTYPE_JOIN		1
#define PKTSUBTYPE_LEAVE	2
#define PKTSUBTYPE_BLOCK	3
#define PKTSUBTYPE_REQUEST	4

/*
 * Protos.
 */
int	ClientNetInit(void);
int	ServerNetInit(void);
int	PacketReceive(Packet_t *p);
int	PacketSend(Packet_t *p);
int	PacketReply(Packet_t *p);
char   *CurrentTimeString(void);
int	fsleep(unsigned int usecs);

/*
 * Globals
 */
extern int		debug;
extern int		portnum;
extern struct in_addr	mcastaddr;
extern struct in_addr	mcastif;
extern char	       *filename;