Skip to content

Commit

Permalink
tests: updates to iperf
Browse files Browse the repository at this point in the history
  • Loading branch information
choppsv1 committed Oct 2, 2023
1 parent 6a3bebd commit c23f223
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 29 deletions.
98 changes: 98 additions & 0 deletions scripts/plot-iperf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python3
# -*- coding: utf-8 eval: (blacken-mode 1) -*-
#
# October 2 2023, Christian Hopps <[email protected]>
#
# Copyright (c) 2023, LabN Consulting, L.L.C.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; see the file COPYING; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#

import argparse
import logging
import os
import re
import subprocess
import sys

# matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
import numpy as np

# import matplotlib


def do_run(datafile, ax):

F_MODE = 0
F_CONFIG = 1
F_PKTSIZE = 2 # pylint: disable=W0612
F_RATE = 3
F_RETRANS = 4
F_HUMAN_RATE = 5

filedata = open(datafile, encoding="utf-8").read().splitlines()
filedata = [x.split(",") for x in filedata if x.strip()]

data = {}
for x in filedata:
if x[1] not in data:
data[x[1]] = {}
d = data[x[1]]
if x[0] not in d:
d[x[0]] = []
l = d[x[0]]
l.append(x[2:5])

for i, config in enumerate(["encap4-ipv4", "encap6-ipv6"]):
d = data[config]
for j, mode in enumerate(["iptfs-policy", "tunnel-policy"]):
l = d[mode]
x = [e[0] for e in l]
y = [float(e[1]) for e in l]
ax[i].plot(x, y, label=mode)
ax[i].set_title(config)
ax[i].legend()

breakpoint()


def main(*margs):
parser = argparse.ArgumentParser()
parser.add_argument("data", help="plot data")
parser.add_argument("--output", help="save to a file")
parser.add_argument("--verbose", action="store_true", help="rate to plot")
args = parser.parse_args(*margs)

# figsize is in inches.
# fig, axs = plt.subplots(nrows=len(args.plots) // 2, ncols=1)
_, axs = plt.subplots(figsize=(16 * 3 / 2, 9 * 3 / 2), nrows=2, ncols=1)
# fig = plt.figure(figsize=(16, 9))
do_run(args.data, axs)

# fig.tight_layout()
# plt.ylabel("Count")
# plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)
if args.output:
plt.savefig(args.output, dpi=300)
else:
plt.show()


