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
| | #! /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 <david@gibson.dropbear.id.au>
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()
|