| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | #ifndef vic_tfwc_sndr_h |
|---|
| 35 | #define vic_tfwc_sndr_h |
|---|
| 36 | |
|---|
| 37 | #include "bitmap.h" // bitmap operations |
|---|
| 38 | #include "cc_timer.h" |
|---|
| 39 | |
|---|
| 40 | #define DUPACKS 3 // simulating TCP's 3 dupacks |
|---|
| 41 | #define TSZ 1000 // tsvec_ size |
|---|
| 42 | #define SSZ 1000 // seqvec_ size |
|---|
| 43 | #define RSZ 1000 // refvec_ size |
|---|
| 44 | #define RECORD 10000 |
|---|
| 45 | |
|---|
| 46 | #define SHORT_HISTORY // history size = 8 |
|---|
| 47 | #ifdef SHORT_HISTORY |
|---|
| 48 | #define HSZ 8 // history size for avg loss history |
|---|
| 49 | #else |
|---|
| 50 | #define HSZ 16 // history size for avg loss history |
|---|
| 51 | #endif |
|---|
| 52 | |
|---|
| 53 | #define T_RTTVAR_BITS 2 |
|---|
| 54 | #define T_SRTT_BITS 3 |
|---|
| 55 | |
|---|
| 56 | #define BITLEN 16 |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | #define TFWC_TIMER_RTX 0 |
|---|
| 60 | #define TFWC_TIMER_RESET 1 |
|---|
| 61 | |
|---|
| 62 | class TfwcSndr; |
|---|
| 63 | class Transmitter; |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | class TfwcRtxTimer : public CcTimerHandler { |
|---|
| 67 | public: |
|---|
| 68 | TfwcRtxTimer(TfwcSndr *s) : CcTimerHandler() { s_ = s;} |
|---|
| 69 | virtual void timeout(); |
|---|
| 70 | |
|---|
| 71 | protected: |
|---|
| 72 | TfwcSndr *s_; |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | class TfwcSndr { |
|---|
| 77 | public: |
|---|
| 78 | |
|---|
| 79 | TfwcSndr(); |
|---|
| 80 | virtual ~TfwcSndr() {}; |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | virtual void cc_tfwc_output(bool recv_by_ch=0) = 0; |
|---|
| 84 | virtual void cc_tfwc_output(pktbuf*) = 0; |
|---|
| 85 | virtual void cc_tfwc_trigger(pktbuf* pb=0) = 0; |
|---|
| 86 | virtual double tx_ts_offset() = 0; |
|---|
| 87 | virtual int tx_buf_size() = 0; |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | void tfwc_sndr_send(pktbuf*, double); |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | void tfwc_sndr_recv(u_int16_t type, u_int16_t begin, u_int16_t end, |
|---|
| 94 | u_int16_t *chunk, double so_rtime, bool recv_by_ch, pktbuf* pb); |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | inline u_int16_t tfwc_sndr_get_aoa() { return aoa_; } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | inline u_int16_t tfwc_sndr_jacked() { return jacked_; } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | inline u_int32_t tfwc_magic() { return cwnd_; }; |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | inline double tfwc_sndr_now() { |
|---|
| 107 | timeval tv; |
|---|
| 108 | ::gettimeofday(&tv, NULL); |
|---|
| 109 | return ((double) tv.tv_sec + 1e-6 * (double) tv.tv_usec); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | inline double now() { return (tfwc_sndr_now()-ts_off_); } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | u_int16_t seqno_; |
|---|
| 117 | u_int32_t cwnd_; |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | void expire(int option); |
|---|
| 121 | |
|---|
| 122 | protected: |
|---|
| 123 | |
|---|
| 124 | void gen_seqvec(u_int16_t *v, int n); |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | void gen_refvec(int end, int begin); |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | void reset_var(bool reverted); |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | inline u_int16_t get_head_pos(u_int16_t ackvec) { |
|---|
| 134 | int l; |
|---|
| 135 | for (l = 0; l < BITLEN; l++) { |
|---|
| 136 | if(GET_HEAD_VEC(ackvec, l)) break; |
|---|
| 137 | } |
|---|
| 138 | return (BITLEN - l); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | inline u_int16_t get_tail_pos(u_int16_t ackvec) { |
|---|
| 142 | int l; |
|---|
| 143 | for (l = 0; l < BITLEN; l++) { |
|---|
| 144 | if(GET_TAIL_VEC(ackvec, l)) break; |
|---|
| 145 | } |
|---|
| 146 | return (l + 1); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | inline void marginvec(u_int16_t hseq) { |
|---|
| 150 | for (int i = 0; i < DUPACKS; i++) |
|---|
| 151 | |
|---|
| 152 | mvec_[i] = ((hseq - i) < 0) ? 0 : (hseq - i); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | inline u_int16_t ackofack () { |
|---|
| 156 | return ((mvec_[DUPACKS - 1] - 1) <= 0) ? |
|---|
| 157 | 0 : (u_int16_t) (mvec_[DUPACKS - 1] - 1); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | TfwcRtxTimer rtx_timer_; |
|---|
| 162 | void set_rtx_timer(); |
|---|
| 163 | void reset_rtx_timer(int backoff); |
|---|
| 164 | void backoff_timer(); |
|---|
| 165 | |
|---|
| 166 | int mvec_[DUPACKS]; |
|---|
| 167 | u_int16_t *ackv_; |
|---|
| 168 | u_int16_t *pvec_; |
|---|
| 169 | u_int16_t aoa_; |
|---|
| 170 | double ts_; |
|---|
| 171 | double ts_echo_; |
|---|
| 172 | double now_; |
|---|
| 173 | double so_recv_; |
|---|
| 174 | double tao_; |
|---|
| 175 | double prev_ts_; |
|---|
| 176 | |
|---|
| 177 | private: |
|---|
| 178 | |
|---|
| 179 | void update_rtt(double tao); |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | void tcp_like_increase(); |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | bool detect_loss(); |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | void window_in_packets(bool revert); |
|---|
| 191 | void cwnd_in_packets(bool revert); |
|---|
| 192 | |
|---|
| 193 | void cwnd_in_bytes(); |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | void avg_loss_interval(); |
|---|
| 197 | void print_history_item (int); |
|---|
| 198 | void print_history_item (int, int); |
|---|
| 199 | bool revert_interval(int reseq); |
|---|
| 200 | void record_history(int seqno, double interval, double ts); |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | void loss_history(); |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | double pseudo_p(int cwnd); |
|---|
| 207 | void pseudo_history(double p); |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | void gen_weight(); |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | void dupack_action(int seqno); |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | void new_rto(double rtt); |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | bool out_of_ack (u_int16_t, u_int32_t*, int); |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | void packet_clocking (pktbuf* pb, bool flag); |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | inline void clone_ackv(u_int16_t *c, int n) { |
|---|
| 226 | for (int i = 0; i < n; i++) |
|---|
| 227 | ackv_[i] = ntohs(c[i]); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | inline void copy_ackv(int n) { |
|---|
| 232 | for(int i = 0; i < n; i++) |
|---|
| 233 | pvec_[i] = ackv_[i]; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | inline void clear_tsv (int n) { |
|---|
| 238 | for (int i = 0; i < n; i++) |
|---|
| 239 | tsvec_[i] = 0; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | inline void clear_sqv (int n) { |
|---|
| 244 | for (int i = 0; i < n; i++) |
|---|
| 245 | seqvec_[i] = 0; |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | inline void clear_ackv (int n) { |
|---|
| 250 | for (int i = 0; i < n; i++) |
|---|
| 251 | ackv_[i] = 0; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | inline void clear_pvec (int n) { |
|---|
| 256 | for (int i = 0; i < n; i++) |
|---|
| 257 | pvec_[i] = 0; |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | inline void clear_refv (int n) { |
|---|
| 262 | for (int i = 0; i < n; i++) |
|---|
| 263 | refvec_[i] = 0; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | inline void clear_record (int n) { |
|---|
| 268 | for (int i = 0; i < n; i++) |
|---|
| 269 | record_[i] = 0; |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | inline void clear_prev_interval (int n) { |
|---|
| 274 | for (int i = 0; i < n; i++) |
|---|
| 275 | prev_interval_[i] = 0; |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | inline void clear_new_hist_seqno (int n) { |
|---|
| 280 | for (int i = 0; i < n; i++) |
|---|
| 281 | new_hist_seqno_[i] = 0; |
|---|
| 282 | new_hist_seqno_size_ = 0; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | inline int get_numvec(int n) { |
|---|
| 287 | return (n/BITLEN + (n%BITLEN > 0)); |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | inline int get_numelm (int begin, int end) { |
|---|
| 292 | return (end - begin + 1); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | inline void replace (u_int16_t highest) { |
|---|
| 297 | jacked_ = highest; |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | inline void store (u_int16_t highest) { |
|---|
| 302 | __jacked_ = highest; |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | bool find_seqno(u_int16_t *v, int n, int target); |
|---|
| 307 | bool find_seqno(u_int32_t *v, int n, u_int32_t target); |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | inline void print_cwnd() { |
|---|
| 311 | fprintf(stderr, "\tnow: %f\tcwnd: %d\n", so_recv_, cwnd_); |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | inline void print_xr_info(const char* str, const int i) { |
|---|
| 316 | fprintf(stderr, |
|---|
| 317 | " [%s +%d] begins: %d ends: %d jacked: %d\n", |
|---|
| 318 | str, i, begins_, ends_, jacked_); |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | inline void print_rtt_info() { |
|---|
| 323 | fprintf(stderr, |
|---|
| 324 | "\t>> now_: %f tsvec_[%d]: %f rtt: %f srtt: %f\n", |
|---|
| 325 | so_recv_, jacked_%TSZ, tsvec_[jacked_%TSZ], tao_, srtt_); |
|---|
| 326 | } |
|---|
| 327 | inline void print_rtt_info(const char* str) { |
|---|
| 328 | fprintf(stderr, |
|---|
| 329 | "\t%s now_: %f tsvec_[%d]: %f rtt: %f srtt: %f\n", |
|---|
| 330 | str, so_recv_, jacked_%TSZ, tsvec_[jacked_%TSZ], tao_, srtt_); |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | inline void print_ALI() { |
|---|
| 335 | fprintf(stderr, "\tnow: %f\tALI: %f\n\n", so_recv_, avg_interval_); |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | inline void print_packet_tsvec() { |
|---|
| 340 | fprintf(stderr, "\t>> now: %f tsvec_[%d]: %f\n", |
|---|
| 341 | now_, seqno_%TSZ, tsvec_[seqno_%TSZ]); |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | inline void print_mvec() { |
|---|
| 346 | fprintf(stderr, "\tmargin numbers: ( %d %d %d )\n", |
|---|
| 347 | mvec_[0], mvec_[1], mvec_[2]); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | inline void print_vec(const char* str, u_int32_t *vec, int c) { |
|---|
| 351 | fprintf(stderr, "\t%s: (", str); |
|---|
| 352 | for (int i = 0; i < c; i++) |
|---|
| 353 | fprintf(stderr, " %d", vec[i]); |
|---|
| 354 | fprintf(stderr, " )\n"); |
|---|
| 355 | } |
|---|
| 356 | inline void print_vec(const char* str, u_int16_t *vec, int c) { |
|---|
| 357 | fprintf(stderr, "\t%s: (", str); |
|---|
| 358 | for (int i = 0; i < c; i++) |
|---|
| 359 | fprintf(stderr, " %d", vec[i]); |
|---|
| 360 | fprintf(stderr, " )\n"); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | int ndtp_; |
|---|
| 364 | int nakp_; |
|---|
| 365 | int ntep_; |
|---|
| 366 | int nsve_; |
|---|
| 367 | |
|---|
| 368 | double ts_off_; |
|---|
| 369 | |
|---|
| 370 | u_int32_t *seqvec_; |
|---|
| 371 | int num_seqvec_; |
|---|
| 372 | u_int32_t *refvec_; |
|---|
| 373 | int num_refvec_; |
|---|
| 374 | double *tsvec_; |
|---|
| 375 | u_int16_t jacked_; |
|---|
| 376 | bool is_first_loss_seen_; |
|---|
| 377 | bool is_tfwc_on_; |
|---|
| 378 | int num_missing_; |
|---|
| 379 | double f_p_; |
|---|
| 380 | double p_; |
|---|
| 381 | double t_win_; |
|---|
| 382 | double avg_interval_; |
|---|
| 383 | int history_[HSZ+1]; |
|---|
| 384 | int prev_history_[HSZ]; |
|---|
| 385 | double weight_[HSZ+1]; |
|---|
| 386 | double I_tot_; |
|---|
| 387 | double I_tot0_; |
|---|
| 388 | double I_tot1_; |
|---|
| 389 | double tot_weight_; |
|---|
| 390 | int hsz_; |
|---|
| 391 | bool to_driven_; |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | double srtt_; |
|---|
| 395 | double rttvar_; |
|---|
| 396 | double rto_; |
|---|
| 397 | double minrto_; |
|---|
| 398 | double maxrto_; |
|---|
| 399 | double df_; |
|---|
| 400 | double sqrtrtt_; |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | int first_lost_pkt_; |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | u_int16_t begins_; |
|---|
| 407 | u_int16_t ends_; |
|---|
| 408 | int num_elm_; |
|---|
| 409 | int num_vec_; |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | double alpha_; |
|---|
| 413 | double beta_; |
|---|
| 414 | double g_; |
|---|
| 415 | int k_; |
|---|
| 416 | int t_rtt_; |
|---|
| 417 | int t_rttvar_; |
|---|
| 418 | int t_srtt_; |
|---|
| 419 | int srtt_init_; |
|---|
| 420 | int rttvar_init_; |
|---|
| 421 | int rttvar_exp_; |
|---|
| 422 | double t0_; |
|---|
| 423 | double tcp_tick_; |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | bool reorder_; |
|---|
| 427 | |
|---|
| 428 | u_int16_t __jacked_; |
|---|
| 429 | double *prev_interval_; |
|---|
| 430 | u_int16_t *new_hist_seqno_; |
|---|
| 431 | int new_hist_seqno_size_; |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | u_int16_t *record_; |
|---|
| 435 | }; |
|---|
| 436 | |
|---|
| 437 | #endif |
|---|