src/vfer_rcp.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  * @file   vfer_rcp.h
00008  * @author Ivan Beschastnikh
00009  * @brief  Header file of common structures and globals defs for use by vfer_rcp.c and vfer_rcpd.c
00010  *
00011  * This file is the only file included by vfer_rcpd.c and
00012  * vfer_rcp.c. It contains the structures, defs and other include
00013  * files for the rcp daemon and client.
00014  *
00015  * -     04/30/06        ivan            made server msg into a structure, added file_size to both client and server msgs
00016  * -     04/12/06        ivan            Added vfer_rcp_print_stats()
00017  * -     02/18/06        ivan            Changed name to vfer_rcp.h, added signal.h include
00018  * -     02/16/06        ivan            Header created
00019  */
00020 
00021 #ifndef TEST_RCP_H
00022 #define TEST_RCP_H
00023 
00024 #include <netdb.h>
00025 #include <sys/select.h>
00026 #include <sys/stat.h>
00027 #include <fcntl.h>
00028 #include <getopt.h>
00029 #include <strings.h>
00030 #include <pwd.h>
00031 #include <sys/stat.h>
00032 #include <signal.h>
00033 #include <dirent.h>
00034 
00035 #include "vfer_tests.h"
00036 #include "vfer_api.h"
00037 
00038 inline void vfer_rcp_print_stats(vfer_stats* stats);
00039 
00040 /* constants controlling the max buffer sizes for paths, usernames, etc */
00041 #define MAX_PATH        128
00042 #define MAX_USER        16
00043 #define MAX_HOST        64
00044 #define DEFAULT_PORT    2046
00045 
00046 /**
00047  * @brief structure used as a client message from the client rcp program
00048  */
00049 typedef struct client_msg {
00050         char local_name [MAX_PATH];     /* filename of the file on the local system */
00051         char remote_path[MAX_PATH];     /* path on the remote host specified on the cmd line */
00052         char user       [MAX_USER];     /* user name to authenticate */
00053         char from_remote;               /* 0: yes (get remote file to local sys), 1: no (put local file to remote sys)*/
00054         uint32_t file_size;             /* file size to transfer if from_remote = 1, ow. set to 0 */
00055 } client_msg_t;
00056 
00057 typedef enum status_t {RCP_READY=0,     /* success, ready/OK */
00058                        RCP_ENOENT,      /* error, component of the path does not exist, or the path is an empty string */
00059                        RCP_EOPEN,       /* error, can't open file for reading or writing */
00060                        RCP_ENOFILE,     /* error, file doesn't exist (if from_remote==0) */
00061                        RCP_EUSER,       /* error, user name does not match for authentication purposes */
00062                        RCP_EOTHER       /* error, some other error occured */
00063 } status_t;
00064 
00065 /**
00066  * @brief structure used as a server message reply from the server rcpd program to the client msg
00067  */
00068 typedef struct server_msg {
00069         uint32_t status;                /* status of the server rcpd proccess (actually of status_t type) */
00070         uint32_t file_size;             /* file size the client should expect (if from_remote set to 0 in client msg (see above)) */
00071 } server_msg_t;
00072 
00073 /**
00074  * This function prints the final transfer statistics after file transfer
00075  *
00076  * @param stats vfer stats structure pointer
00077  */
00078 inline void vfer_rcp_print_stats(vfer_stats* stats) {
00079         double duration;        /* in seconds */
00080         struct timeval tv_end;
00081         uint32_t data_retransmitted;
00082         
00083         if (stats->tv_end.tv_sec == 0 && stats->tv_end.tv_usec == 0) {
00084                 GET_TIME_OF_DAY(&(tv_end));
00085                 printf("-- real time stats --\n");
00086         } else {
00087                 bcopy(&(stats->tv_end), &(tv_end), sizeof(struct timeval));
00088         }
00089 
00090         /* printf("start: %d %d\n", (int)stats->tv_start.tv_sec, (int)stats->tv_start.tv_usec);
00091            printf("end: %d %d\n", (int)tv_end.tv_sec, (int)tv_end.tv_usec);  */
00092         
00093         duration = (tv_end.tv_sec - stats->tv_start.tv_sec);
00094         duration += 0.000000001 * (tv_end.tv_usec - stats->tv_start.tv_usec);
00095         /* retransmit traffic (data payload only) in bytes */
00096         data_retransmitted = (stats->data_bytes_sent - stats->data_bytes_sender_sent);
00097         
00098         printf("\n");
00099         printf("VFER transfer statistics:\n");
00100         printf("\n");
00101         printf("Duration      (s)       conn    %f\n", duration);
00102         printf("Avg rate      (Mb/s)    sending %-16.2f recving %.2f\n", ((stats->bytes_sent * 8.0) / (duration * 1000000)), ((stats->bytes_recvd * 8.0) / (duration * 1000000)));
00103         printf("Total         (packets) sent    %-14u   recvd   %u\n", stats->packets_sent, stats->packets_recvd);
00104         printf("Total         (bytes)   sent    %-14u   recvd   %u\n", stats->bytes_sent, stats->bytes_recvd);
00105         printf("Total data    (bytes)   sent    %-14u   recvd   %-16u retrans      %u\n", stats->data_bytes_sent, stats->data_bytes_recvd, data_retransmitted);
00106         printf("Avg data rate (Mb/s)    sending %-16.2f recving %-16.2f eff. sending %.2f\n",
00107                ((stats->data_bytes_sent * 8.0) / (duration * 1000000)),
00108                ((stats->data_bytes_recvd * 8.0) / (duration * 1000000)),
00109                (((stats->data_bytes_sent - data_retransmitted) * 8.0) / (duration * 1000000)));
00110         printf("RTT           (us)      avg     %-16.2f max     %-16.2f min          %.2f\n", stats->avg_rtt, (double)(stats->max_rtt), (double)(stats->min_rtt));
00111         printf("\n");
00112 } /* vfer_rcp_print_stats() */
00113 
00114 
00115 #endif /* TEST_RCP_H */

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