EwmaThroughputSensor.cc 970 Bytes
Newer Older
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
// EwmaThroughputSensor.cc

#include "lib.h"
#include "EwmaThroughputSensor.h"
#include "ThroughputSensor.h"
#include "CommandOutput.h"

using namespace std;

EwmaThroughputSensor::EwmaThroughputSensor(
  ThroughputSensor * newThroughputSource)
  : throughput(0.0)
  , throughputSource(newThroughputSource)
{
}

void EwmaThroughputSensor::localSend(PacketInfo * packet)
{
}

void EwmaThroughputSensor::localAck(PacketInfo * packet)
{
  int latest = throughputSource->getThroughputInKbps();
  if (latest != 0)
  {
    if (throughput == 0.0)
    {
      throughput = latest;
    }
    else
    {
      static const double alpha = 0.1;
      throughput = throughput*(1.0-alpha) + latest*alpha;
    }
    ostringstream buffer;
    buffer << setiosflags(ios::fixed | ios::showpoint) << setprecision(0);
    buffer << "bandwidth=" << throughput;
    global::output->eventMessage(buffer.str(), packet->elab,
                                 CommandOutput::FORWARD_PATH);
  }
}