From 95b55c3a4a708a7e564f31b76f25b0132dd221a8 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 23 Aug 2023 13:04:54 +0200 Subject: [PATCH] cca interface --- CMakeLists.txt | 1 + solanaceae/ngc_ft1/cca.hpp | 56 +++++++++++++++++++++++++++++++++++ solanaceae/ngc_ft1/ledbat.cpp | 2 +- solanaceae/ngc_ft1/ledbat.hpp | 18 ++++++----- solanaceae/ngc_ft1/ngcft1.hpp | 2 +- 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 solanaceae/ngc_ft1/cca.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9afa7ba..763db96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ add_library(solanaceae_ngcft1 ./solanaceae/ngc_ft1/ngcft1.hpp ./solanaceae/ngc_ft1/ngcft1.cpp + ./solanaceae/ngc_ft1/cca.hpp ./solanaceae/ngc_ft1/ledbat.hpp ./solanaceae/ngc_ft1/ledbat.cpp diff --git a/solanaceae/ngc_ft1/cca.hpp b/solanaceae/ngc_ft1/cca.hpp new file mode 100644 index 0000000..aa017bf --- /dev/null +++ b/solanaceae/ngc_ft1/cca.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include +#include + +struct CCAI { + public: // config + using SeqIDType = std::pair; // 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 + float max_byterate_allowed {10*1024*1024}; // 10MiB/s + + public: // api + CCAI(size_t maximum_segment_data_size) : MAXIMUM_SEGMENT_DATA_SIZE(maximum_segment_data_size) {} + + // return the current believed window in bytes of how much data can be inflight, + virtual float getCWnD(void) const = 0; + + // TODO: api for how much data we should send + // take time since last sent into account + // respect max_byterate_allowed + virtual size_t canSend(void) const = 0; + + // get the list of timed out seq_ids + virtual std::vector getTimeouts(void) const = 0; + + public: // callbacks + // data size is without overhead + virtual void onSent(SeqIDType seq, size_t data_size) = 0; + + // TODO: copy??? + virtual void onAck(std::vector seqs) = 0; + + // if discard, not resent, not inflight + virtual void onLoss(SeqIDType seq, bool discard) = 0; +}; + diff --git a/solanaceae/ngc_ft1/ledbat.cpp b/solanaceae/ngc_ft1/ledbat.cpp index 5f7c5d5..49e8580 100644 --- a/solanaceae/ngc_ft1/ledbat.cpp +++ b/solanaceae/ngc_ft1/ledbat.cpp @@ -15,7 +15,7 @@ inline constexpr bool PLOTTING = false; -LEDBAT::LEDBAT(size_t maximum_segment_data_size) : MAXIMUM_SEGMENT_DATA_SIZE(maximum_segment_data_size) { +LEDBAT::LEDBAT(size_t maximum_segment_data_size) : CCAI(maximum_segment_data_size) { _time_start_offset = clock::now(); } diff --git a/solanaceae/ngc_ft1/ledbat.hpp b/solanaceae/ngc_ft1/ledbat.hpp index d39e2b4..6113550 100644 --- a/solanaceae/ngc_ft1/ledbat.hpp +++ b/solanaceae/ngc_ft1/ledbat.hpp @@ -1,5 +1,7 @@ #pragma once +#include "./cca.hpp" + #include #include #include @@ -9,8 +11,9 @@ // LEDBAT++: https://www.ietf.org/archive/id/draft-irtf-iccrg-ledbat-plus-plus-01.txt // LEDBAT++ implementation -struct LEDBAT { +struct LEDBAT : public CCAI{ public: // config +#if 0 using SeqIDType = std::pair; // tf_id, seq_id static constexpr size_t IPV4_HEADER_SIZE {20}; @@ -32,6 +35,7 @@ struct LEDBAT { //static constexpr size_t maximum_segment_size {496 + segment_overhead}; // tox 500 - 4 from ft 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 +#endif // ledbat++ says 60ms, we might need other values if relayed //const float target_delay {0.060f}; @@ -50,26 +54,26 @@ struct LEDBAT { // return the current believed window in bytes of how much data can be inflight, // without overstepping the delay requirement - float getCWnD(void) const { + float getCWnD(void) const override { return _cwnd; } // TODO: api for how much data we should send // take time since last sent into account // respect max_byterate_allowed - size_t canSend(void) const; + size_t canSend(void) const override; // get the list of timed out seq_ids - std::vector getTimeouts(void) const; + std::vector getTimeouts(void) const override; public: // callbacks // data size is without overhead - void onSent(SeqIDType seq, size_t data_size); + void onSent(SeqIDType seq, size_t data_size) override; - void onAck(std::vector seqs); + void onAck(std::vector seqs) override; // if discard, not resent, not inflight - void onLoss(SeqIDType seq, bool discard); + void onLoss(SeqIDType seq, bool discard) override; private: using clock = std::chrono::steady_clock; diff --git a/solanaceae/ngc_ft1/ngcft1.hpp b/solanaceae/ngc_ft1/ngcft1.hpp index 9ed1e87..160f632 100644 --- a/solanaceae/ngc_ft1/ngcft1.hpp +++ b/solanaceae/ngc_ft1/ngcft1.hpp @@ -139,7 +139,7 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider struct Group { struct Peer { - std::unique_ptr cca = std::make_unique(500-4); // TODO: replace with tox_group_max_custom_lossy_packet_length()-4 + std::unique_ptr cca = std::make_unique(500-4); // TODO: replace with tox_group_max_custom_lossy_packet_length()-4 struct RecvTransfer { uint32_t file_kind;