title: tc: attaching many netems to an interface
body: <p>I'm looking to simulate delays for a set of services that run on different ports on a host. I would like to simulate different delays to different services, potentially many on a given host hopefully without any limits.</p>
  
  <p>The only way I've found to do this is with a prio qdisc. Here's an example:</p>
  
  <pre><code>IF=eth0
  tc qdisc add dev $IF root handle 1: prio bands 16 priomap 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  
  # this loop is only a sample to make the example runnable; values will vary in practice
  for handle in {2..16}; do
   # add a delay for the service on port 20000 + $handle
   tc qdisc add dev $IF handle $handle: parent 1:$handle netem delay 1000ms # example; this will vary in practice
   # add a filter to send the traffic to the correct netem
   tc filter add dev $IF pref $handle protocol ip u32 match ip sport $(( 20000 + $handle )) 0xffff flowid 1:$handle
  done
  </code></pre>
  
  <p>If you run the command above, you'll notice that handles 11-16 don't get created and fail with an error.</p>
  
  <p>NB. Here's an undo for the above.</p>
  
  <pre><code>IF=eth0
  for handle in {2..16}; do
   tc filter del dev $IF pref $handle
   tc qdisc del dev $IF handle $handle: parent 1:$handle netem delay 1000ms
  done
  tc qdisc del dev $IF root
  </code></pre>
  
  <p>Is there a way to add more than 10 netems to an interface?</p>