2023-08-24 18:04:25 +02:00
|
|
|
#include "./cubic.hpp"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
float CUBIC::getCWnD(void) const {
|
|
|
|
const double K = cbrt(
|
|
|
|
(_window_max * (1. - BETA)) / SCALING_CONSTANT
|
|
|
|
);
|
|
|
|
|
2023-08-30 13:45:09 +02:00
|
|
|
const double time_since_reduction = getTimeNow() - _time_point_reduction;
|
2023-08-30 03:03:43 +02:00
|
|
|
|
|
|
|
const double TK = time_since_reduction - K;
|
2023-08-24 18:04:25 +02:00
|
|
|
|
|
|
|
const double cwnd =
|
|
|
|
SCALING_CONSTANT
|
|
|
|
* TK * TK * TK // TK^3
|
|
|
|
+ _window_max
|
|
|
|
;
|
|
|
|
|
2023-08-30 13:45:09 +02:00
|
|
|
#if 0
|
2023-08-30 03:03:43 +02:00
|
|
|
std::cout
|
|
|
|
<< "K:" << K
|
|
|
|
<< " ts:" << time_since_reduction
|
|
|
|
<< " TK:" << TK
|
|
|
|
<< " cwnd:" << cwnd
|
|
|
|
<< " rtt:" << getCurrentDelay()
|
|
|
|
<< "\n"
|
|
|
|
;
|
2023-08-30 13:45:09 +02:00
|
|
|
#endif
|
2023-08-24 18:04:25 +02:00
|
|
|
|
2023-08-30 03:03:43 +02:00
|
|
|
return std::max<float>(cwnd, 2.f * MAXIMUM_SEGMENT_SIZE);
|
2023-08-24 18:04:25 +02:00
|
|
|
}
|
|
|
|
|
2023-08-30 03:03:43 +02:00
|
|
|
void CUBIC::onCongestion(void) {
|
2023-08-30 13:45:09 +02:00
|
|
|
if (getTimeNow() - _time_point_reduction >= getCurrentDelay()) {
|
|
|
|
const auto current_cwnd = getCWnD();
|
|
|
|
_time_point_reduction = getTimeNow();
|
|
|
|
_window_max = current_cwnd;
|
2023-08-24 18:04:25 +02:00
|
|
|
|
2023-08-30 13:45:09 +02:00
|
|
|
std::cout << "CONGESTION! cwnd:" << current_cwnd << "\n";
|
|
|
|
}
|
2023-08-24 18:04:25 +02:00
|
|
|
}
|
|
|
|
|
2023-08-29 18:21:12 +02:00
|
|
|
size_t CUBIC::canSend(void) {
|
2023-08-30 13:45:09 +02:00
|
|
|
const auto fspace_pkgs = FlowOnly::canSend();
|
2023-08-24 18:04:25 +02:00
|
|
|
|
2023-08-30 13:45:09 +02:00
|
|
|
if (fspace_pkgs == 0u) {
|
|
|
|
return 0u;
|
2023-08-30 03:03:43 +02:00
|
|
|
}
|
2023-08-24 18:04:25 +02:00
|
|
|
|
2023-08-30 13:45:09 +02:00
|
|
|
const int64_t cspace_bytes = getCWnD() - _in_flight_bytes;
|
|
|
|
if (cspace_bytes < MAXIMUM_SEGMENT_DATA_SIZE) {
|
2023-08-30 03:03:43 +02:00
|
|
|
return 0u;
|
|
|
|
}
|
2023-08-24 18:04:25 +02:00
|
|
|
|
2023-08-30 03:03:43 +02:00
|
|
|
// limit to whole packets
|
2023-08-30 13:45:09 +02:00
|
|
|
size_t cspace_pkgs = std::floor(cspace_bytes / MAXIMUM_SEGMENT_DATA_SIZE) * MAXIMUM_SEGMENT_DATA_SIZE;
|
2023-08-24 18:04:25 +02:00
|
|
|
|
2023-08-30 13:45:09 +02:00
|
|
|
return std::min(cspace_pkgs, fspace_pkgs);
|
2023-08-24 18:04:25 +02:00
|
|
|
}
|
|
|
|
|