[PATCH net 2/2] selftests: bonding: add test for passive LACP mode

Hangbin Liu posted 2 patches 3 months ago
[PATCH net 2/2] selftests: bonding: add test for passive LACP mode
Posted by Hangbin Liu 3 months ago
Add a selftest to verify bonding behavior when lacp_active is set to off.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 .../drivers/net/bonding/bond_passive_lacp.sh  | 21 +++++
 .../drivers/net/bonding/bond_topo_lacp.sh     | 77 +++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
 create mode 100644 tools/testing/selftests/drivers/net/bonding/bond_topo_lacp.sh

diff --git a/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
new file mode 100755
index 000000000000..4cf8a5999aaa
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Testing if bond works with lacp_active = off
+
+lib_dir=$(dirname "$0")
+source ${lib_dir}/bond_topo_lacp.sh
+
+trap cleanup EXIT
+setup_topo_lacp
+
+lacp_bond_reset "${c_ns}" "lacp_active off"
+# make sure the switch state is not expired [A,T,G,S,Ex]
+if slowwait 15 ip netns exec ${s_ns} grep -q 'port state: 143' /proc/net/bonding/bond0; then
+	RET=1
+else
+	RET=0
+fi
+log_test "bond 802.3ad" "lacp_active off"
+
+exit $EXIT_STATUS
diff --git a/tools/testing/selftests/drivers/net/bonding/bond_topo_lacp.sh b/tools/testing/selftests/drivers/net/bonding/bond_topo_lacp.sh
new file mode 100644
index 000000000000..33dca6ebdc4b
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/bonding/bond_topo_lacp.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Topology for Bond mode 802.3ad testing
+#
+#  +-------------------------+
+#  |          bond0          |  Switch
+#  |            +            |  192.0.2.254/24
+#  |      eth0  |  eth1      |  2001:db8::254/24
+#  |        +---+---+        |
+#  |        |       |        |
+#  +-------------------------+
+#           |       |
+#  +-------------------------+
+#  |        |       |        |
+#  |        +---+---+        |  Client
+#  |      eth0  |  eth1      |  192.0.2.1/24
+#  |            +            |  2001:db8::1/24
+#  |          bond0          |
+#  +-------------------------+
+
+REQUIRE_MZ=no
+NUM_NETIFS=0
+lib_dir=$(dirname "$0")
+source "$lib_dir"/../../../net/forwarding/lib.sh
+
+s_ip4="192.0.2.254"
+c_ip4="192.0.2.1"
+s_ip6="2001:db8::254"
+c_ip6="2001:db8::1"
+
+switch_create()
+{
+	ip netns exec ${s_ns} sysctl -q net.ipv6.conf.default.keep_addr_on_down=1
+	ip -n ${s_ns} link add eth0 type veth peer name eth0 netns ${c_ns}
+	ip -n ${s_ns} link add eth1 type veth peer name eth1 netns ${c_ns}
+	ip -n ${s_ns} link add bond0 type bond mode 802.3ad miimon 100 lacp_active on lacp_rate fast
+	ip -n ${s_ns} link set eth0 master bond0
+	ip -n ${s_ns} link set eth1 master bond0
+	ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0
+	ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0
+	ip -n ${s_ns} link set bond0 up
+}
+
+client_create()
+{
+	ip netns exec ${c_ns} sysctl -q net.ipv6.conf.default.keep_addr_on_down=1
+	ip -n ${c_ns} link add bond0 type bond mode 802.3ad miimon 100 lacp_active on lacp_rate fast
+	ip -n ${c_ns} link set eth0 master bond0
+	ip -n ${c_ns} link set eth1 master bond0
+	ip -n ${c_ns} addr add ${c_ip4}/24 dev bond0
+	ip -n ${c_ns} addr add ${c_ip6}/24 dev bond0
+	ip -n ${c_ns} link set bond0 up
+}
+
+setup_topo_lacp()
+{
+	setup_ns s_ns c_ns
+	defer cleanup_all_ns
+
+	switch_create
+	client_create
+}
+
+# Reset bond with and options
+lacp_bond_reset()
+{
+	local netns="$1"
+	local param="$2"
+
+	ip -n ${netns} link set bond0 down
+	ip -n ${netns} link set bond0 type bond $param
+	ip -n ${netns} link set bond0 up
+
+	# Wait for IPv6 address ready as it needs DAD
+	slowwait 10 ip netns exec ${c_ns} ping6 ${s_ip6} -c 1 -W 0.1 &> /dev/null
+}
-- 
2.46.0
Re: [PATCH net 2/2] selftests: bonding: add test for passive LACP mode
Posted by Paolo Abeni 2 months, 3 weeks ago
On 7/9/25 11:03 AM, Hangbin Liu wrote:
> Add a selftest to verify bonding behavior when lacp_active is set to off.
> 
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  .../drivers/net/bonding/bond_passive_lacp.sh  | 21 +++++
>  .../drivers/net/bonding/bond_topo_lacp.sh     | 77 +++++++++++++++++++
>  2 files changed, 98 insertions(+)
>  create mode 100755 tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
>  create mode 100644 tools/testing/selftests/drivers/net/bonding/bond_topo_lacp.sh

