public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob e14d7a4c8462fdeddad384554f03896c7d456685 3049 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
 
#! /usr/bin/env avocado-runner-avocado-classless

# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright Red Hat
# Author: David Gibson <david@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)
@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

debug log:

solving e14d7a4c ...
found e14d7a4c in https://archives.passt.top/passt-dev/20230627025429.2209702-25-david@gibson.dropbear.id.au/

applying [1/1] https://archives.passt.top/passt-dev/20230627025429.2209702-25-david@gibson.dropbear.id.au/
diff --git a/test/tasst/ndp.py b/test/tasst/ndp.py
new file mode 100644
index 00000000..e14d7a4c

Checking patch test/tasst/ndp.py...
Applied patch test/tasst/ndp.py cleanly.

index at:
100644 e14d7a4c8462fdeddad384554f03896c7d456685	test/tasst/ndp.py

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).