diff --git a/include/openthread/instance.h b/include/openthread/instance.h index eba6c33d4..1a68a8d4a 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (440) +#define OPENTHREAD_API_VERSION (441) /** * @addtogroup api-instance diff --git a/include/openthread/trel.h b/include/openthread/trel.h index e9a0bf00a..dd186fa59 100644 --- a/include/openthread/trel.h +++ b/include/openthread/trel.h @@ -184,6 +184,16 @@ const otTrelCounters *otTrelGetCounters(otInstance *aInstance); */ void otTrelResetCounters(otInstance *aInstance); +/** + * Gets the UDP port of the TREL interface. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns UDP port of the TREL interface. + * + */ +uint16_t otTrelGetUdpPort(otInstance *aInstance); + /** * @} * diff --git a/src/cli/README.md b/src/cli/README.md index 0b7c15f98..47af9a6a0 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -3948,6 +3948,16 @@ Done Done ``` +### trel port + +Get the TREL UDP port number. + +```bash +> trel port +49154 +Done +``` + ### tvcheck enable Enable thread version check when upgrading to router or leader. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 10994ca3c..5da53f96f 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -7577,6 +7577,20 @@ template <> otError Interpreter::Process(Arg aArgs[]) error = OT_ERROR_INVALID_ARGS; } } + /** + * @cli trel port + * @code + * trel port + * 49153 + * Done + * @endcode + * @par api_copy + * #otTrelGetUdpPort + */ + else if (aArgs[0] == "port") + { + OutputLine("%hu", otTrelGetUdpPort(GetInstancePtr())); + } else { error = OT_ERROR_INVALID_ARGS; diff --git a/src/core/api/trel_api.cpp b/src/core/api/trel_api.cpp index 09344d3d1..94e29a279 100644 --- a/src/core/api/trel_api.cpp +++ b/src/core/api/trel_api.cpp @@ -82,4 +82,6 @@ const otTrelCounters *otTrelGetCounters(otInstance *aInstance) void otTrelResetCounters(otInstance *aInstance) { AsCoreType(aInstance).Get().ResetCounters(); } +uint16_t otTrelGetUdpPort(otInstance *aInstance) { return AsCoreType(aInstance).Get().GetUdpPort(); } + #endif // OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE diff --git a/src/core/radio/trel_interface.hpp b/src/core/radio/trel_interface.hpp index 70b4eb0b5..a2e86a35a 100644 --- a/src/core/radio/trel_interface.hpp +++ b/src/core/radio/trel_interface.hpp @@ -256,6 +256,14 @@ public: */ void ResetCounters(void); + /** + * Returns the TREL UDP port. + * + * @returns The TREL UDP port. + * + */ + uint16_t GetUdpPort(void) const { return mUdpPort; } + private: #if OPENTHREAD_CONFIG_TREL_PEER_TABLE_SIZE != 0 static constexpr uint16_t kPeerTableSize = OPENTHREAD_CONFIG_TREL_PEER_TABLE_SIZE; diff --git a/tests/scripts/thread-cert/border_router/test_trel_connectivity.py b/tests/scripts/thread-cert/border_router/test_trel_connectivity.py index 20ed03932..42a3a1870 100755 --- a/tests/scripts/thread-cert/border_router/test_trel_connectivity.py +++ b/tests/scripts/thread-cert/border_router/test_trel_connectivity.py @@ -160,6 +160,8 @@ class TestTrelConnectivity(thread_cert.TestCase): self.assertTrue(counters['Outbound']['bytes'] == 0) self.assertTrue(counters['Outbound']['failures'] == 0) + self.assertGreater(br1.get_trel_port(), 0) + def verify(self, pv: PacketVerifier): pkts: PacketFilter = pv.pkts BR1_RLOC16 = pv.vars['BR1_RLOC16'] diff --git a/tests/scripts/thread-cert/node.py b/tests/scripts/thread-cert/node.py index 6da0f635b..39e801e89 100755 --- a/tests/scripts/thread-cert/node.py +++ b/tests/scripts/thread-cert/node.py @@ -1451,6 +1451,11 @@ class NodeImpl: self.send_command(cmd) self._expect_done() + def get_trel_port(self): + cmd = 'trel port' + self.send_command(cmd) + return int(self._expect_command_output()[0]) + def set_epskc(self, keystring: str, timeout=120000, port=0): cmd = 'ba ephemeralkey set ' + keystring + ' ' + str(timeout) + ' ' + str(port) self.send_command(cmd)