Move Instance Alias handling to icwmp

This commit is contained in:
Amin Ben Romdhane 2024-06-20 14:18:15 +02:00 committed by Suvendhu Hansa
parent 7cdea20a2d
commit 1eaf1298af
19 changed files with 23 additions and 530 deletions

View file

@ -138,11 +138,6 @@ static void fill_optional_data(bbfdm_data_t *data, struct blob_attr *msg)
data->bbf_ctx.dm_type = get_proto_type(val);
}
if (is_str_eq(blobmsg_name(attr), "instance_mode")) {
int instance_mode = blobmsg_get_u32(attr);
data->bbf_ctx.instance_mode = get_instance_mode(instance_mode);
}
if (is_str_eq(blobmsg_name(attr), "transaction_id"))
data->trans_id = blobmsg_get_u32(attr);
@ -152,7 +147,6 @@ static void fill_optional_data(bbfdm_data_t *data, struct blob_attr *msg)
DEBUG("Proto:|%s|, Inst Mode:|%s|, Tran-id:|%d|, Format:|%s|",
(data->bbf_ctx.dm_type == BBFDM_BOTH) ? "both" : (data->bbf_ctx.dm_type == BBFDM_CWMP) ? "cwmp" : "usp",
(data->bbf_ctx.instance_mode == 0) ? "Number" : "Alias",
data->trans_id,
data->is_raw ? "raw" : "pretty");
}
@ -1185,7 +1179,6 @@ static void update_instances_list(struct list_head *inst)
.in_param = ROOT_NODE,
.nextlevel = false,
.disable_mservice_browse = true,
.instance_mode = INSTANCE_MODE_NUMBER,
.dm_type = BBFDM_USP
};
@ -1541,13 +1534,6 @@ static int _parse_input_cli_options(bbfdm_config_t *config, json_object *json_ob
config->proto = BBFDM_BOTH;
}
opt_val = dmjson_get_value(json_obj, 3, "cli", "config", "instance_mode");
if (DM_STRLEN(opt_val)) {
config->instance_mode = get_instance_mode((int) strtol(opt_val, NULL, 10));
} else {
config->instance_mode = INSTANCE_MODE_NUMBER;
}
opt_val = dmjson_get_value(json_obj, 3, "cli", "input", "type");
if (DM_STRLEN(opt_val)) {
snprintf(config->cli_in_type, sizeof(config->cli_in_type), "%s", opt_val);

View file

@ -18,7 +18,6 @@ struct bbfdm_async_req {
typedef struct bbfdm_config {
int proto; // Protocol identifier, Possible values: { '0'<both>, '1'<cwmp>, '2'<usp> }
int instance_mode; // Instance mode, Possible values: { '0'<Instance Number>, '1'<Instance Alias> }
int transaction_timeout; // Timeout for transactions
int subprocess_level; // Subprocess level
uint8_t log_level; // Log level, Possible values: { '1', '2', '3', '4' }

View file

@ -26,7 +26,6 @@ static void *cli_lib_handle = NULL;
typedef struct {
struct dmctx bbf_ctx;
unsigned int instance_mode;
unsigned int proto;
char in_name[128];
char in_plugin_dir[128];
@ -184,7 +183,6 @@ static int in_ubus_out_cli_exec_cmd(cli_data_t *cli_data, const char *path, cons
table = blobmsg_open_table(&b, "optional");
blobmsg_add_string(&b, "proto", (cli_data->proto == BBFDM_CWMP) ? "cwmp" : "usp");
blobmsg_add_string(&b, "format", "raw");
blobmsg_add_u32(&b, "instance_mode", cli_data->instance_mode);
blobmsg_close_table(&b, table);
int e = bbfdm_ubus_invoke(cli_data->in_name, cli_data->cmd, b.head, __ubus_callback, cli_data);
@ -209,7 +207,6 @@ static int bbfdm_load_cli_config(bbfdm_config_t *bbf_config, cli_data_t *cli_dat
char *opt_val = NULL;
cli_data->proto = bbf_config->proto;
cli_data->instance_mode = bbf_config->instance_mode;
opt_val = bbf_config->cli_in_type;
if (opt_val && strlen(opt_val)) {
@ -535,7 +532,6 @@ static int cli_exec_command(cli_data_t *cli_data, int argc, char *argv[])
bbf_ctx_init(&cli_data->bbf_ctx, CLI_DM_ROOT_OBJ);
cli_data->bbf_ctx.dm_type = cli_data->proto;
cli_data->bbf_ctx.instance_mode = cli_data->instance_mode;
} else if (strcasecmp(cli_data->in_type, "UBUS") != 0) {
return -1;
}

View file

@ -197,14 +197,6 @@ int get_proto_type(const char *proto)
return type;
}
int get_instance_mode(int instance_mode)
{
if (instance_mode > INSTANCE_MODE_ALIAS)
instance_mode = INSTANCE_MODE_NUMBER;
return instance_mode;
}
// glibc doesn't guarantee a 0 termianted string on strncpy
// strncpy with always 0 terminated string
void strncpyt(char *dst, const char *src, size_t n)

View file

@ -58,7 +58,6 @@ bool validate_msglen(bbfdm_data_t *data);
int get_dm_type(char *dm_type);
int get_proto_type(const char *proto);
int get_instance_mode(int instance_mode);
#define DEBUG(fmt, args...) \
print_debug("[%s:%d]"fmt, __func__, __LINE__, ##args)

View file

@ -65,7 +65,6 @@ static void bbfdm_event_handler(struct ubus_context *ctx, struct ubus_event_hand
.isevent = true,
.isinfo = false,
.disable_mservice_browse = true,
.instance_mode = INSTANCE_MODE_NUMBER,
.dm_type = BBFDM_USP
};
@ -147,7 +146,6 @@ int register_events_to_ubus(struct ubus_context *ctx, struct list_head *ev_list)
.isevent = true,
.isinfo = false,
.disable_mservice_browse = true,
.instance_mode = INSTANCE_MODE_NUMBER,
.dm_type = BBFDM_USP
};

View file

@ -46,7 +46,6 @@ static int set_resolved_paths(unsigned int dm_type, char *path, char *value, str
{
int fault = 0;
struct dmctx bbf_ctx = {
.instance_mode = INSTANCE_MODE_NUMBER,
.dm_type = dm_type
};

View file

@ -114,12 +114,6 @@
"pretty"
]
},
"instance_mode_t": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 1
},
"trans_id_t": {
"description": "Required for CUD operation, it shall be same number as got from transaction->start",
"type": "integer",
@ -296,9 +290,6 @@
},
"proto": {
"$ref": "#/definitions/proto_t"
},
"instance_mode": {
"$ref": "#/definitions/instance_mode_t"
}
}
}
@ -367,9 +358,6 @@
"properties": {
"proto": {
"$ref": "#/definitions/proto_t"
},
"instance_mode": {
"$ref": "#/definitions/instance_mode_t"
}
}
}
@ -590,9 +578,6 @@
"proto": {
"$ref": "#/definitions/proto_t"
},
"instance_mode": {
"$ref": "#/definitions/instance_mode_t"
},
"transaction_id": {
"$ref": "#/definitions/trans_id_t"
}
@ -671,9 +656,6 @@
},
"proto": {
"$ref": "#/definitions/proto_t"
},
"instance_mode": {
"$ref": "#/definitions/instance_mode_t"
}
}
}

