Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial AMM rule support #116

Open
wants to merge 10 commits into
base: apl-fy24
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/refda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
189 changes: 172 additions & 17 deletions src/refda/adm/ietf_dtnma_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,8 @@ 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)
Expand All @@ -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, 2, 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_copy(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
Expand All @@ -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)
Expand All @@ -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, 2, 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_copy(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
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
46 changes: 46 additions & 0 deletions src/refda/amm/sbr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 = CACE_ARI_INIT_UNDEFINED;
cace_ari_set_uvast(&(obj->max_exec_count), 0);

obj->init_enabled = CACE_ARI_INIT_UNDEFINED;
cace_ari_set_bool(&(obj->max_exec_count), 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));
cace_ari_deinit(&(obj->max_exec_count));
cace_ari_deinit(&(obj->init_enabled));
memset(obj, 0, sizeof(*obj));
}
72 changes: 72 additions & 0 deletions src/refda/amm/sbr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 <cace/amm/typing.h>
#include <cace/ari.h>

#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_t max_exec_count;

/** Initial value for rule's enabled state. If not provided, the initial enabled state SHALL be true.
*/
cace_ari_t init_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_ */
Loading