From 4ee5dd6ca5c85d04aaf15d3394f71c10880ab2b5 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 30 Aug 2023 13:45:09 +0200 Subject: [PATCH] cubic almost working, general fixes --- solanaceae/ngc_ft1/cubic.cpp | 29 ++++++++++++++++------------- solanaceae/ngc_ft1/flow_only.cpp | 5 +++-- solanaceae/ngc_ft1/ngcft1.cpp | 25 ++++++++++++------------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/solanaceae/ngc_ft1/cubic.cpp b/solanaceae/ngc_ft1/cubic.cpp index 2c5ccfd..b538802 100644 --- a/solanaceae/ngc_ft1/cubic.cpp +++ b/solanaceae/ngc_ft1/cubic.cpp @@ -8,7 +8,7 @@ float CUBIC::getCWnD(void) const { (_window_max * (1. - BETA)) / SCALING_CONSTANT ); - const auto time_since_reduction = getTimeNow() - _time_point_reduction; + const double time_since_reduction = getTimeNow() - _time_point_reduction; const double TK = time_since_reduction - K; @@ -18,6 +18,7 @@ float CUBIC::getCWnD(void) const { + _window_max ; +#if 0 std::cout << "K:" << K << " ts:" << time_since_reduction @@ -26,34 +27,36 @@ float CUBIC::getCWnD(void) const { << " rtt:" << getCurrentDelay() << "\n" ; +#endif return std::max(cwnd, 2.f * MAXIMUM_SEGMENT_SIZE); } void CUBIC::onCongestion(void) { - const auto current_cwnd = getCWnD(); - _time_point_reduction = getTimeNow(); - _window_max = current_cwnd; + if (getTimeNow() - _time_point_reduction >= getCurrentDelay()) { + const auto current_cwnd = getCWnD(); + _time_point_reduction = getTimeNow(); + _window_max = current_cwnd; - //std::cout << "CONGESTION!\n"; + std::cout << "CONGESTION! cwnd:" << current_cwnd << "\n"; + } } size_t CUBIC::canSend(void) { - const auto flow_space = FlowOnly::canSend(); + const auto fspace_pkgs = FlowOnly::canSend(); - if (flow_space == 0) { - return 0; + if (fspace_pkgs == 0u) { + return 0u; } - const int64_t cspace = getCWnD() - _in_flight_bytes; - if (cspace < MAXIMUM_SEGMENT_DATA_SIZE) { + const int64_t cspace_bytes = getCWnD() - _in_flight_bytes; + if (cspace_bytes < MAXIMUM_SEGMENT_DATA_SIZE) { return 0u; } // limit to whole packets - size_t space = std::ceil(cspace / MAXIMUM_SEGMENT_DATA_SIZE) - * MAXIMUM_SEGMENT_DATA_SIZE; + size_t cspace_pkgs = std::floor(cspace_bytes / MAXIMUM_SEGMENT_DATA_SIZE) * MAXIMUM_SEGMENT_DATA_SIZE; - return std::min(space, flow_space); + return std::min(cspace_pkgs, fspace_pkgs); } diff --git a/solanaceae/ngc_ft1/flow_only.cpp b/solanaceae/ngc_ft1/flow_only.cpp index cedaae1..5bbfe43 100644 --- a/solanaceae/ngc_ft1/flow_only.cpp +++ b/solanaceae/ngc_ft1/flow_only.cpp @@ -19,6 +19,8 @@ void FlowOnly::updateWindow(void) { _fwnd = max_byterate_allowed * current_delay; //_fwnd *= 1.3f; // try do balance conservative algo a bit, current_delay + + _fwnd = std::max(_fwnd, 2.f * MAXIMUM_SEGMENT_DATA_SIZE); } size_t FlowOnly::canSend(void) { @@ -35,7 +37,7 @@ size_t FlowOnly::canSend(void) { } // limit to whole packets - size_t space = std::ceil(fspace / MAXIMUM_SEGMENT_DATA_SIZE) + size_t space = std::floor(fspace / MAXIMUM_SEGMENT_DATA_SIZE) * MAXIMUM_SEGMENT_DATA_SIZE; return space; @@ -85,7 +87,6 @@ void FlowOnly::onAck(std::vector seqs) { if (it != _in_flight.end()) { if (it != _in_flight.begin()) { // not next expected seq -> skip detected - // TODO: congestion event std::cout << "CONGESTION out of order\n"; onCongestion(); diff --git a/solanaceae/ngc_ft1/ngcft1.cpp b/solanaceae/ngc_ft1/ngcft1.cpp index 409d18d..2e33308 100644 --- a/solanaceae/ngc_ft1/ngcft1.cpp +++ b/solanaceae/ngc_ft1/ngcft1.cpp @@ -563,7 +563,8 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) { } // send acks - std::vector ack_seq_ids(transfer.rsb.ack_seq_ids.cbegin(), transfer.rsb.ack_seq_ids.cend()); + // reverse, last seq is most recent + std::vector ack_seq_ids(transfer.rsb.ack_seq_ids.crbegin(), transfer.rsb.ack_seq_ids.crend()); // TODO: check if this caps at max acks if (!ack_seq_ids.empty()) { // TODO: check return value @@ -588,7 +589,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) { bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data_ack& e) { #if !NDEBUG - std::cout << "NGCFT1: FT1_DATA_ACK\n"; + //std::cout << "NGCFT1: FT1_DATA_ACK\n"; #endif if (!groups.count(e.group_number)) { @@ -610,20 +611,17 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data_ack& e) { return true; } - //if ((length - curser) % sizeof(uint16_t) != 0) { - //fprintf(stderr, "FT: data_ack with misaligned data\n"); - //return; - //} - transfer.time_since_activity = 0.f; - std::vector seqs; - for (const auto it : e.sequence_ids) { - // TODO: improve this o.o - seqs.push_back({e.transfer_id, it}); - transfer.ssb.erase(it); + { + std::vector seqs; + for (const auto it : e.sequence_ids) { + // TODO: improve this o.o + seqs.push_back({e.transfer_id, it}); + transfer.ssb.erase(it); + } + peer.cca->onAck(std::move(seqs)); } - peer.cca->onAck(seqs); // delete if all packets acked if (transfer.file_size == transfer.file_size_current && transfer.ssb.size() == 0) { @@ -635,6 +633,7 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data_ack& e) { e.transfer_id, } ); + // TODO: check for FINISHING state peer.send_transfers[e.transfer_id].reset(); }