• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/tcp/tcp-full.h

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: /cvsroot/nsnam/ns-2/tcp/tcp-full.h,v 1.58 2007/09/16 20:31:35 sallyfloyd 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         virtual void reset();                   // reset to a known point
00135 protected:
00136         virtual void delay_bind_init_all();
00137         virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00138         int closed_;
00139         int ts_option_size_;    // header bytes in a ts option
00140         int pipe_;              // estimate of pipe occupancy (for Sack)
00141         int pipectrl_;          // use pipe-style control
00142         int rtxbytes_;          // retransmitted bytes last recovery
00143         int open_cwnd_on_pack_; // open cwnd on a partial ack?
00144         int segs_per_ack_;  // for window updates
00145         int spa_thresh_;    // rcv_nxt < spa_thresh? -> 1 seg per ack
00146         int nodelay_;       // disable sender-side Nagle?
00147         int fastrecov_;     // are we in fast recovery?
00148         int deflate_on_pack_;   // deflate on partial acks (reno:yes)
00149         int data_on_syn_;   // send data on initial SYN?
00150         double last_send_time_; // time of last send
00151         int close_on_empty_;    // close conn when buffer empty
00152         int signal_on_empty_;   // signal when buffer is empty
00153         int reno_fastrecov_;    // do reno-style fast recovery?
00154         int infinite_send_;     // Always something to send
00155         int tcprexmtthresh_;    // fast retransmit threshold
00156         int iss_;       // initial send seq number
00157         int irs_;       // initial recv'd # (peer's iss)
00158         int dupseg_fix_;    // fix bug with dup segs and dup acks?
00159         int dupack_reset_;  // zero dupacks on dataful dup acks?
00160         int halfclose_;     // allow simplex closes?
00161         int nopredict_;     // disable header predication
00162         int ecn_syn_;       // Make SYN/ACK packets ECN-Capable?
00163         int ecn_syn_wait_;  // Wait if SYN/ACK packet is ECN-marked?
00164         int dsack_;         // do DSACK as well as SACK?
00165         double delack_interval_;
00166         int debug_;                     // Turn on/off debug output
00167 
00168         int headersize();   // a tcp header w/opts
00169         int outflags();     // state-specific tcp header flags
00170         int rcvseqinit(int, int); // how to set rcv_nxt_
00171         int predict_ok(Packet*); // predicate for recv-side header prediction
00172         int idle_restart();     // should I restart after idle?
00173         int fast_retransmit(int);  // do a fast-retransmit on specified seg
00174         inline double now() { return Scheduler::instance().clock(); }
00175         virtual void newstate(int ns);
00176 
00177         void bufferempty();             // called when sender buffer is empty
00178 
00179         void finish();
00180         void reset_rtx_timer(int);      // adjust the rtx timer
00181 
00182         virtual void timeout_action();  // what to do on rtx timeout
00183         virtual void dupack_action();   // what to do on dup acks
00184         virtual void pack_action(Packet*);      // action on partial acks
00185         virtual void ack_action(Packet*);       // action on acks
00186         virtual void send_much(int force, int reason, int maxburst = 0);
00187         virtual int build_options(hdr_tcp*);    // insert opts, return len
00188         virtual int reass(Packet*);             // reassemble: pass to ReassemblyQueue
00189         virtual void process_sack(hdr_tcp*);    // process a SACK
00190         virtual int send_allowed(int);          // ok to send this seq#?
00191         virtual int nxt_tseq() {
00192                 return t_seqno_;                // next seq# to send
00193         }
00194         virtual void sent(int seq, int amt) {
00195                 if (seq == t_seqno_)
00196                         t_seqno_ += amt;
00197                 pipe_ += amt;
00198                 if (seq < int(maxseq_))
00199                         rtxbytes_ += amt;
00200         }
00201         virtual void oldack() {                 // what to do on old ack
00202                 dupacks_ = 0;
00203         }
00204 
00205         virtual void extra_ack() {              // dup ACKs after threshold
00206                 if (reno_fastrecov_)
00207                         cwnd_++;
00208         }
00209 
00210         virtual void sendpacket(int seq, int ack, int flags, int dlen, int why, Packet *p=0);
00211         void connect();                 // do active open
00212         void listen();                  // do passive open
00213         void usrclosed();               // user requested a close
00214         int need_send();                // send ACK/win-update now?
00215         int foutput(int seqno, int reason = 0); // output 1 packet
00216         void newack(Packet* pkt);       // process an ACK
00217         int pack(Packet* pkt);          // is this a partial ack?
00218         void dooptions(Packet*);        // process option(s)
00219         DelAckTimer delack_timer_;      // other timers in tcp.h
00220         void cancel_timers();           // cancel all timers
00221         void prpkt(Packet*);            // print packet (debugging helper)
00222         char *flagstr(int);             // print header flags as symbols
00223         char *statestr(int);            // print states as symbols
00224 
00225         /*
00226         * the following are part of a tcpcb in "real" RFC793 TCP
00227         */
00228         int maxseg_;        /* MSS */
00229         int flags_;     /* controls next output() call */
00230         int state_;     /* enumerated type: FSM state */
00231         int recent_ce_; /* last ce bit we saw */
00232         int last_state_; /* FSM state at last pkt recv */
00233         int rcv_nxt_;       /* next sequence number expected */
00234         ReassemblyQueue rq_;    /* TCP reassembly queue */
00235         /*
00236         * the following are part of a tcpcb in "real" RFC1323 TCP
00237         */
00238         int last_ack_sent_; /* ackno field from last segment we sent */
00239         double recent_;         // ts on SYN written by peer
00240         double recent_age_;     // my time when recent_ was set
00241 
00242         /*
00243          * setting iw, specific to tcp-full, called
00244          * by TcpAgent::reset()
00245          */
00246         void set_initial_window();
00247 };
00248 
00249 class NewRenoFullTcpAgent : public FullTcpAgent {
00250 
00251 public:
00252         NewRenoFullTcpAgent();
00253 protected:
00254         int     save_maxburst_;         // saved value of maxburst_
00255         int     recov_maxburst_;        // maxburst lim during recovery
00256         void pack_action(Packet*);
00257         void ack_action(Packet*);
00258 };
00259 
00260 class TahoeFullTcpAgent : public FullTcpAgent {
00261 protected:
00262         void dupack_action();
00263 };
00264 
00265 class SackFullTcpAgent : public FullTcpAgent {
00266 public:
00267         SackFullTcpAgent() :
00268                 sq_(sack_min_), sack_min_(-1), h_seqno_(-1) { }
00269         ~SackFullTcpAgent() { rq_.clear(); }
00270 protected:
00271 
00272         virtual void delay_bind_init_all();
00273         virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00274 
00275         virtual void pack_action(Packet*);
00276         virtual void ack_action(Packet*);
00277         virtual void dupack_action();
00278         virtual void process_sack(hdr_tcp*);
00279         virtual void timeout_action();
00280         virtual int nxt_tseq();
00281         virtual int hdrsize(int nblks);
00282         virtual int send_allowed(int);
00283         virtual void sent(int seq, int amt) {
00284                 if (seq == h_seqno_)
00285                         h_seqno_ += amt;
00286                 FullTcpAgent::sent(seq, amt);
00287         }
00288 
00289         int build_options(hdr_tcp*);    // insert opts, return len
00290         int clear_on_timeout_;  // clear sender's SACK queue on RTX timeout?
00291         int sack_option_size_;  // base # bytes for sack opt (no blks)
00292         int sack_block_size_;   // # bytes in a sack block (def: 8)
00293         int max_sack_blocks_;   // max # sack blocks to send
00294         int sack_rtx_bthresh_;  // hole-fill byte threshold
00295         int sack_rtx_cthresh_;  // hole-fill counter threshold
00296         int sack_rtx_threshmode_;       // hole-fill mode setting
00297 
00298 
00299         void    reset();
00300         //XXX not implemented?
00301         //void  sendpacket(int seqno, int ackno, int pflags, int datalen, int reason, Packet *p=0);
00302 
00303         ReassemblyQueue sq_;    // SACK queue, used by sender
00304         int sack_min_;          // first seq# in sack queue, initializes sq_
00305         int h_seqno_;           // next seq# to hole-fill
00306 };
00307 
00308 #endif

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1