solanaceae_ngc_ft1/solanaceae/ngc_ft1/flow_only.hpp

88 lines
2.3 KiB
C++
Raw Normal View History

2023-08-29 18:21:12 +02:00
#pragma once
#include "./cca.hpp"
#include <chrono>
#include <vector>
#include <tuple>
struct FlowOnly : public CCAI {
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
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};
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()};
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
2023-09-08 00:41:25 +02:00
float getWindow(void) override;
2023-08-29 18:21:12 +02:00
void addRTT(float new_delay);
void updateWindow(void);
virtual void onCongestion(void) {};
// 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) {}
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
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;
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;
};