src/vfer.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2005, 2006, Internet2
00003  * Legal conditions are in file LICENSE
00004  * (MD5 = c434f2e53b8089d8b4d0172c7ce07360).
00005  */
00006 /**
00007  *
00008  * @file   vfer.h
00009  * @author Ivan Beschastnikh
00010  * @brief  Header file that is used by multiple sources within the protocol stack.
00011  *
00012  * This header file includes many useful macros & functions for error
00013  * processing, memory allocation and more.
00014  *
00015  * -     12/28/05        ivan            tsci2 integration ; rel func prototype def and context structure ; numerous changes to ccontrol struct and others
00016  * -     09/01/05        ivan            added packet debugging macro and packet alloc and release macros
00017  * -     07/28/05        ivan            modified to support c_control socket links + added some defines
00018  * -     05/21/05        ivan            created
00019  */
00020 
00021 
00022 #ifndef VFER_H
00023 #define VFER_H
00024 
00025 /*
00026  * includes
00027  */
00028 
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 
00032 #include <unistd.h>
00033 #include <sys/types.h>
00034 #include <sys/socket.h>
00035 #include <sys/un.h>
00036 #include <string.h>
00037 #include <netinet/in.h>
00038 #include <arpa/inet.h>
00039 #include <pthread.h>    /* thread support => compile with -lpthread */
00040 #include <signal.h>
00041 #include <sys/select.h> /* select */
00042 #include <sys/mman.h>   /* mmap*/
00043 #include <errno.h>      /* error functionality */
00044 #include <sys/select.h>
00045 #include <math.h>
00046 #include <fcntl.h>
00047 #include <sys/time.h>
00048 #include <time.h>
00049 
00050 #ifdef TSCI2
00051 // #include <tsci2.h>
00052 #include "/home/ivan/include/tsci2.h"
00053 #endif
00054 
00055 #include "vfer_btree_delay.h"
00056 #include "vfer_accept_queue.h"
00057 #include "vfer_datagram.h"
00058 #include "vfer_packet.h"
00059 
00060 /*
00061  * constants
00062  */
00063 
00064 /* note that version MUST be less than 16 - see packetizing of the
00065  * vfer header in the spec rev. 1.7 and greater */
00066 #define VFER_VERSION            1
00067 
00068 /* debug\error defs */
00069 
00070 /* these can be reset to point to open files, but they are not used if
00071  * DEBUG_ERR and/or DEBUG_OUT are commented out */
00072 FILE* debug_out;
00073 FILE* error_out;
00074 
00075 /* determines whether we output any err msgs to debug_err */
00076 #define DEBUG_ERR
00077 /* determines whether we output any informational msgs to debug_out */
00078 #define DEBUG_OUT
00079 
00080 /*
00081  * these vars determine the printing of messages for specific layers
00082  * of the protocol (they are set via vfer_debug() in api.c)
00083  */
00084 char DEBUG_ACCEPTQ;
00085 char DEBUG_API;
00086 char DEBUG_CTL;
00087 char DEBUG_CCTL;
00088 char DEBUG_PACKET;
00089 char DEBUG_PMTUD;
00090 
00091 /**/
00092 #ifdef DEBUG_ERR
00093         #define ERROR_PRINT(FILE, FUNC, ...) { \
00094                 fprintf(error_out, "ERROR [%s :: %s] ", FILE, FUNC); \
00095                 fprintf(error_out, __VA_ARGS__); \
00096                 fprintf(error_out, "\n"); \
00097                 fflush(error_out); }
00098 #else
00099         #define ERROR_PRINT(COND, FILE, FUNC, ...)
00100 #endif
00101 /**/
00102 #ifdef DEBUG_OUT
00103         #define DEBUG_PRINT(COND, FILE, FUNC, ...) \
00104                 if (COND && debug_out != NULL) {fprintf(debug_out, "%-13s [ %-20s ] ", #COND, FUNC); \
00105                 fprintf(debug_out, __VA_ARGS__); \
00106                 fprintf(debug_out, "\n"); \
00107                 fflush(debug_out); }
00108         #define DEBUG_PACK(COND, FILE, FUNC, PACKET, ...) \
00109                 if (COND && debug_out != NULL) {fprintf(debug_out, "%-13s [ %-20s ] ", #COND, FUNC); \
00110                 fprintf(debug_out, __VA_ARGS__); \
00111                 fprintf(debug_out, "\n%-50s %s\n", " ", Packet_Str(PACKET)); \
00112                 /* fprintf(debug_out, "%s\n", Packet_Str(PACKET)); */ \
00113                 fflush(debug_out); }
00114         #define DEBUG_CC(COND, FILE, FUNC, SOCKET, ...) \
00115                 if (COND && debug_out != NULL) { \
00116                     struct timeval tv; \
00117                     GET_TIME_OF_DAY(&tv); \
00118                     fprintf(debug_out, "%-13s [ %-20s ] ", #COND, FUNC); \
00119                     fprintf(debug_out, "rtt[%u] sendw[%u,%u] cwnd[%d] inflight[%u] recvw[%u,%u] rlost[%u] delay[dlta %d]\n", \
00120                             (RTT(SOCKET,tv) == 0 ? 1 : RTT(SOCKET,tv)), SOCKET->ccontrol.s_first_seq, SOCKET->ccontrol.s_last_seq, SOCKET->ccontrol.s_cwnd, \
00121                             SOCKET->ccontrol.s_inflight, SOCKET->ccontrol.r_first_seq, SOCKET->ccontrol.r_last_seq, SOCKET->ccontrol.r_packets_lost, \
00122                             SOCKET->ccontrol.delay_delta); \
00123                     fflush(debug_out);   \
00124                 }
00125         #define DEBUG_PMTUD_PRINT(COND, FILE, FUNC, ...) \
00126                 if (COND && debug_out != NULL) {fprintf(debug_out, "%-13s [ %-20s ] ", #COND, FUNC); \
00127                         fprintf(debug_out, __VA_ARGS__); \
00128                         fprintf(debug_out, "\n"); \
00129                         fflush(debug_out);}
00130 #else
00131         #define DEBUG_PRINT(COND, FILE, FUNC, ...)
00132         #define DEBUG_PACK(COND, FILE, FUNC, PACKET, ...)
00133         #define DEBUG_CC(COND, FILE, FUNC, SOCKET, ...)
00134         #define DEBUG_PMTUD_PRINT(COND, FILE, FUNC, SOCKET, ...)
00135 #endif
00136 
00137 
00138 #define PRINT_MEM printf("MEMORY USED [%d bytes]\n", (int)ReqMem);
00139 
00140 /* useful utility macros */
00141 
00142 /**/
00143 #ifdef TSCI2
00144         #define GET_TIME_OF_DAY(TV_PTR) tsci2_gettimeofday(TV_PTR, NULL);
00145 #else
00146         #define GET_TIME_OF_DAY(TV_PTR) gettimeofday(TV_PTR, NULL);
00147 #endif
00148 
00149 /* evaluates to the value of TV in milliseconds where TV is of type struct timeval */
00150 #define TIMEVAL_MS(TV) ((unsigned int)(((TV).tv_sec * 1000) + ((TV).tv_usec / 1000)))
00151 #define TIMEVAL_US(TV) ((unsigned int)(((TV).tv_sec * 1000000) + ((TV).tv_usec)))
00152 
00153 /* evaluates to (TV2 - TV1) in milliseconds where TV1 and TV2 are of type struct timeval */
00154 #define TIMEVAL_MS_DIFF(TV1, TV2) (TIMEVAL_MS(TV2) - TIMEVAL_MS(TV1))
00155 
00156 /* evaluates to (TV2 - TV1) in microseconds where TV1 and TV2 are of type struct timeval */
00157 #define TIMEVAL_US_DIFF(TV1, TV2) (TIMEVAL_US(TV2) - TIMEVAL_US(TV1))
00158 
00159 /* computes round trip time in us, TV is the current time stamp which is used by the btree to prune old delay values */
00160 #define RTT(SOCK_PTR, TV) abs(SOCK_PTR->ccontrol.delay - Tree_Min(&(SOCK_PTR->ccontrol.rev_path_curr_delayhist), TV))
00161 
00162 #define ALLOC(DST_ADDR,TYPE_POINTER,TYPE,NUM) ({ \
00163         DST_ADDR=NULL; \
00164         if ((DST_ADDR = (TYPE_POINTER) calloc(NUM, sizeof( TYPE )))) \
00165              ReqMem += (sizeof(TYPE) * NUM); \
00166         /* printf("ALLOC[%d]\n", ReqMem); */ \
00167         DST_ADDR; })
00168 
00169 #define RELEASE(POINTER_TO_BLOCK, SIZE) { \
00170         free(POINTER_TO_BLOCK); \
00171         ReqMem -= SIZE; \
00172         /* printf("FREE[%d]\n", ReqMem); */ }\
00173 
00174 #define RELEASE_IOV(IOV, LEN) { \
00175         int release_iov_itter; \
00176         for(release_iov_itter = 0; release_iov_itter < LEN; release_iov_itter++) { \
00177                 /* printf(" : iov[%d] len[%d] : ", release_iov_itter, IOV[release_iov_itter].iov_len); */ \
00178                 RELEASE(IOV[release_iov_itter].iov_base, IOV[release_iov_itter].iov_len); } \
00179         RELEASE(IOV, sizeof(struct iovec));}
00180 
00181 #define RELEASE_PACK(PACK) { \
00182         /* printf("releasing pack with iovlen[%d] : ", PACK->iovlen); */ \
00183         RELEASE_IOV(PACK->iov, PACK->iovlen); \
00184         RELEASE(PACK, sizeof(struct packet));}
00185 
00186 #define UNLOCK_AND_RETURN_ERROR(mutex, err) { \
00187         pthread_mutex_unlock(&mutex); \
00188         return err; }
00189 
00190 #define SET_ERROR_RETURN(sock, error_type, ret) { \
00191         if (sock != NULL) sock->err = error_type; \
00192         return ret; }
00193 
00194 #define SET_ERROR_UNLOCK_RETURN(sock, error_type, mutex_ptr, ret) { \
00195         if (sock != NULL) sock->err = error_type; \
00196         pthread_mutex_lock(mutex_ptr); \
00197         return ret; }
00198 
00199 /* INIT_VAL is in microseconds */
00200 #define TREE_INIT(TREE_PTR, INIT_VAL, TV) { \
00201                 if (INIT_VAL >= 1000000) { \
00202                         TV.tv_sec = (int)(INIT_VAL / 1000000.0); \
00203                 } else { \
00204                         TV.tv_sec = 0; \
00205                 } \
00206                 TV.tv_usec = (INIT_VAL - TV.tv_sec * 1000000); \
00207                 Tree_Init(TREE_PTR, TV); }
00208 
00209 #define CLR_SOCKET_STATS(stats_ptr) { bzero(stats_ptr, sizeof(struct vfer_stats)); }
00210 
00211 /* socket util macros for on\off socket options only */
00212 #define SOCK_OPT_ISSET(socket, opt) (socket->opts & opt)
00213 
00214 
00215 /* protocol control constants */
00216 
00217 /* server */
00218 #define MAX_RESPONSE_TRIES              5
00219 #define HANDSHAKE_ACK_WAIT_INTERVAL     1000000                         /* microsecs to wait for an ack after sending a response (before resending a response) */
00220 
00221 /* client */
00222 #define MAX_REQUEST_TRIES               5
00223 #define REQUEST_RETRY_INTERVAL          1000000                         /* microseconds */
00224 
00225 /* default transfer size constants (for now) */
00226 #define INIT_MTU                        1024  /* initial MTU for a VFER connection */
00227 #define MAX_FRAME_SIZE                  65535 /* this is the max UDP datagram size as well */
00228 #define URGENCY_THRESHOLD               1     /* in frames ; accounts for reordering */
00229 
00230 /* default Path MTU constants */
00231 #define COMMON_MTU_LIST { 1024, 1430, 1978, 4282, 8096, 17844, 31030, 65465 } /* List of common MTUS, last value should be no larger than MAX_FRAME_SIZE */
00232 #define COMMON_MTU_MAX_INDEX 7                     /* Number of common MTUS - 1 */
00233 #define NO_PROBE_SENT 0
00234 #define PROBE_SENT 1
00235 #define MTU_FOUND 2
00236 #define NO_PMTUD 3
00237 #define PMTUD_TIME_INTERVAL 600 /* Time in seconds between probes after MTU found. */
00238 
00239 /* define ICMP constants */
00240 #define DEST_UNREACHABLE 3
00241 #define FRAG_NEEDED 4
00242 
00243 /* flow control buffer[s] size constants */
00244 #define DEFAULT_RECV_BUF_MAXPACKETS             3000 /* number of packets ; should be same as SEND_BUF_MAXPACKETS */
00245 #define DEFAULT_SEND_BUF_MAXPACKETS             3000 /* number of packets */
00246 
00247 /* in bytes */
00248 #define CALC_UDP_RECV_BUF_SIZE(MAXPACKETS) ((DATA_LENGTH + INIT_MTU)*MAXPACKETS)
00249 #define CALC_UDP_SEND_BUF_SIZE(MAXPACKETS) ((DATA_LENGTH + INIT_MTU)*MAXPACKETS)
00250 
00251 #define MMAP_CHUNK_SIZE                 50000000 /* 50mb : mmap chunk size for vfer_sendfile to use or rather the closeset page_size multiple to this value */
00252 #define SEQ_WINDOW                      5 /* not used right now */
00253 #define FRAME_WINDOW                    5 /* not used right now: meant to discard frames that are too far away */
00254 
00255 /* control thread sleeping\activity cycle or rate of waking up */
00256 #define CONTROLT_SLEEPTIME              1000 /* in us ; main control loop sleep time ; if this changes, RTT comparisons in ControlT need to change as well */
00257 
00258 /* flow control restriction: max number of bytes that can be enqueued in the send queue */
00259 #define MAX_SEND_WINDOW                 1024*8000 /* 8mb */
00260 
00261 /* default timeouts on vfer_* calls in microseconds */
00262 #define DEFAULT_CONNECT_TIMEOUT         60000000 /* 60s vfer_connect() */
00263 
00264 /* CCONTROL VARIABLES */
00265 #define UNACKED_THRESH                          4 /* MTU factor of unacked data to receive before sending an ack */
00266 #define MAX_CWND_INCREASE_PACKETS_PER_RTT       8
00267 #define CCONTROL_TARGET                         8000 /* in microseconds, 8(ms) target */
00268 
00269 /*
00270  * data structures
00271  */
00272 
00273 typedef struct sockaddr SA;
00274 
00275 /**
00276  * @brief congestion control structure maintained for each socket
00277  */
00278 typedef struct ccontrol {
00279         /* sending vars */
00280         uint32_t s_first_seq;           /* oldest unacknowledged (implicitly or explicitly) sequence number that was sent */
00281         uint32_t s_last_seq;            /* last sequence number sent */
00282         int32_t s_cwnd;                 /* current congestion control sending window size (in bytes) */
00283         uint32_t s_cwnd_sent;           /* number of bytes sent in the s_cwnd in the 'current' RTT */
00284         int32_t s_maxw;         /* maximum (!)congestion sending window size (in bytes) */
00285         uint32_t s_inflight;            /* number of packets in flight (s_last_seq - s_first_seq) */
00286         struct timeval s_last_ack;      /* timestamp of send of last ack */
00287         struct timeval s_rtt_start;     /* timestamp of the start of the current rtt : when this becomes older than RTT, we reset s_cwnd_sent to 0 and set s_rtt_start to curren time */
00288         struct timeval s_last_unacked_data;     /* timestamp of last sent data packet and not receiving any ack afterwards ; set to 0 if did not send any data since receipt of last ack */
00289         frame_link* s_last_data_frame;  /* last data packet frame pointer */
00290 
00291         uint32_t s_last_data_offset;    /* the offset of the last data sent (we don't save the length because the MTU might vary) */
00292 
00293         struct timeval s_last_vec;      /* timestamp of last sending of a vec ack packet */
00294         uint16_t s_need_ccack;          /* binary valued var to tell us if need to send an ack in this RTT period */
00295 
00296         /* receiving vars */
00297         uint16_t r_packets_lost;        /* number of packets lost since last sent cc ack */
00298         uint32_t r_first_seq;           /* first unacked seq received */
00299         uint32_t r_last_seq;            /* last seq received */
00300         uint32_t r_bytes_total;         /* total number of data bytes received for this connection */
00301         struct timeval r_last_ccack;    /* timestamp of receipt of last ccack packet */
00302         struct timeval r_last_data;     /* timestamp of receipt of last data packet */
00303         uint32_t r_unacked_bytes;       /* number of bytes that haven't been acked yet (since sending previous ack) */
00304 
00305         uint16_t last_packets_lost;     /* the last packets_lost received for this connection */
00306         uint32_t last_bytes_total;      /* the last total data bytes advertised as received by the other end host */
00307 
00308         uint32_t mtu;                   /* MTU for the sending path */
00309         uint32_t rtt;                   /* us current rtt estimate */
00310         int32_t delay_delta;            /* this is the value received on last ccack packet and is (base_delay - curr_delay) for the sending path (computed and maintained at the sender) */
00311         int32_t delay;                  /* this is the value received on last ccack packet and is the current delay for the sending path */
00312         tree_t rev_path_base_delayhist; /* delay history structure that maintains min delay over a 'long' time period (on order of seconds) for the reverse path */
00313         tree_t rev_path_curr_delayhist; /* delay history structure that maintains min delay over a shorter time period (on order of ms) for the reverse path */
00314         int syncing;                    /* set when the next data pack to send requires a sync option to be set */
00315         struct timeval r_last_loss;     /* timestamp of last loss event received ; this val reset (ie. tv_sec=0) once the timestamp is older than RTT */
00316 } ccontrol_t;
00317 
00318 /**
00319  * @brief VFER stats structure maintained for each socket
00320  */
00321 typedef struct vfer_stats {
00322         uint32_t packets_recvd;         /* total packets received */
00323         uint32_t packets_sent;          /* total packets sent */
00324         uint32_t bytes_recvd;           /* total bytes received (all packets) */
00325         uint32_t bytes_sent;            /* total bytes sent (all packets) */
00326         uint32_t data_bytes_recvd;      /* total bytes received (data payload only) */
00327         uint32_t data_bytes_sent;       /* total bytes sent (data payload only) */
00328         struct timeval tv_start;        /* the start time of the connection : once the connection has been established (after connecting handshake) */
00329         struct timeval tv_end;          /* the end time of the connection : once the connection has been closed (after closing handshake) */
00330         double avg_rtt;                 /* is us ; avg round trip time recorded for the conn*/
00331         double max_rtt;                 /* is us ; max round trip time recorded for the conn */
00332         double min_rtt;                 /* is us ; min round trip time recorded for the conn */
00333         uint32_t rtt_measurements;      /* number of rtt measurements taken */
00334         uint32_t data_bytes_sender_sent;/* data payload only : bytes that were sent with the vfer_send call (ie. sent by the sender, not the protocol) */
00335 } vfer_stats;
00336 
00337 /**
00338  * @brief context structure used by the reliability functino to evaluate reliability for a frame
00339  */
00340 typedef struct context_t {      /* reliability function's argument/context */
00341         frame f;
00342         vfer_stats* stats;
00343         frame_stats* fstats;
00344 } context_t;
00345 
00346 typedef uint32_t bool_t;                /* reliability function return value: 0,1 */
00347 typedef bool_t(*relfun_t)(context_t*);  /* reliability function type: takes context pointer type and return bool type */
00348 
00349 /**
00350  * @brief vfer_error type
00351  */
00352 enum vfer_error {
00353         VFER_BADTYPE=-40,
00354         VFER_IMPL,
00355         VFER_BADSOCK,
00356         VFER_TIMEOUT,
00357         VFER_REFUSED,
00358         VFER_NOCONN,
00359         VFER_NOBIND,
00360         VFER_BADADDR,
00361         VFER_NOLISTEN,
00362         VFER_NOACCEPT,
00363         VFER_NOTSTREAM,
00364         VFER_WOULDBLOCK,
00365         VFER_BADOPT,
00366         VFER_BADFD,
00367         VFER_INVAL,
00368         VFER_UNCONN,
00369         VFER_INPROGRESS
00370 } vfer_error;
00371 
00372 typedef enum sock_mark {
00373         VFER_READABLE=1,
00374         VFER_WRITABLE=2,
00375         VFER_EXCEPTION=4
00376 } sock_mark_t;
00377 
00378 typedef enum sock_state {
00379         CONN_ACQUIRED,          /* allocated/reserved socket with the vfer_socket() call */
00380         CONN_BOUND,             /* bound socket (to a port number) */
00381         CONN_LISTENING,         /* socket listening for incoming connections */
00382         CONN_ACCEPTING,         /* socket is accepting a connection (has a reference to a socket in CONN_LISTENING state) */
00383         CONN_CONNECTING,        /* handshake state */
00384         CONN_CONNECTED, /* active connection duplex open on both sides local/remote */
00385         CONN_DISCONNECTING,     /* means the connection will be closed once the send queue drains */
00386         CONN_DISCONNECTED,      /* socket does not send/recv & has no
00387                                  * datagrams allocated : error to
00388                                  * recv/send on this socket */
00389         CONN_ERR                /* socket with an error- connection
00390                                  * must be killed without any sending
00391                                  * or receiving (for now immediate,
00392                                  * later with timeout?) */
00393 } sock_state;
00394 
00395 typedef enum sock_opt {
00396         VFERSO_QTTL             = 1,
00397         VFERSO_SNDSIZE          = 3,
00398         VFERSO_RELFUN           = 5,
00399 
00400         VFERSO_CONNECTTIMEOUT   = 6,
00401         VFERSO_CLOSETIMEOUT     = 7,
00402         VFERSO_ACCEPTTIMEOUT    = 9,
00403         VFERSO_SNDTIMEOUT       = 10,
00404         VFERSO_RCVTIMEOUT       = 11,
00405 
00406         /* these have to be powers of 2 as they will be incoded as
00407          * bits into an int (vfer_sock.opts) */
00408         VFERSO_NOPMTUD          = 2,
00409         VFERSO_NONBLOCK         = 4,
00410         /* this option is client read-only */
00411         VFERSO_CLIENT_SOCK      = 8, /* indicates that this sock is a client socket that 'connected' rather than being 'accepted' */
00412 } sock_opt;
00413 
00414 /**
00415 *@brief Structure holding values related to path MTU discovery
00416 */
00417 typedef struct path_mtu {
00418         char probe_state;       /* 0 = no probe sent, 1 = probe_sent, 2 = MTU found, 3 = NO PMTUD */
00419         int common_mtus[COMMON_MTU_MAX_INDEX + 1]; /* List of common mtus to use as search space */
00420         int* search_high;       /* During search, maximum possible value for path mtu */
00421         int* search_low;        /* During search, minimum possible value for path mtu */
00422         int* probe_size;        /* Size of the current probe sent or that will be sent */
00423         uint32_t frame_num;     /* Number of frame containing path MTU probe */
00424         uint32_t data_offset;   /* Offset of probe packet in frame */
00425         time_t next_probe_time; /* Time at which the next probe will be conducted */
00426 } path_mtu;
00427 
00428 /**
00429  * @brief vfer socket structure holding everything associated with a single vfer connection
00430  */
00431 typedef struct vfer_sock {
00432         int fd;                 /* file descriptor for the socket after we are connected or for a server that is listening*/
00433         int icmp_fd;            /* file descriptor to listen for ICMP messages used in PMTU discovery*/
00434         int type;               /* SOCK_STREAM or SOCK_DGRAM */
00435         sock_state state;       /* state of the socket */
00436         int opts;               /* options turned ON\OFF for this socket */
00437         int err;                /* error for this socket */
00438         struct sockaddr_in addr;/* remote address this socket is connected */
00439         socklen_t addr_len;     /* length of addr field */
00440         vfer_stats stats;       /* stats for this socket */
00441         uint32_t l_seq;         /* last local seq number + 1 */
00442         uint16_t l_frame_num;   /* last local frame number */
00443         uint32_t r_seq;         /* last remote seq number + 1 */
00444         uint16_t r_frame_num;   /* last remote frame number */
00445         uint32_t r_opts;                /* remote opts */
00446         uint32_t r_recv_buf_size;       /* remote receive buffer size in packets */
00447         uint32_t r_send_buf_size;       /* remote send buffer size in packets */
00448         uint32_t r_max_frame_size;      /* remote max frame size in bytes */
00449         relfun_t relfun;                /* reliability function to use */
00450 
00451         int select_active;              /* 1(active): implies that ControlT should check select_mark and set result_mark & signal necessary condition var if a condition is satisfied, 0: ignore mark */
00452         sock_mark_t select_mark;        /* mark for vfer_select to test for */
00453         sock_mark_t select_result;      /* resultant mark to be read from after vfer_select() is done */
00454         pthread_mutex_t mutx_readable;
00455         pthread_cond_t cond_readable;
00456         pthread_mutex_t mutx_writeable;
00457         pthread_cond_t cond_writeable;
00458 
00459         pthread_mutex_t mutex;          /* access mutex */
00460         pthread_cond_t cond;            /* used for signaling closure/connection ready to be accepted/connection (ie. CONNECTED state) all set in ControlT main thread loop */
00461         uint32_t udp_send_buf_size;     /* flow control */
00462         uint32_t udp_recv_buf_size;     /* flow control */
00463 
00464         ccontrol_t ccontrol;            /* congestion control structure containing all the necessary information to form ccacks and control sending window */
00465 
00466         frame_list send_frames;         /* frames we are sending */
00467         frame_list recv_frames;         /* frames we are receiving */
00468         frame_list recvd_frames;        /* frames that are completed and ready to be received by the application
00469                                          * note that this frame_list does not use the last_frame_num and first_frame_num vars of the frame list struct */
00470                                          
00471         path_mtu pmtu;                  /* path mtu search values */
00472         char is_df_set;                 /* boolean switch to indicate if DF bit set in IP header */
00473 
00474         /* time outs (set/read via vfer_setsockopt/getsockopt) */
00475         int connect_timeout;            /* microseconds ; timeout for vfer_accept() call */
00476         int close_timeout;              /* microseconds ; timeout for vfer_close() call */
00477         int accept_timeout;             /* microseconds ; timeout for vfer_accept() call */
00478         int snd_timeout;                /* microseconds ; timeout for vfer_send() call */
00479         int rcv_timeout;                /* microseconds ; timeout for vfer_recv() call */
00480 
00481         int backlog;                            /* number of incoming connection to keep in the backlog */
00482         struct accept_queue* accept_queue;      /* backlog of connections size specified by vfer_listen() */
00483         int connect_tries;                      /* counter of number of connect tries attempted on this socket */
00484         int response_tries;                     /* number of times that we've sent a response try on this socket (accepting socket)  */
00485         struct timeval last_request;            /* timestamp of last request packet sent on this socket */
00486         struct timeval last_response;           /* timestamp of last response packet sent on this socket */
00487         struct packet* request;                 /* cached request packet */
00488         struct packet* response;                /* cached response packet */
00489         struct vfer_sock* listening_sock;       /* the sock from which we will grab a connection if we are in CONN_ACCEPTING state */
00490         struct queued_conn* qc;                 /* queued connection which we are currently trying to connect with */
00491         struct sockaddr_in sa;                  /* used to specify new bound addr on a socket that is in conn_accepting state */
00492 } vfer_sock;
00493 
00494 
00495 #define MAX_SOCKETS 64
00496 /**
00497  * @brief a sockets array with a protecting mutex, underlying fd sets, and more.
00498  */
00499 typedef struct vfer_socks {
00500         pthread_mutex_t mutex;          /* access to all variables except for the socks array is controlled by this mutex */
00501         int num_active;                 /* number of active sockets in the list */
00502         fd_set fds;                     /* fds that are currently active */
00503         int max_fd;                     /* number of fds in the fds set */
00504         vfer_sock s[MAX_SOCKETS];       /* static vfer sockets array */
00505         pthread_mutex_t select_mutex;   /* used to control access to select_cond */
00506         pthread_cond_t select_cond;     /* condition var used by vfer_select to wait for event notification from ControlT thread */
00507 } vfer_socks_t;
00508 
00509 typedef int vfer_fd;
00510 
00511 /*
00512  * variables
00513  */
00514 
00515 vfer_socks_t sockets;   /* all VFER sockets, vfer_fd_t used to index into this array */
00516 long int ReqMem;        /* memory allocated in bytes */
00517 
00518 #endif /* VFER_H */

Generated on Tue Aug 8 16:07:17 2006 for VFER by  doxygen 1.4.7