50 lines
1.8 KiB
Nix
50 lines
1.8 KiB
Nix
# 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
|
||
cfg = ((import ./common.nix).tc);
|
||
|
||
mkClass =
|
||
{ minor
|
||
, rate
|
||
, ceil ? cfg.rate
|
||
, burst ? "15k"
|
||
, qdiscArgs ? [ "fq_codel" ]
|
||
, prio
|
||
}: ''
|
||
tc class add dev ${cfg.interface} parent ${toString cfg.major}:1 classid ${toString cfg.major}:${toString minor} htb rate ${rate} ceil ${ceil} burst ${burst} prio ${toString prio}
|
||
tc qdisc add dev ${cfg.interface} parent ${toString cfg.major}:${toString minor} handle ${toString minor}:1 ${lib.escapeShellArgs qdiscArgs}
|
||
'';
|
||
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
|
||
|
||
tc qdisc add dev ${cfg.interface} root handle ${toString cfg.major}:0 htb default 2
|
||
tc class add dev ${cfg.interface} parent ${toString cfg.major}:0 classid ${toString cfg.major}:1 htb rate ${toString cfg.rate} burst 15k
|
||
|
||
${lib.concatMapStrings mkClass cfg.classes}
|
||
'';
|
||
|
||
serviceConfig = {
|
||
Type = "oneshot";
|
||
};
|
||
};
|
||
}
|