Rewrite route stress tests into C
cover Rewrite route stress tests into C
Hi Alexey,
this is prove of concept of route stress tests rewrite into C. I'm myself not convinced it's a good way. The main motivation for rewriting tests from shell to C is speed and thus more efficient stress testing.
Some issues:
* The test is only on lhost, no attempt to set iface on rhost and check connection. The only check is done via error of libnl used. It's questionable whether this way is good enough.
If we want to have established connection, it'd be better to get back to shell testing [1], just replace netstress to new tool (I'd prefer not use ns-udpsender).
* rtnetlink is used via libnl, which is very lazy approach.
As subject of testing is route testing and not rtnetlink testing I didn't reimplement rtnetlink socket communication from scratch, but I guess I should. Also using link caching (used by functions from libnl-cli) might not be a good idea (maybe using libmnl or only libnl-route would be better if using library).
* C code needs environment variables, that's the only reason for having
shell. It'd be possible to load variables in runtest file:
route4-change-dst-test TST_NO_DEFAULT_RUN=1 . tst_net.sh; route-change-dst -d ltp_ns_veth2 -c 5 route6-change-dst-test TST_NO_DEFAULT_RUN=1 . tst_net.sh; route-change-dst -6 -d $(tst_iface) -c 5
but I don't want to introduce more commands in runtest files (it looks non-standard to me, one day we'll have new shell runner, which might not be compatible with it).
If we agreed on it, I'd add functionality for changing gateway and interface (i.e. route{4,6}-change-{gw,if} + rename C source to route-change.c).
Comments are more than welcome.
Kind regards,
Petr
[1] http://lists.linux.it/pipermail/ltp/2018-July/008778.html
Petr Vorel (2):
tst_net: Add missing includes, make functions inline net/route: Rewrite route{4,6}-change-dst into C
configure.ac | 1 + include/mk/config.mk.default | 3 + include/mk/config.mk.in | 2 + include/tst_net.h | 16 ++- m4/ltp-libnl.m4 | 7 + runtest/net_stress.route | 4 +- testcases/network/stress/route/.gitignore | 1 + testcases/network/stress/route/Makefile | 7 +- .../network/stress/route/route-change-dst.c | 129 ++++++++++++++++++ .../network/stress/route/route-change-dst.sh | 16 +++ travis/debian.cross-compile.aarch64.sh | 6 +- travis/debian.cross-compile.ppc64le.sh | 9 +- travis/debian.i386.sh | 3 +- travis/debian.sh | 5 +- travis/fedora.sh | 1 + travis/tumbleweed.sh | 3 + 16 files changed, 198 insertions(+), 15 deletions(-) create mode 100644 m4/ltp-libnl.m4 create mode 100644 testcases/network/stress/route/.gitignore create mode 100644 testcases/network/stress/route/route-change-dst.c create mode 100755 testcases/network/stress/route/route-change-dst.sh
Signature · 1 line
2.19.2
RFC PATCH 1/2 tst_net: Add missing includes, make functions inline
--- include/tst_net.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
include/tst_net.h +9 -7
@@ -17,6 +17,8 @@#include <arpa/inet.h> #include <errno.h> +#include <stdio.h> +#include <stdlib.h> #define MAX_IPV4_PREFIX 32#define MAX_IPV6_PREFIX 128
@@ -45,7 +47,7 @@ static inline void print_svar_change(const char *name, const char *val)/* * Function bit_count is from ipcalc project, ipcalc.c. */ -static int bit_count (uint32_t i) +static inline int bit_count (uint32_t i) {int c =0 ;unsigned int seen_one =0 ;
@@ -67,7 +69,7 @@ static int bit_count(uint32_t i)/* * Function mask2prefix is from ipcalc project, ipcalc.c. */ -static int mask2prefix (struct in_addr mask) +static inline int mask2prefix (struct in_addr mask) {return bit_count (ntohl (mask.s_addr)); }
@@ -75,7 +77,7 @@ static int mask2prefix(struct in_addr mask)/* * Function ipv4_mask_to_int is from ipcalc project, ipcalc.c. */ -static int ipv4_mask_to_int (const char *prefix) +static inline int ipv4_mask_to_int (const char *prefix) {int ret;struct in_addr in;
@@ -90,7 +92,7 @@ static int ipv4_mask_to_int(const char *prefix)/* * Function safe_atoi is from ipcalc project, ipcalc.c. */ -static int safe_atoi (const char *s,int *ret_i) +static inline int safe_atoi (const char *s,int *ret_i) {char *x =NULL ;long l;
@@ -112,7 +114,7 @@ static int safe_atoi(const char *s, int *ret_i)/* * Function get_prefix use code from ipcalc project, str_to_prefix/ipcalc.c. */ -static int get_prefix (const char *ip_str,int is_ipv6) +static inline int get_prefix (const char *ip_str,int is_ipv6) {char *prefix_str =NULL ;int prefix =-1 , r;
@@ -140,13 +142,13 @@ static int get_prefix(const char *ip_str, int is_ipv6)return prefix; } -static void get_in_addr (const char *ip_str,struct in_addr *ip) +static inline void get_in_addr (const char *ip_str,struct in_addr *ip) {if (inet_pton (AF_INET , ip_str, ip) <=0 )tst_brk_comment ("bad IPv4 address: '%s'" , ip_str); } -static void get_in6_addr (const char *ip_str,struct in6_addr *ip6) +static inline void get_in6_addr (const char *ip_str,struct in6_addr *ip6) {if (inet_pton (AF_INET6 , ip_str, ip6) <=0 )tst_brk_comment ("bad IPv6 address: '%s'" , ip_str);
Signature · 1 line
2.19.2
RFC PATCH 2/2 net/route: Rewrite route{4, 6}-change-dst into C
In reply to Petr Vorelusing new API, cleanup
--- configure.ac | 1 + include/mk/config.mk.default | 3 + include/mk/config.mk.in | 2 + m4/ltp-libnl.m4 | 7 + runtest/net_stress.route | 4 +- testcases/network/stress/route/.gitignore | 1 + testcases/network/stress/route/Makefile | 7 +- .../network/stress/route/route-change-dst.c | 129 ++++++++++++++++++ .../network/stress/route/route-change-dst.sh | 16 +++ travis/debian.cross-compile.aarch64.sh | 6 +- travis/debian.cross-compile.ppc64le.sh | 9 +- travis/debian.i386.sh | 3 +- travis/debian.sh | 5 +- travis/fedora.sh | 1 + travis/tumbleweed.sh | 3 + 15 files changed, 189 insertions(+), 8 deletions(-) create mode 100644 m4/ltp-libnl.m4 create mode 100644 testcases/network/stress/route/.gitignore create mode 100644 testcases/network/stress/route/route-change-dst.c create mode 100755 testcases/network/stress/route/route-change-dst.sh
configure.ac +1 -0
@@ -231,6 +231,7 @@ LTP_CHECK_TPACKET_V3 LTP_CHECK_RLIMIT64 LTP_DETECT_HOST_CPU LTP_CHECK_PERF_EVENT +LTP_CHECK_LIBNL if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMA
include/mk/config.mk.default +3 -0
@@ -43,6 +43,9 @@ YACC := bison -y #SELINUX_LIBS := -lselinux #TIRPC_CPPFLAGS := -I/usr/include/tirpc #TIRPC_LIBS := -ltirpc +#LIBNL_CLI3_CFLAGS := -I/usr/include/libnl3 +#LIBNL_CLI3_LIBS := -lnl-cli-3 -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 + prefix := /opt/ltp
include/mk/config.mk.in +2 -0
@@ -46,6 +46,8 @@ SELINUX_LIBS := @SELINUX_LIBS@ TIRPC_CPPFLAGS := @TIRPC_CPPFLAGS@ TIRPC_LIBS := @TIRPC_LIBS@ KEYUTILS_LIBS := @KEYUTILS_LIBS@ +LIBNL_CLI3_CFLAGS := @LIBNL_CLI3_CFLAGS@ +LIBNL_CLI3_LIBS := @LIBNL_CLI3_LIBS@ prefix := @prefix@
m4/ltp-libnl.m4 new file +7 -0
@@ -0,0 +1,7 @@ +dnl Copyright (c) 2019 Petr Vorel <[email protected]> + +AC_DEFUN([LTP_CHECK_LIBNL], [ + PKG_CHECK_MODULES([LIBNL_CLI3], [libnl-cli-3.0], [ + AC_DEFINE([HAVE_LIBNL_CLI3], [1], [Define to 1 if you have netlink libraries and headers]) + ], [have_libnl3=no]) +])
runtest/net_stress.route +2 -2
@@ -2,13 +2,13 @@ # Stress test for routing table # -route4-change-dst route4-change-dst +route4-change-dst route-change-dst.sh route4-change-gw route4-change-gw route4-change-if route4-change-if route4-redirect route4-redirect route4-rmmod route4-rmmod -route6-change-dst route6-change-dst +route6-change-dst route-change-dst.sh -6 route6-change-gw route6-change-gw route6-change-if route6-change-if route6-redirect route6-redirect
testcases/network/stress/route/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/route-change-dst
testcases/network/stress/route/Makefile +5 -2
@@ -22,8 +22,11 @@ top_srcdir ?= ../../../.. -include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/testcases.mk -INSTALL_TARGETS := route* +INSTALL_TARGETS += route[4-6]-* + +route-change-dst: CFLAGS += $(LIBNL_CLI3_CFLAGS) +route-change-dst: LDLIBS += $(LIBNL_CLI3_LIBS) include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/network/stress/route/route-change-dst.c new file +129 -0
129 lines not on this page · raw message
testcases/network/stress/route/route-change-dst.sh new file +16 -0
@@ -0,0 +1,16 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 Petr Vorel <[email protected]> + +TST_TESTFUNC="do_test" +. tst_net.sh + +do_test() +{ + local ip_flag + + [ "$TST_IPV6" ] && ip_flag="-6" + EXPECT_PASS route-change-dst -d $(tst_iface) -c $NS_TIMES $ip_flag +} + +tst_run
travis/debian.cross-compile.aarch64.sh +5 -1
@@ -2,6 +2,10 @@ # Copyright (c) 2018 Petr Vorel <[email protected]> set -e +dpkg --add-architecture arm64 +apt update + apt install -y --no-install-recommends \ gcc-aarch64-linux-gnu \ - libc6-dev-arm64-cross + libc6-dev-arm64-cross \ + pkg-config:arm64
travis/debian.cross-compile.ppc64le.sh +8 -1
@@ -2,6 +2,13 @@ # Copyright (c) 2018 Petr Vorel <[email protected]> set -e +dpkg --add-architecture ppc64el +apt update + apt install -y --no-install-recommends \ gcc-powerpc64le-linux-gnu \ - libc6-dev-ppc64el-cross + libc6-dev-ppc64el-cross \ + pkg-config:ppc64el \ + libnl-3-dev:ppc64el \ + libnl-cli-3-dev:ppc64el \ + libnl-cli-3-200:ppc64el \
travis/debian.i386.sh +2 -1
@@ -16,4 +16,5 @@ apt install -y --no-install-recommends \ libkeyutils1:i386 \ libnuma1:i386 \ libssl-dev:i386 \ - libtirpc1:i386 + libtirpc1:i386 \ + pkg-config:i386
travis/debian.sh +4 -1
@@ -24,12 +24,15 @@ apt install -y --no-install-recommends \ libkeyutils-dev \ libkeyutils1 \ libmm-dev \ + libnl-cli-3-dev \ + libnl-cli-3-200 \ libnuma-dev \ libnuma1 \ libselinux1-dev \ libsepol1-dev \ libssl-dev \ linux-libc-dev \ - lsb-release + lsb-release \ + pkg-config apt install libtirpc1 libtirpc3 || true
travis/fedora.sh +1 -0
@@ -6,6 +6,7 @@ yum -y install \ autoconf \ automake \ make \ + pkg-config \ clang \ gcc \ findutils \
travis/tumbleweed.sh +3 -0
@@ -8,11 +8,14 @@ zypper --non-interactive install --no-recommends \ clang \ gcc \ make \ + pkg-config \ kernel-default-devel \ keyutils-devel \ libacl-devel \ libaio-devel \ libcap-devel \ + libnl3-devel \ + libnl3-200 \ libnuma-devel \ libopenssl-devel \ libselinux-devel \
Signature · 1 line
2.19.2
cover Rewrite route stress tests into C
In reply to Petr VorelHi Petr,
Quoted 10 lines · Petr Vorel
Hi Alexey,
this is prove of concept of route stress tests rewrite into C. I'm myself not convinced it's a good way. The main motivation for rewriting tests from shell to C is speed and thus more efficient stress testing.
Some issues:
* The test is only on lhost, no attempt to set iface on rhost and check connection. The only check is done via error of libnl used. It's questionable whether this way is good enough.
True, it would be better to verify that the route is working and usable.
At least, we could open a socket and send something using the route (ns-udpsender way)...
Quoted 9 lines
If we want to have established connection, it'd be better to get back to shell testing [1], just replace netstress to new tool (I'd prefer not use ns-udpsender).>
* rtnetlink is used via libnl, which is very lazy approach.
As subject of testing is route testing and not rtnetlink testing I didn't reimplement rtnetlink socket communication from scratch, but I guess I should. Also using link caching (used by functions from libnl-cli) might not be a good idea (maybe using libmnl or only libnl-route would be better if using library).
And libmnl has an example:
https://git.netfilter.org/libmnl/tree/examples/rtnl/rtnl-route-add.c
Quoted 8 lines
* C code needs environment variables, that's the only reason for having
shell. It'd be possible to load variables in runtest file:> route4-change-dst-test TST_NO_DEFAULT_RUN=1 .tst_net.sh; route-change-dst -dltp_ns_veth2-c 5 route6-change-dst-test TST_NO_DEFAULT_RUN=1 .tst_net.sh; route-change-dst -6 -d $(tst_iface) -c 5but I don't want to introduce more commands in runtest files (it looks non-standard to me, one day we'll have new shell runner, which might not be compatible with it).
Yes, it's better to use a shell wrapper than this.
Quoted 38 lines
If we agreed on it, I'd add functionality for changing gateway and interface (i.e. route{4,6}-change-{gw,if} + rename C source to
route-change.c).Comments are more than welcome.
Kind regards,
Petr[1] http://lists.linux.it/pipermail/ltp/2018-July/008778.html
Petr Vorel (2):
tst_net: Add missing includes, make functions inline net/route: Rewrite route{4,6}-change-dst into Cconfigure.ac | 1 + include/mk/config.mk.default | 3 + include/mk/config.mk.in | 2 + include/tst_net.h | 16 ++- m4/ltp-libnl.m4 | 7 + runtest/net_stress.route | 4 +- testcases/network/stress/route/.gitignore | 1 + testcases/network/stress/route/Makefile | 7 +- .../network/stress/route/route-change-dst.c | 129 ++++++++++++++++++ .../network/stress/route/route-change-dst.sh | 16 +++ travis/debian.cross-compile.aarch64.sh | 6 +- travis/debian.cross-compile.ppc64le.sh | 9 +- travis/debian.i386.sh | 3 +- travis/debian.sh | 5 +- travis/fedora.sh | 1 + travis/tumbleweed.sh | 3 + 16 files changed, 198 insertions(+), 15 deletions(-) create mode 100644 m4/ltp-libnl.m4 create mode 100644 testcases/network/stress/route/.gitignore create mode 100644 testcases/network/stress/route/route-change-dst.c create mode 100755 testcases/network/stress/route/route-change-dst.sh
cover Rewrite route stress tests into C
Hi Alexey,
thanks for your comments.
Quoted 9 lines
Quoted 4 lines
Some issues:
* The test is only on lhost, no attempt to set iface on rhost and check connection. The only check is done via error of libnl used. It's questionable whether this way is good enough.True, it would be better to verify that the route is working and usable.
At least, we could open a socket and send something using the route (ns-udpsender way)...
OK, I'll try at least this. And if it's not suitable enough, I'll have to get back to shell (or I'd have to implement tst_rhost_run() in C).
Quoted 10 lines
Quoted 9 lines
If we want to have established connection, it'd be better to get back to shell testing [1], just replace netstress to new tool (I'd prefer not use ns-udpsender).>
* rtnetlink is used via libnl, which is very lazy approach.
As subject of testing is route testing and not rtnetlink testing I didn't reimplement rtnetlink socket communication from scratch, but I guess I should. Also using link caching (used by functions from libnl-cli) might not be a good idea (maybe using libmnl or only libnl-route would be better if using library).
Quoted 2 lines
And libmnl has an example:
https://git.netfilter.org/libmnl/tree/examples/rtnl/rtnl-route-add.c
I noticed this as well, I'll use libmnl.
Kind regards,
Petr