{"id":159,"date":"2010-06-03T11:22:49","date_gmt":"2010-06-03T16:22:49","guid":{"rendered":"http:\/\/bda.ath.cx\/blog\/?p=159"},"modified":"2011-03-28T16:10:27","modified_gmt":"2011-03-28T21:10:27","slug":"simulating-network-delay-in-linux","status":"publish","type":"post","link":"https:\/\/bda.ath.cx\/blog\/2010\/06\/03\/simulating-network-delay-in-linux\/","title":{"rendered":"simulating network delay in Linux"},"content":{"rendered":"<p>At work we are having a problem with OpenWRT, where daemons like wifidog and dnsmasq can&#8217;t get information about the wan network interface when they&#8217;re started if the wan uses DHCP and it takes too long to get a lease. I was having trouble reproducing the issue, so I decided to force some extra delay with <a href=\"http:\/\/www.linuxfoundation.org\/collaborate\/workgroups\/networking\/netem\">netem<\/a>. Here are the commands I used to add massive delay to all DHCP traffic going to my DHCP server, which is running on eth3:<\/p>\n<pre>tc qdisc add dev eth3 root handle 1: prio\r\ntc qdisc add dev eth3 parent 1:3 handle 30: netem delay 5000ms\r\n\r\n# Only the first rule should really be necessary, since we are delaying the outgoing\r\n# traffic from 67 (bootps) to 68 (bootpc).\r\ntc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \\\r\n   match ip sport 67 0xfff flowid 1:3\r\ntc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \\\r\n   match ip dport 67 0xfff flowid 1:3\r\ntc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \\\r\n   match ip sport 68 0xfff flowid 1:3\r\ntc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \\\r\n   match ip dport 68 0xfff flowid 1:3\r\n\r\n# Also delay pings so we can more easily see it working\r\ntc filter add dev eth3 protocol ip parent 1:0 prio 3 u32 \\\r\n   match ip protocol 1 0xff flowid 1:3<\/pre>\n<p>See also:\u00c2\u00a0<a href=\"http:\/\/www.linuxpoweruser.com\/?p=41\">another blog post<\/a>,\u00c2\u00a0<a href=\"http:\/\/lartc.org\/howto\/lartc.qdisc.filters.html\">tc filters documentation<\/a> (lartc), <a href=\"http:\/\/tcn.hypert.net\/tcmanual.pdf\">tc manual<\/a> (pdf)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At work we are having a problem with OpenWRT, where daemons like wifidog and dnsmasq can&#8217;t get information about the wan network interface when they&#8217;re started if the wan uses DHCP and it takes too long to get a lease. I was having trouble reproducing the issue, so I decided to force some extra delay [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[81],"class_list":["post-159","post","type-post","status-publish","format-standard","hentry","category-linux","tag-networking"],"_links":{"self":[{"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/posts\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":10,"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":196,"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/posts\/159\/revisions\/196"}],"wp:attachment":[{"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bda.ath.cx\/blog\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}