Simulate a Slow Link by Linux Bridge

To simulate the real world slow link network, sometimes network equipment is not enough. For example, LAN Switch can do rate-limit on each egress port, but it cannot allow packet forwarding delay, or, it cannot setup packet loss rate. The four major elements of QoS are: Bandwidth, Delay, Packet Loss and Jitter. So, in order to achieve the real situation, we can use Linux bridge plus traffic control (tc) features.

Setup Linux Bridge

Two NICs cannot be a bridge unless we install a bridge utility. “yum -y install bridge-utils” can be applied. Sorry I didn’t mention in Ubuntu distribution since I am always working on Fedora Core. Then, we need to plan which two NICs to be the member of the bridge. In my case, I use eth1 and eth2. So, make sure there is no ip on both of Ethernet cards first. Then, we need to type the following commands:

ifconfig eth0 0.0.0.0 up
ifconfig eth1 0.0.0.0 up
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 eth1
ifconfig br0 up

We can assign an IP address to br0, like we assign vlan interface IP address in LAN Switch.

ifconfig br0 192.168.50.50 netmask 255.255.255.0 gw 192.168.50.254

However, since there is no routing over the bridge. we can just leave it as pure bridge.

Brief Introduction of TC

Traffic Control (TC) is a tool that do egress traffic shaping on every port. The primitive purpose to create a module named shaper.o is to slow down interface. It didn’t measure traffic instead, it was only able to decrease interface speed by suing PWM (Pulse Width Modulation). For example, you can transfer power equal to 12V from 36V by switching supply off for 2ms then switch on for 1ms. PWM has one advantage that it didn’t require much cpu usage.

Then, the CBQ (Class Based Queue) is appeared. It can classify traffic but it works in the same way as PWM.

Then, the HTB (Hierarchy Token Bucket) is coming. It controls traffic per packet instead of time slots. It allows to implement very precise control in expense of higher CPU usage.

The detailed description is available in tc manual.

Create a Delay Network

To make a simple work, we don’t need to use classes. We only need to add delay to root. However, very important, each time we have to clear “queue discipline”.

tc qdisc del dev eth1 root
tc qdisc del dev eth2 root

Then, we setup a 500 mini second delay.

tc qdisc add dev eth1 root handle 1:0 netem delay 500msec
tc qdisc add dev eth2 root handle 1:0 netem delay 500msec

Create a Low Bandwidth Network

Still, I didn’t compose any fancy shell script, instead I just use only two lines to achieve a 128K link.

tc qdisc del dev eth1 root
tc qdisc del dev eth2 root
tc qdisc add dev eth2 root tbf rate 128kbit burst 1024kbit latency 50ms
tc qdisc add dev eth1 root tbf rate 128kbit burst 1024kbit latency 50ms

So far I only got this level. I saw quite a lot blogs and tutorials in the web, which have more complicated network.

Discussion Area - Leave a Comment




Anti-Spam Protection by WP-SpamFree