2023-10-07 22:31:29 +02:00
|
|
|
|
# I measured the link capacity with iperf3:
|
|
|
|
|
# The download is pretty exactly 7.5 MiB/s ≈ 62.9 Mbit/s
|
|
|
|
|
# The upstream is more complicated.
|
|
|
|
|
# It initially bursts around 50% higher than the sustained speed
|
|
|
|
|
# and then falls down to 569 KiB/s ≈ 4.66 Mbit/s
|
|
|
|
|
# However, abound every 2 to 3 seconds, it drops to 380 KiB/s ≈ 3.11 Mbit/s.
|
|
|
|
|
# It does so pretty consistently and always at exactly that rate.
|
|
|
|
|
# I averaged a longer iperf3 run to around 509 Kbit/s ≈ 4.17 Mbit/s (excluding the initial burst).
|
|
|
|
|
{ lib, pkgs, utils, ... }:
|
|
|
|
|
let
|
2023-10-18 20:04:04 +02:00
|
|
|
|
cfg = ((pkgs.callPackage ./common.nix { }).tc);
|
2023-10-07 22:31:29 +02:00
|
|
|
|
|
|
|
|
|
mkClass =
|
|
|
|
|
{ minor
|
|
|
|
|
, rate
|
|
|
|
|
, ceil ? cfg.rate
|
|
|
|
|
, burst ? "15k"
|
|
|
|
|
, qdiscArgs ? [ "fq_codel" ]
|
|
|
|
|
, prio
|
|
|
|
|
}: ''
|
2023-10-18 20:01:34 +02:00
|
|
|
|
tc class add dev ${cfg.interface} parent ${lib.toHexString cfg.major}:1 classid ${lib.toHexString cfg.major}:${lib.toHexString minor} htb rate ${rate} ceil ${ceil} burst ${burst} prio ${toString prio}
|
|
|
|
|
tc qdisc add dev ${cfg.interface} parent ${lib.toHexString cfg.major}:${lib.toHexString minor} handle ${lib.toHexString minor}:1 ${lib.escapeShellArgs qdiscArgs}
|
2023-10-07 22:31:29 +02:00
|
|
|
|
'';
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
systemd.services.traffic-control = {
|
|
|
|
|
after = [ "sys-subsystem-net-devices-${utils.escapeSystemdPath cfg.interface}.device" ];
|
|
|
|
|
bindsTo = [ "sys-subsystem-net-devices-${utils.escapeSystemdPath cfg.interface}.device" ];
|
|
|
|
|
wantedBy = [ "network-online.target" ];
|
|
|
|
|
|
|
|
|
|
path = with pkgs; [ iproute2 ];
|
|
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
# deleting might fail
|
|
|
|
|
tc qdisc del root dev ${cfg.interface} || true
|
|
|
|
|
|
2023-10-18 20:01:34 +02:00
|
|
|
|
tc qdisc add dev ${cfg.interface} root handle ${lib.toHexString cfg.major}:0 htb default 2
|
|
|
|
|
tc class add dev ${cfg.interface} parent ${lib.toHexString cfg.major}:0 classid ${lib.toHexString cfg.major}:1 htb rate ${toString cfg.rate} burst 15k
|
2023-10-07 22:31:29 +02:00
|
|
|
|
|
|
|
|
|
${lib.concatMapStrings mkClass cfg.classes}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|