• Main Page
  • Classes
  • Files
  • File List

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

00001 /*
00002  * Copyright (c) 1997 The 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 Network Research
00016  *  Group at Lawrence Berkeley National 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: /cvsroot/nsnam/ns-2/baytcp/tcp-full-bay.h,v 1.3 2006/05/30 21:38:42 pradkin Exp $ (LBL)
00034  */
00035 
00036 #ifndef ns_tcp_full_h
00037 #define ns_tcp_full_h
00038 
00039 #include "tcp.h"
00040 
00041 /*
00042  * these defines are directly from tcp_var.h in "real" TCP
00043  * they are used in the 'tcp_flags_' member variable
00044  */
00045 
00046 #define TF_ACKNOW       0x0001          /* ack peer immediately */
00047 #define TF_DELACK       0x0002          /* ack, but try to delay it */
00048 #define TF_NODELAY      0x0004          /* don't delay packets to coalesce */
00049 #define TF_NOOPT        0x0008          /* don't use tcp options */
00050 #define TF_SENTFIN      0x0010          /* have sent FIN */
00051 #define TF_SENTSYN      0x0020          /* have sent SYN */
00052 
00053 #define TCPS_CLOSED             0       /* closed */
00054 #define TCPS_LISTEN             1       /* listening for connection */
00055 #define TCPS_SYN_SENT           2       /* active, have sent syn */
00056 #define TCPS_SYN_RECEIVED       3       /* have send and received syn */
00057 #define TCPS_ESTABLISHED        4       /* established */
00058 #define TCPS_FIN_WAIT_1         6       /* have closed, sent fin */
00059 #define TCPS_CLOSING            7       /* closed xchd FIN; await FIN ACK */
00060 #define TCPS_LAST_ACK           8       /* had fin and close; await FIN ACK */
00061 #define TCPS_FIN_WAIT_2         9       /* have closed, fin is acked */
00062 
00063 #define TCPIP_BASE_PKTSIZE      40      /* base TCP/IP header in real life */
00064 /* these are used to mark packets as to why we xmitted them */
00065 #define REASON_NORMAL   0  
00066 #define REASON_TIMEOUT  1
00067 #define REASON_DUPACK   2
00068 
00069 /* bits for the tcp_flags field below */
00070 /* from tcp.h in the "real" implementation */
00071 /* RST and URG are not used in the simulator */
00072  
00073 #define TH_FIN  0x01        /* FIN: closing a connection */
00074 #define TH_SYN  0x02        /* SYN: starting a connection */
00075 #define TH_PUSH 0x08        /* PUSH: used here to "deliver" data */
00076 #define TH_ACK  0x10        /* ACK: ack number is valid */
00077 
00078 #define PF_TIMEOUT 0x04         /* protocol defined */
00079 
00080 /*
00081  * inserted by kedar
00082  */
00083 
00084 class BayFullTcpAgent;
00085 
00086 class BayDelAckTimer : public TimerHandler {
00087 public:
00088     BayDelAckTimer(BayFullTcpAgent *a) : TimerHandler(), a_(a) { }
00089 protected:
00090     virtual void expire(Event *);
00091     BayFullTcpAgent *a_;
00092 };
00093  
00094 class BayReassemblyQueue : public TcpAgent {
00095     struct seginfo {
00096         seginfo* next_;
00097         seginfo* prev_;
00098         int startseq_;
00099         int endseq_;
00100         int flags_;
00101     };
00102 public:
00103     BayReassemblyQueue(int& nxt) : head_(NULL), tail_(NULL),
00104         rcv_nxt_(nxt) { }
00105     int empty() { return (head_ == NULL); }
00106     int add(Packet*);
00107     void clear();
00108 protected:
00109     seginfo* head_;
00110     seginfo* tail_;
00111     int& rcv_nxt_;
00112 };
00113 
00114 /* Added by kmn 8/5/97. A hack to create a template base class for
00115  * application agents that expect to talk to full tcps. Don't want
00116  * to do anything fancy since the vint folks should come up with
00117  * something one of these days.
00118  * kmn - 8/12/97 yet another hack added to keep a list of agents
00119  */
00120  /* vint project never came through. Added in to recv 6/8/00 -kmn */
00121 
00122  #define DATA_PUSH 1
00123  #define CONNECTION_END 2
00124 
00125 class BayTcpAppAgent : public Agent {
00126  public:
00127         BayTcpAppAgent(packet_t ptype) : Agent(ptype) {}
00128         virtual void recv(Packet*, BayFullTcpAgent*, int) {}
00129 };
00130 
00131 class BayFullTcpAgent : public TcpAgent {
00132  public:
00133     BayFullTcpAgent();
00134     ~BayFullTcpAgent();
00135     void delay_bind_init_all();
00136     int delay_bind_dispatch(const char *varName, const char *localName,
00137                             TclObject *tracer);
00138     virtual void recv(Packet *pkt, Handler*);
00139     virtual void timeout(int tno);      // tcp_timers() in real code
00140     void advance(int);
00141     int advance(int, int);      //added 7/30/97 by kmn to pass bytes,
00142                                 //      set close_on_empty_
00143     int command(int argc, const char*const* argv);
00144     int state() { return state_; }
00145 
00146  protected:
00147     int segs_per_ack_;  // for window updates
00148     int nodelay_;       // disable sender-side Nagle?
00149     int data_on_syn_;   // send data on initial SYN?
00150     int tcprexmtthresh_;    // fast retransmit threshold
00151     int iss_;       // initial send seq number
00152     int dupseg_fix_;    // fix bug with dup segs and dup acks?
00153     int dupack_reset_;  // zero dupacks on dataful dup acks?
00154     double delack_interval_;
00155 
00156     int headersize();   // a tcp header
00157     int outflags();     // state-specific tcp header flags
00158     int predict_ok(Packet*); // predicate for recv-side header prediction
00159     
00160     void fast_retransmit(int);  // do a fast-retransmit on specified seg
00161     inline double now() { return Scheduler::instance().clock(); }
00162 
00163     void reset_rtx_timer(int);  // adjust the rtx timer
00164     void reset();       // reset to a known point
00165     void reinit();       // reset to a known point
00166     void connect();     // do active open
00167     void listen();      // do passive open
00168     void usrclosed();   // user requested a close
00169     int need_send();    // need to send ACK/win-update now?
00170     void sendpacket(int seqno, int ackno, int pflags, int datalen, int reason, Packet *p=0);
00171     void output(int seqno, int reason = 0); // output 1 packet
00172     void send_much(int force, int reason, int maxburst = 0);
00173     void newack(Packet* pkt);   // process an ACK
00174     void cancel_rtx_timeout();  // cancel the rtx timeout
00175     
00176     /*
00177      * the following are part of a tcpcb in "real" RFC793 TCP
00178      */
00179     int maxseg_;        /* MSS */
00180     int flags_;     /* controls next output() call */
00181     int state_;     /* enumerated type: FSM state */
00182     int rcv_nxt_;       /* next sequence number expected */
00183     BayReassemblyQueue rq_;    /* TCP reassembly queue */
00184     /*
00185      * the following are part of a tcpcb in "real" RFC1323 TCP
00186      */
00187     int last_ack_sent_; /* ackno field from last segment we sent */
00188     /*
00189      * added 7/30/97 by kmn to allow connection to close with FINs
00190      *  when empties data and to allow calling recv() on application
00191      */
00192     int close_on_empty_;
00193     BayTcpAppAgent* app_;
00194     //added 8/12 to start in ack per packet, switch to set value
00195     int switch_spa_thresh_;
00196     int first_data_;
00197     int recover_cause_;
00198     /*
00199      *inserted by kedar
00200      */
00201     BayDelAckTimer delack_timer_;
00202 };
00203 
00204 class BayFullTcpList {
00205 public:
00206         BayFullTcpList() : tcp(0), next(0) {}
00207         BayFullTcpAgent* tcp;
00208         BayFullTcpList* next;
00209 };
00210 
00211 #ifdef notdef
00212 class NewRenoBayFullTcpAgent : public BayFullTcpAgent {
00213 public:
00214         NewRenoBayFullTcpAgent();
00215 protected:
00216         int     save_maxburst_;         // saved value of maxburst_
00217         int     recov_maxburst_;        // maxburst lim during recovery
00218         void pack_action(Packet*);
00219         void ack_action(Packet*);
00220 };
00221 
00222 class TahoeBayFullTcpAgent : public BayFullTcpAgent {
00223 protected:
00224         void dupack_action();
00225 };
00226 
00227 class SackBayFullTcpAgent : public BayFullTcpAgent {
00228 public:
00229         SackBayFullTcpAgent();
00230         ~SackBayFullTcpAgent();
00231         void    recv(Packet*, Handler*);
00232 protected:
00233         int build_options(hdr_tcp*);    // insert opts, return len
00234         int sack_option_size_;  // base # bytes for sack opt (no blks)
00235         int sack_block_size_;   // # bytes in a sack block (def: 8)
00236         int sack_min_;          // first seq# in sack queue
00237         int sack_max_;          // highest seq# seen in any sack block
00238         int sack_nxt_;          // next seq# to hole-fill
00239         int max_sack_blocks_;   // max # sack blocks to send
00240 
00241         BayReassemblyQueue sq_; // SACK queue, used by sender
00242 
00243         void    reset();
00244         void    sendpacket(int seqno, int ackno, int pflags, int datalen, int reason);
00245         void    send_much(int force, int reason, int maxburst = 0);
00246         void    send_holes(int force, int maxburst);
00247         void    pack_action(Packet*);
00248         void    ack_action(Packet*);
00249         void    dupack_action();
00250         int     hdrsize(int nblks);
00251         void    timeout_action();
00252 };
00253 #endif
00254 
00255 #endif

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