OpenThread offers both SRP server and client functionality, enabling devices to register DNS-based services using the standard DNS Update sent as unicast packets. This functionality enables DNS-Based Service Discovery.
This guide provides basic tasks that use some of the more common srp server
and srp client commands.
SRP server commands
For a list of srp server commands, type help:
srp server help
addrmode
auto
disable
domain
enable
help
host
lease
seqnum
service
state
Done
SRP client commands
For a list of srp client commands, type help:
srp client help
autostart
callback
help
host
keyleaseinterval
leaseinterval
service
start
state
stop
ttl
Done
CLI Command Reference
For descriptions and syntax of all commands, refer to the CLI Command Reference. The SRP server commands begin alphabetically with srp server (enable,disable). The SRP client commands begin alphabetically with srp client autostart (get).
Thread Border Router codelab
The OpenThread Border Router codelab includes information about how to set up the SRP client end device.
Overviews of some basic SRP commands
SRP server and client commands can be used in sequence to perform typical SRP tasks:
-
srp server enableenables the SRP server once you have created the Thread network. -
srp client host namesets the host name to be used by the client.srp client host address (set)either enables auto host client address mode or explicitly sets the list of host client addresses.srp client service addadds a service with a given instance name, service name, and port number.srp client autostart enableenables auto-start mode. You can also manually start the client by runningsrp client start.
-
srp client hostandsrp client serviceprovide status about whether the client host and service have been successfully registered on the client node.srp server hostandsrp server serviceprovide host and service status on the server node.
-
srp client service removeremoves a service but retains the service name. Remove the host and service names.
srp client host removeremoves the host and all registered services.
Examples of SRP server and client command usage
These examples use basic CLI commands to set up a Thread network, start the SRP server and client, verify server status, and remove a service. Sample data is used for illustrative purposes.
Start the SRP server
Start the SRP server node:
./output/simulation/bin/ot-cli-ftd 1Set up a Thread network, then enable the SRP server by running the
srp server enablecommand:dataset init newDonedatasetActive Timestamp: 1 Channel: 22 Channel Mask: 0x07fff800 Ext PAN ID: 8d6ed7a05a28fb3b Mesh Local Prefix: fded:5114:8263:1fe1::/64 Network Key: 7fcbae4153cc2955c28440c15d4d4219 Network Name: OpenThread-f7af PAN ID: 0xf7af PSKc: b658e40f174e3a11be149b302ef07a0f Security Policy: 672, onrc Donedataset commit activeDoneifconfig upDonethread startDonestateleader Doneipaddrfded:5114:8263:1fe1:0:ff:fe00:fc00 fded:5114:8263:1fe1:0:ff:fe00:c000 fded:5114:8263:1fe1:68bc:ec03:c1ad:9325 fe80:0:0:0:a8cd:6e23:df3d:4193 Donesrp server enableDone
Start the SRP client
Start the SRP Client node:
./output/simulation/bin/ot-cli-ftd 2Join the Thread network, set the client host name and address, and register a service:
dataset networkkey 7fcbae4153cc2955c28440c15d4d4219Donedataset commit activeDoneifconfig upDonethread startDonestatechild Doneipaddrfded:5114:8263:1fe1:0:ff:fe00:c001 fded:5114:8263:1fe1:44f9:cc06:4a2d:534 fe80:0:0:0:38dd:fdf7:5fd:24e Donesrp client host name my-hostDonesrp client host address fded:5114:8263:1fe1:44f9:cc06:4a2d:534Donesrp client service add my-service _ipps._tcp 12345Donesrp client autostart enableDoneAs shown above, use the
srp client autostart enablecommand to enable auto-start mode on the client. The client monitors network data to discover available SRP servers within the Thread network, then the client automatically starts itself.If manually starting the client, run the following, and include the SRP address and port:
srp client start fded:5114:8263:1fe1:68bc:ec03:c1ad:9325 49154DoneThe SRP server listening UDP port is
c002(49154)in the example above.
Verify the service status
Check if the host and service have been successfully registered on the client node:
srp client hostname:"my-host", state:Registered, addrs:[fded:5114:8263:1fe1:44f9:cc06:4a2d:534] Donesrp client serviceinstance:"my-service", name:"_ipps._tcp", state:Registered, port:12345, priority:0, weight:0 DoneMake sure the output shows
state:Registeredfor both host and service commands, as in the above example.Check the host and service on the server node:
srp server hostmy-host.default.service.arpa. deleted: false addresses: [fded:5114:8263:1fe1:44f9:cc06:4a2d:534] Donesrp server servicemy-service._ipps._tcp.default.service.arpa. deleted: false port: 12345 priority: 0 weight: 0 ttl: 7200 lease: 7200 key-lease: 1209600 TXT: [] host: my-host.default.service.arpa. addresses: [fded:5114:8263:1fe1:44f9:cc06:4a2d:534] DoneMake sure the output shows
deleted: falsefor both thesrp server hostandsrp server servicecommands, as in the example above.
Remove the service
Remove the service via the client node:
srp client service remove my-service _ipps._tcpDoneConfirm via the server node that the service has been removed:
srp server servicemy-service._ipps._tcp.default.service.arpa. deleted: true DoneThe service entry is listed in the output because the name of service is not removed.
Remove the host and service names
Remove the host and all its registered services:
srp client host remove 1DoneConfirm on the server node that no host or service entries are listed:
srp server hostDonesrp server serviceDone >