B#14347: usp events not working for multi-instance objects

This commit is contained in:
Amin Ben Romdhane 2024-05-07 15:01:38 +02:00
parent d988764f9d
commit eee1130299
8 changed files with 182 additions and 60 deletions

View file

@ -45,8 +45,14 @@ static void bbfdm_event_handler(struct ubus_context *ctx, struct ubus_event_hand
if (!msg || !type)
return;
char *dm_path = get_events_dm_path(&u->event_handlers, type);
if (dm_path == NULL)
char *event_dm_path = get_events_dm_path(&u->event_handlers, type);
if (event_dm_path == NULL)
return;
char dm_path[MAX_DM_PATH];
replace_str(event_dm_path, ".{i}.", ".*.", dm_path, sizeof(dm_path));
if (strlen(dm_path) == 0)
return;
char *str = blobmsg_format_json(msg, true);
@ -80,12 +86,16 @@ static void bbfdm_event_handler(struct ubus_context *ctx, struct ubus_event_hand
blob_buf_init(&bb, 0);
list_for_each_entry(param, &bbf_ctx.list_parameter, list) {
if (strcmp(param->name, "Event_Path") == 0) {
blobmsg_add_string(&b, "name", param->data);
strncpyt(dm_path, param->data, sizeof(dm_path));
} else {
blobmsg_add_string(&bb, param->name, param->data);
}
}
snprintf(method_name, sizeof(method_name), "%s.%s", DM_STRLEN(u->config.out_root_obj) ? u->config.out_root_obj : u->config.out_name, BBF_EVENT_NAME);
blobmsg_add_string(&b, "name", dm_path);
blobmsg_add_field(&b, BLOBMSG_TYPE_TABLE, "input", blob_data(bb.head), blob_len(bb.head));
ubus_send_event(ctx, method_name, b.head);

View file

@ -45,6 +45,11 @@ static int get_event_args_WiFiDataElementsAssociationEvent_Associated(char *refp
static int event_WiFiDataElementsAssociationEvent_Associated(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case EVENT_CHECK:
// Nothing to check
break;
case EVENT_RUN:
char *event_time = dmjson_get_value((json_object *)value, 1, "eventTime");
char *bssid = dmjson_get_value((json_object *)value, 3, "wfa-dataelements:AssociationEvent.AssocData", "DisassocData", "BSSID");
char *mac_addr = dmjson_get_value((json_object *)value, 3, "wfa-dataelements:AssociationEvent.AssocData", "DisassocData", "MACAddress");
@ -52,6 +57,8 @@ static int event_WiFiDataElementsAssociationEvent_Associated(char *refparam, str
add_list_parameter(ctx, dmstrdup("TimeStamp"), dmstrdup(event_time), DMT_TYPE[DMT_STRING], NULL);
add_list_parameter(ctx, dmstrdup("BSSID"), dmstrdup(bssid), DMT_TYPE[DMT_STRING], NULL);
add_list_parameter(ctx, dmstrdup("MACAddress"), dmstrdup(mac_addr), DMT_TYPE[DMT_STRING], NULL);
break;
}
return 0;
}

View file

@ -243,6 +243,11 @@ enum set_value_action {
VALUESET
};
enum event_action_enum {
EVENT_RUN,
EVENT_CHECK
};
enum del_action_enum {
DEL_INST,
DEL_ALL

View file

@ -2782,21 +2782,37 @@ static int mobj_event(DMOBJECT_ARGS)
static int mparam_event(DMPARAM_ARGS)
{
char full_param[MAX_DM_PATH];
int fault = 0;
snprintf(full_param, MAX_DM_PATH, "%s%s", node->current_object, leaf->parameter);
if (DM_STRCMP(full_param, dmctx->in_param) != 0)
if (dmctx->iswildcard) {
if (dm_strcmp_wildcard(dmctx->in_param, full_param) != 0)
return USP_FAULT_INVALID_PATH;
} else {
if (DM_STRCMP(dmctx->in_param, full_param) != 0)
return USP_FAULT_INVALID_PATH;
}
if (!leaf->setvalue) {
dmctx->stop = 1;
return USP_FAULT_INTERNAL_ERROR;
}
json_object *j_input = (dmctx->in_value) ? json_tokener_parse(dmctx->in_value) : NULL;
fault = (leaf->setvalue)(full_param, dmctx, data, instance, (char *)j_input, EVENT_CHECK);
if (fault)
goto end;
dmctx->stop = 1;
if (!leaf->setvalue)
return USP_FAULT_INTERNAL_ERROR;
fault = (leaf->setvalue)(full_param, dmctx, data, instance, (char *)j_input, EVENT_RUN);
if (!fault)
add_list_parameter(dmctx, dmstrdup("Event_Path"), dmstrdup(full_param), DMT_TYPE[DMT_STRING], NULL);
json_object *j_input = (dmctx->in_value) ? json_tokener_parse(dmctx->in_value) : NULL;
int fault = (leaf->setvalue)(full_param, dmctx, data, instance, (char *)j_input, 0);
end:
json_object_put(j_input);
return fault;
}
@ -2812,8 +2828,8 @@ int dm_entry_event(struct dmctx *dmctx)
dmctx->isevent = 1;
dmctx->inparam_isparam = 1;
dmctx->stop = 0;
dmctx->checkobj = plugin_obj_match;
dmctx->checkleaf = plugin_leaf_match;
dmctx->checkobj = (dmctx->iswildcard) ? plugin_obj_wildcard_match : plugin_obj_match;
dmctx->checkleaf = (dmctx->iswildcard) ? plugin_leaf_wildcard_match : plugin_leaf_match;
dmctx->method_obj = mobj_event;
dmctx->method_param = mparam_event;

View file

@ -3876,6 +3876,12 @@ static int get_event_args_WiFiDataElementsAssociationEvent_Associated(char *refp
static int event_WiFiDataElementsAssociationEvent_Associated(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case EVENT_CHECK:
// Nothing to check
break;
case EVENT_RUN:
{
char *event_time = dmjson_get_value((json_object *)value, 1, "eventTime");
char *bssid = dmjson_get_value((json_object *)value, 3, "wfa-dataelements:AssociationEvent", "AssocData", "BSSID");
char *mac_addr = dmjson_get_value((json_object *)value, 3, "wfa-dataelements:AssociationEvent", "AssocData", "MACAddress");
@ -3891,6 +3897,9 @@ static int event_WiFiDataElementsAssociationEvent_Associated(char *refparam, str
add_list_parameter(ctx, dmstrdup("HTCapabilities"), dmstrdup(ht_cap), DMT_TYPE[DMT_STRING], NULL);
add_list_parameter(ctx, dmstrdup("VHTCapabilities"), dmstrdup(vht_cap), DMT_TYPE[DMT_STRING], NULL);
add_list_parameter(ctx, dmstrdup("HECapabilities"), dmstrdup(he_cap), DMT_TYPE[DMT_STRING], NULL);
break;
}
}
return 0;
}
@ -3924,6 +3933,12 @@ static int get_event_args_WiFiDataElementsDisassociationEvent_Disassociated(char
static int event_WiFiDataElementsDisassociationEvent_Disassociated(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case EVENT_CHECK:
// Nothing to check
break;
case EVENT_RUN:
{
char *event_time = dmjson_get_value((json_object *)value, 1, "eventTime");
char *bssid = dmjson_get_value((json_object *)value, 3, "wfa-dataelements:DisassociationEvent", "DisassocData", "BSSID");
char *mac_addr = dmjson_get_value((json_object *)value, 3, "wfa-dataelements:DisassociationEvent", "DisassocData", "MACAddress");
@ -3947,6 +3962,9 @@ static int event_WiFiDataElementsDisassociationEvent_Disassociated(char *refpara
add_list_parameter(ctx, dmstrdup("ErrorsSent"), dmstrdup(errors_sent), DMT_TYPE[DMT_STRING], NULL);
add_list_parameter(ctx, dmstrdup("ErrorsReceived"), dmstrdup(errors_received), DMT_TYPE[DMT_STRING], NULL);
add_list_parameter(ctx, dmstrdup("RetransCount"), dmstrdup(retrans_count), DMT_TYPE[DMT_STRING], NULL);
break;
}
}
return 0;
}

View file

@ -23,6 +23,24 @@ DM_MAP_OBJ tDynamicObj[] = {
{0}
};
/*************************************************************
* ENTRY METHOD
**************************************************************/
static int browseX_IOPSYS_EU_EventTESTInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL;
for (int i = 0; i < 2; i++) {
inst = handle_instance_without_section(dmctx, parent_node, i + 1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, NULL, inst) == DM_STOP)
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
@ -158,6 +176,44 @@ static int get_event_args_XIOPSYSEU_Boot(char *refparam, struct dmctx *ctx, void
return 0;
}
static event_args test_event_args = {
.name = "bbf.test",
.param = (const char *[]) {
"CommandKey",
"Status",
NULL
}
};
static int get_event_args_XIOPSYSEUEventTEST_Test(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = (char *)&test_event_args;
return 0;
}
static int event_XIOPSYSEUEventTEST_Test(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case EVENT_CHECK:
{
char *test_instance = dmjson_get_value((json_object *)value, 1, "instance");
if (DM_STRCMP(test_instance, instance) != 0)
return USP_FAULT_INVALID_PATH_SYNTAX;
break;
}
case EVENT_RUN:
{
char *command_key = dmjson_get_value((json_object *)value, 1, "command_key");
char *status = dmjson_get_value((json_object *)value, 1, "status");
add_list_parameter(ctx, dmstrdup("CommandKey"), dmstrdup(command_key), DMT_TYPE[DMT_STRING], NULL);
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(status), DMT_TYPE[DMT_STRING], NULL);
break;
}
}
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
@ -166,6 +222,7 @@ DMOBJ tDynamicDeviceObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
{"X_IOPSYS_EU_Syslog", &DMREAD, NULL, NULL, "file:/etc/config/system", NULL, NULL, NULL, NULL, tX_IOPSYS_EU_SyslogParam, NULL, BBFDM_BOTH},
{"X_IOPSYS_EU_PingTEST", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tX_IOPSYS_EU_PingTESTParam, NULL, BBFDM_BOTH},
{"X_IOPSYS_EU_EventTEST", &DMREAD, NULL, NULL, NULL, browseX_IOPSYS_EU_EventTESTInst, NULL, NULL, NULL, tX_IOPSYS_EU_EventTESTParam, NULL, BBFDM_BOTH},
{0}
};
@ -192,3 +249,11 @@ DMLEAF tX_IOPSYS_EU_PingTESTParam[] = {
{"Run()", &DMASYNC, DMT_COMMAND, get_operate_args_XIOPSYSEUPingTEST_Run, operate_DeviceXIOPSYSEUPingTEST_Run, BBFDM_USP},
{0}
};
/*** Device.X_IOPSYS_EU_EventTEST. ***/
DMLEAF tX_IOPSYS_EU_EventTESTParam[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/
{"Test!", &DMREAD, DMT_EVENT, get_event_args_XIOPSYSEUEventTEST_Test, event_XIOPSYSEUEventTEST_Test, BBFDM_USP},
{0}
};

View file

@ -15,6 +15,7 @@ extern DMOBJ tDynamicDeviceObj[];
extern DMLEAF tDynamicDeviceParams[];
extern DMLEAF tX_IOPSYS_EU_SyslogParam[];
extern DMLEAF tX_IOPSYS_EU_PingTESTParam[];
extern DMLEAF tX_IOPSYS_EU_EventTESTParam[];
#endif //__LIBBBFD_TEST_H

View file

@ -1667,7 +1667,7 @@ static void test_api_bbfdm_valid_library_event(void **state)
idx++;
}
assert_int_equal(idx, 9);
assert_int_not_equal(idx, 0);
}
static void test_api_bbfdm_valid_json_event(void **state)
@ -1714,7 +1714,7 @@ static void test_api_bbfdm_valid_json_event(void **state)
idx++;
}
assert_int_equal(idx, 9);
assert_int_not_equal(idx, 0);
}
static void test_api_bbfdm_valid_json_v1_event(void **state)
@ -1763,7 +1763,7 @@ static void test_api_bbfdm_valid_json_v1_event(void **state)
idx++;
}
assert_int_equal(idx, 9);
assert_int_not_equal(idx, 0);
}
int main(void)