pytest_otbr.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Unlicense OR CC0-1.0
  3. # !/usr/bin/env python3
  4. import os.path
  5. import re
  6. import subprocess
  7. import threading
  8. import time
  9. from typing import Tuple
  10. import ot_ci_function as ocf
  11. import pexpect
  12. import pytest
  13. from pytest_embedded_idf.dut import IdfDut
  14. # This file contains the test scripts for Thread:
  15. # Case 1: Thread network formation and attaching
  16. # A Thread Border Router forms a Thread network, Thread devices attache to it, then test ping connection between them.
  17. # Case 2: Bidirectional IPv6 connectivity
  18. # Test IPv6 ping connection between Thread device and Linux Host (via Thread Border Router).
  19. # Case 3: Multicast forwarding from Wi-Fi to Thread network
  20. # Thread device joins the multicast group, then test group communication from Wi-Fi to Thread network.
  21. # Case 4: Multicast forwarding from Thread to Wi-Fi network
  22. # Linux Host joins the multicast group, test group communication from Thread to Wi-Fi network.
  23. # Case 5: discover Serice published by Thread device
  24. # Thread device publishes the service, Linux Host discovers the service on Wi-Fi network.
  25. # Case 6: discover Serice published by W-Fi device
  26. # Linux Host device publishes the service on Wi-Fi network, Thread device discovers the service.
  27. # Case 7: ICMP communication via NAT64
  28. # Thread device (IPV6) ping the host device (IPV4) via NAT64.
  29. # Case 8: UDP communication via NAT64
  30. # Thread device (IPV6) send udp message to the host device (IPV4) via NAT64.
  31. # Case 9: TCP communication via NAT64
  32. # Thread device (IPV6) send tcp message to the host device (IPV4) via NAT64.
  33. @pytest.fixture(scope='module', name='Init_avahi')
  34. def fixture_Init_avahi() -> bool:
  35. print('Init Avahi')
  36. ocf.start_avahi()
  37. time.sleep(10)
  38. return True
  39. @pytest.fixture(name='Init_interface')
  40. def fixture_Init_interface() -> bool:
  41. print('Init interface')
  42. ocf.init_interface_ipv6_address()
  43. ocf.reset_host_interface()
  44. time.sleep(30)
  45. ocf.set_interface_sysctl_options()
  46. return True
  47. default_br_ot_para = ocf.thread_parameter('leader', '', '12', '7766554433221100', True)
  48. default_br_wifi_para = ocf.wifi_parameter('OTCITE', 'otcitest888', 10)
  49. default_cli_ot_para = ocf.thread_parameter('router', '', '12', '', False)
  50. # Case 1: Thread network formation and attaching
  51. @pytest.mark.esp32s3
  52. @pytest.mark.esp32h2
  53. @pytest.mark.esp32h4
  54. @pytest.mark.esp32c6
  55. @pytest.mark.openthread_br
  56. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  57. @pytest.mark.parametrize(
  58. 'port, config, count, app_path, beta_target, target', [
  59. ('/dev/USB_RCP|/dev/USB_CLI|/dev/USB_BR|/dev/USB_CLI_C6', 'rcp|cli|br|cli_c6', 4,
  60. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  61. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  62. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}'
  63. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}',
  64. 'esp32h2beta2|esp32h2beta2|esp32s3|esp32c6', 'esp32h4|esp32h4|esp32s3|esp32c6'),
  65. ],
  66. indirect=True,
  67. )
  68. def test_thread_connect(dut:Tuple[IdfDut, IdfDut, IdfDut, IdfDut]) -> None:
  69. br = dut[2]
  70. cli_h2 = dut[1]
  71. cli_c6 = dut[3]
  72. dut[0].serial.stop_redirect_thread()
  73. cli_list = [cli_h2, cli_c6]
  74. router_extaddr_list = ['7766554433221101', '7766554433221102']
  75. ocf.reset_thread(br)
  76. for cli in cli_list:
  77. ocf.reset_thread(cli)
  78. br_ot_para = default_br_ot_para
  79. ocf.joinThreadNetwork(br, br_ot_para)
  80. cli_ot_para = default_cli_ot_para
  81. cli_ot_para.dataset = ocf.getDataset(br)
  82. try:
  83. order = 0
  84. for cli in cli_list:
  85. cli_ot_para.exaddr = router_extaddr_list[order]
  86. order = order + 1
  87. ocf.joinThreadNetwork(cli, cli_ot_para)
  88. for cli in cli_list:
  89. cli_mleid_addr = ocf.get_mleid_addr(cli)
  90. br_mleid_addr = ocf.get_mleid_addr(br)
  91. rx_nums = ocf.ot_ping(cli, br_mleid_addr, 5)[1]
  92. assert rx_nums == 5
  93. rx_nums = ocf.ot_ping(br, cli_mleid_addr, 5)[1]
  94. assert rx_nums == 5
  95. finally:
  96. br.write('factoryreset')
  97. for cli in cli_list:
  98. cli.write('factoryreset')
  99. time.sleep(3)
  100. # Form a Wi-Fi/Thread network with a Wi-Fi host, a border router and a Thread end device
  101. # Topology:
  102. # Border_Router
  103. # / \
  104. # / \
  105. # Wi-FI_Host Thread_End_Device
  106. def formBasicWiFiThreadNetwork(br:IdfDut, cli:IdfDut) -> None:
  107. ocf.reset_thread(br)
  108. ocf.reset_thread(cli)
  109. ocf.joinWiFiNetwork(br, default_br_wifi_para)
  110. ocf.joinThreadNetwork(br, default_br_ot_para)
  111. ot_para = default_cli_ot_para
  112. ot_para.dataset = ocf.getDataset(br)
  113. ot_para.exaddr = '7766554433221101'
  114. ocf.joinThreadNetwork(cli, ot_para)
  115. ocf.wait(cli,10)
  116. # Case 2: Bidirectional IPv6 connectivity
  117. @pytest.mark.esp32s3
  118. @pytest.mark.esp32h4
  119. @pytest.mark.openthread_br
  120. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  121. @pytest.mark.parametrize(
  122. 'port, config, count, app_path, beta_target, target', [
  123. ('/dev/USB_RCP|/dev/USB_CLI|/dev/USB_BR', 'rcp|cli|br', 3,
  124. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  125. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  126. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  127. 'esp32h2beta2|esp32h2beta2|esp32s3', 'esp32h4|esp32h4|esp32s3'),
  128. ],
  129. indirect=True,
  130. )
  131. def test_Bidirectional_IPv6_connectivity(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  132. br = dut[2]
  133. cli = dut[1]
  134. assert Init_interface
  135. dut[0].serial.stop_redirect_thread()
  136. formBasicWiFiThreadNetwork(br, cli)
  137. try:
  138. assert ocf.is_joined_wifi_network(br)
  139. cli_global_unicast_addr = ocf.get_global_unicast_addr(cli, br)
  140. print('cli_global_unicast_addr', cli_global_unicast_addr)
  141. command = 'ping ' + str(cli_global_unicast_addr) + ' -c 10'
  142. out_str = subprocess.getoutput(command)
  143. print('ping result:\n', str(out_str))
  144. role = re.findall(r' (\d+)%', str(out_str))[0]
  145. assert role != '100'
  146. interface_name = ocf.get_host_interface_name()
  147. command = 'ifconfig ' + interface_name
  148. out_bytes = subprocess.check_output(command, shell=True, timeout=5)
  149. out_str = out_bytes.decode('utf-8')
  150. host_global_unicast_addr = re.findall(r'inet6 ((?:\w+:){7}\w+) prefixlen 64 scopeid 0x0<global>', str(out_str))
  151. rx_nums = 0
  152. for ip_addr in host_global_unicast_addr:
  153. txrx_nums = ocf.ot_ping(cli, str(ip_addr), 5)
  154. rx_nums = rx_nums + int(txrx_nums[1])
  155. assert rx_nums != 0
  156. finally:
  157. br.write('factoryreset')
  158. cli.write('factoryreset')
  159. time.sleep(3)
  160. # Case 3: Multicast forwarding from Wi-Fi to Thread network
  161. @pytest.mark.esp32s3
  162. @pytest.mark.esp32h4
  163. @pytest.mark.openthread_br
  164. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  165. @pytest.mark.parametrize(
  166. 'port, config, count, app_path, beta_target, target', [
  167. ('/dev/USB_RCP|/dev/USB_CLI|/dev/USB_BR', 'rcp|cli|br', 3,
  168. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  169. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  170. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  171. 'esp32h2beta2|esp32h2beta2|esp32s3', 'esp32h4|esp32h4|esp32s3'),
  172. ],
  173. indirect=True,
  174. )
  175. def test_multicast_forwarding_A(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  176. br = dut[2]
  177. cli = dut[1]
  178. assert Init_interface
  179. dut[0].serial.stop_redirect_thread()
  180. formBasicWiFiThreadNetwork(br, cli)
  181. try:
  182. assert ocf.is_joined_wifi_network(br)
  183. br.write('bbr')
  184. br.expect('server16', timeout=5)
  185. assert ocf.thread_is_joined_group(cli)
  186. interface_name = ocf.get_host_interface_name()
  187. command = 'ping -I ' + str(interface_name) + ' -t 64 ff04::125 -c 10'
  188. out_str = subprocess.getoutput(command)
  189. print('ping result:\n', str(out_str))
  190. role = re.findall(r' (\d+)%', str(out_str))[0]
  191. assert role != '100'
  192. finally:
  193. br.write('factoryreset')
  194. cli.write('factoryreset')
  195. time.sleep(3)
  196. # Case 4: Multicast forwarding from Thread to Wi-Fi network
  197. @pytest.mark.esp32s3
  198. @pytest.mark.esp32h4
  199. @pytest.mark.openthread_br
  200. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  201. @pytest.mark.parametrize(
  202. 'port, config, count, app_path, beta_target, target', [
  203. ('/dev/USB_RCP|/dev/USB_CLI|/dev/USB_BR', 'rcp|cli|br', 3,
  204. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  205. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  206. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  207. 'esp32h2beta2|esp32h2beta2|esp32s3', 'esp32h4|esp32h4|esp32s3'),
  208. ],
  209. indirect=True,
  210. )
  211. def test_multicast_forwarding_B(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  212. br = dut[2]
  213. cli = dut[1]
  214. assert Init_interface
  215. dut[0].serial.stop_redirect_thread()
  216. formBasicWiFiThreadNetwork(br, cli)
  217. try:
  218. assert ocf.is_joined_wifi_network(br)
  219. br.write('bbr')
  220. br.expect('server16', timeout=5)
  221. cli.write('udp open')
  222. cli.expect('Done', timeout=5)
  223. ocf.wait(cli, 3)
  224. myudp = ocf.udp_parameter('INET6', '::', 5090, 'ff04::125', False, 15.0, b'')
  225. udp_mission = threading.Thread(target=ocf.create_host_udp_server, args=(myudp, ))
  226. udp_mission.start()
  227. start_time = time.time()
  228. while not myudp.init_flag:
  229. if (time.time() - start_time) > 10:
  230. assert False
  231. assert ocf.host_joined_group('ff04::125')
  232. for num in range(0, 3):
  233. command = 'udp send ff04::125 5090 hello' + str(num)
  234. cli.write(command)
  235. cli.expect('Done', timeout=5)
  236. ocf.wait(cli, 0.5)
  237. while udp_mission.is_alive():
  238. time.sleep(1)
  239. finally:
  240. br.write('factoryreset')
  241. cli.write('factoryreset')
  242. time.sleep(3)
  243. assert b'hello' in myudp.udp_bytes
  244. # Case 5: discover dervice published by Thread device
  245. @pytest.mark.esp32s3
  246. @pytest.mark.esp32h4
  247. @pytest.mark.openthread_br
  248. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  249. @pytest.mark.parametrize(
  250. 'port, config, count, app_path, beta_target, target', [
  251. ('/dev/USB_RCP|/dev/USB_CLI|/dev/USB_BR', 'rcp|cli|br', 3,
  252. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  253. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  254. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  255. 'esp32h2beta2|esp32h2beta2|esp32s3', 'esp32h4|esp32h4|esp32s3'),
  256. ],
  257. indirect=True,
  258. )
  259. def test_service_discovery_of_Thread_device(Init_interface:bool, Init_avahi:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  260. br = dut[2]
  261. cli = dut[1]
  262. assert Init_interface
  263. assert Init_avahi
  264. dut[0].serial.stop_redirect_thread()
  265. formBasicWiFiThreadNetwork(br, cli)
  266. try:
  267. assert ocf.is_joined_wifi_network(br)
  268. command = 'avahi-browse -rt _testyyy._udp'
  269. out_str = subprocess.getoutput(command)
  270. print('avahi-browse:\n', str(out_str))
  271. assert 'myTest' not in str(out_str)
  272. hostname = 'myTest'
  273. command = 'srp client host name ' + hostname
  274. cli.write(command)
  275. cli.expect('Done', timeout=5)
  276. cli_global_unicast_addr = ocf.get_global_unicast_addr(cli, br)
  277. print('cli_global_unicast_addr', cli_global_unicast_addr)
  278. command = 'srp client host address ' + str(cli_global_unicast_addr)
  279. cli.write(command)
  280. cli.expect('Done', timeout=5)
  281. port = '12348'
  282. command = 'srp client service add my-service _testyyy._udp ' + port
  283. cli.write(command)
  284. cli.expect('Done', timeout=5)
  285. cli.write('srp client autostart enable')
  286. cli.expect('Done', timeout=5)
  287. ocf.wait(cli, 3)
  288. command = 'avahi-browse -rt _testyyy._udp'
  289. out_str = subprocess.getoutput(command)
  290. print('avahi-browse:\n', str(out_str))
  291. assert 'myTest' in str(out_str)
  292. finally:
  293. br.write('factoryreset')
  294. cli.write('factoryreset')
  295. time.sleep(3)
  296. # Case 6: discover dervice published by Wi-Fi device
  297. @pytest.mark.esp32s3
  298. @pytest.mark.esp32h4
  299. @pytest.mark.openthread_br
  300. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  301. @pytest.mark.parametrize(
  302. 'port, config, count, app_path, beta_target, target', [
  303. ('/dev/USB_RCP|/dev/USB_CLI|/dev/USB_BR', 'rcp|cli|br', 3,
  304. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  305. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  306. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  307. 'esp32h2beta2|esp32h2beta2|esp32s3', 'esp32h4|esp32h4|esp32s3'),
  308. ],
  309. indirect=True,
  310. )
  311. def test_service_discovery_of_WiFi_device(Init_interface:bool, Init_avahi:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  312. br = dut[2]
  313. cli = dut[1]
  314. assert Init_interface
  315. assert Init_avahi
  316. dut[0].serial.stop_redirect_thread()
  317. formBasicWiFiThreadNetwork(br, cli)
  318. try:
  319. assert ocf.is_joined_wifi_network(br)
  320. br_global_unicast_addr = ocf.get_global_unicast_addr(br, br)
  321. command = 'dns config ' + br_global_unicast_addr
  322. ocf.clean_buffer(cli)
  323. cli.write(command)
  324. cli.expect('Done', timeout=5)
  325. ocf.wait(cli, 1)
  326. command = 'dns resolve FA000123.default.service.arpa.'
  327. ocf.clean_buffer(cli)
  328. cli.write(command)
  329. cli.expect('Error', timeout=15)
  330. domain_name = ocf.get_domain()
  331. print('domain name is: ', domain_name)
  332. command = 'dns resolve ' + domain_name + '.default.service.arpa.'
  333. ocf.clean_buffer(cli)
  334. cli.write(command)
  335. cli.expect('TTL', timeout=10)
  336. cli.expect('Done', timeout=10)
  337. ocf.clean_buffer(cli)
  338. cli.write('dns browse _testxxx._udp.default.service.arpa')
  339. tmp = cli.expect(pexpect.TIMEOUT, timeout=5)
  340. assert 'Port:12347' not in str(tmp)
  341. ocf.host_publish_service()
  342. ocf.wait(cli, 5)
  343. ocf.clean_buffer(cli)
  344. cli.write('dns browse _testxxx._udp.default.service.arpa')
  345. tmp = cli.expect(pexpect.TIMEOUT, timeout=5)
  346. assert 'response for _testxxx' in str(tmp)
  347. assert 'Port:12347' in str(tmp)
  348. ocf.clean_buffer(cli)
  349. cli.write('dns service testxxx _testxxx._udp.default.service.arpa.')
  350. tmp = cli.expect(pexpect.TIMEOUT, timeout=5)
  351. assert 'response for testxxx' in str(tmp)
  352. assert 'Port:12347' in str(tmp)
  353. finally:
  354. ocf.host_close_service()
  355. br.write('factoryreset')
  356. cli.write('factoryreset')
  357. time.sleep(3)
  358. # Case 7: ICMP communication via NAT64
  359. @pytest.mark.esp32s3
  360. @pytest.mark.esp32h4
  361. @pytest.mark.openthread_br
  362. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  363. @pytest.mark.parametrize(
  364. 'port, config, count, app_path, beta_target, target', [
  365. ('/dev/USB_RCP|/dev/USB_CLI|/dev/USB_BR', 'rcp|cli|br', 3,
  366. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  367. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  368. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  369. 'esp32h2beta2|esp32h2beta2|esp32s3', 'esp32h4|esp32h4|esp32s3'),
  370. ],
  371. indirect=True,
  372. )
  373. def test_ICMP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  374. br = dut[2]
  375. cli = dut[1]
  376. assert Init_interface
  377. dut[0].serial.stop_redirect_thread()
  378. formBasicWiFiThreadNetwork(br, cli)
  379. try:
  380. assert ocf.is_joined_wifi_network(br)
  381. host_ipv4_address = ocf.get_host_ipv4_address()
  382. print('host_ipv4_address: ', host_ipv4_address)
  383. rx_nums = ocf.ot_ping(cli, str(host_ipv4_address), 5)[1]
  384. assert rx_nums != 0
  385. finally:
  386. br.write('factoryreset')
  387. cli.write('factoryreset')
  388. time.sleep(3)
  389. # Case 8: UDP communication via NAT64
  390. @pytest.mark.esp32s3
  391. @pytest.mark.esp32h4
  392. @pytest.mark.openthread_br
  393. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  394. @pytest.mark.parametrize(
  395. 'port, config, count, app_path, beta_target, target', [
  396. ('/dev/USB_RCP|/dev/USB_CLI|/dev/USB_BR', 'rcp|cli|br', 3,
  397. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  398. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  399. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  400. 'esp32h2beta2|esp32h2beta2|esp32s3', 'esp32h4|esp32h4|esp32s3'),
  401. ],
  402. indirect=True,
  403. )
  404. def test_UDP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  405. br = dut[2]
  406. cli = dut[1]
  407. assert Init_interface
  408. dut[0].serial.stop_redirect_thread()
  409. formBasicWiFiThreadNetwork(br, cli)
  410. try:
  411. assert ocf.is_joined_wifi_network(br)
  412. br.write('bbr')
  413. br.expect('server16', timeout=5)
  414. cli.write('udp open')
  415. cli.expect('Done', timeout=5)
  416. ocf.wait(cli, 3)
  417. host_ipv4_address = ocf.get_host_ipv4_address()
  418. print('host_ipv4_address: ', host_ipv4_address)
  419. myudp = ocf.udp_parameter('INET4', host_ipv4_address, 5090, '', False, 15.0, b'')
  420. udp_mission = threading.Thread(target=ocf.create_host_udp_server, args=(myudp, ))
  421. udp_mission.start()
  422. start_time = time.time()
  423. while not myudp.init_flag:
  424. if (time.time() - start_time) > 10:
  425. assert False
  426. for num in range(0, 3):
  427. command = 'udp send ' + host_ipv4_address + ' 5090 hello' + str(num)
  428. cli.write(command)
  429. cli.expect('Done', timeout=5)
  430. ocf.wait(cli, 0.5)
  431. while udp_mission.is_alive():
  432. time.sleep(1)
  433. finally:
  434. br.write('factoryreset')
  435. cli.write('factoryreset')
  436. time.sleep(3)
  437. assert b'hello' in myudp.udp_bytes
  438. # Case 9: TCP communication via NAT64
  439. @pytest.mark.esp32s3
  440. @pytest.mark.esp32h4
  441. @pytest.mark.openthread_br
  442. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  443. @pytest.mark.parametrize(
  444. 'port, config, count, app_path, beta_target, target', [
  445. ('/dev/USB_RCP|/dev/USB_CLI|/dev/USB_BR', 'rcp|cli|br', 3,
  446. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  447. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  448. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  449. 'esp32h2beta2|esp32h2beta2|esp32s3', 'esp32h4|esp32h4|esp32s3'),
  450. ],
  451. indirect=True,
  452. )
  453. def test_TCP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  454. br = dut[2]
  455. cli = dut[1]
  456. assert Init_interface
  457. dut[0].serial.stop_redirect_thread()
  458. formBasicWiFiThreadNetwork(br, cli)
  459. try:
  460. assert ocf.is_joined_wifi_network(br)
  461. br.write('bbr')
  462. br.expect('server16', timeout=5)
  463. cli.write('tcpsockclient open')
  464. cli.expect('Done', timeout=5)
  465. ocf.wait(cli, 3)
  466. host_ipv4_address = ocf.get_host_ipv4_address()
  467. connect_address = ocf.get_ipv6_from_ipv4(host_ipv4_address, br)
  468. print('connect_address is: ', connect_address)
  469. mytcp = ocf.tcp_parameter('INET4', host_ipv4_address, 12345, False, False, 15.0, b'')
  470. tcp_mission = threading.Thread(target=ocf.create_host_tcp_server, args=(mytcp, ))
  471. tcp_mission.start()
  472. start_time = time.time()
  473. while not mytcp.listen_flag:
  474. if (time.time() - start_time) > 10:
  475. assert False
  476. command = 'tcpsockclient connect ' + connect_address + ' 12345'
  477. cli.write(command)
  478. cli.expect('Successfully connected', timeout=10)
  479. start_time = time.time()
  480. while not mytcp.recv_flag:
  481. if (time.time() - start_time) > 10:
  482. assert False
  483. command = 'tcpsockclient send hello'
  484. cli.write(command)
  485. cli.expect('Done', timeout=5)
  486. while tcp_mission.is_alive():
  487. time.sleep(1)
  488. finally:
  489. br.write('factoryreset')
  490. cli.write('factoryreset')
  491. time.sleep(3)
  492. assert b'hello' in mytcp.tcp_bytes