tests/gnrc_dhcpv6_client: Add test for IA_NA
This commit is contained in:
parent
234a71870a
commit
85eae9d2da
@ -9,6 +9,7 @@ RIOTBASE ?= $(CURDIR)/../..
|
|||||||
BOARD_BLACKLIST += mips-malta pic32-wifire pic32-clicker ruuvitag thingy52
|
BOARD_BLACKLIST += mips-malta pic32-wifire pic32-clicker ruuvitag thingy52
|
||||||
|
|
||||||
USEMODULE += dhcpv6_client_ia_pd
|
USEMODULE += dhcpv6_client_ia_pd
|
||||||
|
USEMODULE += dhcpv6_client_ia_na
|
||||||
USEMODULE += gnrc_dhcpv6_client
|
USEMODULE += gnrc_dhcpv6_client
|
||||||
USEMODULE += gnrc_ipv6_default
|
USEMODULE += gnrc_ipv6_default
|
||||||
USEMODULE += xtimer
|
USEMODULE += xtimer
|
||||||
|
|||||||
@ -22,8 +22,9 @@
|
|||||||
"subnet6": [
|
"subnet6": [
|
||||||
{ "interface": "tapbr0",
|
{ "interface": "tapbr0",
|
||||||
"subnet": "2001:db8::/32",
|
"subnet": "2001:db8::/32",
|
||||||
"pd-pools": [ { "prefix": "2001:db8::",
|
"pools": [ { "pool": "2001:db8:1::/64" } ],
|
||||||
"prefix-len": 32,
|
"pd-pools": [ { "prefix": "2001:db8:8000::",
|
||||||
|
"prefix-len": 33,
|
||||||
"delegated-len": 64 } ] }
|
"delegated-len": 64 } ] }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -37,6 +37,8 @@ void *_dhcpv6_client_thread(void *args)
|
|||||||
(void)args;
|
(void)args;
|
||||||
/* initialize client event queue */
|
/* initialize client event queue */
|
||||||
event_queue_init(&event_queue);
|
event_queue_init(&event_queue);
|
||||||
|
/* Configure client to use DHCPv6 IA_NA */
|
||||||
|
netif->ipv6.aac_mode |= GNRC_NETIF_AAC_DHCP;
|
||||||
/* initialize DHCPv6 client on any interface */
|
/* initialize DHCPv6 client on any interface */
|
||||||
dhcpv6_client_init(&event_queue, SOCK_ADDR_ANY_NETIF);
|
dhcpv6_client_init(&event_queue, SOCK_ADDR_ANY_NETIF);
|
||||||
/* configure client to request prefix delegation of /64 subnet
|
/* configure client to request prefix delegation of /64 subnet
|
||||||
|
|||||||
@ -8,6 +8,13 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from testrunner import run
|
from testrunner import run
|
||||||
|
from ipaddress import (
|
||||||
|
IPv6Address,
|
||||||
|
IPv6Network,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
IA_NA_ADDRESS_POOL_PREFIX = "2001:db8:1::"
|
||||||
|
|
||||||
|
|
||||||
def testfunc(child):
|
def testfunc(child):
|
||||||
@ -15,17 +22,64 @@ def testfunc(child):
|
|||||||
child.expect(r"inet6 addr:\sfe80:[0-9a-f:]+\s+scope: link")
|
child.expect(r"inet6 addr:\sfe80:[0-9a-f:]+\s+scope: link")
|
||||||
child.expect(r"Iface\s+\d+")
|
child.expect(r"Iface\s+\d+")
|
||||||
child.expect(r"inet6 addr:\s+fe80:[0-9a-f:]+\s+scope: link")
|
child.expect(r"inet6 addr:\s+fe80:[0-9a-f:]+\s+scope: link")
|
||||||
child.expect(r"inet6 addr:\s+(?P<global_addr>[0-9a-f:]+)\s+scope: global")
|
|
||||||
global_addr = child.match.group("global_addr")
|
global_addr_1, global_addr_2 = extract_global_addresses(child)
|
||||||
|
|
||||||
|
global_pfx = extract_global_prefix(child)
|
||||||
|
|
||||||
|
test_global_addrs(global_addr_1, global_addr_2, global_pfx)
|
||||||
|
|
||||||
|
|
||||||
|
def extract_global_prefix(child):
|
||||||
child.expect(r"(?P<global_pfx>[0-9a-f:]+)/64\s+dev #\d\s+"
|
child.expect(r"(?P<global_pfx>[0-9a-f:]+)/64\s+dev #\d\s+"
|
||||||
r"expires \d+ sec\s+"
|
r"expires \d+ sec\s+"
|
||||||
r"deprecates \d+ sec")
|
r"deprecates \d+ sec")
|
||||||
global_pfx = child.match.group("global_pfx")
|
global_pfx = child.match.group("global_pfx")
|
||||||
|
|
||||||
if global_pfx.endswith("::"):
|
if global_pfx.endswith("::"):
|
||||||
# remove one trailing : in case there are no 0s between prefix and
|
# remove one trailing : in case there are no 0s between prefix and
|
||||||
# suffix
|
# suffix
|
||||||
global_pfx = global_pfx[0:-1]
|
global_pfx = global_pfx[0:-1]
|
||||||
assert global_addr.startswith(global_pfx)
|
|
||||||
|
return global_pfx
|
||||||
|
|
||||||
|
|
||||||
|
def extract_global_address(child):
|
||||||
|
"""Expect and extract a global address from the command line."""
|
||||||
|
child.expect(r"inet6 addr:\s+(?P<global_addr>[0-9a-f:]+)\s+scope: global")
|
||||||
|
return child.match.group("global_addr")
|
||||||
|
|
||||||
|
|
||||||
|
def extract_global_addresses(child):
|
||||||
|
"""Extract two global addresses and return them as a tuple."""
|
||||||
|
return extract_global_address(child), extract_global_address(child)
|
||||||
|
|
||||||
|
|
||||||
|
def check_ia_na_addr(ia_na_addr):
|
||||||
|
"""Check if the expected IA_NA address has been assigned"""
|
||||||
|
return IPv6Address(ia_na_addr) in IPv6Network("{}/64".format(IA_NA_ADDRESS_POOL_PREFIX))
|
||||||
|
|
||||||
|
|
||||||
|
def check_ia_pd_addr(ia_pd_addr, global_pfx):
|
||||||
|
"""Check if the expected IA_PD address has been assigned"""
|
||||||
|
return ia_pd_addr.startswith(global_pfx)
|
||||||
|
|
||||||
|
|
||||||
|
def check_global_addrs(ia_na_addr, ia_pd_addr, global_pfx):
|
||||||
|
"""Perform IA_NA check for the first and IA_PD for the second address"""
|
||||||
|
return {
|
||||||
|
"ia_na_check": check_ia_na_addr(ia_na_addr),
|
||||||
|
"ia_pd_check": check_ia_pd_addr(ia_pd_addr, global_pfx),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_global_addrs(global_addr_1, global_addr_2, global_pfx):
|
||||||
|
"""Assert that one global address is the IA_NA and the other one is the IA_PD address"""
|
||||||
|
result_1 = check_global_addrs(global_addr_1, global_addr_2, global_pfx)
|
||||||
|
result_2 = check_global_addrs(global_addr_2, global_addr_1, global_pfx)
|
||||||
|
assert result_1 != result_2
|
||||||
|
assert result_1["ia_na_check"] != result_2["ia_na_check"]
|
||||||
|
assert result_1["ia_pd_check"] != result_2["ia_pd_check"]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user