New test should be listed in the relevant makefile
> diff --git a/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> new file mode 100755
> index 000000000000..4cf8a5999aaa
> --- /dev/null
> +++ b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> @@ -0,0 +1,21 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Testing if bond works with lacp_active = off
> +
> +lib_dir=$(dirname "$0")
> +source ${lib_dir}/bond_topo_lacp.sh

shellcheck is not super happy about 'source' usage:

In bond_passive_lacp.sh line 7:
source ${lib_dir}/bond_topo_lacp.sh
^-- SC3046 (warning): In POSIX sh, 'source' in place of '.' is undefined.
^-- SC3051 (warning): In POSIX sh, 'source' in place of '.' is undefined.

either switch to '. ' or use bash instead of 'sh'.

> +lacp_bond_reset "${c_ns}" "lacp_active off"
> +# make sure the switch state is not expired [A,T,G,S,Ex]
> +if slowwait 15 ip netns exec ${s_ns} grep -q 'port state: 143' /proc/net/bonding/bond0; then

Shellcheck wants double quote everywhere. Since in many cases (all the
blamed ones in this patch) we know the variable is really a single word,
I think you could simply disable the warning with:

#shellcheck disable=SC2086

(same in the other test file)

> +	RET=1
> +else
> +	RET=0
> +fi

/P
Re: [PATCH net 2/2] selftests: bonding: add test for passive LACP mode
Posted by Hangbin Liu 2 months, 2 weeks ago
On Tue, Jul 15, 2025 at 11:37:54AM +0200, Paolo Abeni wrote:
> > diff --git a/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> > new file mode 100755
> > index 000000000000..4cf8a5999aaa
> > --- /dev/null
> > +++ b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> > @@ -0,0 +1,21 @@
> > +#!/bin/sh
> > +# SPDX-License-Identifier: GPL-2.0
> > +#
> > +# Testing if bond works with lacp_active = off
> > +
> > +lib_dir=$(dirname "$0")
> > +source ${lib_dir}/bond_topo_lacp.sh
> 
> shellcheck is not super happy about 'source' usage:
> 
> In bond_passive_lacp.sh line 7:
> source ${lib_dir}/bond_topo_lacp.sh
> ^-- SC3046 (warning): In POSIX sh, 'source' in place of '.' is undefined.
> ^-- SC3051 (warning): In POSIX sh, 'source' in place of '.' is undefined.
> 
> either switch to '. ' or use bash instead of 'sh'.

Hi Paolo,

I updated the case and remove the source file bond_topo_lacp.sh.
Instead I source the forwarding lib directly like:

lib_dir=$(dirname "$0")
source "$lib_dir"/../../../net/forwarding/lib.sh

But this cause shell check unable to find the lib.sh as $lib_dir is get
dynamically. This usage is common in selftest. How should we resolves this
problem?

