• Main Page
  • Classes
  • Files
  • File List

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

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         friend class XcpSink;
00101 public:
00102         TcpSink(Acker*);
00103         void recv(Packet* pkt, Handler*);
00104         void reset();
00105         int command(int argc, const char*const* argv);
00106         TracedInt& maxsackblocks() { return max_sack_blocks_; }
00107 protected:
00108         void ack(Packet*);
00109         virtual void add_to_ack(Packet* pkt);
00110 
00111         virtual void delay_bind_init_all();
00112         virtual int delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer);
00113 
00114         Acker* acker_;
00115         int ts_echo_bugfix_;
00116         int ts_echo_rfc1323_;   // conforms to rfc1323 for timestamps echo
00117                                 // Added by Andrei Gurtov
00118 
00119         friend void Sacker::configure(TcpSink*);
00120         TracedInt max_sack_blocks_;     /* used only by sack sinks */
00121         Packet* save_;          /* place to stash saved packet while delaying */
00122                                 /* used by DelAckSink */
00123         int generate_dsacks_;   // used only by sack sinks
00124         int qs_enabled_; // to enable QuickStart 
00125         int RFC2581_immediate_ack_;     // Used to generate ACKs immediately 
00126         int bytes_;     // for JOBS
00127                                         // for RFC2581-compliant gap-filling.
00128         double lastreset_;      /* W.N. used for detecting packets  */
00129                                 /* from previous incarnations */
00130         int ecn_syn_;           /* allow SYN/ACK packets to be ECN-capable */
00131 
00132 };
00133 
00134 class DelAckSink;
00135 
00136 class DelayTimer : public TimerHandler {
00137 public:
00138         DelayTimer(DelAckSink *a) : TimerHandler() { a_ = a; }
00139 protected:
00140         virtual void expire(Event *e);
00141         DelAckSink *a_;
00142 };
00143 
00144 class DelAckSink : public TcpSink {
00145 public:
00146         DelAckSink(Acker* acker);
00147         void recv(Packet* pkt, Handler*);
00148         virtual void timeout(int tno);
00149         void reset();
00150 protected:
00151         double interval_;
00152         DelayTimer delay_timer_;
00153 };
00154 
00155 #endif

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