/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ /* * Copyright (c) 2001 University of Mannheim, Praktische Informatik IV * 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 Praktische Informatik IV, * University of Mannheim. * 4. Neither the name of Praktische Informatik IV nor of University of * Mannheim may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY U. MANNHEIM 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 U. MANNHEIM 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. */ #include "agent.h" #include "packet.h" #include "ip.h" #include "timer-handler.h" #include "random.h" #include "pcc.h" #define LARGE_DOUBLE 9999999999.99 //potential Year 2287 problem :-) #define SAMLLFLOAT 0.0000001 /* packet status */ #define UNKNOWN 0 #define RCVD 1 #define LOSS_EVENT 2 #define NOLOSS 3 #define LOSS 4 #define DEFAULT_NUMSAMPLES 8 class PccSinkAgent; class PccNackTimer : public TimerHandler { public: PccNackTimer(PccSinkAgent *a) : TimerHandler() { a_ = a; } virtual void expire(Event *e); protected: PccSinkAgent *a_; }; class PccReExpTimer : public TimerHandler { //timer for next experiment (continuous evalutation) public: PccReExpTimer(PccSinkAgent *a) : TimerHandler() { a_ = a; } virtual void expire(Event *e); protected: PccSinkAgent *a_; }; class PccOffTimer : public TimerHandler { //timer for turning an off flow back on public: PccOffTimer(PccSinkAgent *a) : TimerHandler() { a_ = a; } virtual void expire(Event *e); protected: PccSinkAgent *a_; }; class PccSinkAgent : public Agent { friend PccNackTimer; friend PccReExpTimer; friend PccOffTimer; public: PccSinkAgent(); void recv(Packet*, Handler*); int command(int argc, const char*const* argv); void stop(); protected: void sendpkt(); void nextpkt(); double est_loss(); void print_loss(int sample, double ave_interval); void print_loss_all(int *sample); void shift_array(int *a, int sz, int defval) ; void shift_array(double *a, int sz, double defval) ; void multiply_array(double *a, int sz, double multiplier); void init_WALI(); double weighted_average(int start, int end, double factor, double *m, double *w, int *sample); void update_rtt(double tao, double now); void init_vectors(hdr_pcc *pcch, double now); //PCC-specific void init_pcc_values(); void experiment(); void est_rate(); //common variables PccNackTimer nack_timer_; PccReExpTimer reexp_timer_; PccOffTimer off_timer_; int psize_; // size of received packet double rtt_; // smoothed rtt value //-- reported by sender double sqrtrtt_; // smoothed square root of measured rtt double reported_rtt_; // last rtt reported to sender int smooth_; // for the smoother method for incorporating // new loss intervals int UrgentFlag ; // send loss report immediately int total_received_; // total # of pkts rcvd by rcvr int bval_; // value of B used in the formula double last_report_sent; // when was last feedback sent double NumFeedback_; // how many feedbacks per rtt int printLoss_; // to print estimated loss rates int maxseq; // max seq number seen // these assist in keep track of incoming packets and calculate flost_ double last_timestamp_, last_arrival_; int hsz; char *lossvec_; double *rtvec_; double *tsvec_; int lastloss_round_id ; int round_id ; double lastloss; // when last loss occured // WALI specific int numsamples ; int *sample; double *weights ; double *mult ; double mult_factor_; // most recent multiple of mult array int sample_count ; int last_sample ; //seq-nr at which last WALI sample was taken int init_WALI_flag; int discount ; // emphasize most recent loss interval double df_; // decay factor for accurate RTT estimate // when it is very large double rate_; //PCC-specific variables //application parameters int protLossEvents; //number of loss events required for good estimate int protRTTs; //number of rtt samples required for good estimate double protMaxTime; //maximum protected time allowed (optional) double Toff; //time flows are to stay off before the next experiment double Texp; //time until next experiment (ongoing evaluation) double rateDiscount; //EWMA-factor for rate estimation //variables int on; // 1 if sender may send, 0 otherwise int protect; //is always turned on when a flow stops (not just before it restarts!) double protected_time; //time since the first packet of protected time double protected_start; //time when first packet of protected time arrived int protected_losses; //number of loss events since first packet of protected time int protected_rounds; //number of rounds (=> rtt samples) in protected time double exp_failed_time; //the time when the last experiment failed double *pwindow; //window of previous Toff/Texp prob values (if <1) double *p_ts_window; //keeps the timestamps of the prob values int wsize; //size of pwindow int discard_after; //seqno after which all packets will be discarded, none if < 0 double sendrate; //estimated smoothed sending rate int rcv_while_off; //receive the packets the sender sent before receiving our off packet double lossrate; //current smoothed loss rate (as opposed to loss event rate) int adjust_rate; //do we use the tcprate adjustment hack? int noAckCount; //used in sendpkt to determine whether to send an ACK to a quiescent sender int flowID; double runtime_; //for testing purposes int pcc_recv_nr_; //JCW int always_on_; //JCW };