From 594c2f93716380feb29aeb774ba77704684aa125 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 13 Sep 2022 14:35:16 +1000 Subject: test: Group tests by mode then protocol, rather than the reverse For example, passt/dhcp rather than dhcp/passt. This is more consistent with the two_guests and other test groups, and makes some other cleanups simpler. Signed-off-by: David Gibson --- test/pasta/dhcp | 46 ++++++++++++++++++++++ test/pasta/ndp | 33 ++++++++++++++++ test/pasta/tcp | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/pasta/udp | 69 +++++++++++++++++++++++++++++++++ 4 files changed, 264 insertions(+) create mode 100644 test/pasta/dhcp create mode 100644 test/pasta/ndp create mode 100644 test/pasta/tcp create mode 100644 test/pasta/udp (limited to 'test/pasta') diff --git a/test/pasta/dhcp b/test/pasta/dhcp new file mode 100644 index 0000000..80eabf5 --- /dev/null +++ b/test/pasta/dhcp @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# PASST - Plug A Simple Socket Transport +# for qemu/UNIX domain socket mode +# +# PASTA - Pack A Subtle Tap Abstraction +# for network namespace/tap device mode +# +# test/pasta/dhcp - Check DHCP and DHCPv6 functionality in pasta mode +# +# Copyright (c) 2021 Red Hat GmbH +# Author: Stefano Brivio + +nstools ip jq /sbin/dhclient +htools ip jq + +test Interface name +nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' +check [ -n "__IFNAME__" ] + +test DHCP: address +ns /sbin/dhclient -4 --no-pid __IFNAME__ +nsout ADDR ip -j -4 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local' +hout HOST_ADDR ip -j -4 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[0].local' +check [ __ADDR__ = __HOST_ADDR__ ] + +test DHCP: route +nsout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' +hout HOST_GW ip -j -4 route show|jq -rM '[.[] | select(.dst == "default").gateway] | .[0]' +check [ __GW__ = __HOST_GW__ ] + +test DHCP: MTU +nsout MTU ip -j link show | jq -rM '.[] | select(.ifname == "__IFNAME__").mtu' +check [ __MTU__ = 65520 ] + +test DHCPv6: address +ns /sbin/dhclient -6 --no-pid __IFNAME__ +hout HOST_IFNAME6 ip -j -6 route show|jq -rM '[.[] | select(.dst == "default").dev] | .[0]' +nsout ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[] | select(.prefixlen == 128).local' +hout HOST_ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__HOST_IFNAME6__").addr_info[] | select(.scope == "global").local' +check [ __ADDR6__ = __HOST_ADDR6__ ] + +test DHCPv6: route +nsout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' +hout HOST_GW6 ip -j -6 route show|jq -rM '[.[] | select(.dst == "default").gateway] | .[0]' +check [ __GW6__ = __HOST_GW6__ ] diff --git a/test/pasta/ndp b/test/pasta/ndp new file mode 100644 index 0000000..d2b2c0b --- /dev/null +++ b/test/pasta/ndp @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# PASST - Plug A Simple Socket Transport +# for qemu/UNIX domain socket mode +# +# PASTA - Pack A Subtle Tap Abstraction +# for network namespace/tap device mode +# +# test/pasta/ndp - Check DHCP and DHCPv6 functionality in pasta mode +# +# Copyright (c) 2021 Red Hat GmbH +# Author: Stefano Brivio + +nstools ip jq sipcalc grep cut +htools ip jq sipcalc grep cut + +test Interface name +nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' +check [ -n "__IFNAME__" ] +ns ip link set dev __IFNAME__ up +sleep 2 + +test SLAAC: prefix +nsout ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[] | select(.scope == "global" and .prefixlen == 64).local' +nsout PREFIX6 sipcalc __ADDR6__/64 | grep prefix | cut -d' ' -f4 +hout HOST_ADDR6 ip -j -6 addr show|jq -rM '.[] | select(.ifname == "__IFNAME__").addr_info[] | select(.scope == "global").local' +hout HOST_PREFIX6 sipcalc __HOST_ADDR6__/64 | grep prefix | cut -d' ' -f4 +check [ "__PREFIX6__" = "__HOST_PREFIX6__" ] + +test SLAAC: route +nsout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' +hout HOST_GW6 ip -j -6 route show|jq -rM '[.[] | select(.dst == "default").gateway] | .[0]' +check [ __GW6__ = __HOST_GW6__ ] diff --git a/test/pasta/tcp b/test/pasta/tcp new file mode 100644 index 0000000..7c7de06 --- /dev/null +++ b/test/pasta/tcp @@ -0,0 +1,116 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# PASST - Plug A Simple Socket Transport +# for qemu/UNIX domain socket mode +# +# PASTA - Pack A Subtle Tap Abstraction +# for network namespace/tap device mode +# +# test/pasta/tcp - Check TCP functionality for pasta +# +# Copyright (c) 2021 Red Hat GmbH +# Author: Stefano Brivio + +htools dd socat ip jq md5sum cut +nstools socat ip jq md5sum cut + +test TCP/IPv4: host to ns: big transfer +temp TEMP_BIG +temp TEMP_NS_BIG +nsb socat -u TCP4-LISTEN:10002,bind=127.0.0.1 OPEN:__TEMP_NS_BIG__,create,trunc +host dd if=/dev/urandom bs=1M count=10 of=__TEMP_BIG__ +host socat -u OPEN:__TEMP_BIG__ TCP4:127.0.0.1:10002 +nsw +hout MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 +nsout NS_MD5_BIG md5sum __TEMP_NS_BIG__ | cut -d' ' -f1 +check [ "__NS_MD5_BIG__" = "__MD5_BIG__" ] + +test TCP/IPv4: ns to host (spliced): big transfer +hostb socat -u TCP4-LISTEN:10003,bind=127.0.0.1 OPEN:__TEMP_BIG__,create,trunc +ns socat -u OPEN:__TEMP_NS_BIG__ TCP4:127.0.0.1:10003 +hostw +hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 +check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] + +test TCP/IPv4: ns to host (via tap): big transfer +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc +nsout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' +ns socat -u OPEN:__TEMP_NS_BIG__ TCP4:__GW__:10003 +hostw +hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 +check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] + +test TCP/IPv4: host to ns: small transfer +temp TEMP_SMALL +temp TEMP_NS_SMALL +nsb socat -u TCP4-LISTEN:10002,bind=127.0.0.1 OPEN:__TEMP_NS_SMALL__,create,trunc +host dd if=/dev/urandom bs=2k count=1 of=__TEMP_SMALL__ +host socat OPEN:__TEMP_SMALL__ TCP4:127.0.0.1:10002 +nsw +hout MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 +nsout NS_MD5_SMALL md5sum __TEMP_NS_SMALL__ | cut -d' ' -f1 +check [ "__NS_MD5_SMALL__" = "__MD5_SMALL__" ] + +test TCP/IPv4: ns to host (spliced): small transfer +hostb socat -u TCP4-LISTEN:10003,bind=127.0.0.1 OPEN:__TEMP_SMALL__,create,trunc +ns socat OPEN:__TEMP_NS_SMALL__ TCP4:127.0.0.1:10003 +hostw +hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 +check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] + +test TCP/IPv4: ns to host (via tap): small transfer +hostb socat -u TCP4-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc +nsout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP4:__GW__:10003 +hostw +hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 +check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] + +test TCP/IPv6: host to ns: big transfer +nsb socat -u TCP6-LISTEN:10002,bind=[::1] OPEN:__TEMP_NS_BIG__,create,trunc +host socat -u OPEN:__TEMP_BIG__ TCP6:[::1]:10002 +nsw +hout MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 +nsout NS_MD5_BIG md5sum __TEMP_NS_BIG__ | cut -d' ' -f1 +check [ "__NS_MD5_BIG__" = "__MD5_BIG__" ] + +test TCP/IPv6: ns to host (spliced): big transfer +hostb socat -u TCP6-LISTEN:10003,bind=[::1] OPEN:__TEMP_BIG__,create,trunc +ns socat -u OPEN:__TEMP_NS_BIG__ TCP6:[::1]:10003 +hostw +hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 +check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] + +test TCP/IPv6: ns to host (via tap): big transfer +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_BIG__,create,trunc +nsout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' +nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' +ns socat -u OPEN:__TEMP_NS_BIG__ TCP6:[__GW6__%__IFNAME__]:10003 +hostw +hout HOST_MD5_BIG md5sum __TEMP_BIG__ | cut -d' ' -f1 +check [ "__HOST_MD5_BIG__" = "__MD5_BIG__" ] + +test TCP/IPv6: host to ns: small transfer +temp TEMP_SMALL +temp TEMP_NS_SMALL +nsb socat -u TCP6-LISTEN:10002,bind=[::1] OPEN:__TEMP_NS_SMALL__,create,trunc +host dd if=/dev/urandom bs=2k count=1 of=__TEMP_SMALL__ +host socat -u OPEN:__TEMP_SMALL__ TCP6:[::1]:10002 +nsw +hout MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 +nsout NS_MD5_SMALL md5sum __TEMP_NS_SMALL__ | cut -d' ' -f1 +check [ "__NS_MD5_SMALL__" = "__MD5_SMALL__" ] + +test TCP/IPv6: ns to host (spliced): small transfer +hostb socat -u TCP6-LISTEN:10003,bind=[::1] OPEN:__TEMP_SMALL__,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP6:[::1]:10003 +hostw +hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 +check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] + +test TCP/IPv6: ns to host (via tap): small transfer +hostb socat -u TCP6-LISTEN:10003 OPEN:__TEMP_SMALL__,create,trunc +ns socat -u OPEN:__TEMP_NS_SMALL__ TCP6:[__GW6__%__IFNAME__]:10003 +hostw +hout HOST_MD5_SMALL md5sum __TEMP_SMALL__ | cut -d' ' -f1 +check [ "__HOST_MD5_SMALL__" = "__MD5_SMALL__" ] diff --git a/test/pasta/udp b/test/pasta/udp new file mode 100644 index 0000000..0e58152 --- /dev/null +++ b/test/pasta/udp @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# PASST - Plug A Simple Socket Transport +# for qemu/UNIX domain socket mode +# +# PASTA - Pack A Subtle Tap Abstraction +# for network namespace/tap device mode +# +# test/pasta/udp - Check UDP functionality for pasta +# +# Copyright (c) 2021 Red Hat GmbH +# Author: Stefano Brivio + +nstools socat tee grep cat ip jq md5sum cut +htools printf dd socat tee grep cat ip jq md5sum cut + +test UDP/IPv4: host to ns +temp TEMP +temp TEMP_NS +temp NC_PID +nsb (socat -u UDP4-LISTEN:10002,bind=127.0.0.1 STDOUT & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +host dd if=/dev/urandom bs=1k count=5 > __TEMP__ && printf "\nEND_OF_TEST\n" >> __TEMP__ + +host socat OPEN:__TEMP__ UDP4:127.0.0.1:10002 +nsw +hout MD5 md5sum __TEMP__ | cut -d' ' -f1 +nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 +check [ "__NS_MD5__" = "__MD5__" ] + +test UDP/IPv4: ns to host (recvmmsg/sendmmsg) +hostb (socat -u UDP4-LISTEN:10003,bind=127.0.0.1 STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +sleep 1 +ns socat OPEN:__TEMP_NS__ UDP4:127.0.0.1:10003 +hostw +hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 +check [ "__HOST_MD5__" = "__MD5__" ] + +test UDP/IPv4: ns to host (via tap) +hostb (socat -u UDP4-LISTEN:10003 STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +nsout GW ip -j -4 route show|jq -rM '.[] | select(.dst == "default").gateway' +ns socat -u OPEN:__TEMP_NS__ UDP4:__GW__:10003 +hostw +hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 +check [ "__HOST_MD5__" = "__MD5__" ] + +test UDP/IPv6: host to ns +nsb (socat -u UDP6-LISTEN:10002,bind=[::1] STDOUT & echo $! > __NC_PID__) | tee __TEMP_NS__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +host socat -u OPEN:__TEMP__ UDP6:[::1]:10002 +nsw +hout MD5 md5sum __TEMP__ | cut -d' ' -f1 +nsout NS_MD5 md5sum __TEMP_NS__ | cut -d' ' -f1 +check [ "__NS_MD5__" = "__MD5__" ] + +test UDP/IPv6: ns to host (recvmmsg/sendmmsg) +hostb (socat -u UDP6-LISTEN:10003,bind=[::1] STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +sleep 1 +ns socat -u OPEN:__TEMP_NS__ UDP6:[::1]:10003 +hostw +hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 +check [ "__HOST_MD5__" = "__MD5__" ] + +test UDP/IPv6: ns to host (via tap) +hostb (socat -u UDP6-LISTEN:10003 STDOUT & echo $! > __NC_PID__) | tee __TEMP__ | (grep -qm1 "END_OF_TEST" && kill $(cat __NC_PID__)) +nsout GW6 ip -j -6 route show|jq -rM '.[] | select(.dst == "default").gateway' +nsout IFNAME ip -j link show | jq -rM '.[] | select(.link_type == "ether").ifname' +ns socat -u OPEN:__TEMP_NS__ UDP6:[__GW6__%__IFNAME__]:10003 +hostw +hout HOST_MD5 md5sum __TEMP__ | cut -d' ' -f1 +check [ "__HOST_MD5__" = "__MD5__" ] -- cgit v1.2.3