tcp.h

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ /*
00002  * Copyright (c) 1991-1997 Regents of the University of California.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *  This product includes software developed by the Computer Systems
00016  *  Engineering Group at Lawrence Berkeley Laboratory.
00017  * 4. Neither the name of the University nor of the Laboratory may be used
00018  *    to endorse or promote products derived from this software without
00019  *    specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tcp/tcp.h,v 1.121 2005/06/20 16:30:30 sfloyd Exp $ (LBL)
00034  */
00035 #ifndef ns_tcp_h
00036 #define ns_tcp_h
00037 
00038 #include "agent.h"
00039 #include "packet.h"
00040 
00041 //class EventTrace;
00042 
00043 struct hdr_tcp {
00044 #define NSA 3
00045     double ts_;             /* time packet generated (at source) */
00046     double ts_echo_;        /* the echoed timestamp (originally sent by
00047                                the peer) */
00048     int seqno_;             /* sequence number */
00049     int reason_;            /* reason for a retransmit */
00050     int sack_area_[NSA+1][2];   /* sack blocks: start, end of block */
00051     int sa_length_;         /* Indicate the number of SACKs in this  *
00052                              * packet.  Adds 2+sack_length*8 bytes   */ 
00053     int ackno_;             /* ACK number for FullTcp */
00054     int hlen_;              /* header len (bytes) for FullTcp */
00055     int tcp_flags_;         /* TCP flags for FullTcp */
00056     int last_rtt_;      /* more recent RTT measurement in ms, */
00057                 /*   for statistics only */
00058 
00059     static int offset_; // offset for this header
00060     inline static int& offset() { return offset_; }
00061     inline static hdr_tcp* access(Packet* p) {
00062         return (hdr_tcp*) p->access(offset_);
00063     }
00064 
00065     /* per-field member functions */
00066     double& ts() { return (ts_); }
00067     double& ts_echo() { return (ts_echo_); }
00068     int& seqno() { return (seqno_); }
00069     int& reason() { return (reason_); }
00070     int& sa_left(int n) { return (sack_area_[n][0]); }
00071     int& sa_right(int n) { return (sack_area_[n][1]); }
00072     int& sa_length() { return (sa_length_); }
00073     int& hlen() { return (hlen_); }
00074     int& ackno() { return (ackno_); }  
00075     int& flags() { return (tcp_flags_); }
00076     int& last_rtt() { return (last_rtt_); }
00077 };
00078 
00079 /* these are used to mark packets as to why we xmitted them */
00080 #define TCP_REASON_TIMEOUT  0x01
00081 #define TCP_REASON_DUPACK   0x02
00082 #define TCP_REASON_RBP      0x03   // used only in tcp-rbp.cc
00083 #define TCP_REASON_PARTIALACK   0x04
00084 
00085 /* these are reasons we adjusted our congestion window */
00086 
00087 #define CWND_ACTION_DUPACK  1   // dup acks/fast retransmit
00088 #define CWND_ACTION_TIMEOUT 2   // retransmission timeout
00089 #define CWND_ACTION_ECN     3   // ECN bit [src quench if supported]
00090 #define CWND_ACTION_EXITED      4       // congestion recovery has ended
00091                     // (when previously CWND_ACTION_DUPACK)
00092 
00093 /* these are bits for how to change the cwnd and ssthresh values */
00094 
00095 #define CLOSE_SSTHRESH_HALF 0x00000001
00096 #define CLOSE_CWND_HALF     0x00000002
00097 #define CLOSE_CWND_RESTART  0x00000004
00098 #define CLOSE_CWND_INIT     0x00000008
00099 #define CLOSE_CWND_ONE      0x00000010
00100 #define CLOSE_SSTHRESH_HALVE    0x00000020
00101 #define CLOSE_CWND_HALVE    0x00000040
00102 #define THREE_QUARTER_SSTHRESH  0x00000080
00103 #define CLOSE_CWND_HALF_WAY     0x00000100
00104 #define CWND_HALF_WITH_MIN  0x00000200
00105 #define TCP_IDLE        0x00000400
00106 #define NO_OUTSTANDING_DATA     0x00000800
00107 
00108 /*
00109  * tcp_tick_:
00110  * default 0.1,
00111  * 0.3 for 4.3 BSD, 
00112  * 0.01 for new window algorithms,
00113  */
00114 
00115 #define NUMDUPACKS 3        /* This is no longer used.  The variable */
00116                 /* numdupacks_ is used instead. */
00117 #define TCP_MAXSEQ 1073741824   /* Number that curseq_ is set to for */
00118                 /* "infinite send" (2^30)            */
00119 
00120 #define TCP_TIMER_RTX       0
00121 #define TCP_TIMER_DELSND    1
00122 #define TCP_TIMER_BURSTSND  2
00123 #define TCP_TIMER_DELACK    3
00124 #define TCP_TIMER_Q         4
00125 #define TCP_TIMER_RESET        5 
00126 
00127 class TcpAgent;
00128 
00129 class RtxTimer : public TimerHandler {
00130 public: 
00131     RtxTimer(TcpAgent *a) : TimerHandler() { a_ = a; }
00132 protected:
00133     virtual void expire(Event *e);
00134     TcpAgent *a_;
00135 };
00136 
00137 class DelSndTimer : public TimerHandler {
00138 public: 
00139     DelSndTimer(TcpAgent *a) : TimerHandler() { a_ = a; }
00140 protected:
00141     virtual void expire(Event *e);
00142     TcpAgent *a_;
00143 };
00144 
00145 class BurstSndTimer : public TimerHandler {
00146 public: 
00147     BurstSndTimer(TcpAgent *a) : TimerHandler() { a_ = a; }
00148 protected:
00149     virtual void expire(Event *e);
00150     TcpAgent *a_;
00151 };
00152 
00153 /*
00154  * Variables for HighSpeed TCP.
00155  */
00156 //int *hs_win_;     // array of cwnd values
00157 //int *hs_increase_;    // array of increase values
00158 //double *hs_decrease_; // array of decrease values
00159 struct hstcp {
00160     double low_p;  // low_p
00161     double dec1;    // for computing the decrease parameter
00162     double dec2;    // for computing the decrease parameter
00163     double p1;  // for computing p
00164         double p2;  // for computing p
00165     /* The next three parameters are for CPU overhead, for computing */
00166     /*   the HighSpeed parameters less frequently.  A better solution */
00167     /*   might be just to have a look-up array.  */
00168     double cwnd_last_;  /* last cwnd for computed parameters */
00169         double increase_last_;  /* increase param for cwnd_last_ */
00170     hstcp() : low_p(0.0), dec1(0.0), dec2(0.0), p1(0.0), p2(0.0),
00171         cwnd_last_(0.0), increase_last_(0.0) { }
00172 };
00173 
00174 class TcpAgent : public Agent {
00175 public:
00176     TcpAgent();
00177     ~TcpAgent() {free(tss);}
00178         virtual void recv(Packet*, Handler*);
00179     virtual void timeout(int tno);
00180     virtual void timeout_nonrtx(int tno);
00181     int command(int argc, const char*const* argv);
00182     virtual void sendmsg(int nbytes, const char *flags = 0);
00183 
00184     void trace(TracedVar* v);
00185     virtual void advanceby(int delta);
00186 protected:
00187     virtual int window();
00188     virtual double windowd();
00189     void print_if_needed(double memb_time);
00190     void traceAll();
00191     virtual void traceVar(TracedVar* v);
00192     virtual int headersize();   // a tcp header
00193 
00194     virtual void delay_bind_init_all();
00195     virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00196 
00197     TracedInt t_seqno_; /* sequence number */
00198     /*
00199      * State encompassing the round-trip-time estimate.
00200      * srtt and rttvar are stored as fixed point;
00201      * srtt has 3 bits to the right of the binary point, rttvar has 2.
00202      */
00203     TracedInt t_rtt_;       /* round trip time */
00204     TracedInt t_srtt_;      /* smoothed round-trip time */
00205     TracedInt t_rttvar_;    /* variance in round-trip time */
00206     TracedInt t_backoff_;   /* current multiplier, 1 if not backed off */
00207     #define T_RTT_BITS 0
00208     int T_SRTT_BITS;        /* exponent of weight for updating t_srtt_ */
00209     int srtt_init_;     /* initial value for computing t_srtt_ */
00210     int T_RTTVAR_BITS;      /* exponent of weight for updating t_rttvar_ */ 
00211     int rttvar_exp_;        /* exponent of multiple for t_rtxcur_ */
00212     int rttvar_init_;       /* initial value for computing t_rttvar_ */
00213     double t_rtxcur_;   /* current retransmit value */
00214     double rtxcur_init_;    /* initial value for t_rtxcur_ */
00215     virtual void rtt_init();
00216     virtual double rtt_timeout();   /* provide RTO based on RTT estimates */
00217     virtual void rtt_update(double tao);    /* update RTT estimate */
00218     virtual void rtt_backoff();     /* double multiplier */
00219     /* End of state for the round-trip-time estimate. */
00220 
00221     /* Timestamps. */
00222     double ts_peer_;        /* the most recent timestamp the peer sent */
00223     double ts_echo_;        /* the most recent timestamp the peer echoed */
00224     int ts_option_size_;    // header bytes in a ts option
00225         double *tss;            // To store sent timestamps, with bugfix_ts_
00226         int tss_size_;          // Current capacity of tss
00227     int ts_option_;     /* use RFC1323-like timestamps? */
00228     /* End of timestamps. */
00229 
00230     /* connection and packet dynamics */
00231     virtual void output(int seqno, int reason = 0);
00232     virtual void send_much(int force, int reason, int maxburst = 0);
00233     virtual void newtimer(Packet*);
00234     virtual void dupack_action();       /* do this on dupacks */
00235     virtual void send_one();        /* do this on 1-2 dupacks */
00236     double linear(double x, double x_1, double y_1, double x_2, double y_2);
00237     /* the "linear" function is for experimental highspeed TCP */
00238     void opencwnd();
00239 
00240     void slowdown(int how);         /* reduce cwnd/ssthresh */
00241     void ecn(int seqno);        /* react to quench */
00242     virtual void set_initial_window();  /* set IW */
00243     double initial_window();        /* what is IW? */
00244     void reset();
00245     void newack(Packet*);
00246     void tcp_eln(Packet *pkt); /* reaction to ELN (usually wireless) */
00247     void finish(); /* called when the connection is terminated */
00248     void reset_qoption();   /* for QOption with EnblRTTCtr_ */
00249     void rtt_counting();    /* for QOption with EnblRTTCtr_ */
00250     int network_limited();  /* Sending limited by network? */
00251     double limited_slow_start(double cwnd, double max_ssthresh, double increment);
00252                 /* Limited slow-start for high windows */
00253     virtual int numdupacks(double cwnd);    /* for getting numdupacks_ */
00254     virtual void processQuickStart(Packet *pkt);
00255     virtual void endQuickStart();
00256     int lossQuickStart();
00257 
00258     /* Helper functions. Currently used by tcp-asym */
00259     virtual void output_helper(Packet*) { return; }
00260     virtual void send_helper(int) { return; }
00261     virtual void send_idle_helper() { return; }
00262     virtual void recv_helper(Packet*) { return; }
00263     virtual void recv_frto_helper(Packet*);
00264     virtual void recv_newack_helper(Packet*);
00265     virtual void partialnewack_helper(Packet*) {};
00266     /* End of helper functions. */
00267 
00268     int force_wnd(int num);
00269     void spurious_timeout();
00270 
00271     /* Timers */
00272     RtxTimer rtx_timer_;
00273     DelSndTimer delsnd_timer_;
00274     BurstSndTimer burstsnd_timer_;
00275     virtual void cancel_timers() {
00276         rtx_timer_.force_cancel();
00277         burstsnd_timer_.force_cancel();
00278         delsnd_timer_.force_cancel();
00279     }
00280     virtual void cancel_rtx_timer() {
00281         rtx_timer_.force_cancel();
00282     }
00283     virtual void set_rtx_timer();
00284     void reset_rtx_timer(int mild, int backoff = 1);
00285     int timerfix_;      /* set to true to update timer *after* */
00286                 /* update the RTT, instead of before   */
00287     int rfc2988_;       /* Use updated RFC 2988 timers */
00288     /* End of timers. */ 
00289 
00290     double boot_time_;  /* where between 'ticks' this sytem came up */
00291     double overhead_;
00292     double wnd_;
00293     double wnd_const_;
00294     double wnd_th_;     /* window "threshold" */
00295     double wnd_init_;
00296     double wnd_restart_;
00297     double tcp_tick_;   /* clock granularity */
00298     int wnd_option_;
00299     int wnd_init_option_;   /* 1 for using wnd_init_ */
00300                 /* 2 for using large initial windows */
00301     double decrease_num_;   /* factor for multiplicative decrease */
00302     double increase_num_;   /* factor for additive increase */
00303     int tcpip_base_hdr_size_;  /* size of base TCP/IP header */
00304     int ts_resetRTO_;   /* Un-backoff RTO after any valid RTT, */
00305                 /*   including from a retransmitted pkt?  */
00306                 /* The old version was "false". */
00307                 /* But "true" gives better performance, and */
00308                                 /* seems conformant with RFC 2988. */
00309     int maxcwnd_;       /* max # cwnd can ever be */
00310         int numdupacks_;    /* dup ACKs before fast retransmit */
00311     int numdupacksFrac_;    /* for a larger numdupacks_ with large */
00312                 /* windows */
00313     double maxrto_;     /* max value of an RTO */
00314     double minrto_;         /* min value of an RTO */
00315 
00316     /* For modeling SYN and SYN/ACK packets. */
00317     int syn_;       /* 1 for modeling SYN/ACK exchange */
00318     int delay_growth_;      /* delay opening cwnd until 1st data recv'd */
00319     /* End of modeling SYN and SYN/ACK packets. */
00320 
00321     /* F-RTO */
00322     int frto_enabled_;  /* != 0 to enable F-RTO */
00323     int sfrto_enabled_; /* != 0 to enabled SACK-based F-RTO */
00324     int spurious_response_; /* Response variant to spurious RTO */
00325     /* End of R-RTO */
00326 
00327     /* Parameters for backwards compatility with old code. */ 
00328     int bug_fix_;       /* 1 for multiple-fast-retransmit fix */
00329     int less_careful_;  /* 1 for Less Careful variant of bug_fix_, */
00330                 /*  for illustration only  */
00331     int exitFastRetrans_;   /* True to clean exits of Fast Retransmit */ 
00332                 /* False for buggy old behavior */
00333     int bugfix_ack_;        // 1 to enable ACK heuristic, to allow
00334                 //  multiple-fast-retransmits in special cases.
00335                 // From Andrei Gurtov
00336     int bugfix_ts_;         // 1 to enable timestamp heuristic, to allow
00337                 //  multiple-fast-retransmits in special cases.
00338                 // From Andrei Gurtov
00339                 // Not implemented yet.
00340     int old_ecn_;       /* For backwards compatibility with the 
00341                  * old ECN implementation, which never
00342                  * reduced the congestion window below
00343                  * one packet. */ 
00344     /* End of parameters for backwards compatility. */
00345 
00346     /* Parameters for alternate congestion control mechanisms. */
00347     double k_parameter_;     /* k parameter in binomial controls */
00348     double l_parameter_;     /* l parameter in binomial controls */
00349     int precision_reduce_;  /* non-integer reduction of cwnd */
00350     int maxburst_;      /* max # packets can send back-2-back */
00351     int aggressive_maxburst_;   /* Send on a non-valid ack? */
00352     /* End of parameters for alternate congestion control mechanisms. */
00353 
00354     FILE *plotfile_;
00355     /*
00356      * Dynamic state.
00357      */
00358     TracedInt dupacks_; /* number of duplicate acks */
00359     TracedInt curseq_;  /* highest seqno "produced by app" */
00360     TracedInt highest_ack_; /* not frozen during Fast Recovery */
00361     TracedDouble cwnd_; /* current window */
00362     TracedInt ssthresh_;    /* slow start threshold */
00363     TracedInt maxseq_;  /* used for Karn algorithm */
00364                 /* highest seqno sent so far */
00365     int last_ack_;      /* largest consecutive ACK, frozen during
00366                  *      Fast Recovery */
00367     int recover_;       /* highest pkt sent before dup acks, */
00368                 /*   timeout, or source quench/ecn */
00369     int last_cwnd_action_;  /* CWND_ACTION_{TIMEOUT,DUPACK,ECN} */
00370     int count_;     /* used in window increment algorithms */
00371     int rtt_active_;    /* 1 if a rtt sample is pending */
00372     int rtt_seq_;       /* seq # of timed seg if rtt_active_ is 1 */
00373     double rtt_ts_;     /* time at which rtt_seq_ was sent */
00374     double firstsent_;  /* When first packet was sent  --Allman */
00375     double lastreset_;  /* W.N. Last time connection was reset - for */
00376                 /* detecting pkts from previous incarnations */
00377     int closed_;            /* whether this connection has closed */
00378 
00379     /* Dynamic state used for alternate congestion control mechanisms */
00380     double awnd_;       /* averaged window */
00381     int first_decrease_;    /* First decrease of congestion window.  */
00382                 /* Used for decrease_num_ != 0.5. */
00383     double fcnt_;       /* used in window increment algorithms */
00384     double base_cwnd_;  /* base window (for experimental purposes) */
00385     /* End of state for alternate congestion control mechanisms */
00386 
00387     /* Dynamic state only used for monitoring */
00388     int trace_all_oneline_; /* TCP tracing vars all in one line or not? */
00389     int nam_tracevar_;      /* Output nam's variable trace or just plain 
00390                    text variable trace? */
00391         TracedInt ndatapack_;   /* number of data packets sent */
00392         TracedInt ndatabytes_;  /* number of data bytes sent */
00393         TracedInt nackpack_;    /* number of ack packets received */
00394         TracedInt nrexmit_;     /* number of retransmit timeouts 
00395                    when there was data outstanding */
00396         TracedInt nrexmitpack_; /* number of retransmited packets */
00397         TracedInt nrexmitbytes_; /* number of retransmited bytes */
00398         TracedInt necnresponses_; /* number of times cwnd was reduced
00399                    in response to an ecn packet -- sylvia */
00400         TracedInt ncwndcuts_;   /* number of times cwnd was reduced 
00401                    for any reason -- sylvia */
00402         TracedInt ncwndcuts1_;     /* number of times cwnd was reduced 
00403                                    due to congestion (as opposed to idle
00404                                    periods */
00405     /* end of dynamic state for monitoring */
00406 
00407     /* Specifying variants in TCP algorithms.  */
00408     int slow_start_restart_; /* boolean: re-init cwnd after connection 
00409                     goes idle.  On by default. */
00410     int restart_bugfix_;    /* ssthresh is cut down because of
00411                    timeouts during a connection's idle period.
00412                    Setting this boolean fixes this problem.
00413                    For now, it is off by default. */ 
00414         TracedInt singledup_;   /* Send on a single dup ack.  */
00415     int LimTransmitFix_;    /* To fix a bug in Limited Transmit. */
00416     int noFastRetrans_; /* No Fast Retransmit option.  */
00417     int oldCode_;       /* Use old code. */
00418     int useHeaders_;    /* boolean: Add TCP/IP header sizes */
00419     /* end of specifying variants */
00420 
00421     /* Used for ECN */
00422     int ecn_;       /* Explicit Congestion Notification */
00423     int cong_action_;   /* Congestion Action.  True to indicate
00424                    that the sender responded to congestion. */
00425         int ecn_burst_;     /* True when the previous ACK packet
00426                  *  carried ECN-Echo. */
00427     int ecn_backoff_;   /* True when retransmit timer should begin
00428                     to be backed off.  */
00429     int ect_;           /* turn on ect bit now? */
00430     int SetCWRonRetransmit_;  /* True to allow setting CWR on */
00431                   /*  retransmitted packets.   Affects */
00432                   /*  performance for Reno with ECN.  */
00433     /* end of ECN */
00434 
00435     /* used for Explicit Loss Notification */
00436         int eln_;               /* Explicit Loss Notification (wireless) */
00437         int eln_rxmit_thresh_;  /* Threshold for ELN-triggered rxmissions */
00438         int eln_last_rxmit_;    /* Last packet rxmitted due to ELN info */
00439     /* end of Explicit Loss Notification */
00440 
00441     /* for experimental high-speed TCP */
00442     /* These four parameters define the HighSpeed response function. */
00443     int low_window_;    /* window for turning on high-speed TCP */
00444     int high_window_;   /* target window for new response function */
00445     double high_p_;     /* target drop rate for new response function */
00446     double high_decrease_;  /* decrease rate at target window */
00447     /* The next parameter is for Limited Slow-Start. */
00448     int max_ssthresh_;  /* max value for ssthresh_ */
00449 
00450     /* These two functions are just an easy structuring of the code. */ 
00451     double increase_param();  /* get increase parameter for current cwnd */
00452     double decrease_param();  /* get decrease parameter for current cwnd */
00453     int cwnd_range_;    /* for determining when to recompute params. */
00454     hstcp hstcp_;       /* HighSpeed TCP variables */
00455         /* end of section for experimental high-speed TCP */
00456 
00457     /* for Quick-Start, experimental. */
00458     int rate_request_;      /* Rate request in Kbps, for QuickStart.  */
00459     int qs_enabled_;        /* to enable QuickStart. */
00460     int qs_requested_;
00461     int qs_approved_;
00462         int qs_window_;  /* >0: there are outstanding non-acked segments
00463                             from QS window */
00464         int qs_cwnd_; /* Initial window for Quick-Start */
00465         int tcp_qs_recovery_; /* != 0 if we apply slow start on packet
00466                                  losses during QS window */
00467     int qs_request_mode_;   /* 1 = Try to avoid unnecessary QS requests
00468                    for short flows. Use qs_rtt_ as the RTT
00469                    used in window calculation.
00470                    2 = Always request 'rate_request_' bytes,
00471                    regardless of flow size */
00472     int qs_thresh_;         /* Do not use QS if there are less data to send
00473                    than this. Applies only if
00474                    qs_request_mode_ == 1 */
00475     int qs_rtt_;            /* QS needs some assumption of the RTT in
00476                    in order to be able to determine how much
00477                    it needs for rate request with given amount
00478                    of data to send. milliseconds. */
00479     int ttl_diff_;
00480         /* end of section for Quick-Start. */
00481 
00482     /* F-RTO: !=0 when F-RTO recovery is underway, N:th round-trip
00483      * since RTO. Can have values between 0-2 */
00484     int frto_;
00485     int pipe_prev_; /* window size when timeout last occurred */
00486 
00487         /* support for event-tracing */
00488         //EventTrace *et_;
00489         void trace_event(char *eventtype);
00490 
00491     /* these function are now obsolete, see other above */
00492     void closecwnd(int how);
00493     void quench(int how);
00494         
00495     /* TCP quiescence, reducing cwnd after an idle period */
00496     void process_qoption_after_send() ;
00497     void process_qoption_after_ack(int seqno) ;
00498     int QOption_ ; /* TCP quiescence option */
00499     int EnblRTTCtr_ ; /* are we using a corase grained timer? */
00500     int T_full ; /* last time the window was full */
00501     int T_last ;
00502     int T_prev ;
00503     int T_start ;
00504     int RTT_count ;
00505     int RTT_prev ;
00506     int RTT_goodcount ;
00507     int F_counting ;
00508     int W_used ; 
00509     int W_timed ;
00510     int F_full ; 
00511     int Backoffs ;
00512     int control_increase_ ; /* If true, don't increase cwnd if sender */
00513                 /*  is not window-limited.  */
00514     int prev_highest_ack_ ; /* Used to determine if sender is */
00515                 /*  window-limited.  */
00516     /* end of TCP quiescence */
00517 };
00518 
00519 /* TCP Reno */
00520 class RenoTcpAgent : public virtual TcpAgent {
00521  public:
00522     RenoTcpAgent();
00523     virtual int window();
00524     virtual double windowd();
00525     virtual void recv(Packet *pkt, Handler*);
00526     virtual void timeout(int tno);
00527     virtual void dupack_action();
00528  protected:
00529     int allow_fast_retransmit(int last_cwnd_action_);
00530     unsigned int dupwnd_;
00531 };
00532 
00533 /* TCP New Reno */
00534 class NewRenoTcpAgent : public virtual RenoTcpAgent {
00535  public:
00536     NewRenoTcpAgent();
00537     virtual void recv(Packet *pkt, Handler*);
00538     virtual void partialnewack_helper(Packet* pkt);
00539     virtual void dupack_action();
00540  protected:
00541     int newreno_changes_;   /* 0 for fixing unnecessary fast retransmits */
00542                 /* 1 for additional code from Allman, */
00543                 /* to implement other algorithms from */
00544                 /* Hoe's paper, including sending a new */
00545                 /* packet for every two duplicate ACKs. */
00546                 /* The default is set to 0. */
00547     int newreno_changes1_;  /* Newreno_changes1_ set to 0 gives the */
00548                 /* Slow-but-Steady variant of NewReno from */
00549                 /* RFC 2582, with the retransmit timer reset */
00550                 /* after each partial new ack. */  
00551                 /* Newreno_changes1_ set to 1 gives the */
00552                 /* Impatient variant of NewReno from */
00553                 /* RFC 2582, with the retransmit timer reset */
00554                 /* only for the first partial new ack. */
00555                 /* The default is set to 0 */
00556     void partialnewack(Packet *pkt);
00557     int allow_fast_retransmit(int last_cwnd_action_);
00558     int acked_, new_ssthresh_;  /* used if newreno_changes_ == 1 */
00559     double ack2_, ack3_, basertt_; /* used if newreno_changes_ == 1 */
00560     int firstpartial_;  /* For the first partial ACK. */ 
00561     int partial_window_deflation_; /* 0 if set cwnd to ssthresh upon */
00562                        /* partial new ack (default) */
00563                        /* 1 if deflate (cwnd + dupwnd) by */
00564                        /* amount of data acked */
00565                        /* "Partial window deflation" is */
00566                        /* discussed in RFC 2582. */
00567     int exit_recovery_fix_;  /* 0 for setting cwnd to ssthresh upon */
00568                  /* leaving fast recovery (default) */
00569                  /* 1 for setting cwnd to min(ssthresh, */
00570                  /* amnt. of data in network) when leaving */
00571 };
00572 
00573 /* TCP vegas (VegasTcpAgent) */
00574 class VegasTcpAgent : public virtual TcpAgent {
00575  public:
00576     VegasTcpAgent();
00577     ~VegasTcpAgent();
00578     virtual void recv(Packet *pkt, Handler *);
00579     virtual void timeout(int tno);
00580 protected:
00581     double vegastime() {
00582         return(Scheduler::instance().clock() - firstsent_);
00583     }
00584     virtual void output(int seqno, int reason = 0);
00585     virtual void recv_newack_helper(Packet*);
00586     int vegas_expire(Packet*); 
00587     void reset();
00588     void vegas_inflate_cwnd(int win, double current_time);
00589 
00590     virtual void delay_bind_init_all();
00591     virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00592 
00593     double t_cwnd_changed_; // last time cwnd changed
00594     double firstrecv_;  // time recv the 1st ack
00595 
00596     int    v_alpha_;        // vegas thruput thresholds in pkts
00597     int    v_beta_;             
00598 
00599     int    v_gamma_;        // threshold to change from slow-start to
00600                 // congestion avoidance, in pkts
00601 
00602     int    v_slowstart_;    // # of pkts to send after slow-start, deflt(2)
00603     int    v_worried_;      // # of pkts to chk after dup ack (1 or 2)
00604 
00605     double v_timeout_;      // based on fine-grained timer
00606     double v_rtt_;      
00607     double v_sa_;       
00608     double v_sd_;   
00609 
00610     int    v_cntRTT_;       // # of rtt measured within one rtt
00611     double v_sumRTT_;       // sum of rtt measured within one rtt
00612 
00613     double v_begtime_;  // tagged pkt sent
00614     int    v_begseq_;   // tagged pkt seqno
00615 
00616     double* v_sendtime_;    // each unacked pkt's sendtime is recorded.
00617     int*   v_transmits_;    // # of retx for an unacked pkt
00618 
00619     int    v_maxwnd_;   // maxwnd size for v_sendtime_[]
00620     double v_newcwnd_;  // record un-inflated cwnd
00621 
00622     double v_baseRTT_;  // min of all rtt
00623 
00624     double v_incr_;     // amount cwnd is increased in the next rtt
00625     int    v_inc_flag_; // if cwnd is allowed to incr for this rtt
00626 
00627     double v_actual_;   // actual send rate (pkt/s; needed for tcp-rbp)
00628 
00629     int ns_vegas_fix_level_;   // see comment at end of tcp-vegas.cc for details of fixes
00630 };
00631 
00632 // Local Variables:
00633 // mode:c++
00634 // c-basic-offset: 8
00635 // End:
00636 
00637 #endif

Generated on Tue Mar 6 16:47:52 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6