Simulate Network Latency » History » Version 2
neels, 08/31/2021 12:14 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 | Any shell within the "abis" namespace should show only the "abis-in" and loopback links, |
||
67 | and the "abis-in" link should be in state UP: |
||
68 | |||
69 | 2 | neels | (I repeat the 'ip netns exec' step below just to clarify, of course it suffices to keep one shell within the "abis" namespace open) |
70 | |||
71 | 1 | neels | <pre> |
72 | # ip netns exec abis bash |
||
73 | # ip link |
||
74 | 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 |
||
75 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
||
76 | 6: abis-in@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000 |
||
77 | link/ether f6:c6:b5:47:46:4f brd ff:ff:ff:ff:ff:ff link-netnsid 0 |
||
78 | |||
79 | # ip a |
||
80 | 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000 |
||
81 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
||
82 | 6: abis-in@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 |
||
83 | link/ether f6:c6:b5:47:46:4f brd ff:ff:ff:ff:ff:ff link-netnsid 0 |
||
84 | inet 10.9.8.2/24 scope global abis-in |
||
85 | valid_lft forever preferred_lft forever |
||
86 | inet6 fe80::f4c6:b5ff:fe47:464f/64 scope link |
||
87 | valid_lft forever preferred_lft forever |
||
88 | </pre> |
||
89 | |||
90 | A shell running in the "root" namespace should show the "abis-out" link |
||
91 | and any other links your machine may have configured: |
||
92 | |||
93 | <pre> |
||
94 | # ip link |
||
95 | 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 |
||
96 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
||
97 | [...] |
||
98 | 5: abis-out@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc netem state UP mode DEFAULT group default qlen 1000 |
||
99 | link/ether be:49:d6:ef:35:38 brd ff:ff:ff:ff:ff:ff link-netns abis |
||
100 | |||
101 | # ip a |
||
102 | 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 |
||
103 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
||
104 | inet 127.0.0.1/8 scope host lo |
||
105 | valid_lft forever preferred_lft forever |
||
106 | inet6 ::1/128 scope host |
||
107 | valid_lft forever preferred_lft forever |
||
108 | [...] |
||
109 | 5: abis-out@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc netem state UP group default qlen 1000 |
||
110 | link/ether be:49:d6:ef:35:38 brd ff:ff:ff:ff:ff:ff link-netns abis |
||
111 | inet 10.9.8.1/24 scope global abis-out |
||
112 | valid_lft forever preferred_lft forever |
||
113 | inet6 fe80::bc49:d6ff:feef:3538/64 scope link |
||
114 | valid_lft forever preferred_lft forever |
||
115 | 2 | neels | </pre> |
116 | |||
117 | A shell run within the "abis" namespace should be able to ping the "root" namespace: |
||
118 | |||
119 | <pre> |
||
120 | # ip netns exec abis bash |
||
121 | # ping 10.9.8.1 |
||
122 | PING 10.9.8.1 (10.9.8.1) 56(84) bytes of data. |
||
123 | 64 bytes from 10.9.8.1: icmp_seq=1 ttl=64 time=0.133 ms |
||
124 | 64 bytes from 10.9.8.1: icmp_seq=2 ttl=64 time=0.059 ms |
||
125 | 64 bytes from 10.9.8.1: icmp_seq=3 ttl=64 time=0.059 ms |
||
126 | 64 bytes from 10.9.8.1: icmp_seq=4 ttl=64 time=0.058 ms |
||
127 | ^C |
||
128 | </pre> |
||
129 | |||
130 | And a running in the "root" namespace should be able to ping into the "abis" namespace: |
||
131 | <pre> |
||
132 | # ping 10.9.8.2 |
||
133 | PING 10.9.8.2 (10.9.8.2) 56(84) bytes of data. |
||
134 | 64 bytes from 10.9.8.2: icmp_seq=1 ttl=64 time=0.133 ms |
||
135 | 64 bytes from 10.9.8.2: icmp_seq=2 ttl=64 time=0.059 ms |
||
136 | 64 bytes from 10.9.8.2: icmp_seq=3 ttl=64 time=0.059 ms |
||
137 | 64 bytes from 10.9.8.2: icmp_seq=4 ttl=64 time=0.058 ms |
||
138 | ^C |
||
139 | </pre> |
||
140 | |||
141 | h2. add latency |
||
142 | |||
143 | In a shell running in the "root" namespace, add a netem delay, for example: |
||
144 | |||
145 | <pre> |
||
146 | tc qdisc add dev abis-out root handle 1:0 netem delay 200ms 50ms 50% |
||
147 | </pre> |
||
148 | |||
149 | From here on, there is latency in *only one* direction on the virtual ethernet. |
||
150 | It already shows in the ping time on both sides, because ping always includes the entire roundtrip. |
||
151 | |||
152 | Also add similar latency in the other direction: |
||
153 | |||
154 | <pre> |
||
155 | ip netns exec abis bash |
||
156 | tc qdisc add dev abis-in root handle 1:0 netem delay 200ms 50ms 50% |
||
157 | </pre> |
||
158 | |||
159 | At this point there is latency in both directions between "abis-in" and "abis-out" |
||
160 | |||
161 | h2. usage |
||
162 | |||
163 | In my specific example, I configure the BSC to listen for Abis on 10.9.8.1, |
||
164 | and I can now run my osmo-bts-trx and osmo-trx-uhd within the "abis" namespace: |
||
165 | |||
166 | <pre> |
||
167 | ip netns exec abis bash |
||
168 | osmo-trx-uhd -C osmo-trx.cfg |
||
169 | </pre> |
||
170 | |||
171 | In my specific case, I am running osmo-trx-uhd as root user above to be able to set realtime priority on the process. |
||
172 | osmo-bts-trx should run as my normal user, but first I need to enter the "abis" netns: |
||
173 | |||
174 | <pre> |
||
175 | ip netns exec abis bash |
||
176 | su - neels |
||
177 | osmo-bts-trx -c osmo-bts.cfg |
||
178 | 1 | neels | </pre> |