Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Testing if bond lacp per port priority works
5#
6# Switch (s_ns) Backup Switch (b_ns)
7# +-------------------------+ +-------------------------+
8# | bond0 | | bond0 |
9# | + | | + |
10# | eth0 | eth1 | | eth0 | eth1 |
11# | +---+---+ | | +---+---+ |
12# | | | | | | | |
13# +-------------------------+ +-------------------------+
14# | | | |
15# +-----------------------------------------------------+
16# | | | | | |
17# | +-------+---------+---------+-------+ |
18# | eth0 eth1 | eth2 eth3 |
19# | + |
20# | bond0 |
21# +-----------------------------------------------------+
22# Client (c_ns)
23
24lib_dir=$(dirname "$0")
25# shellcheck disable=SC1091
26source "$lib_dir"/../../../net/lib.sh
27
28setup_links()
29{
30 # shellcheck disable=SC2154
31 ip -n "${c_ns}" link add eth0 type veth peer name eth0 netns "${s_ns}"
32 ip -n "${c_ns}" link add eth1 type veth peer name eth1 netns "${s_ns}"
33 # shellcheck disable=SC2154
34 ip -n "${c_ns}" link add eth2 type veth peer name eth0 netns "${b_ns}"
35 ip -n "${c_ns}" link add eth3 type veth peer name eth1 netns "${b_ns}"
36
37 ip -n "${c_ns}" link add bond0 type bond mode 802.3ad miimon 100 \
38 lacp_rate fast ad_select actor_port_prio
39 ip -n "${s_ns}" link add bond0 type bond mode 802.3ad miimon 100 \
40 lacp_rate fast
41 ip -n "${b_ns}" link add bond0 type bond mode 802.3ad miimon 100 \
42 lacp_rate fast
43
44 ip -n "${c_ns}" link set eth0 master bond0
45 ip -n "${c_ns}" link set eth1 master bond0
46 ip -n "${c_ns}" link set eth2 master bond0
47 ip -n "${c_ns}" link set eth3 master bond0
48 ip -n "${s_ns}" link set eth0 master bond0
49 ip -n "${s_ns}" link set eth1 master bond0
50 ip -n "${b_ns}" link set eth0 master bond0
51 ip -n "${b_ns}" link set eth1 master bond0
52
53 ip -n "${c_ns}" link set bond0 up
54 ip -n "${s_ns}" link set bond0 up
55 ip -n "${b_ns}" link set bond0 up
56}
57
58test_port_prio_setting()
59{
60 RET=0
61 ip -n "${c_ns}" link set eth0 type bond_slave actor_port_prio 1000
62 prio=$(cmd_jq "ip -n ${c_ns} -d -j link show eth0" \
63 ".[].linkinfo.info_slave_data.actor_port_prio")
64 [ "$prio" -ne 1000 ] && RET=1
65 ip -n "${c_ns}" link set eth2 type bond_slave actor_port_prio 10
66 prio=$(cmd_jq "ip -n ${c_ns} -d -j link show eth2" \
67 ".[].linkinfo.info_slave_data.actor_port_prio")
68 [ "$prio" -ne 10 ] && RET=1
69}
70
71test_agg_reselect()
72{
73 local bond_agg_id slave_agg_id
74 local expect_slave="$1"
75 RET=0
76
77 # Trigger link state change to reselect the aggregator
78 ip -n "${c_ns}" link set eth1 down
79 sleep 0.5
80 ip -n "${c_ns}" link set eth1 up
81 sleep 0.5
82
83 bond_agg_id=$(cmd_jq "ip -n ${c_ns} -d -j link show bond0" \
84 ".[].linkinfo.info_data.ad_info.aggregator")
85 slave_agg_id=$(cmd_jq "ip -n ${c_ns} -d -j link show $expect_slave" \
86 ".[].linkinfo.info_slave_data.ad_aggregator_id")
87 # shellcheck disable=SC2034
88 [ "${bond_agg_id}" -ne "${slave_agg_id}" ] && \
89 RET=1
90}
91
92trap cleanup_all_ns EXIT
93setup_ns c_ns s_ns b_ns
94setup_links
95
96test_port_prio_setting
97log_test "bond 802.3ad" "actor_port_prio setting"
98
99test_agg_reselect eth0
100log_test "bond 802.3ad" "actor_port_prio select"
101
102# Change the actor port prio and re-test
103ip -n "${c_ns}" link set eth0 type bond_slave actor_port_prio 10
104ip -n "${c_ns}" link set eth2 type bond_slave actor_port_prio 1000
105test_agg_reselect eth2
106log_test "bond 802.3ad" "actor_port_prio switch"
107
108exit "${EXIT_STATUS}"