cubic almost working, general fixes

This commit is contained in:
Green Sky 2023-08-30 13:45:09 +02:00
parent 0d49752c3e
commit 4ee5dd6ca5
No known key found for this signature in database
3 changed files with 31 additions and 28 deletions

View File

@ -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<float>(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);
}

View File

@ -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<SeqIDType> 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();

View File

@ -563,7 +563,8 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) {
}
// send acks
std::vector<uint16_t> ack_seq_ids(transfer.rsb.ack_seq_ids.cbegin(), transfer.rsb.ack_seq_ids.cend());
// reverse, last seq is most recent
std::vector<uint16_t> 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<CCAI::SeqIDType> 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<CCAI::SeqIDType> 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();
}