Ticket refs #5811: BBF JSON doesn't support indexes

This commit is contained in:
Amin Ben Ramdhane 2021-08-25 12:45:15 +01:00
parent e3483f5935
commit c6b88c7668
7 changed files with 322 additions and 40 deletions

View file

@ -495,36 +495,10 @@ The application should bring its JSON file under **'/etc/bbfdm/json/'** path wit
}
```
- **UBUS command:** ubus call network.interface status '{"interface":"lan"}' | jsonfilter -e @.device
- **@Name:** the section name of paraent object, in this example, the section name is "lan"
```bash
"SSID": {
"type": "string",
"protocols": [
"cwmp",
"usp"
],
"read": true,
"write": false,
"mapping": [
{
"type" : "ubus",
"ubus" : {
"object" : "network.interface",
"method" : "status",
"args" : {
"interface" : "@Name"
},
"key" : "device"
}
}
]
}
```
- **UBUS command:** ubus call wifi status | jsonfilter -e @.radios[0].noise
- **@i:** is the number of instance object
```bash
"Noise": {
"type": "int",
@ -541,7 +515,7 @@ The application should bring its JSON file under **'/etc/bbfdm/json/'** path wit
"object" : "wifi",
"method" : "status",
"args" : {},
"key" : "radios[i-1].noise"
"key" : "radios[@i-1].noise"
}
}
]

View file

@ -321,6 +321,21 @@ static int delete_obj(char *refparam, struct dmctx *ctx, void *data, char *insta
return 0;
}
static char *get_param_ubus_value(json_object *json_obj, char *arguments)
{
char *value = "";
char *opt = strchr(arguments, '.');
if (opt) {
*opt = '\0';
value = dmjson_get_value(json_obj, 2, arguments, opt + 1);
} else {
value = dmjson_get_value(json_obj, 1, arguments);
}
return value;
}
static int getvalue_param(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct dm_json_parameter *pleaf = NULL;
@ -392,18 +407,15 @@ static int getvalue_param(char *refparam, struct dmctx *ctx, void *data, char *i
DM_ASSERT(res, *value = "");
if (arg6) {
char arg6_1[128] = "";
DM_STRNCPY(arg6_1, arg6, sizeof(arg6_1));
char *opt = strchr(arg6_1, '.');
if (opt) {
*opt = '\0';
char *arg6_2 = opt + 1;
if (data && (strcmp(arg6_1, "@Name") == 0))
*value = dmjson_get_value(res, 2, section_name((struct uci_section *)data), arg6_2);
else
*value = dmjson_get_value(res, 2, arg6_1, arg6_2);
char arg6_buf[128] = "";
DM_STRNCPY(arg6_buf, arg6, sizeof(arg6_buf));
char *is_array = strstr(arg6_buf, "[@i-1]");
if (is_array) {
char *arguments = is_array + sizeof("[@i-1]");
*value = get_param_ubus_value((json_object *)data, arguments);
} else {
*value = dmjson_get_value(res, 1, arg6);
*value = get_param_ubus_value(res, arg6_buf);
}
}
} else {

View file

@ -114,6 +114,42 @@ static void test_api_bbfdm_get_set_json_parameter(void **state)
// validate parameter after setting to fr: name, type, value
validate_parameter(ctx, "Device.UserInterface.CurrentLanguage", "fr", "xsd:string");
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.X_IOPSYS_EU_Radio.1.Noise", NULL, NULL);
printf("fault=%d \n", fault);
assert_int_equal(fault, 0);
// validate parameter : name, type, value
validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.2.Noise", "-87", "xsd:int");
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.X_IOPSYS_EU_Radio.2.Noise", NULL, NULL);
assert_int_equal(fault, 0);
// validate parameter : name, type, value
validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.2.Noise", "-85", "xsd:int");
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.X_IOPSYS_EU_Radio.2.Band", NULL, NULL);
assert_int_equal(fault, 0);
// validate parameter : name, type, value
validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.2.Band", "2.4GHz", "xsd:string");
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.X_IOPSYS_EU_Radio.1.Stats.BytesSent", NULL, NULL);
assert_int_equal(fault, 0);
// validate parameter : name, type, value
validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.1.Stats.BytesSent", "14418177,", "xsd:unsignedInt");
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.X_IOPSYS_EU_Radio.2.Stats.BytesSent", NULL, NULL);
assert_int_equal(fault, 0);
// validate parameter : name, type, value
validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.2.Stats.BytesSent", "14417451", "xsd:unsignedInt");
}
static void test_api_bbfdm_get_set_library_parameter(void **state)

View file

@ -0,0 +1,113 @@
{
"Device.WiFi.X_IOPSYS_EU_Radio.{i}.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": true,
"mapping": {
"type": "ubus",
"ubus": {
"object": "wifi",
"method": "status",
"args": {},
"key": "radios"
}
},
"Noise": {
"type": "int",
"read": true,
"write": true,
"protocols": [
"cwmp",
"usp"
],
"datatype": "int",
"mapping": [
{
"type" : "ubus",
"ubus" : {
"object" : "wifi",
"method" : "status",
"args" : {},
"key" : "radios[@i-1].noise"
}
}
]
},
"Band": {
"type": "string",
"read": true,
"write": true,
"protocols": [
"cwmp",
"usp"
],
"datatype": "string",
"mapping": [
{
"type" : "ubus",
"ubus" : {
"object" : "wifi",
"method" : "status",
"args" : {},
"key" : "radios[@i-1].band"
}
}
]
},
"Device.WiFi.X_IOPSYS_EU_Radio.{i}.Stats.": {
"type": "object",
"protocols": [
"cwmp",
"usp"
],
"access": false,
"array": false,
"BytesSent": {
"type": "unsignedInt",
"read": true,
"write": true,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"type" : "ubus",
"ubus" : {
"object" : "wifi",
"method" : "status",
"args" : {},
"key" : "radios[@i-1].stats.tx_bytes"
}
}
]
},
"PacketsReceived": {
"type": "unsignedInt",
"read": true,
"write": true,
"protocols": [
"cwmp",
"usp"
],
"datatype": "unsignedInt",
"mapping": [
{
"type" : "ubus",
"ubus" : {
"object" : "wifi",
"method" : "status",
"args" : {},
"key" : "radios[@i-1].stats.rx_packets"
}
}
]
}
}
}
}

