Linux Traffic Shaping

Gabriel Rosa

03/15/2004

Topics

Introduction

Theory

Practice

Conclusions/Benchmarks

What is traffic shaping?

prioritizing traffic based on TOS, TOD, source, destination, size, moon phase, etc

enforcing bandwidth floors and ceilings to traffic based on (see above)

enforcing bandwidth “fairness” (as defined by you)

Why do this?

Reducing latency to services you want

Ensuring high bandwidth availability

Being a control freak

Won't this slow down my router?

Not unless you're using a 486 to route 100mbit

You can keep the rules very simple, and achieve very useful results

can use iptables, not much overhead on top of firewall overhead

How hard is this to set up?

if you know iptables, you know about 50% of it

very throughout howtos

pretty well documented (if sometimes a little cryptic)

very simple rules can sometimes be satisfactory, from there we can expand

However, getting it “just right” can require some tweaking

Queuing Disciplines

Fast First In First Out (F_FIFO)

Stochastic Fairness Queuing (SFQ)

Hierarchical Token Bucket (HTB)

Others, but these are the three that we're interested in for day to day operation, and relatively simple shaping.

Packet Queues

transmission buffer

default linux packet queue size 100

DSL and cable modems also have packet queues

miscalculated packet queues source of all evil (when it comes to traffic shaping)

HTB

we want to be able to say “service X is more important to me than service Y in Z fashion”

very simple structure (we like trees, right?)

very easy to understand and manipulate

built in to newer kernels

What do we want to shape?

tcp/ip return packets should have high priority

ssh and other interactive ports high priority

icmp low priority (unless you want to get into game servers that filter by ping time)

bulk traffic (web, ftp, scp, kazaa, etc) low priority

quick response (dns, small packets) high priority

anything you can't think of, low priority (default)

Ingress/Egress?

Egress is the traffic we send out (uplink)

Ingress is traffic we receive (downlink)

So?

Qdisk? Root Handle? Leafs?

Qdisk is the main container (our HTB tree)

root handle is the top of the tree, everything attaches to it

leafs are the rules we attach to the qdisk

Alright, I'm ready.

Linux 2.2 or higher

iproute2 package (contains 'tc' and 'ip' tools)

netfilter (contains iptables)

a good plan (although a mediocre one will work at first)

Netfilter

iptables used to flag packets for later scheduling

we use the 'mangle' table for this

mark method (more available)

classify method (more better)

Examples

simple shaper (from traffic shaping howto)

more complicated shaper (pieced together from various examples)

Demo

start a ping, or type on a console

start an upload, what interactivity die, stop upload

start traffic shaper

start upload, whatch interactivity stay ok, fluctuate a bit

note the small price we pay for traffic shaping

Questions?

http://tim.plush.org/~grosa/talks/shaper/

http://lartc.org/howto/lartc.cookbook.ultimate-tc.html

your_favorite_howto_mirror_here/ADSL-Bandwidth-Management-HOWTO.html

http://www.knowplace.org/shaper/

Thanks!
(applause)

2004-03-15T11:28:38