/* -*- 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: /usr/src/mash/repository/vint/ns-2/red.h,v 1.14 1998/06/27 01:24:29 gnguyen Exp $ (LBL) * * adapted to REM 01/2000 by lmwang@cs.princeton.edu */ #ifndef ns_REM_h #define ns_REM_h #include "queue.h" #include "timer-handler.h" class LinkDelay; class REMQueue; class AggrRateTimer : public TimerHandler { public: AggrRateTimer(REMQueue *q) : TimerHandler() { q_ = q; } protected: virtual void expire(Event *e); REMQueue *q_; }; /* * early marking parameters, supplied by user */ struct emp { /* * User supplied. */ int mean_pktsize; /* avg pkt size, linked into Tcl */ int bytes; /* true if queue in bytes, false if packets */ double q_w; /* queue weight given to cur q size sample */ int rate_count; double rate_timeout; /* time period to measure input rate */ double delta; /* weight in aggregate input rate est */ double gamma; /* stepsize in price adjustment*/ double alpha_l; /* weight of buffer in price adjustment */ double phi; /* base in marking probability computing */ /* * Computed as a function of user supplied paramters. */ double ptc; /* packet time constant in packets/second */ emp(): ptc(0.0) {} }; /* * Early marking variables, maintained by REM */ struct emv { TracedDouble v_ave; /* average queue size */ TracedDouble v_prob1; /* prob. of packet drop before "count". */ double v_slope; /* used in computing average queue size */ double aggr_input; /* aggregate input rate estimate*/ TracedDouble p_l; /* link price */ TracedDouble m_l; /* current marking probability */ emv() : v_ave(0.0), v_prob1(0.0), v_slope(0.0), aggr_input(0.0), p_l(0.0), m_l(0.){ } }; class REMQueue : public Queue { public: REMQueue(); void timeout(); protected: int command(int argc, const char*const* argv); void enque(Packet* pkt); virtual Packet *pickPacketForECN(Packet* pkt); virtual Packet* pickPacketToDrop(); Packet* deque(); void reset(); void run_estimator(int nqueued, int m); int random_mark(Packet* pkt); void set_rate_timer(); void updatePrice(); LinkDelay* link_; /* outgoing link */ int fifo_; /* fifo queue? */ PacketQueue *q_; /* underlying (usually) FIFO queue */ int bcount_; /* byte count */ int qib_; /* bool: queue measuREM in bytes? */ 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? */ emp emp_; /* early-drop params */ /* * Dynamic state. */ int idle_; /* queue is idle? */ double idletime_; /* if so, since this time */ emv emv_; /* early-marking variables */ double new_aggr_input; /* for rate estimation */ double last_aggr_time; int aggr_bytes; // for calculating new_aggr_input int aggr_count; double cur_buffer; // for current buffer occupancy /* Timer */ AggrRateTimer aggr_timer; void print_emp(); // for debugging void print_emv(); }; #endif