#! /usr/bin/python3 # SPDX-License-Identifier: GPL-2.0-or-later # # avocado/pasta_ndp.py - Test NDP operations with pasta # # Copyright Red Hat # Author: David Gibson import ipaddress import json import common from pasta import PastaUnconfiguredTest class PastaNdpTest(PastaUnconfiguredTest): def setUp(self): super().setUp() self.innerx('ip link set dev {} up'.format(self.IFNAME), sudo=True) common.slaac_wait(self.innerx, self.IFNAME) def test_addr(self): ifinfo = self.innerx('ip -6 -j addr show {}'.format(self.IFNAME)) ifinfo = json.loads(ifinfo)[0] for adinfo in ifinfo['addr_info']: if adinfo['scope'] == 'global': print(adinfo) global_addr = ipaddress.ip_address(adinfo['local']) prefixlen = adinfo['prefixlen'] # 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 match the prefix of the host # address, though inner_if = ipaddress.IPv6Interface('{}/{}' .format(global_addr, prefixlen)) outer_if = ipaddress.IPv6Interface('{}/{}' .format(self.OUTER_IP6, prefixlen)) self.assertEquals(inner_if.network, outer_if.network) self.shutdown() def test_route(self): rinfo = self.innerx('ip -j -6 route show') rinfo = json.loads(rinfo) for route in rinfo: if route['dst'] != 'default': continue gateway = ipaddress.ip_address(route['gateway']) self.assertEquals(gateway, self.gw_ll) self.shutdown()