├── .gitignore ├── CASE_STUDIES.md ├── CONTRIBUTING.md ├── FEATURE_PLAN.md ├── LICENSE.txt ├── Makefile ├── README.md ├── SECURITY.md ├── TESTING.md ├── THIRD_PARTY_LICENSES.txt ├── TROUBLESHOOTING.md ├── bpftune.tcp_buffer.png ├── buildrpm └── bpftune.spec ├── debian ├── changelog ├── control ├── copyright ├── rules ├── salsa-ci.yml ├── source │ └── format └── upstream │ └── metadata ├── docs ├── Makefile ├── bpftune-ip-frag.rst ├── bpftune-neigh.rst ├── bpftune-net-buffer.rst ├── bpftune-netns.rst ├── bpftune-sysctl.rst ├── bpftune-tcp-buffer.rst ├── bpftune-tcp-conn.rst ├── bpftune-udp-buffer.rst └── bpftune.rst ├── include ├── Makefile ├── bpftune │ ├── bpftune.bpf.h │ ├── bpftune.h │ ├── corr.h │ ├── libbpftune.h │ ├── rl.h │ ├── vmlinux_aarch64.h │ └── vmlinux_x86_64.h └── uapi │ └── linux │ ├── bpf.h │ └── btf.h ├── sample_tuner ├── Makefile ├── README.md ├── sample_tuner.bpf.c └── sample_tuner.c ├── src ├── .gitignore ├── Makefile ├── README.md ├── bpftune.c ├── bpftune.service ├── buffer_sizing.md ├── ip_frag_tuner.bpf.c ├── ip_frag_tuner.c ├── ip_frag_tuner.h ├── libbpftune.c ├── libbpftune.map ├── neigh_table_tuner.bpf.c ├── neigh_table_tuner.c ├── neigh_table_tuner.h ├── net_buffer_tuner.bpf.c ├── net_buffer_tuner.c ├── net_buffer_tuner.h ├── netns_tuner.bpf.c ├── netns_tuner.c ├── netns_tuner.h ├── pcp │ ├── Install │ ├── Makefile │ ├── README │ ├── Remove │ ├── pmdabpftune.python │ └── pmns-for-testing ├── probe.bpf.c ├── route_table_tuner.bpf.c ├── route_table_tuner.c ├── route_table_tuner.h ├── sysctl_tuner.bpf.c ├── sysctl_tuner.c ├── tcp_buffer_tuner.bpf.c ├── tcp_buffer_tuner.c ├── tcp_buffer_tuner.h ├── tcp_conn_tuner.bpf.c ├── tcp_conn_tuner.c ├── tcp_conn_tuner.h ├── udp_buffer_tuner.bpf.c ├── udp_buffer_tuner.c └── udp_buffer_tuner.h └── test ├── .gitignore ├── Makefile ├── backlog_legacy_test.sh ├── backlog_test.sh ├── budget_test.sh ├── cap_test.sh ├── cong_legacy_test.sh ├── cong_test.sh ├── conn_bomb.c ├── file_download_legacy_test.sh ├── file_download_test.sh ├── frag_legacy_test.sh ├── frag_test.sh ├── good_syn_flood_test.sh ├── inotify_test.sh ├── iperf3_test.sh ├── log_test.sh ├── many_netns_legacy_test.sh ├── many_netns_test.sh ├── mem_exhaust_legacy_test.sh ├── mem_exhaust_test.sh ├── mem_pressure_legacy_test.sh ├── mem_pressure_test.sh ├── mem_test.sh ├── neigh_table_legacy_test.sh ├── neigh_table_test.sh ├── neigh_table_v4only_test.sh ├── netns_legacy_test.sh ├── netns_test.sh ├── pcp_pmda_test.sh ├── podman_globalonly_legacy_test.sh ├── podman_globalonly_test.sh ├── qperf_test.sh ├── query_test.sh ├── rate_test.sh ├── rmem_legacy_test.sh ├── rmem_test.sh ├── rollback_legacy_test.sh ├── rollback_test.sh ├── route_table_test.sh ├── sample_legacy_test.sh ├── sample_test.sh ├── service_test.sh ├── strategy ├── Makefile ├── README.md ├── strategy_tuner.bpf.c └── strategy_tuner.c ├── strategy_legacy_test.sh ├── strategy_test.sh ├── stress_ng_test.sh ├── support_test.sh ├── syn_flood_test.sh ├── sysctl_legacy_test.sh ├── sysctl_netns_test.sh ├── sysctl_test.sh ├── test_lib.sh ├── udp_mem_exhaust_test.sh ├── udp_rmem_legacy_test.sh ├── udp_rmem_locked_test.sh ├── udp_rmem_test.sh ├── wmem_legacy_test.sh └── wmem_test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so* 3 | *.8 4 | *.skel.h 5 | *.skel.legacy.h 6 | *.skel.nobtf.h 7 | *.swp 8 | *.plist 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2 | # 3 | # Copyright (c) 2023, Oracle and/or its affiliates. 4 | # 5 | # This program is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public 7 | # License v2 as published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public 15 | # License along with this program; if not, write to the 16 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 021110-1307, USA. 18 | # 19 | 20 | PKG_NAME = `rpmspec -q --queryformat="%{NAME}-%{VERSION}-%{RELEASE}\n" buildrpm/bpftune.spec | head -1`.`uname -m` 21 | PKG_ARCHIVE = `rpmspec -q --queryformat="%{NAME}-%{VERSION}\n" buildrpm/bpftune.spec | head -1` 22 | PKG_DIR ?= ${HOME}/rpmbuild 23 | SRC_DIR = $(PKG_DIR)/SOURCES 24 | THIS_DIR = `basename $PWD` 25 | LICENSEDIR ?= $(PKG_DIR)/BUILD 26 | BUILD_DIR = $(PKG_DIR)/BUILDROOT/$(PKG_NAME) 27 | 28 | DESTDIR ?= 29 | prefix ?= /usr 30 | installprefix ?= $(DESTDIR)/$(prefix) 31 | 32 | INSTALLPATH = $(installprefix) 33 | 34 | .DELETE_ON_ERROR: 35 | 36 | .PHONY: all clean 37 | 38 | all: srcdir docdir testdir 39 | 40 | srcdir: 41 | cd src; make 42 | docdir: 43 | cd docs; make man 44 | 45 | testdir: srcdir 46 | cd test; make 47 | 48 | test: FORCE 49 | cd test; make test 50 | 51 | pkg: all 52 | mkdir -p $(SRC_DIR) $(BUILD_DIR) $(BUILD_DIR)/$(prefix) $(LICENSEDIR);\ 53 | rm -fr $(SRC_DIR)/$(PKG_ARCHIVE)* ;\ 54 | git archive --format=tar --prefix=$(PKG_ARCHIVE)/ -o $(SRC_DIR)/$(PKG_ARCHIVE).tar HEAD;\ 55 | bzip2 $(SRC_DIR)/$(PKG_ARCHIVE).tar ; \ 56 | cp -pr LICENSE* $(LICENSEDIR) ;\ 57 | DESTDIR=$(BUILD_DIR) installprefix=$(BUILD_DIR)/$(prefix) rpmbuild --define "_topdir $(PKG_DIR)" -ba buildrpm/bpftune.spec 58 | 59 | FORCE: 60 | 61 | clean: srcclean docclean testclean 62 | 63 | distclean: clean distclean_src 64 | 65 | srcclean: 66 | cd src; make clean 67 | docclean: 68 | cd docs; make clean 69 | distclean_src: 70 | cd src; make distclean 71 | testclean: 72 | cd test; make clean 73 | 74 | install: srcinstall includeinstall docinstall pcpinstall 75 | 76 | srcinstall: 77 | cd src; make install 78 | includeinstall: 79 | cd include; make install 80 | docinstall: 81 | cd docs; make install 82 | pcpinstall: 83 | cd src/pcp; make install 84 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting security vulnerabilities 2 | 3 | Oracle values the independent security research community and believes that 4 | responsible disclosure of security vulnerabilities helps us ensure the security 5 | and privacy of all our users. 6 | 7 | Please do NOT raise a GitHub Issue to report a security vulnerability. If you 8 | believe you have found a security vulnerability, please submit a report to 9 | [secalert_us@oracle.com][1] preferably with a proof of concept. Please review 10 | some additional information on [how to report security vulnerabilities to Oracle][2]. 11 | We encourage people who contact Oracle Security to use email encryption using 12 | [our encryption key][3]. 13 | 14 | We ask that you do not use other channels or contact the project maintainers 15 | directly. 16 | 17 | Non-vulnerability related security issues including ideas for new or improved 18 | security features are welcome on GitHub Issues. 19 | 20 | ## Security updates, alerts and bulletins 21 | 22 | Security updates will be released on a regular cadence. Many of our projects 23 | will typically release security fixes in conjunction with the 24 | Oracle Critical Patch Update program. Additional 25 | information, including past advisories, is available on our [security alerts][4] 26 | page. 27 | 28 | ## Security-related information 29 | 30 | We will provide security related information such as a threat model, considerations 31 | for secure use, or any known security issues in our documentation. Please note 32 | that labs and sample code are intended to demonstrate a concept and may not be 33 | sufficiently hardened for production use. 34 | 35 | [1]: mailto:secalert_us@oracle.com 36 | [2]: https://www.oracle.com/corporate/security-practices/assurance/vulnerability/reporting.html 37 | [3]: https://www.oracle.com/security-alerts/encryptionkey.html 38 | [4]: https://www.oracle.com/security-alerts/ 39 | -------------------------------------------------------------------------------- /bpftune.tcp_buffer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/bpftune/0bec9fe09b024fd0d4d3a4ae7f8529c50e7bb41b/bpftune.tcp_buffer.png -------------------------------------------------------------------------------- /buildrpm/bpftune.spec: -------------------------------------------------------------------------------- 1 | # BPF-based auto-tuning SPEC file 2 | 3 | %define name bpftune 4 | %define rel 1 5 | %define release %{rel}%{?dist} 6 | %define version 0.2 7 | %global _unitdir /usr/lib/systemd/system/ 8 | %global pcpdir /var/lib/pcp/pmdas 9 | 10 | License: GPLv2 WITH Linux-syscall-note 11 | Name: %{name} 12 | Summary: BPF/tracing tools for auto-tuning Linux 13 | Group: Development/Tools 14 | Requires: libbpf >= 0.6 15 | Requires: libnl3 16 | Requires: libcap 17 | BuildRequires: libbpf-devel >= 0.6 18 | BuildRequires: libcap-devel 19 | BuildRequires: bpftool >= 4.18 20 | BuildRequires: libnl3-devel 21 | BuildRequires: clang >= 11 22 | BuildRequires: clang-libs >= 11 23 | BuildRequires: llvm >= 11 24 | BuildRequires: llvm-libs >= 11 25 | BuildRequires: python3-docutils 26 | Version: %{version} 27 | Release: %{release} 28 | Source: bpftune-%{version}.tar.bz2 29 | Prefix: %{_prefix} 30 | 31 | %description 32 | Service consisting of daemon (bpftune) and plugins which 33 | support auto-tuning of Linux via BPF observability. 34 | 35 | %package devel 36 | Summary: Development files for %{name} 37 | Requires: %{name} = %{version}-%{release} 38 | Requires: libbpf-devel >= 0.6 39 | Requires: libcap-devel 40 | Requires: bpftool 41 | Requires: libnl3-devel 42 | 43 | %description devel 44 | The %{name}-devel package contains libraries and header files for 45 | developing BPF shared object tuners that use %{name} 46 | 47 | %package pcp-pmda 48 | Summary: Performance Co-Pilot PMDA for bpftune 49 | Requires: %{name} = %{version}-%{release} 50 | Requires: pcp 51 | Requires: python3-pcp 52 | 53 | %description pcp-pmda 54 | The %{name}-pcp-pmda exports tunables and metrics from bpftune 55 | to Performance Co-Pilot (PCP) 56 | 57 | %prep 58 | %setup -q -n bpftune-%{version} 59 | 60 | %build 61 | make 62 | 63 | %install 64 | rm -Rf %{buildroot} 65 | %make_install 66 | 67 | %files 68 | %defattr(-,root,root) 69 | %{_sysconfdir}/ld.so.conf.d/libbpftune.conf 70 | %{_sbindir}/bpftune 71 | %{_unitdir}/bpftune.service 72 | %{_libdir}/libbpftune.so.%{version}.%{rel} 73 | %{_libdir}/bpftune/* 74 | %{_mandir}/*/* 75 | 76 | %license LICENSE.txt 77 | 78 | %files devel 79 | %{_libdir}/libbpftune.so 80 | %{_includedir}/bpftune 81 | 82 | %license LICENSE.txt 83 | 84 | %files pcp-pmda 85 | %{pcpdir}/%{name}/* 86 | 87 | %license LICENSE.txt 88 | 89 | %changelog 90 | * Wed Mar 26 2025 Alan Maguire - 0.2-1 91 | - Add support for PCP PMDA package 92 | * Tue May 30 2023 Alan Maguire - 0.1-3 93 | - Fix timeout retry logic in libbpftune. [Orabug: 35385703] 94 | * Wed May 24 2023 Alan Maguire - 0.1-2 95 | - Spec file reviewed. 96 | * Mon May 30 2022 Alan Maguire - 0.1-1 97 | - Initial packaging support 98 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | bpftune (0-1) UNRELEASED; urgency=medium 2 | 3 | * Initial release. (Closes: #nnnn) 4 | 5 | -- Bernd Zeimetz Thu, 28 Nov 2024 21:39:29 +0100 6 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: bpftune 2 | Section: admin 3 | Priority: optional 4 | Maintainer: Bernd Zeimetz 5 | Rules-Requires-Root: no 6 | Build-Depends: 7 | debhelper-compat (= 13), 8 | python3-docutils, 9 | libbpf-dev, 10 | libcap-dev, 11 | clang, 12 | llvm, 13 | bpftool, 14 | libnl-3-dev, 15 | libnl-route-3-dev, 16 | iperf3 17 | Standards-Version: 4.7.0 18 | Homepage: https://github.com/oracle/bpftune/tree/main 19 | #Vcs-Browser: https://salsa.debian.org/debian/bpftune 20 | #Vcs-Git: https://salsa.debian.org/debian/bpftune.git 21 | 22 | Package: bpftune 23 | Architecture: any 24 | Depends: 25 | ${shlibs:Depends}, 26 | ${misc:Depends}, 27 | Description: BPF driven auto-tuning 28 | bpftune aims to provide lightweight, always-on auto-tuning 29 | of system behaviour via BPF observability. 30 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Source: https://github.com/oracle/bpftune 3 | Upstream-Name: bpftune 4 | Upstream-Contact: https://github.com/oracle/bpftune/issues 5 | 6 | Files: 7 | * 8 | Copyright: 9 | 2023 Oracle and/or its affiliates 10 | License: GPL-2.0 WITH Linux-syscall-note 11 | This package is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | . 16 | This package is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | . 21 | You should have received a copy of the GNU General Public License 22 | along with this package. If not, see . 23 | . 24 | With an explicit syscall exception, as stated: 25 | . 26 | SPDX-Exception-Identifier: Linux-syscall-note 27 | SPDX-URL: https://spdx.org/licenses/Linux-syscall-note.html 28 | SPDX-Licenses: GPL-2.0 29 | Usage-Guide: 30 | This exception is used together with one of the above SPDX-Licenses 31 | to mark user space API (uapi) header files so they can be included 32 | into non GPL compliant user space application code. 33 | To use this exception add it with the keyword WITH to one of the 34 | identifiers in the SPDX-Licenses tag: 35 | SPDX-License-Identifier: WITH Linux-syscall-note 36 | License-Text: 37 | . 38 | NOTE! This copyright does *not* cover user programs that use kernel 39 | services by normal system calls - this is merely considered normal use 40 | of the kernel, and does *not* fall under the heading of "derived work". 41 | Also note that the GPL below is copyrighted by the Free Software 42 | Foundation, but the instance of code that it refers to (the Linux 43 | kernel) is copyrighted by me and others who actually wrote it. 44 | . 45 | Also note that the only valid version of the GPL as far as the kernel 46 | is concerned is _this_ particular version of the license (ie v2, not 47 | v2.2 or v3.x or whatever), unless explicitly otherwise stated. 48 | Comment: 49 | On Debian systems, the complete text of the GNU General 50 | Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". 51 | 52 | 53 | Files: 54 | debian/* 55 | Copyright: 56 | 2024 Bernd Zeimetz 57 | License: GPL-2.0 WITH Linux-syscall-note 58 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | # See debhelper(7) (uncomment to enable). 4 | # Output every command that modifies files on the build system. 5 | #export DH_VERBOSE = 1 6 | 7 | 8 | # See FEATURE AREAS in dpkg-buildflags(1). 9 | export DEB_BUILD_MAINT_OPTIONS = hardening=+all 10 | 11 | # See ENVIRONMENT in dpkg-buildflags(1). 12 | # Package maintainers to append CFLAGS. 13 | #export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic 14 | # Package maintainers to append LDFLAGS. 15 | #export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed 16 | 17 | export libdir=lib 18 | 19 | %: 20 | dh $@ 21 | 22 | clean: 23 | dh $@ 24 | rm -f src/*.plist 25 | 26 | override_dh_auto_test: 27 | # no test for now, needs root and more magic. 28 | 29 | override_dh_auto_install: 30 | dh_auto_install 31 | rm -rf debian/bpftune/etc 32 | 33 | # dh_make generated override targets. 34 | # This is an example for Cmake (see ). 35 | #override_dh_auto_configure: 36 | # dh_auto_configure -- \ 37 | # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) 38 | -------------------------------------------------------------------------------- /debian/salsa-ci.yml: -------------------------------------------------------------------------------- 1 | # For more information on what jobs are run see: 2 | # https://salsa.debian.org/salsa-ci-team/pipeline 3 | # 4 | # To enable the jobs, go to your repository (at salsa.debian.org) 5 | # and click over Settings > CI/CD > Expand (in General pipelines). 6 | # In "CI/CD configuration file" write debian/salsa-ci.yml and click 7 | # in "Save Changes". The CI tests will run after the next commit. 8 | --- 9 | include: 10 | - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/recipes/debian.yml 11 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /debian/upstream/metadata: -------------------------------------------------------------------------------- 1 | Bug-Database: https://github.com/oracle/bpftune/issues 2 | Bug-Submit: https://github.com/oracle/bpftune/issues/new 3 | Changelog: https://github.com/oracle/bpftune/blob/master/CHANGES 4 | Documentation: https://github.com/oracle/bpftune/wiki 5 | Repository-Browse: https://github.com/oracle/bpftune 6 | Repository: https://github.com/oracle/bpftune.git 7 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2 | # 3 | # Copyright (c) 2023, Oracle and/or its affiliates. 4 | # 5 | # This program is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public 7 | # License v2 as published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public 15 | # License along with this program; if not, write to the 16 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 021110-1307, USA. 18 | # 19 | 20 | INSTALL ?= install 21 | RM ?= rm -f 22 | RMDIR ?= rmdir --ignore-fail-on-non-empty 23 | 24 | ifeq ($(V),1) 25 | Q = 26 | else 27 | Q = @ 28 | endif 29 | 30 | DESTDIR ?= 31 | prefix ?= /usr/share 32 | installprefix = $(DESTDIR)/$(prefix) 33 | 34 | mandir ?= $(prefix)/man 35 | man8dir = $(mandir)/man8 36 | 37 | MAN8_RST = bpftune.rst bpftune-sysctl.rst bpftune-tcp-conn.rst \ 38 | bpftune-neigh.rst bpftune-tcp-buffer.rst bpftune-netns.rst \ 39 | bpftune-net-buffer.rst bpftune-ip-frag.rst bpftune-udp-buffer.rst 40 | 41 | _DOC_MAN8 = $(patsubst %.rst,%.8,$(MAN8_RST)) 42 | DOC_MAN8 = $(addprefix $(OUTPUT),$(_DOC_MAN8)) 43 | 44 | man: man8 45 | man8: $(DOC_MAN8) 46 | 47 | RST2MAN_DEP := $(shell command -v rst2man 2>/dev/null) 48 | RST2MAN_OPTS += --verbose 49 | 50 | list_pages = $(sort $(basename $(filter-out $(1),$(MAN8_RST)))) 51 | see_also = $(subst " ",, \ 52 | "\n" \ 53 | "SEE ALSO\n" \ 54 | "========\n" \ 55 | "\t**bpf**\ (2), **bpftune**\ (8),\n") 56 | 57 | $(OUTPUT)%.8: %.rst 58 | $(QUIET_GEN)( cat $< ; printf "%b" $(call see_also,$<) ) | rst2man $(RST2MAN_OPTS) > $@ 59 | 60 | clean: 61 | $(call QUIET_CLEAN, Documentation) 62 | $(Q)$(RM) $(DOC_MAN8) 63 | 64 | install: man 65 | $(call QUIET_INSTALL, Documentation-man) 66 | $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(man8dir) 67 | $(Q)$(INSTALL) -m 644 $(DOC_MAN8) $(DESTDIR)$(man8dir) 68 | 69 | uninstall: 70 | $(call QUIET_UNINST, Documentation-man) 71 | $(Q)$(RM) $(addprefix $(DESTDIR)$(man8dir)/,$(_DOC_MAN8)) 72 | $(Q)$(RMDIR) $(DESTDIR)$(man8dir) 73 | 74 | .PHONY: man man8 clean install uninstall 75 | .DEFAULT_GOAL := man 76 | -------------------------------------------------------------------------------- /docs/bpftune-ip-frag.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | BPFTUNE-IP-FRAG 3 | =============== 4 | ------------------------------------------------------------------------------- 5 | IP fragmentation bpftune plugin for managing fragment reassembly memory limits 6 | ------------------------------------------------------------------------------- 7 | 8 | :Manual section: 8 9 | 10 | 11 | DESCRIPTION 12 | =========== 13 | 14 | For IPv[46] fragmentation reassembly, memory is capped at 15 | 16 | net.ipv[46].ip[6]frag_high_thresh 17 | 18 | Fragmentation reassembly can fail if this value is set too low; 19 | monitor for fragmentation reassembly and bump value if needed. 20 | 21 | Avoid bumping it if assembly failures are correlated with 22 | increases in frag_high_thresh; this suggests that increasing 23 | available memory does not help. While correlation is high, 24 | tune down the frag_high_thresh value. 25 | 26 | Tunables: 27 | 28 | - net.ipv4.ipfrag_high_thresh: number of bytes devoted to 29 | IPv4 fragmentation reassembly; default 4MB 30 | - net.ipv6.ip6frag_high_thresh: number of bytes devoted to 31 | IPv6 fragmentation reassembly; default 4MB 32 | -------------------------------------------------------------------------------- /docs/bpftune-neigh.rst: -------------------------------------------------------------------------------- 1 | ================ 2 | BPFTUNE-NEIGH 3 | ================ 4 | ------------------------------------------------------------------------------- 5 | Neighbor table bpftune plugin for managing neighbor table sizing 6 | ------------------------------------------------------------------------------- 7 | 8 | :Manual section: 8 9 | 10 | 11 | DESCRIPTION 12 | =========== 13 | The neighbor table contains layer 3 -> layer 2 mappings and 14 | reachability information on remote systems. We look up via 15 | layer 3 address (IP address) to find layer 2 address (MAC address) 16 | associated. 17 | 18 | The table is populated with both static and garbage-collected values. 19 | When adding entries we can specify that they should be PERMANENT, 20 | in which case they are not (exempt from) garbage-collected. 21 | 22 | Periodic garbage collection happens for non-permanent failed or 23 | expired entries; it is run immediately if we cannot alloc a 24 | new neighbor table entry. 25 | 26 | There are a few pathologies we want to avoid here, principally 27 | 28 | - neighbor table full: if we see /var/log/messages 29 | "Neighbour table overflow." we have run out of space. 30 | Can occur if garbage collection isn't run quickly enough 31 | or we are full with entries not subject to garbage collection. 32 | 33 | In former case, we could auto-tune by reducing gc_thresh2 since 34 | this makes GC run more quickly. 35 | 36 | In the latter case, with a large number (75% or more) of 37 | exempt from GC entries, garbage collection won't help 38 | so we have to increase gc_thresh3. This is done on a per-table 39 | basis via netlink, so the resource costs are limitied rather 40 | than setting a system-wide tunable. Size is increased by 41 | 25% of the current value (so 1024 -> 1280, etc). 42 | 43 | Note that by increasing gc_thresh3 only, garbage collection gets 44 | gets more time to run from table sized gc_thresh2 until we 45 | reach gc_thresh3. So it effectively helps with both scenarios. 46 | 47 | - neighbor table thrashing: too-aggressive GC eviction might lead 48 | to excessive overhead in re-estabilishing L3->L2 reachability 49 | information. TBD. 50 | 51 | Tunables: 52 | 53 | - gc_interval: how often garbage collection should happen; 54 | default 30 seconds. 55 | - gc_stale_time: how often to check for stale entries. 56 | If neighbor goes stale, it is resolved again 57 | before sending data; defaults to 60sec 58 | - base_reachable_time_ms: how long neighbor entry is considered 59 | reachable for; defaults to 30sec. 60 | - gc_thresh1: with a table size below this value, no GC 61 | happens; default 128 62 | - gc_thresh2: soft max of entries in table; wait 5 secs if 63 | we exceed this value to do GC; default 512. 64 | - gc_thresh3: hard max for table size, GC will run if more 65 | entries than this exist, default 1024. 66 | 67 | Note: to set table size we need to use the equivalent of 68 | "ip ntable"; i.e. 69 | "ip ntable change name arp_cache dev eth0 thresh3 1024" 70 | (this is done directly in bpftune via netlink) 71 | 72 | Contrast this approach with simply choosing a large 73 | net.ipv4.neigh.gc_thresh3. If thresh2 and thresh3 74 | are far apart, we may over-garbage collect, whereas 75 | if they are close we may end up keeping around too 76 | many entries. In either case, we're mistuned because 77 | we've had to choose coarse-grained defaults rather 78 | than adapting on a per-table basis as the need arises. 79 | -------------------------------------------------------------------------------- /docs/bpftune-net-buffer.rst: -------------------------------------------------------------------------------- 1 | ================== 2 | BPFTUNE-NET-BUFFER 3 | ================== 4 | ------------------------------------------------------------------------------- 5 | Networking buffer bpftune plugin for managing net core buffers 6 | ------------------------------------------------------------------------------- 7 | 8 | :Manual section: 8 9 | 10 | 11 | DESCRIPTION 12 | =========== 13 | A backlog queue is used to buffer incoming traffic and its 14 | length is controlled by net.core.netdev_max_backlog. On 15 | fast connections (10Gb/s or higher) the default backlog length 16 | of 1024 can be insufficient; here the backlog length is increased 17 | if 1/16 of current backlog size in the last minute is dropped 18 | (drops occur when the backlog limit is reached). In addition, 19 | backlog drops can avoid small flows; the tunable 20 | net.core.flow_limit_cpu_bitmap can be used to set this on a 21 | per-cpu basis; when we see sufficient drops on a CPU, the 22 | appropriate bit is set in the CPU bitmask to prioritize small 23 | flows for drop avoidance. 24 | 25 | When NAPI polls to handle multiple packets, the number of packets 26 | is limited by net.core.netdev_budget while the time is limited 27 | by net.core.netdev_budget_usecs. If we hit the limit of number 28 | of packets processed without using the usecs budget the time_squeezed 29 | softnet stat is bumped; if we see increases in time_squeezed, bump 30 | netdev_budget/netdev_budget_usecs. 31 | 32 | However, we want to limit such increases if they lead to longer 33 | task scheduling wait times, so we monitor the ratio of time tasks 34 | spend waiting versus running across all processors, and if we see 35 | correlations between increases in netdev budget and wait/run ratio 36 | increases, netdev budget is tuned down. 37 | 38 | Tunables: 39 | 40 | - net.core.netdev_max_backlog: maximum per-cpu backlog queue length; 41 | default 1024. 42 | - net.core.flow_limit_cpu_bitmap: avoid drops for small flows on 43 | a per-cpu basis; default 0. 44 | - net.core.netdev_budget: maximum number of packets processed in 45 | a NAPI cycle 46 | - net.core.netdev_budget_usecs: maximum amount of time in microseconds 47 | for a NAPI cycle 48 | -------------------------------------------------------------------------------- /docs/bpftune-netns.rst: -------------------------------------------------------------------------------- 1 | ================== 2 | BPFTUNE-NETNS 3 | ================== 4 | ------------------------------------------------------------------------------- 5 | bpftune plugin for network namespace awareness 6 | ------------------------------------------------------------------------------- 7 | 8 | :Manual section: 8 9 | 10 | 11 | DESCRIPTION 12 | =========== 13 | bpftune needs to be namespace-aware; when it receives events, they 14 | are tied to a specific netns cookie, and if we see an event in that 15 | netns we want to be able to auto-tune within it and not in the global 16 | network namespace. 17 | 18 | On startup, the netns tuner iterates over the various sources of 19 | netns info to collate a list of network namespaces, and supplements 20 | this by watching for addition of network namespaces via BPF. 21 | Using this info, we can then maintain tuner state on a per-namespace 22 | basis. 23 | 24 | Per-namespace support requires netns cookie support; running 25 | "bpftune -S" shows if this is present. 26 | -------------------------------------------------------------------------------- /docs/bpftune-sysctl.rst: -------------------------------------------------------------------------------- 1 | ================ 2 | BPFTUNE-SYSCTL 3 | ================ 4 | ------------------------------------------------------------------------------- 5 | sysctl bpftune plugin for monitoring sysctl settings 6 | ------------------------------------------------------------------------------- 7 | 8 | :Manual section: 8 9 | 10 | 11 | DESCRIPTION 12 | =========== 13 | The sysctl tuner watches for administrator-driven sysctl settings, 14 | and disables tuners that could collide with them. 15 | 16 | Each tuner declares which sysctls it operates on, and if we see a sysctl 17 | setting that collides with one of our managed sysctls, the associated tuner 18 | is disabled. bpftune must be restarted to re-enable it. 19 | 20 | Intent is to get out of the way of the active administrator. 21 | 22 | -------------------------------------------------------------------------------- /docs/bpftune-udp-buffer.rst: -------------------------------------------------------------------------------- 1 | ================== 2 | BPFTUNE-UDP-BUFFER 3 | ================== 4 | ------------------------------------------------------------------------------- 5 | UDP buffer bpftune plugin for managing UDP buffer sizes, memory limits 6 | ------------------------------------------------------------------------------- 7 | 8 | :Manual section: 8 9 | 10 | 11 | DESCRIPTION 12 | =========== 13 | 14 | For UDP - like TCP - a triple of min, pressure, max 15 | represents UDP memory limits and is specified in 16 | 17 | net.ipv4.udp_mem 18 | 19 | If receive fails with -ENOBUFS this indicates memory 20 | limits are being reached; we adaptively increase pressure and 21 | max to ensure that memory exhaustion does not occur (as long 22 | as we do not approach real memory exhaustion). As memory 23 | exhaustion is approached and we can no longer increase 24 | overall memory limits, reduce net.core.rmem* values to limit 25 | socket memory overheads. 26 | 27 | For UDP receive buffer memory, bump net.core.rmem_max if 28 | a socket experiences receive buffer drops within range of 29 | the rmem_max_value. Similarly bump rmem_default if sockets are 30 | within range of it and do not have a locked (via setsockopt) 31 | value. 32 | 33 | Tunables: 34 | 35 | - net.ipv4.udp_mem: min, pressure, max UDP memory 36 | - net.core.rmem_max: max rcvbuf size specifiable via setsockopt() 37 | - net.core.rmem_default: default rcvbuf size where none was set 38 | -------------------------------------------------------------------------------- /include/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2 | # 3 | # Copyright (c) 2023, Oracle and/or its affiliates. 4 | # 5 | # This program is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public 7 | # License v2 as published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public 15 | # License along with this program; if not, write to the 16 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 021110-1307, USA. 18 | # 19 | 20 | INSTALLFILES = $(wildcard bpftune/*.h) 21 | 22 | DESTDIR ?= 23 | prefix ?= /usr 24 | installprefix ?= $(DESTDIR)/$(prefix) 25 | 26 | INSTALLPATH = $(installprefix)/include 27 | 28 | install_sh_HDR = install -m 0444 29 | install_sh_DIR = install -dv 30 | 31 | all: 32 | 33 | install: $(INSTALLFILES) 34 | $(install_sh_DIR) -d $(INSTALLPATH)/bpftune ; \ 35 | $(install_sh_HDR) $^ -t $(INSTALLPATH)/bpftune ; \ 36 | 37 | -------------------------------------------------------------------------------- /include/bpftune/corr.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #ifndef _CORR_H 21 | #define _CORR_H 22 | 23 | #define CORR_MIN_SAMPLES 10 24 | 25 | /* threshold at which we determine correlation is significant */ 26 | #define CORR_THRESHOLD ((long double)0.75) 27 | #define CORR_HIGH_THRESHOLD ((long double)0.9) 28 | 29 | /* correlate tunables via id + netns cookie */ 30 | struct corr_key { 31 | __u64 id; 32 | unsigned long netns_cookie; 33 | }; 34 | 35 | struct corr { 36 | __u64 n; 37 | __u64 sum_x; 38 | __u64 sum_x_sq; 39 | __u64 sum_y; 40 | __u64 sum_y_sq; 41 | __u64 sum_prod_x_y; 42 | }; 43 | 44 | static inline void corr_reset(struct corr *c) 45 | { 46 | __builtin_memset(c, 0, sizeof(*c)); 47 | } 48 | 49 | /* reset correlation if we overflow any values */ 50 | #define corr_update_var(c, var, delta) \ 51 | do { \ 52 | if (((c->var) + (delta)) < c->var) { \ 53 | corr_reset(c); \ 54 | return; \ 55 | } \ 56 | (c->var) += (delta); \ 57 | } while (0) 58 | 59 | static inline void corr_update(struct corr *c, __u64 x, __u64 y) 60 | { 61 | corr_update_var(c, n, 1); 62 | corr_update_var(c, sum_x, x); 63 | corr_update_var(c, sum_x_sq, x*x); 64 | corr_update_var(c, sum_y, y); 65 | corr_update_var(c, sum_y_sq, y*y); 66 | corr_update_var(c, sum_prod_x_y, x*y); 67 | } 68 | 69 | #ifndef __KERNEL__ 70 | 71 | #include 72 | 73 | /* covar(x,y) = sum((x - mean(x))(y - mean(y)))/(N-1) 74 | * 75 | * the above numerator simplifies to 76 | * 77 | * sum(x*y) + (N*mean(x)*mean(y)) - (2*sum(x)*mean(y)) - (2*sum(y)*mean(x)) 78 | * -> ...since mean(x) = sum(x)/N... 79 | * sum(x*y) + (sum(x)*sum(y)/N - sum(x)*sum(y)/N - sum(y)*sum(x)/N 80 | * 81 | * So 82 | * covar(x,y) = 83 | * -> 84 | * ((sum(x*y)) - (sum(x)*sum(y)))/N/(N-1) 85 | */ 86 | static inline long double covar_compute(struct corr *c) 87 | { 88 | long double result; 89 | 90 | if (c->n < CORR_MIN_SAMPLES) 91 | return 0; 92 | 93 | result = (long double)c->sum_prod_x_y - 94 | ((long double)(c->sum_x * c->sum_y)/c->n); 95 | result /= (c->n - 1); 96 | 97 | return result; 98 | } 99 | 100 | static inline long double corr_compute(struct corr *c) 101 | { 102 | long double cov = covar_compute(c); 103 | long double var_x, var_y; 104 | 105 | if (c->n < CORR_MIN_SAMPLES) 106 | return 0; 107 | var_x = ((long double)c->sum_x_sq - 108 | ((long double)(c->sum_x * c->sum_x)/c->n))/ 109 | (c->n - 1); 110 | var_y = ((long double)c->sum_y_sq - 111 | ((long double)(c->sum_y * c->sum_y)/c->n))/ 112 | (c->n - 1); 113 | 114 | if (var_x == 0 || var_y == 0) 115 | return 0; 116 | return cov/(sqrtl(var_x)*sqrtl(var_y)); 117 | } 118 | 119 | static inline int corr_update_user(int map, __u64 id, 120 | __u64 netns_cookie, 121 | __u64 x, __u64 y) 122 | { 123 | struct corr_key key = { .id = id, .netns_cookie = netns_cookie }; 124 | struct corr corr = {}; 125 | 126 | bpf_map_lookup_elem(map, &key, &corr); 127 | corr_update(&corr, x, y); 128 | return bpf_map_update_elem(map, &key, &corr, 0); 129 | } 130 | 131 | #endif /* __KERNEL__ */ 132 | 133 | #endif /* _CORR_H */ 134 | -------------------------------------------------------------------------------- /include/bpftune/rl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #ifndef _RL_H 21 | #define _RL_H 22 | 23 | #ifdef __KERNEL__ 24 | 25 | /* choose random state every epsilon states */ 26 | static __always_inline int epsilon_greedy(__u32 greedy_state, __u32 num_states, 27 | __u32 epsilon) 28 | { 29 | __u32 r = bpf_get_prandom_u32(); 30 | 31 | if (r % epsilon) 32 | return greedy_state; 33 | /* need a fresh random number, since we already know r % epsilon == 0. */ 34 | r = bpf_get_prandom_u32(); 35 | return r % num_states; 36 | } 37 | 38 | #endif /* __KERNEL__ */ 39 | 40 | /* simple RL update for a value function; use gain to update value function 41 | * using bitshift scaling for learning rate. 42 | */ 43 | static __always_inline __u64 rl_update(__u64 value, __u64 gain, __u8 bitshift) 44 | { 45 | if (!value) 46 | return gain; 47 | if (gain > value) 48 | return value + ((gain - value) >> bitshift); 49 | else if (gain < value) 50 | return value - ((value - gain) >> bitshift); 51 | else 52 | return value; 53 | } 54 | 55 | #endif /* _RL_H */ 56 | -------------------------------------------------------------------------------- /sample_tuner/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2 | # 3 | # Copyright (c) 2023, Oracle and/or its affiliates. 4 | # 5 | # This program is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public 7 | # License v2 as published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public 15 | # License along with this program; if not, write to the 16 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 021110-1307, USA. 18 | # 19 | 20 | SRCARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ 21 | -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \ 22 | -e s/aarch64.*/arm64/ ) 23 | 24 | CLANG ?= clang 25 | LLC ?= llc 26 | LLVM_STRIP ?= llvm-strip 27 | BPFTOOL ?= bpftool 28 | BPF_INCLUDE := /usr/include 29 | NL_INCLUDE := /usr/include/libnl3 30 | INCLUDES := -I$(BPF_INCLUDE) -I$(NL_INCLUDE) -I/usr/include/uapi 31 | 32 | INSTALL ?= install 33 | 34 | DESTDIR ?= 35 | prefix ?= /usr 36 | installprefix = $(DESTDIR)/$(prefix) 37 | 38 | INSTALLPATH = $(installprefix) 39 | 40 | CFLAGS = -fPIC -Wall -Wextra -march=native -g -I../include -std=c99 41 | 42 | CFLAGS += -DBPFTUNE_VERSION='"$(BPFTUNE_VERSION)"' $(INCLUDES) 43 | 44 | LDLIBS = -lbpf -ldl -lm -lcap -lpthread 45 | 46 | LDFLAGS += -L. -L/usr/local/lib64 47 | 48 | ifeq ($(V),1) 49 | Q = 50 | else 51 | Q = @ 52 | MAKEFLAGS += --no-print-directory 53 | submake_extras := feature_display=0 54 | endif 55 | 56 | TUNERS = sample_tuner 57 | 58 | TUNER_OBJS = $(patsubst %,%.o,$(TUNERS)) 59 | TUNER_LIBS = $(patsubst %,%.so,$(TUNERS)) 60 | 61 | BPF_TUNERS = $(patsubst %,%.bpf.o,$(TUNERS)) 62 | 63 | BPF_OBJS = $(BPF_TUNERS) 64 | 65 | BPF_SKELS = $(patsubst %,%.skel.h,$(TUNERS)) 66 | 67 | .DELETE_ON_ERROR: 68 | 69 | .PHONY: clean 70 | 71 | all: $(TUNER_LIBS) 72 | 73 | clean: 74 | $(Q)$(RM) *.o *.d *.so* 75 | $(Q)$(RM) *.skel*.h 76 | $(Q)$(RM) -r .output 77 | 78 | install: all 79 | $(INSTALL) -m 0755 -d $(INSTALLPATH)/local/lib64 80 | $(INSTALL) -m 0755 -d $(INSTALLPATH)/local/lib64/bpftune 81 | $(INSTALL) $(TUNER_LIBS) $(INSTALLPATH)/local/lib64/bpftune 82 | 83 | $(TUNER_LIBS): $(BPF_SKELS) $(TUNER_OBJS) 84 | $(CC) $(CFLAGS) -shared -o $(@) $(patsubst %.so,%.c,$(@)) \ 85 | $(LDLIBS) -lbpftune $(LDFLAGS) 86 | 87 | %.skel.h: %.bpf.o 88 | $(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@ 89 | 90 | $(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS)) ../include/bpftune/bpftune.bpf.h 91 | $(CLANG) -g -D__TARGET_ARCH_$(SRCARCH) -O2 -target bpf \ 92 | $(INCLUDES) -c $(patsubst %.o,%.c,$(@)) -o $(@); 93 | $(CLANG) -g -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_LEGACY -O2 -target bpf \ 94 | $(INCLUDES) -c $(patsubst %.o,%.c,$(@)) \ 95 | -o $(patsubst %.o,%.legacy.o,$(@)); 96 | $(CLANG) -g -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_NOBTF -DBPFTUNE_LEGACY -O2 -target bpf \ 97 | $(INCLUDES) -c $(patsubst %.o,%.c,$(@)) \ 98 | -o $(patsubst %.o,%.nobtf.o,$(@)); 99 | 100 | $(BPF_SKELS): $(BPF_OBJS) 101 | $(BPFTOOL) gen skeleton $(subst .skel.h,.bpf.o,$@) > $@ ;\ 102 | $(BPFTOOL) gen skeleton $(subst .skel.h,.bpf.legacy.o,$@) > $(subst .skel.h,.skel.legacy.h,$@);\ 103 | $(BPFTOOL) gen skeleton $(subst .skel.h,.bpf.nobtf.o,$@) > $(subst .skel.h,.skel.nobtf.h,$@) 104 | 105 | -------------------------------------------------------------------------------- /sample_tuner/README.md: -------------------------------------------------------------------------------- 1 | # sample tuner 2 | 3 | simple example showing Makefile and bpf/userspace portions of a 4 | tuner shared object. This sample tuner fires events when 5 | coredump sysctls are read as a demonstration of how to send/catch 6 | ring buffer events. 7 | -------------------------------------------------------------------------------- /sample_tuner/sample_tuner.bpf.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | /* fire when coredump sysctls are read */ 23 | BPF_FENTRY(proc_dostring_coredump, struct ctl_table *table, int write, 24 | void *buffer, size_t *lenp, loff_t *ppos) 25 | { 26 | struct bpftune_event event = {}; 27 | int ret, scenario_id = 0; 28 | 29 | /* tuner id is a global declared in bpftune.bpf.h and set by bfttune 30 | * when the tuner is added. 31 | */ 32 | event.tuner_id = tuner_id; 33 | event.scenario_id = scenario_id; 34 | ret = bpf_ringbuf_output(&ring_buffer_map, &event, sizeof(event), 0); 35 | bpftune_debug("tuner [%d] scenario [%d]: event send: %d ", 36 | tuner_id, scenario_id, ret); 37 | return 0; 38 | } 39 | 40 | BPF_FENTRY(this_function_does_not_exist, void *arg) 41 | { 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /sample_tuner/sample_tuner.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include "sample_tuner.skel.h" 23 | #include "sample_tuner.skel.legacy.h" 24 | #include "sample_tuner.skel.nobtf.h" 25 | 26 | int init(struct bpftuner *tuner) 27 | { 28 | const char *optionals[] = { "entry__this_function_does_not_exist", 29 | NULL }; 30 | 31 | return bpftuner_bpf_init(sample, tuner, optionals); 32 | } 33 | 34 | void fini(struct bpftuner *tuner) 35 | { 36 | bpftuner_bpf_fini(tuner); 37 | } 38 | 39 | void event_handler(struct bpftuner *tuner, struct bpftune_event *event, 40 | __attribute__((unused))void *ctx) 41 | { 42 | bpftune_log(LOG_DEBUG, "event (scenario %d) for tuner %s\n", 43 | event->scenario_id, tuner->name); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | bpftune 2 | vmlinux.h 3 | *.skel.h 4 | *.skel.legacy.h 5 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # Adding new tuners 2 | 3 | 1. Create 4 | - tuner_name_tuner.bpf.c containing BPF programs. It must 5 | ``` 6 | #include "bpftune.bpf.h" 7 | ``` 8 | - tuner_name_tuner.c containing init, fini and event handler. It must 9 | ``` 10 | #include 11 | ``` 12 | 13 | - tuner_name_tuner.h containing common definitions for bpf/userspace; 14 | examples of these are enumerated values covering tunable and 15 | scenario ids (see tcp_buffer_tuner.h for examples). 16 | 17 | 18 | Ensure that LOG_INFO events are logged when tunable updates are 19 | made; this allows the admin to understand what changes were made 20 | and motivations for doing so. bpftuner_tunable_sysctl_write() can be 21 | used as a wrapper for sysctl changes which takes care of logging 22 | (additional reasons can be supplied) and bpftuner_tunable_update() 23 | can be used for other cases (see cong_tuner.c for example). 24 | 25 | 2. Add tuner_name to TUNERS in Makefile so it will be built. 26 | 27 | 3. Add bpftune-tuner-name.rst to docs and add tuner-name to TUNERS in 28 | Makefile there also. 29 | 30 | # Example 31 | 32 | neigh_table_tuner.bpf.c monitors neighbour table updates, and when the 33 | neighbour table is approaching garbage collection limits, those 34 | limits are raised. It consists of 35 | 36 | - src/neigh_table_tuner.bpf.c 37 | - src/neigh_table_tuner.c 38 | - src/neigh_table_tuner.h 39 | - docs/bpftune-neigh.rst 40 | 41 | We see that ringbuf messages are sent from the BPF program when the 42 | neighbour table approaches being full, and these are handled in the 43 | event_handler function. 44 | -------------------------------------------------------------------------------- /src/bpftune.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=BPF-based auto-tuning of system parameters 3 | After=systemd-sysctl.service network.target 4 | 5 | [Service] 6 | ExecStart=/usr/sbin/bpftune 7 | Restart=on-failure 8 | 9 | [Install] 10 | WantedBy=multi-user.target 11 | 12 | -------------------------------------------------------------------------------- /src/ip_frag_tuner.bpf.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include "ip_frag_tuner.h" 22 | #include 23 | 24 | static __always_inline int defrag(struct net *net, struct fqdir *fqdir, 25 | struct ipstats_mib *mib, int tunable) 26 | { 27 | long mem = BPFTUNE_CORE_READ(fqdir, mem.counter); 28 | long high_thresh = BPFTUNE_CORE_READ(fqdir, high_thresh); 29 | 30 | bpftune_debug("defrag: mem %ld high thresh %ld\n", 31 | mem, high_thresh); 32 | if (!fqdir || !mem || !high_thresh) 33 | return 0; 34 | 35 | /* do not raise limits when we see a correlation between raised fragment 36 | * threshold and fragmentation failures; this suggests DoS 37 | */ 38 | if (NEARLY_FULL(mem, high_thresh)) { 39 | struct bpftune_event event = { 0 }; 40 | long old[3] = {}; 41 | long new[3] = {}; 42 | 43 | old[0] = high_thresh; 44 | new[0] = BPFTUNE_GROW_BY_DELTA(high_thresh); 45 | send_net_sysctl_event(net, IP_FRAG_THRESHOLD_INCREASE, 46 | tunable, 47 | old, new, &event); 48 | } 49 | return 0; 50 | } 51 | 52 | BPF_FENTRY(ip_defrag, struct net *net, struct sk_buff *skb, u32 user) 53 | { 54 | struct fqdir *fqdir = BPFTUNE_CORE_READ(net, ipv4.fqdir); 55 | struct ipstats_mib *mib = BPFTUNE_CORE_READ(net, mib.ip_statistics); 56 | 57 | if (!fqdir) 58 | return 0; 59 | return defrag(net, fqdir, mib, IP_FRAG_MAX_THRESHOLD); 60 | } 61 | 62 | #define SKB_DST_NOREF 1UL 63 | #define SKB_DST_PTRMASK ~(SKB_DST_NOREF) 64 | BPF_FENTRY(ipv6_frag_rcv, struct sk_buff *skb) 65 | { 66 | long unsigned int refdst = BPFTUNE_CORE_READ(skb, _skb_refdst); 67 | struct dst_entry *dst = (struct dst_entry *)(refdst & SKB_DST_PTRMASK); 68 | struct ipstats_mib *mib; 69 | struct net_device *dev; 70 | struct fqdir *fqdir; 71 | struct net *net; 72 | 73 | if (!dst) 74 | return 0; 75 | dev = BPFTUNE_CORE_READ(dst, dev); 76 | if (!dev) 77 | return 0; 78 | net = BPFTUNE_CORE_READ(dev, nd_net.net); 79 | if (!net) 80 | return 0; 81 | fqdir = BPFTUNE_CORE_READ(net, ipv6.fqdir); 82 | if (!fqdir) 83 | return 0; 84 | mib = BPFTUNE_CORE_READ(net, mib.ipv6_statistics); 85 | if (!mib) 86 | return 0; 87 | return defrag(net, fqdir, mib, IP6_FRAG_MAX_THRESHOLD); 88 | } 89 | -------------------------------------------------------------------------------- /src/ip_frag_tuner.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* Copyright (c) 2023, Oracle and/or its affiliates. */ 3 | 4 | #include 5 | #include 6 | 7 | #include "ip_frag_tuner.h" 8 | #include "ip_frag_tuner.skel.h" 9 | #include "ip_frag_tuner.skel.legacy.h" 10 | #include "ip_frag_tuner.skel.nobtf.h" 11 | 12 | #include 13 | #include 14 | 15 | struct tcp_buffer_tuner_bpf *skel; 16 | 17 | static struct bpftunable_desc descs[] = { 18 | { IP_FRAG_MAX_THRESHOLD, BPFTUNABLE_SYSCTL, "net.ipv4.ipfrag_high_thresh", 19 | 0, 1 }, 20 | { IP6_FRAG_MAX_THRESHOLD, BPFTUNABLE_SYSCTL, "net.ipv6.ip6frag_high_thresh", 21 | BPFTUNABLE_OPTIONAL, 1 }, 22 | }; 23 | 24 | static struct bpftunable_scenario scenarios[] = { 25 | { IP_FRAG_THRESHOLD_INCREASE, "need to increase IP fragmentation high threshold", 26 | "this allows additional memory to be used to accommodate more defragmentation." }, 27 | { IP_FRAG_THRESHOLD_DECREASE, "need to decrease IP fragmentation high threshold", 28 | "as we increased fragmentation high threshold we saw a correlation in reassembly failures; this indicates that we received more invalid fragments as we added memory to process them. As such, further increases are likely to be ineffective so reduce high threshold." }, 29 | }; 30 | 31 | int init(struct bpftuner *tuner) 32 | { 33 | int err; 34 | 35 | err = bpftuner_bpf_init(ip_frag, tuner, NULL); 36 | if (err) 37 | return err; 38 | return bpftuner_tunables_init(tuner, IP_FRAG_NUM_TUNABLES, descs, 39 | ARRAY_SIZE(scenarios), scenarios); 40 | } 41 | 42 | void fini(struct bpftuner *tuner) 43 | { 44 | bpftune_log(LOG_DEBUG, "calling fini for %s\n", tuner->name); 45 | bpftuner_bpf_fini(tuner); 46 | } 47 | 48 | void event_handler(struct bpftuner *tuner, 49 | struct bpftune_event *event, 50 | __attribute__((unused))void *ctx) 51 | { 52 | long new, old, reasmfails, reasmreqds, reasm_failrate; 53 | int scenario = event->scenario_id; 54 | struct corr c = { 0 }; 55 | long double corr = 0; 56 | struct corr_key key; 57 | const char *tunable; 58 | int id, af; 59 | 60 | /* netns cookie not supported; ignore */ 61 | if (event->netns_cookie == (unsigned long)-1) 62 | return; 63 | 64 | id = event->update[0].id; 65 | 66 | memcpy(&new, event->update[0].new, sizeof(new)); 67 | memcpy(&old, event->update[0].old, sizeof(old)); 68 | 69 | tunable = bpftuner_tunable_name(tuner, id); 70 | if (!tunable) { 71 | bpftune_log(LOG_DEBUG, "unknown tunable [%d] for ip_frag_tuner\n", id); 72 | return; 73 | } 74 | key.id = (__u64)id; 75 | key.netns_cookie = event->netns_cookie; 76 | 77 | af = id == IP_FRAG_MAX_THRESHOLD ? AF_INET : AF_INET6; 78 | if (!bpftune_snmpstat_read(event->netns_cookie, af, NULL, 79 | "ReasmFails", &reasmfails) && 80 | !bpftune_snmpstat_read(event->netns_cookie, af, NULL, 81 | "ReasmReqds", &reasmreqds)) { 82 | /* % of reasm fails */ 83 | reasm_failrate = (reasmfails * 100)/reasmreqds; 84 | bpftune_log(LOG_DEBUG, "got %ld reasmfails, %ld reasmreqds, %ld reasm fail rate (% of reasm failures)\n", 85 | reasmfails, reasmreqds, reasm_failrate); 86 | if (corr_update_user(tuner->corr_map_fd, key.id, key.netns_cookie, 87 | (__u64)new, (__u64)reasm_failrate)) { 88 | bpftune_log(LOG_DEBUG, "corr map fd %d xxx update failed %d\n", tuner->corr_map_fd, errno); 89 | } 90 | } 91 | if (!bpf_map_lookup_elem(tuner->corr_map_fd, &key, &c)) { 92 | corr = corr_compute(&c); 93 | bpftune_log(LOG_DEBUG, "covar for '%s' netns %ld (new %ld): %LF ; corr %LF\n", 94 | tunable, key.netns_cookie, new, covar_compute(&c), corr); 95 | if (corr > CORR_THRESHOLD && scenario == IP_FRAG_THRESHOLD_INCREASE) { 96 | scenario = IP_FRAG_THRESHOLD_DECREASE; 97 | new = BPFTUNE_SHRINK_BY_DELTA(old); 98 | } 99 | } 100 | 101 | switch (id) { 102 | case IP_FRAG_MAX_THRESHOLD: 103 | case IP6_FRAG_MAX_THRESHOLD: 104 | bpftuner_tunable_sysctl_write(tuner, id, scenario, 105 | event->netns_cookie, 1, &new, 106 | "Due to approaching fragmentation maximum threshold change %s from (%ld) -> (%ld)\n", 107 | tunable, old, new); 108 | break; 109 | default: 110 | break; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/ip_frag_tuner.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | 23 | enum ip_frag_tunables { 24 | IP_FRAG_MAX_THRESHOLD, 25 | IP6_FRAG_MAX_THRESHOLD, 26 | IP_FRAG_NUM_TUNABLES 27 | }; 28 | 29 | enum ip_frag_scenarios { 30 | IP_FRAG_THRESHOLD_INCREASE, 31 | IP_FRAG_THRESHOLD_DECREASE, 32 | }; 33 | -------------------------------------------------------------------------------- /src/libbpftune.map: -------------------------------------------------------------------------------- 1 | LIBBPFTUNE_0.1.1 { 2 | global: 3 | bpftune_log_level; 4 | bpftune_log_stderr; 5 | bpftune_log_syslog; 6 | bpftune_log_buf; 7 | bpftune_log; 8 | bpftune_set_log; 9 | bpftune_set_bpf_log; 10 | bpftune_log_bpf_err; 11 | bpftune_cap_add; 12 | bpftune_cap_drop; 13 | bpftune_set_learning_rate; 14 | bpftune_learning_rate; 15 | bpftune_cgroup_init; 16 | bpftune_cgroup_name; 17 | bpftune_cgroup_fd; 18 | bpftune_cgroup_fini; 19 | bpftuner_cgroup_attach; 20 | bpftuner_cgroup_detach; 21 | bpftune_server_start; 22 | bpftune_server_port; 23 | bpftune_server_request; 24 | bpftune_server_stop; 25 | bpftune_tuner; 26 | bpftune_tuner_num; 27 | bpftune_bpf_support; 28 | bpftuner_init; 29 | bpftune_force_bpf_support; 30 | __bpftuner_bpf_load; 31 | __bpftuner_bpf_attach; 32 | bpftuner_tunables_init; 33 | bpftuner_tunable; 34 | bpftuner_num_tunables; 35 | bpftuner_tunable_sysctl_write; 36 | bpftuner_tunable_update; 37 | bpftuner_tunable_stats_update; 38 | bpftuner_fini; 39 | bpftuner_bpf_fini; 40 | bpftuner_bpf_set_autoload; 41 | bpftuner_bpf_prog_in_strategy; 42 | bpftuner_tunables_fini; 43 | bpftune_netns_cookie_supported; 44 | bpftune_global_netns_cookie; 45 | bpftuner_netns_init; 46 | bpftuner_netns_fini; 47 | bpftuner_netns_from_cookie; 48 | bpftuner_netns_fd_from_cookie; 49 | bpftuner_ring_buffer_map_fd; 50 | bpftuner_strategy_set; 51 | bpftuner_strategies_add; 52 | bpftuner_rollback_set; 53 | bpftune_ring_buffer_init; 54 | bpftune_ring_buffer_poll; 55 | bpftune_ring_buffer_fini; 56 | bpftune_sysctl_name_to_path; 57 | bpftune_sysctl_read; 58 | bpftune_sysctl_read_string; 59 | bpftune_sysctl_write; 60 | bpftune_sysctl_write_string; 61 | bpftune_ksym_addr; 62 | bpftune_netstat_read; 63 | bpftune_snmpstat_read; 64 | bpftune_sched_wait_run_percent_read; 65 | bpftune_netns_init_all; 66 | bpftune_netns_set; 67 | bpftune_netns_info; 68 | bpftune_module_load; 69 | bpftune_module_unload; 70 | local: 71 | *; 72 | }; 73 | -------------------------------------------------------------------------------- /src/neigh_table_tuner.bpf.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include "neigh_table_tuner.h" 22 | 23 | BPF_MAP_DEF(tbl_map, BPF_MAP_TYPE_HASH, __u64, struct tbl_stats, 1024, 0); 24 | 25 | #ifdef BPFTUNE_LEGACY 26 | SEC("raw_tracepoint/neigh_create") 27 | #else 28 | SEC("tp_btf/neigh_create") 29 | #endif 30 | int BPF_PROG(bpftune_neigh_create, struct neigh_table *tbl, 31 | struct net_device *dev, const void *pkey, 32 | struct neighbour *n, bool exempt_from_gc) 33 | { 34 | 35 | struct tbl_stats *tbl_stats; 36 | struct bpftune_event event = {}; 37 | __u64 key = (__u64)tbl; 38 | 39 | tbl_stats = bpf_map_lookup_elem(&tbl_map, &key); 40 | 41 | if (!tbl_stats) { 42 | struct tbl_stats new_tbl_stats = {}; 43 | 44 | new_tbl_stats.family = BPFTUNE_CORE_READ(tbl, family); 45 | new_tbl_stats.entries = BPFTUNE_CORE_READ(tbl, entries.counter); 46 | new_tbl_stats.max = BPFTUNE_CORE_READ(tbl, gc_thresh3); 47 | if (dev) { 48 | bpf_probe_read(&new_tbl_stats.dev, sizeof(new_tbl_stats.dev), dev); 49 | new_tbl_stats.ifindex = BPFTUNE_CORE_READ(dev, ifindex); 50 | } 51 | bpf_map_update_elem(&tbl_map, &key, &new_tbl_stats, BPF_ANY); 52 | tbl_stats = bpf_map_lookup_elem(&tbl_map, &key); 53 | if (!tbl_stats) 54 | return 0; 55 | } 56 | tbl_stats->entries = BPFTUNE_CORE_READ(tbl, entries.counter); 57 | tbl_stats->gc_entries = BPFTUNE_CORE_READ(tbl, gc_entries.counter); 58 | tbl_stats->max = BPFTUNE_CORE_READ(tbl, gc_thresh3); 59 | 60 | /* exempt from gc entries are not subject to space constraints, but 61 | * do take up table entries. 62 | */ 63 | if (NEARLY_FULL(tbl_stats->entries, tbl_stats->max)) { 64 | struct neigh_parms *parms = BPFTUNE_CORE_READ(n, parms); 65 | struct net *net = BPFTUNE_CORE_READ(parms, net.net); 66 | 67 | event.tuner_id = tuner_id; 68 | event.scenario_id = NEIGH_TABLE_FULL; 69 | if (net) { 70 | event.netns_cookie = get_netns_cookie(net); 71 | if (event.netns_cookie < 0) 72 | return 0; 73 | } 74 | STATIC_ASSERT(sizeof(event.raw_data) >= sizeof(*tbl_stats), 75 | "event.raw_data too small"); 76 | __builtin_memcpy(&event.raw_data, tbl_stats, sizeof(*tbl_stats)); 77 | bpf_ringbuf_output(&ring_buffer_map, &event, sizeof(event), 0); 78 | } 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /src/neigh_table_tuner.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | #ifndef IFNAMSIZ 23 | #define IFNAMSIZ 16 24 | #endif 25 | 26 | enum neigh_table_tunables { 27 | NEIGH_TABLE_IPV4_GC_INTERVAL, 28 | NEIGH_TABLE_IPV4_GC_STALE_TIME, 29 | NEIGH_TABLE_IPV4_GC_THRESH1, 30 | NEIGH_TABLE_IPV4_GC_THRESH2, 31 | NEIGH_TABLE_IPV4_GC_THRESH3, 32 | NEIGH_TABLE_IPV6_GC_INTERVAL, 33 | NEIGH_TABLE_IPV6_GC_STALE_TIME, 34 | NEIGH_TABLE_IPV6_GC_THRESH1, 35 | NEIGH_TABLE_IPV6_GC_THRESH2, 36 | NEIGH_TABLE_IPV6_GC_THRESH3, 37 | NEIGH_TABLE_NUM_TUNABLES 38 | }; 39 | 40 | enum neigh_table_scenarios { 41 | NEIGH_TABLE_FULL, 42 | }; 43 | 44 | struct tbl_stats { 45 | int family; 46 | int entries; 47 | int gc_entries; 48 | int max; 49 | int ifindex; 50 | char dev[IFNAMSIZ]; 51 | }; 52 | -------------------------------------------------------------------------------- /src/net_buffer_tuner.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | enum net_buffer_tunables { 23 | NETDEV_MAX_BACKLOG, 24 | FLOW_LIMIT_CPU_BITMAP, 25 | NETDEV_BUDGET, 26 | NETDEV_BUDGET_USECS, 27 | NET_BUFFER_NUM_TUNABLES, 28 | }; 29 | 30 | enum net_buffer_scenarios { 31 | NETDEV_MAX_BACKLOG_INCREASE, 32 | FLOW_LIMIT_CPU_SET, 33 | NETDEV_BUDGET_INCREASE, 34 | NETDEV_BUDGET_DECREASE, 35 | }; 36 | -------------------------------------------------------------------------------- /src/netns_tuner.bpf.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include "netns_tuner.h" 22 | 23 | struct setup_net { 24 | struct net *net; 25 | }; 26 | 27 | BPF_MAP_DEF(setup_net_map, BPF_MAP_TYPE_HASH, __u64, __u64, 65536, 0); 28 | 29 | SEC("kprobe/setup_net") 30 | int BPF_KPROBE(bpftune_setup_net, struct net *net) 31 | { 32 | save_entry_data(setup_net_map, setup_net, net, net); 33 | return 0; 34 | } 35 | 36 | SEC("kretprobe/setup_net") 37 | int BPF_KRETPROBE(bpftune_setup_net_return, int ret) 38 | { 39 | struct bpftune_event event = {}; 40 | struct net *netns = NULL; 41 | 42 | if (ret != 0) 43 | return 0; 44 | 45 | get_entry_data(setup_net_map, setup_net, net, netns); 46 | if (netns == NULL) 47 | return 0; 48 | 49 | event.tuner_id = tuner_id; 50 | event.pid = bpf_get_current_pid_tgid() >> 32; 51 | event.scenario_id = NETNS_SCENARIO_CREATE; 52 | event.netns_cookie = get_netns_cookie(netns); 53 | if (event.netns_cookie >= 0) 54 | bpf_ringbuf_output(&ring_buffer_map, &event, sizeof(event), 0); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /src/netns_tuner.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include "netns_tuner.h" 22 | #include "netns_tuner.skel.h" 23 | #include "netns_tuner.skel.legacy.h" 24 | #include "netns_tuner.skel.nobtf.h" 25 | 26 | struct netns_tuner_bpf *skel; 27 | 28 | #define NETNS 0 29 | 30 | static struct bpftunable_desc descs[] = { 31 | { 32 | NETNS, BPFTUNABLE_OTHER, "network_namespace", BPFTUNABLE_NAMESPACED, 0 }, 33 | }; 34 | 35 | static struct bpftunable_scenario scenarios[] = { 36 | { NETNS_SCENARIO_CREATE, "netns created", "network namespace creation" }, 37 | { NETNS_SCENARIO_DESTROY, "netns destroyed", "network namespace destruction" }, 38 | }; 39 | 40 | int init(struct bpftuner *tuner) 41 | { 42 | const char *optionals[] = { "entry__net_free", NULL }; 43 | int err; 44 | 45 | if (!bpftune_netns_cookie_supported()) 46 | return -ENOTSUP; 47 | 48 | err = bpftuner_bpf_open(netns, tuner); 49 | if (err) 50 | return err; 51 | err = bpftuner_bpf_load(netns, tuner, optionals); 52 | if (err) 53 | return err; 54 | err = bpftuner_bpf_attach(netns, tuner); 55 | if (err) 56 | return err; 57 | 58 | return bpftuner_tunables_init(tuner, ARRAY_SIZE(descs), descs, 59 | ARRAY_SIZE(scenarios), scenarios); 60 | } 61 | 62 | void fini(struct bpftuner *tuner) 63 | { 64 | bpftune_log(LOG_DEBUG, "calling fini for %s\n", tuner->name); 65 | bpftuner_bpf_fini(tuner); 66 | } 67 | 68 | void event_handler(__attribute__((unused))struct bpftuner *tuner, 69 | struct bpftune_event *event, 70 | __attribute__((unused))void *ctx) 71 | { 72 | unsigned long netns_cookie; 73 | int netns_fd = 0, ret; 74 | struct bpftuner *t; 75 | 76 | switch (event->scenario_id) { 77 | case NETNS_SCENARIO_CREATE: 78 | ret = bpftune_netns_info(event->pid, &netns_fd, &netns_cookie); 79 | if (ret || netns_cookie != event->netns_cookie) { 80 | 81 | bpftune_log(LOG_DEBUG, "netns cookie from pid %d %ld != %ld (cookie from event)\n", 82 | event->pid, netns_cookie, event->netns_cookie); 83 | netns_fd = bpftuner_netns_fd_from_cookie(tuner, event->netns_cookie); 84 | if (netns_fd < 0) { 85 | bpftune_log(LOG_DEBUG, "netns fd not found for cookie %ld: %s\n", 86 | event->netns_cookie, strerror(-netns_fd)); 87 | return; 88 | } 89 | } 90 | bpftune_log(LOG_DEBUG, "got netns fd %d for cookie %ld\n", 91 | netns_fd, event->netns_cookie); 92 | bpftune_for_each_tuner(t) 93 | bpftuner_netns_init(t, event->netns_cookie); 94 | close(netns_fd); 95 | break; 96 | case NETNS_SCENARIO_DESTROY: 97 | bpftune_for_each_tuner(t) 98 | bpftuner_netns_fini(t, event->netns_cookie, BPFTUNE_GONE); 99 | break; 100 | default: 101 | return; 102 | } 103 | /* use debug logging as these events are very frequent. */ 104 | bpftune_log(LOG_DEBUG, "netns %s (cookie %ld)\n", 105 | event->scenario_id == NETNS_SCENARIO_CREATE ? 106 | "created" : "destroyed", 107 | event->netns_cookie); 108 | } 109 | -------------------------------------------------------------------------------- /src/netns_tuner.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | enum { 23 | NETNS_SCENARIO_CREATE, 24 | NETNS_SCENARIO_DESTROY 25 | }; 26 | -------------------------------------------------------------------------------- /src/pcp/Install: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 3 | # 4 | # Copyright (c) 2025, Oracle and/or its affiliates. 5 | # 6 | # This program is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU General Public 8 | # License v2 as published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public 16 | # License along with this program; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 021110-1307, USA. 19 | # 20 | 21 | . $PCP_DIR/etc/pcp.env 22 | . $PCP_SHARE_DIR/lib/pmdaproc.sh 23 | 24 | iam=bpftune 25 | domain=486 26 | python_opt=true 27 | daemon_opt=false 28 | 29 | pmdaSetup 30 | pmdaInstall 31 | exit 32 | 33 | -------------------------------------------------------------------------------- /src/pcp/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2 | # 3 | # Copyright (c) 2023, Oracle and/or its affiliates. 4 | # 5 | # This program is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public 7 | # License v2 as published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public 15 | # License along with this program; if not, write to the 16 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 021110-1307, USA. 18 | # 19 | 20 | 21 | INSTALLFILES = Install Remove pmdabpftune.python 22 | 23 | DESTDIR ?= 24 | prefix ?= /usr 25 | installprefix ?= $(DESTDIR)/$(prefix) 26 | 27 | INSTALLPATH = $(installprefix)/../var/lib/pcp/pmdas/bpftune 28 | 29 | install_sh_PROGRAM = install 30 | install_sh_DIR = install -dv 31 | 32 | all: 33 | 34 | PHONY: clean 35 | 36 | clean: 37 | 38 | test: 39 | 40 | install: $(INSTALLFILES) 41 | $(install_sh_DIR) -d $(INSTALLPATH) ; \ 42 | $(install_sh_PROGRAM) $^ -t $(INSTALLPATH) ; \ 43 | install README -t $(INSTALLPATH); 44 | 45 | PHONY: clean 46 | -------------------------------------------------------------------------------- /src/pcp/README: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2 | # 3 | # Copyright (c) 2025, Oracle and/or its affiliates. 4 | # 5 | # This program is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public 7 | # License v2 as published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public 15 | # License along with this program; if not, write to the 16 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 021110-1307, USA. 18 | # 19 | 20 | bpftune PMDA 21 | ============ 22 | 23 | This PMDA exports information about bpftune-controlled tunables; 24 | these are mostly sysctl values. 25 | 26 | Metrics 27 | ======= 28 | Metrics exported are dynamic and based upon the bpftune tuners 29 | loaded; information is gathered from bpftune via a query 30 | 31 | bpftune -q jstatus 32 | 33 | Installation 34 | ============ 35 | 36 | + Ensure that bpftune is installed and running 37 | 38 | + # cd $PCP_PMDAS_DIR/bpftune 39 | 40 | + Check there is no clash in the Performance Metrics domain 41 | defined in ./domain.h. If there is edit ./domain.h to 42 | choose another number 43 | 44 | + Then run 45 | 46 | # sudo ./Install 47 | 48 | De-installation 49 | =============== 50 | 51 | # cd $PCP_PMDAS_DIR/bpftune 52 | # sudo ./Remove 53 | 54 | Troubleshooting 55 | =============== 56 | + Ensure bpftune is running 57 | 58 | + Ensure bpftune -q jstatus returns valid json 59 | 60 | -------------------------------------------------------------------------------- /src/pcp/Remove: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 3 | # 4 | # Copyright (c) 2025, Oracle and/or its affiliates. 5 | # 6 | # This program is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU General Public 8 | # License v2 as published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public 16 | # License along with this program; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 021110-1307, USA. 19 | # 20 | 21 | . $PCP_DIR/etc/pcp.env 22 | . $PCP_SHARE_DIR/lib/pmdaproc.sh 23 | 24 | iam=bpftune 25 | 26 | pmdaSetup 27 | pmdaRemove 28 | exit 29 | 30 | -------------------------------------------------------------------------------- /src/pcp/pmns-for-testing: -------------------------------------------------------------------------------- 1 | root { 2 | bpftune 486:*:* 3 | } 4 | -------------------------------------------------------------------------------- /src/probe.bpf.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include "netns_tuner.h" 22 | #include "tcp_conn_tuner.h" 23 | 24 | /* probe hash map */ 25 | BPF_MAP_DEF(probe_hash_map, BPF_MAP_TYPE_HASH, __u64, __u64, 65536, 0); 26 | 27 | /* probe kprobe/fentry */ 28 | BPF_FENTRY(setup_net, struct net *net, struct user_namespace *user_ns) 29 | { 30 | if (get_netns_cookie(net)) 31 | return 0; 32 | return 0; 33 | } 34 | 35 | /* check BPF iterators work ad support getsockopt() */ 36 | #ifndef BPFTUNE_LEGACY 37 | SEC("iter/tcp") 38 | int probe_cong_iter(struct bpf_iter__tcp *ctx) 39 | { 40 | struct sock_common *skc = ctx->sk_common; 41 | struct sock *sk = NULL; 42 | char buf[CONG_MAXNAME] = {}; 43 | 44 | if (!skc) 45 | return 0; 46 | sk = (struct sock *)bpf_skc_to_tcp_sock(skc); 47 | if (!sk) 48 | return 0; 49 | bpf_getsockopt(sk, SOL_TCP, TCP_CONGESTION, &buf, sizeof(buf)); 50 | return 0; 51 | } 52 | #endif 53 | 54 | #ifdef BPFTUNE_LEGACY 55 | SEC("raw_tracepoint/neigh_create") 56 | #else 57 | SEC("tp_btf/neigh_create") 58 | #endif 59 | int BPF_PROG(bpftune_neigh_create, struct neigh_table *tbl, 60 | struct net_device *dev, const void *pkey, 61 | struct neighbour *n, bool exempt_from_gc) 62 | { 63 | return 0; 64 | } 65 | 66 | SEC("cgroup/sysctl") 67 | int sysctl_write(struct bpf_sysctl *ctx) 68 | { 69 | return 1; 70 | } 71 | -------------------------------------------------------------------------------- /src/route_table_tuner.bpf.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include "route_table_tuner.h" 22 | 23 | struct dst_net { 24 | struct net *net; 25 | int entries; 26 | }; 27 | 28 | BPF_MAP_DEF(dst_net_map, BPF_MAP_TYPE_HASH, __u64, struct dst_net, 65536, 0); 29 | 30 | SEC("kprobe/fib6_run_gc") 31 | int BPF_KPROBE(bpftune_fib6_run_gc_entry, unsigned long expires, 32 | struct net *net, bool force) 33 | { 34 | struct dst_net *dst_netp; 35 | 36 | get_entry_struct(dst_net_map, dst_netp); 37 | /* already in gc, skip */ 38 | if (dst_netp) 39 | return 0; 40 | save_entry_data(dst_net_map, dst_net, net, net); 41 | return 0; 42 | } 43 | 44 | /* catch dst alloc approaching limit and increase route table max size */ 45 | SEC("kretprobe/fib6_run_gc") 46 | int BPF_KRETPROBE(bpftune_fib6_run_gc) 47 | { 48 | struct dst_net *dst_net; 49 | struct net *net; 50 | int max_size; 51 | 52 | get_entry_struct(dst_net_map, dst_net); 53 | if (!dst_net || !dst_net->net) 54 | return 0; 55 | 56 | net = dst_net->net; 57 | 58 | max_size = BPFTUNE_CORE_READ(net, ipv6.sysctl.ip6_rt_max_size); 59 | if (NEARLY_FULL(dst_net->entries, max_size)) { 60 | struct bpftune_event event = {}; 61 | long old[3] = {}; 62 | long new[3] = {}; 63 | 64 | event.tuner_id = tuner_id; 65 | event.scenario_id = ROUTE_TABLE_FULL; 66 | 67 | old[0] = max_size; 68 | new[0] = BPFTUNE_GROW_BY_DELTA(max_size); 69 | (void) send_net_sysctl_event(net, ROUTE_TABLE_FULL, 70 | ROUTE_TABLE_IPV6_MAX_SIZE, 71 | old, new, &event); 72 | } 73 | del_entry_struct(dst_net_map); 74 | return 0; 75 | } 76 | 77 | /* count dst entries */ 78 | BPF_FENTRY(fib6_age, struct fib6_info *rt, void *arg) 79 | { 80 | struct dst_net *dst_net; 81 | 82 | get_entry_struct(dst_net_map, dst_net); 83 | if (dst_net) 84 | dst_net->entries++; 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /src/route_table_tuner.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include "route_table_tuner.h" 23 | #include "route_table_tuner.skel.h" 24 | #include "route_table_tuner.skel.legacy.h" 25 | #include "route_table_tuner.skel.nobtf.h" 26 | 27 | struct route_table_tuner_bpf *skel; 28 | 29 | static struct bpftunable_desc descs[] = { 30 | { ROUTE_TABLE_IPV6_MAX_SIZE, BPFTUNABLE_SYSCTL, 31 | "net.ipv6.route.max_size", 32 | BPFTUNABLE_NAMESPACED | BPFTUNABLE_OPTIONAL, 1 }, 33 | }; 34 | 35 | static struct bpftunable_scenario scenarios[] = { 36 | { ROUTE_TABLE_FULL, "destination table nearly full", 37 | "destination table is nearly full, preventing new entries from being added." }, 38 | }; 39 | 40 | int init(struct bpftuner *tuner) 41 | { 42 | const char *optionals[] = { "entry__fib6_age", NULL }; 43 | 44 | int err = bpftuner_bpf_init(route_table, tuner, optionals); 45 | 46 | if (err) 47 | return err; 48 | return bpftuner_tunables_init(tuner, ARRAY_SIZE(descs), descs, 49 | ARRAY_SIZE(scenarios), scenarios); 50 | } 51 | 52 | void fini(struct bpftuner *tuner) 53 | { 54 | bpftune_log(LOG_DEBUG, "calling fini for %s\n", tuner->name); 55 | bpftuner_bpf_fini(tuner); 56 | } 57 | 58 | void event_handler(struct bpftuner *tuner, 59 | struct bpftune_event *event, 60 | __attribute__((unused))void *ctx) 61 | { 62 | int id; 63 | 64 | switch (event->scenario_id) { 65 | case ROUTE_TABLE_FULL: 66 | id = event->update[0].id; 67 | 68 | bpftuner_tunable_sysctl_write(tuner, id, ROUTE_TABLE_FULL, 69 | event->netns_cookie, 1, 70 | event->update[0].new, 71 | "Due to dst table filling up, change net.ipv6.route.max_size from %ld -> %ld\n", 72 | event->update[0].old[0], 73 | event->update[0].new[0]); 74 | break; 75 | default: 76 | return; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/route_table_tuner.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | #ifndef IFNAMSIZ 23 | #define IFNAMSIZ 16 24 | #endif 25 | 26 | enum route_table_tunables { 27 | ROUTE_TABLE_IPV6_MAX_SIZE, 28 | ROUTE_TABLE_NUM_TUNABLES 29 | }; 30 | 31 | enum route_table_scenarios { 32 | ROUTE_TABLE_FULL, 33 | }; 34 | 35 | struct tbl_stats { 36 | int family; 37 | int entries; 38 | int gc_entries; 39 | int max; 40 | int ifindex; 41 | char dev[IFNAMSIZ]; 42 | }; 43 | -------------------------------------------------------------------------------- /src/sysctl_tuner.bpf.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | /* use kprobe here as it is not in fastpath and the function has a large 23 | * number of args not well handled by fentry. We trace the sysctl set 24 | * because we cannot derive the net namespace easily from sysctl progs. 25 | */ 26 | SEC("kprobe/__cgroup_bpf_run_filter_sysctl") 27 | int BPF_KPROBE(bpftune_sysctl, struct ctl_table_header *head, 28 | struct ctl_table *table, int write, char **buf) 29 | { 30 | /* these are used to get offsets of fields within structures to 31 | * get pointer to struct net from the struct ctl_table we are 32 | * passed. 33 | */ 34 | struct ctl_table_set *dummy_ctl_table_set = NULL; 35 | struct net *dummy_net = NULL; 36 | struct bpftune_event event = {}; 37 | struct ctl_dir *root, *parent, *gparent, *ggparent; 38 | struct ctl_dir *gggparent; 39 | struct ctl_table *parent_table; 40 | int len = sizeof(event.str); 41 | const char *procname; 42 | int current_pid = 0; 43 | char *str; 44 | void *net; 45 | 46 | if (!write) 47 | return 0; 48 | event.tuner_id = tuner_id; 49 | event.scenario_id = 0; 50 | current_pid = bpf_get_current_pid_tgid() >> 32; 51 | if (current_pid == bpftune_pid) 52 | return 0; 53 | parent = BPFTUNE_CORE_READ(head, parent); 54 | if (!parent) 55 | return 0; 56 | gparent = BPFTUNE_CORE_READ(parent, header.parent); 57 | if (!gparent) 58 | return 0; 59 | ggparent = BPFTUNE_CORE_READ(gparent, header.parent); 60 | if (!ggparent) { 61 | root = gparent; 62 | } else { 63 | gggparent = BPFTUNE_CORE_READ(ggparent, header.parent); 64 | if (!gggparent) { 65 | root = ggparent; 66 | } else { 67 | root = BPFTUNE_CORE_READ(gggparent, header.parent); 68 | if (!root) 69 | root = gggparent; 70 | } 71 | } 72 | net = (void *)root - 73 | (__u64)BPFTUNE_PRESERVE_ACCESS_INDEX(dummy_net, sysctls) - 74 | (__u64)BPFTUNE_PRESERVE_ACCESS_INDEX(dummy_ctl_table_set, dir); 75 | event.pid = current_pid; 76 | event.netns_cookie = get_netns_cookie(net); 77 | if (event.netns_cookie == (unsigned long)-1) 78 | return 0; 79 | parent_table = BPFTUNE_CORE_READ(parent, header.ctl_table); 80 | str = event.str; 81 | if (parent_table) { 82 | procname = BPFTUNE_CORE_READ(parent_table, procname); 83 | if (procname) { 84 | if (!bpf_probe_read(event.str, sizeof(event.str), procname)) { 85 | for (; len > 0 && *str; len--, str++) {} 86 | if (len == 0) 87 | return 0; 88 | str[0] = '/'; 89 | str++; 90 | len--; 91 | } 92 | } 93 | } 94 | 95 | procname = BPFTUNE_CORE_READ(table, procname); 96 | if (!procname) 97 | return 0; 98 | if (bpf_probe_read(str, len, procname) < 0) 99 | return 0; 100 | bpf_ringbuf_output(&ring_buffer_map, &event, sizeof(event), 0); 101 | return 0; 102 | } 103 | 104 | /* dummy prog so we can use its firing as a means to collect info 105 | * via kprobe. 106 | */ 107 | SEC("cgroup/sysctl") 108 | int sysctl_write(struct bpf_sysctl *ctx) 109 | { 110 | return 1; 111 | } 112 | -------------------------------------------------------------------------------- /src/sysctl_tuner.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include "sysctl_tuner.skel.h" 23 | #include "sysctl_tuner.skel.legacy.h" 24 | #include "sysctl_tuner.skel.nobtf.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | extern unsigned short learning_rate; 34 | 35 | int init(struct bpftuner *tuner) 36 | { 37 | int err = bpftuner_bpf_init(sysctl, tuner, NULL); 38 | 39 | if (err) 40 | return err; 41 | /* attach to root cgroup */ 42 | if (bpftuner_cgroup_attach(tuner, "sysctl_write", BPF_CGROUP_SYSCTL)) 43 | return 1; 44 | 45 | return 0; 46 | } 47 | 48 | void fini(struct bpftuner *tuner) 49 | { 50 | bpftune_log(LOG_DEBUG, "calling fini for %s\n", tuner->name); 51 | bpftuner_cgroup_detach(tuner, "sysctl_write", BPF_CGROUP_SYSCTL); 52 | bpftuner_bpf_fini(tuner); 53 | } 54 | 55 | static const char *pid2cmd(int pid, char *cmd, size_t cmdsize) 56 | { 57 | char cmdline[64]; 58 | FILE *fp; 59 | 60 | snprintf(cmdline, sizeof(cmdline) - 1, "/proc/%d/cmdline", pid); 61 | fp = fopen(cmdline, "r"); 62 | if (fp) { 63 | fgets(cmd, cmdsize - 1, fp); 64 | fclose(fp); 65 | } 66 | if (strlen(cmd) == 0) 67 | strncpy(cmd, "?", 2); 68 | return cmd; 69 | } 70 | 71 | void event_handler(struct bpftuner *tuner, struct bpftune_event *event, 72 | __attribute__((unused))void *ctx) 73 | { 74 | struct bpftuner *t = NULL; 75 | 76 | bpftune_log(LOG_DEBUG, "sysctl write for '%s' (scenario %d) for tuner %s\n", 77 | event->str, event->scenario_id, tuner->name); 78 | 79 | if (event->netns_cookie == (unsigned long)-1) 80 | return; 81 | 82 | bpftune_for_each_tuner(t) { 83 | struct bpftunable *tunable; 84 | 85 | bpftune_log(LOG_DEBUG, "checking tuner %s\n", tuner->name); 86 | bpftuner_for_each_tunable(t, tunable) { 87 | char path[PATH_MAX]; 88 | 89 | bpftune_sysctl_name_to_path(tunable->desc.name, path, 90 | sizeof(path)); 91 | 92 | bpftune_log(LOG_DEBUG, "checking path %s against %s\n", 93 | path, event->str); 94 | /* does name match last characters in path? want to 95 | * avoid gc_thresh in routing table tuner matching 96 | * gc_thresh3 in neigh table tuner for example. 97 | */ 98 | if (strstr(path, event->str)) { 99 | char cmd[1024] = {}; 100 | 101 | bpftune_log(BPFTUNE_LOG_LEVEL, 102 | "pid %ld, cmd '%s' modified sysctl '%s' that tuner '%s' uses; disabling '%s' for namespace cookie %ld\n", 103 | event->pid, 104 | pid2cmd(event->pid, cmd, sizeof(cmd)), 105 | event->str, t->name, t->name, 106 | event->netns_cookie); 107 | bpftuner_netns_fini(t, event->netns_cookie, BPFTUNE_MANUAL); 108 | break; 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/tcp_buffer_tuner.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | #ifndef SK_MEM_QUANTUM 23 | #define SK_MEM_QUANTUM 4096 24 | #endif 25 | 26 | enum tcp_buffer_tunables { 27 | TCP_BUFFER_TCP_WMEM, 28 | TCP_BUFFER_TCP_RMEM, 29 | TCP_BUFFER_TCP_MEM, 30 | TCP_BUFFER_TCP_MODERATE_RCVBUF, 31 | TCP_BUFFER_TCP_NO_METRICS_SAVE, 32 | TCP_BUFFER_TCP_NO_SSTHRESH_METRICS_SAVE, 33 | TCP_BUFFER_NET_CORE_HIGH_ORDER_ALLOC_DISABLE, 34 | TCP_BUFFER_TCP_SYNCOOKIES, 35 | TCP_BUFFER_TCP_MAX_SYN_BACKLOG, 36 | TCP_BUFFER_TCP_MAX_ORPHANS, 37 | TCP_BUFFER_NUM_TUNABLES, 38 | }; 39 | 40 | enum tcp_buffer_scenarios { 41 | TCP_BUFFER_INCREASE, 42 | TCP_BUFFER_DECREASE, 43 | TCP_BUFFER_DECREASE_LATENCY, 44 | TCP_MEM_PRESSURE, 45 | TCP_MEM_EXHAUSTION, 46 | TCP_MODERATE_RCVBUF_ENABLE, 47 | TCP_LOW_MEM_ENTER_ENABLE, 48 | TCP_LOW_MEM_LEAVE_DISABLE, 49 | TCP_MAX_SYN_BACKLOG_INCREASE, 50 | TCP_MAX_SYN_BACKLOG_DECREASE, 51 | TCP_SYNCOOKIES_ENABLE, 52 | TCP_SYNCOOKIES_DISABLE, 53 | TCP_MAX_ORPHANS_INCREASE, 54 | }; 55 | 56 | #define TCP_RESET_COUNT 100 57 | 58 | #define TCP_SYN_BACKLOG_MIN 128 59 | 60 | #define TCP_SYNCOOKIES_BAD_COUNT 1024 61 | -------------------------------------------------------------------------------- /src/udp_buffer_tuner.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | #define UDP_BUFFER_MIN 8192 23 | #define UDP_BUFFER_MAX 268435456 /* 256Mb */ 24 | 25 | #ifndef SK_MEM_QUANTUM 26 | #define SK_MEM_QUANTUM 4096 27 | #endif 28 | 29 | enum udp_buffer_tunables { 30 | UDP_BUFFER_UDP_MEM, 31 | UDP_BUFFER_NET_CORE_RMEM_MAX, 32 | UDP_BUFFER_NET_CORE_RMEM_DEFAULT, 33 | UDP_BUFFER_NUM_TUNABLES 34 | }; 35 | 36 | enum tcp_buffer_scenarios { 37 | UDP_BUFFER_INCREASE, 38 | UDP_BUFFER_DECREASE, 39 | UDP_MEM_PRESSURE, 40 | UDP_MEM_EXHAUSTION, 41 | }; 42 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | conn_bomb 2 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2 | # 3 | # Copyright (c) 2023, Oracle and/or its affiliates. 4 | # 5 | # This program is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public 7 | # License v2 as published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public 15 | # License along with this program; if not, write to the 16 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | # Boston, MA 021110-1307, USA. 18 | # 19 | 20 | 21 | PERF_TESTS = stress_ng_test iperf3_test qperf_test 22 | 23 | TUNER_TESTS = support_test log_test service_test inotify_test cap_test \ 24 | sample_test sample_legacy_test \ 25 | strategy_test strategy_legacy_test \ 26 | rollback_test rollback_legacy_test \ 27 | query_test rate_test \ 28 | pcp_pmda_test \ 29 | many_netns_test many_netns_legacy_test \ 30 | podman_globalonly_test podman_globalonly_legacy_test \ 31 | sysctl_test sysctl_legacy_test sysctl_netns_test \ 32 | netns_test netns_legacy_test \ 33 | file_download_test file_download_legacy_test \ 34 | udp_rmem_test udp_rmem_legacy_test \ 35 | udp_rmem_locked_test udp_mem_exhaust_test \ 36 | budget_test \ 37 | backlog_test backlog_legacy_test \ 38 | frag_test frag_legacy_test \ 39 | neigh_table_test neigh_table_v4only_test \ 40 | neigh_table_legacy_test \ 41 | mem_pressure_test mem_pressure_legacy_test \ 42 | mem_exhaust_test mem_exhaust_legacy_test \ 43 | good_syn_flood_test syn_flood_test \ 44 | wmem_test wmem_legacy_test \ 45 | rmem_test rmem_legacy_test \ 46 | cong_test cong_legacy_test 47 | 48 | DEFAULT_TESTS = $(TUNER_TESTS) $(PERF_TESTS) 49 | 50 | TESTS = $(DEFAULT_TESTS) 51 | 52 | LIBS = test_lib.sh 53 | 54 | PROGS = conn_bomb 55 | 56 | CFLAGS += -lpthread 57 | 58 | OBJS = conn_bomb.o 59 | 60 | INSTALLFILES = $(DEFAULT_TESTS:%=%.sh) $(LIBS) 61 | 62 | DESTDIR ?= 63 | prefix ?= /usr 64 | installprefix ?= $(DESTDIR)/$(prefix) 65 | 66 | INSTALLPATH = $(installprefix)/lib/tcptune_test/ 67 | 68 | install_sh_PROGRAM = install 69 | install_sh_DIR = install -dv 70 | 71 | all: strategydir $(PROGS) 72 | 73 | strategydir: 74 | cd strategy; make 75 | 76 | PHONY: clean 77 | 78 | clean: strategyclean 79 | rm -f $(PROGS) 80 | 81 | strategyclean: 82 | cd strategy; make clean 83 | 84 | test: all $(TESTS) 85 | 86 | test_perf: $(PERF_TESTS) 87 | 88 | test_tuner: $(TUNER_TESTS) 89 | 90 | install: $(INSTALLFILES) 91 | $(install_sh_DIR) -d $(INSTALLPATH) ; \ 92 | $(install_sh_PROGRAM) $^ -t $(INSTALLPATH) ; \ 93 | 94 | $(TESTS): %:%.sh 95 | TEST_ID=$$PPID bash $< 96 | 97 | PHONY: clean 98 | -------------------------------------------------------------------------------- /test/backlog_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run iperf3 test with low netdev_max_backlog, ensure tuner increases it. 23 | 24 | PORT=5201 25 | 26 | . ./test_lib.sh 27 | 28 | SLEEPTIME=1 29 | TIMEOUT=30 30 | MAX_CONN=50 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | for CLIENT_OPTS in "" ; do 35 | # use localhost to maximize bandwidth -> hit backlog limits 36 | case $FAMILY in 37 | ipv4) 38 | ADDR=127.0.0.1 39 | ;; 40 | ipv6) 41 | ADDR=::1 42 | ;; 43 | esac 44 | 45 | test_start "$0|backlog legacy test to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 46 | 47 | backlog_orig=($(sysctl -n net.core.netdev_max_backlog)) 48 | mask_orig=($(sysctl -n net.core.flow_limit_cpu_bitmap)) 49 | test_setup true 50 | 51 | sysctl -w net.core.netdev_max_backlog=8 52 | sysctl -w net.core.flow_limit_cpu_bitmap=0 53 | backlog_pre=($(sysctl -n net.core.netdev_max_backlog)) 54 | mask_pre=($(sysctl -n net.core.flow_limit_cpu_bitmap)) 55 | declare -A results 56 | for MODE in baseline test ; do 57 | 58 | echo "Running ${MODE}..." 59 | test_run_cmd_local "$IPERF3 -s -p $PORT &" 60 | if [[ $MODE != "baseline" ]]; then 61 | test_run_cmd_local "$BPFTUNE -L &" 62 | sleep $SETUPTIME 63 | else 64 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 65 | LOGSZ=$(expr $LOGSZ + 1) 66 | fi 67 | test_run_cmd_local "$IPERF3 -fm -t 20 $CLIENT_OPTS -c $PORT -c $ADDR" true 68 | sleep $SLEEPTIME 69 | 70 | sresults=$(grep -E "sender" ${CMDLOG} | awk '{print $7}') 71 | rresults=$(grep -E "receiver" ${CMDLOG} | awk '{print $7}') 72 | units=$(grep -E "sender|receiver" ${CMDLOG} | awk '{print $8}' |head -1) 73 | 74 | if [[ $MODE == "baseline" ]]; then 75 | read -r -a sbaseline_results <<< $sresults 76 | read -r -a rbaseline_results <<< $rresults 77 | echo "" > ${CMDLOG} 78 | else 79 | read -r -a stest_results <<< $sresults 80 | read -r -a rtest_results <<< $rresults 81 | 82 | fi 83 | sleep $SLEEPTIME 84 | done 85 | 86 | backlog_post=($(sysctl -n net.core.netdev_max_backlog)) 87 | mask_post=($(sysctl -n net.core.flow_limit_cpu_bitmap)) 88 | sysctl -w net.core.netdev_max_backlog="$backlog_orig" 89 | sysctl -w net.core.flow_limit_cpu_bitmap="$mask_orig" 90 | if [[ $MODE == "test" ]]; then 91 | echo "backlog ${backlog_pre} -> ${backlog_post}" 92 | echo "mask ${mask_pre} -> ${mask_post}" 93 | test_pass 94 | fi 95 | test_cleanup 96 | done 97 | done 98 | 99 | test_exit 100 | -------------------------------------------------------------------------------- /test/backlog_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run iperf3 test with low netdev_max_backlog, ensure tuner increases it. 23 | 24 | PORT=5201 25 | 26 | . ./test_lib.sh 27 | 28 | SLEEPTIME=1 29 | TIMEOUT=30 30 | MAX_CONN=50 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | for CLIENT_OPTS in "" ; do 35 | # use localhost to maximize bandwidth -> hit backlog limits 36 | case $FAMILY in 37 | ipv4) 38 | ADDR=127.0.0.1 39 | ;; 40 | ipv6) 41 | ADDR=::1 42 | ;; 43 | esac 44 | 45 | test_start "$0|backlog test to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 46 | 47 | backlog_orig=($(sysctl -n net.core.netdev_max_backlog)) 48 | mask_orig=($(sysctl -n net.core.flow_limit_cpu_bitmap)) 49 | test_setup true 50 | 51 | sysctl -w net.core.netdev_max_backlog=8 52 | sysctl -w net.core.flow_limit_cpu_bitmap=0 53 | backlog_pre=($(sysctl -n net.core.netdev_max_backlog)) 54 | mask_pre=($(sysctl -n net.core.flow_limit_cpu_bitmap)) 55 | declare -A results 56 | for MODE in baseline test ; do 57 | 58 | echo "Running ${MODE}..." 59 | test_run_cmd_local "$IPERF3 -s -p $PORT &" 60 | if [[ $MODE != "baseline" ]]; then 61 | test_run_cmd_local "$BPFTUNE &" 62 | sleep $SETUPTIME 63 | else 64 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 65 | LOGSZ=$(expr $LOGSZ + 1) 66 | fi 67 | test_run_cmd_local "$IPERF3 -fm -t 20 $CLIENT_OPTS -c $PORT -c $ADDR" true 68 | sleep $SLEEPTIME 69 | 70 | sresults=$(grep -E "sender" ${CMDLOG} | awk '{print $7}') 71 | rresults=$(grep -E "receiver" ${CMDLOG} | awk '{print $7}') 72 | units=$(grep -E "sender|receiver" ${CMDLOG} | awk '{print $8}' |head -1) 73 | 74 | if [[ $MODE == "baseline" ]]; then 75 | read -r -a sbaseline_results <<< $sresults 76 | read -r -a rbaseline_results <<< $rresults 77 | echo "" > ${CMDLOG} 78 | else 79 | read -r -a stest_results <<< $sresults 80 | read -r -a rtest_results <<< $rresults 81 | 82 | fi 83 | sleep $SLEEPTIME 84 | done 85 | 86 | backlog_post=($(sysctl -n net.core.netdev_max_backlog)) 87 | mask_post=($(sysctl -n net.core.flow_limit_cpu_bitmap)) 88 | sysctl -w net.core.netdev_max_backlog="$backlog_orig" 89 | sysctl -w net.core.flow_limit_cpu_bitmap="$mask_orig" 90 | if [[ $MODE == "test" ]]; then 91 | echo "backlog ${backlog_pre} -> ${backlog_post}" 92 | echo "mask ${mask_pre} -> ${mask_post}" 93 | test_pass 94 | fi 95 | test_cleanup 96 | done 97 | done 98 | 99 | test_exit 100 | -------------------------------------------------------------------------------- /test/budget_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run iperf3 test with low netdev_budget, ensure tuner increases it. 23 | 24 | PORT=5201 25 | 26 | . ./test_lib.sh 27 | 28 | SLEEPTIME=1 29 | TIMEOUT=30 30 | MAX_CONN=100 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | for CLIENT_OPTS in "" ; do 35 | case $FAMILY in 36 | ipv4) 37 | ADDR=$VETH2_IPV4 38 | ;; 39 | ipv6) 40 | ADDR=$VETH2_IPV6 41 | ;; 42 | esac 43 | 44 | test_start "$0|budget test to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 45 | 46 | budget_orig=($(sysctl -n net.core.netdev_budget)) 47 | usecs_orig=($(sysctl -n net.core.netdev_budget_usecs)) 48 | test_setup true 49 | 50 | sysctl -w net.core.netdev_budget=10 51 | sysctl -w net.core.netdev_budget_usecs=100 52 | budget_pre=($(sysctl -n net.core.netdev_budget)) 53 | usecs_pre=($(sysctl -n net.core.netdev_budget_usecs)) 54 | declare -A results 55 | for MODE in baseline test ; do 56 | 57 | echo "Running ${MODE}..." 58 | test_run_cmd_local "$IPERF3 -s -p $PORT &" 59 | if [[ $MODE != "baseline" ]]; then 60 | test_run_cmd_local "$BPFTUNE -s &" true 61 | sleep $SETUPTIME 62 | else 63 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 64 | LOGSZ=$(expr $LOGSZ + 1) 65 | fi 66 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -fm -t 10 -P 20 $CLIENT_OPTS -c $PORT -c $ADDR" true 67 | sleep $SLEEPTIME 68 | 69 | sresults=$(grep -E "sender" ${CMDLOG} | awk '{print $7}') 70 | rresults=$(grep -E "receiver" ${CMDLOG} | awk '{print $7}') 71 | units=$(grep -E "sender|receiver" ${CMDLOG} | awk '{print $8}' |head -1) 72 | 73 | if [[ $MODE == "baseline" ]]; then 74 | read -r -a sbaseline_results <<< $sresults 75 | read -r -a rbaseline_results <<< $rresults 76 | echo "" > ${CMDLOG} 77 | else 78 | read -r -a stest_results <<< $sresults 79 | read -r -a rtest_results <<< $rresults 80 | 81 | fi 82 | sleep $SLEEPTIME 83 | done 84 | 85 | budget_post=($(sysctl -n net.core.netdev_budget)) 86 | usecs_post=($(sysctl -n net.core.netdev_budget_usecs)) 87 | sleep $SLEEPTIME 88 | sysctl -w net.core.netdev_budget="$budget_orig" 89 | sysctl -w net.core.netdev_budget_usecs="$usecs_orig" 90 | echo "budget ${budget_pre} -> ${budget_post}" 91 | echo "usecs ${usecs_pre} -> ${usecs_post}" 92 | if [[ "$budget_post" -gt "$budget_pre" ]]; then 93 | if [[ "$usecs_post" -gt "$usecs_pre" ]]; then 94 | test_pass 95 | fi 96 | fi 97 | test_cleanup 98 | done 99 | done 100 | 101 | test_exit 102 | -------------------------------------------------------------------------------- /test/cap_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # verify caps are dropped by bpftune after init 23 | 24 | BPFTUNE_FLAGS="-s" 25 | 26 | . ./test_lib.sh 27 | 28 | 29 | SLEEPTIME=1 30 | 31 | test_setup "true" 32 | 33 | for BPFTUNECMD in "$BPFTUNE &" "service bpftune start" ; do 34 | test_start "$0|cap test: are caps dropped by '$BPFTUNECMD' after init?" 35 | test_run_cmd_local "$BPFTUNECMD" true 36 | 37 | sleep $SETUPTIME 38 | 39 | caps=$(getpcaps $(pgrep bpftune) 2>&1) 40 | # awk '/[+=]p/ { print $0 }') 41 | 42 | echo "caps: $caps" 43 | 44 | for cap in cap_net_admin cap_sys_module cap_sys_chroot cap_sys_admin cap_syslog ; do 45 | echo $caps | grep -E $cap >/dev/null 46 | done 47 | 48 | if [[ -n "$caps" ]]; then 49 | test_pass 50 | else 51 | break 52 | fi 53 | set +e 54 | service bpftune stop 2>/dev/null 55 | pkill -TERM bpftune 56 | set -e 57 | done 58 | 59 | test_cleanup 60 | 61 | test_exit 62 | -------------------------------------------------------------------------------- /test/cong_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | PORT=5201 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=1 29 | TIMEOUT=30 30 | 31 | for FAMILY in ipv4 ipv6 ; do 32 | 33 | for DROP_PERCENT in 0 10; do 34 | for LATENCY in "delay 100" ""; do 35 | for CLIENT_OPTS in "" "-R" ; do 36 | case $FAMILY in 37 | ipv4) 38 | ADDR=$VETH1_IPV4 39 | ;; 40 | ipv6) 41 | ADDR=$VETH1_IPV6 42 | ;; 43 | esac 44 | 45 | test_start "$0|cong legacy test (drop $DROP_PERCENT %) to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 46 | 47 | if [[ $DROP_PERCENT -gt 0 ]]; then 48 | DROP=$DROP_PERCENT 49 | fi 50 | 51 | test_setup "true" 52 | 53 | declare -A results 54 | for MODE in baseline test ; do 55 | 56 | echo "Running ${MODE}..." 57 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -p $PORT -s &" 58 | if [[ $MODE != "baseline" ]]; then 59 | test_run_cmd_local "$BPFTUNE -dsL &" true 60 | sleep $SETUPTIME 61 | # warm up connection... 62 | for i in {1..40}; do 63 | set +e 64 | $IPERF3 -fm $CLIENT_OPTS -p $PORT -t 1 -c $ADDR > /dev/null 2>&1 65 | set -e 66 | done 67 | else 68 | sleep $SLEEPTIME 69 | fi 70 | set +e 71 | test_run_cmd_local "$IPERF3 -fm $CLIENT_OPTS -p $PORT -c $ADDR" true 72 | IPERF_STATUS=$? 73 | set -e 74 | if [[ $MODE != "baseline" ]]; then 75 | pkill -TERM bpftune 76 | sleep $SETUPTIME 77 | fi 78 | sresults=$(grep -E "sender" ${CMDLOG} | awk '{print $7}') 79 | rresults=$(grep -E "receiver" ${CMDLOG} | awk '{print $7}') 80 | units=$(grep -E "sender|receiver" ${CMDLOG} | awk '{print $8}' |head -1) 81 | 82 | if [[ $MODE == "baseline" ]]; then 83 | read -r -a sbaseline_results <<< $sresults 84 | read -r -a rbaseline_results <<< $rresults 85 | echo "" > ${CMDLOG} 86 | else 87 | read -r -a stest_results <<< $sresults 88 | read -r -a rtest_results <<< $rresults 89 | fi 90 | sleep $SLEEPTIME 91 | done 92 | 93 | if [[ $IPERF_STATUS == 0 ]]; then 94 | printf "Results sender (${units}): " 95 | for (( i=0; i < ${#sbaseline_results[@]}; i++ )) 96 | do 97 | sbase=$(roundup ${sbaseline_results[$i]}) 98 | stest=$(roundup ${stest_results[$i]}) 99 | if [[ ${sbase} -gt ${stest} ]]; then 100 | bold "Warning: baseline (${sbase}) > test (${stest})" 101 | else 102 | echo "baseline (${sbase}) < test (${stest})" 103 | fi 104 | done 105 | printf "Results receiver (${units}): " 106 | for (( i=0; i < ${#rbaseline_results[@]}; i++ )) 107 | do 108 | rbase=$(roundup ${rbaseline_results[$i]}) 109 | rtest=$(roundup ${rtest_results[$i]}) 110 | if [[ ${rbase} -gt ${rtest} ]]; then 111 | bold "Warning: baseline (${rbase}) > test (${rtest})" 112 | else 113 | echo "baseline (${rbase}) < test (${rtest})" 114 | fi 115 | done 116 | fi 117 | sleep $SETUPTIME 118 | grep "Summary: tcp_conn_tuner" $LOGFILE 119 | 120 | test_pass 121 | 122 | test_cleanup 123 | done 124 | done 125 | done 126 | done 127 | 128 | test_exit 129 | -------------------------------------------------------------------------------- /test/cong_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | PORT=5201 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=1 29 | TIMEOUT=30 30 | 31 | for FAMILY in ipv6 ipv4 ; do 32 | 33 | for DROP_PERCENT in 0 10; do 34 | for LATENCY in "delay 100" ""; do 35 | for CLIENT_OPTS in "" "-R" ; do 36 | case $FAMILY in 37 | ipv4) 38 | ADDR=$VETH1_IPV4 39 | ;; 40 | ipv6) 41 | ADDR=$VETH1_IPV6 42 | ;; 43 | esac 44 | 45 | test_start "$0|cong test (drop $DROP_PERCENT %) to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 46 | 47 | if [[ $DROP_PERCENT -gt 0 ]]; then 48 | DROP=$DROP_PERCENT 49 | fi 50 | 51 | test_setup "true" 52 | 53 | declare -A results 54 | for MODE in baseline test ; do 55 | 56 | echo "Running ${MODE}..." 57 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -p $PORT -s &" 58 | if [[ $MODE != "baseline" ]]; then 59 | test_run_cmd_local "$BPFTUNE -ds &" true 60 | sleep $SETUPTIME 61 | # warm up connection... 62 | for i in {1..40}; do 63 | set +e 64 | $IPERF3 -fm $CLIENT_OPTS -p $PORT -t 1 -c $ADDR > /dev/null 2>&1 65 | set -e 66 | done 67 | else 68 | sleep $SLEEPTIME 69 | fi 70 | set +e 71 | test_run_cmd_local "$IPERF3 -fm $CLIENT_OPTS -p $PORT -c $ADDR" true 72 | IPERF_STATUS=$? 73 | set -e 74 | if [[ $MODE != "baseline" ]]; then 75 | pkill -TERM bpftune 76 | sleep $SETUPTIME 77 | fi 78 | sresults=$(grep -E "sender" ${CMDLOG} | awk '{print $7}') 79 | rresults=$(grep -E "receiver" ${CMDLOG} | awk '{print $7}') 80 | units=$(grep -E "sender|receiver" ${CMDLOG} | awk '{print $8}' |head -1) 81 | 82 | if [[ $MODE == "baseline" ]]; then 83 | read -r -a sbaseline_results <<< $sresults 84 | read -r -a rbaseline_results <<< $rresults 85 | echo "" > ${CMDLOG} 86 | else 87 | read -r -a stest_results <<< $sresults 88 | read -r -a rtest_results <<< $rresults 89 | fi 90 | sleep $SLEEPTIME 91 | done 92 | 93 | if [[ $IPERF_STATUS == 0 ]]; then 94 | printf "Results sender (${units}): " 95 | for (( i=0; i < ${#sbaseline_results[@]}; i++ )) 96 | do 97 | sbase=$(roundup ${sbaseline_results[$i]}) 98 | stest=$(roundup ${stest_results[$i]}) 99 | if [[ ${sbase} -gt ${stest} ]]; then 100 | bold "Warning: baseline (${sbase}) > test (${stest})" 101 | else 102 | echo "baseline (${sbase}) < test (${stest})" 103 | fi 104 | done 105 | printf "Results receiver (${units}): " 106 | for (( i=0; i < ${#rbaseline_results[@]}; i++ )) 107 | do 108 | rbase=$(roundup ${rbaseline_results[$i]}) 109 | rtest=$(roundup ${rtest_results[$i]}) 110 | if [[ ${rbase} -gt ${rtest} ]]; then 111 | bold "Warning: baseline (${rbase}) > test (${rtest})" 112 | else 113 | echo "baseline (${rbase}) < test (${rtest})" 114 | fi 115 | done 116 | fi 117 | sleep $SETUPTIME 118 | grep "Summary: tcp_conn_tuner" $LOGFILE 119 | 120 | test_pass 121 | 122 | test_cleanup 123 | done 124 | done 125 | done 126 | done 127 | 128 | test_exit 129 | -------------------------------------------------------------------------------- /test/file_download_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # download file via wget with various drop/latencies; bbr should 23 | # be used when drops >= 1.5% 24 | 25 | . ./test_lib.sh 26 | 27 | LOGFILE=$TESTLOG_LAST 28 | 29 | SLEEPTIME=1 30 | TIMEOUT=30 31 | MAX_CONN=50 32 | 33 | for DROP_PERCENT in 2 4 0; do 34 | for LATENCY in "" "delay 10" "delay 100"; do 35 | for NS in nonglobal global; do 36 | for FAMILY in ipv4 ipv6 ; do 37 | 38 | case $FAMILY in 39 | ipv4) 40 | if [[ $NS == "global" ]]; then 41 | ADDR=$VETH2_IPV4 42 | else 43 | ADDR=$VETH1_IPV4 44 | fi 45 | WGET_ARG="" 46 | WGET_ADDR=$ADDR 47 | HTTP_BIND_ADDR="" 48 | ;; 49 | ipv6) 50 | pyversion=$(python3 --version | awk -F '.' '{ print $2 }') 51 | # http.server supports IPv6 for 3.8 and later. 52 | if [[ $pyversion -lt 8 ]]; then 53 | echo "IPv6 test needs python 3.8 or later, skipping" 54 | continue 55 | fi 56 | if [[ $NS == "global" ]]; then 57 | ADDR=$VETH2_IPV6 58 | else 59 | ADDR=$VETH1_IPV6 60 | fi 61 | WGET_ARG="-6" 62 | WGET_ADDR="[${ADDR}]" 63 | HTTP_BIND_ADDR="--bind $ADDR" 64 | ;; 65 | esac 66 | 67 | test_start "$0|file legacy test to $ADDR:$PORT $FAMILY $NS drop $DROP_PERCENT $LATENCY" 68 | 69 | if [[ $DROP_PERCENT -gt 0 ]]; then 70 | DROP=$DROP_PERCENT 71 | fi 72 | 73 | if [[ $NS == "global" ]]; then 74 | CLIENT_PREFIX="ip netns exec $NETNS" 75 | CLIENT_VETH=$VETH1 76 | SERVER_PREFIX="" 77 | SERVER_VETH=$VETH2 78 | else 79 | CLIENT_PREFIX="" 80 | CLIENT_VETH=$VETH2 81 | SERVER_PREFIX="ip netns exec $NETNS" 82 | SERVER_VETH=$VETH1 83 | fi 84 | test_setup true 85 | mkdir -p $SERVERDIR 86 | dd if=/dev/zero of=${SERVERFILE} bs=$SERVERFILE_SIZE count=1 87 | 88 | set +e 89 | FIREWALLD_PID=$(pgrep firewalld) 90 | set -e 91 | if [[ -n "$FIREWALLD_PID" ]]; then 92 | service firewalld stop 93 | fi 94 | for MODE in baseline test ; do 95 | 96 | echo "Running ${MODE}..." 97 | if [[ $MODE != "baseline" ]]; then 98 | test_run_cmd_local "$BPFTUNE -sL &" true 99 | sleep $SETUPTIME 100 | else 101 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 102 | LOGSZ=$(expr $LOGSZ + 1) 103 | fi 104 | pushd $SERVERDIR 105 | test_run_cmd_local "$SERVER_PREFIX python3 -m http.server $HTTP_BIND_ADDR $PORT &" true 106 | sleep $SLEEPTIME 107 | $CLIENT_PREFIX wget $WGET_ARG http://${WGET_ADDR}:${PORT}/file 108 | popd 109 | rm -f ${SERVERFILE}.1 110 | if [[ $MODE != "baseline" ]]; then 111 | pkill -TERM bpftune 112 | sleep $SETUPTIME 113 | tail -n +${LOGSZ} $LOGFILE | grep bbr 114 | else 115 | sleep $SLEEPTIME 116 | fi 117 | done 118 | if [[ -n "$FIREWALLD_PID" ]]; then 119 | service firewalld start 120 | fi 121 | test_pass 122 | test_cleanup 123 | done 124 | done 125 | done 126 | done 127 | 128 | test_exit 129 | -------------------------------------------------------------------------------- /test/file_download_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # download file via wget with various drop/latencies; bbr should 23 | # be used when drops >= 1.5% 24 | 25 | . ./test_lib.sh 26 | 27 | LOGFILE=$TESTLOG_LAST 28 | 29 | SLEEPTIME=1 30 | TIMEOUT=30 31 | MAX_CONN=50 32 | 33 | for DROP_PERCENT in 2 4 0; do 34 | for LATENCY in "" "delay 10" "delay 100"; do 35 | for NS in nonglobal global; do 36 | for FAMILY in ipv4 ipv6 ; do 37 | 38 | case $FAMILY in 39 | ipv4) 40 | if [[ $NS == "global" ]]; then 41 | ADDR=$VETH2_IPV4 42 | else 43 | ADDR=$VETH1_IPV4 44 | fi 45 | WGET_ARG="" 46 | WGET_ADDR=$ADDR 47 | HTTP_BIND_ADDR="" 48 | ;; 49 | ipv6) 50 | pyversion=$(python3 --version | awk -F '.' '{ print $2 }') 51 | # http.server supports IPv6 for 3.8 and later. 52 | if [[ $pyversion -lt 8 ]]; then 53 | echo "IPv6 test needs python 3.8 or later, skipping" 54 | continue 55 | fi 56 | if [[ $NS == "global" ]]; then 57 | ADDR=$VETH2_IPV6 58 | else 59 | ADDR=$VETH1_IPV6 60 | fi 61 | WGET_ARG="-6" 62 | WGET_ADDR="[${ADDR}]" 63 | HTTP_BIND_ADDR="--bind $ADDR" 64 | ;; 65 | esac 66 | 67 | test_start "$0|file test to $ADDR:$PORT $FAMILY $NS drop $DROP_PERCENT $LATENCY" 68 | 69 | if [[ $DROP_PERCENT -gt 0 ]]; then 70 | DROP=$DROP_PERCENT 71 | fi 72 | 73 | if [[ $NS == "global" ]]; then 74 | CLIENT_PREFIX="ip netns exec $NETNS" 75 | CLIENT_VETH=$VETH1 76 | SERVER_PREFIX="" 77 | SERVER_VETH=$VETH2 78 | else 79 | CLIENT_PREFIX="" 80 | CLIENT_VETH=$VETH2 81 | SERVER_PREFIX="ip netns exec $NETNS" 82 | SERVER_VETH=$VETH1 83 | fi 84 | test_setup true 85 | mkdir -p $SERVERDIR 86 | dd if=/dev/zero of=${SERVERFILE} bs=$SERVERFILE_SIZE count=1 87 | 88 | set +e 89 | FIREWALLD_PID=$(pgrep firewalld) 90 | set -e 91 | if [[ -n "$FIREWALLD_PID" ]]; then 92 | service firewalld stop 93 | fi 94 | for MODE in baseline test ; do 95 | 96 | echo "Running ${MODE}..." 97 | if [[ $MODE != "baseline" ]]; then 98 | test_run_cmd_local "$BPFTUNE -s &" true 99 | sleep $SETUPTIME 100 | else 101 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 102 | LOGSZ=$(expr $LOGSZ + 1) 103 | fi 104 | pushd $SERVERDIR 105 | test_run_cmd_local "$SERVER_PREFIX python3 -m http.server $HTTP_BIND_ADDR $PORT &" true 106 | sleep $SLEEPTIME 107 | $CLIENT_PREFIX wget $WGET_ARG http://${WGET_ADDR}:${PORT}/file 108 | popd 109 | rm -f ${SERVERFILE}.1 110 | if [[ $MODE != "baseline" ]]; then 111 | pkill -TERM bpftune 112 | sleep $SETUPTIME 113 | tail -n +${LOGSZ} $LOGFILE | grep bbr 114 | else 115 | sleep $SLEEPTIME 116 | fi 117 | done 118 | if [[ -n "$FIREWALLD_PID" ]]; then 119 | service firewalld start 120 | fi 121 | test_pass 122 | test_cleanup 123 | done 124 | done 125 | done 126 | done 127 | 128 | test_exit 129 | -------------------------------------------------------------------------------- /test/frag_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # send frags > MTU via ping with netns with too-low high_thresh for 23 | # fragment memory; ensure we bump up memory limits. 24 | 25 | . ./test_lib.sh 26 | 27 | LOGFILE=$TESTLOG_LAST 28 | 29 | SLEEPTIME=1 30 | TIMEOUT=30 31 | MAX_CONN=50 32 | 33 | for FAMILY in ipv6 ipv4 ; do 34 | for NS in nonglobal global; do 35 | case $FAMILY in 36 | ipv4) 37 | if [[ $NS == "global" ]]; then 38 | ADDR=$VETH2_IPV4 39 | else 40 | ADDR=$VETH1_IPV4 41 | fi 42 | SYSCTL_PREFIX=net.ipv4.ipfrag_ 43 | SYSCTL_NAME="${SYSCTL_PREFIX}high_thresh" 44 | ;; 45 | ipv6) 46 | if [[ $NS == "global" ]]; then 47 | ADDR=$VETH2_IPV6 48 | else 49 | ADDR=$VETH1_IPV6 50 | fi 51 | SYSCTL_PREFIX=net.ipv6.ip6frag_ 52 | SYSCTL_NAME="${SYSCTL_PREFIX}high_thresh" 53 | ;; 54 | esac 55 | 56 | test_start "$0|frag test to $ADDR:$PORT $FAMILY $NS" 57 | 58 | if [[ $NS == "global" ]]; then 59 | CLIENT_PREFIX="ip netns exec $NETNS" 60 | CLIENT_VETH=$VETH1 61 | SERVER_PREFIX="" 62 | SERVER_VETH=$VETH2 63 | else 64 | CLIENT_PREFIX="" 65 | CLIENT_VETH=$VETH2 66 | SERVER_PREFIX="ip netns exec $NETNS" 67 | SERVER_VETH=$VETH1 68 | fi 69 | test_setup true 70 | 71 | $CLIENT_PREFIX ethtool --offload $CLIENT_VETH rx off tx off gso off gro off lro off tso off 72 | $SERVER_PREFIX ethtool --offload $SERVER_VETH rx off tx off gso off gro off lro off tso off 73 | frag_orig=($(sysctl -n $SYSCTL_NAME)) 74 | low_orig=($(sysctl -n ${SYSCTL_PREFIX}low_thresh)) 75 | sysctl -w ${SYSCTL_PREFIX}low_thresh=8192 76 | sysctl -w $SYSCTL_NAME="8192" 77 | 78 | frag_pre=($(sysctl -n $SYSCTL_NAME)) 79 | 80 | # prevent firewall from reassembling packets. 81 | set +e 82 | FIREWALLD_PID=$(pgrep firewalld) 83 | set -e 84 | if [[ -n "$FIREWALLD_PID" ]]; then 85 | service firewalld stop 86 | fi 87 | for MODE in baseline test ; do 88 | 89 | echo "Running ${MODE}..." 90 | if [[ $MODE != "baseline" ]]; then 91 | test_run_cmd_local "$BPFTUNE -sL &" true 92 | sleep $SETUPTIME 93 | else 94 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 95 | LOGSZ=$(expr $LOGSZ + 1) 96 | fi 97 | set +e 98 | echo "Running $CLIENT_PREFIX ping -v -c 20 -M t -s 8192 $ADDR" 99 | $CLIENT_PREFIX ping -v -c 20 -M want -s 8192 $ADDR 100 | set -e 101 | 102 | if [[ $MODE != "baseline" ]]; then 103 | pkill -TERM bpftune 104 | sleep $SETUPTIME 105 | else 106 | sleep $SLEEPTIME 107 | fi 108 | done 109 | if [[ -n "$FIREWALLD_PID" ]]; then 110 | service firewalld start 111 | fi 112 | frag_post=($(sysctl -n $SYSCTL_NAME)) 113 | if [[ -n $SERVER_PREFIX ]]; then 114 | sysctl -w ${SYSCTL_NAME}=$frag_orig 115 | sysctl -w ${SYSCTL_PREFIX}low_thresh=$low_orig 116 | fi 117 | echo "$SYSCTL_NAME before ${frag_pre}" 118 | echo "$SYSCTL_NAME after ${frag_post}" 119 | if [[ $MODE == "test" ]]; then 120 | if [[ "${frag_post}" -gt ${frag_pre} ]]; then 121 | grep "approaching fragmentation maximum threshold" $LOGFILE 122 | test_pass 123 | else 124 | test_cleanup 125 | fi 126 | fi 127 | 128 | test_cleanup 129 | done 130 | done 131 | 132 | test_exit 133 | -------------------------------------------------------------------------------- /test/frag_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # send frags > MTU via ping with netns with too-low high_thresh for 23 | # fragment memory; ensure we bump up memory limits. 24 | 25 | . ./test_lib.sh 26 | 27 | LOGFILE=$TESTLOG_LAST 28 | 29 | SLEEPTIME=1 30 | TIMEOUT=30 31 | MAX_CONN=50 32 | 33 | for FAMILY in ipv6 ipv4 ; do 34 | for NS in nonglobal global; do 35 | case $FAMILY in 36 | ipv4) 37 | if [[ $NS == "global" ]]; then 38 | ADDR=$VETH2_IPV4 39 | else 40 | ADDR=$VETH1_IPV4 41 | fi 42 | SYSCTL_PREFIX=net.ipv4.ipfrag_ 43 | SYSCTL_NAME="${SYSCTL_PREFIX}high_thresh" 44 | ;; 45 | ipv6) 46 | if [[ $NS == "global" ]]; then 47 | ADDR=$VETH2_IPV6 48 | else 49 | ADDR=$VETH1_IPV6 50 | fi 51 | SYSCTL_PREFIX=net.ipv6.ip6frag_ 52 | SYSCTL_NAME="${SYSCTL_PREFIX}high_thresh" 53 | ;; 54 | esac 55 | 56 | test_start "$0|frag test to $ADDR:$PORT $FAMILY $NS" 57 | 58 | if [[ $NS == "global" ]]; then 59 | CLIENT_PREFIX="ip netns exec $NETNS" 60 | CLIENT_VETH=$VETH1 61 | SERVER_PREFIX="" 62 | SERVER_VETH=$VETH2 63 | else 64 | CLIENT_PREFIX="" 65 | CLIENT_VETH=$VETH2 66 | SERVER_PREFIX="ip netns exec $NETNS" 67 | SERVER_VETH=$VETH1 68 | fi 69 | test_setup true 70 | 71 | $CLIENT_PREFIX ethtool --offload $CLIENT_VETH rx off tx off gso off gro off lro off tso off 72 | $SERVER_PREFIX ethtool --offload $SERVER_VETH rx off tx off gso off gro off lro off tso off 73 | frag_orig=($(sysctl -n $SYSCTL_NAME)) 74 | low_orig=($(sysctl -n ${SYSCTL_PREFIX}low_thresh)) 75 | sysctl -w ${SYSCTL_PREFIX}low_thresh=8192 76 | sysctl -w $SYSCTL_NAME="8192" 77 | 78 | frag_pre=($(sysctl -n $SYSCTL_NAME)) 79 | 80 | # prevent firewall from reassembling packets. 81 | set +e 82 | FIREWALLD_PID=$(pgrep firewalld) 83 | set -e 84 | if [[ -n "$FIREWALLD_PID" ]]; then 85 | service firewalld stop 86 | fi 87 | for MODE in baseline test ; do 88 | 89 | echo "Running ${MODE}..." 90 | if [[ $MODE != "baseline" ]]; then 91 | test_run_cmd_local "$BPFTUNE -s &" true 92 | sleep $SETUPTIME 93 | else 94 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 95 | LOGSZ=$(expr $LOGSZ + 1) 96 | fi 97 | set +e 98 | echo "Running $CLIENT_PREFIX ping -v -c 20 -M t -s 8192 $ADDR" 99 | $CLIENT_PREFIX ping -v -c 20 -M want -s 8192 $ADDR 100 | set -e 101 | 102 | if [[ $MODE != "baseline" ]]; then 103 | pkill -TERM bpftune 104 | sleep $SETUPTIME 105 | else 106 | sleep $SLEEPTIME 107 | fi 108 | done 109 | if [[ -n "$FIREWALLD_PID" ]]; then 110 | service firewalld start 111 | fi 112 | frag_post=($(sysctl -n $SYSCTL_NAME)) 113 | if [[ -n $SERVER_PREFIX ]]; then 114 | sysctl -w ${SYSCTL_NAME}=$frag_orig 115 | sysctl -w ${SYSCTL_PREFIX}low_thresh=$low_orig 116 | fi 117 | echo "$SYSCTL_NAME before ${frag_pre}" 118 | echo "$SYSCTL_NAME after ${frag_post}" 119 | if [[ $MODE == "test" ]]; then 120 | if [[ "${frag_post}" -gt ${frag_pre} ]]; then 121 | grep "approaching fragmentation maximum threshold" $LOGFILE 122 | test_pass 123 | else 124 | test_cleanup 125 | fi 126 | fi 127 | 128 | test_cleanup 129 | done 130 | done 131 | 132 | test_exit 133 | -------------------------------------------------------------------------------- /test/good_syn_flood_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # check performance under syn flood 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=1 29 | TIMEOUT=30 30 | MAX_CONN=1000 31 | 32 | for NS in nonglobal global ; do 33 | for FAMILY in ipv4 ; do 34 | 35 | case $FAMILY in 36 | ipv4) 37 | if [[ $NS == "global" ]]; then 38 | ADDR=$VETH2_IPV4 39 | else 40 | ADDR=$VETH1_IPV4 41 | fi 42 | DUMMY_SERVER=192.168.200.3 43 | DUMMY_CLIENT=192.168.200.4 44 | WGET_ARG="" 45 | WGET_ADDR=$ADDR 46 | HTTP_BIND_ADDR="" 47 | ;; 48 | ipv6) 49 | pyversion=$(python3 --version | awk -F '.' '{ print $2 }') 50 | # http.server supports IPv6 for 3.8 and later. 51 | if [[ $pyversion -lt 8 ]]; then 52 | echo "IPv6 test needs python 3.8 or later, skipping" 53 | continue 54 | fi 55 | if [[ $NS == "global" ]]; then 56 | ADDR=$VETH2_IPV6 57 | else 58 | ADDR=$VETH1_IPV6 59 | fi 60 | DUMMY_SERVER=fe::1 61 | DUMMY_CLIENT=fe::2 62 | WGET_ARG="-6" 63 | WGET_ADDR="[${ADDR}]" 64 | HTTP_BIND_ADDR="--bind $ADDR" 65 | ;; 66 | esac 67 | 68 | LATENCY="delay 1000" 69 | test_start "$0|syn flood test to $ADDR:$PORT $FAMILY $NS " 70 | 71 | if [[ $NS == "global" ]]; then 72 | CLIENT_PREFIX="ip netns exec $NETNS" 73 | CLIENT_VETH=$VETH1 74 | export SERVER_PREFIX="" 75 | SERVER_VETH=$VETH2 76 | else 77 | CLIENT_PREFIX="" 78 | CLIENT_VETH=$VETH2 79 | export SERVER_PREFIX="ip netns exec $NETNS" 80 | SERVER_VETH=$VETH1 81 | fi 82 | test_setup true 83 | ip netns exec $NETNS tc qdisc add dev $VETH1 root netem loss 0 ${LATENCY} 84 | 85 | syn_backlog_pre=128 86 | $SERVER_PREFIX sysctl -w net.ipv4.tcp_max_syn_backlog=$syn_backlog_pre 87 | $SERVER_PREFIX sysctl -w net.ipv4.tcp_syncookies=0 88 | 89 | set +e 90 | FIREWALLD_PID=$(pgrep firewalld) 91 | set -e 92 | if [[ -n "$FIREWALLD_PID" ]]; then 93 | service firewalld stop 94 | fi 95 | 96 | $SERVER_PREFIX ulimit -n 100000 97 | $SERVER_PREFIX ulimit -u 100000 98 | $CLIENT_PREFIX ulimit -n 100000 99 | $CLIENT_PREFIX ulimit -u 100000 100 | 101 | for MODE in baseline test ; do 102 | 103 | echo "Running ${MODE}..." 104 | test_run_cmd_local "$SERVER_PREFIX ./conn_bomb -q -l 0.0.0.0 -p $PORT -C $MAX_CONN -b 20 &" true 105 | sleep $SLEEPTIME 106 | 107 | if [[ $MODE != "baseline" ]]; then 108 | test_run_cmd_local "$BPFTUNE -s &" true 109 | sleep $SETUPTIME 110 | else 111 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 112 | LOGSZ=$(expr $LOGSZ + 1) 113 | fi 114 | set +e 115 | $CLIENT_PREFIX ./conn_bomb -q -r $ADDR -P $PORT -C $MAX_CONN 116 | set -e 117 | if [[ $MODE != "baseline" ]]; then 118 | pkill -TERM bpftune 119 | sleep $SETUPTIME 120 | tail -n +${LOGSZ} $LOGFILE 121 | else 122 | sleep $SLEEPTIME 123 | fi 124 | done 125 | if [[ -n "$FIREWALLD_PID" ]]; then 126 | service firewalld start 127 | fi 128 | 129 | syn_backlog_post=$(sysctl -n net.ipv4.tcp_max_syn_backlog) 130 | echo "net.ipv4.tcp_max_syn_backlog is $syn_backlog_post" 131 | if [[ $syn_backlog_post -lt $syn_backlog_pre ]]; then 132 | echo "net.ipv4.tcp_max_syn_backlog did not increase under load from $syn_backlog_pre" 133 | else 134 | test_pass 135 | fi 136 | test_cleanup 137 | done 138 | done 139 | 140 | test_exit 141 | -------------------------------------------------------------------------------- /test/inotify_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # check removal/addition of tuners is noticed. 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=10 28 | 29 | for TUNER in neigh_table ; do 30 | 31 | test_start "$0|inotify test: do we notice removal/addition of tuner?" 32 | 33 | test_setup "true" 34 | 35 | test_run_cmd_local "$BPFTUNE -ds &" true 36 | 37 | sleep $SETUPTIME 38 | 39 | cp /usr/lib64/bpftune/tcp_buffer_tuner.so /tmp 40 | rm /usr/lib64/bpftune/tcp_buffer_tuner.so 41 | 42 | sleep $SLEEPTIME 43 | grep "fini tuner" $TESTLOG_LAST 44 | 45 | sleep $SLEEPTIME 46 | 47 | cp /tmp/tcp_buffer_tuner.so /usr/lib64/bpftune 48 | 49 | sleep $SLEEPTIME 50 | grep "added lib" $TESTLOG_LAST 51 | 52 | test_pass 53 | 54 | test_cleanup 55 | done 56 | 57 | test_exit 58 | -------------------------------------------------------------------------------- /test/iperf3_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run iperf3 test 23 | 24 | PORT=5201 25 | 26 | TUNER=${TUNER:-} 27 | if [[ -n "$TUNER" ]]; then 28 | BPFTUNE_FLAGS="$BPFTUNE_FLAGS -a $TUNER" 29 | fi 30 | 31 | . ./test_lib.sh 32 | 33 | LOGFILE=$TESTLOG_LAST 34 | 35 | SLEEPTIME=0.5 36 | TIMEOUT=30 37 | 38 | DROP=0 39 | 40 | for FAMILY in ipv4 ipv6 ; do 41 | 42 | for LATENCY in "" "latency 20ms" ; do 43 | for CLIENT_OPTS in "" "-R" ; do 44 | case $FAMILY in 45 | ipv4) 46 | ADDR=$VETH1_IPV4 47 | ;; 48 | ipv6) 49 | ADDR=$VETH1_IPV6 50 | ;; 51 | esac 52 | 53 | test_start "$0|iperf3 test to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 54 | 55 | test_setup "true" 56 | 57 | declare -A results 58 | for MODE in baseline test ; do 59 | 60 | echo "Running ${MODE}..." 61 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 62 | if [[ $MODE == "test" ]]; then 63 | test_run_cmd_local "$BPFTUNE -s &" true 64 | sleep $SETUPTIME 65 | else 66 | sleep $SLEEPTIME 67 | fi 68 | test_run_cmd_local "$IPERF3 -fm $CLIENT_OPTS -p $PORT -c $ADDR" true 69 | 70 | sresults=$(grep -E "sender" ${CMDLOG} | awk '{print $7}') 71 | rresults=$(grep -E "receiver" ${CMDLOG} | awk '{print $7}') 72 | units=$(grep -E "sender|receiver" ${CMDLOG} | awk '{print $8}' |head -1) 73 | 74 | if [[ $MODE == "baseline" ]]; then 75 | read -r -a sbaseline_results <<< $sresults 76 | read -r -a rbaseline_results <<< $rresults 77 | echo "" > ${CMDLOG} 78 | else 79 | read -r -a stest_results <<< $sresults 80 | read -r -a rtest_results <<< $rresults 81 | fi 82 | sleep $SLEEPTIME 83 | done 84 | 85 | printf "Results sender (${units}): " 86 | for (( i=0; i < ${#sbaseline_results[@]}; i++ )) 87 | do 88 | sbase=$(roundup ${sbaseline_results[$i]}) 89 | stest=$(roundup ${stest_results[$i]}) 90 | if [[ ${sbase} -gt ${stest} ]]; then 91 | bold "Warning: baseline (${sbase}) > test (${stest})" 92 | else 93 | echo "baseline (${sbase}) < test (${stest})" 94 | fi 95 | done 96 | printf "Results receiver (${units}): " 97 | for (( i=0; i < ${#rbaseline_results[@]}; i++ )) 98 | do 99 | rbase=$(roundup ${rbaseline_results[$i]}) 100 | rtest=$(roundup ${rtest_results[$i]}) 101 | if [[ ${rbase} -gt ${rtest} ]]; then 102 | bold "Warning: baseline (${rbase}) > test (${rtest})" 103 | else 104 | echo "baseline (${rbase}) < test (${rtest})" 105 | fi 106 | done 107 | echo "Following changes were made:" 108 | set +e 109 | grep bpftune $LOGFILE 110 | set -e 111 | test_pass 112 | 113 | test_cleanup 114 | done 115 | done 116 | done 117 | 118 | test_exit 119 | -------------------------------------------------------------------------------- /test/log_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run sysctl test 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=1 28 | 29 | for MODE in debug info syslog service; do 30 | 31 | LOGFILE=$TESTLOG_LAST 32 | case $MODE in 33 | debug) 34 | OPTIONS="-ds" 35 | BPFTUNECMD="$BPFTUNE $OPTIONS &" 36 | ;; 37 | syslog) 38 | OPTIONS="-d" 39 | BPFTUNECMD="$BPFTUNE $OPTIONS &" 40 | LOGFILE=$SYSLOGFILE 41 | ;; 42 | service) 43 | BPFTUNECMD="service bpftue start" 44 | LOGFILE=$SYSLOGFILE 45 | ;; 46 | *) 47 | OPTIONS="-s" 48 | BPFTUNECMD="$BPFTUNE $OPTIONS &" 49 | ;; 50 | esac 51 | 52 | test_start "$0|log test: does setting $MODE logging generate messages for $BPFTUNECMD?" 53 | 54 | test_setup "true" 55 | 56 | test_run_cmd_local "$BPFTUNECMD &" true 57 | 58 | sleep $SETUPTIME 59 | grep "bpftune works" $LOGFILE 60 | if [[ "$OPTIONS" == "-ds" ]]; then 61 | # should see multiple lines for debug 62 | LINES=$(wc -l $LOGFILE | awk '{ print $1 }') 63 | if [[ $LINES -gt 1 ]]; then 64 | test_pass 65 | fi 66 | else 67 | test_pass 68 | fi 69 | 70 | test_cleanup 71 | done 72 | 73 | test_exit 74 | -------------------------------------------------------------------------------- /test/mem_exhaust_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | PORT=5201 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=5 29 | TIMEOUT=30 30 | MAX_CONN=100 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | case $FAMILY in 35 | ipv4) 36 | ADDR=$VETH1_IPV4 37 | ;; 38 | ipv6) 39 | ADDR=$VETH1_IPV6 40 | ;; 41 | esac 42 | 43 | test_start "$0|mem legacy test to $ADDR:$PORT $FAMILY $MAX_CONN conn" 44 | 45 | mem_orig=($(sysctl -n net.ipv4.tcp_mem)) 46 | 47 | mem_test=($(echo 50 100 100)) 48 | 49 | sysctl -w net.ipv4.tcp_mem="${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 50 | 51 | test_setup true 52 | 53 | declare -A results 54 | for MODE in baseline test ; do 55 | 56 | echo "Running ${MODE}..." 57 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 58 | if [[ $MODE != "baseline" ]]; then 59 | test_run_cmd_local "$BPFTUNE -L -a tcp_buffer_tuner.so -s &" true 60 | sleep $SETUPTIME 61 | else 62 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 63 | fi 64 | set +e 65 | test_run_cmd_local "$IPERF3 -fm -P $MAX_CONN -p $PORT -c $ADDR " true 66 | set -e 67 | 68 | sleep $SLEEPTIME 69 | done 70 | 71 | mem_post=($(sysctl -n net.ipv4.tcp_mem)) 72 | sysctl -w net.ipv4.tcp_mem="${mem_orig[0]} ${mem_orig[1]} ${mem_orig[2]}" 73 | echo "mem before ${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 74 | echo "mem after ${mem_post[0]} ${mem_post[1]} ${mem_post[2]}" 75 | if [[ $MODE == "test" ]]; then 76 | echo "Following changes were made:" 77 | set +e 78 | grep bpftune $LOGFILE 79 | set -e 80 | if [[ "${mem_post[2]}" -gt ${mem_test[2]} ]]; then 81 | test_pass 82 | else 83 | test_cleanup 84 | fi 85 | fi 86 | 87 | test_cleanup 88 | done 89 | 90 | test_exit 91 | -------------------------------------------------------------------------------- /test/mem_exhaust_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | PORT=5201 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=5 29 | TIMEOUT=30 30 | MAX_CONN=100 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | case $FAMILY in 35 | ipv4) 36 | ADDR=$VETH1_IPV4 37 | ;; 38 | ipv6) 39 | ADDR=$VETH1_IPV6 40 | ;; 41 | esac 42 | 43 | test_start "$0|mem test to $ADDR:$PORT $FAMILY $MAX_CONN conn" 44 | 45 | mem_orig=($(sysctl -n net.ipv4.tcp_mem)) 46 | 47 | mem_test=($(echo 50 100 100)) 48 | 49 | sysctl -w net.ipv4.tcp_no_metrics_save=0 50 | sysctl -w net.ipv4.tcp_no_ssthresh_metrics_save=0 51 | sysctl -w net.ipv4.tcp_mem="${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 52 | 53 | test_setup true 54 | 55 | declare -A results 56 | for MODE in baseline test ; do 57 | 58 | echo "Running ${MODE}..." 59 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 60 | if [[ $MODE != "baseline" ]]; then 61 | test_run_cmd_local "$BPFTUNE -a tcp_buffer_tuner.so -s &" true 62 | sleep $SETUPTIME 63 | else 64 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 65 | fi 66 | set +e 67 | test_run_cmd_local "$IPERF3 -fm -P $MAX_CONN -p $PORT -c $ADDR " true 68 | set -e 69 | 70 | sleep $SLEEPTIME 71 | done 72 | 73 | mem_post=($(sysctl -n net.ipv4.tcp_mem)) 74 | no_metrics_save=($(sysctl -n net.ipv4.tcp_no_metrics_save)) 75 | no_ssthresh_metrics_save=($(sysctl -n net.ipv4.tcp_no_ssthresh_metrics_save)) 76 | sysctl -w net.ipv4.tcp_mem="${mem_orig[0]} ${mem_orig[1]} ${mem_orig[2]}" 77 | echo "mem before ${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 78 | echo "mem after ${mem_post[0]} ${mem_post[1]} ${mem_post[2]}" 79 | echo "no_[ssthresh]metrics_save before 0, 0" 80 | echo "no_[ssthresh]metrics_save after $no_metrics_save , $no_ssthresh_metrics_save" 81 | if [[ $MODE == "test" ]]; then 82 | echo "Following changes were made:" 83 | set +e 84 | grep bpftune $LOGFILE 85 | set -e 86 | if [[ "${mem_post[2]}" -gt ${mem_test[2]} ]]; then 87 | if [[ "$no_metrics_save" -eq 1 ]]; then 88 | test_pass 89 | fi 90 | else 91 | test_cleanup 92 | fi 93 | fi 94 | 95 | test_cleanup 96 | done 97 | 98 | test_exit 99 | -------------------------------------------------------------------------------- /test/mem_pressure_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | PORT=5201 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=5 29 | TIMEOUT=30 30 | MAX_CONN=50 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | case $FAMILY in 35 | ipv4) 36 | ADDR=$VETH1_IPV4 37 | ;; 38 | ipv6) 39 | ADDR=$VETH1_IPV6 40 | ;; 41 | esac 42 | 43 | test_start "$0|mem legacy test to $ADDR:$PORT $FAMILY $MAX_CONN conn" 44 | 45 | mem_orig=($(sysctl -n net.ipv4.tcp_mem)) 46 | 47 | mem_test=($(echo 50 100 2000000000)) 48 | 49 | sysctl -w net.ipv4.tcp_mem="${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 50 | 51 | test_setup true 52 | 53 | declare -A results 54 | for MODE in baseline test ; do 55 | 56 | echo "Running ${MODE}..." 57 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 58 | if [[ $MODE != "baseline" ]]; then 59 | test_run_cmd_local "$BPFTUNE -L -a tcp_buffer_tuner.so -s &" true 60 | sleep $SETUPTIME 61 | else 62 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 63 | fi 64 | set +e 65 | test_run_cmd_local "$IPERF3 -fm -P $MAX_CONN -p $PORT -c $ADDR " true 66 | set -e 67 | 68 | sleep $SLEEPTIME 69 | done 70 | 71 | mem_post=($(sysctl -n net.ipv4.tcp_mem)) 72 | sysctl -w net.ipv4.tcp_mem="${mem_orig[0]} ${mem_orig[1]} ${mem_orig[2]}" 73 | echo "mem before ${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 74 | echo "mem after ${mem_post[0]} ${mem_post[1]} ${mem_post[2]}" 75 | if [[ $MODE == "test" ]]; then 76 | echo "Following changes were made:" 77 | set +e 78 | grep bpftune $LOGFILE 79 | set -e 80 | if [[ "${mem_post[1]}" -gt ${mem_test[1]} ]]; then 81 | if [[ "${mem_post[2]}" -lt ${mem_test[2]} ]]; then 82 | test_pass 83 | fi 84 | else 85 | test_cleanup 86 | fi 87 | fi 88 | 89 | test_cleanup 90 | done 91 | 92 | test_exit 93 | -------------------------------------------------------------------------------- /test/mem_pressure_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | PORT=5201 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=5 29 | TIMEOUT=30 30 | MAX_CONN=50 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | case $FAMILY in 35 | ipv4) 36 | ADDR=$VETH1_IPV4 37 | ;; 38 | ipv6) 39 | ADDR=$VETH1_IPV6 40 | ;; 41 | esac 42 | 43 | test_start "$0|mem test to $ADDR:$PORT $FAMILY $MAX_CONN conn" 44 | 45 | mem_orig=($(sysctl -n net.ipv4.tcp_mem)) 46 | 47 | mem_test=($(echo 50 100 2000000000)) 48 | 49 | sysctl -w net.ipv4.tcp_mem="${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 50 | 51 | test_setup true 52 | 53 | declare -A results 54 | for MODE in baseline test ; do 55 | 56 | echo "Running ${MODE}..." 57 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 58 | if [[ $MODE != "baseline" ]]; then 59 | test_run_cmd_local "$BPFTUNE -a tcp_buffer_tuner.so -s &" true 60 | sleep $SETUPTIME 61 | else 62 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 63 | fi 64 | set +e 65 | test_run_cmd_local "$IPERF3 -fm -P $MAX_CONN -p $PORT -c $ADDR " true 66 | set -e 67 | 68 | sleep $SLEEPTIME 69 | done 70 | 71 | mem_post=($(sysctl -n net.ipv4.tcp_mem)) 72 | sysctl -w net.ipv4.tcp_mem="${mem_orig[0]} ${mem_orig[1]} ${mem_orig[2]}" 73 | echo "mem before ${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 74 | echo "mem after ${mem_post[0]} ${mem_post[1]} ${mem_post[2]}" 75 | if [[ $MODE == "test" ]]; then 76 | echo "Following changes were made:" 77 | set +e 78 | grep bpftune $LOGFILE 79 | set -e 80 | if [[ "${mem_post[1]}" -gt ${mem_test[1]} ]]; then 81 | if [[ "${mem_post[2]}" -lt ${mem_test[2]} ]]; then 82 | test_pass 83 | fi 84 | else 85 | test_cleanup 86 | fi 87 | fi 88 | 89 | test_cleanup 90 | done 91 | 92 | test_exit 93 | -------------------------------------------------------------------------------- /test/mem_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run iperf3 test with low mem max, ensure tuner increases it. 23 | 24 | PORT=5201 25 | 26 | . ./test_lib.sh 27 | 28 | SLEEPTIME=1 29 | TIMEOUT=30 30 | MAX_CONN=50 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | case $FAMILY in 35 | ipv4) 36 | ADDR=$VETH1_IPV4 37 | ;; 38 | ipv6) 39 | ADDR=$VETH1_IPV6 40 | ;; 41 | esac 42 | 43 | test_start "$0|mem test to $ADDR:$PORT $FAMILY $MAX_CONN conn" 44 | 45 | mem_orig=($(sysctl -n net.ipv4.tcp_mem)) 46 | 47 | mem_test=($(echo 50 100 2000)) 48 | test_setup true 49 | 50 | sysctl -w net.ipv4.tcp_mem="${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 51 | 52 | declare -A results 53 | for MODE in baseline test ; do 54 | 55 | echo "Running ${MODE}..." 56 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 57 | if [[ $MODE != "baseline" ]]; then 58 | test_run_cmd_local "$BPFTUNE -ds &" true 59 | sleep $SETUPTIME 60 | else 61 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 62 | LOGSZ=$(expr $LOGSZ + 1) 63 | fi 64 | set +e 65 | test_run_cmd_local "$IPERF3 -fm -P $MAX_CONN -p $PORT -c $ADDR " true 66 | set -e 67 | 68 | sleep $SLEEPTIME 69 | done 70 | 71 | mem_post=($(sysctl -n net.ipv4.tcp_mem)) 72 | sysctl -w net.ipv4.tcp_mem="${mem_orig[0]} ${mem_orig[1]} ${mem_orig[2]}" 73 | echo "mem before ${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 74 | echo "mem after ${mem_post[0]} ${mem_post[1]} ${mem_post[2]}" 75 | if [[ $MODE == "test" ]]; then 76 | if [[ "${mem_post[2]}" -gt ${mem_test[2]} ]]; then 77 | test_pass 78 | else 79 | test_cleanup 80 | fi 81 | fi 82 | 83 | test_cleanup 84 | done 85 | 86 | test_exit 87 | -------------------------------------------------------------------------------- /test/neigh_table_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | 23 | # run neigh table test 24 | 25 | . ./test_lib.sh 26 | 27 | LOGFILE=$TESTLOG_LAST 28 | 29 | SLEEPTIME=1 30 | 31 | for TUNER in neigh_table ; do 32 | 33 | # gc_thresh3 is not namespaced... 34 | 35 | for NS in global ; do 36 | for TBL in arp_cache ndisc_cache ; do 37 | 38 | test_start "$0|neigh table legacy test ($NS netns): does filling $TBL make it grow?" 39 | 40 | test_setup "true" 41 | 42 | test_run_cmd_local "$BPFTUNE -sL &" true 43 | 44 | sleep $SETUPTIME 45 | 46 | if [[ $NS != "global" ]]; then 47 | PREFIX_CMD="ip netns exec $NETNS " 48 | INTF=$VETH1 49 | else 50 | PREFIX_CMD="" 51 | INTF=$VETH2 52 | fi 53 | $PREFIX_CMD ip ntable change name $TBL dev $INTF thresh3 128 54 | 55 | for ((i=3; i < 255; i++ )) 56 | do 57 | ipaddr="192.168.168.${i}" 58 | ih=$(printf '%x' $i) 59 | ip6addr="fd::${ih}" 60 | macaddr="de:ad:be:ef:de:${ih}" 61 | if [[ $TBL == "arp_cache" ]]; then 62 | $PREFIX_CMD ip neigh replace $ipaddr lladdr $macaddr dev $INTF 63 | else 64 | $PREFIX_CMD ip neigh replace $ip6addr lladdr $macaddr dev $INTF 65 | fi 66 | done 67 | grep "updated gc_thresh3 for $TBL table" $LOGFILE 68 | test_pass 69 | done 70 | done 71 | done 72 | 73 | test_cleanup 74 | 75 | test_exit 76 | -------------------------------------------------------------------------------- /test/neigh_table_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run neigh table test 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=1 29 | 30 | for TUNER in neigh_table ; do 31 | 32 | # gc_thresh3 is not namespaced... 33 | 34 | for NS in global ; do 35 | for TBL in arp_cache ndisc_cache ; do 36 | 37 | test_start "$0|neigh table test ($NS netns): does filling $TBL make it grow?" 38 | 39 | test_setup "true" 40 | 41 | test_run_cmd_local "$BPFTUNE -s &" true 42 | 43 | sleep $SETUPTIME 44 | 45 | if [[ $NS != "global" ]]; then 46 | PREFIX_CMD="ip netns exec $NETNS " 47 | INTF=$VETH1 48 | else 49 | PREFIX_CMD="" 50 | INTF=$VETH2 51 | fi 52 | $PREFIX_CMD ip ntable change name $TBL dev $INTF thresh3 128 53 | 54 | for ((i=3; i < 255; i++ )) 55 | do 56 | ipaddr="192.168.168.${i}" 57 | ih=$(printf '%x' $i) 58 | ip6addr="fd::${ih}" 59 | macaddr="de:ad:be:ef:de:${ih}" 60 | if [[ $TBL == "arp_cache" ]]; then 61 | $PREFIX_CMD ip neigh replace $ipaddr lladdr $macaddr dev $INTF 62 | else 63 | $PREFIX_CMD ip neigh replace $ip6addr lladdr $macaddr dev $INTF 64 | fi 65 | done 66 | grep "updated gc_thresh3 for $TBL table" $LOGFILE 67 | test_pass 68 | done 69 | done 70 | done 71 | 72 | test_cleanup 73 | 74 | test_exit 75 | -------------------------------------------------------------------------------- /test/neigh_table_v4only_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run neigh table test when ipv6 is disabled 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=1 29 | 30 | for TUNER in neigh_table ; do 31 | 32 | # gc_thresh3 is not namespaced... 33 | 34 | for NS in global ; do 35 | for TBL in arp_cache ; do 36 | 37 | test_start "$0|neigh table test ($NS netns): does filling $TBL make it grow?" 38 | 39 | test_setup "true" 40 | 41 | sysctl -w net.ipv6.conf.all.disable_ipv6=1 42 | if [[ $NS != "global" ]]; then 43 | ip netns exec $NS sysctl -w net.ipv6.conf.all.disable_ipv6=1 44 | fi 45 | test_run_cmd_local "$BPFTUNE -s &" true 46 | 47 | sleep $SETUPTIME 48 | 49 | if [[ $NS != "global" ]]; then 50 | PREFIX_CMD="ip netns exec $NETNS " 51 | INTF=$VETH1 52 | else 53 | PREFIX_CMD="" 54 | INTF=$VETH2 55 | fi 56 | $PREFIX_CMD ip ntable change name $TBL dev $INTF thresh3 128 57 | 58 | for ((i=3; i < 255; i++ )) 59 | do 60 | ipaddr="192.168.168.${i}" 61 | ih=$(printf '%x' $i) 62 | macaddr="de:ad:be:ef:de:${ih}" 63 | $PREFIX_CMD ip neigh replace $ipaddr lladdr $macaddr dev $INTF 64 | done 65 | grep "updated gc_thresh3 for $TBL table" $LOGFILE 66 | test_pass 67 | done 68 | done 69 | done 70 | 71 | test_cleanup 72 | 73 | test_exit 74 | -------------------------------------------------------------------------------- /test/netns_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # verify netns/container add/remove is caught by bpftune 23 | 24 | . ./test_lib.sh 25 | 26 | check_podman 27 | 28 | SLEEPTIME=2 29 | 30 | 31 | test_setup "true" 32 | 33 | for CONTAINER_CMD in "ip netns add testns.$$" "$PODMAN_CMD sleep 5" ; do 34 | test_start "$0|netns legacy test: does running '${CONTAINER_CMD}' generate event?" 35 | 36 | if [[ ${BPFTUNE_NETNS} -eq 0 ]]; then 37 | echo "bpftune does not support per-netns policy, skipping..." 38 | test_pass 39 | continue 40 | fi 41 | if [[ ${CONTAINER_CMD} =~ "$PODMAN_CMD" ]]; then 42 | if [[ -z "$PODMAN" ]]; then 43 | echo "podman not available, skipping..." 44 | test_pass 45 | continue 46 | fi 47 | fi 48 | test_run_cmd_local "$BPFTUNE -dsL &" true 49 | sleep $SETUPTIME 50 | test_run_cmd_local "$CONTAINER_CMD" 51 | if [[ ${CONTAINER_CMD} =~ "ip netns" ]]; then 52 | ip netns del testns.$$ 53 | fi 54 | sleep $SLEEPTIME 55 | grep "netns created" $TESTLOG_LAST 56 | test_pass 57 | done 58 | test_cleanup 59 | test_exit 60 | -------------------------------------------------------------------------------- /test/netns_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # verify netns/container add/remove is caught by bpftune 23 | 24 | # enable proxyt if available... 25 | service proxyt start 2>/dev/null 26 | 27 | # ...and skip disable of it during test setup so we can find podman images. 28 | PROXYT_SERVICE="" 29 | 30 | . ./test_lib.sh 31 | 32 | check_podman 33 | 34 | SLEEPTIME=2 35 | 36 | 37 | test_setup "true" 38 | 39 | for CONTAINER_CMD in "ip netns add testns.$$" "$PODMAN_CMD sleep 5" ; do 40 | test_start "$0|netns test: does running '${CONTAINER_CMD}' generate event?" 41 | 42 | if [[ ${BPFTUNE_NETNS} -eq 0 ]]; then 43 | echo "bpftune does not support per-netns policy, skipping..." 44 | test_pass 45 | continue 46 | fi 47 | if [[ ${CONTAINER_CMD} =~ "$PODMAN_CMD" ]]; then 48 | if [[ -z "$PODMAN" ]]; then 49 | echo "podman not available, skipping..." 50 | test_pass 51 | continue 52 | fi 53 | fi 54 | test_run_cmd_local "$BPFTUNE -ds &" true 55 | sleep $SETUPTIME 56 | test_run_cmd_local "$CONTAINER_CMD" 57 | if [[ ${CONTAINER_CMD} =~ "ip netns" ]]; then 58 | ip netns del testns.$$ 59 | fi 60 | sleep $SLEEPTIME 61 | grep "netns created" $TESTLOG_LAST 62 | test_pass 63 | done 64 | test_cleanup 65 | test_exit 66 | -------------------------------------------------------------------------------- /test/pcp_pmda_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2025, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | . ./test_lib.sh 23 | 24 | 25 | SETUPTIME=10 26 | 27 | CWD=$(dirname $0) 28 | 29 | test_start "$0|pcp pmda test: are tunables available" 30 | 31 | if [[ -n "$DBPMDA_CMD" ]]; then 32 | test_run_cmd_local "$BPFTUNE -s &" true 33 | sleep $SETUPTIME 34 | cat</dev/null 2>&1 33 | if [[ $? -ne 0 ]]; then 34 | echo "$QPERF does not work, skipping qperf-based tests..." 35 | exit 0 36 | fi 37 | set -e 38 | LOGFILE=$TESTLOG_LAST 39 | 40 | for FAMILY in ipv4 ipv6 ; do 41 | 42 | SLEEPTIME=0.5 43 | 44 | DROP=0 45 | 46 | for LATENCY in "" "latency 20ms" ; do 47 | 48 | for CLIENT_OPTS in tcp_bw tcp_lat ; do 49 | case $FAMILY in 50 | ipv4) 51 | ADDR=$VETH1_IPV4 52 | ;; 53 | ipv6) 54 | ADDR=$VETH1_IPV6 55 | ;; 56 | esac 57 | 58 | test_start "$0|qperf test to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 59 | 60 | test_setup "true" 61 | 62 | declare -A results 63 | for MODE in baseline test ; do 64 | 65 | echo "Running ${MODE}..." 66 | test_run_cmd_local "ip netns exec $NETNS $QPERF &" 67 | if [[ $MODE == "test" ]]; then 68 | test_run_cmd_local "$BPFTUNE -s &" true 69 | sleep $SETUPTIME 70 | fi 71 | test_run_cmd_local \ 72 | "$QPERF -v $ADDR -uu -oo msg_size:1:64k:*4 -vu ${CLIENT_OPTS}" true 73 | sleep $SLEEPTIME 74 | results=$(grep -E "bw.*=|lat.*=" ${CMDLOG} | awk '{print $3}') 75 | units=$(grep -E "bw.*=|lat.*=" ${CMDLOG} | awk '{print $4}' |head -1) 76 | if [[ $MODE == "baseline" ]]; then 77 | read -r -a baseline_results <<< $results 78 | echo "" > ${CMDLOG} 79 | else 80 | read -r -a test_results <<< $results 81 | fi 82 | done 83 | 84 | for (( i=0; i < ${#baseline_results[@]}; i++ )) 85 | do 86 | printf "Results $i ${CLIENT_OPTS} (${units}): " 87 | case $CLIENT_OPTS in 88 | tcp_bw) 89 | if [[ ${baseline_results[$i]} -gt ${test_results[$i]} ]]; then 90 | bold "Warning: baseline ${baseline_results[$i]} > test (${test_results[$i]})" 91 | else 92 | echo "baseline (${baseline_results[$i]}) < test (${test_results[$i]})" 93 | fi 94 | ;; 95 | 96 | tcp_lat) 97 | if [[ ${baseline_results[$i]} -lt ${test_results[$i]} ]]; then 98 | bold "Warning: baseline ${baseline_results[$i]} < test (${test_results[$i]})" 99 | else 100 | echo "baseline (${baseline_results[$i]}) > test (${test_results[$i]})" 101 | fi 102 | ;; 103 | esac 104 | done 105 | 106 | echo "Following changes were made:" 107 | set +e 108 | grep "bpftune" $LOGFILE 109 | set -e 110 | 111 | test_pass 112 | 113 | test_cleanup 114 | done 115 | done 116 | done 117 | 118 | test_exit 119 | -------------------------------------------------------------------------------- /test/query_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # test various queries 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=1 29 | TIMEOUT=30 30 | MAX_CONN=50 31 | 32 | test_setup true 33 | for QUERY in help tuners tunables ; do 34 | test_start "$0|query $QUERY test" 35 | test_run_cmd_local "$BPFTUNE -s &" true 36 | sleep $SETUPTIME 37 | $BPFTUNE_CMD -q $QUERY 38 | test_pass 39 | done 40 | test_cleanup 41 | 42 | if [[ -n "$JQ_CMD" ]]; then 43 | test_setup true 44 | for JQUERY in jtunables jstatus ; do 45 | test_start "$0|query $JQUERY test" 46 | test_run_cmd_local "$BPFTUNE -s &" true 47 | sleep $SETUPTIME 48 | $BPFTUNE_CMD -q $JQUERY | $JQ_CMD 49 | test_pass 50 | done 51 | test_cleanup 52 | fi 53 | 54 | for QUERY in summary rollback status ; do 55 | for FAMILY in ipv4 ; do 56 | for NS in global; do 57 | case $FAMILY in 58 | ipv4) 59 | if [[ $NS == "global" ]]; then 60 | ADDR=$VETH2_IPV4 61 | else 62 | ADDR=$VETH1_IPV4 63 | fi 64 | SYSCTL_PREFIX=net.ipv4.ipfrag_ 65 | SYSCTL_NAME="${SYSCTL_PREFIX}high_thresh" 66 | ;; 67 | ipv6) 68 | if [[ $NS == "global" ]]; then 69 | ADDR=$VETH2_IPV6 70 | else 71 | ADDR=$VETH1_IPV6 72 | fi 73 | SYSCTL_PREFIX=net.ipv6.ip6frag_ 74 | SYSCTL_NAME="${SYSCTL_PREFIX}high_thresh" 75 | ;; 76 | esac 77 | 78 | test_start "$0|query $QUERY test to $ADDR:$PORT $FAMILY $NS" 79 | 80 | if [[ $NS == "global" ]]; then 81 | CLIENT_PREFIX="ip netns exec $NETNS" 82 | CLIENT_VETH=$VETH1 83 | SERVER_PREFIX="" 84 | SERVER_VETH=$VETH2 85 | else 86 | CLIENT_PREFIX="" 87 | CLIENT_VETH=$VETH2 88 | SERVER_PREFIX="ip netns exec $NETNS" 89 | SERVER_VETH=$VETH1 90 | fi 91 | test_setup true 92 | 93 | $CLIENT_PREFIX ethtool --offload $CLIENT_VETH rx off tx off gso off gro off lro off tso off 94 | $SERVER_PREFIX ethtool --offload $SERVER_VETH rx off tx off gso off gro off lro off tso off 95 | frag_orig=($(sysctl -n $SYSCTL_NAME)) 96 | low_orig=($(sysctl -n ${SYSCTL_PREFIX}low_thresh)) 97 | sysctl -w ${SYSCTL_PREFIX}low_thresh=8192 98 | sysctl -w $SYSCTL_NAME="8192" 99 | 100 | frag_pre=($(sysctl -n $SYSCTL_NAME)) 101 | 102 | # prevent firewall from reassembling packets. 103 | set +e 104 | FIREWALLD_PID=$(pgrep firewalld) 105 | set -e 106 | if [[ -n "$FIREWALLD_PID" ]]; then 107 | service firewalld stop 108 | fi 109 | for MODE in baseline test ; do 110 | 111 | echo "Running ${MODE}..." 112 | if [[ $MODE != "baseline" ]]; then 113 | test_run_cmd_local "$BPFTUNE -s &" true 114 | sleep $SETUPTIME 115 | else 116 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 117 | LOGSZ=$(expr $LOGSZ + 1) 118 | fi 119 | set +e 120 | echo "Running $CLIENT_PREFIX ping -v -c 20 -M t -s 8192 $ADDR" 121 | $CLIENT_PREFIX ping -v -c 20 -M want -s 8192 $ADDR 122 | set -e 123 | 124 | sleep $SLEEPTIME 125 | done 126 | if [[ -n "$FIREWALLD_PID" ]]; then 127 | service firewalld start 128 | fi 129 | frag_post=($(sysctl -n $SYSCTL_NAME)) 130 | if [[ -n $SERVER_PREFIX ]]; then 131 | sysctl -w ${SYSCTL_NAME}=$frag_orig 132 | sysctl -w ${SYSCTL_PREFIX}low_thresh=$low_orig 133 | fi 134 | echo "$SYSCTL_NAME before ${frag_pre}" 135 | echo "$SYSCTL_NAME after ${frag_post}" 136 | if [[ $MODE == "test" ]]; then 137 | if [[ "${frag_post}" -gt ${frag_pre} ]]; then 138 | grep "approaching fragmentation maximum threshold" $LOGFILE 139 | ${BPFTUNE_PROG} -q $QUERY 140 | pkill -TERM bpftune 141 | test_pass 142 | else 143 | pkill -TERM bpftune 144 | test_cleanup 145 | fi 146 | fi 147 | 148 | test_cleanup 149 | done 150 | done 151 | done 152 | 153 | test_exit 154 | -------------------------------------------------------------------------------- /test/rate_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run iperf3 test with low rmem max, ensure sampling was used 23 | # on rcvbuf expand. 24 | 25 | PORT=5201 26 | 27 | . ./test_lib.sh 28 | 29 | SLEEPTIME=1 30 | TIMEOUT=30 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | for CLIENT_OPTS in "" "-R" ; do 35 | case $FAMILY in 36 | ipv4) 37 | ADDR=$VETH1_IPV4 38 | ;; 39 | ipv6) 40 | ADDR=$VETH1_IPV6 41 | ;; 42 | esac 43 | 44 | test_start "$0|rate test to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 45 | 46 | rmem_orig=($(sysctl -n net.ipv4.tcp_rmem)) 47 | 48 | test_setup true 49 | 50 | rmem_orig_netns=($(ip netns exec $NETNS sysctl -n net.ipv4.tcp_rmem)) 51 | 52 | sysctl -w net.ipv4.tcp_rmem="${rmem_orig[0]} ${rmem_orig[1]} ${rmem_orig[1]}" 53 | ip netns exec $NETNS sysctl -w net.ipv4.tcp_rmem="${rmem_orig_netns[0]} ${rmem_orig_netns[1]} ${rmem_orig_netns[1]}" 54 | 55 | declare -A results 56 | for MODE in baseline test ; do 57 | 58 | echo "Running ${MODE}..." 59 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 60 | if [[ $MODE != "baseline" ]]; then 61 | test_run_cmd_local "$BPFTUNE -s &" true 62 | sleep $SETUPTIME 63 | else 64 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 65 | LOGSZ=$(expr $LOGSZ + 1) 66 | fi 67 | test_run_cmd_local "$IPERF3 -fm $CLIENT_OPTS -c $PORT -c $ADDR" true 68 | sleep $SLEEPTIME 69 | done 70 | 71 | pkill -TERM bpftune 72 | rmem_post=($(sysctl -n net.ipv4.tcp_rmem)) 73 | rmem_post_netns=($(ip netns exec $NETNS sysctl -n net.ipv4.tcp_rmem)) 74 | sysctl -w net.ipv4.tcp_rmem="${rmem_orig[0]} ${rmem_orig[1]} ${rmem_orig[2]}" 75 | if [[ $MODE == "test" ]]; then 76 | if [[ "${rmem_post[2]}" -gt ${rmem_orig[1]} ]]; then 77 | echo "rmem before ${rmem_orig[1]} ; after ${rmem_post[2]}" 78 | 79 | if [[ "${rmem_post_netns[2]}" -gt ${rmem_orig_netns[1]} ]]; then 80 | echo "netns rmem before ${rmem_orig_netns[1]} ; after ${rmem_post_netns[2]}" 81 | else 82 | echo "netns rmem before ${rmem_orig_netns[1]} ; after ${rmem_post_netns[2]}" 83 | if [[ ${BPFTUNE_NETNS} -eq 0 ]]; then 84 | echo "bpftune does not support per-netns policy, skipping..." 85 | else 86 | test_cleanup 87 | fi 88 | fi 89 | else 90 | test_cleanup 91 | fi 92 | fi 93 | sleep $SLEEPTIME 94 | 95 | grep "Sample" $TESTLOG_LAST 96 | 97 | test_pass 98 | 99 | test_cleanup 100 | done 101 | done 102 | 103 | test_exit 104 | -------------------------------------------------------------------------------- /test/rollback_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run iperf3 test with low wmem max, ensure tuner increases it but it is 23 | # rolled back on exit. 24 | 25 | PORT=5201 26 | 27 | . ./test_lib.sh 28 | 29 | SLEEPTIME=1 30 | TIMEOUT=30 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | for CLIENT_OPTS in "" ; do 35 | case $FAMILY in 36 | ipv4) 37 | ADDR=$VETH1_IPV4 38 | ;; 39 | ipv6) 40 | ADDR=$VETH1_IPV6 41 | ;; 42 | esac 43 | 44 | test_start "$0|rollback legacy test to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 45 | 46 | wmem_orig=($(sysctl -n net.ipv4.tcp_wmem)) 47 | 48 | test_setup true 49 | 50 | sysctl -w net.ipv4.tcp_wmem="${wmem_orig[0]} ${wmem_orig[1]} ${wmem_orig[1]}" 51 | 52 | declare -A results 53 | for MODE in baseline test ; do 54 | 55 | echo "Running ${MODE}..." 56 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 57 | if [[ $MODE != "baseline" ]]; then 58 | test_run_cmd_local "$BPFTUNE -LR &" 59 | sleep $SETUPTIME 60 | else 61 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 62 | LOGSZ=$(expr $LOGSZ + 1) 63 | fi 64 | test_run_cmd_local "$IPERF3 -fm $CLIENT_OPTS -p $PORT -c $ADDR" true 65 | 66 | sleep $SLEEPTIME 67 | 68 | sresults=$(grep -E "sender" ${CMDLOG} | awk '{print $7}') 69 | rresults=$(grep -E "receiver" ${CMDLOG} | awk '{print $7}') 70 | units=$(grep -E "sender|receiver" ${CMDLOG} | awk '{print $8}' |head -1) 71 | 72 | if [[ $MODE == "baseline" ]]; then 73 | read -r -a sbaseline_results <<< $sresults 74 | read -r -a rbaseline_results <<< $rresults 75 | echo "" > ${CMDLOG} 76 | else 77 | read -r -a stest_results <<< $sresults 78 | read -r -a rtest_results <<< $rresults 79 | pkill -TERM bpftune 80 | sleep $SETUPTIME 81 | fi 82 | sleep $SLEEPTIME 83 | done 84 | 85 | wmem_post=($(sysctl -n net.ipv4.tcp_wmem)) 86 | sysctl -w net.ipv4.tcp_wmem="${wmem_orig[0]} ${wmem_orig[1]} ${wmem_orig[2]}" 87 | if [[ $MODE == "test" ]]; then 88 | if [[ "${wmem_post[2]}" -eq ${wmem_orig[1]} ]]; then 89 | echo "wmem before ${wmem_orig[1]} ; after ${wmem_post[2]}" 90 | else 91 | test_cleanup 92 | fi 93 | fi 94 | printf "Results sender (${units}): " 95 | for (( i=0; i < ${#sbaseline_results[@]}; i++ )) 96 | do 97 | sbase=$(roundup ${sbaseline_results[$i]}) 98 | stest=$(roundup ${stest_results[$i]}) 99 | if [[ ${sbase} -gt ${stest} ]]; then 100 | bold "Warning: baseline (${sbase}) > test (${stest})" 101 | else 102 | echo "baseline (${sbase}) < test (${stest})" 103 | fi 104 | done 105 | printf "Results receiver (${units}): " 106 | for (( i=0; i < ${#rbaseline_results[@]}; i++ )) 107 | do 108 | rbase=$(roundup ${rbaseline_results[$i]}) 109 | rtest=$(roundup ${rtest_results[$i]}) 110 | if [[ ${rbase} -gt ${rtest} ]]; then 111 | bold "Warning: baseline (${rbase}) > test (${rtest})" 112 | else 113 | echo "baseline (${rbase}) < test (${rtest})" 114 | fi 115 | done 116 | 117 | grep "Rolling back" $LOGFILE 118 | 119 | test_pass 120 | 121 | test_cleanup 122 | done 123 | done 124 | 125 | test_exit 126 | -------------------------------------------------------------------------------- /test/rollback_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run iperf3 test with low wmem max, ensure tuner increases it but it is 23 | # rolled back on exit. 24 | 25 | PORT=5201 26 | 27 | . ./test_lib.sh 28 | 29 | SLEEPTIME=1 30 | TIMEOUT=30 31 | 32 | for FAMILY in ipv4 ipv6 ; do 33 | 34 | for CLIENT_OPTS in "" ; do 35 | case $FAMILY in 36 | ipv4) 37 | ADDR=$VETH1_IPV4 38 | ;; 39 | ipv6) 40 | ADDR=$VETH1_IPV6 41 | ;; 42 | esac 43 | 44 | test_start "$0|rollback test to $ADDR:$PORT $FAMILY opts $CLIENT_OPTS $LATENCY" 45 | 46 | wmem_orig=($(sysctl -n net.ipv4.tcp_wmem)) 47 | 48 | test_setup true 49 | 50 | sysctl -w net.ipv4.tcp_wmem="${wmem_orig[0]} ${wmem_orig[1]} ${wmem_orig[1]}" 51 | 52 | declare -A results 53 | for MODE in baseline test ; do 54 | 55 | echo "Running ${MODE}..." 56 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 57 | if [[ $MODE != "baseline" ]]; then 58 | test_run_cmd_local "$BPFTUNE -R &" 59 | sleep $SETUPTIME 60 | else 61 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 62 | LOGSZ=$(expr $LOGSZ + 1) 63 | fi 64 | test_run_cmd_local "$IPERF3 -fm $CLIENT_OPTS -p $PORT -c $ADDR" true 65 | 66 | sleep $SLEEPTIME 67 | 68 | sresults=$(grep -E "sender" ${CMDLOG} | awk '{print $7}') 69 | rresults=$(grep -E "receiver" ${CMDLOG} | awk '{print $7}') 70 | units=$(grep -E "sender|receiver" ${CMDLOG} | awk '{print $8}' |head -1) 71 | 72 | if [[ $MODE == "baseline" ]]; then 73 | read -r -a sbaseline_results <<< $sresults 74 | read -r -a rbaseline_results <<< $rresults 75 | echo "" > ${CMDLOG} 76 | else 77 | read -r -a stest_results <<< $sresults 78 | read -r -a rtest_results <<< $rresults 79 | pkill -TERM bpftune 80 | sleep $SETUPTIME 81 | fi 82 | sleep $SLEEPTIME 83 | done 84 | 85 | wmem_post=($(sysctl -n net.ipv4.tcp_wmem)) 86 | sysctl -w net.ipv4.tcp_wmem="${wmem_orig[0]} ${wmem_orig[1]} ${wmem_orig[2]}" 87 | if [[ $MODE == "test" ]]; then 88 | if [[ "${wmem_post[2]}" -eq ${wmem_orig[1]} ]]; then 89 | echo "wmem before ${wmem_orig[1]} ; after ${wmem_post[2]}" 90 | else 91 | test_cleanup 92 | fi 93 | fi 94 | printf "Results sender (${units}): " 95 | for (( i=0; i < ${#sbaseline_results[@]}; i++ )) 96 | do 97 | sbase=$(roundup ${sbaseline_results[$i]}) 98 | stest=$(roundup ${stest_results[$i]}) 99 | if [[ ${sbase} -gt ${stest} ]]; then 100 | bold "Warning: baseline (${sbase}) > test (${stest})" 101 | else 102 | echo "baseline (${sbase}) < test (${stest})" 103 | fi 104 | done 105 | printf "Results receiver (${units}): " 106 | for (( i=0; i < ${#rbaseline_results[@]}; i++ )) 107 | do 108 | rbase=$(roundup ${rbaseline_results[$i]}) 109 | rtest=$(roundup ${rtest_results[$i]}) 110 | if [[ ${rbase} -gt ${rtest} ]]; then 111 | bold "Warning: baseline (${rbase}) > test (${rtest})" 112 | else 113 | echo "baseline (${rbase}) < test (${rtest})" 114 | fi 115 | done 116 | 117 | grep "Rolling back" $LOGFILE 118 | 119 | test_pass 120 | 121 | test_cleanup 122 | done 123 | done 124 | 125 | test_exit 126 | -------------------------------------------------------------------------------- /test/route_table_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run neigh table test 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=10 29 | 30 | for TUNER in route_table ; do 31 | 32 | 33 | for NS in global $NETNS ; do 34 | for TBL in v6 ; do 35 | 36 | test_start "$0|route table test ($NS netns): does filling $TBL cache make it grow?" 37 | 38 | test_setup "true" 39 | 40 | if [[ $NS != "global" ]]; then 41 | PREFIX_CMD="ip netns exec $NETNS " 42 | OPREFIX_CMD="" 43 | else 44 | PREFIX_CMD="" 45 | OPREFIX_CMD="ip netns exec $NETNS" 46 | fi 47 | 48 | max_size_orig=($($PREFIX_CMD sysctl -n net.ipv6.route.max_size)) 49 | thresh_orig=($($PREFIX_CMD sysctl -n net.ipv6.route.gc_thresh)) 50 | $PREFIX_CMD sysctl -w net.ipv6.route.gc_thresh=16 51 | $PREFIX_CMD sysctl -w net.ipv6.route.max_size=32 52 | max_size_pre=($($PREFIX_CMD sysctl -n net.ipv6.route.max_size)) 53 | 54 | test_run_cmd_local "$BPFTUNE -s &" true 55 | 56 | sleep $SETUPTIME 57 | 58 | for ((i=1; i < 1024; i++ )) 59 | do 60 | $PREFIX_CMD ip link add bpftunelink${i} type dummy 61 | $PREFIX_CMD ip link set bpftunelink${i} up 62 | done 63 | for ((i=1; i < 1024; i++ )) 64 | do 65 | $PREFIX_CMD ip link del bpftunelink${i} 66 | done 67 | # wait for gc... 68 | sleep $SLEEPTIME 69 | sleep $SLEEPTIME 70 | sleep $SLEEPTIME 71 | sleep $SLEEPTIME 72 | max_size_post=($($PREFIX_CMD sysctl -n net.ipv6.route.max_size)) 73 | $PREFIX_CMD sysctl -w net.ipv6.route.max_size="$max_size_orig" 74 | $PREFIX_CMD sysctl -w net.ipv6.route.gc_thresh="$thresh_orig" 75 | grep "change net.ipv6.route.max_size" $LOGFILE 76 | if [[ "$max_size_post" -gt "$max_size_pre" ]]; then 77 | test_pass 78 | fi 79 | test_cleanup 80 | done 81 | done 82 | done 83 | 84 | test_exit 85 | -------------------------------------------------------------------------------- /test/sample_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run sysctl test 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=10 28 | 29 | 30 | test_start "$0|sample legacy test: does sample tuner appear, trigger event and disappear?" 31 | 32 | test_setup "true" 33 | 34 | # dir may not be there yet 35 | mkdir -p /usr/local/lib64/bpftune 36 | rm -f /usr/local/lib64/bpftune/sample_tuner.so 37 | sleep 1 38 | test_run_cmd_local "$BPFTUNE -dsL &" true 39 | sleep $SETUPTIME 40 | cd ../sample_tuner ; make clean; make install 41 | sleep $SLEEPTIME 42 | # trigger event 43 | sysctl kernel.core_pattern 44 | sleep $SLEEPTIME 45 | grep -E "event .* for tuner sample" $TESTLOG_LAST 46 | # remove tuner 47 | rm /usr/local/lib64/bpftune/sample_tuner.so 48 | sleep $SLEEPTIME 49 | grep "fini tuner sample" $TESTLOG_LAST 50 | test_pass 51 | test_cleanup 52 | test_exit 53 | -------------------------------------------------------------------------------- /test/sample_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run sysctl test 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=10 28 | 29 | 30 | test_start "$0|sample test: does sample tuner appear, trigger event and disappear?" 31 | 32 | test_setup "true" 33 | 34 | # dir may not be there yet 35 | mkdir -p /usr/local/lib64/bpftune 36 | rm -f /usr/local/lib64/bpftune/sample_tuner.so 37 | sleep 1 38 | test_run_cmd_local "$BPFTUNE -ds &" true 39 | sleep $SETUPTIME 40 | cd ../sample_tuner ; make clean; make install 41 | sleep $SLEEPTIME 42 | # trigger event 43 | sysctl kernel.core_pattern 44 | sleep $SLEEPTIME 45 | grep -E "event .* for tuner sample" $TESTLOG_LAST 46 | # remove tuner 47 | rm /usr/local/lib64/bpftune/sample_tuner.so 48 | sleep $SLEEPTIME 49 | grep "fini tuner sample" $TESTLOG_LAST 50 | test_pass 51 | test_cleanup 52 | test_exit 53 | -------------------------------------------------------------------------------- /test/service_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run service test 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=1 28 | 29 | 30 | LOGFILE=$SYSLOGFILE 31 | 32 | test_start "$0|service test: does enabling the service work?" 33 | 34 | test_setup "true" 35 | 36 | test_run_cmd_local "service bpftune start" true 37 | 38 | sleep $SETUPTIME 39 | grep "bpftune works" $LOGFILE 40 | oldpid=$(pgrep bpftune) 41 | 42 | test_pass 43 | 44 | test_start "$0|service test: does restarting the service work?" 45 | 46 | test_run_cmd_local "service bpftune restart" 47 | 48 | sleep $SETUPTIME 49 | newpid=$(pgrep bpftune) 50 | 51 | if [[ "$newpid" -ne "$oldpid" ]]; then 52 | test_pass 53 | else 54 | test_cleanup 55 | fi 56 | 57 | test_start "$0|service test: does stopping the service work?" 58 | test_run_cmd_local "service bpftune stop" true 59 | sleep $SETUPTIME 60 | 61 | set +e 62 | gonepid=$(pgrep bpftune) 63 | set -e 64 | 65 | if [[ -n "$gonepid" ]]; then 66 | echo "bpftune still running: $gonepid" 67 | test_cleanup 68 | else 69 | test_pass 70 | fi 71 | 72 | test_start "$0|service test: does enabling the service work?" 73 | test_run_cmd_local "systemctl enable bpftune" 74 | sleep $SETUPTIME 75 | test_pass 76 | 77 | test_start "$0|service test: does disabling the service work?" 78 | test_run_cmd_local "systemctl disable bpftune" 79 | sleep $SETUPTIME 80 | test_pass 81 | 82 | test_cleanup 83 | 84 | test_exit 85 | -------------------------------------------------------------------------------- /test/strategy/README.md: -------------------------------------------------------------------------------- 1 | # strategy tuner 2 | 3 | simple example showing Makefile and bpf/userspace portions of a 4 | tuner shared object that implements multiple strategies, switching 5 | between them. 6 | -------------------------------------------------------------------------------- /test/strategy/strategy_tuner.bpf.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | 22 | /* fire when coredump sysctls are read */ 23 | /* strategy A uses this BPF prog. */ 24 | BPF_FENTRY(proc_dostring_coredump, struct ctl_table *table, int write, 25 | void *buffer, size_t *lenp, loff_t *ppos) 26 | { 27 | struct bpftune_event event = {}; 28 | int ret, scenario_id = 0; 29 | 30 | /* tuner id is a global declared in bpftune.bpf.h and set by bfttune 31 | * when the tuner is added. 32 | */ 33 | event.tuner_id = tuner_id; 34 | event.scenario_id = scenario_id; 35 | ret = bpf_ringbuf_output(&ring_buffer_map, &event, sizeof(event), 0); 36 | bpftune_debug("tuner [%d] scenario [%d]: event send: %d ", 37 | tuner_id, scenario_id, ret); 38 | return 0; 39 | } 40 | 41 | /* strategy B uses this BPF prog. */ 42 | BPF_FENTRY(proc_dostring, struct ctl_table *table, int write, 43 | void *buffer, size_t *lenp, loff_t *ppos) 44 | { 45 | struct bpftune_event event = {}; 46 | int ret, scenario_id = 0; 47 | 48 | /* tuner id is a global declared in bpftune.bpf.h and set by bfttune 49 | * when the tuner is added. 50 | */ 51 | event.tuner_id = tuner_id; 52 | event.scenario_id = scenario_id; 53 | ret = bpf_ringbuf_output(&ring_buffer_map, &event, sizeof(event), 0); 54 | bpftune_debug("tuner [%d] scenario [%d]: event send: %d ", 55 | tuner_id, scenario_id, ret); 56 | return 0; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /test/strategy/strategy_tuner.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2023, Oracle and/or its affiliates. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public 7 | * License v2 as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public 15 | * License along with this program; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 021110-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include "strategy_tuner.skel.h" 23 | #include "strategy_tuner.skel.legacy.h" 24 | #include "strategy_tuner.skel.nobtf.h" 25 | 26 | static long double evaluate_A(struct bpftuner *tuner, struct bpftuner_strategy *strategy) 27 | { 28 | if (tuner->strategy == strategy) 29 | return (long double)0; 30 | else 31 | return (long double)1; 32 | } 33 | 34 | const char *progs_A[] = { "entry__proc_dostring_coredump", NULL }; 35 | 36 | struct bpftuner_strategy strategy_A = { 37 | .name = "strategy_A", 38 | .description = "first strategy", 39 | .evaluate = evaluate_A, 40 | .timeout = 30, 41 | .bpf_progs = progs_A, 42 | }; 43 | 44 | static long double evaluate_B(struct bpftuner *tuner, struct bpftuner_strategy *strategy) 45 | { 46 | if (tuner->strategy == strategy) 47 | return (long double)0; 48 | else 49 | return (long double)1; 50 | } 51 | 52 | const char *progs_B[] = { "entry__proc_dostring", NULL }; 53 | 54 | struct bpftuner_strategy strategy_B = { 55 | .name = "strategy_B", 56 | .description = "second strategy", 57 | .evaluate = evaluate_B, 58 | .timeout = 30, 59 | .bpf_progs = progs_B, 60 | }; 61 | 62 | struct bpftuner_strategy *strategies[] = { &strategy_A, &strategy_B, NULL }; 63 | 64 | int init(struct bpftuner *tuner) 65 | { 66 | int err = bpftuner_strategies_add(tuner, strategies, &strategy_A); 67 | 68 | if (err) 69 | return err; 70 | return bpftuner_bpf_init(strategy, tuner, NULL); 71 | } 72 | 73 | void fini(struct bpftuner *tuner) 74 | { 75 | bpftuner_bpf_fini(tuner); 76 | } 77 | 78 | void event_handler(struct bpftuner *tuner, struct bpftune_event *event, 79 | __attribute__((unused))void *ctx) 80 | { 81 | bpftune_log(LOG_DEBUG, "event (scenario %d) for tuner %s, strategy %s\n", 82 | event->scenario_id, tuner->name, tuner->strategy->name); 83 | } 84 | -------------------------------------------------------------------------------- /test/strategy_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run sysctl test 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=10 28 | 29 | 30 | test_start "$0|strategy legacy test: does strategy tuner appear, trigger event and change strategies?" 31 | 32 | test_setup "true" 33 | 34 | sleep 1 35 | test_run_cmd_local "$BPFTUNE -dsLl ./strategy &" true 36 | sleep $SETUPTIME 37 | # trigger event 38 | sysctl kernel.core_pattern 39 | sleep $SLEEPTIME 40 | grep -E "event .* for tuner strategy, strategy strategy_A" $TESTLOG_LAST 41 | sleep 30 42 | # trigger event 43 | sysctl kernel.core_pattern 44 | sleep $SLEEPTIME 45 | grep -E "event .* for tuner strategy, strategy strategy_B" $TESTLOG_LAST 46 | test_pass 47 | test_cleanup 48 | test_exit 49 | -------------------------------------------------------------------------------- /test/strategy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run sysctl test 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=10 28 | 29 | 30 | test_start "$0|strategy test: does strategy tuner appear, trigger event and change strategies?" 31 | 32 | test_setup "true" 33 | 34 | sleep 1 35 | test_run_cmd_local "$BPFTUNE -dsl ./strategy &" true 36 | sleep $SETUPTIME 37 | # trigger event 38 | sysctl kernel.core_pattern 39 | sleep $SLEEPTIME 40 | grep -E "event .* for tuner strategy, strategy strategy_A" $TESTLOG_LAST 41 | sleep 30 42 | # trigger event 43 | sysctl kernel.core_pattern 44 | sleep $SLEEPTIME 45 | grep -E "event .* for tuner strategy, strategy strategy_B" $TESTLOG_LAST 46 | test_pass 47 | test_cleanup 48 | test_exit 49 | -------------------------------------------------------------------------------- /test/stress_ng_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run socket stress-ng test in baseline/test to compare differences 23 | # in ops/sec 24 | 25 | . ./test_lib.sh 26 | 27 | LOGFILE=$TESTLOG_LAST 28 | 29 | SLEEPTIME=1 30 | TIMEOUT=30 31 | MAX_CONN=500 32 | 33 | for SOCKS in 10 $MAX_CONN ; do 34 | test_start "$0|stress-ng test, $SOCKS sockets" 35 | 36 | test_setup true 37 | 38 | set +e 39 | FIREWALLD_PID=$(pgrep firewalld) 40 | set -e 41 | if [[ -n "$FIREWALLD_PID" ]]; then 42 | service firewalld stop 43 | fi 44 | for MODE in baseline test ; do 45 | 46 | echo "Running ${MODE}..." 47 | if [[ $MODE != "baseline" ]]; then 48 | test_run_cmd_local "$BPFTUNE -sR &" true 49 | sleep $SETUPTIME 50 | fi 51 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 52 | LOGSZ=$(expr $LOGSZ + 1) 53 | export TIMEOUT=60 54 | test_run_cmd_local "stress-ng -S $SOCKS --metrics -t 30" true 55 | export TIMEOUT=30 56 | tail -n +${LOGSZ} $LOGFILE | grep stress-ng 57 | if [[ $MODE != "baseline" ]]; then 58 | $BPFTUNE_PROG -q summary 59 | pkill -TERM bpftune 60 | sleep $SETUPTIME 61 | fi 62 | done 63 | if [[ -n "$FIREWALLD_PID" ]]; then 64 | service firewalld start 65 | fi 66 | test_pass 67 | test_cleanup 68 | done 69 | 70 | test_exit 71 | -------------------------------------------------------------------------------- /test/support_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run sysctl test 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=1 28 | 29 | test_start "$0|support test: does 'bpftune -S' show support level?" 30 | 31 | ARCH=$(uname -m) 32 | 33 | expected="bpftune is not supported" 34 | expected_netns="does not support per-netns policy" 35 | 36 | if [[ $MAJ_KVER -gt 4 ]]; then 37 | if [[ "$MIN_KVER" -gt 3 ]]; then 38 | expected="bpftune works in legacy mode" 39 | fi 40 | case $MAJ_KVER in 41 | 2|3|4) 42 | ;; 43 | 5) 44 | if [[ $MIN_KVER -gt 14 ]]; then 45 | expected_netns="supports per-netns policy" 46 | if [[ "$ARCH" == "x86_64" ]]; then 47 | expected="bpftune works fully" 48 | fi 49 | fi 50 | ;; 51 | 6) 52 | expected_netns="supports per-netns policy" 53 | if [[ "$ARCH" == "x86_64" ]]; then 54 | expected="bpftune works fully" 55 | elif [[ $MIN_KVER -gt 4 ]]; then 56 | expected="bpftune works fully" 57 | fi 58 | ;; 59 | *) 60 | expected_netns="supports per-netns policy" 61 | if [[ "$ARCH" == "x86_64" ]]; then 62 | expected="bpftune works fully" 63 | fi 64 | ;; 65 | esac 66 | fi 67 | 68 | SUPPORT=$($BPFTUNE_PROG -S 2>&1) 69 | 70 | if [[ "$SUPPORT" =~ $expected ]]; then 71 | if [[ "$SUPPORT" =~ $expected_netns ]]; then 72 | test_pass 73 | fi 74 | fi 75 | 76 | test_cleanup 77 | test_exit 78 | -------------------------------------------------------------------------------- /test/syn_flood_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # check performance under syn flood 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=1 29 | TIMEOUT=30 30 | MAX_CONN=50 31 | 32 | for NS in nonglobal global ; do 33 | for FAMILY in ipv4 ; do 34 | 35 | case $FAMILY in 36 | ipv4) 37 | if [[ $NS == "global" ]]; then 38 | ADDR=$VETH2_IPV4 39 | else 40 | ADDR=$VETH1_IPV4 41 | fi 42 | DUMMY_SERVER=192.168.200.3 43 | DUMMY_CLIENT=192.168.200.4 44 | WGET_ARG="" 45 | WGET_ADDR=$ADDR 46 | HTTP_BIND_ADDR="" 47 | ;; 48 | ipv6) 49 | pyversion=$(python3 --version | awk -F '.' '{ print $2 }') 50 | # http.server supports IPv6 for 3.8 and later. 51 | if [[ $pyversion -lt 8 ]]; then 52 | echo "IPv6 test needs python 3.8 or later, skipping" 53 | continue 54 | fi 55 | if [[ $NS == "global" ]]; then 56 | ADDR=$VETH2_IPV6 57 | else 58 | ADDR=$VETH1_IPV6 59 | fi 60 | DUMMY_SERVER=fe::1 61 | DUMMY_CLIENT=fe::2 62 | WGET_ARG="-6" 63 | WGET_ADDR="[${ADDR}]" 64 | HTTP_BIND_ADDR="--bind $ADDR" 65 | ;; 66 | esac 67 | 68 | test_start "$0|syn flood test to $ADDR:$PORT $FAMILY $NS " 69 | 70 | if [[ $NS == "global" ]]; then 71 | CLIENT_PREFIX="ip netns exec $NETNS" 72 | CLIENT_VETH=$VETH1 73 | export SERVER_PREFIX="" 74 | SERVER_VETH=$VETH2 75 | else 76 | CLIENT_PREFIX="" 77 | CLIENT_VETH=$VETH2 78 | export SERVER_PREFIX="ip netns exec $NETNS" 79 | SERVER_VETH=$VETH1 80 | fi 81 | test_setup true 82 | syn_backlog_pre=256 83 | $SERVER_PREFIX sysctl -w net.ipv4.tcp_max_syn_backlog=$syn_backlog_pre 84 | $SERVER_PREFIX sysctl -w net.ipv4.tcp_syncookies=0 85 | 86 | mkdir -p $SERVERDIR 87 | 88 | set +e 89 | FIREWALLD_PID=$(pgrep firewalld) 90 | set -e 91 | if [[ -n "$FIREWALLD_PID" ]]; then 92 | service firewalld stop 93 | fi 94 | pushd $SERVERDIR 95 | test_run_cmd_local "$SERVER_PREFIX python3 -m http.server $PORT &" true 96 | popd 97 | sleep $SLEEPTIME 98 | 99 | set +e 100 | $SERVER_PREFIX ip link add dummyserver type dummy 101 | $SERVER_PREFIX ip addr add ${DUMMY_SERVER}/24 dev dummyserver 102 | $SERVER_PREFIX ip link set dummyserver up 103 | $SERVER_PREFIX ip link set dummyserver arp on 104 | $SERVER_PREFIX ip link set lo up 105 | set -e 106 | 107 | for MODE in baseline test ; do 108 | 109 | echo "Running ${MODE}..." 110 | if [[ $MODE != "baseline" ]]; then 111 | test_run_cmd_local "$BPFTUNE -s &" true 112 | sleep $SETUPTIME 113 | else 114 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 115 | LOGSZ=$(expr $LOGSZ + 1) 116 | fi 117 | set +e 118 | $SERVER_PREFIX $HPING -a $DUMMY_CLIENT -S -i u1 -c 1000000 -S -p $PORT $DUMMY_SERVER 119 | set -e 120 | if [[ $MODE != "baseline" ]]; then 121 | pkill -TERM bpftune 122 | sleep $SETUPTIME 123 | tail -n +${LOGSZ} $LOGFILE 124 | else 125 | sleep $SLEEPTIME 126 | fi 127 | done 128 | if [[ -n "$FIREWALLD_PID" ]]; then 129 | service firewalld start 130 | fi 131 | $SERVER_PREFIX ip link del dummyserver 132 | 133 | syn_backlog_post=$($SERVER_PREFIX sysctl -n net.ipv4.tcp_max_syn_backlog) 134 | if [[ $syn_backlog_post -ge $syn_backlog_pre ]]; then 135 | echo "net.ipv4.tcp_max_syn_backlog unexpectedly increased to $syn_backlog_post" 136 | else 137 | test_pass 138 | fi 139 | test_cleanup 140 | done 141 | done 142 | 143 | test_exit 144 | -------------------------------------------------------------------------------- /test/sysctl_legacy_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run sysctl test 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=10 28 | 29 | for TUNER in neigh_table ; do 30 | 31 | test_start "$0|sysctl legacy test: does setting sysctl switch off tuner?" 32 | 33 | test_setup "true" 34 | 35 | test_run_cmd_local "$BPFTUNE -sL &" true 36 | 37 | sleep $SETUPTIME 38 | for SYSCTL in net.ipv4.neigh.default.gc_thresh1 kernel.core_pattern ; do 39 | val="$(sysctl -qn $SYSCTL)" 40 | sysctl -qw ${SYSCTL}="${val}" 41 | done 42 | sleep $SLEEPTIME 43 | grep "modified sysctl" $TESTLOG_LAST 44 | test_pass 45 | 46 | test_cleanup 47 | done 48 | 49 | test_exit 50 | -------------------------------------------------------------------------------- /test/sysctl_netns_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run sysctl test 23 | 24 | PORT=5201 25 | 26 | . ./test_lib.sh 27 | 28 | SLEEPTIME=5 29 | TIMEOUT=30 30 | 31 | for TUNER in neigh_table ; do 32 | 33 | test_start "$0|sysctl test: does setting sysctl switch off tuner in netns only?" 34 | 35 | rmem_orig=($(sysctl -n net.ipv4.tcp_rmem)) 36 | 37 | sysctl -qw net.ipv4.tcp_rmem="${rmem_orig[0]} ${rmem_orig[1]} ${rmem_orig[1]}" 38 | 39 | test_run_cmd_local "$BPFTUNE -ds &" true 40 | 41 | sleep $SETUPTIME 42 | 43 | # need to setup netns after bpftune starts... 44 | test_setup "true" 45 | 46 | if [[ ${BPFTUNE_NETNS} -eq 0 ]]; then 47 | echo "bpftune does not support per-netns policy, skipping..." 48 | test_pass 49 | fi 50 | 51 | rmem_orig_netns=($(ip netns exec $NETNS sysctl -n net.ipv4.tcp_rmem)) 52 | 53 | for SYSCTL in kernel.core_pattern net.ipv4.tcp_rmem ; do 54 | val=$(ip netns exec $NETNS sysctl -qn $SYSCTL) 55 | ip netns exec $NETNS sysctl -qw ${SYSCTL}="${val}" 56 | done 57 | sleep $SLEEPTIME 58 | grep "modified sysctl" $TESTLOG_LAST 59 | grep "setting state of netns" $TESTLOG_LAST 60 | 61 | ADDR=$VETH1_IPV4 62 | 63 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 64 | sleep $SLEEPTIME 65 | test_run_cmd_local "$IPERF3 -fm -p $PORT -c $ADDR" true 66 | sleep $SLEEPTIME 67 | 68 | rmem_post=($(sysctl -n net.ipv4.tcp_rmem)) 69 | rmem_post_netns=($(ip netns exec $NETNS sysctl -n net.ipv4.tcp_rmem)) 70 | if [[ "${rmem_post[2]}" -gt ${rmem_orig[1]} ]]; then 71 | echo "rmem before ${rmem_orig[1]} ; after ${rmem_post[2]}" 72 | echo "netns rmem before ${rmem_orig_netns[2]} ; after ${rmem_post_netns[2]}" 73 | if [[ "${rmem_post_netns[2]}" -gt ${rmem_orig_netns[2]} ]]; then 74 | test_cleanup 75 | fi 76 | else 77 | test_cleanup 78 | fi 79 | 80 | test_pass 81 | 82 | test_cleanup 83 | done 84 | 85 | test_exit 86 | -------------------------------------------------------------------------------- /test/sysctl_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | # run sysctl test 23 | 24 | . ./test_lib.sh 25 | 26 | 27 | SLEEPTIME=10 28 | 29 | for TUNER in neigh_table ; do 30 | 31 | test_start "$0|sysctl test: does setting sysctl switch off tuner?" 32 | 33 | test_setup "true" 34 | 35 | test_run_cmd_local "$BPFTUNE -s &" true 36 | 37 | sleep $SETUPTIME 38 | for SYSCTL in net.ipv4.neigh.default.gc_thresh1 kernel.core_pattern ; do 39 | val="$(sysctl -qn $SYSCTL)" 40 | sysctl -qw ${SYSCTL}="${val}" 41 | done 42 | sleep $SLEEPTIME 43 | grep "modified sysctl" $TESTLOG_LAST 44 | test_pass 45 | 46 | test_cleanup 47 | done 48 | 49 | test_exit 50 | -------------------------------------------------------------------------------- /test/udp_mem_exhaust_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # 3 | # SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 4 | # 5 | # Copyright (c) 2023, Oracle and/or its affiliates. 6 | # 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU General Public 9 | # License v2 as published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public 17 | # License along with this program; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 021110-1307, USA. 20 | # 21 | 22 | PORT=5201 23 | 24 | . ./test_lib.sh 25 | 26 | LOGFILE=$TESTLOG_LAST 27 | 28 | SLEEPTIME=5 29 | TIMEOUT=30 30 | MAX_CONN=10 31 | 32 | # udp_fail_queue_rcv_skb tracepoint IPv6 support only on 6.4+ kernels. 33 | FAMILIES="ipv4" 34 | if [[ $MAJ_KVER -ge 6 ]]; then 35 | if [[ $MIN_KVER -ge 4 ]]; then 36 | FAMILIES="$FAMILIES ipv6" 37 | fi 38 | fi 39 | 40 | for FAMILY in $FAMILIES ; do 41 | 42 | case $FAMILY in 43 | ipv4) 44 | ADDR=$VETH1_IPV4 45 | ;; 46 | ipv6) 47 | ADDR=$VETH1_IPV6 48 | ;; 49 | esac 50 | 51 | test_start "$0|udp mem test to $ADDR:$PORT $FAMILY $MAX_CONN conn" 52 | 53 | rmem_default_orig=$(sysctl -n net.core.rmem_default) 54 | sysctl -w net.core.rmem_default=8192 55 | mem_orig=($(sysctl -n net.ipv4.udp_mem)) 56 | 57 | mem_test=($(echo 10 20 20)) 58 | 59 | sysctl -w net.ipv4.udp_mem="${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 60 | 61 | test_setup true 62 | 63 | declare -A results 64 | for MODE in baseline test ; do 65 | 66 | echo "Running ${MODE}..." 67 | test_run_cmd_local "ip netns exec $NETNS $IPERF3 -s -p $PORT -1 &" 68 | if [[ $MODE != "baseline" ]]; then 69 | test_run_cmd_local "$BPFTUNE -a udp_buffer_tuner.so -s &" true 70 | sleep $SETUPTIME 71 | else 72 | LOGSZ=$(wc -l $LOGFILE | awk '{print $1}') 73 | fi 74 | set +e 75 | $IPERF3 -u -b100m -fm -P $MAX_CONN -p $PORT -c $ADDR 76 | set -e 77 | 78 | sleep $SLEEPTIME 79 | done 80 | 81 | mem_post=($(sysctl -n net.ipv4.udp_mem)) 82 | sysctl -w net.ipv4.udp_mem="${mem_orig[0]} ${mem_orig[1]} ${mem_orig[2]}" 83 | sysctl -w net.core.rmem_default=${rmem_default_orig} 84 | echo "mem before ${mem_test[0]} ${mem_test[1]} ${mem_test[2]}" 85 | echo "mem after ${mem_post[0]} ${mem_post[1]} ${mem_post[2]}" 86 | if [[ $MODE == "test" ]]; then 87 | echo "Following changes were made:" 88 | set +e 89 | grep bpftune $LOGFILE 90 | set -e 91 | if [[ "${mem_post[2]}" -gt ${mem_test[2]} ]]; then 92 | test_pass 93 | else 94 | test_cleanup 95 | fi 96 | fi 97 | 98 | test_cleanup 99 | done 100 | 101 | test_exit 102 | --------------------------------------------------------------------------------