Network Emulation

Dummynet

Create links

ipfw add pipe 3 ip from any to any out

ipfw add pipe 4 ip from any to any in

ipfw pipe 3 config bw 128Kbit/s queue 10 delay 1000ms

ipfw pipe 4 config bw 640Kbit/s queue 30 delay 1000ms

Create bridge

sysctl -w net.link.ether.bridge=1

sysctl -w net.link.ether.bridge_ipfw=1

NetEm

To lock ethernet ports to the correct MAC (after identifying which is which using ethtool and checking the line state after pulling a plug), the following file was used:

/etc/iftab script

# This file assigns persistent names to network interfaces.

# See iftab(5) for syntax.

eth0 mac XX:XX:XX:XX:XX:XX arp 1

eth1 mac XX:XX:XX:XX:XX:XX arp 1

Note that in later versions of Ubuntu, a different file (/etc/udev/rules.d/70-persistent-net.rules) needs to be edited to lock MACs to NICs. Also, note that Ubuntu can't initialise D-link quad port NIC MACs - you need to boot up in Windows or FreeBSD otherwise the MACs show as all zeros.

The following script was created and installed as a startup script. Changing the settings requires the script to be edited then executed to update the link.

NetEm init.d script

#!/bin/sh

# This script emulates a WAN or radio link between eth1 and eth2.

#

# This script is added to the boot sequence by putting it in

# /etc/init.d then using the command

# update-rc.d netem.sh defaults

#

# It requires bridge-utils and iproute2 to be installed.

# Written for ubuntu 6.1 (edgy eft).

#

# Edward Chan 20070111

#-----------------------------------------------------------------

# INMARSAT

# Shutdown any current services

ifconfig eth3 down > /dev/null

ifconfig eth4 down > /dev/null

ifconfig eth5 down > /dev/null

ifconfig eth6 down > /dev/null

tc qdisc del dev eth3 parent 1: handle 10: > /dev/null

tc qdisc del dev eth4 parent 1: handle 10: > /dev/null

tc qdisc del dev eth5 parent 1: handle 10: > /dev/null

tc qdisc del dev eth6 parent 1: handle 10: > /dev/null

tc qdisc del dev eth3 root > /dev/null

tc qdisc del dev eth4 root > /dev/null

tc qdisc del dev eth5 root > /dev/null

tc qdisc del dev eth6 root > /dev/null

ifconfig inmarsat down > /dev/null

brctl delbr inmarsat > /dev/null

# Create a bridge

ifconfig eth3 0.0.0.0

ifconfig eth4 0.0.0.0

ifconfig eth5 0.0.0.0

ifconfig eth6 0.0.0.0

brctl addbr inmarsat

brctl addif inmarsat eth3

brctl addif inmarsat eth4

brctl addif inmarsat eth5

brctl addif inmarsat eth6

ifconfig inmarsat up

# Add delay to link

tc qdisc add dev eth3 root handle 1: netem delay 450ms 100ms distribution normal

tc qdisc add dev eth4 root handle 1: netem delay 450ms 100ms distribution normal

tc qdisc add dev eth5 root handle 1: netem delay 450ms 100ms distribution normal

tc qdisc add dev eth6 root handle 1: netem delay 450ms 100ms distribution normal

# Add a bandwidth limit to the link

#

# tc-tbf Parameters

#

# rate

# The speed at which the bucket can be filled with packets

# burst

# The size of the bucket (effectively, the number of bytes that

# can be sent at any time. This should be kept just larger than

# the MTU otherwise it isn't a realistic link.

# limit

# The number of bytes that can be in the queue. Basically the buffer.

# Set to twice the MTU for a more interactive link, or larger for

# backhaul links. Otherwise, use htb to set up different classes for a

# mix of interactive and backhaul links.

tc qdisc add dev eth3 parent 1:1 handle 10: tbf rate 128Kbit buffer 1600 limit 100K

tc qdisc add dev eth4 parent 1:1 handle 10: tbf rate 128Kbit buffer 1600 limit 100K

tc qdisc add dev eth5 parent 1:1 handle 10: tbf rate 128Kbit buffer 1600 limit 100K

tc qdisc add dev eth6 parent 1:1 handle 10: tbf rate 128Kbit buffer 1600 limit 100K

# An example using classful Heirarchical Token Buckets

#tc qdisc add dev eth2 parent 1: handle 10: htb default 1

#tc qdisc add dev eth1 parent 1: handle 10: htb default 1

#tc class add dev eth2 parent 10: classid 10:1 htb rate 2400bit ceil 2400bit

#tc class add dev eth1 parent 10: classid 10:1 htb rate 2400bit ceil 2400bit

# Commands to show current link status

# tc -s qdisc ls dev eth2

# tc -s qdisc ls dev eth1

# ================================================================================

#-----------------------------------------------------------------

# MASTIS

# Shutdown any current services

ifconfig eth7 down > /dev/null

ifconfig eth8 down > /dev/null

ifconfig eth9 down > /dev/null

ifconfig eth10 down > /dev/null

tc qdisc del dev eth7 parent 1: handle 10: > /dev/null

tc qdisc del dev eth8 parent 1: handle 10: > /dev/null

tc qdisc del dev eth9 parent 1: handle 10: > /dev/null

tc qdisc del dev eth10 parent 1: handle 10: > /dev/null

tc qdisc del dev eth7 root > /dev/null

tc qdisc del dev eth8 root > /dev/null

tc qdisc del dev eth9 root > /dev/null

tc qdisc del dev eth10 root > /dev/null

ifconfig mastis down > /dev/null

brctl delbr mastis > /dev/null

# Create a bridge

ifconfig eth7 0.0.0.0

ifconfig eth8 0.0.0.0

ifconfig eth9 0.0.0.0

ifconfig eth10 0.0.0.0

brctl addbr mastis

brctl addif mastis eth7

brctl addif mastis eth8

brctl addif mastis eth9

brctl addif mastis eth10

ifconfig mastis up

# Add delay to link

tc qdisc add dev eth7 root handle 1: netem delay 300ms 100ms distribution normal

tc qdisc add dev eth8 root handle 1: netem delay 300ms 100ms distribution normal

tc qdisc add dev eth9 root handle 1: netem delay 300ms 100ms distribution normal

tc qdisc add dev eth10 root handle 1: netem delay 300ms 100ms distribution normal

# Add a bandwidth limit to the link

#

# tc-tbf Parameters

#

# rate

# The speed at which the bucket can be filled with packets

# burst

# The size of the bucket (effectively, the number of bytes that

# can be sent at any time. This should be kept just larger than

# the MTU otherwise it isn't a realistic link.

# limit

# The number of bytes that can be in the queue. Basically the buffer.

# Set to twice the MTU for a more interactive link, or larger for

# backhaul links. Otherwise, use htb to set up different classes for a

# mix of interactive and backhaul links.

tc qdisc add dev eth7 parent 1:1 handle 10: tbf rate 192Kbit buffer 1600 limit 100K

tc qdisc add dev eth8 parent 1:1 handle 10: tbf rate 192Kbit buffer 1600 limit 100K

tc qdisc add dev eth9 parent 1:1 handle 10: tbf rate 192Kbit buffer 1600 limit 100K

tc qdisc add dev eth10 parent 1:1 handle 10: tbf rate 192Kbit buffer 1600 limit 100K