Skip to content

Commit

Permalink
The flows now include their very own rate estimator, and only count R…
Browse files Browse the repository at this point in the history
…TT when rate exceeds a threshold - 5mbps right now, which is probably not a good choice.
  • Loading branch information
thebracket committed Feb 14, 2024
1 parent 1ca595b commit 23487f3
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions src/rust/lqos_sys/src/bpf/common/flows.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "dissector.h"
#include "debug.h"

#define SECOND_IN_NANOS 1000000000

// Defines a TCP connection flow key
struct tcp_flow_key_t {
struct in6_addr src;
Expand All @@ -27,6 +29,11 @@ struct tcp_flow_data_t {
__u64 packets_received;
__u64 retries_a;
__u64 retries_b;

__u64 last_count_time;
__u64 next_count_time;
__u64 next_count_bytes;
__u64 rate_estimate;
};

// Map for tracking TCP flow progress.
Expand Down Expand Up @@ -141,7 +148,11 @@ static __always_inline void track_flows(
.packets_sent = 1,
.packets_received = 0,
.retries_a = 0,
.retries_b = 0
.retries_b = 0,
.next_count_time = now + SECOND_IN_NANOS,
.next_count_bytes = dissector->skb_len,
.rate_estimate = 0,
.last_count_time = now
};
bpf_map_update_elem(&flowbee, &key, &data, BPF_ANY);
}
Expand Down Expand Up @@ -180,6 +191,23 @@ static __always_inline void track_flows(
// We don't need to record an RTT measurement and check for issues.
//bpf_debug("%d / %d", data->time_a, data->time_b);

if (now > data->next_count_time) {
// Calculate the rate estimate
__u64 bytes = data->bytes_sent + data->bytes_received - data->next_count_bytes;
__u64 time = now - data->last_count_time;
data->rate_estimate = ((bytes * SECOND_IN_NANOS / time)*8)/1000000;
data->next_count_time = now + SECOND_IN_NANOS;
data->next_count_bytes = data->bytes_sent + data->bytes_received;
data->last_count_time = now;
bpf_debug("Rate estimate: %u mbits/sec", data->rate_estimate);

if (data->rate_estimate > 5) {
__u64 rtt = now - last_seen;
bpf_debug("RTT: %d nanos", rtt);
data->last_rtt = rtt;
}
}

if (data->time_a != 0 && sequence < data->time_a) {
// This is a retransmission
//bpf_debug("DIR 1 Retransmission (or out of order) detected");
Expand All @@ -193,9 +221,23 @@ static __always_inline void track_flows(
// We need to record an RTT measurement, but we can check for issues.
//bpf_debug("%d / %d", data->time_a, data->time_b);

__u64 rtt = now - last_seen;
//bpf_debug("RTT: %d nanos", rtt);
data->last_rtt = rtt;
if (now > data->next_count_time) {
// Calculate the rate estimate
__u64 bytes = data->bytes_sent + data->bytes_received - data->next_count_bytes;
__u64 time = now - data->last_count_time;
data->rate_estimate = ((bytes * SECOND_IN_NANOS / time)*8)/1000000;
data->next_count_time = now + SECOND_IN_NANOS;
data->next_count_bytes = data->bytes_sent + data->bytes_received;
data->last_count_time = now;
bpf_debug("Rate estimate: %u mbits/sec", data->rate_estimate);

if (data->rate_estimate > 5) {
__u64 rtt = now - last_seen;
bpf_debug("RTT: %d nanos", rtt);
data->last_rtt = rtt;
}
}


if (data->time_b != 0 && sequence < data->time_b) {
// This is a retransmission
Expand Down

0 comments on commit 23487f3

Please sign in to comment.