Signed-iff-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/tasst/ndp.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 test/tasst/ndp.py diff --git a/test/tasst/ndp.py b/test/tasst/ndp.py new file mode 100644 index 00000000..e14d7a4c --- /dev/null +++ b/test/tasst/ndp.py @@ -0,0 +1,99 @@ +#! /usr/bin/env avocado-runner-avocado-classless + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright Red Hat +# Author: David Gibson <david(a)gibson.dropbear.id.au> + +""" +Test A Simple Socket Transport + +ndp.py - Helpers for testing NDP +""" + +import contextlib +import ipaddress +import os +import tempfile + +from avocado_classless.test import assert_eq, test_output + +from tasst.address import IpiAllocator, TEST_NET6_TASST_A +from tasst.nstool import unshare_site + + +def test_ndp(ifname, network): + def dec(sitefn): + def test_ndp_addr(setup): + with setup as (site, _): + # Wait for NDP to do its thing + (addr,) = site.addr_wait(ifname, family='inet6', + scope='global') + + # The SLAAC address is derived from the guest ns MAC, + # so probably won't exactly match the host address (we + # need DHCPv6 for that). It should be in the right + # network though. + assert_eq(addr.network, network) + + def test_ndp_route(setup): + with setup as (site, gateway): + defroutes = site.routes6(dst='default') + while not defroutes: + defroutes = site.routes6(dst='default') + + assert_eq(len(defroutes), 1) + gw = ipaddress.ip_address(defroutes[0]['gateway']) + assert_eq(gw, gateway) + + return test_output(test_ndp_addr, test_ndp_route)(sitefn) + return dec + + +IFNAME = 'clientif' +NETWORK = TEST_NET6_TASST_A +ipa = IpiAllocator(NETWORK) +(ROUTER_IP6,) = ipa.next_ipis() + + +@test_ndp(IFNAME, NETWORK) +(a)contextlib.contextmanager +def setup_radvd(): + router_ifname = 'routerif' + + with unshare_site('client', '-Un') as client, \ + unshare_site('router', '-n', parent=client, sudo=True) as router: + with tempfile.TemporaryDirectory() as tmpdir: + router.require_cmds('radvd') + + client.veth(IFNAME, router_ifname, router) + + # Configure the simulated router + confpath = os.path.join(tmpdir, 'radvd.conf') + pidfile = os.path.join(tmpdir, 'radvd.pid') + open(confpath, 'w', encoding='UTF-8').write( + f''' + interface {router_ifname} {{ + AdvSendAdvert on; + prefix {NETWORK} {{ + }}; + }}; + ''' + ) + + router.ifup('lo') + router.ifup('routerif', ROUTER_IP6) + + # Configure the client + client.ifup('lo') + client.ifup(IFNAME) + + # Get the router's link-local-address + (router_ll,) = router.addr_wait(router_ifname, + family='inet6', scope='link') + + # Run radvd + router.fg(f'radvd -c -C {confpath}') + radvd_cmd = f'radvd -C {confpath} -p {pidfile} -n -d 5' + with router.bg(radvd_cmd, sudo=True, pidfile=pidfile): + yield client, router_ll.ip -- 2.41.0