1

I have 2 types of traffic

  1. TCP
  2. UDP

I want to apply 2 different filters on them, 1 Mbps b/w for UDP and 7 Mbps b/w for TCP

But I want their traffic to use a common buffer of size 100 packets

I've written the following shell script

#!/bin/bash

#Size of the queue
qlen=$1

#Delay per link
sdelay=$3

tcp_rate=7Mbit
udp_rate=1Mbit
total_rate=8Mbit

function add_qdisc {

    # deleting default qdisc
    dev=$1
    tc qdisc del dev $dev root
    echo qdisc removed

    # adding custom qdisc
    tc qdisc add dev $dev root handle 1:0 htb default 1
    echo qdisc added

    # creating classes for tcp and udp traffic
    tc class add dev $dev parent 1:0 classid 1:1 htb rate $total_rate ceil $total_rate
    tc class add dev $dev parent 1:1 classid 1:11 htb rate $udp_rate ceil $udp_rate
    tc class add dev $dev parent 1:1 classid 1:12 htb rate $tcp_rate ceil $tcp_rate
    echo classes created

    # creating link delays and queues
    tc qdisc add dev $dev parent 1:1 handle 10: netem delay $sdelay limit $qlen
    echo "delay and queue added"

    # matching the tcp/udp traffic to the appropriate class
    tc filter add dev $dev parent 1:0 protocol ip u32 match ip protocol 0x11 0xff flowid 1:11
    tc filter add dev $dev parent 1:0 protocol ip u32 match ip protocol 0x06 0xff flowid 1:12
    tc filter add dev $dev parent 1:0 protocol ip u32 match ip protocol 0x01 0xff flowid 1:12

    echo filters added

}

add_qdisc s1-eth1
add_qdisc s1-eth2

add_qdisc s3-eth1
add_qdisc s3-eth2

add_qdisc s6-eth1
add_qdisc s6-eth2

But I'm getting the error RTNETLINK answers: Invalid argument when I'm adding the buffer size to the tc tree node 1:1

When I'm adding the buffer for 1:1's child, say 1:11, the script is working perfectly.

Can the buffer size be added to 1:1 as I want both traffic to use a common buffer?

PS : I've just started learning the tc command

EDIT Updated udp_rate to 1 Mbps

  • You can only attach other qdiscs to leaf classes, not somewhere in the middle. So it won't work this way. Maybe you could turn it around (HTB as child qdisc for netem instead of the other way around), but I'm not sure what you're hoping to achieve with that (and perhaps that is the question you should ask). – frostschutz Jan 8 '17 at 18:45
  • Also if you want reliable results from HTB, sum of child class rates should not exceed parent class rate (currently you have 3mbit + 7mbit = 10mbit instead of 8mbit) – frostschutz Jan 8 '17 at 18:46
  • @frostschutz The 3mbit was originally 1. I changed it to see whether it was working or not. – xavier666 Jan 8 '17 at 18:49
  • @frostschutz My goal is simple. The switch interface should have a buffer of size 100. Total b/w = 8 Mbps. UDP b/w = 1 Mbps and TCP b/w = 7 Mbps. Can it be done differently? – xavier666 Jan 8 '17 at 18:53
0

You can't share the buffer between two qdiscs in tc.
Although, since your bandwidth is static, it would make sense to hardcode the split : 12 and 88 packet.

tc qdisc add dev $dev parent 1:11 handle 9: netem delay $sdelay limit $qlen_udp
tc qdisc add dev $dev parent 1:12 handle 10: netem delay $sdelay limit $qlen_tcp

If your UDP packets are small ones, you may want to adapt the value from 12 to 20-30 to keep the ability to buffer and keeping the latency low (before the netem action).

Why are you writing this function with both netem and buffer sharing ? What are you trying to show ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.