#!/bin/bash set -vmeE HTTP_PROC=0 # Must run as root [ $(id -u) -eq 0 ] || exit 1 trap 'end $?' EXIT end() { ip netns delete server [ $HTTP_PROC -eq 0 ] || kill $HTTP_PROC exit $1 } ip link add client0 type veth peer name server0 ip netns add server ip link set client0 up ip link set server0 netns server up ip addr add dev client0 1.1.1.1/24 ip -n server addr add dev server0 1.1.1.2/24 ip netns exec server nohup python3 -m http.server 8080 & HTTP_PROC=$! yes | head -n 25000000 | tr -d '\n' > y.txt sleep 10 # HTB tc -n server qdisc add dev server0 root handle 1: htb default 1 tc -n server class add dev server0 parent 1: classid 1:1 htb rate 1gbps tc -n server class add dev server0 parent 1: classid 1:2 htb rate 2mbps # HSFC #tc -n server qdisc add dev server0 root handle 1: hfsc default 1 #tc -n server class add dev server0 parent 1: classid 1:1 hfsc rt m2 1gbps #tc -n server class add dev server0 parent 1: classid 1:2 hfsc rt m2 2mbps # classify with filter for HTB and HSFC, comment out for netem test tc -n server filter add dev server0 parent 1: protocol ip u32 match ip dst 1.1.1.1 flowid 1:2 # NETEM #tc -n server qdisc add dev server0 root handle 1: netem rate 2mbps curl -o /dev/null "http://1.1.1.2:8080/y.txt"