|
7 | 7 | # Can be overridden by the configuration file.
|
8 | 8 | PING=${PING:=ping}
|
9 | 9 | PING6=${PING6:=ping6}
|
| 10 | +MZ=${MZ:=mausezahn} |
10 | 11 | WAIT_TIME=${WAIT_TIME:=5}
|
11 | 12 | PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
|
12 | 13 | PAUSE_ON_CLEANUP=${PAUSE_ON_CLEANUP:=no}
|
@@ -34,6 +35,11 @@ if [[ ! -x "$(command -v jq)" ]]; then
|
34 | 35 | exit 0
|
35 | 36 | fi
|
36 | 37 |
|
| 38 | +if [[ ! -x "$(command -v $MZ)" ]]; then |
| 39 | + echo "SKIP: $MZ not installed" |
| 40 | + exit 0 |
| 41 | +fi |
| 42 | + |
37 | 43 | if [[ ! -v NUM_NETIFS ]]; then
|
38 | 44 | echo "SKIP: importer does not define \"NUM_NETIFS\""
|
39 | 45 | exit 0
|
@@ -250,6 +256,17 @@ master_name_get()
|
250 | 256 | ip -j link show dev $if_name | jq -r '.[]["master"]'
|
251 | 257 | }
|
252 | 258 |
|
| 259 | +bridge_ageing_time_get() |
| 260 | +{ |
| 261 | + local bridge=$1 |
| 262 | + local ageing_time |
| 263 | + |
| 264 | + # Need to divide by 100 to convert to seconds. |
| 265 | + ageing_time=$(ip -j -d link show dev $bridge \ |
| 266 | + | jq '.[]["linkinfo"]["info_data"]["ageing_time"]') |
| 267 | + echo $((ageing_time / 100)) |
| 268 | +} |
| 269 | + |
253 | 270 | ##############################################################################
|
254 | 271 | # Tests
|
255 | 272 |
|
@@ -280,3 +297,78 @@ ping6_test()
|
280 | 297 | check_err $?
|
281 | 298 | log_test "ping6"
|
282 | 299 | }
|
| 300 | + |
| 301 | +learning_test() |
| 302 | +{ |
| 303 | + local bridge=$1 |
| 304 | + local br_port1=$2 # Connected to `host1_if`. |
| 305 | + local host1_if=$3 |
| 306 | + local host2_if=$4 |
| 307 | + local mac=de:ad:be:ef:13:37 |
| 308 | + local ageing_time |
| 309 | + |
| 310 | + RET=0 |
| 311 | + |
| 312 | + bridge -j fdb show br $bridge brport $br_port1 \ |
| 313 | + | jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null |
| 314 | + check_fail $? "Found FDB record when should not" |
| 315 | + |
| 316 | + # Disable unknown unicast flooding on `br_port1` to make sure |
| 317 | + # packets are only forwarded through the port after a matching |
| 318 | + # FDB entry was installed. |
| 319 | + bridge link set dev $br_port1 flood off |
| 320 | + |
| 321 | + tc qdisc add dev $host1_if ingress |
| 322 | + tc filter add dev $host1_if ingress protocol ip pref 1 handle 101 \ |
| 323 | + flower dst_mac $mac action drop |
| 324 | + |
| 325 | + $MZ $host2_if -c 1 -p 64 -b $mac -t ip -q |
| 326 | + sleep 1 |
| 327 | + |
| 328 | + tc -j -s filter show dev $host1_if ingress \ |
| 329 | + | jq -e ".[] | select(.options.handle == 101) \ |
| 330 | + | select(.options.actions[0].stats.packets == 1)" &> /dev/null |
| 331 | + check_fail $? "Packet reached second host when should not" |
| 332 | + |
| 333 | + $MZ $host1_if -c 1 -p 64 -a $mac -t ip -q |
| 334 | + sleep 1 |
| 335 | + |
| 336 | + bridge -j fdb show br $bridge brport $br_port1 \ |
| 337 | + | jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null |
| 338 | + check_err $? "Did not find FDB record when should" |
| 339 | + |
| 340 | + $MZ $host2_if -c 1 -p 64 -b $mac -t ip -q |
| 341 | + sleep 1 |
| 342 | + |
| 343 | + tc -j -s filter show dev $host1_if ingress \ |
| 344 | + | jq -e ".[] | select(.options.handle == 101) \ |
| 345 | + | select(.options.actions[0].stats.packets == 1)" &> /dev/null |
| 346 | + check_err $? "Packet did not reach second host when should" |
| 347 | + |
| 348 | + # Wait for 10 seconds after the ageing time to make sure FDB |
| 349 | + # record was aged-out. |
| 350 | + ageing_time=$(bridge_ageing_time_get $bridge) |
| 351 | + sleep $((ageing_time + 10)) |
| 352 | + |
| 353 | + bridge -j fdb show br $bridge brport $br_port1 \ |
| 354 | + | jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null |
| 355 | + check_fail $? "Found FDB record when should not" |
| 356 | + |
| 357 | + bridge link set dev $br_port1 learning off |
| 358 | + |
| 359 | + $MZ $host1_if -c 1 -p 64 -a $mac -t ip -q |
| 360 | + sleep 1 |
| 361 | + |
| 362 | + bridge -j fdb show br $bridge brport $br_port1 \ |
| 363 | + | jq -e ".[] | select(.mac == \"$mac\")" &> /dev/null |
| 364 | + check_fail $? "Found FDB record when should not" |
| 365 | + |
| 366 | + bridge link set dev $br_port1 learning on |
| 367 | + |
| 368 | + tc filter del dev $host1_if ingress protocol ip pref 1 handle 101 flower |
| 369 | + tc qdisc del dev $host1_if ingress |
| 370 | + |
| 371 | + bridge link set dev $br_port1 flood on |
| 372 | + |
| 373 | + log_test "FDB learning" |
| 374 | +} |
0 commit comments