View file

@ -1,3 +1,16 @@
config wifi-device 'test1'
option channel 'auto'
option hwmode 'auto'
option country 'DE'
option band 'a'
option bandwidth '80'
config wifi-iface 'test1_1'
option device 'test1'
option ifname 'test1'
option mode 'ap'
option encryption 'psk2'
config wifi-device 'test2'
option channel 'auto'
option hwmode 'auto'

View file

@ -0,0 +1,117 @@
{
"radios": [
{
"name": "test1",
"isup": true,
"standard": "802.11a/n/ac/ax",
"country": "DE",
"band": "5GHz",
"channel": 36,
"frequency": 5180,
"bandwidth": 80,
"noise": -87,
"maxrate": 2401,
"supp_bands": [
"5GHz"
],
"supp_std": [
"11a",
"11n",
"11ac",
"11ax"
],
"channels": [
36,
40,
44,
48,
52,
56,
60,
64,
100,
104,
108,
112,
116,
120,
124,
128,
132,
136,
140
],
"accesspoints": [
{
"ifname": "test1",
"status": "running",
"ssid": "iopsysWrt-44D43771AD50",
"bssid": "44:d4:37:71:ad:5f"
}
],
"backhauls": [
],
"stats": {
"tx_bytes": 14418177,
"tx_packets": 521,
"rx_bytes": 25518977,
"rx_packets": 789,
}
},
{
"name": "test2",
"isup": true,
"standard": "802.11b/g/n/ax",
"country": "DE",
"band": "2.4GHz",
"channel": 11,
"frequency": 2462,
"bandwidth": 20,
"noise": -85,
"maxrate": 286,
"supp_bands": [
"2.4GHz"
],
"supp_std": [
"11b",
"11g",
"11n",
"11ac",
"11ax"
],
"channels": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
],
"accesspoints": [
{
"ifname": "test2",
"status": "running",
"ssid": "iopsysWrt-44D43771AD50",
"bssid": "44:d4:37:71:ad:5e"
}
],
"backhauls": [
],
"stats": {
"tx_bytes": 14417451,
"tx_packets": 861,
"rx_bytes": 274118977,
"rx_packets": 809,
}
}
]
}

View file

@ -0,0 +1,17 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
case "$1" in
list)
echo '{ "status" : {} }'
;;
call)
case "$2" in
status)
cat /tmp/wifi.status.data 2>/dev/null
;;
esac
;;
esac