From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 2959F5A0281 for ; Tue, 27 Jun 2023 04:54:47 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Qqq7K1JWbz4wqy; Tue, 27 Jun 2023 12:54:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1687834477; bh=OrmOENnnj8yJGXQ5zNcK/U6pl6a9mMukS33iZKZkK64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H+kk0PpCrP0DFiCXKt5XV4uK5flvpISI2elz6UtK1zWIaRlteC6sbA9g7WgVNKFUD yNcrcbd+C9UhgaCn7bseLUOs8lriU32y/Vzn2HX2buyI8kIAeYYhg3ZOMAvtFMKwLx wQr6/OLAtRyvAYFkRtW2HEAxsAnSDshpFwrBYs9I= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 24/27] tasst: Helpers for testing NDP behaviour Date: Tue, 27 Jun 2023 12:54:25 +1000 Message-ID: <20230627025429.2209702-25-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230627025429.2209702-1-david@gibson.dropbear.id.au> References: <20230627025429.2209702-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: UV2EMYAZCQVLLAT7C6754G5UVO25MFGG X-Message-ID-Hash: UV2EMYAZCQVLLAT7C6754G5UVO25MFGG X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: crosa@redhat.com, jarichte@redhat.com, David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-iff-by: David Gibson --- 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 + +""" +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) +@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