From: hyunuk.tak Date: Mon, 30 May 2022 07:47:14 +0000 (+0900) Subject: Add a new CAPI and test for thread_br_get_preference X-Git-Tag: accepted/tizen/unified/20220914.164046~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f921a6eae3c75b9506cd6d8657b76626dc48ff36;p=platform%2Fcore%2Fapi%2Fthread.git Add a new CAPI and test for thread_br_get_preference Change-Id: I6a469b91288a4fb74509024d56423528169ac37f Signed-off-by: hyunuk.tak --- diff --git a/include/thread.h b/include/thread.h index 6739477..97f6204 100644 --- a/include/thread.h +++ b/include/thread.h @@ -526,6 +526,24 @@ int thread_br_get_ipv6_prefix(thread_route_info_h route, int thread_br_get_rloc16(thread_route_info_h route, uint16_t *rloc16); +/** + * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE + * @brief Get preference for route + * @since_tizen 7.0 + * + * @return 0 on success, otherwise a negative error value. + * @retval #THREAD_ERROR_NONE Successful + * @retval #THREAD_ERROR_NOT_INITIALIZED Not initialized + * @retval #THREAD_ERROR_OPERATION_FAILED Operation failed + * @retval #THREAD_ERROR_NOT_SUPPORTED Not supported + * + * @pre thread API must be initialized with thread_initialize(). + * + * @see thread_external_route_foreach_cb() + */ +int thread_br_get_preference(thread_route_info_h route, + int8_t *preference); + /** * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE * @brief Add an external border routing rule to the network. diff --git a/src/thread-br.c b/src/thread-br.c index ed2a655..8d8b87d 100644 --- a/src/thread-br.c +++ b/src/thread-br.c @@ -311,6 +311,22 @@ int thread_br_get_rloc16(thread_route_info_h route, return THREAD_ERROR_NONE; } +int thread_br_get_preference(thread_route_info_h route, + int8_t *preference) +{ + FUNC_ENTRY; + THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON); + THREAD_CHECK_INIT_STATUS(); + THREAD_VALIDATE_INPUT_PARAMETER(route); + THREAD_VALIDATE_INPUT_PARAMETER(preference); + + thread_route_info_s *route_info = (thread_route_info_s*)route; + *preference = route_info->preference; + + FUNC_EXIT; + return THREAD_ERROR_NONE; +} + int thread_br_add_external_route(thread_instance_h instance, const uint8_t *ipv6_prefix, uint8_t ipv6_prefix_len, uint16_t rloc16, int8_t preference, diff --git a/tests/unittest/thread-unittest-br.cpp b/tests/unittest/thread-unittest-br.cpp index f05843a..bdf1c39 100644 --- a/tests/unittest/thread-unittest-br.cpp +++ b/tests/unittest/thread-unittest-br.cpp @@ -26,6 +26,7 @@ public: enum class RouteInfo { kIpv6Prefix, kRloc16, + kPreference, }; uint8_t ipv6Prefix[THREAD_IPV6_PREFIX_SIZE]; @@ -69,6 +70,12 @@ public: EXPECT_EQ(THREAD_ERROR_NONE, thread_br_get_rloc16(route_info, &rloc16)); } break; + case RouteInfo::kPreference: + { + int8_t preference; + EXPECT_EQ(THREAD_ERROR_NONE, thread_br_get_preference(route_info, &preference)); + } + break; default: break; } @@ -207,6 +214,15 @@ TEST_F(ThreadBRTest, BRGetRloc16ErrorNone) GUINT_TO_POINTER(static_cast(RouteInfo::kRloc16)))); } +TEST_F(ThreadBRTest, BRGetPreferenceErrorNone) +{ + EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance)); + EXPECT_EQ(THREAD_ERROR_NONE, thread_br_enable(instance)); + EXPECT_EQ(THREAD_ERROR_NONE, + thread_br_get_external_routes(instance, GetExternalRoutesCallback, + GUINT_TO_POINTER(static_cast(RouteInfo::kPreference)))); +} + TEST_F(ThreadBRTest, BRAddExternalRouteNotInitialized) { EXPECT_EQ(THREAD_ERROR_NONE, thread_deinitialize());