2023-01-11 04:11:32 -05:00
|
|
|
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
2022-08-16 22:57:39 -04:00
|
|
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
|
|
|
# !/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
|
|
import os.path
|
|
|
|
import re
|
|
|
|
import subprocess
|
2022-10-12 23:55:36 -04:00
|
|
|
import threading
|
2022-08-16 22:57:39 -04:00
|
|
|
import time
|
|
|
|
from typing import Tuple
|
|
|
|
|
|
|
|
import ot_ci_function as ocf
|
2022-09-23 10:11:18 -04:00
|
|
|
import pexpect
|
2022-08-16 22:57:39 -04:00
|
|
|
import pytest
|
|
|
|
from pytest_embedded_idf.dut import IdfDut
|
|
|
|
|
|
|
|
# This file contains the test scripts for Thread:
|
|
|
|
|
|
|
|
# Case 1: Thread network formation and attaching
|
2023-01-11 04:11:32 -05:00
|
|
|
# A Thread Border Router forms a Thread network, Thread devices attache to it, then test ping connection between them.
|
2022-08-16 22:57:39 -04:00
|
|
|
|
|
|
|
# Case 2: Bidirectional IPv6 connectivity
|
|
|
|
# Test IPv6 ping connection between Thread device and Linux Host (via Thread Border Router).
|
|
|
|
|
|
|
|
# Case 3: Multicast forwarding from Wi-Fi to Thread network
|
|
|
|
# Thread device joins the multicast group, then test group communication from Wi-Fi to Thread network.
|
|
|
|
|
|
|
|
# Case 4: Multicast forwarding from Thread to Wi-Fi network
|
|
|
|
# Linux Host joins the multicast group, test group communication from Thread to Wi-Fi network.
|
|
|
|
|
2022-09-23 10:11:18 -04:00
|
|
|
# Case 5: discover Serice published by Thread device
|
|
|
|
# Thread device publishes the service, Linux Host discovers the service on Wi-Fi network.
|
|
|
|
|
|
|
|
# Case 6: discover Serice published by W-Fi device
|
|
|
|
# Linux Host device publishes the service on Wi-Fi network, Thread device discovers the service.
|
|
|
|
|
|
|
|
# Case 7: ICMP communication via NAT64
|
|
|
|
# Thread device (IPV6) ping the host device (IPV4) via NAT64.
|
|
|
|
|
|
|
|
# Case 8: UDP communication via NAT64
|
|
|
|
# Thread device (IPV6) send udp message to the host device (IPV4) via NAT64.
|
|
|
|
|
|
|
|
# Case 9: TCP communication via NAT64
|
|
|
|
# Thread device (IPV6) send tcp message to the host device (IPV4) via NAT64.
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module', name='Init_avahi')
|
|
|
|
def fixture_Init_avahi() -> bool:
|
|
|
|
print('Init Avahi')
|
|
|
|
ocf.start_avahi()
|
|
|
|
time.sleep(10)
|
|
|
|
return True
|
|
|
|
|
2022-08-16 22:57:39 -04:00
|
|
|
|
|
|
|
@pytest.fixture(name='Init_interface')
|
|
|
|
def fixture_Init_interface() -> bool:
|
2022-09-23 10:11:18 -04:00
|
|
|
print('Init interface')
|
2022-08-16 22:57:39 -04:00
|
|
|
ocf.init_interface_ipv6_address()
|
|
|
|
ocf.reset_host_interface()
|
2022-10-12 23:55:36 -04:00
|
|
|
time.sleep(30)
|
2022-08-16 22:57:39 -04:00
|
|
|
ocf.set_interface_sysctl_options()
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2023-01-11 04:11:32 -05:00
|
|
|
default_br_ot_para = ocf.thread_parameter('leader', '', '12', '7766554433221100', True)
|
|
|
|
default_br_wifi_para = ocf.wifi_parameter('OTCITE', 'otcitest888', 10)
|
2023-03-22 04:26:29 -04:00
|
|
|
default_cli_ot_para = ocf.thread_parameter('router', '', '', '', False)
|
2022-10-12 23:55:36 -04:00
|
|
|
|
|
|
|
|
2022-08-16 22:57:39 -04:00
|
|
|
# Case 1: Thread network formation and attaching
|
2023-03-22 04:26:29 -04:00
|
|
|
@pytest.mark.supported_targets
|
2023-02-24 03:02:12 -05:00
|
|
|
@pytest.mark.esp32h2
|
2023-01-11 04:11:32 -05:00
|
|
|
@pytest.mark.esp32c6
|
|
|
|
@pytest.mark.openthread_br
|
2023-04-06 03:54:16 -04:00
|
|
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
2022-08-16 22:57:39 -04:00
|
|
|
@pytest.mark.parametrize(
|
2023-03-22 04:26:29 -04:00
|
|
|
'config, count, app_path, target', [
|
|
|
|
('rcp|cli_h2|br', 3,
|
2022-10-12 23:55:36 -04:00
|
|
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
2022-08-16 22:57:39 -04:00
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
|
2023-03-22 04:26:29 -04:00
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
|
|
|
'esp32c6|esp32h2|esp32s3'),
|
2022-08-16 22:57:39 -04:00
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
2023-03-22 04:26:29 -04:00
|
|
|
def test_thread_connect(dut:Tuple[IdfDut, IdfDut, IdfDut]) -> None:
|
2022-10-12 23:55:36 -04:00
|
|
|
br = dut[2]
|
2023-03-22 04:26:29 -04:00
|
|
|
cli_h2 = dut[1]
|
2022-09-23 10:11:18 -04:00
|
|
|
dut[0].serial.stop_redirect_thread()
|
2023-03-22 04:26:29 -04:00
|
|
|
cli_list = [cli_h2]
|
|
|
|
router_extaddr_list = ['7766554433221101']
|
2023-01-11 04:11:32 -05:00
|
|
|
|
|
|
|
ocf.reset_thread(br)
|
|
|
|
for cli in cli_list:
|
|
|
|
ocf.reset_thread(cli)
|
|
|
|
br_ot_para = default_br_ot_para
|
|
|
|
ocf.joinThreadNetwork(br, br_ot_para)
|
|
|
|
cli_ot_para = default_cli_ot_para
|
|
|
|
cli_ot_para.dataset = ocf.getDataset(br)
|
2022-08-16 22:57:39 -04:00
|
|
|
try:
|
2023-01-11 04:11:32 -05:00
|
|
|
order = 0
|
|
|
|
for cli in cli_list:
|
|
|
|
cli_ot_para.exaddr = router_extaddr_list[order]
|
|
|
|
order = order + 1
|
|
|
|
ocf.joinThreadNetwork(cli, cli_ot_para)
|
|
|
|
for cli in cli_list:
|
|
|
|
cli_mleid_addr = ocf.get_mleid_addr(cli)
|
|
|
|
br_mleid_addr = ocf.get_mleid_addr(br)
|
|
|
|
rx_nums = ocf.ot_ping(cli, br_mleid_addr, 5)[1]
|
|
|
|
assert rx_nums == 5
|
|
|
|
rx_nums = ocf.ot_ping(br, cli_mleid_addr, 5)[1]
|
|
|
|
assert rx_nums == 5
|
2022-08-16 22:57:39 -04:00
|
|
|
finally:
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'factoryreset')
|
2023-01-11 04:11:32 -05:00
|
|
|
for cli in cli_list:
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, 'factoryreset')
|
2022-08-16 22:57:39 -04:00
|
|
|
time.sleep(3)
|
2023-01-11 04:11:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
# Form a Wi-Fi/Thread network with a Wi-Fi host, a border router and a Thread end device
|
|
|
|
# Topology:
|
|
|
|
# Border_Router
|
|
|
|
# / \
|
|
|
|
# / \
|
|
|
|
# Wi-FI_Host Thread_End_Device
|
|
|
|
def formBasicWiFiThreadNetwork(br:IdfDut, cli:IdfDut) -> None:
|
|
|
|
ocf.reset_thread(br)
|
|
|
|
ocf.reset_thread(cli)
|
|
|
|
ocf.joinWiFiNetwork(br, default_br_wifi_para)
|
|
|
|
ocf.joinThreadNetwork(br, default_br_ot_para)
|
|
|
|
ot_para = default_cli_ot_para
|
|
|
|
ot_para.dataset = ocf.getDataset(br)
|
|
|
|
ot_para.exaddr = '7766554433221101'
|
|
|
|
ocf.joinThreadNetwork(cli, ot_para)
|
|
|
|
ocf.wait(cli,10)
|
2022-08-16 22:57:39 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Case 2: Bidirectional IPv6 connectivity
|
2023-03-22 04:26:29 -04:00
|
|
|
@pytest.mark.supported_targets
|
|
|
|
@pytest.mark.esp32h2
|
|
|
|
@pytest.mark.esp32c6
|
2023-01-11 04:11:32 -05:00
|
|
|
@pytest.mark.openthread_br
|
2023-06-06 22:36:29 -04:00
|
|
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
2022-08-16 22:57:39 -04:00
|
|
|
@pytest.mark.parametrize(
|
2023-03-22 04:26:29 -04:00
|
|
|
'config, count, app_path, target', [
|
|
|
|
('rcp|cli_h2|br', 3,
|
2022-10-12 23:55:36 -04:00
|
|
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
2022-08-16 22:57:39 -04:00
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
|
2022-10-12 23:55:36 -04:00
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
2023-03-22 04:26:29 -04:00
|
|
|
'esp32c6|esp32h2|esp32s3'),
|
2022-08-16 22:57:39 -04:00
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
2022-10-12 23:55:36 -04:00
|
|
|
def test_Bidirectional_IPv6_connectivity(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
|
|
|
|
br = dut[2]
|
2022-08-16 22:57:39 -04:00
|
|
|
cli = dut[1]
|
|
|
|
assert Init_interface
|
2022-09-23 10:11:18 -04:00
|
|
|
dut[0].serial.stop_redirect_thread()
|
2022-08-16 22:57:39 -04:00
|
|
|
|
2023-01-11 04:11:32 -05:00
|
|
|
formBasicWiFiThreadNetwork(br, cli)
|
2022-08-16 22:57:39 -04:00
|
|
|
try:
|
2022-10-12 23:55:36 -04:00
|
|
|
assert ocf.is_joined_wifi_network(br)
|
|
|
|
cli_global_unicast_addr = ocf.get_global_unicast_addr(cli, br)
|
|
|
|
print('cli_global_unicast_addr', cli_global_unicast_addr)
|
2022-08-16 22:57:39 -04:00
|
|
|
command = 'ping ' + str(cli_global_unicast_addr) + ' -c 10'
|
2022-10-12 23:55:36 -04:00
|
|
|
out_str = subprocess.getoutput(command)
|
|
|
|
print('ping result:\n', str(out_str))
|
2022-08-16 22:57:39 -04:00
|
|
|
role = re.findall(r' (\d+)%', str(out_str))[0]
|
|
|
|
assert role != '100'
|
|
|
|
interface_name = ocf.get_host_interface_name()
|
2023-04-28 06:56:01 -04:00
|
|
|
command = 'ifconfig ' + interface_name + ' | grep inet6 | grep global'
|
2022-08-16 22:57:39 -04:00
|
|
|
out_bytes = subprocess.check_output(command, shell=True, timeout=5)
|
|
|
|
out_str = out_bytes.decode('utf-8')
|
2023-04-28 06:56:01 -04:00
|
|
|
onlinkprefix = ocf.get_onlinkprefix(br)
|
|
|
|
host_global_unicast_addr = re.findall(r'\W+(%s(?:\w+:){3}\w+)\W+' % onlinkprefix, str(out_str))
|
2022-08-16 22:57:39 -04:00
|
|
|
rx_nums = 0
|
|
|
|
for ip_addr in host_global_unicast_addr:
|
|
|
|
txrx_nums = ocf.ot_ping(cli, str(ip_addr), 5)
|
|
|
|
rx_nums = rx_nums + int(txrx_nums[1])
|
|
|
|
assert rx_nums != 0
|
|
|
|
finally:
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'factoryreset')
|
|
|
|
ocf.execute_command(cli, 'factoryreset')
|
2022-08-16 22:57:39 -04:00
|
|
|
time.sleep(3)
|
|
|
|
|
|
|
|
|
|
|
|
# Case 3: Multicast forwarding from Wi-Fi to Thread network
|
2023-03-22 04:26:29 -04:00
|
|
|
@pytest.mark.supported_targets
|
|
|
|
@pytest.mark.esp32h2
|
|
|
|
@pytest.mark.esp32c6
|
2023-01-11 04:11:32 -05:00
|
|
|
@pytest.mark.openthread_br
|
2022-09-23 10:11:18 -04:00
|
|
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
2022-08-16 22:57:39 -04:00
|
|
|
@pytest.mark.parametrize(
|
2023-03-22 04:26:29 -04:00
|
|
|
'config, count, app_path, target', [
|
|
|
|
('rcp|cli_h2|br', 3,
|
2022-10-12 23:55:36 -04:00
|
|
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
2022-08-16 22:57:39 -04:00
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
|
2022-10-12 23:55:36 -04:00
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
2023-03-22 04:26:29 -04:00
|
|
|
'esp32c6|esp32h2|esp32s3'),
|
2022-08-16 22:57:39 -04:00
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
2022-10-12 23:55:36 -04:00
|
|
|
def test_multicast_forwarding_A(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
|
|
|
|
br = dut[2]
|
2022-08-16 22:57:39 -04:00
|
|
|
cli = dut[1]
|
|
|
|
assert Init_interface
|
2022-09-23 10:11:18 -04:00
|
|
|
dut[0].serial.stop_redirect_thread()
|
2022-08-16 22:57:39 -04:00
|
|
|
|
2023-01-11 04:11:32 -05:00
|
|
|
formBasicWiFiThreadNetwork(br, cli)
|
2022-08-16 22:57:39 -04:00
|
|
|
try:
|
2022-10-12 23:55:36 -04:00
|
|
|
assert ocf.is_joined_wifi_network(br)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'bbr')
|
2022-09-23 10:11:18 -04:00
|
|
|
br.expect('server16', timeout=5)
|
2022-10-12 23:55:36 -04:00
|
|
|
assert ocf.thread_is_joined_group(cli)
|
2022-08-16 22:57:39 -04:00
|
|
|
interface_name = ocf.get_host_interface_name()
|
|
|
|
command = 'ping -I ' + str(interface_name) + ' -t 64 ff04::125 -c 10'
|
2022-10-12 23:55:36 -04:00
|
|
|
out_str = subprocess.getoutput(command)
|
|
|
|
print('ping result:\n', str(out_str))
|
2022-08-16 22:57:39 -04:00
|
|
|
role = re.findall(r' (\d+)%', str(out_str))[0]
|
|
|
|
assert role != '100'
|
|
|
|
finally:
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'factoryreset')
|
|
|
|
ocf.execute_command(cli, 'factoryreset')
|
2022-08-16 22:57:39 -04:00
|
|
|
time.sleep(3)
|
|
|
|
|
|
|
|
|
|
|
|
# Case 4: Multicast forwarding from Thread to Wi-Fi network
|
2023-03-22 04:26:29 -04:00
|
|
|
@pytest.mark.supported_targets
|
|
|
|
@pytest.mark.esp32h2
|
|
|
|
@pytest.mark.esp32c6
|
2023-01-11 04:11:32 -05:00
|
|
|
@pytest.mark.openthread_br
|
2022-09-23 10:11:18 -04:00
|
|
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
2022-08-16 22:57:39 -04:00
|
|
|
@pytest.mark.parametrize(
|
2023-03-22 04:26:29 -04:00
|
|
|
'config, count, app_path, target', [
|
|
|
|
('rcp|cli_h2|br', 3,
|
2022-10-12 23:55:36 -04:00
|
|
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
2022-08-16 22:57:39 -04:00
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
|
2022-10-12 23:55:36 -04:00
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
2023-03-22 04:26:29 -04:00
|
|
|
'esp32c6|esp32h2|esp32s3'),
|
2022-08-16 22:57:39 -04:00
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
2022-10-12 23:55:36 -04:00
|
|
|
def test_multicast_forwarding_B(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
|
|
|
|
br = dut[2]
|
2022-08-16 22:57:39 -04:00
|
|
|
cli = dut[1]
|
|
|
|
assert Init_interface
|
2022-09-23 10:11:18 -04:00
|
|
|
dut[0].serial.stop_redirect_thread()
|
2022-08-16 22:57:39 -04:00
|
|
|
|
2023-01-11 04:11:32 -05:00
|
|
|
formBasicWiFiThreadNetwork(br, cli)
|
2022-08-16 22:57:39 -04:00
|
|
|
try:
|
2022-10-12 23:55:36 -04:00
|
|
|
assert ocf.is_joined_wifi_network(br)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'bbr')
|
2022-09-23 10:11:18 -04:00
|
|
|
br.expect('server16', timeout=5)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, 'udp open')
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
|
|
|
ocf.wait(cli, 3)
|
|
|
|
myudp = ocf.udp_parameter('INET6', '::', 5090, 'ff04::125', False, 15.0, b'')
|
|
|
|
udp_mission = threading.Thread(target=ocf.create_host_udp_server, args=(myudp, ))
|
|
|
|
udp_mission.start()
|
|
|
|
start_time = time.time()
|
|
|
|
while not myudp.init_flag:
|
|
|
|
if (time.time() - start_time) > 10:
|
|
|
|
assert False
|
|
|
|
for num in range(0, 3):
|
|
|
|
command = 'udp send ff04::125 5090 hello' + str(num)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
|
|
|
ocf.wait(cli, 0.5)
|
|
|
|
while udp_mission.is_alive():
|
|
|
|
time.sleep(1)
|
|
|
|
finally:
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'factoryreset')
|
|
|
|
ocf.execute_command(cli, 'factoryreset')
|
2022-09-23 10:11:18 -04:00
|
|
|
time.sleep(3)
|
|
|
|
assert b'hello' in myudp.udp_bytes
|
|
|
|
|
|
|
|
|
|
|
|
# Case 5: discover dervice published by Thread device
|
2023-03-22 04:26:29 -04:00
|
|
|
@pytest.mark.supported_targets
|
|
|
|
@pytest.mark.esp32h2
|
|
|
|
@pytest.mark.esp32c6
|
2023-01-11 04:11:32 -05:00
|
|
|
@pytest.mark.openthread_br
|
2022-09-23 10:11:18 -04:00
|
|
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
|
|
|
@pytest.mark.parametrize(
|
2023-03-22 04:26:29 -04:00
|
|
|
'config, count, app_path, target', [
|
|
|
|
('rcp|cli_h2|br', 3,
|
2022-09-23 10:11:18 -04:00
|
|
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
2023-03-22 04:26:29 -04:00
|
|
|
'esp32c6|esp32h2|esp32s3'),
|
2022-09-23 10:11:18 -04:00
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
|
|
|
def test_service_discovery_of_Thread_device(Init_interface:bool, Init_avahi:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
|
|
|
|
br = dut[2]
|
|
|
|
cli = dut[1]
|
|
|
|
assert Init_interface
|
|
|
|
assert Init_avahi
|
|
|
|
dut[0].serial.stop_redirect_thread()
|
|
|
|
|
2023-01-11 04:11:32 -05:00
|
|
|
formBasicWiFiThreadNetwork(br, cli)
|
2022-09-23 10:11:18 -04:00
|
|
|
try:
|
|
|
|
assert ocf.is_joined_wifi_network(br)
|
|
|
|
command = 'avahi-browse -rt _testyyy._udp'
|
|
|
|
out_str = subprocess.getoutput(command)
|
|
|
|
print('avahi-browse:\n', str(out_str))
|
|
|
|
assert 'myTest' not in str(out_str)
|
|
|
|
hostname = 'myTest'
|
|
|
|
command = 'srp client host name ' + hostname
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
|
|
|
cli_global_unicast_addr = ocf.get_global_unicast_addr(cli, br)
|
|
|
|
print('cli_global_unicast_addr', cli_global_unicast_addr)
|
|
|
|
command = 'srp client host address ' + str(cli_global_unicast_addr)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
|
|
|
port = '12348'
|
|
|
|
command = 'srp client service add my-service _testyyy._udp ' + port
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, 'srp client autostart enable')
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
|
|
|
ocf.wait(cli, 3)
|
|
|
|
command = 'avahi-browse -rt _testyyy._udp'
|
|
|
|
out_str = subprocess.getoutput(command)
|
|
|
|
print('avahi-browse:\n', str(out_str))
|
|
|
|
assert 'myTest' in str(out_str)
|
|
|
|
finally:
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'factoryreset')
|
|
|
|
ocf.execute_command(cli, 'factoryreset')
|
2022-09-23 10:11:18 -04:00
|
|
|
time.sleep(3)
|
|
|
|
|
|
|
|
|
|
|
|
# Case 6: discover dervice published by Wi-Fi device
|
2023-03-22 04:26:29 -04:00
|
|
|
@pytest.mark.supported_targets
|
|
|
|
@pytest.mark.esp32h2
|
|
|
|
@pytest.mark.esp32c6
|
2023-01-11 04:11:32 -05:00
|
|
|
@pytest.mark.openthread_br
|
2022-09-23 10:11:18 -04:00
|
|
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
|
|
|
@pytest.mark.parametrize(
|
2023-03-22 04:26:29 -04:00
|
|
|
'config, count, app_path, target', [
|
|
|
|
('rcp|cli_h2|br', 3,
|
2022-09-23 10:11:18 -04:00
|
|
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
2023-03-22 04:26:29 -04:00
|
|
|
'esp32c6|esp32h2|esp32s3'),
|
2022-09-23 10:11:18 -04:00
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
|
|
|
def test_service_discovery_of_WiFi_device(Init_interface:bool, Init_avahi:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
|
|
|
|
br = dut[2]
|
|
|
|
cli = dut[1]
|
|
|
|
assert Init_interface
|
|
|
|
assert Init_avahi
|
|
|
|
dut[0].serial.stop_redirect_thread()
|
|
|
|
|
2023-01-11 04:11:32 -05:00
|
|
|
formBasicWiFiThreadNetwork(br, cli)
|
2022-09-23 10:11:18 -04:00
|
|
|
try:
|
|
|
|
assert ocf.is_joined_wifi_network(br)
|
|
|
|
br_global_unicast_addr = ocf.get_global_unicast_addr(br, br)
|
|
|
|
command = 'dns config ' + br_global_unicast_addr
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
2022-10-12 23:55:36 -04:00
|
|
|
ocf.wait(cli, 1)
|
2022-09-23 10:11:18 -04:00
|
|
|
command = 'dns resolve FA000123.default.service.arpa.'
|
|
|
|
ocf.clean_buffer(cli)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Error', timeout=15)
|
|
|
|
domain_name = ocf.get_domain()
|
|
|
|
print('domain name is: ', domain_name)
|
|
|
|
command = 'dns resolve ' + domain_name + '.default.service.arpa.'
|
2023-04-28 06:56:01 -04:00
|
|
|
|
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('TTL', timeout=10)
|
|
|
|
cli.expect('Done', timeout=10)
|
2023-04-28 06:56:01 -04:00
|
|
|
|
|
|
|
command = 'dns browse _testxxx._udp.default.service.arpa'
|
|
|
|
tmp = ocf.get_ouput_string(cli, command, 5)
|
2022-09-23 10:11:18 -04:00
|
|
|
assert 'Port:12347' not in str(tmp)
|
|
|
|
ocf.host_publish_service()
|
|
|
|
ocf.wait(cli, 5)
|
2023-04-28 06:56:01 -04:00
|
|
|
|
|
|
|
command = 'dns browse _testxxx._udp.default.service.arpa'
|
|
|
|
tmp = ocf.get_ouput_string(cli, command, 5)
|
2022-09-23 10:11:18 -04:00
|
|
|
assert 'response for _testxxx' in str(tmp)
|
|
|
|
assert 'Port:12347' in str(tmp)
|
2023-04-28 06:56:01 -04:00
|
|
|
|
|
|
|
command = 'dns browse _testxxx._udp.default.service.arpa'
|
|
|
|
tmp = ocf.get_ouput_string(cli, command, 5)
|
|
|
|
ocf.execute_command(cli, 'dns service testxxx _testxxx._udp.default.service.arpa.')
|
2022-09-23 10:11:18 -04:00
|
|
|
tmp = cli.expect(pexpect.TIMEOUT, timeout=5)
|
|
|
|
assert 'response for testxxx' in str(tmp)
|
|
|
|
assert 'Port:12347' in str(tmp)
|
|
|
|
finally:
|
|
|
|
ocf.host_close_service()
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'factoryreset')
|
|
|
|
ocf.execute_command(cli, 'factoryreset')
|
2022-09-23 10:11:18 -04:00
|
|
|
time.sleep(3)
|
|
|
|
|
|
|
|
|
|
|
|
# Case 7: ICMP communication via NAT64
|
2023-03-22 04:26:29 -04:00
|
|
|
@pytest.mark.supported_targets
|
|
|
|
@pytest.mark.esp32h2
|
|
|
|
@pytest.mark.esp32c6
|
2023-01-11 04:11:32 -05:00
|
|
|
@pytest.mark.openthread_br
|
2022-09-23 10:11:18 -04:00
|
|
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
|
|
|
@pytest.mark.parametrize(
|
2023-03-22 04:26:29 -04:00
|
|
|
'config, count, app_path, target', [
|
|
|
|
('rcp|cli_h2|br', 3,
|
2022-09-23 10:11:18 -04:00
|
|
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
2023-03-22 04:26:29 -04:00
|
|
|
'esp32c6|esp32h2|esp32s3'),
|
2022-09-23 10:11:18 -04:00
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
|
|
|
def test_ICMP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
|
|
|
|
br = dut[2]
|
|
|
|
cli = dut[1]
|
|
|
|
assert Init_interface
|
|
|
|
dut[0].serial.stop_redirect_thread()
|
|
|
|
|
2023-01-11 04:11:32 -05:00
|
|
|
formBasicWiFiThreadNetwork(br, cli)
|
2022-09-23 10:11:18 -04:00
|
|
|
try:
|
|
|
|
assert ocf.is_joined_wifi_network(br)
|
|
|
|
host_ipv4_address = ocf.get_host_ipv4_address()
|
|
|
|
print('host_ipv4_address: ', host_ipv4_address)
|
|
|
|
rx_nums = ocf.ot_ping(cli, str(host_ipv4_address), 5)[1]
|
|
|
|
assert rx_nums != 0
|
|
|
|
finally:
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'factoryreset')
|
|
|
|
ocf.execute_command(cli, 'factoryreset')
|
2022-09-23 10:11:18 -04:00
|
|
|
time.sleep(3)
|
|
|
|
|
|
|
|
|
|
|
|
# Case 8: UDP communication via NAT64
|
2023-03-22 04:26:29 -04:00
|
|
|
@pytest.mark.supported_targets
|
|
|
|
@pytest.mark.esp32h2
|
|
|
|
@pytest.mark.esp32c6
|
2023-01-11 04:11:32 -05:00
|
|
|
@pytest.mark.openthread_br
|
2022-09-23 10:11:18 -04:00
|
|
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
|
|
|
@pytest.mark.parametrize(
|
2023-03-22 04:26:29 -04:00
|
|
|
'config, count, app_path, target', [
|
|
|
|
('rcp|cli_h2|br', 3,
|
2022-09-23 10:11:18 -04:00
|
|
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
2023-03-22 04:26:29 -04:00
|
|
|
'esp32c6|esp32h2|esp32s3'),
|
2022-09-23 10:11:18 -04:00
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
|
|
|
def test_UDP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
|
|
|
|
br = dut[2]
|
|
|
|
cli = dut[1]
|
|
|
|
assert Init_interface
|
|
|
|
dut[0].serial.stop_redirect_thread()
|
|
|
|
|
2023-01-11 04:11:32 -05:00
|
|
|
formBasicWiFiThreadNetwork(br, cli)
|
2022-09-23 10:11:18 -04:00
|
|
|
try:
|
|
|
|
assert ocf.is_joined_wifi_network(br)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'bbr')
|
2022-09-23 10:11:18 -04:00
|
|
|
br.expect('server16', timeout=5)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, 'udp open')
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
|
|
|
ocf.wait(cli, 3)
|
|
|
|
host_ipv4_address = ocf.get_host_ipv4_address()
|
|
|
|
print('host_ipv4_address: ', host_ipv4_address)
|
|
|
|
myudp = ocf.udp_parameter('INET4', host_ipv4_address, 5090, '', False, 15.0, b'')
|
2022-10-12 23:55:36 -04:00
|
|
|
udp_mission = threading.Thread(target=ocf.create_host_udp_server, args=(myudp, ))
|
|
|
|
udp_mission.start()
|
|
|
|
start_time = time.time()
|
2022-09-23 10:11:18 -04:00
|
|
|
while not myudp.init_flag:
|
2022-10-12 23:55:36 -04:00
|
|
|
if (time.time() - start_time) > 10:
|
|
|
|
assert False
|
|
|
|
for num in range(0, 3):
|
2022-09-23 10:11:18 -04:00
|
|
|
command = 'udp send ' + host_ipv4_address + ' 5090 hello' + str(num)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
2022-10-12 23:55:36 -04:00
|
|
|
ocf.wait(cli, 0.5)
|
|
|
|
while udp_mission.is_alive():
|
|
|
|
time.sleep(1)
|
2022-08-16 22:57:39 -04:00
|
|
|
finally:
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'factoryreset')
|
|
|
|
ocf.execute_command(cli, 'factoryreset')
|
2022-08-16 22:57:39 -04:00
|
|
|
time.sleep(3)
|
2022-10-12 23:55:36 -04:00
|
|
|
assert b'hello' in myudp.udp_bytes
|
2022-09-23 10:11:18 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Case 9: TCP communication via NAT64
|
2023-03-22 04:26:29 -04:00
|
|
|
@pytest.mark.supported_targets
|
|
|
|
@pytest.mark.esp32h2
|
|
|
|
@pytest.mark.esp32c6
|
2023-01-11 04:11:32 -05:00
|
|
|
@pytest.mark.openthread_br
|
2022-09-23 10:11:18 -04:00
|
|
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
|
|
|
@pytest.mark.parametrize(
|
2023-03-22 04:26:29 -04:00
|
|
|
'config, count, app_path, target', [
|
|
|
|
('rcp|cli_h2|br', 3,
|
2022-09-23 10:11:18 -04:00
|
|
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
|
|
|
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
2023-03-22 04:26:29 -04:00
|
|
|
'esp32c6|esp32h2|esp32s3'),
|
2022-09-23 10:11:18 -04:00
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
|
|
|
def test_TCP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
|
|
|
|
br = dut[2]
|
|
|
|
cli = dut[1]
|
|
|
|
assert Init_interface
|
|
|
|
dut[0].serial.stop_redirect_thread()
|
|
|
|
|
2023-01-11 04:11:32 -05:00
|
|
|
formBasicWiFiThreadNetwork(br, cli)
|
2022-09-23 10:11:18 -04:00
|
|
|
try:
|
|
|
|
assert ocf.is_joined_wifi_network(br)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'bbr')
|
2022-09-23 10:11:18 -04:00
|
|
|
br.expect('server16', timeout=5)
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, 'tcpsockclient open')
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
|
|
|
ocf.wait(cli, 3)
|
|
|
|
host_ipv4_address = ocf.get_host_ipv4_address()
|
|
|
|
connect_address = ocf.get_ipv6_from_ipv4(host_ipv4_address, br)
|
|
|
|
print('connect_address is: ', connect_address)
|
|
|
|
mytcp = ocf.tcp_parameter('INET4', host_ipv4_address, 12345, False, False, 15.0, b'')
|
|
|
|
tcp_mission = threading.Thread(target=ocf.create_host_tcp_server, args=(mytcp, ))
|
|
|
|
tcp_mission.start()
|
|
|
|
start_time = time.time()
|
|
|
|
while not mytcp.listen_flag:
|
|
|
|
if (time.time() - start_time) > 10:
|
|
|
|
assert False
|
|
|
|
command = 'tcpsockclient connect ' + connect_address + ' 12345'
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Successfully connected', timeout=10)
|
|
|
|
start_time = time.time()
|
|
|
|
while not mytcp.recv_flag:
|
|
|
|
if (time.time() - start_time) > 10:
|
|
|
|
assert False
|
|
|
|
command = 'tcpsockclient send hello'
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(cli, command)
|
2022-09-23 10:11:18 -04:00
|
|
|
cli.expect('Done', timeout=5)
|
|
|
|
while tcp_mission.is_alive():
|
|
|
|
time.sleep(1)
|
|
|
|
finally:
|
2023-04-28 06:56:01 -04:00
|
|
|
ocf.execute_command(br, 'factoryreset')
|
|
|
|
ocf.execute_command(cli, 'factoryreset')
|
2022-09-23 10:11:18 -04:00
|
|
|
time.sleep(3)
|
|
|
|
assert b'hello' in mytcp.tcp_bytes
|