Commit bea13523 authored by Jonathon Duerig's avatar Jonathon Duerig

Whoops! The ewma sensor itself.

parent 7877d27a
// 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);
}
}
// EwmaThroughputSensor.h
#ifndef EWMA_THROUGHPUT_SENSOR_H_STUB_2
#define EWMA_THROUGHPUT_SENSOR_H_STUB_2
#include "Sensor.h"
class ThroughputSensor;
class EwmaThroughputSensor : public Sensor
{
public:
EwmaThroughputSensor(ThroughputSensor * newThroughputSource);
protected:
virtual void localSend(PacketInfo * packet);
virtual void localAck(PacketInfo * packet);
private:
double throughput;
ThroughputSensor * throughputSource;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment