00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) 1990-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 00037 /* 00038 * Based on PI controller described in: 00039 * C. Hollot, V. Misra, D. Towsley and W. Gong. 00040 * On Designing Improved Controllers for AQM Routers 00041 * Supporting TCP Flows, 00042 * INFOCOMM 2001. 00043 */ 00044 00045 #ifndef ns_pi_h 00046 #define ns_pi_h 00047 00048 #undef setbit 00049 00050 #include "queue.h" 00051 #include "trace.h" 00052 #include "timer-handler.h" 00053 00054 #define DTYPE_NONE 0 /* ok, no drop */ 00055 #define DTYPE_FORCED 1 /* a "forced" drop */ 00056 #define DTYPE_UNFORCED 2 /* an "unforced" (random) drop */ 00057 00058 // Insert APPLE specific macro here 00059 // 00060 #if defined( __MACH__ ) && defined( __APPLE__ ) 00061 #undef setbit 00062 #endif 00063 00064 /* 00065 * Early drop parameters, supplied by user 00066 */ 00067 struct edp_pi { 00068 /* 00069 * User supplied. 00070 */ 00071 int mean_pktsize; /* avg pkt size, linked into Tcl */ 00072 int bytes; /* true if queue in bytes, false if packets */ 00073 int setbit; /* true to set congestion indication bit */ 00074 double a, b; /* parameters to pi controller */ 00075 double w; /* sampling frequency (# of times per second) */ 00076 double qref; /* desired queue size */ 00077 edp_pi(): mean_pktsize(0), bytes(0), setbit(0), a(0.0), b(0.0), w(0.0), qref(0.0) { } 00078 }; 00079 00080 /* 00081 * Early drop variables, maintained by PI 00082 */ 00083 struct edv_pi { 00084 TracedDouble v_prob; /* prob. of packet drop before "count". */ 00085 int count; /* # of packets since last drop */ 00086 int count_bytes; /* # of bytes since last drop */ 00087 int qold; 00088 edv_pi() : v_prob(0.0), count(0), count_bytes(0), qold(0) { } 00089 }; 00090 00091 class LinkDelay; 00092 class PIQueue ; 00093 00094 class PICalcTimer : public TimerHandler { 00095 public: 00096 PICalcTimer(PIQueue *a) : TimerHandler() { a_ = a; } 00097 virtual void expire(Event *e); 00098 protected: 00099 PIQueue *a_; 00100 }; 00101 00102 class PIQueue : public Queue { 00103 00104 friend class PICalcTimer; 00105 public: 00106 PIQueue(const char * = "Drop"); 00107 protected: 00108 int command(int argc, const char*const* argv); 00109 void enque(Packet* pkt); 00110 virtual Packet *pickPacketForECN(Packet* pkt); 00111 virtual Packet *pickPacketToDrop(); 00112 Packet* deque(); 00113 void reset(); 00114 int drop_early(Packet* pkt, int qlen); 00115 double calculate_p(); 00116 PICalcTimer CalcTimer; 00117 00118 LinkDelay* link_; /* outgoing link */ 00119 int fifo_; /* fifo queue? */ 00120 PacketQueue *q_; /* underlying (usually) FIFO queue */ 00121 00122 int qib_; /* bool: queue measured in bytes? */ 00123 NsObject* de_drop_; /* drop_early target */ 00124 00125 //added to be able to trace EDrop Objects - ratul 00126 //the other events - forced drop, enque and deque are traced by a different mechanism. 00127 NsObject * EDTrace; //early drop trace 00128 char traceType[20]; //the preferred type for early drop trace. 00129 //better be less than 19 chars long 00130 Tcl_Channel tchan_; /* place to write trace records */ 00131 TracedInt curq_; /* current qlen seen by arrivals */ 00132 void trace(TracedVar*); /* routine to write trace records */ 00133 00134 edp_pi edp_; /* early-drop params */ 00135 edv_pi edv_; /* early-drop variables */ 00136 00137 int first_reset_; /* first time reset() is called */ 00138 00139 }; 00140 00141 #endif