Simulate Network Latency » History » Version 1
neels, 08/31/2021 12:03 PM
1 | 1 | neels | h1. Simulate Network Latency |
---|---|---|---|
2 | |||
3 | This describes how to virtually introduce network latency on a specific ethernet link, |
||
4 | based on the practical example of introducing latency on the Abis link (between BSC and BTS). |
||
5 | All of this on a single machine using the loopback interface. |
||
6 | |||
7 | {{graphviz_link() |
||
8 | digraph G { |
||
9 | rankdir = LR; |
||
10 | |||
11 | subgraph cluster_abis { |
||
12 | label="namespace: abis";style=dotted |
||
13 | BTS [rank="min"] |
||
14 | abisin [label="link: abis-in\n10.9.8.2/24";shape=box] |
||
15 | } |
||
16 | |||
17 | subgraph cluster_root { |
||
18 | label="namespace: root";style=dotted |
||
19 | abisout [label="link: abis-out\n10.9.8.1/24";shape=box] |
||
20 | BSC |
||
21 | MSC |
||
22 | } |
||
23 | |||
24 | BTS -> abisin [dir=both] |
||
25 | abisin -> abisout [label="netem delay"] |
||
26 | abisout -> abisin [label="netem delay"] |
||
27 | abisout -> BSC -> MSC [dir=both] |
||
28 | } |
||
29 | |||
30 | }} |
||
31 | |||
32 | h2. setup |
||
33 | |||
34 | (Perform the following steps as root user) |
||
35 | |||
36 | create network namespace "abis", |
||
37 | create a virtual ethernet link "abis-in" <-> "abis-out" |
||
38 | and put "abis-in" in the new network namespace: |
||
39 | |||
40 | <pre> |
||
41 | ip netns add abis |
||
42 | ip link add abis-in type veth peer name abis-out |
||
43 | ip link set abis-in netns abis |
||
44 | </pre> |
||
45 | |||
46 | make up a new local IP subnet, here 10.9.8.0/24, |
||
47 | and give each link an address in that subnet. |
||
48 | First for "abis-out" in the root namespace: |
||
49 | |||
50 | <pre> |
||
51 | ip link set abis-out up |
||
52 | ip addr add 10.9.8.1/24 dev abis-out |
||
53 | </pre> |
||
54 | |||
55 | And for "abis-in" within the "abis" namespace, |
||
56 | first opening a shell in that namespace: |
||
57 | |||
58 | <pre> |
||
59 | ip netns exec abis bash |
||
60 | ip link set abis-in up |
||
61 | ip addr add 10.9.8.2/24 dev abis-in |
||
62 | </pre> |
||
63 | |||
64 | h2. verify |
||
65 | |||
66 | At this point the shell (bash) run within the "abis" namespace should be able to ping the "root" namespace: |
||
67 | |||
68 | <pre> |
||
69 | # ping 10.9.8.1 |
||
70 | PING 10.9.8.1 (10.9.8.1) 56(84) bytes of data. |
||
71 | 64 bytes from 10.9.8.1: icmp_seq=1 ttl=64 time=0.133 ms |
||
72 | 64 bytes from 10.9.8.1: icmp_seq=2 ttl=64 time=0.059 ms |
||
73 | 64 bytes from 10.9.8.1: icmp_seq=3 ttl=64 time=0.059 ms |
||
74 | 64 bytes from 10.9.8.1: icmp_seq=4 ttl=64 time=0.058 ms |
||
75 | ^C |
||
76 | </pre> |
||
77 | |||
78 | And a new shell(!) running in the "root" namespace should be able to ping into the "abis" namespace: |
||
79 | <pre> |
||
80 | # ping 10.9.8.2 |
||
81 | PING 10.9.8.2 (10.9.8.2) 56(84) bytes of data. |
||
82 | 64 bytes from 10.9.8.2: icmp_seq=1 ttl=64 time=0.133 ms |
||
83 | 64 bytes from 10.9.8.2: icmp_seq=2 ttl=64 time=0.059 ms |
||
84 | 64 bytes from 10.9.8.2: icmp_seq=3 ttl=64 time=0.059 ms |
||
85 | 64 bytes from 10.9.8.2: icmp_seq=4 ttl=64 time=0.058 ms |
||
86 | ^C |
||
87 | </pre> |
||
88 | |||
89 | Any shell within the "abis" namespace should show only the "abis-in" and loopback links, |
||
90 | and the "abis-in" link should be in state UP: |
||
91 | |||
92 | <pre> |
||
93 | # ip netns exec abis bash |
||
94 | # ip link |
||
95 | 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 |
||
96 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
||
97 | 6: abis-in@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000 |
||
98 | link/ether f6:c6:b5:47:46:4f brd ff:ff:ff:ff:ff:ff link-netnsid 0 |
||
99 | |||
100 | # ip a |
||
101 | 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000 |
||
102 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
||
103 | 6: abis-in@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 |
||
104 | link/ether f6:c6:b5:47:46:4f brd ff:ff:ff:ff:ff:ff link-netnsid 0 |
||
105 | inet 10.9.8.2/24 scope global abis-in |
||
106 | valid_lft forever preferred_lft forever |
||
107 | inet6 fe80::f4c6:b5ff:fe47:464f/64 scope link |
||
108 | valid_lft forever preferred_lft forever |
||
109 | </pre> |
||
110 | |||
111 | A shell running in the "root" namespace should show the "abis-out" link |
||
112 | and any other links your machine may have configured: |
||
113 | |||
114 | <pre> |
||
115 | # ip link |
||
116 | 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 |
||
117 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
||
118 | [...] |
||
119 | 5: abis-out@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc netem state UP mode DEFAULT group default qlen 1000 |
||
120 | link/ether be:49:d6:ef:35:38 brd ff:ff:ff:ff:ff:ff link-netns abis |
||
121 | |||
122 | # ip a |
||
123 | 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 |
||
124 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
||
125 | inet 127.0.0.1/8 scope host lo |
||
126 | valid_lft forever preferred_lft forever |
||
127 | inet6 ::1/128 scope host |
||
128 | valid_lft forever preferred_lft forever |
||
129 | [...] |
||
130 | 5: abis-out@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc netem state UP group default qlen 1000 |
||
131 | link/ether be:49:d6:ef:35:38 brd ff:ff:ff:ff:ff:ff link-netns abis |
||
132 | inet 10.9.8.1/24 scope global abis-out |
||
133 | valid_lft forever preferred_lft forever |
||
134 | inet6 fe80::bc49:d6ff:feef:3538/64 scope link |
||
135 | valid_lft forever preferred_lft forever |
||
136 | </pre> |