00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef ns_tcp_h
00037 #define ns_tcp_h
00038
00039 #include "agent.h"
00040 #include "packet.h"
00041
00042
00043
00044 struct hdr_tcp {
00045 #define NSA 3
00046 double ts_;
00047 double ts_echo_;
00048
00049 int seqno_;
00050 int reason_;
00051 int sack_area_[NSA+1][2];
00052 int sa_length_;
00053
00054 int ackno_;
00055 int hlen_;
00056 int tcp_flags_;
00057 int last_rtt_;
00058
00059
00060 static int offset_;
00061 inline static int& offset() { return offset_; }
00062 inline static hdr_tcp* access(Packet* p) {
00063 return (hdr_tcp*) p->access(offset_);
00064 }
00065
00066
00067 double& ts() { return (ts_); }
00068 double& ts_echo() { return (ts_echo_); }
00069 int& seqno() { return (seqno_); }
00070 int& reason() { return (reason_); }
00071 int& sa_left(int n) { return (sack_area_[n][0]); }
00072 int& sa_right(int n) { return (sack_area_[n][1]); }
00073 int& sa_length() { return (sa_length_); }
00074 int& hlen() { return (hlen_); }
00075 int& ackno() { return (ackno_); }
00076 int& flags() { return (tcp_flags_); }
00077 int& last_rtt() { return (last_rtt_); }
00078 };
00079
00080
00081 #define TCP_REASON_TIMEOUT 0x01
00082 #define TCP_REASON_DUPACK 0x02
00083 #define TCP_REASON_RBP 0x03 // used only in tcp-rbp.cc
00084 #define TCP_REASON_PARTIALACK 0x04
00085
00086
00087
00088 #define CWND_ACTION_DUPACK 1 // dup acks/fast retransmit
00089 #define CWND_ACTION_TIMEOUT 2 // retransmission timeout
00090 #define CWND_ACTION_ECN 3 // ECN bit [src quench if supported]
00091
00092
00093
00094 #define CLOSE_SSTHRESH_HALF 0x00000001
00095 #define CLOSE_CWND_HALF 0x00000002
00096 #define CLOSE_CWND_RESTART 0x00000004
00097 #define CLOSE_CWND_INIT 0x00000008
00098 #define CLOSE_CWND_ONE 0x00000010
00099 #define CLOSE_SSTHRESH_HALVE 0x00000020
00100 #define CLOSE_CWND_HALVE 0x00000040
00101 #define THREE_QUARTER_SSTHRESH 0x00000080
00102 #define CLOSE_CWND_HALF_WAY 0x00000100
00103 #define CWND_HALF_WITH_MIN 0x00000200
00104
00105
00106
00107
00108
00109
00110
00111
00112 #define NUMDUPACKS 3
00113
00114 #define TCP_MAXSEQ 1073741824
00115
00116
00117 #define TCP_TIMER_RTX 0
00118 #define TCP_TIMER_DELSND 1
00119 #define TCP_TIMER_BURSTSND 2
00120 #define TCP_TIMER_DELACK 3
00121 #define TCP_TIMER_Q 4
00122 #define TCP_TIMER_RESET 5
00123
00124 class TcpAgent;
00125
00126 class RtxTimer : public TimerHandler {
00127 public:
00128 RtxTimer(TcpAgent *a) : TimerHandler() { a_ = a; }
00129 protected:
00130 virtual void expire(Event *e);
00131 TcpAgent *a_;
00132 };
00133
00134 class DelSndTimer : public TimerHandler {
00135 public:
00136 DelSndTimer(TcpAgent *a) : TimerHandler() { a_ = a; }
00137 protected:
00138 virtual void expire(Event *e);
00139 TcpAgent *a_;
00140 };
00141
00142 class BurstSndTimer : public TimerHandler {
00143 public:
00144 BurstSndTimer(TcpAgent *a) : TimerHandler() { a_ = a; }
00145 protected:
00146 virtual void expire(Event *e);
00147 TcpAgent *a_;
00148 };
00149
00150
00151 class TcpAgent : public Agent {
00152 public:
00153 TcpAgent();
00154 virtual void recv(Packet*, Handler*);
00155 virtual void timeout(int tno);
00156 virtual void timeout_nonrtx(int tno);
00157 int command(int argc, const char*const* argv);
00158 virtual void sendmsg(int nbytes, const char *flags = 0);
00159
00160 void trace(TracedVar* v);
00161 virtual void advanceby(int delta);
00162 protected:
00163 virtual int window();
00164 virtual double windowd();
00165 void print_if_needed(double memb_time);
00166 void traceAll();
00167 virtual void traceVar(TracedVar* v);
00168 virtual int headersize();
00169
00170 virtual void delay_bind_init_all();
00171 virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00172
00173
00174
00175
00176
00177
00178 TracedInt t_seqno_;
00179 #define T_RTT_BITS 0
00180 TracedInt t_rtt_;
00181 int T_SRTT_BITS;
00182 TracedInt t_srtt_;
00183 int srtt_init_;
00184 int T_RTTVAR_BITS;
00185 int rttvar_exp_;
00186 TracedInt t_rttvar_;
00187 int rttvar_init_;
00188 double t_rtxcur_;
00189 double rtxcur_init_;
00190 TracedInt t_backoff_;
00191 virtual void rtt_init();
00192 virtual double rtt_timeout();
00193 virtual void rtt_update(double tao);
00194 virtual void rtt_backoff();
00195
00196 double ts_peer_;
00197
00198
00199 virtual void output(int seqno, int reason = 0);
00200 virtual void send_much(int force, int reason, int maxburst = 0);
00201 virtual void newtimer(Packet*);
00202 virtual void dupack_action();
00203 virtual void send_one();
00204 double linear(double x, double x_1, double y_1, double x_2, double y_2);
00205
00206 void opencwnd();
00207
00208 void slowdown(int how);
00209 void ecn(int seqno);
00210 virtual void set_initial_window();
00211 double initial_window();
00212 void reset();
00213 void newack(Packet*);
00214 void tcp_eln(Packet *pkt);
00215 void finish();
00216 void reset_qoption();
00217 void rtt_counting();
00218 int network_limited();
00219 double limited_slow_start(double cwnd, double max_ssthresh, double increment);
00220
00221 virtual int numdupacks(double cwnd);
00222 virtual void processQuickStart(Packet *pkt);
00223 virtual void endQuickStart();
00224
00225
00226 virtual void output_helper(Packet*) { return; }
00227 virtual void send_helper(int) { return; }
00228 virtual void send_idle_helper() { return; }
00229 virtual void recv_helper(Packet*) { return; }
00230 virtual void recv_newack_helper(Packet*);
00231 virtual void partialnewack_helper(Packet*) {};
00232
00233
00234 RtxTimer rtx_timer_;
00235 DelSndTimer delsnd_timer_;
00236 BurstSndTimer burstsnd_timer_;
00237 virtual void cancel_timers() {
00238 rtx_timer_.force_cancel();
00239 burstsnd_timer_.force_cancel();
00240 delsnd_timer_.force_cancel();
00241 }
00242 virtual void cancel_rtx_timer() {
00243 rtx_timer_.force_cancel();
00244 }
00245 virtual void set_rtx_timer();
00246 void reset_rtx_timer(int mild, int backoff = 1);
00247 int timerfix_;
00248
00249 int rfc2988_;
00250 double boot_time_;
00251 double overhead_;
00252 double wnd_;
00253 double wnd_const_;
00254 double wnd_th_;
00255 double wnd_init_;
00256 double wnd_restart_;
00257 double tcp_tick_;
00258 int wnd_option_;
00259 int wnd_init_option_;
00260
00261 double decrease_num_;
00262 double increase_num_;
00263 double k_parameter_;
00264 double l_parameter_;
00265 int precision_reduce_;
00266 int syn_;
00267 int delay_growth_;
00268 int tcpip_base_hdr_size_;
00269 int ts_option_size_;
00270 int bug_fix_;
00271 int less_careful_;
00272
00273 int ts_option_;
00274 int maxburst_;
00275 int maxcwnd_;
00276 int numdupacks_;
00277 int numdupacksFrac_;
00278
00279 double maxrto_;
00280 double minrto_;
00281 int old_ecn_;
00282
00283
00284
00285 FILE *plotfile_;
00286
00287
00288
00289 TracedInt dupacks_;
00290 TracedInt curseq_;
00291 int last_ack_;
00292
00293 TracedInt highest_ack_;
00294 int recover_;
00295
00296 int last_cwnd_action_;
00297 TracedDouble cwnd_;
00298 double base_cwnd_;
00299 double awnd_;
00300 TracedInt ssthresh_;
00301 int count_;
00302 double fcnt_;
00303 int rtt_active_;
00304 int rtt_seq_;
00305 double rtt_ts_;
00306 TracedInt maxseq_;
00307
00308 int ecn_;
00309 int cong_action_;
00310
00311 int ecn_burst_;
00312
00313 int ecn_backoff_;
00314
00315 int ect_;
00316 int eln_;
00317 int eln_rxmit_thresh_;
00318 int eln_last_rxmit_;
00319 double firstsent_;
00320 double lastreset_;
00321
00322 int slow_start_restart_;
00323
00324 int restart_bugfix_;
00325
00326
00327
00328 int closed_;
00329 TracedInt ndatapack_;
00330 TracedInt ndatabytes_;
00331 TracedInt nackpack_;
00332 TracedInt nrexmit_;
00333
00334 TracedInt nrexmitpack_;
00335 TracedInt nrexmitbytes_;
00336 TracedInt necnresponses_;
00337
00338 TracedInt ncwndcuts_;
00339
00340 int trace_all_oneline_;
00341 int nam_tracevar_;
00342
00343 int first_decrease_;
00344
00345 TracedInt singledup_;
00346 int noFastRetrans_;
00347 int oldCode_;
00348 int useHeaders_;
00349
00350
00351
00352 int low_window_;
00353 int high_window_;
00354 double high_p_;
00355 double high_decrease_;
00356
00357 int max_ssthresh_;
00358
00359
00360 double increase_param();
00361 double decrease_param();
00362 double compute_p();
00363
00364
00365
00366 double cwnd_last_;
00367 double increase_last_;
00368 double cwnd_frac_;
00369
00370
00371
00372 int rate_request_;
00373 int qs_enabled_;
00374 int qs_requested_;
00375 int qs_approved_;
00376 int ttl_diff_;
00377
00378
00379
00380
00381 void trace_event(char *eventtype);
00382
00383
00384 void closecwnd(int how);
00385 void quench(int how);
00386
00387 void process_qoption_after_send() ;
00388 void process_qoption_after_ack(int seqno) ;
00389
00390 int QOption_ ;
00391 int EnblRTTCtr_ ;
00392 int T_full ;
00393 int T_last ;
00394 int T_prev ;
00395 int T_start ;
00396 int RTT_count ;
00397 int RTT_prev ;
00398 int RTT_goodcount ;
00399 int F_counting ;
00400 int W_used ;
00401 int W_timed ;
00402 int F_full ;
00403 int Backoffs ;
00404
00405 int control_increase_ ;
00406
00407 int prev_highest_ack_ ;
00408
00409 };
00410
00411
00412 class RenoTcpAgent : public virtual TcpAgent {
00413 public:
00414 RenoTcpAgent();
00415 virtual int window();
00416 virtual double windowd();
00417 virtual void recv(Packet *pkt, Handler*);
00418 virtual void timeout(int tno);
00419 virtual void dupack_action();
00420 protected:
00421 int allow_fast_retransmit(int last_cwnd_action_);
00422 unsigned int dupwnd_;
00423 };
00424
00425
00426 class NewRenoTcpAgent : public virtual RenoTcpAgent {
00427 public:
00428 NewRenoTcpAgent();
00429 virtual void recv(Packet *pkt, Handler*);
00430 virtual void partialnewack_helper(Packet* pkt);
00431 virtual void dupack_action();
00432 protected:
00433 int newreno_changes_;
00434
00435
00436
00437
00438
00439 int newreno_changes1_;
00440
00441
00442
00443
00444
00445
00446
00447
00448 void partialnewack(Packet *pkt);
00449 int allow_fast_retransmit(int last_cwnd_action_);
00450 int acked_, new_ssthresh_;
00451 double ack2_, ack3_, basertt_;
00452 int firstpartial_;
00453 int partial_window_deflation_;
00454
00455
00456
00457
00458
00459 int exit_recovery_fix_;
00460
00461
00462
00463 };
00464
00465
00466 class VegasTcpAgent : public virtual TcpAgent {
00467 public:
00468 VegasTcpAgent();
00469 ~VegasTcpAgent();
00470 virtual void recv(Packet *pkt, Handler *);
00471 virtual void timeout(int tno);
00472 protected:
00473 double vegastime() {
00474 return(Scheduler::instance().clock() - firstsent_);
00475 }
00476 virtual void output(int seqno, int reason = 0);
00477 virtual void recv_newack_helper(Packet*);
00478 int vegas_expire(Packet*);
00479 void reset();
00480 void vegas_inflate_cwnd(int win, double current_time);
00481
00482 virtual void delay_bind_init_all();
00483 virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00484
00485 double t_cwnd_changed_;
00486 double firstrecv_;
00487
00488 int v_alpha_;
00489 int v_beta_;
00490
00491 int v_gamma_;
00492
00493
00494 int v_slowstart_;
00495 int v_worried_;
00496
00497 double v_timeout_;
00498 double v_rtt_;
00499 double v_sa_;
00500 double v_sd_;
00501
00502 int v_cntRTT_;
00503 double v_sumRTT_;
00504
00505 double v_begtime_;
00506 int v_begseq_;
00507
00508 double* v_sendtime_;
00509 int* v_transmits_;
00510
00511 int v_maxwnd_;
00512 double v_newcwnd_;
00513
00514 double v_baseRTT_;
00515
00516 double v_incr_;
00517 int v_inc_flag_;
00518
00519 double v_actual_;
00520
00521 int ns_vegas_fix_level_;
00522 };
00523
00524
00525
00526
00527
00528 #endif