public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob 1c18385cdeb9c3dfdf4d38b377206f3ba944b1fc 3377 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
#! /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

import exeter

from . import address, nstool


class NdpTestScenario:
    def __init__(self, *, client, ifname, network, gateway):
        self.client = client
        self.ifname = ifname
        self.network = network
        self.gateway = gateway


def test_ndp_addr(setup):
    with setup as scn:
        # Wait for NDP to do its thing
        (addr,) = scn.client.addr_wait(scn.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.
        exeter.assert_eq(addr.network, scn.network)


def test_ndp_route(setup):
    with setup as scn:
        defroutes = scn.client.routes6(dst='default')
        while not defroutes:
            defroutes = scn.client.routes6(dst='default')

        exeter.assert_eq(len(defroutes), 1)
        gw = ipaddress.ip_address(defroutes[0]['gateway'])
        exeter.assert_eq(gw, scn.gateway)


NDP_TESTS = [test_ndp_addr, test_ndp_route]


def ndp_tests(setup):
    for t in NDP_TESTS:
        testid = f'{setup.__qualname__}|{t.__qualname__}'
        exeter.register_pipe(testid, setup, t)


IFNAME = 'clientif'
NETWORK = address.TEST_NET6_TASST_A
ipa = address.IpiAllocator(NETWORK)
(ROUTER_IP6,) = ipa.next_ipis()


@contextlib.contextmanager
def setup_radvd():
    router_ifname = 'routerif'

    with nstool.unshare_snh('client', '-Un') as client, \
         nstool.unshare_snh('router', '-n',
                            parent=client, capable=True) as router:
        with tempfile.TemporaryDirectory() as tmpdir:
            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('radvd', '-c', '-C', f'{confpath}')
            radvd_cmd = ['radvd', '-C', f'{confpath}', '-n',
                         '-p', f'{pidfile}', '-d', '5']
            with router.bg(*radvd_cmd, capable=True) as radvd:
                yield NdpTestScenario(client=client,
                                      ifname=IFNAME,
                                      network=NETWORK,
                                      gateway=router_ll.ip)
                radvd.terminate()


ndp_tests(setup_radvd)

debug log:

solving 1c18385c ...
found 1c18385c in https://archives.passt.top/passt-dev/20240805123701.1720730-20-david@gibson.dropbear.id.au/

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

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

index at:
100644 1c18385cdeb9c3dfdf4d38b377206f3ba944b1fc	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).