tcp-sink.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) 1991-1997 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 Computer Systems
00017  *  Engineering Group at Lawrence Berkeley 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  */
00035  
00036 #ifndef ns_tcpsink_h
00037 #define ns_tcpsink_h
00038 
00039 #include <math.h>
00040 #include "agent.h"
00041 #include "tcp.h"
00042 
00043 /* max window size */
00044 // #define MWS 1024  
00045 #define MWS 64
00046 #define MWM (MWS-1)
00047 #define HS_MWS 65536
00048 #define HS_MWM (MWS-1)
00049 /* For Tahoe TCP, the "window" parameter, representing the receiver's
00050  * advertised window, should be less than MWM.  For Reno TCP, the
00051  * "window" parameter should be less than MWM/2.
00052  */
00053 
00054 class TcpSink;
00055 class Acker {
00056 public:
00057     Acker();
00058     virtual ~Acker() { delete[] seen_; }
00059     void update_ts(int seqno, double ts, int rfc1323 = 0);
00060     int update(int seqno, int numBytes);
00061     void update_ecn_unacked(int value);
00062     inline int Seqno() const { return (next_ - 1); }
00063     virtual void append_ack(hdr_cmn*, hdr_tcp*, int oldSeqno) const;
00064     void reset();
00065     double ts_to_echo() { return ts_to_echo_;}
00066     int ecn_unacked() { return ecn_unacked_;}
00067     inline int Maxseen() const { return (maxseen_); }
00068     void resize_buffers(int sz);  // resize the seen_ buffer
00069 
00070 protected:
00071     int next_;      /* next packet expected */
00072     int maxseen_;       /* max packet number seen */
00073     int wndmask_;       /* window mask - either MWM or HS_MWM - Sylvia */ 
00074     int ecn_unacked_;   /* ECN forwarded to sender, but not yet
00075                  * acknowledged. */
00076     int *seen_;     /* array of packets seen */
00077     double ts_to_echo_; /* timestamp to echo to peer */
00078     int is_dup_;        // A duplicate packet.
00079 public:
00080         int last_ack_sent_;     // For updating timestamps, from Andrei Gurtov.
00081 };
00082 
00083 // derive Sacker from TclObject to allow for traced variable
00084 class SackStack;
00085 class Sacker : public Acker, public TclObject {
00086 public: 
00087     Sacker() : base_nblocks_(-1), sf_(0) { };
00088     ~Sacker();
00089     void append_ack(hdr_cmn*, hdr_tcp*, int oldSeqno) const;
00090     void reset();
00091     void configure(TcpSink*);
00092 protected:
00093     int base_nblocks_;
00094     int* dsacks_;       // Generate DSACK blocks.
00095     SackStack *sf_;
00096     void trace(TracedVar*);
00097 };
00098 
00099 class TcpSink : public Agent {
00100 public:
00101     TcpSink(Acker*);
00102     void recv(Packet* pkt, Handler*);
00103     void reset();
00104     int command(int argc, const char*const* argv);
00105     TracedInt& maxsackblocks() { return max_sack_blocks_; }
00106 protected:
00107     void ack(Packet*);
00108     virtual void add_to_ack(Packet* pkt);
00109 
00110         virtual void delay_bind_init_all();
00111         virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00112 
00113     Acker* acker_;
00114     int ts_echo_bugfix_;
00115     int ts_echo_rfc1323_;   // conforms to rfc1323 for timestamps echo
00116                 // Added by Andrei Gurtov
00117 
00118     friend void Sacker::configure(TcpSink*);
00119     TracedInt max_sack_blocks_; /* used only by sack sinks */
00120     Packet* save_;      /* place to stash saved packet while delaying */
00121                 /* used by DelAckSink */
00122     int generate_dsacks_;   // used only by sack sinks
00123     int qs_enabled_; // to enable QuickStart 
00124     int RFC2581_immediate_ack_; // Used to generate ACKs immediately 
00125     int bytes_;     // for JOBS
00126                     // for RFC2581-compliant gap-filling.
00127     double lastreset_;  /* W.N. used for detecting packets  */
00128                 /* from previous incarnations */
00129 };
00130 
00131 class DelAckSink;
00132 
00133 class DelayTimer : public TimerHandler {
00134 public:
00135     DelayTimer(DelAckSink *a) : TimerHandler() { a_ = a; }
00136 protected:
00137     virtual void expire(Event *e);
00138     DelAckSink *a_;
00139 };
00140 
00141 class DelAckSink : public TcpSink {
00142 public:
00143     DelAckSink(Acker* acker);
00144     void recv(Packet* pkt, Handler*);
00145     virtual void timeout(int tno);
00146     void reset();
00147 protected:
00148     double interval_;
00149     DelayTimer delay_timer_;
00150 };
00151 
00152 #endif

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