if __name__ == "__main__":
try:
main()
except Exception as ex:
logging.error("Exception from main: %s", ex, exc_info=True)
5 changes: 3 additions & 2 deletions tests/iperf/iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ async def _test_iperf(
pytest.skip("Can't run IPv6 iperf with MSS < 536")
return

mds = "iptfs " if mode == "iptfs" else "tunnel"
r1.cmd_nostatus(
f"echo test start: routed={routed} v6tun={tun_ipv6} v6={ipv6} pktsize={pktsize} opts={iptfs_opts} > /dev/kmsg"
f"echo test start: mode={mds} routed={routed} v6tun={tun_ipv6} v6={ipv6} pktsize={pktsize} opts={iptfs_opts} > /dev/kmsg"
)
r2.cmd_nostatus(
f"echo test start: routed={routed} v6tun={tun_ipv6} v6={ipv6} pktsize={pktsize} opts={iptfs_opts} > /dev/kmsg"
f"echo test start: mode={mds} routed={routed} v6tun={tun_ipv6} v6={ipv6} pktsize={pktsize} opts={iptfs_opts} > /dev/kmsg"
)

await cleanup_config(unet, ipv4=True, ipv6=True)
Expand Down
2 changes: 2 additions & 0 deletions tests/iperf/munet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ topology:
connections:
- to: mgmt0
- to: net2

# watch -n1 "egrep 'kmemleak_obj|skbuff_(ext|head)' /proc/slabinfo"
21 changes: 10 additions & 11 deletions tests/iperf/test_iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ async def _unet(rundir_module, pytestconfig):
# 10.0.0.0/24 10.0.1.0/24 10.0.2.0/24


@pytest.mark.parametrize("mode", ["iptfs", "tunnel"])
@pytest.mark.parametrize("mode", ["iptfs"]) # ["iptfs", "tunnel"])
@pytest.mark.parametrize("iptfs_opts", [None])
@pytest.mark.parametrize("pktsize", [None, 88, 256, 536, 1442])
@pytest.mark.parametrize(
"pktsize", [88, 128, 256, 384, 536, 768, 1024, 1442, 1500, None]
)
@pytest.mark.parametrize("inner", ["ipv4", "ipv6"])
@pytest.mark.parametrize("encap", ["encap4", "encap6"])
@pytest.mark.parametrize("routed", ["policy", "routed"])
Expand All @@ -64,11 +66,9 @@ async def test_iperf(
iptfs_opts = ""
ipv6 = inner == "ipv6"
tun_ipv6 = encap == "encap6"
routed = routed == "routed"

if skip_future:
pytest.skip("Skipping test due to earlier failure")

if (not ipv6) != (not tun_ipv6):
pytest.skip("Skipping std ipsec test with mixed modes")
if mode == "tunnel" and ((not ipv6) != (not tun_ipv6)):
pytest.skip("Skipping std ipsec test with mixed modes")

Expand All @@ -86,7 +86,7 @@ async def test_iperf(
use_iperf3=use_iperf3,
iptfs_opts=iptfs_opts,
pktsize=pktsize,
routed=routed,
routed=routed == "routed",
ipv6=ipv6,
tun_ipv6=tun_ipv6,
profile=pytestconfig.getoption("--profile", False),
Expand All @@ -97,13 +97,12 @@ async def test_iperf(
assert result, "No result from test!"

rundir = str(unet.rundir)
fname = rundir[: rundir.rindex("/")] + "/speed.csv"
fname = rundir[: rundir.rindex("/")] + "/speed-phy.csv"
fmode = "w+" if test_iperf.count == 0 else "a+"
tunstr = "routed" if routed else "policy"
vstr = "IPv6" if tun_ipv6 else "IPv4"
pktsize = pktsize if pktsize is not None else "any"
with open(fname, fmode, encoding="ascii") as f:
print(
f"{result[2]}{result[3]}bits/s,{result[1]},{result[0]},{pktsize},{tunstr},{vstr},{iptfs_opts}",
f"{mode}-{routed},{encap}-{inner},{pktsize},{result[0]},{result[1]},{result[2]}{result[3]}bits/s",
file=f,
)

Expand Down
12 changes: 6 additions & 6 deletions tests/iperf/test_iperf_phy.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def _unet(rundir_module, pytestconfig):

@pytest.mark.parametrize("mode", ["iptfs", "tunnel"])
@pytest.mark.parametrize("iptfs_opts", [None])
@pytest.mark.parametrize("pktsize", [None, 88, 256, 536, 1442])
@pytest.mark.parametrize("pktsize", [None, 1442, 546, 88])
@pytest.mark.parametrize("inner", ["ipv4", "ipv6"])
@pytest.mark.parametrize("encap", ["encap4", "encap6"])
@pytest.mark.parametrize("routed", ["policy", "routed"])
Expand All @@ -93,11 +93,12 @@ async def test_iperf(
iptfs_opts = ""
ipv6 = inner == "ipv6"
tun_ipv6 = encap == "encap6"
routed = routed == "routed"

if skip_future:
pytest.skip("Skipping test due to earlier failure")

if (not ipv6) != (not tun_ipv6):
pytest.skip("Skipping mixed modes")
if mode == "tunnel" and ((not ipv6) != (not tun_ipv6)):
pytest.skip("Skipping std ipsec test with mixed modes")

Expand All @@ -116,7 +117,7 @@ async def test_iperf(
use_udp=False,
iptfs_opts=iptfs_opts,
pktsize=pktsize,
routed=routed,
routed=routed == "routed",
ipv6=ipv6,
tun_ipv6=tun_ipv6,
profile=pytestconfig.getoption("--profile", False),
Expand All @@ -129,11 +130,10 @@ async def test_iperf(
rundir = str(unet.rundir)
fname = rundir[: rundir.rindex("/")] + "/speed-phy.csv"
fmode = "w+" if test_iperf.count == 0 else "a+"
tunstr = "routed" if routed else "policy"
vstr = "IPv6" if tun_ipv6 else "IPv4"
pktsize = pktsize if pktsize is not None else "any"
with open(fname, fmode, encoding="ascii") as f:
print(
f"{result[2]}{result[3]}bits/s,{result[1]},{result[0]},{pktsize},{tunstr},{vstr},{iptfs_opts}",
f"{mode}-{routed},{encap}-{inner},{pktsize},{result[0]},{result[1]},{result[2]}{result[3]}bits/s",
file=f,
)

Expand Down
29 changes: 20 additions & 9 deletions tests/kinds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ kinds:
#cmdline-extra: "acpi=off idle=poll nokaslr"
#cmdline-extra: "idle=poll nokaslr trace_buf_size=1024M"
cmdline-extra: "idle=poll nokaslr"
#memory: "2048"
memory: "2048"
kvm: true
ncpu: 1
console:
timeout: 180

- name: slinux1
merge: [ "qemu" ]
gdb-cmd: "/usr/bin/sudo -E gdb %CONFIGDIR%/../../output-linux/vmlinux"
gdb-target-cmds: ["target remote %RUNDIR%/s/gdbserver"]
gdb-run-cmds: ["c"]
gdb-run-cmd: ["c"]
qemu:
kernel: "%CONFIGDIR%/../../output-linux/arch/x86/boot/bzImage"
initrd: "%CONFIGDIR%/../../output-buildroot/images/rootfs.cpio.gz"
sshkey: "%CONFIGDIR%/../../root-key"
cmdline-extra: "idle=poll nokaslr"
memory: "1024"
kvm: true
ncpu: 1
console:
timeout: 180

- name: linux1
merge: [ "qemu" ]
gdb-cmd: "/usr/bin/sudo -E gdb %CONFIGDIR%/../../output-linux/vmlinux"
Expand All @@ -29,11 +45,8 @@ kinds:
kernel: "%CONFIGDIR%/../../output-linux/arch/x86/boot/bzImage"
initrd: "%CONFIGDIR%/../../output-buildroot/images/rootfs.cpio.gz"
sshkey: "%CONFIGDIR%/../../root-key"
#cmdline-extra: "acpi=off idle=poll nokaslr"
#cmdline-extra: "idle=poll nokaslr trace_buf_size=1024M"
cmdline-extra: "idle=poll nokaslr"
#memory: "2048"
memory: "2048"
memory: "4096"
kvm: true
ncpu: 1
console:
Expand All @@ -52,8 +65,7 @@ kinds:
#cmdline-extra: "acpi=off idle=poll nokaslr"
#cmdline-extra: "idle=poll nokaslr trace_buf_size=1024M"
cmdline-extra: "idle=poll nokaslr"
#memory: "2048"
memory: "4096"
memory: "8192"
kvm: true
ncpu: 2
console:
Expand All @@ -72,8 +84,7 @@ kinds:
#cmdline-extra: "acpi=off idle=poll nokaslr"
#cmdline-extra: "idle=poll nokaslr trace_buf_size=1024M"
cmdline-extra: "idle=poll nokaslr"
#memory: "2048"
memory: "6144"
memory: "12288"
kvm: true
ncpu: 3
console:
Expand Down
2 changes: 1 addition & 1 deletion tests/utpkt/test_utpkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ async def test_small_pkt_agg(unet, astepf, ipv6):
@pytest.mark.parametrize("ipv6", [False, True])
async def test_recv_runt(unet, astepf, ipv6, tun_ipv6):
await setup_policy_tun(unet, r1only=True, iptfs_opts="", ipv6=ipv6)
await astepf(f"Prior to gen_pkt_test, ipv6: {ipv6}")
await astepf(f"Prior to gen_pkt_test ipv6: {ipv6} tun_ipv6: {tun_ipv6}")
await gen_pkt_test(
unet, psize=1421 if tun_ipv6 else 1441, mtu=1500, count=3, ipv6=ipv6
)
Expand Down

0 comments on commit c23f223

Please sign in to comment.