congestion: add leaky bucket, not interfaced yet.

This commit is contained in:
Théophile Bastian 2020-07-22 14:08:30 +02:00
parent c23741bea3
commit 3f4e5ee227
2 changed files with 18 additions and 4 deletions

View file

@ -7,7 +7,9 @@ CongestionController::CongestionController(const VpnPeer& peer):
_last_seqno = _peer.get_loss_logger().get_cur_seqno(); _last_seqno = _peer.get_loss_logger().get_cur_seqno();
_loss_based.bandwidth = 3e5; // 300kBps seems a good value to start with _loss_based.bandwidth = 3e5; // 300kBps seems a good value to start with
_loss_based.prev_tot_sent = _peer.get_tot_bytes_sent(); _loss_based.prev_tot_sent = _peer.get_tot_bytes_sent();
_loss_based.prev_time = std::chrono::steady_clock::now(); _last_bucket_update = _loss_based.prev_time =
std::chrono::steady_clock::now();
update_params();
} }
void CongestionController::update_lossbased() { void CongestionController::update_lossbased() {
@ -35,8 +37,12 @@ void CongestionController::update_lossbased() {
} }
else if(loss_rate >= 0.1) else if(loss_rate >= 0.1)
_loss_based.bandwidth *= (1 - 0.5 * loss_rate); _loss_based.bandwidth *= (1 - 0.5 * loss_rate);
update_params();
} }
uint64_t CongestionController::get_bandwidth() const { void CongestionController::update_params() {
return _loss_based.bandwidth; _bandwidth = _loss_based.bandwidth; // meant to integrate other controllers
_bucket_max_level = _bandwidth * _peer.get_rtt().avg_rtt();
_bucket_level = std::min(_bucket_level, _bucket_max_level);
} }

View file

@ -18,14 +18,22 @@ class CongestionController {
void update_lossbased(); void update_lossbased();
uint64_t get_bandwidth() const; uint64_t get_bandwidth() const { return _bandwidth; }
uint64_t get_lossbased_bandwidth() const { uint64_t get_lossbased_bandwidth() const {
return _loss_based.bandwidth; } return _loss_based.bandwidth; }
private: // meth
void update_params(); ///< called after an update
private: private:
const VpnPeer& _peer; const VpnPeer& _peer;
LossBased _loss_based; LossBased _loss_based;
uint64_t _bandwidth; // Bps
uint32_t _last_seqno; // seqno at the last update time uint32_t _last_seqno; // seqno at the last update time
uint64_t _bucket_level, ///< implements a leaky bucket
_bucket_max_level; // bandwidth * RTT
std::chrono::steady_clock::time_point _last_bucket_update;
}; };