View file

@ -507,7 +507,6 @@ Integer to decide the depth of data model to be parsed
| Property | Type | Required | Default |
| --------------- | ------- | -------- | ---------- |
| `format` | string | Optional | `"pretty"` |
| `instance_mode` | integer | Optional | `0` |
| `proto` | string | Optional | `"both"` |
#### format
@ -531,21 +530,6 @@ The value of this property **must** be equal to one of the [known values below](
| raw |
| pretty |
#### instance_mode
`instance_mode`
- is optional
- type: reference
- default: `0`
##### instance_mode Type
`integer`
- minimum value: `0`
- maximum value: `1`
#### proto
`proto`
@ -635,7 +619,7 @@ All items must be of the type: Unknown type ``.
### Ubus CLI Example
```
ubus call bbf get {"path":"reprehende","paths":["nostrud"],"maxdepth":-31156882,"optional":{"format":"pretty","proto":"cwmp","instance_mode":1}}
ubus call bbf get {"path":"reprehende","paths":["nostrud"],"maxdepth":-31156882,"optional":{"format":"pretty","proto":"cwmp"}}
```
### JSONRPC Example
@ -653,7 +637,7 @@ ubus call bbf get {"path":"reprehende","paths":["nostrud"],"maxdepth":-31156882,
"path": "reprehende",
"paths": ["nostrud"],
"maxdepth": -31156882,
"optional": { "format": "pretty", "proto": "cwmp", "instance_mode": 1 }
"optional": { "format": "pretty", "proto": "cwmp" }
}
]
}
@ -797,24 +781,8 @@ gets only first level objects if true
| Property | Type | Required | Default |
| --------------- | ------- | -------- | -------- |
| `instance_mode` | integer | Optional | `0` |
| `proto` | string | Optional | `"both"` |
#### instance_mode
`instance_mode`
- is optional
- type: reference
- default: `0`
##### instance_mode Type
`integer`
- minimum value: `0`
- maximum value: `1`
#### proto
`proto`
@ -878,7 +846,7 @@ Device.WiFi.
### Ubus CLI Example
```
ubus call bbf instances {"path":"veniam","first_level":false,"optional":{"proto":"cwmp","instance_mode":0}}
ubus call bbf instances {"path":"veniam","first_level":false,"optional":{"proto":"cwmp"}}
```
### JSONRPC Example
@ -892,7 +860,7 @@ ubus call bbf instances {"path":"veniam","first_level":false,"optional":{"proto"
"<SID>",
"bbf",
"instances",
{ "path": "veniam", "first_level": false, "optional": { "proto": "cwmp", "instance_mode": 0 } }
{ "path": "veniam", "first_level": false, "optional": { "proto": "cwmp" } }
]
}
```
@ -1130,19 +1098,13 @@ Unknown type ``.
"default": "pretty",
"enum": ["raw", "pretty"]
},
"instance_mode_t": {
"type": "integer",
"default": 0,
"minimum": 0,
"maximum": 1
},
"trans_id_t": {
"description": "Required for CUD operation, it shall be same number as got from transaction->start",
"type": "integer",
"minimum": 1
}
},
"out": "{\"definitions\":{\"path_t\":{\"description\":\"Complete object element path as per TR181\",\"type\":\"string\",\"minLength\":6,\"maxLength\":1024,\"examples\":[\"Device.\",\"Device.DeviceInfo.Manufacturer\",\"Device.WiFi.SSID.1.\",\"Device.WiFi.\"]},\"schema_path_t\":{\"description\":\"Datamodel object schema path\",\"type\":\"string\",\"minLength\":6,\"maxLength\":1024,\"examples\":[\"Device.Bridging.Bridge.{i}.\",\"Device.DeviceInfo.Manufacturer\",\"Device.WiFi.SSID.{i}.SSID\"]},\"boolean_t\":{\"type\":\"string\",\"enum\":[\"0\",\"1\"]},\"operate_path_t\":{\"description\":\"Datamodel object schema path\",\"type\":\"string\",\"minLength\":6,\"maxLength\":1024,\"examples\":[\"Device.IP.Diagnostics.IPPing()\",\"Device.DHCPv4.Client.{i}.Renew()\",\"Device.FactoryReset()\"]},\"query_path_t\":{\"description\":\"DM object path with search queries\",\"type\":\"string\",\"minLength\":6,\"maxLength\":1024,\"examples\":[\"Device.\",\"Device.DeviceInfo.Manufacturer\",\"Device.WiFi.SSID.1.BSSID\",\"Device.WiFi.SSID.*.BSSID\",\"Device.WiFi.\"]},\"instance_t\":{\"description\":\"Multi object instances\",\"type\":\"string\",\"minLength\":6,\"maxLength\":256},\"proto_t\":{\"type\":\"string\",\"default\":\"both\",\"enum\":[\"usp\",\"cwmp\",\"both\"]},\"type_t\":{\"type\":\"string\",\"enum\":[\"xsd:string\",\"xsd:unsignedInt\",\"xsd:int\",\"xsd:unsignedLong\",\"xsd:long\",\"xsd:boolean\",\"xsd:dateTime\",\"xsd:hexBinary\",\"xsd:object\",\"xsd:command\",\"xsd:event\"]},\"fault_t\":{\"type\":\"integer\",\"minimum\":7000,\"maximum\":9050},\"trans_type_t\":{\"type\":\"string\",\"enum\":[\"start\",\"commit\",\"abort\",\"status\"]},\"srv_type_t\":{\"type\":\"string\",\"enum\":[\"register\",\"list\"]},\"format_t\":{\"type\":\"string\",\"default\":\"pretty\",\"enum\":[\"raw\",\"pretty\"]},\"instance_mode_t\":{\"type\":\"integer\",\"default\":0,\"minimum\":0,\"maximum\":1},\"trans_id_t\":{\"description\":\"Required for CUD operation, it shall be same number as got from transaction->start\",\"type\":\"integer\",\"minimum\":1}}}",
"out": "{\"definitions\":{\"path_t\":{\"description\":\"Complete object element path as per TR181\",\"type\":\"string\",\"minLength\":6,\"maxLength\":1024,\"examples\":[\"Device.\",\"Device.DeviceInfo.Manufacturer\",\"Device.WiFi.SSID.1.\",\"Device.WiFi.\"]},\"schema_path_t\":{\"description\":\"Datamodel object schema path\",\"type\":\"string\",\"minLength\":6,\"maxLength\":1024,\"examples\":[\"Device.Bridging.Bridge.{i}.\",\"Device.DeviceInfo.Manufacturer\",\"Device.WiFi.SSID.{i}.SSID\"]},\"boolean_t\":{\"type\":\"string\",\"enum\":[\"0\",\"1\"]},\"operate_path_t\":{\"description\":\"Datamodel object schema path\",\"type\":\"string\",\"minLength\":6,\"maxLength\":1024,\"examples\":[\"Device.IP.Diagnostics.IPPing()\",\"Device.DHCPv4.Client.{i}.Renew()\",\"Device.FactoryReset()\"]},\"query_path_t\":{\"description\":\"DM object path with search queries\",\"type\":\"string\",\"minLength\":6,\"maxLength\":1024,\"examples\":[\"Device.\",\"Device.DeviceInfo.Manufacturer\",\"Device.WiFi.SSID.1.BSSID\",\"Device.WiFi.SSID.*.BSSID\",\"Device.WiFi.\"]},\"instance_t\":{\"description\":\"Multi object instances\",\"type\":\"string\",\"minLength\":6,\"maxLength\":256},\"proto_t\":{\"type\":\"string\",\"default\":\"both\",\"enum\":[\"usp\",\"cwmp\",\"both\"]},\"type_t\":{\"type\":\"string\",\"enum\":[\"xsd:string\",\"xsd:unsignedInt\",\"xsd:int\",\"xsd:unsignedLong\",\"xsd:long\",\"xsd:boolean\",\"xsd:dateTime\",\"xsd:hexBinary\",\"xsd:object\",\"xsd:command\",\"xsd:event\"]},\"fault_t\":{\"type\":\"integer\",\"minimum\":7000,\"maximum\":9050},\"trans_type_t\":{\"type\":\"string\",\"enum\":[\"start\",\"commit\",\"abort\",\"status\"]},\"srv_type_t\":{\"type\":\"string\",\"enum\":[\"register\",\"list\"]},\"format_t\":{\"type\":\"string\",\"default\":\"pretty\",\"enum\":[\"raw\",\"pretty\"]},\"trans_id_t\":{\"description\":\"Required for CUD operation, it shall be same number as got from transaction->start\",\"type\":\"integer\",\"minimum\":1}}}",
"simpletype": "complex"
}
```
@ -1209,7 +1171,6 @@ Unknown type ``.
"trans_type_t": { "type": "string", "enum": ["start", "commit", "abort", "status"] },
"srv_type_t": { "type": "string", "enum": ["register", "list"] },
"format_t": { "type": "string", "default": "pretty", "enum": ["raw", "pretty"] },
"instance_mode_t": { "type": "integer", "default": 0, "minimum": 0, "maximum": 1 },
"trans_id_t": {
"description": "Required for CUD operation, it shall be same number as got from transaction->start",
"type": "integer",
@ -1334,7 +1295,6 @@ Input arguments for the operate command as defined in TR-181-2.13
| Property | Type | Required | Default |
| --------------- | ------- | -------- | ---------- |
| `format` | string | Optional | `"pretty"` |
| `instance_mode` | integer | Optional | `0` |
| `proto` | string | Optional | `"both"` |
#### format
@ -1358,21 +1318,6 @@ The value of this property **must** be equal to one of the [known values below](
| raw |
| pretty |
#### instance_mode
`instance_mode`
- is optional
- type: reference
- default: `0`
##### instance_mode Type
`integer`
- minimum value: `0`
- maximum value: `1`
#### proto
`proto`
@ -1398,7 +1343,7 @@ The value of this property **must** be equal to one of the [known values below](
### Ubus CLI Example
```
ubus call bbf operate {"command":"ex in sint ullamco","command_key":"in culpa in","input":{},"optional":{"format":"raw","proto":"cwmp","instance_mode":1}}
ubus call bbf operate {"command":"ex in sint ullamco","command_key":"in culpa in","input":{},"optional":{"format":"raw","proto":"cwmp"}}
```
### JSONRPC Example
@ -1416,7 +1361,7 @@ ubus call bbf operate {"command":"ex in sint ullamco","command_key":"in culpa in
"command": "ex in sint ullamco",
"command_key": "in culpa in",
"input": {},
"optional": { "format": "raw", "proto": "cwmp", "instance_mode": 1 }
"optional": { "format": "raw", "proto": "cwmp" }
}
]
}
@ -2090,25 +2035,9 @@ To set multiple values at once, path should be relative to object elements
| Property | Type | Required | Default |
| ---------------- | ------- | -------- | -------- |
| `instance_mode` | integer | Optional | `0` |
| `proto` | string | Optional | `"both"` |
| `transaction_id` | integer | Optional | |
#### instance_mode
`instance_mode`
- is optional
- type: reference
- default: `0`
##### instance_mode Type
`integer`
- minimum value: `0`
- maximum value: `1`
#### proto
`proto`
@ -2214,7 +2143,7 @@ value of the object element provided in path, path should contains valid writabl
### Ubus CLI Example
```
ubus call bbf set {"path":"Duis et","value":"elit velit fugiat mollit sunt","optional":{"proto":"cwmp","instance_mode":0,"transaction_id":94067988},"obj_path":{}}
ubus call bbf set {"path":"Duis et","value":"elit velit fugiat mollit sunt","optional":{"proto":"cwmp","transaction_id":94067988},"obj_path":{}}
```
### JSONRPC Example
@ -2231,7 +2160,7 @@ ubus call bbf set {"path":"Duis et","value":"elit velit fugiat mollit sunt","opt
{
"path": "Duis et",
"value": "elit velit fugiat mollit sunt",
"optional": { "proto": "cwmp", "instance_mode": 0, "transaction_id": 94067988 },
"optional": { "proto": "cwmp", "transaction_id": 94067988 },
"obj_path": {}
}
]

View file

@ -29,8 +29,7 @@
},
"cli": {
"config": {
"proto": "both",
"instance_mode": 0
"proto": "both"
},
"input": {
"type": "UBUS",
@ -382,11 +381,17 @@ To configure the log_level in micro-service, update the `loglevel` module json f
```json
# cat /etc/bbfdm/micro_services/sshmngr.json
{
"daemon": {
"enable": "1",
"service_name": "sshmngr",
"config": {
"loglevel": "1"
"cli": {
"config": {
"proto": "usp" // usp, cwmp
},
"input": {
"type": "UBUS", // JSON, UBUS, DotSO, UNIX
"name": "bbfdm"
},
"output": {
"type": "CLI" // CLI, JSON
}
}
}
}

View file

@ -318,7 +318,6 @@ static char *bbfdm_get_reference_value(char *reference_path)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string("usp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string("0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
dmubus_call("bbfdm", "get",

View file

@ -183,9 +183,6 @@ struct dmctx {
char *addobj_instance;
char *linker;
char *linker_param;
unsigned int alias_register;
unsigned int nbrof_instance;
unsigned int instance_mode;
unsigned int dm_type;
unsigned char inparam_isparam;
unsigned char findparam;
@ -346,11 +343,6 @@ enum fault_code_enum {
__FAULT_MAX
};
enum instance_mode {
INSTANCE_MODE_NUMBER,
INSTANCE_MODE_ALIAS
};
enum dm_browse_enum {
DM_ERROR = -1,
DM_OK = 0,

View file

@ -644,21 +644,6 @@ int get_number_of_entries(struct dmctx *ctx, void *data, char *instance, int (*b
return node.num_of_entries;
}
static int get_instance_mode(struct dmctx *dmctx, DMNODE *node)
{
unsigned char instancelevel = node->instance_level;
int inst_mode = INSTANCE_MODE_NUMBER;
if (dmctx->nbrof_instance <= instancelevel) {
if (dmctx->instance_mode == INSTANCE_MODE_ALIAS)
inst_mode = INSTANCE_MODE_ALIAS;
} else if (dmctx->alias_register & (1 << instancelevel)) {
inst_mode = INSTANCE_MODE_ALIAS;
}
return inst_mode;
}
static int find_max_instance(struct dmctx *ctx, DMNODE *node)
{
if (node->max_instance == 0) {
@ -685,21 +670,6 @@ char *handle_instance(struct dmctx *dmctx, DMNODE *parent_node, struct uci_secti
dmuci_set_value_by_section(s, inst_opt, buf);
instance = dmstrdup(buf);
}
int inst_mode = get_instance_mode(dmctx, parent_node);
if (inst_mode == INSTANCE_MODE_ALIAS) {
char *alias = "";
dmuci_get_value_by_section_string(s, alias_opt, &alias);
if (alias && alias[0] == '\0') {
snprintf(buf, sizeof(buf), "cpe-%s", instance);
dmuci_set_value_by_section(s, alias_opt, buf);
alias = dmstrdup(buf);
}
snprintf(buf, sizeof(buf), "[%s]", alias);
instance = dmstrdup(buf);
}
break;
case BROWSE_FIND_MAX_INST:
case BROWSE_NUM_OF_ENTRIES:
@ -717,9 +687,6 @@ char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node,
switch(parent_node->browse_type) {
case BROWSE_NORMAL:
dmasprintf(&instance, "%d", inst_nbr);
int inst_mode = get_instance_mode(dmctx, parent_node);
if (inst_mode == INSTANCE_MODE_ALIAS)
dmasprintf(&instance, "[cpe-%d]", inst_nbr);
break;
case BROWSE_FIND_MAX_INST:
case BROWSE_NUM_OF_ENTRIES:
@ -730,86 +697,6 @@ char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node,
return instance;
}
char *update_instance(char *max_inst, int argc, ...)
{
va_list arg;
char *instance, *last_inst = NULL;
int i = 0;
void *argv[8] = {0};
va_start(arg, argc);
for (i = 0; i < argc; i++) {
argv[i] = va_arg(arg, void*);
}
va_end(arg);
instance = update_instance_alias(0, &last_inst, &max_inst, argv);
return instance;
}
static int get_max_instance(char *dmmap_package, char *section_type, char *inst_opt, int (*check_browse)(struct uci_section *section, void *data), void *data)
{
struct uci_section *s;
char *inst;
int max = 0;
uci_path_foreach_sections(bbfdm, dmmap_package, section_type, s) {
if (check_browse && check_browse(s, data) != 0)
continue;
dmuci_get_value_by_section_string(s, inst_opt, &inst);
if (DM_STRLEN(inst) == 0)
continue;
int instance = DM_STRTOL(inst);
max = max > instance ? max : instance;
}
return max;
}
char *update_instance_alias(int action, char **last_inst, char **max_inst, void *argv[])
{
char *instance, *alias;
char buf[64] = {0};
int max_instance = 0;
struct uci_section *s = (struct uci_section *) argv[0];
char *inst_opt = (char *) argv[1];
char *alias_opt = (char *) argv[2];
int (*check_browse)(struct uci_section *section, void *data) = argv[3];
void *data = (void *) argv[4];
if (*max_inst == NULL)
max_instance = get_max_instance(section_config(s), section_type(s), inst_opt, check_browse, data);
else
max_instance = DM_STRTOL(*max_inst);
dmuci_get_value_by_section_string(s, inst_opt, &instance);
if (instance[0] == '\0') {
snprintf(buf, sizeof(buf), "%d", max_instance + 1);
dmuci_set_value_by_section(s, inst_opt, buf);
*max_inst = dmstrdup(instance);
} else {
dmasprintf(max_inst, "%d", max_instance);
}
*last_inst = instance;
if (action == INSTANCE_MODE_ALIAS) {
dmuci_get_value_by_section_string(s, alias_opt, &alias);
if (alias[0] == '\0') {
snprintf(buf, sizeof(buf), "cpe-%s", instance);
dmuci_set_value_by_section(s, alias_opt, buf);
alias = dmstrdup(buf);
}
snprintf(buf, sizeof(buf), "[%s]", alias);
instance = dmstrdup(buf);
}
return instance;
}
int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "";
@ -1096,24 +983,6 @@ static char *get_default_value_by_type(int type)
}
}
void dmentry_instance_lookup_inparam(struct dmctx *ctx)
{
char *pch, *spch, *in_param;
in_param = dmstrdup(ctx->in_param);
int i = 0;
for (pch = strtok_r(in_param, ".", &spch); pch != NULL; pch = strtok_r(NULL, ".", &spch)) {
if (pch[0]== '[') {
ctx->alias_register |= (1 << i);
i++;
} else if (isdigit(pch[0])) {
i++;
}
}
dmfree(in_param);
ctx->nbrof_instance = i;
}
static void get_reference_paramater_value(struct dmctx *dmctx, char *in_value, char *str, size_t size)
{
char *pch = NULL, *pchr = NULL;
@ -1156,7 +1025,6 @@ static int get_ubus_value(struct dmctx *dmctx, struct dmnode *node)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
dmubus_call(ubus_name, "get",
@ -1236,7 +1104,6 @@ static int get_ubus_supported_dm(struct dmctx *dmctx, struct dmnode *node)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
dmubus_call(ubus_name, "schema",
@ -1375,7 +1242,6 @@ static int get_ubus_instances(struct dmctx *dmctx, struct dmnode *node)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
dmubus_call(ubus_name, "instances",
@ -1426,7 +1292,6 @@ static int add_ubus_object(struct dmctx *dmctx, struct dmnode *node)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
json_object_object_add(in_args, "transaction_id", json_object_new_int(dmctx->trans_id));
@ -1473,7 +1338,6 @@ static int del_ubus_object(struct dmctx *dmctx, struct dmnode *node)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
json_object_object_add(in_args, "transaction_id", json_object_new_int(dmctx->trans_id));
@ -1545,7 +1409,6 @@ static int set_ubus_value(struct dmctx *dmctx, struct dmnode *node)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
json_object_object_add(in_args, "transaction_id", json_object_new_int(dmctx->trans_id));
@ -1600,7 +1463,6 @@ static int get_ubus_name(struct dmctx *dmctx, struct dmnode *node)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string("cwmp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
dmubus_call(ubus_name, "schema",
@ -1664,7 +1526,6 @@ static int operate_ubus(struct dmctx *dmctx, struct dmnode *node)
char *ubus_name = node->obj->checkdep;
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
dmubus_call_blocking(ubus_name, "operate",
@ -1736,7 +1597,6 @@ static int get_ubus_reference_value(struct dmctx *dmctx, struct dmnode *node)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
dmubus_call(ubus_name, "get",
@ -2487,7 +2347,6 @@ static int get_key_ubus_value(struct dmctx *dmctx, struct dmnode *node)
json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp"));
json_object_object_add(in_args, "instance_mode", json_object_new_string(dmctx->instance_mode ? "1" : "0"));
json_object_object_add(in_args, "format", json_object_new_string("raw"));
dmubus_call(ubus_name, "get",
@ -2584,106 +2443,6 @@ int dm_entry_get_reference_param(struct dmctx *dmctx)
return (dmctx->stop) ? err : FAULT_9005;
}
/******************
* get linker param
*****************/
static int get_linker_check_obj(DMOBJECT_ARGS)
{
char *link_val = "";
if (!get_linker)
return FAULT_9005;
if (node->obj->browseinstobj && !node->is_instanceobj)
return FAULT_9005;
get_linker(node->current_object, dmctx, data, instance, &link_val);
if (dmctx == NULL)
return FAULT_9005;
if (dmctx->linker == NULL)
return FAULT_9005;
if (dmctx->linker[0] == '\0')
return FAULT_9005;
if (link_val && link_val[0] != '\0' && DM_STRCMP(link_val, dmctx->linker) == 0) {
if (node->current_object[DM_STRLEN(node->current_object) - 1] == '.')
node->current_object[DM_STRLEN(node->current_object) - 1] = 0;
dmctx->linker_param = dmstrdup(node->current_object);
dmctx->stop = true;
return 0;
}
return FAULT_9005;
}
static int get_linker_check_param(DMPARAM_ARGS)
{
return FAULT_9005;
}
int dm_entry_get_linker(struct dmctx *dmctx)
{
int err = 0;
DMOBJ *root = dmctx->dm_entryobj;
DMNODE node = { .current_object = "" };
dmctx->method_obj = get_linker_check_obj;
dmctx->method_param = get_linker_check_param;
dmctx->checkobj = plugin_obj_match;
dmctx->checkleaf = plugin_leaf_onlyobj_match;
err = dm_browse(dmctx, &node, root, NULL, NULL);
return (dmctx->stop) ? err : FAULT_9005;
}
/******************
* get linker value
*****************/
static int get_linker_value_check_obj(DMOBJECT_ARGS)
{
if (!get_linker)
return FAULT_9005;
if (DM_STRCMP(node->current_object, dmctx->in_param) == 0) {
char *link_val = NULL;
if (!data || !instance)
return FAULT_9005;
get_linker(node->current_object, dmctx, data, instance, &link_val);
dmctx->linker = link_val ? dmstrdup(link_val) : "";
dmctx->stop = true;
return 0;
}
return FAULT_9005;
}
static int get_linker_value_check_param(DMPARAM_ARGS)
{
return FAULT_9005;
}
int dm_entry_get_linker_value(struct dmctx *dmctx)
{
int err = 0;
DMOBJ *root = dmctx->dm_entryobj;
DMNODE node = { .current_object = "" };
dmctx->method_obj = get_linker_value_check_obj;
dmctx->method_param = get_linker_value_check_param;
dmctx->checkobj = plugin_obj_match;
dmctx->checkleaf = plugin_leaf_match;
dmentry_instance_lookup_inparam(dmctx);
err = dm_browse(dmctx, &node, root, NULL, NULL);
return (dmctx->stop) ? err : FAULT_9005;
}
/******************
* get reference value
*****************/
@ -2737,7 +2496,6 @@ int dm_entry_get_reference_value(struct dmctx *dmctx)
dmctx->method_param = get_reference_value_check_param;
dmctx->checkobj = plugin_obj_match;
dmctx->checkleaf = plugin_leaf_match;
dmentry_instance_lookup_inparam(dmctx);
err = dm_browse(dmctx, &node, root, NULL, NULL);
@ -2782,7 +2540,6 @@ int dm_entry_object_exists(struct dmctx *dmctx)
dmctx->method_param = object_exists_check_param;
dmctx->checkobj = plugin_obj_match;
dmctx->checkleaf = plugin_leaf_match;
dmentry_instance_lookup_inparam(dmctx);
err = dm_browse(dmctx, &node, root, NULL, NULL);

View file

@ -35,7 +35,6 @@ void add_list_parameter(struct dmctx *ctx, char *param_name, char *param_data, c
void free_all_list_parameter(struct dmctx *ctx);
int string_to_bool(char *v, bool *b);
char *get_value_by_reference(struct dmctx *ctx, char *value);
void dmentry_instance_lookup_inparam(struct dmctx *ctx);
int dm_entry_get_value(struct dmctx *dmctx);
int dm_entry_get_name(struct dmctx *ctx);
int dm_entry_get_supported_dm(struct dmctx *ctx);
@ -48,13 +47,8 @@ int dm_entry_operate(struct dmctx *dmctx);
int dm_entry_event(struct dmctx *dmctx);
int dm_entry_get_reference_param(struct dmctx *dmctx);
int dm_entry_get_reference_value(struct dmctx *dmctx);
int dm_entry_get_linker(struct dmctx *dmctx);
int dm_entry_get_linker_value(struct dmctx *dmctx);
int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance);
char *update_instance_alias(int action, char **last_inst, char **max_inst, void *argv[]);
char *update_instance(char *max_inst, int argc, ...);
static inline int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance)
{
dmctx->faultcode = dm_link_inst_obj(dmctx, parent_node, data, instance);

View file

@ -199,7 +199,6 @@ int bbf_entry_method(struct dmctx *ctx, int cmd)
return bbf_fault_map(ctx, FAULT_9005);
}
dmentry_instance_lookup_inparam(ctx);
ctx->iswildcard = DM_STRCHR(ctx->in_param, '*') ? 1 : 0;
ctx->stop = false;

View file

@ -439,70 +439,6 @@ static void test_api_bbfdm_get_set_library_parameter(void **state)
validate_parameter(ctx, "Device.WiFi.SSID.1.Enable", "0", "xsd:boolean");
}
static void test_api_bbfdm_get_set_standard_parameter_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
int fault = 0;
ctx->instance_mode = INSTANCE_MODE_ALIAS;
// get value ==> expected "0" error
ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel";
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
// validate parameter : name, type, value
validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "100", "xsd:unsignedInt");
// Set Wrong Value ==> expected "9007" error
ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel";
ctx->in_value = "64t";
fault = bbf_entry_method(ctx, BBF_SET_VALUE);
assert_int_equal(fault, FAULT_9007);
// set value ==> expected "0" error
ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel";
ctx->in_value = "52";
fault = bbf_entry_method(ctx, BBF_SET_VALUE);
assert_int_equal(fault, 0);
// get value ==> expected "0" error
ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel";
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
// validate parameter after setting to 64: name, type, value
validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "52", "xsd:unsignedInt");
// set value ==> expected "0" error
ctx->in_param = "Device.WiFi.Radio.[cpe-1].Alias";
ctx->in_value = "iopsys_test";
fault = bbf_entry_method(ctx, BBF_SET_VALUE);
assert_int_equal(fault, 0);
// get value ==> expected "0" error
ctx->in_param = "Device.WiFi.Radio.[iopsys_test].Alias";
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
// validate parameter after setting to 64: name, type, value
validate_parameter(ctx, "Device.WiFi.Radio.[iopsys_test].Alias", "iopsys_test", "xsd:string");
// set value ==> expected "0" error
ctx->in_param = "Device.WiFi.Radio.[iopsys_test].Channel";
ctx->in_value = "116";
fault = bbf_entry_method(ctx, BBF_SET_VALUE);
assert_int_equal(fault, 0);
// get value ==> expected "0" error
ctx->in_param = "Device.WiFi.Radio.[iopsys_test].Channel";
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
// validate parameter after setting to 64: name, type, value
validate_parameter(ctx, "Device.WiFi.Radio.[iopsys_test].Channel", "116", "xsd:unsignedInt");
}
static void test_api_bbfdm_input_value_validation_json_parameter(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -1777,7 +1713,6 @@ int main(void)
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_json_parameter, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_json_v1_parameter, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_library_parameter, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_standard_parameter_alias, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_input_value_validation_json_parameter, setup, teardown_commit),
// Add/Delete Object method test cases

View file

@ -137,38 +137,6 @@ static void test_api_bbfdm_get_value_wrong_parameter_path(void **state)
assert_true(&first_entry->list == &ctx->list_parameter);
}
static void test_api_bbfdm_get_value_object_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.";
ctx->instance_mode = INSTANCE_MODE_ALIAS;
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
}
static void test_api_bbfdm_get_value_parameter_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.WiFi.Radio.[cpe-1].Alias";
ctx->instance_mode = INSTANCE_MODE_ALIAS;
fault = bbf_entry_method(ctx, BBF_GET_VALUE);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
}
static void test_api_bbfdm_get_name_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -233,23 +201,6 @@ static void test_api_bbfdm_get_name_wrong_object_path(void **state)
assert_true(&first_entry->list == &ctx->list_parameter);
}
static void test_api_bbfdm_get_name_parameter_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
ctx->in_param = "Device.WiFi.Radio.[cpe-1].Enable";
ctx->instance_mode = INSTANCE_MODE_ALIAS;
ctx->nextlevel = false;
fault = bbf_entry_method(ctx, BBF_GET_NAME);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
}
static void test_api_bbfdm_set_value_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -322,19 +273,6 @@ static void test_api_bbfdm_set_value_parameter_wrong_value(void **state)
assert_int_equal(fault, FAULT_9007);
}
static void test_api_bbfdm_set_value_parameter_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
int fault = 0;
ctx->in_param = "Device.Users.User.[cpe-1].Username";
ctx->in_value = "test";
ctx->instance_mode = INSTANCE_MODE_ALIAS;
fault = bbf_entry_method(ctx, BBF_SET_VALUE);
assert_int_equal(fault, 0);
}
static void test_api_bbfdm_add_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -699,15 +637,12 @@ int main(void)
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_empty, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_wrong_object_path, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_wrong_parameter_path, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_object_alias, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_parameter_alias, setup, teardown_commit),
// Get Name method test cases
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_object, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_parameter, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_dot, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_wrong_object_path, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_parameter_alias, setup, teardown_commit),
// Set Value method test cases
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_object, setup, teardown_revert),
@ -716,7 +651,6 @@ int main(void)
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_wrong_parameter_path, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter_non_writable, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter_wrong_value, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter_alias, setup, teardown_commit),
// Add Object method test cases
cmocka_unit_test_setup_teardown(test_api_bbfdm_add_object, setup, teardown_commit),

View file

@ -15,8 +15,7 @@
},
"cli": {
"config": {
"proto": "both",
"instance_mode": 0
"proto": "both"
},
"input": {
"type": "UBUS",

View file

@ -235,8 +235,7 @@ def create_bbfdm_input_json_file(proto, dm_name=None):
},
"cli": {
"config": {
"proto": proto,
"instance_mode": 0
"proto": proto
},
"input": {
"type": "DotSo",