#! /usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-or-later # # Copyright Red Hat # Author: David Gibson """ Test A Simple Socket Transport selftest/veth.py - Test various veth configurations """ import contextlib import ipaddress import exeter from tasst import address, nstool, transfer @contextlib.contextmanager def unconfigured_veth(): with nstool.unshare_snh('ns1', '-Un') as ns1: with nstool.unshare_snh('ns2', '-n', parent=ns1, capable=True) as ns2: ns1.veth('veth1', 'veth2', ns2) yield (ns1, ns2) @exeter.test def test_ifs(): with unconfigured_veth() as (ns1, ns2): exeter.assert_eq(set(ns1.ifs()), set(['lo', 'veth1'])) exeter.assert_eq(set(ns2.ifs()), set(['lo', 'veth2'])) @exeter.test def test_mtu(): with unconfigured_veth() as (ns1, ns2): exeter.assert_eq(ns1.mtu('veth1'), 1500) exeter.assert_eq(ns2.mtu('veth2'), 1500) @exeter.test def test_slaac(dad=None): TESTMAC = '02:aa:bb:cc:dd:ee' TESTIP = ipaddress.ip_interface('fe80::aa:bbff:fecc:ddee/64') with unconfigured_veth() as (ns1, ns2): ns1.fg('ip', 'link', 'set', 'dev', 'veth1', 'address', f'{TESTMAC}', capable=True) ns1.ifup('veth1', dad=dad) ns2.ifup('veth2') addrs = ns1.addr_wait('veth1', family='inet6', scope='link') exeter.assert_eq(addrs, [TESTIP]) @exeter.test def test_optimistic_dad(): test_slaac(dad='optimistic') @exeter.test def test_no_dad(): test_slaac(dad='disable') @contextlib.contextmanager def configured_veth(ip1, ip2): with unconfigured_veth() as (ns1, ns2): ns1.ifup('lo') ns1.ifup('veth1', ip1, dad='disable') ns2.ifup('lo') ns2.ifup('veth2', ip2, dad='disable') yield (ns1, ns2) @contextlib.contextmanager def veth_transfer(ip1, ip2): with configured_veth(ip1, ip2) as (ns1, ns2): yield transfer.TransferTestScenario(client=ns1, server=ns2, connect_ip=ip2.ip, connect_port=10000) ipa = address.IpiAllocator() NS1_IP4, NS1_IP6 = ipa.next_ipis() NS2_IP4, NS2_IP6 = ipa.next_ipis() def veth_transfer4(): return veth_transfer(NS1_IP4, NS2_IP4) transfer.transfer_tests(veth_transfer4) def veth_transfer6(): return veth_transfer(NS1_IP6, NS2_IP6) transfer.transfer_tests(veth_transfer6)