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 9E9535A0285 for ; Tue, 16 May 2023 04:01:49 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4QKzxd40wjz4y1g; Tue, 16 May 2023 12:01:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1684202501; bh=S4Lfszso96JwzHbTe0snFYx/3a36jp9h0/0+fkSPWg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=odEwiw07EhR+tbsP7Tu+lY7z4/T6mNdqUNowV5d+R4aXQ7buHyGRytBEbfCLQILCc 9MEeg8WXU9GWkRQhs8W3hSIKgobGpDJq2WCvAX5hsQWrxuwDZYfIh5HHBBmHseNWPs M8zuIEy5scCXkqDCPUG5j9Q/q8gqBKJD0nhYVHjI= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 18/21] avocado/tasst: Helpers for testing NDP behaviour Date: Tue, 16 May 2023 12:01:32 +1000 Message-Id: <20230516020135.1901256-19-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516020135.1901256-1-david@gibson.dropbear.id.au> References: <20230516020135.1901256-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: BMEHYIOLPL47TAQPGXMI7TS6WQAWHK6C X-Message-ID-Hash: BMEHYIOLPL47TAQPGXMI7TS6WQAWHK6C 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: jarichte@redhat.com, Cleber Rosa , 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 --- avocado/tasst/ndp.py | 129 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 avocado/tasst/ndp.py diff --git a/avocado/tasst/ndp.py b/avocado/tasst/ndp.py new file mode 100644 index 0000000..5d9c01c --- /dev/null +++ b/avocado/tasst/ndp.py @@ -0,0 +1,129 @@ +#! /usr/bin/python3 + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# tasst - Test A Simple Socket Transport +# library of test helpers for passt & pasta +# +# tasst/ndp.py - Helpers for testing NDP +# +# Copyright Red Hat +# Author: David Gibson + +import ipaddress +import os + +from tasst import Tasst, TasstSubData +from tasst.address import IpiAllocator, TEST_NET6_TASST_A +from tasst.nstool import UnshareSite + +class BaseNdpTasst(Tasst): + """ + Test NDP behaviour. + + :avocado: disable + """ + + def subsetup(self, site, ifname, net, gw): + Tasst.subsetup(self, BaseNdpTasst, + TasstSubData(site=site, ifname=ifname, net=net, gw=gw)) + + def test_addr(self): + sub = self.get_subsetup(BaseNdpTasst) + + # Wait for NDP to do its thing + (addr,) = sub.site.addr_wait(sub.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. + self.assertEquals(addr.network, sub.net) + + def test_route(self): + sub = self.get_subsetup(BaseNdpTasst) + + defroutes = sub.site.routes6(dst='default') + while not defroutes: + defroutes = sub.site.routes6(dst='default') + + self.assertEquals(len(defroutes), 1) + gateway = ipaddress.ip_address(defroutes[0]['gateway']) + self.assertEquals(gateway, sub.gw) + + +class MetaNdpTasst(BaseNdpTasst): + """Ugly workaround for + https://github.com/avocado-framework/avocado/issues/5680. + Explicitly apply the "meta" tag to inherited tests + + :avocado: disable + :avocado: tags=meta + + """ + + def test_addr(self): + super().test_addr() + + def test_route(self): + super().test_route() + + +class RadvdNdpTasst(MetaNdpTasst): + timeout = 15.0 + + def setUp(self): + super().setUp() + + ifname = 'clientif' + router_ifname = 'routerif' + prefix = TEST_NET6_TASST_A + + self.client = UnshareSite(self.__class__.__name__ + '.client', '-Un') + self.router = UnshareSite(self.__class__.__name__ + '.router', '-n', + parent=self.client, sudo=True) + + self.router.require_cmds('radvd') + + self.client.veth(ifname, router_ifname, self.router) + + # Configure the simulated router + ipa = IpiAllocator(prefix) + (router_ip6,) = ipa.next_ipis() + + confpath = os.path.join(self.workdir, 'radvd.conf') + self.pidpath = os.path.join(self.workdir, 'radvd.pid') + open(confpath, 'w').write( + ''' + interface {} {{ + AdvSendAdvert on; + prefix {} {{ + }}; + }}; + '''.format(router_ifname, prefix)) + + self.router.ifup('lo') + self.router.ifup('routerif', router_ip6) + + # Configure the client + self.client.ifup('lo') + self.client.ifup(ifname) + + # Get the router's link-local-address + (self.router_ll,) = self.router.addr_wait(router_ifname, + family='inet6', scope='link') + + # Run radvd + self.router.fg('radvd -c -C {}'.format(confpath)) + self.radvd = self.router.bg('radvd -C {} -p {} -n -d 5'.format(confpath, self.pidpath), + sudo=True) + + BaseNdpTasst.subsetup(self, self.client, ifname, prefix, self.router_ll.ip) + + def tearDown(self): + pid = int(open(self.pidpath).read()) + self.router.fg('kill {}'.format(pid)) + status = self.radvd.wait() + self.assertEquals(status, 0) + self.router.close() + self.client.close() + super().tearDown() -- 2.40.1