Reputation: 71
I'm trying to generate impairments on my linux ubuntu 18.04 and use it as a hotspot to affect a mobile app with those impairments but I need it to affect only the UDP traffic.
I'm trying to test my app under bad network and when the test is done I want the app to upload the results, this flow should run in a loop so i can't switch networks between each iteration. The problem is that linux tc using netem generates impairments both on TCP connections and UDP connections and I'm using the TCP connection for collecting the test results so the results are malformed or not coming at all.
I used it like this:
tc qdisc add dev <name> root netem delay XXms loss gemodel 20% 30% 1% 15%
do you know if there is a way to limit the tc using netem or any other way to affect only UDP packets?
Upvotes: 4
Views: 1552
Reputation: 71
I've found how to do it- so if it will help anyone I'm adding the answer:
the protocol 17 is for UDP but it can be replaced with other protocols and then only those protocols will be filtered
tc qdisc add dev <name> root handle 1: prio
tc filter add dev <name> protocol ip parent 1:prio 10 u32 match ip protocol 17 oxff flowid 1:1
tc filter add dev <name> protocol ip parent 1:prio 10 u32 match ip protocol 17 oxff flowid 1:2
tc filter add dev <name> protocol ip parent 1:prio 10 u32 match ip protocol 17 oxff flowid 1:3
after those lines you can add the network impairments:
tc qdisc add dev <name> parent 1:1 netem <impairments>
tc qdisc add dev <name> parent 1:2 netem <impairments>
tc qdisc add dev <name> parent 1:3 netem <impairments>
for fully understand what "prio" does I suggest to read here but basically it creates some kind of 3 routes for the packets to enter through, then we filter the traffic that come to take only the packets that are by the protocol of udp on every route and then I'm adding the network impairments on this route
Upvotes: 3