Ben Stienstra

Linux, Unix, network, radio and more...

User Tools

Site Tools


linux_traffic_control

Linux Traffic Control

  • Hardware: PC Engines APU (1)
  • OS: Voyage Linux 0.11
  • eth0: management
  • eth1: bridge with eth1
  • eth2: bridge with eth2

Create bridge

  • Install required packages:
    apt-get install bridge-utils
  • Configure network:
    cat > /etc/network/interfaces <<'EOF'
    auto lo
    iface lo inet loopback
    
    source /etc/network/interfaces.d/*
    EOF
    
    cat > /etc/network/interfaces.d/eth0.conf <<'EOF'
    auto eth0
    iface eth0 inet dhcp
    EOF
    
    cat > /etc/network/interfaces.d/br0.conf <<'EOF'
    allow-hotplug eth1
    iface eth1 inet manual
    
    allow-hotplug eth2
    iface eth2 inet manual
    
    auto br0
    iface br0 inet manual
        bridge_ports eth1 eth2
        bridge_stp on
        bridge_maxwait 0
    EOF

Control traffic

Emulate lower bandwidth, packet loss, latency, etc.

  • Example:
    # Clear queue discipline
    tc qdisc del dev eth1 root
    tc qdisc del dev eth2 root
    
    # Add 500msec latency
    tc qdisc add dev eth1 root handle 1:0 netem delay 500msec
    
    # Inspect rules
    tc -s qdisc ls dev eth1
    qdisc pfifo_fast 0: root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
     Sent 894508 bytes 1187 pkt (dropped 0, overlimits 0 requeues 0) 
     backlog 0b 0p requeues 0 
    
    # Never allow more than 50mbit
    tc qdisc add dev eth1 handle 1: root htb default 11
    tc class add dev eth1 parent 1: classid 1:1 htb rate 50mbit
    tc class add dev eth1 parent 1:1 classid 1:11 htb rate 50mbit
    tc qdisc add dev eth2 handle 1: root htb default 11
    tc class add dev eth2 parent 1: classid 1:1 htb rate 50mbit
    tc class add dev eth2 parent 1:1 classid 1:11 htb rate 50mbit
linux_traffic_control.txt · Last modified: 2017/12/15 22:18 by admin