Project

General

Profile

Actions

Simulate Network Latency » History » Revision 1

Revision 1/9 | Next »
neels, 08/31/2021 12:03 PM


Simulate Network Latency

This describes how to virtually introduce network latency on a specific ethernet link,
based on the practical example of introducing latency on the Abis link (between BSC and BTS).
All of this on a single machine using the loopback interface.

setup

(Perform the following steps as root user)

create network namespace "abis",
create a virtual ethernet link "abis-in" <-> "abis-out"
and put "abis-in" in the new network namespace:

ip netns add abis
ip link add abis-in type veth peer name abis-out
ip link set abis-in netns abis

make up a new local IP subnet, here 10.9.8.0/24,
and give each link an address in that subnet.
First for "abis-out" in the root namespace:

ip link set abis-out up
ip addr add 10.9.8.1/24 dev abis-out

And for "abis-in" within the "abis" namespace,
first opening a shell in that namespace:

ip netns exec abis bash
ip link set abis-in up
ip addr add 10.9.8.2/24 dev abis-in

verify

At this point the shell (bash) run within the "abis" namespace should be able to ping the "root" namespace:

# ping 10.9.8.1
PING 10.9.8.1 (10.9.8.1) 56(84) bytes of data.
64 bytes from 10.9.8.1: icmp_seq=1 ttl=64 time=0.133 ms
64 bytes from 10.9.8.1: icmp_seq=2 ttl=64 time=0.059 ms
64 bytes from 10.9.8.1: icmp_seq=3 ttl=64 time=0.059 ms
64 bytes from 10.9.8.1: icmp_seq=4 ttl=64 time=0.058 ms
^C

And a new shell(!) running in the "root" namespace should be able to ping into the "abis" namespace:

# ping 10.9.8.2
PING 10.9.8.2 (10.9.8.2) 56(84) bytes of data.
64 bytes from 10.9.8.2: icmp_seq=1 ttl=64 time=0.133 ms
64 bytes from 10.9.8.2: icmp_seq=2 ttl=64 time=0.059 ms
64 bytes from 10.9.8.2: icmp_seq=3 ttl=64 time=0.059 ms
64 bytes from 10.9.8.2: icmp_seq=4 ttl=64 time=0.058 ms
^C

Any shell within the "abis" namespace should show only the "abis-in" and loopback links,
and the "abis-in" link should be in state UP:

# ip netns exec abis bash
# ip link
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
6: abis-in@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether f6:c6:b5:47:46:4f brd ff:ff:ff:ff:ff:ff link-netnsid 0

# ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
6: abis-in@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether f6:c6:b5:47:46:4f brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.9.8.2/24 scope global abis-in
       valid_lft forever preferred_lft forever
    inet6 fe80::f4c6:b5ff:fe47:464f/64 scope link 
       valid_lft forever preferred_lft forever

A shell running in the "root" namespace should show the "abis-out" link
and any other links your machine may have configured:

# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
[...]
5: abis-out@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc netem state UP mode DEFAULT group default qlen 1000
    link/ether be:49:d6:ef:35:38 brd ff:ff:ff:ff:ff:ff link-netns abis

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
[...]
5: abis-out@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc netem state UP group default qlen 1000
    link/ether be:49:d6:ef:35:38 brd ff:ff:ff:ff:ff:ff link-netns abis
    inet 10.9.8.1/24 scope global abis-out
       valid_lft forever preferred_lft forever
    inet6 fe80::bc49:d6ff:feef:3538/64 scope link 
       valid_lft forever preferred_lft forever
Files (1)
virtual-link.sh virtual-link.sh 1.05 KB automatically set up a network namespace with latency on a link to/from it neels, 08/31/2021 01:35 PM

Updated by neels over 2 years ago · 1 revisions

Add picture from clipboard (Maximum size: 48.8 MB)