Thanks
Hangbin
Re: [PATCH net 2/2] selftests: bonding: add test for passive LACP mode
Posted by Hangbin Liu 2 months, 2 weeks ago
On Thu, Jul 24, 2025 at 04:06:03AM +0000, Hangbin Liu wrote:
> On Tue, Jul 15, 2025 at 11:37:54AM +0200, Paolo Abeni wrote:
> > > diff --git a/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> > > new file mode 100755
> > > index 000000000000..4cf8a5999aaa
> > > --- /dev/null
> > > +++ b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> > > @@ -0,0 +1,21 @@
> > > +#!/bin/sh
> > > +# SPDX-License-Identifier: GPL-2.0
> > > +#
> > > +# Testing if bond works with lacp_active = off
> > > +
> > > +lib_dir=$(dirname "$0")
> > > +source ${lib_dir}/bond_topo_lacp.sh
> > 
> > shellcheck is not super happy about 'source' usage:
> > 
> > In bond_passive_lacp.sh line 7:
> > source ${lib_dir}/bond_topo_lacp.sh
> > ^-- SC3046 (warning): In POSIX sh, 'source' in place of '.' is undefined.
> > ^-- SC3051 (warning): In POSIX sh, 'source' in place of '.' is undefined.
> > 
> > either switch to '. ' or use bash instead of 'sh'.
> 
> Hi Paolo,
> 
> I updated the case and remove the source file bond_topo_lacp.sh.
> Instead I source the forwarding lib directly like:
> 
> lib_dir=$(dirname "$0")
> source "$lib_dir"/../../../net/forwarding/lib.sh
> 
> But this cause shell check unable to find the lib.sh as $lib_dir is get
> dynamically. This usage is common in selftest. How should we resolves this
> problem?

OK, I just disabled this warning.

# shellcheck disable=SC1091

Hangbin
Re: [PATCH net 2/2] selftests: bonding: add test for passive LACP mode
Posted by Petr Machata 2 months, 2 weeks ago
Hangbin Liu <liuhangbin@gmail.com> writes:

> On Thu, Jul 24, 2025 at 04:06:03AM +0000, Hangbin Liu wrote:
>> On Tue, Jul 15, 2025 at 11:37:54AM +0200, Paolo Abeni wrote:
>> > > diff --git a/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
>> > > b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
>> > > new file mode 100755
>> > > index 000000000000..4cf8a5999aaa
>> > > --- /dev/null
>> > > +++ b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
>> > > @@ -0,0 +1,21 @@
>> > > +#!/bin/sh
>> > > +# SPDX-License-Identifier: GPL-2.0
>> > > +#
>> > > +# Testing if bond works with lacp_active = off
>> > > +
>> > > +lib_dir=$(dirname "$0")
>> > > +source ${lib_dir}/bond_topo_lacp.sh
>> > 
>> > shellcheck is not super happy about 'source' usage:
>> > 
>> > In bond_passive_lacp.sh line 7:
>> > source ${lib_dir}/bond_topo_lacp.sh
>> > ^-- SC3046 (warning): In POSIX sh, 'source' in place of '.' is undefined.
>> > ^-- SC3051 (warning): In POSIX sh, 'source' in place of '.' is undefined.
>> > 
>> > either switch to '. ' or use bash instead of 'sh'.
>> 
>> Hi Paolo,
>> 
>> I updated the case and remove the source file bond_topo_lacp.sh.
>> Instead I source the forwarding lib directly like:
>> 
>> lib_dir=$(dirname "$0")
>> source "$lib_dir"/../../../net/forwarding/lib.sh
>> 
>> But this cause shell check unable to find the lib.sh as $lib_dir is get
>> dynamically. This usage is common in selftest. How should we resolves this
>> problem?
>
> OK, I just disabled this warning.
>
> # shellcheck disable=SC1091

I believe the point was only about using "." instead of "source". The
following should have fixed it:

. ${lib_dir}/bond_topo_lacp.sh

