tcp-full.h

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997, 2001 The Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *  This product includes software developed by the Network Research
00017  *  Group at Lawrence Berkeley National Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tcp/tcp-full.h,v 1.54 2005/06/19 00:33:27 sfloyd Exp $ (LBL)
00035  */
00036 
00037 #ifndef ns_tcp_full_h
00038 #define ns_tcp_full_h
00039 
00040 #include "tcp.h"
00041 #include "rq.h"
00042 
00043 /*
00044  * most of these defines are directly from
00045  * tcp_var.h or tcp_fsm.h in "real" TCP
00046  */
00047 
00048 
00049 /*
00050  * these are used in 'tcp_flags_' member variable
00051  */
00052 
00053 #define TF_ACKNOW       0x0001          /* ack peer immediately */
00054 #define TF_DELACK       0x0002          /* ack, but try to delay it */
00055 #define TF_NODELAY      0x0004          /* don't delay packets to coalesce */
00056 #define TF_NOOPT        0x0008          /* don't use tcp options */
00057 #define TF_SENTFIN      0x0010          /* have sent FIN */
00058 #define TF_RCVD_TSTMP   0x0100      /* timestamp rcv'd in SYN */
00059 #define TF_NEEDFIN  0x0800      /* send FIN (implicit state) */
00060 
00061 /* these are simulator-specific */
00062 #define TF_NEEDCLOSE    0x10000     /* perform close on empty */
00063 
00064 /*
00065  * these are used in state_ member variable
00066  */
00067 
00068 #define TCPS_CLOSED             0       /* closed */
00069 #define TCPS_LISTEN             1       /* listening for connection */
00070 #define TCPS_SYN_SENT           2       /* active, have sent syn */
00071 #define TCPS_SYN_RECEIVED       3       /* have sent and received syn */
00072 #define TCPS_ESTABLISHED        4       /* established */
00073 #define TCPS_CLOSE_WAIT     5   /* rcvd fin, waiting for app close */
00074 #define TCPS_FIN_WAIT_1         6       /* have closed, sent fin */
00075 #define TCPS_CLOSING            7       /* closed xchd FIN; await FIN ACK */
00076 #define TCPS_LAST_ACK           8       /* had fin and close; await FIN ACK */
00077 #define TCPS_FIN_WAIT_2         9       /* have closed, fin is acked */
00078 
00079 #define TCP_NSTATES     10  /* total number of states */
00080 
00081 #define TCPS_HAVERCVDFIN(s) ((s) == TCPS_CLOSING || (s) == TCPS_CLOSED || (s) == TCPS_CLOSE_WAIT)
00082 #define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED)
00083 
00084 #define TCPIP_BASE_PKTSIZE      40      /* base TCP/IP header in real life */
00085 /* these are used to mark packets as to why we xmitted them */
00086 #define REASON_NORMAL   0  
00087 #define REASON_TIMEOUT  1
00088 #define REASON_DUPACK   2
00089 #define REASON_RBP  3   /* if ever implemented */
00090 #define REASON_SACK 4   /* hole fills in SACK */
00091 
00092 /* bits for the tcp_flags field below */
00093 /* from tcp.h in the "real" implementation */
00094 /* RST and URG are not used in the simulator */
00095  
00096 #define TH_FIN  0x01        /* FIN: closing a connection */
00097 #define TH_SYN  0x02        /* SYN: starting a connection */
00098 #define TH_PUSH 0x08        /* PUSH: used here to "deliver" data */
00099 #define TH_ACK  0x10        /* ACK: ack number is valid */
00100 #define TH_ECE  0x40        /* ECE: CE echo flag */
00101 #define TH_CWR  0x80        /* CWR: congestion window reduced */
00102 
00103 
00104 #define PF_TIMEOUT 0x04     /* protocol defined */
00105 #define TCP_PAWS_IDLE   (24 * 24 * 60 * 60) /* 24 days in secs */
00106 
00107 class FullTcpAgent;
00108 class DelAckTimer : public TimerHandler {
00109 public:
00110     DelAckTimer(FullTcpAgent *a) : TimerHandler(), a_(a) { }
00111 protected:
00112     virtual void expire(Event *);
00113     FullTcpAgent *a_;
00114 };
00115 
00116 class FullTcpAgent : public TcpAgent {
00117 public:
00118     FullTcpAgent() :
00119         closed_(0), pipe_(-1), rtxbytes_(0), fastrecov_(FALSE),
00120             last_send_time_(-1.0), infinite_send_(FALSE), irs_(-1),
00121             delack_timer_(this), flags_(0),
00122             state_(TCPS_CLOSED), recent_ce_(FALSE),
00123             last_state_(TCPS_CLOSED), rq_(rcv_nxt_), last_ack_sent_(-1) { }
00124 
00125     ~FullTcpAgent() { cancel_timers(); rq_.clear(); }
00126     virtual void recv(Packet *pkt, Handler*);
00127     virtual void timeout(int tno);  // tcp_timers() in real code
00128     virtual void close() { usrclosed(); }
00129     void advanceby(int);    // over-rides tcp base version
00130     void advance_bytes(int);    // unique to full-tcp
00131         virtual void sendmsg(int nbytes, const char *flags = 0);
00132         virtual int& size() { return maxseg_; } //FullTcp uses maxseg_ for size_
00133     virtual int command(int argc, const char*const* argv);
00134 protected:
00135     virtual void delay_bind_init_all();
00136     virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00137     int closed_;
00138     int ts_option_size_;    // header bytes in a ts option
00139     int pipe_;      // estimate of pipe occupancy (for Sack)
00140     int pipectrl_;      // use pipe-style control
00141     int rtxbytes_;      // retransmitted bytes last recovery
00142     int open_cwnd_on_pack_; // open cwnd on a partial ack?
00143     int segs_per_ack_;  // for window updates
00144     int spa_thresh_;    // rcv_nxt < spa_thresh? -> 1 seg per ack
00145     int nodelay_;       // disable sender-side Nagle?
00146     int fastrecov_;     // are we in fast recovery?
00147     int deflate_on_pack_;   // deflate on partial acks (reno:yes)
00148     int data_on_syn_;   // send data on initial SYN?
00149     double last_send_time_; // time of last send
00150     int close_on_empty_;    // close conn when buffer empty
00151     int signal_on_empty_;   // signal when buffer is empty
00152     int reno_fastrecov_;    // do reno-style fast recovery?
00153     int infinite_send_; // Always something to send
00154     int tcprexmtthresh_;    // fast retransmit threshold
00155     int iss_;       // initial send seq number
00156     int irs_;   // initial recv'd # (peer's iss)
00157     int dupseg_fix_;    // fix bug with dup segs and dup acks?
00158     int dupack_reset_;  // zero dupacks on dataful dup acks?
00159     int halfclose_;     // allow simplex closes?
00160     int nopredict_;     // disable header predication
00161     int dsack_;     // do DSACK as well as SACK?
00162     double delack_interval_;
00163 
00164     int headersize();   // a tcp header w/opts
00165     int outflags();     // state-specific tcp header flags
00166     int rcvseqinit(int, int); // how to set rcv_nxt_
00167     int predict_ok(Packet*); // predicate for recv-side header prediction
00168     int idle_restart(); // should I restart after idle?
00169     int fast_retransmit(int);  // do a fast-retransmit on specified seg
00170     inline double now() { return Scheduler::instance().clock(); }
00171     virtual void newstate(int ns);
00172 
00173     void bufferempty();         // called when sender buffer is empty
00174 
00175     void finish();
00176     void reset_rtx_timer(int);      // adjust the rtx timer
00177 
00178     virtual void timeout_action();  // what to do on rtx timeout
00179     virtual void dupack_action();   // what to do on dup acks
00180     virtual void pack_action(Packet*);  // action on partial acks
00181     virtual void ack_action(Packet*);   // action on acks
00182         virtual void reset();               // reset to a known point
00183     virtual void send_much(int force, int reason, int maxburst = 0);
00184     virtual int build_options(hdr_tcp*);    // insert opts, return len
00185     virtual int reass(Packet*);     // reassemble: pass to ReassemblyQueue
00186     virtual void process_sack(hdr_tcp*);    // process a SACK
00187     virtual int send_allowed(int);      // ok to send this seq#?
00188     virtual int nxt_tseq() {
00189         return t_seqno_;        // next seq# to send
00190     }
00191     virtual void sent(int seq, int amt) {
00192         if (seq == t_seqno_)
00193             t_seqno_ += amt;
00194         pipe_ += amt;
00195         if (seq < int(maxseq_))
00196             rtxbytes_ += amt;
00197     }
00198     virtual void oldack() {         // what to do on old ack
00199         dupacks_ = 0;
00200     }
00201 
00202     virtual void extra_ack() {      // dup ACKs after threshold
00203         if (reno_fastrecov_)
00204             cwnd_++;
00205     }
00206 
00207     void sendpacket(int seq, int ack, int flags, int dlen, int why);
00208     void connect();             // do active open
00209     void listen();              // do passive open
00210     void usrclosed();           // user requested a close
00211     int need_send();            // send ACK/win-update now?
00212     int foutput(int seqno, int reason = 0); // output 1 packet
00213     void newack(Packet* pkt);   // process an ACK
00214     int pack(Packet* pkt);      // is this a partial ack?
00215     void dooptions(Packet*);    // process option(s)
00216     DelAckTimer delack_timer_;  // other timers in tcp.h
00217     void cancel_timers();       // cancel all timers
00218     void prpkt(Packet*);        // print packet (debugging helper)
00219     char *flagstr(int);     // print header flags as symbols
00220     char *statestr(int);        // print states as symbols
00221 
00222     /*
00223     * the following are part of a tcpcb in "real" RFC793 TCP
00224     */
00225     int maxseg_;        /* MSS */
00226     int flags_;     /* controls next output() call */
00227     int state_;     /* enumerated type: FSM state */
00228     int recent_ce_; /* last ce bit we saw */
00229     int last_state_; /* FSM state at last pkt recv */
00230     int rcv_nxt_;       /* next sequence number expected */
00231     ReassemblyQueue rq_;    /* TCP reassembly queue */
00232     /*
00233     * the following are part of a tcpcb in "real" RFC1323 TCP
00234     */
00235     int last_ack_sent_; /* ackno field from last segment we sent */
00236     double recent_;     // ts on SYN written by peer
00237     double recent_age_; // my time when recent_ was set
00238 
00239     /*
00240      * setting iw, specific to tcp-full, called
00241      * by TcpAgent::reset()
00242      */
00243     void set_initial_window();
00244 };
00245 
00246 class NewRenoFullTcpAgent : public FullTcpAgent {
00247 
00248 public:
00249     NewRenoFullTcpAgent();
00250 protected:
00251     int save_maxburst_;     // saved value of maxburst_
00252     int recov_maxburst_;    // maxburst lim during recovery
00253     void pack_action(Packet*);
00254     void ack_action(Packet*);
00255 };
00256 
00257 class TahoeFullTcpAgent : public FullTcpAgent {
00258 protected:
00259     void dupack_action();
00260 };
00261 
00262 class SackFullTcpAgent : public FullTcpAgent {
00263 public:
00264     SackFullTcpAgent() :
00265         sq_(sack_min_), sack_min_(-1), h_seqno_(-1) { }
00266     ~SackFullTcpAgent() { rq_.clear(); }
00267 protected:
00268 
00269     virtual void delay_bind_init_all();
00270     virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00271 
00272     virtual void pack_action(Packet*);
00273     virtual void ack_action(Packet*);
00274     virtual void dupack_action();
00275     virtual void process_sack(hdr_tcp*);
00276     virtual void timeout_action();
00277     virtual int nxt_tseq();
00278     virtual int hdrsize(int nblks);
00279     virtual int send_allowed(int);
00280     virtual void sent(int seq, int amt) {
00281         if (seq == h_seqno_)
00282             h_seqno_ += amt;
00283         FullTcpAgent::sent(seq, amt);
00284     }
00285 
00286     int build_options(hdr_tcp*);    // insert opts, return len
00287     int clear_on_timeout_;  // clear sender's SACK queue on RTX timeout?
00288     int sack_option_size_;  // base # bytes for sack opt (no blks)
00289     int sack_block_size_;   // # bytes in a sack block (def: 8)
00290     int max_sack_blocks_;   // max # sack blocks to send
00291     int sack_rtx_bthresh_;  // hole-fill byte threshold
00292     int sack_rtx_cthresh_;  // hole-fill counter threshold
00293     int sack_rtx_threshmode_;   // hole-fill mode setting
00294 
00295 
00296     void    reset();
00297     void    sendpacket(int seqno, int ackno, int pflags, int datalen, int reason);
00298 
00299     ReassemblyQueue sq_;    // SACK queue, used by sender
00300     int sack_min_;      // first seq# in sack queue, initializes sq_
00301     int h_seqno_;       // next seq# to hole-fill
00302 };
00303 
00304 #endif

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