[srp-client] add API to specify TTL (#7735)

This commit is contained in:
Jonathan Hui
2022-05-20 15:34:50 -07:00
committed by GitHub
parent 0f4531b22f
commit fcbc4bef9b
9 changed files with 122 additions and 6 deletions
+10
View File
@@ -1156,6 +1156,16 @@ class NodeImpl:
self.send_command(cmd)
return int(self._expect_result('\d+'))
def srp_client_set_ttl(self, ttl: int):
cmd = f'srp client ttl {ttl}'
self.send_command(cmd)
self._expect_done()
def srp_client_get_ttl(self) -> int:
cmd = 'srp client ttl'
self.send_command(cmd)
return int(self._expect_result('\d+'))
#
# TREL utilities
#
@@ -50,9 +50,11 @@ DEFAULT_LEASE_TIME = 7200
LEASE_TIME = 60
NEW_LEASE_TIME = 120
KEY_LEASE_TIME = 240
NEW_TTL = 10
assert LEASE_TIME < KEY_LEASE_TIME
assert NEW_LEASE_TIME < KEY_LEASE_TIME
assert NEW_TTL < NEW_LEASE_TIME
class SrpClientChangeLeaseTime(thread_cert.TestCase):
@@ -112,6 +114,14 @@ class SrpClientChangeLeaseTime(thread_cert.TestCase):
self.simulator.go(KEY_LEASE_TIME * 2)
self.assertEqual(client.srp_client_get_host_state(), 'Registered')
client.srp_client_set_ttl(NEW_TTL)
self.simulator.go(NEW_LEASE_TIME)
self.assertEqual(client.srp_client_get_host_state(), 'Registered')
client.srp_client_set_ttl(0)
self.simulator.go(NEW_LEASE_TIME)
self.assertEqual(client.srp_client_get_host_state(), 'Registered')
def verify(self, pv):
pkts: PacketFilter = pv.pkts
pv.summary.show()
@@ -122,6 +132,10 @@ class SrpClientChangeLeaseTime(thread_cert.TestCase):
DEFAULT_LEASE_TIME=DEFAULT_LEASE_TIME).must_next()
pkts.filter_wpan_src64(CLIENT_SRC64).filter('dns.flags.response == 0 and dns.resp.ttl == {NEW_LEASE_TIME}',
NEW_LEASE_TIME=NEW_LEASE_TIME).must_next()
pkts.filter_wpan_src64(CLIENT_SRC64).filter('dns.flags.response == 0 and dns.resp.ttl == {NEW_TTL}',
NEW_TTL=NEW_TTL).must_next()
pkts.filter_wpan_src64(CLIENT_SRC64).filter('dns.flags.response == 0 and dns.resp.ttl == {NEW_LEASE_TIME}',
NEW_LEASE_TIME=NEW_LEASE_TIME).must_next()
def check_host_and_service(self, server, client):
"""Check that we have properly registered host and service instance.