rate-estimator.cc

Go to the documentation of this file.
00001 #include "rate-estimator.h"
00002 #include <math.h>
00003 
00004 RateEstimator::RateEstimator(): k_(0.1), estRate_(0.0), bytesArr_(0.0), temp_size_(0) {
00005   prevTime_ = Scheduler::instance().clock();
00006   reset_time_ = Scheduler::instance().clock();
00007 }
00008 
00009 RateEstimator::RateEstimator(double estimate): k_(0.1), bytesArr_(0.0), temp_size_(0) {
00010   prevTime_ = Scheduler::instance().clock();
00011   reset_time_ = Scheduler::instance().clock();
00012   estRate_ = estimate;
00013 }
00014 
00015 void
00016 RateEstimator::estimateRate(Packet * pkt) {
00017 
00018   hdr_cmn* hdr  = HDR_CMN(pkt);
00019   bytesArr_+= hdr->size();
00020   int pktSize   = hdr->size() << 3; /* length of the packet in bits */
00021   
00022   double now = Scheduler::instance().clock();
00023   double timeGap = ( now - prevTime_);
00024 
00025   if (timeGap == 0) {
00026     temp_size_ += pktSize;
00027     return;
00028   }
00029   else {
00030     pktSize+= temp_size_;
00031     temp_size_ = 0;
00032   }
00033     
00034   prevTime_ = now;
00035   estRate_ = (1 - exp(-timeGap/k_))*((double)pktSize)/timeGap + exp(-timeGap/k_)*estRate_;
00036 }
00037 
00038   
00039 void
00040 RateEstimator::reset() {
00041   reset_time_ = Scheduler::instance().clock();
00042   bytesArr_ = 0;
00043 //shoule the rate estimate be reset?
00044   //  estRate_=0.0;
00045   //  prevTime_= Scheduler::instance().clock();
00046   // temp_size_=0;
00047 
00048 }

Generated on Tue Mar 6 16:47:49 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6