mirror of
https://github.com/espressif/openthread.git
synced 2026-08-21 09:59:52 +00:00
[cli] add support for DNS-SD command (#6116)
This commit adds new commands in CLI to support DNS-SD browse and service resolution.
This commit is contained in:
committed by
Jonathan Hui
parent
7084422a0e
commit
4538a5fb7c
@@ -2411,12 +2411,13 @@ class NodeImpl:
|
||||
self.simulator.go(10)
|
||||
output = self._expect_command_output(cmd)
|
||||
dns_resp = output[0]
|
||||
# example output: DNS response for host1.default.service.arpa. - fd00:db8:0:0:ae43:4938:4c42:e6af TTL: 7190
|
||||
ip, ttl = dns_resp.split(' - ')[1].split(' TTL: ')
|
||||
ip = ip.strip()
|
||||
ttl = int(ttl)
|
||||
# example output: "DNS response for host1.default.service.arpa. - fd00:db8:0:0:fd3d:d471:1e8c:b60 TTL:7190 "
|
||||
# " fd00:db8:0:0:0:ff:fe00:9000 TTL:7190"
|
||||
addrs = dns_resp.strip().split(' - ')[1].split(' ')
|
||||
ip = [item.strip() for item in addrs[::2]]
|
||||
ttl = [int(item.split('TTL:')[1]) for item in addrs[1::2]]
|
||||
|
||||
return (ip, ttl)
|
||||
return list(zip(ip, ttl))
|
||||
|
||||
|
||||
class Node(NodeImpl, OtCli):
|
||||
|
||||
@@ -88,11 +88,11 @@ class TestDnssd(thread_cert.TestCase):
|
||||
self._config_srp_client_services(CLIENT2, 'ins2', 'host2', 22222, 2, 2, client2_addrs)
|
||||
|
||||
# Test AAAA query using DNS client
|
||||
ip, ttl = self.nodes[CLIENT1].dns_resolve(f"host1.{DOMAIN}", self.nodes[SERVER].get_mleid(), 53)
|
||||
self.assertIn(ipaddress.IPv6Address(ip), map(ipaddress.IPv6Address, client1_addrs))
|
||||
response = self.nodes[CLIENT1].dns_resolve(f"host1.{DOMAIN}", self.nodes[SERVER].get_mleid(), 53)
|
||||
self.assertIn(ipaddress.IPv6Address(response[0][0]), map(ipaddress.IPv6Address, client1_addrs))
|
||||
|
||||
ip, ttl = self.nodes[CLIENT1].dns_resolve(f"host2.{DOMAIN}", self.nodes[SERVER].get_mleid(), 53)
|
||||
self.assertIn(ipaddress.IPv6Address(ip), map(ipaddress.IPv6Address, client2_addrs))
|
||||
response = self.nodes[CLIENT1].dns_resolve(f"host2.{DOMAIN}", self.nodes[SERVER].get_mleid(), 53)
|
||||
self.assertIn(ipaddress.IPv6Address(response[0][0]), map(ipaddress.IPv6Address, client2_addrs))
|
||||
|
||||
# TODO: test other query types using DNS-SD client
|
||||
|
||||
|
||||
Reference in New Issue
Block a user