xcp-end-sys.h

Go to the documentation of this file.
00001 // -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-
00002 
00003 /*
00004  * Copyright (C) 2004 by the University of Southern California
00005  * Copyright (C) 2004 by USC/ISI
00006  *               2002 by Dina Katabi
00007  * $Id: xcp-end-sys.h,v 1.8 2005/09/21 20:52:48 haldar Exp $
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License,
00011  * version 2, as published by the Free Software Foundation.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License along
00019  * with this program; if not, write to the Free Software Foundation, Inc.,
00020  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00021  *
00022  *
00023  * The copyright of this module includes the following
00024  * linking-with-specific-other-licenses addition:
00025  *
00026  * In addition, as a special exception, the copyright holders of
00027  * this module give you permission to combine (via static or
00028  * dynamic linking) this module with free software programs or
00029  * libraries that are released under the GNU LGPL and with code
00030  * included in the standard release of ns-2 under the Apache 2.0
00031  * license or under otherwise-compatible licenses with advertising
00032  * requirements (or modified versions of such code, with unchanged
00033  * license).  You may copy and distribute such a system following the
00034  * terms of the GNU GPL for this module and the licenses of the
00035  * other code concerned, provided that you include the source code of
00036  * that other code when and as the GNU GPL requires distribution of
00037  * source code.
00038  *
00039  * Note that people who make modified versions of this module
00040  * are not obligated to grant this special exception for their
00041  * modified versions; it is their choice whether to do so.  The GNU
00042  * General Public License gives permission to release a modified
00043  * version without this exception; this exception also makes it
00044  * possible to release a modified version which carries forward this
00045  * exception.
00046  *
00047  */
00048 
00049 /*
00050  * $Header: /nfs/jade/vint/CVSROOT/ns-2/xcp/xcp-end-sys.h,v 1.8 2005/09/21 20:52:48 haldar Exp $
00051  */
00052 
00053 #ifndef ns_xcp_end_sys_h
00054 #define ns_xcp_end_sys_h
00055 
00056 #include <stdio.h>
00057 #include <stdlib.h>
00058 #include <sys/types.h>
00059 
00060 #include "ip.h"
00061 #include "tcp.h"
00062 #include "flags.h"
00063 
00064 #include "agent.h"
00065 #include "packet.h"
00066 
00067 #include "flags.h"
00068 #include "tcp-sink.h"
00069 
00070 #define XCP_HDR_LEN  20
00071 
00072 //-----------  The Congestion Header ------------//
00073 struct hdr_xcp {
00074     double  throughput_;
00075     double  rtt_;
00076     enum {
00077         XCP_DISABLED = 0,
00078         XCP_ENABLED,
00079         XCP_ACK,
00080     }   xcp_enabled_;       // to indicate that the flow is XCP enabled
00081     bool    xcp_sparse_;        // flag used with xcp_sparse extension
00082     int xcpId_;         // Sender's ID (debugging only)
00083     double  cwnd_;          // The current window (debugging only) 
00084     double  reverse_feedback_;
00085 
00086     // --- Initialized by source and Updated by Router 
00087     double delta_throughput_;
00088     unsigned int controlling_hop_;  // The AQM ID of the controlling router
00089 
00090     static int offset_;     // offset for this header
00091     inline static int& offset() { return offset_; }
00092     inline static hdr_xcp* access(Packet* p) {
00093         return (hdr_xcp*) p->access(offset_);
00094     }
00095 
00096     /* per-field member functions */
00097     double& cwnd() { return (cwnd_); }
00098     double& rtt() { return (rtt_); }
00099 };
00100 
00101 /*--------------- Cwnd Shrinking Timer ---------------*
00102  *  If the cwnd becomes smaller than 1 then we keep it
00103  *  as one and reduce but delay sending the packet
00104  *  for s_rtt/cwnd
00105  * 
00106  * This code is to be written later!
00107  */
00108 
00109 #define     MAX(a,b)    ((a) > (b) ? (a) : (b))
00110 #define     TP_TO_TICKS MAX(1, (t_srtt_ >> T_SRTT_BITS))
00111 
00112 #define TP_AVG_EXP      4   // used for xcp_metered_output_ == true
00113 
00114 class XcpAgent;
00115   
00116 class cwndShrinkingTimer : public TimerHandler {
00117 public: 
00118     cwndShrinkingTimer(XcpAgent *a) : TimerHandler() { a_ = a; }
00119 protected:
00120     virtual void expire(Event *e);
00121     XcpAgent *a_;
00122 };
00123 
00124 class XcpAgent : public RenoTcpAgent {
00125 public:
00126     XcpAgent();
00127 
00128 protected:
00129     
00130     double time_now()  { return  Scheduler::instance().clock(); };
00131     void trace_var(char * var_name, double var);
00132     
00133     void init_rtt_vars(){
00134         srtt_estimate_           = 0.0;
00135     }
00136     virtual void delay_bind_init_all();
00137     virtual int delay_bind_dispatch(const char *varName, 
00138                     const char *localName, 
00139                     TclObject *tracer);
00140     
00141     virtual void output(int seqno, int reason = 0);
00142     virtual void recv_newack_helper(Packet *); 
00143     virtual void opencwnd(); 
00144     virtual void rtt_init(); // called in reset()
00145     virtual void rtt_update(double tao);
00146     
00147     /*--------- Variables --------------*/
00148     double current_positive_feedback_ ;
00149     int    tcpId_;
00150     double srtt_estimate_;
00151     /* more bits in delta for better precision, just for SRTT */
00152 #define XCP_DELTA_SHIFT     5
00153 #define XCP_EXPO_SHIFT      3
00154 #define XCP_RTT_SHIFT       (XCP_DELTA_SHIFT + XCP_EXPO_SHIFT)  
00155     /* macros for SRTT calculations */
00156 #define XCP_INIT_SRTT(rtt)                  \
00157     ((rtt) << XCP_RTT_SHIFT)
00158        
00159 #define XCP_UPDATE_SRTT(srtt, rtt)              \
00160     ((srtt) + (((rtt) << XCP_DELTA_SHIFT)           \
00161            - (((srtt) + (1 << (XCP_EXPO_SHIFT - 1)))    \
00162               >> XCP_EXPO_SHIFT)))
00163     long    xcp_srtt_; // srtt estimate using the above macros
00164 
00165     int xcp_sparse_;
00166     int xcp_sparse_seqno_;
00167 
00168     cwndShrinkingTimer shrink_cwnd_timer_;
00169 };
00170 
00171 class XcpSink : public Agent {
00172 public:
00173     XcpSink(Acker*);
00174     void recv(Packet* pkt, Handler*);
00175     void reset();
00176     int command(int argc, const char*const* argv);
00177 //  TracedInt& maxsackblocks() { return max_sack_blocks_; }
00178 protected:
00179     void ack(Packet*);
00180     virtual void add_to_ack(Packet* pkt);
00181 
00182     virtual void delay_bind_init_all();
00183     virtual int delay_bind_dispatch(const char *varName, 
00184                     const char *localName, 
00185                     TclObject *tracer);
00186     Acker* acker_;
00187     int ts_echo_bugfix_;
00188     int ts_echo_rfc1323_;   // conforms to rfc1323 for timestamps echo
00189     // Added by Andrei Gurtov
00190     friend void Sacker::configure(TcpSink*);
00191 //  TracedInt max_sack_blocks_; /* used only by sack sinks */
00192     Packet* save_;      /* place to stash saved packet while delaying */
00193                 /* used by DelAckSink */
00194     int RFC2581_immediate_ack_;     // Used to generate ACKs immediately
00195     int bytes_;     // for JOBS
00196     // for RFC2581-compliant gap-filling.
00197     double lastreset_;      /* W.N. used for detecting packets
00198                  * from previous incarnations */
00199 };
00200 
00201 #endif /* ns_xcp_end_sys_h */

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