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: xcpq.h,v 1.9 2005/08/25 18:58:14 johnh 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/xcpq.h,v 1.9 2005/08/25 18:58:14 johnh Exp $ 00051 */ 00052 00053 00054 #ifndef NS_XCPQ_H 00055 #define NS_XCPQ_H 00056 00057 #include "drop-tail.h" 00058 #include "packet.h" 00059 #include "xcp-end-sys.h" 00060 00061 #define INITIAL_Te_VALUE 0.05 // Was 0.3 Be conservative when 00062 // we don't kow the RTT 00063 00064 #define TRACE 1 // when 0, we don't race or write 00065 // var to disk 00066 00067 class XCPWrapQ; 00068 class XCPQueue; 00069 00070 class XCPTimer : public TimerHandler { 00071 public: 00072 XCPTimer(XCPQueue *a, void (XCPQueue::*call_back)() ) 00073 : a_(a), call_back_(call_back) {}; 00074 protected: 00075 virtual void expire (Event *e); 00076 XCPQueue *a_; 00077 void (XCPQueue::*call_back_)(); 00078 }; 00079 00080 00081 class XCPQueue : public DropTail { 00082 friend class XCPTimer; 00083 public: 00084 XCPQueue(); 00085 virtual ~XCPQueue() {} 00086 void Tq_timeout (); // timeout every propagation delay 00087 void Te_timeout (); // timeout every avg. rtt 00088 void everyRTT(); // timeout every highest rtt seen by rtr or some 00089 // preset rtt value 00090 void setupTimers(); // setup timers for xcp queue only 00091 void setEffectiveRtt(double rtt) ; 00092 void routerId(XCPWrapQ* queue, int i); 00093 int routerId(int id = -1); 00094 00095 int limit(int len = 0); 00096 void setBW(double bw); 00097 void setChannel(Tcl_Channel queue_trace_file); 00098 double totalDrops() { return total_drops_; } 00099 00100 void spread_bytes(bool b) { 00101 spread_bytes_ = b; 00102 if (b) 00103 Te_ = BWIDTH; 00104 } 00105 00106 // Overloaded functions 00107 void enque(Packet* pkt); 00108 Packet* deque(); 00109 virtual void drop(Packet* p); 00110 00111 // tracing var 00112 void setNumMice(int mice) {num_mice_ = mice;} 00113 00114 protected: 00115 00116 // Utility Functions 00117 double max(double d1, double d2) { return (d1 > d2) ? d1 : d2; } 00118 double min(double d1, double d2) { return (d1 < d2) ? d1 : d2; } 00119 int max(int i1, int i2) { return (i1 > i2) ? i1 : i2; } 00120 int min(int i1, int i2) { return (i1 < i2) ? i1 : i2; } 00121 double abs(double d) { return (d < 0) ? -d : d; } 00122 00123 virtual void trace_var(char * var_name, double var); 00124 00125 // Estimation & Control Helpers 00126 void init_vars(); 00127 00128 // called in enque, but packet may be dropped; used for 00129 // updating the estimation helping vars such as 00130 // counting the offered_load_, sum_rtt_by_cwnd_ 00131 virtual void do_on_packet_arrival(Packet* pkt); 00132 00133 // called in deque, before packet leaves 00134 // used for writing the feedback in the packet 00135 virtual void do_before_packet_departure(Packet* p); 00136 00137 00138 // ---- Variables -------- 00139 unsigned int routerId_; 00140 XCPWrapQ* myQueue_; //pointer to wrapper queue lying on top 00141 XCPTimer* queue_timer_; 00142 XCPTimer* estimation_control_timer_; 00143 XCPTimer* rtt_timer_; 00144 double link_capacity_bps_; 00145 00146 static const double ALPHA_ = 0.4; 00147 static const double BETA_ = 0.226; 00148 static const double GAMMA_ = 0.1; 00149 static const double XCP_MAX_INTERVAL= 1.0; 00150 static const double XCP_MIN_INTERVAL= .001; 00151 00152 double Te_; // control interval 00153 double Tq_; 00154 double Tr_; 00155 double avg_rtt_; // average rtt of flows 00156 double high_rtt_; // highest rtt seen in flows 00157 double effective_rtt_; // pre-set rtt value 00158 double Cp_; 00159 double Cn_; 00160 double residue_pos_fbk_; 00161 double residue_neg_fbk_; 00162 double queue_bytes_; // our estimate of the fluid model queue 00163 double input_traffic_bytes_; // traffic in Te 00164 double sum_rtt_by_throughput_; 00165 double sum_inv_throughput_; 00166 double running_min_queue_bytes_; 00167 unsigned int num_cc_packets_in_Te_; 00168 00169 bool spread_bytes_; 00170 static const int BSIZE = 4096; 00171 double b_[BSIZE]; 00172 double t_[BSIZE]; 00173 int maxb_; 00174 static const double BWIDTH = 0.01; 00175 int min_queue_ci_; 00176 int max_queue_ci_; 00177 00178 double thruput_elep_; 00179 double thruput_mice_; 00180 double total_thruput_; 00181 int num_mice_; 00182 // drops 00183 int drops_; 00184 double total_drops_ ; 00185 00186 // ----- For Tracing Vars --------------// 00187 Tcl_Channel queue_trace_file_; 00188 00189 }; 00190 00191 00192 #endif //NS_XCPQ_H
1.4.6