diff --git a/src/refda/CMakeLists.txt b/src/refda/CMakeLists.txt index dd3bf347..23df49d5 100644 --- a/src/refda/CMakeLists.txt +++ b/src/refda/CMakeLists.txt @@ -75,6 +75,8 @@ set(CFILES "amm/edd.c" "amm/ctrl.c" "amm/oper.c" + "amm/sbr.c" + "amm/tbr.c" "adm/ietf_amm.c" "adm/ietf_dtnma_agent.c" ) diff --git a/src/refda/adm/ietf_dtnma_agent.c b/src/refda/adm/ietf_dtnma_agent.c index 403fff58..d0b926c6 100644 --- a/src/refda/adm/ietf_dtnma_agent.c +++ b/src/refda/adm/ietf_dtnma_agent.c @@ -946,10 +946,11 @@ static void refda_adm_ietf_dtnma_agent_edd_var_list(refda_edd_prod_ctx_t *ctx) * Description: * A table of SBR within the agent. * - * Parameters: none + * Parameters list: + * * Index 0, name "include-adm", type: use of ari:/ARITYPE/BOOL * - * Produced type: TBLT with 6 columns (use of ari:/ARITYPE/SBR, use of ari://ietf/amm/TYPEDEF/MAC, use of - * ari://ietf/amm/TYPEDEF/TIME, use of ari://ietf/amm/TYPEDEF/EXPR, use of ari:/ARITYPE/TD, use of ari:/ARITYPE/UVAST) + * Produced type: TBLT with 5 columns (use of ari:/ARITYPE/SBR, use of ari://ietf/amm/TYPEDEF/MAC, use of + * ari://ietf/amm/TYPEDEF/EXPR, use of ari:/ARITYPE/TD, use of ari:/ARITYPE/UVAST) */ static void refda_adm_ietf_dtnma_agent_edd_sbr_list(refda_edd_prod_ctx_t *ctx) { @@ -958,6 +959,78 @@ static void refda_adm_ietf_dtnma_agent_edd_sbr_list(refda_edd_prod_ctx_t *ctx) * |START CUSTOM FUNCTION refda_adm_ietf_dtnma_agent_edd_sbr_list BODY * +-------------------------------------------------------------------------+ */ + bool include_adm = true; + if (cace_ari_get_bool(refda_edd_prod_ctx_get_aparam_index(ctx, 0), &include_adm)) + { + CACE_LOG_ERR("no parameter"); + return; + } + + refda_agent_t *agent = ctx->prodctx->parent->agent; + REFDA_AGENT_LOCK(agent, ); + + cace_ari_tbl_t table; + cace_ari_tbl_init(&table, 5, 0); + const cace_ari_type_t obj_type = CACE_ARI_TYPE_SBR; + + cace_amm_obj_ns_list_it_t ns_it; + for (cace_amm_obj_ns_list_it(ns_it, agent->objs.ns_list); !cace_amm_obj_ns_list_end_p(ns_it); + cace_amm_obj_ns_list_next(ns_it)) + { + cace_amm_obj_ns_ptr_t *const *ns_ptr = cace_amm_obj_ns_list_cref(ns_it); + if (!ns_ptr) + { + continue; + } + const cace_amm_obj_ns_t *ns = cace_amm_obj_ns_ptr_ref(*ns_ptr); + if ((ns->model_id.intenum >= 0) && !include_adm) + { + // ignore ADMs + continue; + } + + cace_amm_obj_ns_ctr_ptr_t *const *ctr_ptr = cace_amm_obj_ns_ctr_dict_get(ns->object_types, obj_type); + if (!ctr_ptr) + { + continue; + } + const cace_amm_obj_ns_ctr_t *ctr = cace_amm_obj_ns_ctr_ptr_ref(*ctr_ptr); + + cace_amm_obj_desc_list_it_t obj_it; + for (cace_amm_obj_desc_list_it(obj_it, ctr->obj_list); !cace_amm_obj_desc_list_end_p(obj_it); + cace_amm_obj_desc_list_next(obj_it)) + { + const cace_amm_obj_desc_t *obj = cace_amm_obj_desc_ptr_ref(*cace_amm_obj_desc_list_cref(obj_it)); + + cace_ari_array_t row; + cace_ari_array_init(row); + cace_ari_array_resize(row, 5); + + { + cace_ari_ref_t *ref = cace_ari_set_objref(cace_ari_array_get(row, 0)); + refda_adm_ietf_dtnma_agent_set_objpath(&(ref->objpath), ns, obj_type, obj); + } + + const refda_amm_sbr_desc_t *sbr = obj->app_data.ptr; + if (sbr) + { + cace_ari_set_copy(cace_ari_array_get(row, 1), &(sbr->action)); + cace_ari_set_copy(cace_ari_array_get(row, 2), &(sbr->condition)); + cace_ari_set_copy(cace_ari_array_get(row, 3), &(sbr->min_interval)); + cace_ari_set_uvast(cace_ari_array_get(row, 4), sbr->max_exec_count); + } + + // append the row + cace_ari_tbl_move_row_array(&table, row); + cace_ari_array_clear(row); + } + } + + cace_ari_t result = CACE_ARI_INIT_UNDEFINED; + cace_ari_set_tbl(&result, &table); + refda_edd_prod_ctx_set_result_move(ctx, &result); + + REFDA_AGENT_UNLOCK(agent, ); /* * +-------------------------------------------------------------------------+ * |STOP CUSTOM FUNCTION refda_adm_ietf_dtnma_agent_edd_sbr_list BODY @@ -969,7 +1042,8 @@ static void refda_adm_ietf_dtnma_agent_edd_sbr_list(refda_edd_prod_ctx_t *ctx) * Description: * A table of TBR within the agent. * - * Parameters: none + * Parameters list: + * * Index 0, name "include-adm", type: use of ari:/ARITYPE/BOOL * * Produced type: TBLT with 5 columns (use of ari:/ARITYPE/TBR, use of ari://ietf/amm/TYPEDEF/MAC, use of * ari://ietf/amm/TYPEDEF/TIME, use of ari:/ARITYPE/TD, use of ari:/ARITYPE/UVAST) @@ -981,6 +1055,79 @@ static void refda_adm_ietf_dtnma_agent_edd_tbr_list(refda_edd_prod_ctx_t *ctx) * |START CUSTOM FUNCTION refda_adm_ietf_dtnma_agent_edd_tbr_list BODY * +-------------------------------------------------------------------------+ */ + bool include_adm = true; + if (cace_ari_get_bool(refda_edd_prod_ctx_get_aparam_index(ctx, 0), &include_adm)) + { + CACE_LOG_ERR("no parameter"); + return; + } + + refda_agent_t *agent = ctx->prodctx->parent->agent; + REFDA_AGENT_LOCK(agent, ); + + cace_ari_tbl_t table; + cace_ari_tbl_init(&table, 5, 0); + const cace_ari_type_t obj_type = CACE_ARI_TYPE_TBR; + + cace_amm_obj_ns_list_it_t ns_it; + for (cace_amm_obj_ns_list_it(ns_it, agent->objs.ns_list); !cace_amm_obj_ns_list_end_p(ns_it); + cace_amm_obj_ns_list_next(ns_it)) + { + cace_amm_obj_ns_ptr_t *const *ns_ptr = cace_amm_obj_ns_list_cref(ns_it); + if (!ns_ptr) + { + continue; + } + const cace_amm_obj_ns_t *ns = cace_amm_obj_ns_ptr_ref(*ns_ptr); + if ((ns->model_id.intenum >= 0) && !include_adm) + { + // ignore ADMs + continue; + } + + cace_amm_obj_ns_ctr_ptr_t *const *ctr_ptr = cace_amm_obj_ns_ctr_dict_get(ns->object_types, obj_type); + if (!ctr_ptr) + { + continue; + } + const cace_amm_obj_ns_ctr_t *ctr = cace_amm_obj_ns_ctr_ptr_ref(*ctr_ptr); + + cace_amm_obj_desc_list_it_t obj_it; + for (cace_amm_obj_desc_list_it(obj_it, ctr->obj_list); !cace_amm_obj_desc_list_end_p(obj_it); + cace_amm_obj_desc_list_next(obj_it)) + { + const cace_amm_obj_desc_t *obj = cace_amm_obj_desc_ptr_ref(*cace_amm_obj_desc_list_cref(obj_it)); + + cace_ari_array_t row; + cace_ari_array_init(row); + cace_ari_array_resize(row, 5); + + { + cace_ari_ref_t *ref = cace_ari_set_objref(cace_ari_array_get(row, 0)); + refda_adm_ietf_dtnma_agent_set_objpath(&(ref->objpath), ns, obj_type, obj); + } + + const refda_amm_tbr_desc_t *tbr = obj->app_data.ptr; + if (tbr) + { + cace_ari_set_copy(cace_ari_array_get(row, 1), &(tbr->action)); + cace_ari_set_copy(cace_ari_array_get(row, 2), &(tbr->start_time)); + cace_ari_set_copy(cace_ari_array_get(row, 3), &(tbr->period)); + cace_ari_set_uvast(cace_ari_array_get(row, 4), tbr->max_exec_count); + } + + // append the row + cace_ari_tbl_move_row_array(&table, row); + cace_ari_array_clear(row); + } + } + + cace_ari_t result = CACE_ARI_INIT_UNDEFINED; + cace_ari_set_tbl(&result, &table); + refda_edd_prod_ctx_set_result_move(ctx, &result); + + REFDA_AGENT_UNLOCK(agent, ); + /* * +-------------------------------------------------------------------------+ * |STOP CUSTOM FUNCTION refda_adm_ietf_dtnma_agent_edd_tbr_list BODY @@ -2634,7 +2781,7 @@ int refda_adm_ietf_dtnma_agent_init(refda_agent_t *agent) // produced type { // table template - cace_amm_semtype_tblt_t *semtype = cace_amm_type_set_tblt_size(&(objdata->prod_type), 6); + cace_amm_semtype_tblt_t *semtype = cace_amm_type_set_tblt_size(&(objdata->prod_type), 5); { cace_amm_named_type_t *col = cace_amm_named_type_array_get(semtype->columns, 0); m_string_set_cstr(col->name, "obj"); @@ -2656,16 +2803,6 @@ int refda_adm_ietf_dtnma_agent_init(refda_agent_t *agent) } { cace_amm_named_type_t *col = cace_amm_named_type_array_get(semtype->columns, 2); - m_string_set_cstr(col->name, "start-time"); - { - cace_ari_t name = CACE_ARI_INIT_UNDEFINED; - // ari://ietf/amm/TYPEDEF/TIME - cace_ari_set_objref_path_intid(&name, 1, 0, CACE_ARI_TYPE_TYPEDEF, 5); - cace_amm_type_set_use_ref_move(&(col->typeobj), &name); - } - } - { - cace_amm_named_type_t *col = cace_amm_named_type_array_get(semtype->columns, 3); m_string_set_cstr(col->name, "condition"); { cace_ari_t name = CACE_ARI_INIT_UNDEFINED; @@ -2675,7 +2812,7 @@ int refda_adm_ietf_dtnma_agent_init(refda_agent_t *agent) } } { - cace_amm_named_type_t *col = cace_amm_named_type_array_get(semtype->columns, 4); + cace_amm_named_type_t *col = cace_amm_named_type_array_get(semtype->columns, 3); m_string_set_cstr(col->name, "min-interval"); { cace_ari_t name = CACE_ARI_INIT_UNDEFINED; @@ -2684,7 +2821,7 @@ int refda_adm_ietf_dtnma_agent_init(refda_agent_t *agent) } } { - cace_amm_named_type_t *col = cace_amm_named_type_array_get(semtype->columns, 5); + cace_amm_named_type_t *col = cace_amm_named_type_array_get(semtype->columns, 4); m_string_set_cstr(col->name, "max-count"); { cace_ari_t name = CACE_ARI_INIT_UNDEFINED; @@ -2699,7 +2836,16 @@ int refda_adm_ietf_dtnma_agent_init(refda_agent_t *agent) obj = refda_register_edd( adm, cace_amm_idseg_ref_withenum("sbr-list", REFDA_ADM_IETF_DTNMA_AGENT_ENUM_OBJID_EDD_SBR_LIST), objdata); - // no parameters + // parameters: + { + cace_amm_formal_param_t *fparam = refda_register_add_param(obj, "include-adm"); + { + cace_ari_t name = CACE_ARI_INIT_UNDEFINED; + cace_ari_set_aritype(&name, CACE_ARI_TYPE_BOOL); + cace_amm_type_set_use_ref_move(&(fparam->typeobj), &name); + } + cace_ari_set_bool(&(fparam->defval), false); + } } { // For ./EDD/tbr-list refda_amm_edd_desc_t *objdata = CACE_MALLOC(sizeof(refda_amm_edd_desc_t)); @@ -2762,7 +2908,16 @@ int refda_adm_ietf_dtnma_agent_init(refda_agent_t *agent) obj = refda_register_edd( adm, cace_amm_idseg_ref_withenum("tbr-list", REFDA_ADM_IETF_DTNMA_AGENT_ENUM_OBJID_EDD_TBR_LIST), objdata); - // no parameters + // parameters: + { + cace_amm_formal_param_t *fparam = refda_register_add_param(obj, "include-adm"); + { + cace_ari_t name = CACE_ARI_INIT_UNDEFINED; + cace_ari_set_aritype(&name, CACE_ARI_TYPE_BOOL); + cace_amm_type_set_use_ref_move(&(fparam->typeobj), &name); + } + cace_ari_set_bool(&(fparam->defval), false); + } } /** diff --git a/src/refda/amm/sbr.c b/src/refda/amm/sbr.c new file mode 100644 index 00000000..77af8e83 --- /dev/null +++ b/src/refda/amm/sbr.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2011-2024 The Johns Hopkins University Applied Physics + * Laboratory LLC. + * + * This file is part of the Delay-Tolerant Networking Management + * Architecture (DTNMA) Tools package. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "sbr.h" + +void refda_amm_sbr_desc_init(refda_amm_sbr_desc_t *obj) +{ + obj->action = CACE_ARI_INIT_UNDEFINED; + obj->condition = CACE_ARI_INIT_UNDEFINED; + + obj->min_interval = CACE_ARI_INIT_UNDEFINED; + struct timespec interval; + interval.tv_nsec = 0; + interval.tv_sec = 0; + cace_ari_set_td(&(obj->min_interval), interval); + + obj->max_exec_count = 0; + obj->init_enabled = true; + obj->enabled = true; +} + +void refda_amm_sbr_desc_deinit(refda_amm_sbr_desc_t *obj) +{ + cace_ari_deinit(&(obj->action)); + cace_ari_deinit(&(obj->condition)); + cace_ari_deinit(&(obj->min_interval)); + memset(obj, 0, sizeof(*obj)); +} diff --git a/src/refda/amm/sbr.h b/src/refda/amm/sbr.h new file mode 100644 index 00000000..2d0fb000 --- /dev/null +++ b/src/refda/amm/sbr.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2011-2024 The Johns Hopkins University Applied Physics + * Laboratory LLC. + * + * This file is part of the Delay-Tolerant Networking Management + * Architecture (DTNMA) Tools package. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef REFDA_AMM_SBR_H_ +#define REFDA_AMM_SBR_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** A SBR descriptor. + * This defines the properties of a SBR in an Agent and includes common + * object metadata. + */ +typedef struct +{ + /** Action in the form of a Macro (MAC). When triggered, the action execution + * SHALL be executed in accordance with Section 6.6 in an execution context with no parameters. + */ + cace_ari_t action; + + /** An SBR definition SHALL include a condition in the form of an Expression (EXPR). + * The condition SHALL be evaluated in accordance with Section 6.7 in an evaluation + * context with no parameters. The result of the condition SHALL be converted to a + * BOOL value after evaluation and used to determine when to execute the action of the SBR. + */ + cace_ari_t condition; + + /** An SBR definition SHALL include a minimum execution interval in the form of a non-negative TD value. + * The interval MAY be zero to indicate that there is no minimum. This is not a limit on the interval of + * evaluations of the condition. This value can be used to limit potentially high processing loads on an Agent. + */ + cace_ari_t min_interval; + + /** Maximum execution count in the form of a non-negative UVAST value. + * The count sentinel value zero SHALL be interpreted as having no maximum. + * This is not a limit on the number of evaluations of the condition. + */ + cace_ari_uvast max_exec_count; + + /** Initial value for rule's enabled state. If not provided, the initial enabled state SHALL be true. + */ + bool init_enabled; + + /** Current enabled state of the rule. + */ + bool enabled; + +} refda_amm_sbr_desc_t; + +void refda_amm_sbr_desc_init(refda_amm_sbr_desc_t *obj); + +void refda_amm_sbr_desc_deinit(refda_amm_sbr_desc_t *obj); + +#ifdef __cplusplus +} // extern C +#endif + +#endif /* REFDA_AMM_SBR_H_ */ diff --git a/src/refda/amm/tbr.c b/src/refda/amm/tbr.c new file mode 100644 index 00000000..1e21632d --- /dev/null +++ b/src/refda/amm/tbr.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011-2024 The Johns Hopkins University Applied Physics + * Laboratory LLC. + * + * This file is part of the Delay-Tolerant Networking Management + * Architecture (DTNMA) Tools package. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "tbr.h" + +void refda_amm_tbr_desc_init(refda_amm_tbr_desc_t *obj) +{ + obj->action = CACE_ARI_INIT_UNDEFINED; + obj->start_time = CACE_ARI_INIT_UNDEFINED; + obj->period = CACE_ARI_INIT_UNDEFINED; + obj->max_exec_count = 0; + obj->init_enabled = true; + obj->enabled = true; +} + +void refda_amm_tbr_desc_deinit(refda_amm_tbr_desc_t *obj) +{ + cace_ari_deinit(&(obj->action)); + cace_ari_deinit(&(obj->start_time)); + cace_ari_deinit(&(obj->period)); + memset(obj, 0, sizeof(*obj)); +} diff --git a/src/refda/amm/tbr.h b/src/refda/amm/tbr.h new file mode 100644 index 00000000..4d3c8087 --- /dev/null +++ b/src/refda/amm/tbr.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2011-2024 The Johns Hopkins University Applied Physics + * Laboratory LLC. + * + * This file is part of the Delay-Tolerant Networking Management + * Architecture (DTNMA) Tools package. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef REFDA_AMM_TBR_H_ +#define REFDA_AMM_TBR_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** A TBR descriptor. + * This defines the properties of a TBR in an Agent and includes common + * object metadata. + */ +typedef struct +{ + /** Action in the form of a Macro (MAC). When triggered, the action execution + * SHALL be executed in accordance with Section 6.6 in an execution context with no parameters. + */ + cace_ari_t action; + + /** Start time in the form of a TIME (TP or TD) value. + * A relative start time SHALL be interpreted relative to the absolute time at which the + * Agent is initialized (for ADM rules) or the rule is created (for ODM rules). + * The start time MAY be the relative time zero to indicate that the TBR is always active. + * This is not a limit on the interval of evaluations of the condition. + */ + + cace_ari_t start_time; + + /** Time period in the form of a positive TD value. + * The period SHALL NOT be zero but any non-zero small period is valid. + */ + + cace_ari_t period; + + /** Maximum execution count in the form of a non-negative UVAST value. + * The count sentinel value zero SHALL be interpreted as having no maximum. + * This is not a limit on the number of evaluations of the condition. + */ + cace_ari_uvast max_exec_count; + + /** Initial value for rule's enabled state. If not provided, the initial enabled state SHALL be true. + */ + bool init_enabled; + + /** Current enabled state of the rule. + */ + bool enabled; + +} refda_amm_tbr_desc_t; + +void refda_amm_tbr_desc_init(refda_amm_tbr_desc_t *obj); + +void refda_amm_tbr_desc_deinit(refda_amm_tbr_desc_t *obj); + +#ifdef __cplusplus +} // extern C +#endif + +#endif /* REFDA_AMM_TBR_H_ */ diff --git a/src/refda/register.h b/src/refda/register.h index ff25de7b..000b6650 100644 --- a/src/refda/register.h +++ b/src/refda/register.h @@ -25,6 +25,8 @@ #include "amm/edd.h" #include "amm/ctrl.h" #include "amm/oper.h" +#include "amm/sbr.h" +#include "amm/tbr.h" #include "cace/amm/idseg_ref.h" #include "cace/amm/obj_ns.h" diff --git a/test/refda/test_adm_ietf_dtnma_agent.c b/test/refda/test_adm_ietf_dtnma_agent.c index e84991bb..8b206f82 100644 --- a/test/refda/test_adm_ietf_dtnma_agent.c +++ b/test/refda/test_adm_ietf_dtnma_agent.c @@ -116,6 +116,14 @@ TEST_CASE("850101230B81F5", 0, CACE_ARI_PRIM_OTHER, CACE_ARI_TYPE_TBL) TEST_CASE("840101230E", 0, CACE_ARI_PRIM_OTHER, CACE_ARI_TYPE_TBL) // ari://1/1/EDD/const-list(true) -> ari:/TBL/c=2; TEST_CASE("850101230E81F5", 0, CACE_ARI_PRIM_OTHER, CACE_ARI_TYPE_TBL) +// ari://1/1/EDD/sbr-list -> ari:/TBL/c=5; +TEST_CASE("840101230C", 0, CACE_ARI_PRIM_OTHER, CACE_ARI_TYPE_TBL) +// ari://1/1/EDD/sbr-list(true) -> ari:/TBL/c=5; +TEST_CASE("850101230C81F5", 0, CACE_ARI_PRIM_OTHER, CACE_ARI_TYPE_TBL) +// ari://1/1/EDD/tbr-list -> ari:/TBL/c=5; +TEST_CASE("840101230D", 0, CACE_ARI_PRIM_OTHER, CACE_ARI_TYPE_TBL) +// ari://1/1/EDD/tbr-list(true) -> ari:/TBL/c=5; +TEST_CASE("850101230D81F5", 0, CACE_ARI_PRIM_OTHER, CACE_ARI_TYPE_TBL) // clang-format on void test_refda_adm_ietf_dtnma_agent_edd_produce(const char *targethex, int expect_res, enum cace_ari_prim_type_e expect_prim, cace_ari_type_t expect_type)