diff --git a/pelab/magent/EwmaThroughputSensor.cc b/pelab/magent/EwmaThroughputSensor.cc new file mode 100644 index 0000000000000000000000000000000000000000..a7c139fb0401f0d194f2991e730b8c899bb5aa80 --- /dev/null +++ b/pelab/magent/EwmaThroughputSensor.cc @@ -0,0 +1,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); + } +} diff --git a/pelab/magent/EwmaThroughputSensor.h b/pelab/magent/EwmaThroughputSensor.h new file mode 100644 index 0000000000000000000000000000000000000000..075f0bb332884a0c3cbf01f78275f0c2072522d7 --- /dev/null +++ b/pelab/magent/EwmaThroughputSensor.h @@ -0,0 +1,22 @@ +// 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