Add new CAPIs and unittest to get/set rloc for onmesh 86/276686/1
authorhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 20 Jun 2022 02:51:23 +0000 (11:51 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Thu, 23 Jun 2022 02:25:13 +0000 (11:25 +0900)
Change-Id: I68fa300d736897fc85b92c329c7b46687fa5b291
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
include/thread.h
src/thread-br.c
tests/unittest/thread-unittest-br.cpp

index ba65271..51863b9 100644 (file)
@@ -713,6 +713,44 @@ int thread_onmesh_prefix_get_preference(thread_onmesh_prefix_info_h onmesh_prefi
 
 /**
  * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
+ * @brief Set rloc to on-mesh prefix info
+ * @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_onmesh_prefix_create()
+ * @see thread_onmesh_prefix_destroy()
+ */
+int thread_onmesh_prefix_set_rloc(thread_onmesh_prefix_info_h onmesh_prefix,
+       uint16_t rloc);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
+ * @brief Get rloc to on-mesh prefix info
+ * @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_onmesh_prefix_create()
+ * @see thread_onmesh_prefix_destroy()
+ */
+int thread_onmesh_prefix_get_rloc(thread_onmesh_prefix_info_h onmesh_prefix,
+       uint16_t *rloc);
+
+/**
+ * @ingroup CAPI_NETWORK_THREAD_BORDERROUTER_MODULE
  * @brief Set preferred to on-mesh prefix info
  * @since_tizen 7.0
  *
index b9e9dec..75ec0c7 100644 (file)
@@ -658,6 +658,37 @@ int thread_onmesh_prefix_get_preference(thread_onmesh_prefix_info_h onmesh_prefi
        return THREAD_ERROR_NONE;
 }
 
+int thread_onmesh_prefix_set_rloc(thread_onmesh_prefix_info_h onmesh_prefix,
+       uint16_t rloc)
+{
+       FUNC_ENTRY;
+       THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+       THREAD_CHECK_INIT_STATUS();
+       THREAD_VALIDATE_INPUT_PARAMETER(onmesh_prefix);
+
+       thread_onmesh_prefix_info_s *onmesh_prefix_info =
+                                       (thread_onmesh_prefix_info_s *)onmesh_prefix;
+       onmesh_prefix_info->rloc = rloc;
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
+
+int thread_onmesh_prefix_get_rloc(thread_onmesh_prefix_info_h onmesh_prefix,
+       uint16_t *rloc)
+{
+       FUNC_ENTRY;
+       THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+       THREAD_CHECK_INIT_STATUS();
+       THREAD_VALIDATE_INPUT_PARAMETER(onmesh_prefix);
+
+       thread_onmesh_prefix_info_s *onmesh_prefix_info =
+                                       (thread_onmesh_prefix_info_s *)onmesh_prefix;
+       *rloc = onmesh_prefix_info->rloc;
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
 int thread_onmesh_prefix_set_preferred(thread_onmesh_prefix_info_h onmesh_prefix,
        bool is_preferred)
 {
index 7cb6be7..73062fd 100644 (file)
@@ -41,6 +41,7 @@ public:
        uint8_t onmeshIpv6Prefix[THREAD_IPV6_PREFIX_SIZE];
        uint8_t onmeshIpv6PrefixLen;
        bool preferred;
+       bool rloc;
        bool slaac;
        bool dhcp;
        bool configure;
@@ -391,6 +392,26 @@ TEST_F(ThreadBRTest, BRGetOnmeshPreferenceErrorNone)
                thread_onmesh_prefix_get_preference(onmeshPrefix, &preference));
 }
 
+TEST_F(ThreadBRTest, BRSetOnmeshRlocErrorNone)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_create(instance, &onmeshPrefix));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_set_rloc(onmeshPrefix, rloc));
+}
+
+TEST_F(ThreadBRTest, BRGetOnmeshRlocErrorNone)
+{
+       EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_create(instance, &onmeshPrefix));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_set_rloc(onmeshPrefix, rloc));
+       EXPECT_EQ(THREAD_ERROR_NONE,
+               thread_onmesh_prefix_get_rloc(onmeshPrefix, &rloc));
+}
+
 TEST_F(ThreadBRTest, BRSetOnmeshPreferredErrorNone)
 {
        EXPECT_EQ(THREAD_ERROR_NONE, thread_enable(&instance));