2023-08-29 18:21:12 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "./cca.hpp"
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
struct FlowOnly : public CCAI {
|
2023-08-30 03:03:43 +02:00
|
|
|
protected:
|
|
|
|
using clock = std::chrono::steady_clock;
|
2023-08-29 18:21:12 +02:00
|
|
|
|
|
|
|
public: // config
|
2023-09-01 15:51:28 +02:00
|
|
|
static constexpr float RTT_EMA_ALPHA = 0.001f; // might need change over time
|
|
|
|
static constexpr float RTT_UP_MAX = 3.0f; // how much larger a delay can be to be taken into account
|
2023-08-29 18:21:12 +02:00
|
|
|
static constexpr float RTT_MAX = 2.f; // 2 sec is probably too much
|
|
|
|
|
2023-08-30 03:03:43 +02:00
|
|
|
protected:
|
2023-08-29 18:21:12 +02:00
|
|
|
// initialize to low value, will get corrected very fast
|
|
|
|
float _fwnd {0.01f * max_byterate_allowed}; // in bytes
|
|
|
|
|
|
|
|
// rtt exponental moving average
|
|
|
|
float _rtt_ema {0.1f};
|
|
|
|
|
|
|
|
// list of sequence ids and timestamps of when they where sent (and payload size)
|
2023-09-02 13:28:32 +02:00
|
|
|
struct FlyingBunch {
|
|
|
|
SeqIDType id;
|
|
|
|
float timestamp;
|
|
|
|
size_t bytes;
|
|
|
|
|
|
|
|
// set to true if counted as ce or resent due to timeout
|
|
|
|
bool ignore {false};
|
|
|
|
};
|
|
|
|
std::vector<FlyingBunch> _in_flight;
|
2023-08-29 18:21:12 +02:00
|
|
|
int64_t _in_flight_bytes {0};
|
2024-10-31 12:35:32 +01:00
|
|
|
int64_t _in_flight_bytes_accounted {0};
|
2023-08-29 18:21:12 +02:00
|
|
|
|
2023-09-07 12:26:54 +02:00
|
|
|
int32_t _consecutive_events {0};
|
|
|
|
|
2023-08-29 18:21:12 +02:00
|
|
|
clock::time_point _time_start_offset;
|
|
|
|
|
2024-05-27 11:31:36 +02:00
|
|
|
// used to clamp growth rate in the void
|
|
|
|
double _time_point_last_update {getTimeNow()};
|
|
|
|
|
2023-08-30 03:03:43 +02:00
|
|
|
protected:
|
2023-08-29 18:21:12 +02:00
|
|
|
// make values relative to algo start for readability (and precision)
|
|
|
|
// get timestamp in seconds
|
|
|
|
double getTimeNow(void) const {
|
|
|
|
return std::chrono::duration<double>{clock::now() - _time_start_offset}.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
// moving avg over the last few delay samples
|
|
|
|
// VERY sensitive to bundling acks
|
2023-09-01 17:34:05 +02:00
|
|
|
float getCurrentDelay(void) const override;
|
2023-08-29 18:21:12 +02:00
|
|
|
|
2024-07-12 13:14:24 +02:00
|
|
|
// call updateWindow() to update this value
|
|
|
|
float getWindow(void) const override;
|
2023-09-08 00:41:25 +02:00
|
|
|
|
2023-08-29 18:21:12 +02:00
|
|
|
void addRTT(float new_delay);
|
|
|
|
|
|
|
|
void updateWindow(void);
|
|
|
|
|
2024-10-31 12:35:32 +01:00
|
|
|
void updateAccounted(void);
|
|
|
|
|
2023-08-30 03:03:43 +02:00
|
|
|
virtual void onCongestion(void) {};
|
|
|
|
|
2024-01-11 00:48:57 +01:00
|
|
|
// internal logic, calls the onCongestion() event
|
|
|
|
void updateCongestion(void);
|
|
|
|
|
2023-08-29 18:21:12 +02:00
|
|
|
public: // api
|
|
|
|
FlowOnly(size_t maximum_segment_data_size) : CCAI(maximum_segment_data_size) {}
|
2024-03-05 16:48:58 +01:00
|
|
|
virtual ~FlowOnly(void) {}
|
2023-08-29 18:21:12 +02:00
|
|
|
|
|
|
|
// TODO: api for how much data we should send
|
|
|
|
// take time since last sent into account
|
|
|
|
// respect max_byterate_allowed
|
2024-01-07 17:23:06 +01:00
|
|
|
int64_t canSend(float time_delta) override;
|
2023-08-29 18:21:12 +02:00
|
|
|
|
|
|
|
// get the list of timed out seq_ids
|
|
|
|
std::vector<SeqIDType> getTimeouts(void) const override;
|
|
|
|
|
2024-05-31 17:03:22 +02:00
|
|
|
int64_t inFlightCount(void) const override;
|
2024-07-12 13:14:24 +02:00
|
|
|
int64_t inFlightBytes(void) const override;
|
2024-10-31 12:35:32 +01:00
|
|
|
int64_t inFlightBytesAccounted(void) const override;
|
2024-05-31 17:03:22 +02:00
|
|
|
|
2023-08-29 18:21:12 +02:00
|
|
|
public: // callbacks
|
|
|
|
// data size is without overhead
|
|
|
|
void onSent(SeqIDType seq, size_t data_size) override;
|
|
|
|
|
|
|
|
void onAck(std::vector<SeqIDType> seqs) override;
|
|
|
|
|
|
|
|
// if discard, not resent, not inflight
|
|
|
|
void onLoss(SeqIDType seq, bool discard) override;
|
|
|
|
};
|
|
|
|
|