00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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>
00025
00026 #include "vfer_datagram.h"
00027 #include "vfer.h"
00028
00029
00030
00031 #define TOPH_LENGTH 16
00032
00033
00034 #define REQUESTH_LENGTH 14
00035 #define RESPONSEH_LENGTH 20
00036 #define DATAH_LENGTH 10
00037 #define CCACKH_LENGTH 22
00038 #define CLOSEH_LENGTH 0
00039
00040 #define DATAACKH_LENGTH DATAH_LENGTH + SYNCH_LENGTH
00041
00042
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
00052
00053
00054
00055
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
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;
00074 } response_pack;
00075
00076
00077
00078
00079 typedef struct data_pack {
00080 uint16_t frame_num;
00081 uint32_t data_offset;
00082 uint32_t frame_len;
00083 void* data;
00084 uint32_t data_len;
00085 } data_pack;
00086
00087
00088
00089
00090 typedef struct ccack_pack {
00091 uint32_t last_seq;
00092 uint16_t packets_lost;
00093 uint16_t oldest_frame;
00094 uint16_t newest_frame;
00095 int32_t delay_delta;
00096 int32_t delay;
00097 uint32_t bytes_total;
00098
00099 uint16_t intervals_frame_num;
00100 uint32_t interval_count;
00101 uint32_t* raw_intervals;
00102 } ccack_pack;
00103
00104
00105
00106
00107 typedef struct close_pack {
00108 } close_pack;
00109
00110
00111
00112
00113 typedef struct packet {
00114 unsigned char type;
00115 unsigned char version;
00116 uint32_t opts;
00117 uint32_t seq;
00118
00119 uint32_t tv_sec;
00120
00121 uint32_t tv_usec;
00122
00123 int32_t delay;
00124
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
00137
00138
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
00152
00153
00154
00155 char* Packet_Str_Type (packet* p);
00156 char* Packet_Str (packet* p);
00157 void Packet_Print (packet* p);
00158
00159
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
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
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
00184 inline uint16_t Packet_Gen_FrameNum();
00185 inline uint32_t Packet_Gen_SeqNum();
00186
00187
00188 inline void Packet_Set_Seq (packet* p, uint32_t seq);
00189
00190
00191
00192 char pack_buf[65536];
00193
00194 #endif