... or just use bash as the interpreter, I suspect lib.sh is not
actually POSIX clean.
Re: [PATCH net 2/2] selftests: bonding: add test for passive LACP mode
Posted by Hangbin Liu 2 months, 2 weeks ago
On Fri, Jul 25, 2025 at 10:27:48AM +0200, Petr Machata wrote:
> 
> Hangbin Liu <liuhangbin@gmail.com> writes:
> 
> > On Thu, Jul 24, 2025 at 04:06:03AM +0000, Hangbin Liu wrote:
> >> On Tue, Jul 15, 2025 at 11:37:54AM +0200, Paolo Abeni wrote:
> >> > > diff --git a/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> >> > > b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> >> > > new file mode 100755
> >> > > index 000000000000..4cf8a5999aaa
> >> > > --- /dev/null
> >> > > +++ b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> >> > > @@ -0,0 +1,21 @@
> >> > > +#!/bin/sh
> >> > > +# SPDX-License-Identifier: GPL-2.0
> >> > > +#
> >> > > +# Testing if bond works with lacp_active = off
> >> > > +
> >> > > +lib_dir=$(dirname "$0")
> >> > > +source ${lib_dir}/bond_topo_lacp.sh
> >> > 
> >> > shellcheck is not super happy about 'source' usage:
> >> > 
> >> > In bond_passive_lacp.sh line 7:
> >> > source ${lib_dir}/bond_topo_lacp.sh
> >> > ^-- SC3046 (warning): In POSIX sh, 'source' in place of '.' is undefined.
> >> > ^-- SC3051 (warning): In POSIX sh, 'source' in place of '.' is undefined.
> >> > 
> >> > either switch to '. ' or use bash instead of 'sh'.
> >> 
> >> Hi Paolo,
> >> 
> >> I updated the case and remove the source file bond_topo_lacp.sh.
> >> Instead I source the forwarding lib directly like:
> >> 
> >> lib_dir=$(dirname "$0")
> >> source "$lib_dir"/../../../net/forwarding/lib.sh
> >> 
> >> But this cause shell check unable to find the lib.sh as $lib_dir is get
> >> dynamically. This usage is common in selftest. How should we resolves this
> >> problem?
> >
> > OK, I just disabled this warning.
> >
> > # shellcheck disable=SC1091
> 
> I believe the point was only about using "." instead of "source". The
> following should have fixed it:
> 
> . ${lib_dir}/bond_topo_lacp.sh
> 
> ... or just use bash as the interpreter, I suspect lib.sh is not
> actually POSIX clean.

Thanks Petr, I know Paolo means to use "." to fix this. The issue is that
I changed the script to source forwarding lib. And shell check could only
analyse static path. Unless use -x to supply the real source path. But I guess
the CI can't do this. So I disabled the SC1091 checking as a workaround.

Regards
Hangbin
Re: [PATCH net 2/2] selftests: bonding: add test for passive LACP mode
Posted by Hangbin Liu 2 months, 3 weeks ago
On Tue, Jul 15, 2025 at 11:37:54AM +0200, Paolo Abeni wrote:
> On 7/9/25 11:03 AM, Hangbin Liu wrote:
> > Add a selftest to verify bonding behavior when lacp_active is set to off.
> > 
> > Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> > ---
> >  .../drivers/net/bonding/bond_passive_lacp.sh  | 21 +++++
> >  .../drivers/net/bonding/bond_topo_lacp.sh     | 77 +++++++++++++++++++
> >  2 files changed, 98 insertions(+)
> >  create mode 100755 tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> >  create mode 100644 tools/testing/selftests/drivers/net/bonding/bond_topo_lacp.sh
> 
> New test should be listed in the relevant makefile

Ah, yes, I forgot this.

> > diff --git a/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> > new file mode 100755
> > index 000000000000..4cf8a5999aaa
> > --- /dev/null
> > +++ b/tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
> > @@ -0,0 +1,21 @@
> > +#!/bin/sh
> > +# SPDX-License-Identifier: GPL-2.0
> > +#
> > +# Testing if bond works with lacp_active = off
> > +
> > +lib_dir=$(dirname "$0")
> > +source ${lib_dir}/bond_topo_lacp.sh
> 
> shellcheck is not super happy about 'source' usage:
> 
> In bond_passive_lacp.sh line 7:
> source ${lib_dir}/bond_topo_lacp.sh
> ^-- SC3046 (warning): In POSIX sh, 'source' in place of '.' is undefined.
> ^-- SC3051 (warning): In POSIX sh, 'source' in place of '.' is undefined.
> 
> either switch to '. ' or use bash instead of 'sh'.

OK, I will fix this and other warns.

Thanks
Hangbin
> 
> > +lacp_bond_reset "${c_ns}" "lacp_active off"
> > +# make sure the switch state is not expired [A,T,G,S,Ex]
> > +if slowwait 15 ip netns exec ${s_ns} grep -q 'port state: 143' /proc/net/bonding/bond0; then
> 
> Shellcheck wants double quote everywhere. Since in many cases (all the
> blamed ones in this patch) we know the variable is really a single word,
> I think you could simply disable the warning with:
> 
> #shellcheck disable=SC2086
> 
> (same in the other test file)
> 
> > +	RET=1
> > +else
> > +	RET=0
> > +fi
> 
> /P
>