solanaceae_ngc_ft1/solanaceae/ngc_ft1/cca.hpp

80 lines
2.6 KiB
C++
Raw Permalink Normal View History

2023-08-23 13:04:54 +02:00
#pragma once
#include <vector>
#include <cstdint>
2023-08-24 18:06:26 +02:00
#include <cstddef>
2023-08-23 13:04:54 +02:00
2023-08-24 18:04:25 +02:00
// TODO: refactor, more state tracking in ccai and seperate into flow and congestion algos
inline bool isSkipSeqID(const std::pair<uint8_t, uint16_t>& a, const std::pair<uint8_t, uint16_t>& b) {
// this is not perfect, would need more ft id based history
if (a.first != b.first) {
return false; // we dont know
} else {
return a.second+1 != b.second;
}
}
2023-08-23 13:04:54 +02:00
struct CCAI {
public: // config
using SeqIDType = std::pair<uint8_t, uint16_t>; // tf_id, seq_id
static constexpr size_t IPV4_HEADER_SIZE {20};
static constexpr size_t IPV6_HEADER_SIZE {40}; // bru
static constexpr size_t UDP_HEADER_SIZE {8};
// TODO: tcp AND IPv6 will be different
static constexpr size_t SEGMENT_OVERHEAD {
4+ // ft overhead
46+ // tox?
UDP_HEADER_SIZE+
IPV4_HEADER_SIZE
};
// TODO: make configurable, set with tox ngc lossy packet size
//const size_t MAXIMUM_SEGMENT_DATA_SIZE {1000-4};
const size_t MAXIMUM_SEGMENT_DATA_SIZE {500-4};
const size_t MAXIMUM_SEGMENT_SIZE {MAXIMUM_SEGMENT_DATA_SIZE + SEGMENT_OVERHEAD}; // tox 500 - 4 from ft
//static_assert(maximum_segment_size == 574); // mesured in wireshark
// flow control
2023-12-13 19:38:55 +01:00
//float max_byterate_allowed {100.f*1024*1024}; // 100MiB/s
float max_byterate_allowed {10.f*1024*1024}; // 10MiB/s
//float max_byterate_allowed {1.f*1024*1024}; // 1MiB/s
//float max_byterate_allowed {0.6f*1024*1024}; // 600KiB/s
//float max_byterate_allowed {0.5f*1024*1024}; // 500KiB/s
//float max_byterate_allowed {0.15f*1024*1024}; // 150KiB/s
//float max_byterate_allowed {0.05f*1024*1024}; // 50KiB/s
2023-08-23 13:04:54 +02:00
public: // api
CCAI(size_t maximum_segment_data_size) : MAXIMUM_SEGMENT_DATA_SIZE(maximum_segment_data_size) {}
virtual ~CCAI(void) {}
2023-08-23 13:04:54 +02:00
2023-09-01 17:34:05 +02:00
// returns current rtt/delay
virtual float getCurrentDelay(void) const = 0;
// return the current believed window in bytes of how much data can be inflight,
2023-09-08 00:41:25 +02:00
virtual float getWindow(void) = 0;
2023-08-23 13:04:54 +02:00
// TODO: api for how much data we should send
// take time since last sent into account
// respect max_byterate_allowed
virtual int64_t canSend(float time_delta) = 0;
2023-08-23 13:04:54 +02:00
// get the list of timed out seq_ids
virtual std::vector<SeqIDType> getTimeouts(void) const = 0;
virtual int64_t inFlightCount(void) const { return -1; }
2023-08-23 13:04:54 +02:00
public: // callbacks
// data size is without overhead
virtual void onSent(SeqIDType seq, size_t data_size) = 0;
// TODO: copy???
virtual void onAck(std::vector<SeqIDType> seqs) = 0;
// if discard, not resent, not inflight
virtual void onLoss(SeqIDType seq, bool discard) = 0;
};