/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ /* * Copyright (c) 1990-1997 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the Computer Systems * Engineering Group at Lawrence Berkeley Laboratory. * 4. Neither the name of the University nor of the Laboratory may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * Here is one set of parameters from one of my simulations: * * ed [ q_weight=0.002 thresh=5 linterm=30 maxthresh=15 * mean_pktsize=500 dropmech=random-drop queue-size=60 * plot-file=none bytes=false doubleq=false dqthresh=50 * wait=true ] * * 1/"linterm" is the max probability of dropping a packet. * There are different options that make the code * more messy that it would otherwise be. For example, * "doubleq" and "dqthresh" are for a queue that gives priority to * small (control) packets, * "bytes" indicates whether the queue should be measured in bytes * or in packets, * "dropmech" indicates whether the drop function should be random-drop * or drop-tail when/if the queue overflows, and * the commented-out Holt-Winters method for computing the average queue * size can be ignored. * "wait" indicates whether the gateway should wait between dropping * packets. * * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/red.h,v 1.23 2000/07/20 04:56:29 ratul Exp $ (LBL) */ /* * FRED * Author: Srinivas R. Avasarala (Computer Science, Purdue University) * * Note that this code is written based on the paper, D. Lin and R. Morris, * "Dynamics of Random Early Detection," in Proceedings of ACM SIGCOMM, September 1997. */ #ifndef ns_fred_h #define ns_fred_h #include "queue.h" #include "trace.h" class LinkDelay; /* * Early drop parameters, supplied by user */ struct fred_edp { /* * User supplied. */ int mean_pktsize; /* avg pkt size, linked into Tcl */ int bytes; /* true if queue in bytes, false if packets */ int wait; /* true for waiting between dropped packets */ int setbit; /* true to set congestion indication bit */ int gentle; /* true to increases dropping prob. slowly * * when ave queue exceeds maxthresh. */ double th_min; /* minimum threshold of average queue size */ double th_max; /* maximum threshold of average queue size */ double max_p_inv; /* 1/max_p, for max_p = maximum prob. */ double q_w; /* queue weight given to cur q size sample */ double minq; /* added for FRED */ /* * Computed as a function of user supplied paramters. */ double ptc; /* packet time constant in packets/second */ }; /* * Early drop variables, maintained by FRED */ struct fred_edv { TracedDouble v_ave; /* average queue size */ TracedDouble v_prob1; /* prob. of packet drop before "count". */ double v_prob; /* prob. of packet drop */ double v_a; /* v_prob = v_a * v_ave + v_b */ double v_b; double v_c; /* used for "gentle" mode */ double v_d; /* used for "gentle" mode */ int count; /* # of packets since last drop */ int count_bytes; /* # of bytes since last drop */ int old; /* 0 when average queue first exceeds thresh */ double avgcq; /* added for FRED */ double maxq; /* added for FRED */ int Nactive; /* added for FRED */ fred_edv() : v_ave(0.0), v_prob1(0.0), v_prob(0.0), v_a(0.0), v_b(0.0), count(0), count_bytes(0), old(0), avgcq(0.0), maxq(0), Nactive(0) { } }; /* added for FRED */ struct flowv { int state; int fid; int qlen; int strike; }; #define MAX_FLOWS 4000 class FREDQueue : public Queue { public: /* FREDQueue();*/ FREDQueue(const char * = "Drop"); protected: int command(int argc, const char*const* argv); struct flowv* flowlkup(int fid); struct flowv* allocflowstate(int fid); void freeflowstate(int fid); void enque(Packet* pkt); virtual Packet *pickPacketForECN(Packet* pkt); virtual Packet *pickPacketToDrop(); Packet* deque(); void reset(); double estimator(int nqueued, int m, double ave, double q_w); int drop_early(Packet* pkt); double modify_p(double p, int count, int count_bytes, int bytes, int mean_pktsize, int wait, int size); double calculate_p(double v_ave, double th_max, int gentle, double v_a, double v_b, double v_c, double v_d, double max_p_inv); LinkDelay* link_; /* outgoing link */ int fifo_; /* fifo queue? */ PacketQueue *q_; /* underlying (usually) FIFO queue */ int bcount_; /* byte count */ int qib_; /* bool: queue measured in bytes? */ NsObject* de_drop_; /* drop_early target */ //added to be able to trace EDrop Objects - ratul //the other events - forced drop, enque and deque are traced by a different mechanism. NsObject * EDTrace; //early drop trace char traceType[20]; //the preferred type for early drop trace. //better be less than 19 chars long Tcl_Channel tchan_; /* place to write trace records */ TracedInt curq_; /* current qlen seen by arrivals */ void trace(TracedVar*); /* routine to write trace records */ /* * Static state. */ int drop_tail_; /* drop-tail */ int drop_front_; /* drop-from-front */ int drop_rand_; /* drop-tail, or drop random? */ int ns1_compat_; /* for ns-1 compat, bypass a small bugfix */ fred_edp edp_; /* early-drop params */ /* * Dynamic state. */ int idle_; /* queue is idle? */ double idletime_; /* if so, since this time */ fred_edv edv_; /* early-drop variables */ int first_reset_; /* first time reset() is called */ int which_; struct flowv flowv_[MAX_FLOWS]; void print_edp(); // for debugging void print_edv(); // for debugging }; #endif