src/vfer_packet.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_packet.h
00009  * @author Ivan Beschastnikh
00010  * @brief  Defines packet structures for the protocol.
00011  *
00012  * Supports packet.c and defines structures used by c_control.c. 
00013  *
00014  * -     07/26/06        ivan            removed vector ack packet type declarations and related functions
00015  * -     09/01/05        ivan            created new packet structures
00016  * -     05/18/05        ivan            created
00017  */
00018 
00019 #ifndef VFER_PACKET_H
00020 #define VFER_PACKET_H
00021 
00022 #include <limits.h>
00023 #include <netinet/in.h>
00024 #include <sys/uio.h>            /* writev */
00025 
00026 #include "vfer_datagram.h"
00027 #include "vfer.h"
00028 
00029 /* all lengths are in bytes */
00030 /* top most (generic) header for VFer */
00031 #define TOPH_LENGTH             16 /* includes an 8 byte timestamp  */
00032 
00033 /* packet specific header lengths not including generic header: */
00034 #define REQUESTH_LENGTH         14
00035 #define RESPONSEH_LENGTH        20
00036 #define DATAH_LENGTH            10 /* counting the optional frame_len field */
00037 #define CCACKH_LENGTH           22 /* counting the optional frame_len field, but not any of the nack data range related variables */
00038 #define CLOSEH_LENGTH           0
00039 
00040 #define DATAACKH_LENGTH         DATAH_LENGTH + SYNCH_LENGTH /* not counting the optional frame length field */
00041 
00042 /* data and dataack lengths are minimums */
00043 #define REQUEST_LENGTH          REQUESTH_LENGTH + TOPH_LENGTH
00044 #define RESPONSE_LENGTH         RESPONSEH_LENGTH + TOPH_LENGTH
00045 #define DATA_LENGTH             DATAH_LENGTH + TOPH_LENGTH
00046 #define DATAACK_LENGTH          DATAACKH_LENGTH + TOPH_LENGTH
00047 #define CCACK_LENGTH            CCACKH_LENGTH + TOPH_LENGTH
00048 #define CLOSE_LENGTH            CLOSEH_LENGTH + TOPH_LENGTH
00049 
00050 /*
00051  * data structures
00052  */
00053 
00054 /**
00055  * @brief request packet type
00056  */
00057 typedef struct request_pack {
00058         uint32_t max_frame_size;
00059         uint32_t recv_buf_size;
00060         uint32_t send_buf_size;
00061         uint16_t init_frame_num;
00062 } request_pack;
00063 
00064 /**
00065  * @brief response packet type
00066  */
00067 typedef struct response_pack {
00068         uint16_t init_frame_num;
00069         uint16_t connection_port;
00070         uint32_t max_frame_size;
00071         uint32_t recv_buf_size;
00072         uint32_t send_buf_size;
00073         int32_t request_delay;  /* this delay measurement (in microseconds) is used to estimate RTT after the handshake is completed */
00074 } response_pack;
00075 
00076 /**
00077  * @brief data packet type
00078  */
00079 typedef struct data_pack {
00080         uint16_t frame_num;
00081         uint32_t data_offset;
00082         uint32_t frame_len;     /* optional: 0 if not set in the packet ; o.w > 0 */
00083         void*    data;
00084         uint32_t data_len;      /* this is not actually in the packet (its computed and set on reception) */
00085 } data_pack;
00086 
00087 /**
00088  * @brief congestion control ack packet type
00089  */
00090 typedef struct ccack_pack {
00091         uint32_t last_seq;              /* last sequence number that the sender of the ack received */
00092         uint16_t packets_lost;          /* note this field is cumulative: total number of packets lost since beginning of connection */
00093         uint16_t oldest_frame;          /* oldest frame that the sender of the ack is interested in */
00094         uint16_t newest_frame;          /* newest frame that the sender of the ack has seen */
00095         int32_t  delay_delta;           /* current delay delta (current_delay - base_delay) in us for the reverse data path */
00096         int32_t  delay;                 /* current delay (as apposed to base delay) in us for the reverse data path */
00097         uint32_t bytes_total;           /* total number of data bytes recvd for this connection */
00098         /* inherited from vecack_pack structure */
00099         uint16_t intervals_frame_num;
00100         uint32_t interval_count;
00101         uint32_t* raw_intervals;
00102 } ccack_pack;
00103 
00104 /**
00105  * @brief close packet type
00106  */
00107 typedef struct close_pack {
00108 } close_pack;
00109 
00110 /**
00111  * @brief generic vfer packet type
00112  */
00113 typedef struct packet {
00114         unsigned char type;
00115         unsigned char version;
00116         uint32_t opts;
00117         uint32_t seq;
00118         /** seconds receipt timestamp */
00119         uint32_t tv_sec;
00120         /** microseconds receipt timestamp */
00121         uint32_t tv_usec;
00122         /** delay in us for this packet, only defined on the receiver after being processed by packet.c which sets this field */
00123         int32_t delay;
00124         /** contains the raw packet received/sent and the corresponding length[s] */
00125         struct iovec* iov;
00126         int iovlen;
00127         union {
00128                 request_pack    req;
00129                 response_pack   res;
00130                 data_pack       data;
00131                 ccack_pack      ccack;
00132                 close_pack      close;
00133         } u;
00134 } packet;
00135 
00136 /* packet types MUST be multiples of 16 - see packetizing of the
00137  * VFer header in the spec rev. 1.7 and greater, the packet_type
00138  * cannot be more than 240 = (16 * 15) */
00139 typedef enum packet_type {REQUEST       =16,
00140                           RESPONSE      =32,
00141                           DATA          =48,
00142                           CC_ACK        =64,
00143                           DATA_ACK      =96,
00144                           CLOSE         =112} packet_type;
00145 
00146 typedef enum packet_opt {OPT_FRAME_LEN = 1,
00147                          OPT_SYNC = 2,
00148                          OPT_VEC = 4} packet_opt;
00149 
00150 /*
00151  * function prototypes
00152  */
00153 
00154 /* printing functions */
00155 char*   Packet_Str_Type         (packet* p);
00156 char*   Packet_Str              (packet* p);
00157 void    Packet_Print            (packet* p);
00158 
00159 /* packet formation functions */
00160 packet* Packet_Form_Request     (uint32_t opts, uint32_t init_seq_num,
00161                                  uint32_t max_frame_size, uint32_t recv_buf_size,
00162                                  uint32_t send_buf_size, uint16_t init_frame_num);
00163 packet* Packet_Form_Response    (uint32_t opts, uint32_t init_seq_num, uint16_t init_frame_num,
00164                                  uint16_t connection_port, uint32_t max_frame_size, uint32_t recv_buf_size, uint32_t send_buf_size, int32_t request_delay);
00165 packet* Packet_Form_Data        (uint32_t opts, uint32_t seq_num, uint16_t frame_num,
00166                                  uint32_t data_offset, uint32_t frame_len, void* data, int data_len);
00167 packet* Packet_Form_CCAck       (uint32_t opts, uint32_t seq_num, uint32_t last_seq_received,
00168                                  uint16_t packets_lost, uint16_t oldest_frame, uint16_t newest_frame, int32_t delay_delta, int32_t delay, uint32_t bytes_total, uint16_t intervals_frame_num, intervals_t* intervals);
00169 packet* Packet_Form_Close       (uint32_t opts, uint32_t seq_num);
00170 
00171 /* packet translation functions (interpreters) */
00172 int Packet_Translate_Request    (packet* p);
00173 int Packet_Translate_Response   (packet* p);
00174 int Packet_Translate_Data       (packet* p);
00175 int Packet_Translate_CCAck      (packet* p);
00176 int Packet_Translate_Close      (packet* p);
00177 
00178 /* receiver/sender of packets */
00179 int Packet_Read                 (int fd, packet** p, struct sockaddr* addr, socklen_t* addr_len);
00180 int Packet_Read_ICMP    (int icmp_fd, void *pmtu);
00181 int Packet_Write                (packet* p, int fd, struct sockaddr* addr, socklen_t addr_len);
00182 
00183 /* rand frame/seq num generatoes */
00184 inline uint16_t Packet_Gen_FrameNum();
00185 inline uint32_t Packet_Gen_SeqNum();
00186 
00187 /* helpers that need visibility outside the scope of packet.c */
00188 inline void Packet_Set_Seq      (packet* p, uint32_t seq);
00189 
00190 /* variables */
00191 
00192 char pack_buf[65536];           /* 64K UDP packet buffer to read packets from the wire */
00193 
00194 #endif  /* VFER_PACKET_H */

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