File: rate-estimator.cc

package info (click to toggle)
ns2 2.35%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 78,780 kB
  • ctags: 27,490
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (48 lines) | stat: -rw-r--r-- 1,168 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "rate-estimator.h"
#include <math.h>

RateEstimator::RateEstimator(): k_(0.1), estRate_(0.0), bytesArr_(0.0), temp_size_(0) {
  prevTime_ = Scheduler::instance().clock();
  reset_time_ = Scheduler::instance().clock();
}

RateEstimator::RateEstimator(double estimate): k_(0.1), bytesArr_(0.0), temp_size_(0) {
  prevTime_ = Scheduler::instance().clock();
  reset_time_ = Scheduler::instance().clock();
  estRate_ = estimate;
}

void
RateEstimator::estimateRate(Packet * pkt) {

  hdr_cmn* hdr  = HDR_CMN(pkt);
  bytesArr_+= hdr->size();
  int pktSize   = hdr->size() << 3; /* length of the packet in bits */
  
  double now = Scheduler::instance().clock();
  double timeGap = ( now - prevTime_);

  if (timeGap == 0) {
    temp_size_ += pktSize;
    return;
  }
  else {
    pktSize+= temp_size_;
    temp_size_ = 0;
  }
	
  prevTime_ = now;
  estRate_ = (1 - exp(-timeGap/k_))*((double)pktSize)/timeGap + exp(-timeGap/k_)*estRate_;
}

  
void
RateEstimator::reset() {
  reset_time_ = Scheduler::instance().clock();
  bytesArr_ = 0;
//shoule the rate estimate be reset?
  //  estRate_=0.0;
  //  prevTime_= Scheduler::instance().clock();
  // temp_size_=0;

}