mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-26 03:53:58 +08:00
Compare commits
1 Commits
devel-no-h
...
dynamic_bb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1b793ca53 |
39
bbfdetest/Makefile
Normal file
39
bbfdetest/Makefile
Normal file
@@ -0,0 +1,39 @@
|
||||
#
|
||||
# Copyright (C) 2020 IOPSYS
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=bbfdetest
|
||||
PKG_VERSION:=1.0.0
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/bbfdetest
|
||||
SECTION:=utils
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=Library for example shared libraries
|
||||
DEPENDS:=+libubox +ubus +libbbf_api
|
||||
endef
|
||||
|
||||
TARGET_CFLAGS += \
|
||||
-I$(STAGING_DIR)/usr/include \
|
||||
-D_GNU_SOURCE
|
||||
|
||||
define Build/Prepare
|
||||
$(CP) ./src/* $(PKG_BUILD_DIR)/
|
||||
endef
|
||||
|
||||
define Package/bbfdetest/install
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bbfdetest.init $(1)/etc/init.d/bbfdetest
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bbfdetest $(1)/usr/sbin/bbfdetest
|
||||
$(INSTALL_DIR) $(1)/usr/lib/bbfdm
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/*.so $(1)/usr/lib/bbfdm
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,bbfdetest))
|
||||
|
||||
25
bbfdetest/src/Makefile
Normal file
25
bbfdetest/src/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
PROG = bbfdetest
|
||||
LIB = libbbfdetest.so
|
||||
|
||||
PROG_OBJS = bbfdetest.o
|
||||
LIB_OBJS = libbbfdetest.o
|
||||
|
||||
PROG_CFLAGS = $(CFLAGS) -fstrict-aliasing
|
||||
PROG_LDFLAGS = $(LDFLAGS) -lubus -lubox
|
||||
LIB_LDFLAGS = $(LDFLAGS) -lbbf_api
|
||||
|
||||
.PHONY: all
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(PROG_CFLAGS) $(FPIC) -c -o $@ $<
|
||||
|
||||
all: $(PROG) $(LIB)
|
||||
|
||||
$(PROG): $(PROG_OBJS)
|
||||
$(CC) $(PROG_LDFLAGS) -o $@ $^
|
||||
|
||||
$(LIB): $(LIB_OBJS)
|
||||
$(CC) $(PROG_CFLAGS) $(LIB_LDFLAGS) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -f *.o $(PROG) $(LIB)
|
||||
185
bbfdetest/src/bbfdetest.c
Normal file
185
bbfdetest/src/bbfdetest.c
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (C) 2020 iopsys Software Solutions AB
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License version 2.1
|
||||
* as published by the Free Software Foundation
|
||||
*
|
||||
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <libubox/blobmsg.h>
|
||||
#include <libubox/uloop.h>
|
||||
#include <libubus.h>
|
||||
|
||||
typedef struct SupportedDataModel
|
||||
{
|
||||
char url[128];
|
||||
char urn[128];
|
||||
char features[128];
|
||||
} Supported_DataModel;
|
||||
|
||||
struct SupportedDataModel DataModel[] = {
|
||||
{"http://www.broadband-forum.org/cwmp/tr-181-2-13-0.xml","urn:broadband-forum-org:tr-181-2-13-0","Router,Wireless,Firewall,NAT,IPv4,IPv6"},
|
||||
{"http://www.broadband-forum.org/cwmp/tr-104-1-1-0.xml","urn:broadband-forum-org:tr-104-1-1-0", "VoiceService"},
|
||||
{"http://www.broadband-forum.org/cwmp/tr-143-1-1-0.xml","urn:broadband-forum-org:tr-143-1-1-0", "Ping,TraceRoute,Download,Upload,UDPecho,ServerSelectionDiag"},
|
||||
{"http://www.broadband-forum.org/cwmp/tr-157-1-3-0.xml","urn:broadband-forum-org:tr-157-1-3-0", "Bulkdata,SoftwareModules"},
|
||||
};
|
||||
|
||||
void remove_new_line(char *buf)
|
||||
{
|
||||
int len;
|
||||
len = strlen(buf) - 1;
|
||||
if (buf[len] == '\n')
|
||||
buf[len] = 0;
|
||||
}
|
||||
|
||||
static int device_info(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg)
|
||||
{
|
||||
void *a, *t;
|
||||
struct blob_buf bb;
|
||||
char line[256];
|
||||
char *p;
|
||||
|
||||
memset(&bb,0,sizeof(struct blob_buf));
|
||||
blob_buf_init(&bb, 0);
|
||||
|
||||
FILE* fs = fopen( "/proc/cpuinfo" , "r");
|
||||
if (fs) {
|
||||
a = blobmsg_open_array(&bb, "processor");
|
||||
while (fgets(line, 256, fs)) {
|
||||
remove_new_line(line);
|
||||
strtok_r(line, ":", &p);
|
||||
if (strcasestr(line, "processor")) {
|
||||
t = blobmsg_open_table(&bb, "");
|
||||
blobmsg_add_u32(&bb, "number", atoi(p+1));
|
||||
}
|
||||
if (strcasestr(line, "model")) {
|
||||
blobmsg_add_string(&bb, "model", p+1);
|
||||
blobmsg_close_table(&bb, t);
|
||||
}
|
||||
}
|
||||
fclose(fs);
|
||||
blobmsg_close_array(&bb, a);
|
||||
}
|
||||
|
||||
a = blobmsg_open_array(&bb, "dataModel");
|
||||
for (int i = 0; i < sizeof(DataModel)/sizeof(struct SupportedDataModel); i++) {
|
||||
t = blobmsg_open_table(&bb, "");
|
||||
blobmsg_add_string(&bb, "url", DataModel[i].url);
|
||||
blobmsg_add_string(&bb, "urn", DataModel[i].urn);
|
||||
blobmsg_add_string(&bb, "features", DataModel[i].features);
|
||||
blobmsg_close_table(&bb, t);
|
||||
}
|
||||
blobmsg_close_array(&bb, a);
|
||||
|
||||
ubus_send_reply(ctx, req, bb.head);
|
||||
blob_buf_free(&bb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum {
|
||||
PING_HOST,
|
||||
__PING_MAX
|
||||
};
|
||||
|
||||
static const struct blobmsg_policy ping_policy[__PING_MAX] = {
|
||||
[PING_HOST] = { .name = "host", .type = BLOBMSG_TYPE_STRING },
|
||||
};
|
||||
|
||||
static int device_ping(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg)
|
||||
{
|
||||
struct blob_attr *tb[__PING_MAX] = {NULL};
|
||||
char *p, *min, *avg, *max, line[512], command[512];
|
||||
struct blob_buf bb;
|
||||
FILE *log;
|
||||
int host_ping = 0;
|
||||
|
||||
if(blobmsg_parse(ping_policy, __PING_MAX, tb, blob_data(msg), blob_len(msg)))
|
||||
return UBUS_STATUS_UNKNOWN_ERROR;
|
||||
|
||||
if (!tb[PING_HOST])
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
|
||||
snprintf(command, sizeof(command), "ping -c 1 -W 1 %s", blobmsg_get_string(tb[PING_HOST]));
|
||||
|
||||
memset(&bb,0,sizeof(struct blob_buf));
|
||||
blob_buf_init(&bb, 0);
|
||||
|
||||
if ((log = popen(command, "r"))) {
|
||||
while (fgets(line, sizeof(line), log) != NULL) {
|
||||
if (strstr(line, "round-trip")) {
|
||||
host_ping = 1;
|
||||
blobmsg_add_u8(&bb,"status", true);
|
||||
strtok_r(line, "=", &min);
|
||||
strtok_r(min+1, "/", &avg);
|
||||
blobmsg_add_string(&bb, "min", min+1);
|
||||
strtok_r(avg, "/", &max);
|
||||
blobmsg_add_string(&bb, "avg", avg);
|
||||
strtok_r(max, " ", &p);
|
||||
blobmsg_add_string(&bb, "max", max);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pclose(log);
|
||||
}
|
||||
|
||||
if (!host_ping)
|
||||
blobmsg_add_u8(&bb,"status", false);
|
||||
|
||||
ubus_send_reply(ctx, req, bb.head);
|
||||
blob_buf_free(&bb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ubus_method device_object_methods[] = {
|
||||
UBUS_METHOD_NOARG("info", device_info),
|
||||
UBUS_METHOD("ping", device_ping, ping_policy),
|
||||
};
|
||||
|
||||
static struct ubus_object_type device_object_type = UBUS_OBJECT_TYPE("device", device_object_methods);
|
||||
|
||||
static struct ubus_object device_object = {
|
||||
.name = "device",
|
||||
.type = &device_object_type,
|
||||
.methods = device_object_methods,
|
||||
.n_methods = ARRAY_SIZE(device_object_methods),
|
||||
};
|
||||
|
||||
static void device_init(struct ubus_context *ctx)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ubus_add_object(ctx, &device_object);
|
||||
if (ret)
|
||||
fprintf(stderr, "Failed to publish '%s' object : %s\n", device_object.name, ubus_strerror(ret));
|
||||
|
||||
uloop_run();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *ubus_socket = NULL;
|
||||
struct ubus_context *ctx = NULL;
|
||||
|
||||
uloop_init();
|
||||
ctx = ubus_connect(ubus_socket);
|
||||
if (!ctx) {
|
||||
fprintf(stderr, "Failed to connect to ubus\n");
|
||||
return -1;
|
||||
}
|
||||
ubus_add_uloop(ctx);
|
||||
device_init(ctx);
|
||||
uloop_run();
|
||||
ubus_free(ctx);
|
||||
if (ctx) ubus_free(ctx);
|
||||
uloop_done();
|
||||
|
||||
return 0;
|
||||
}
|
||||
19
bbfdetest/src/bbfdetest.init
Normal file
19
bbfdetest/src/bbfdetest.init
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=94
|
||||
STOP=10
|
||||
|
||||
USE_PROCD=1
|
||||
PROG=/usr/sbin/bbfdetest
|
||||
|
||||
start_service() {
|
||||
procd_open_instance
|
||||
procd_set_param command ${PROG}
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
292
bbfdetest/src/libbbfdetest.c
Normal file
292
bbfdetest/src/libbbfdetest.c
Normal file
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
* Copyright (C) 2020 iopsys Software Solutions AB
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License version 2.1
|
||||
* as published by the Free Software Foundation
|
||||
*
|
||||
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
*/
|
||||
|
||||
#include <libbbf_api/dmbbf.h>
|
||||
#include <libbbf_api/dmcommon.h>
|
||||
#include <libbbf_api/dmuci.h>
|
||||
#include <libbbf_api/dmubus.h>
|
||||
#include <libbbf_api/dmjson.h>
|
||||
#include "libbbfdetest.h"
|
||||
|
||||
/* ********** RootDynamicObj ********** */
|
||||
LIB_MAP_OBJ tRootDynamicObj[] = {
|
||||
/* parentobj, nextobject */
|
||||
{"Device.IP.Diagnostics.", tdynamicIPDiagnosticsObj},
|
||||
{"Device.DeviceInfo.", tdynamicDeviceInfobj},
|
||||
{"Device.", tdynamicDeviceObj},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* ********** RootDynamicOperate ********** */
|
||||
LIB_MAP_OPERATE tRootDynamicOperate[] = {
|
||||
/* pathname, operation */
|
||||
{"Device.X_IOPSYS_EU_PingTEST.Run", dynamicDevicePingOperate},
|
||||
{"Device.X_IOPSYS_EU_Reboot", dynamicDeviceRebootOperate},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.IP.Diagnostics. *** */
|
||||
DMOBJ tdynamicIPDiagnosticsObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/
|
||||
{"X_IOPSYS_EU_PingTest", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tdynamicIPDiagnosticsX_IOPSYS_EU_PingTestParams, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.IP.Diagnostics.X_IOPSYS_EU_PingTest. *** */
|
||||
DMLEAF tdynamicIPDiagnosticsX_IOPSYS_EU_PingTestParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"DiagnosticsState", &DMWRITE, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_DiagnosticsState, setdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_DiagnosticsState, NULL, NULL, BBFDM_BOTH},
|
||||
{"Host", &DMWRITE, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_Host, setdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_Host, NULL, NULL, BBFDM_BOTH},
|
||||
{"MinimumResponseTime", &DMREAD, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_MinimumResponseTime, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"AverageResponseTime", &DMREAD, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_AverageResponseTime, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"MaximumResponseTime", &DMREAD, DMT_STRING, getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_MaximumResponseTime, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.DeviceInfo. *** */
|
||||
DMOBJ tdynamicDeviceInfobj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/
|
||||
{"SupportedDataModel", &DMREAD, NULL, NULL, NULL, browseDeviceInfoSupportedDataModelInst, NULL, NULL, NULL, NULL, tdynamicDeviceInfoSupportedDataModelTestParams, NULL, BBFDM_CWMP},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.DeviceInfo.SupportedDataModel.{i}. *** */
|
||||
DMLEAF tdynamicDeviceInfoSupportedDataModelTestParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"URL", &DMREAD, DMT_STRING, getdynamic_DeviceInfoSupportedDataModel_URL, NULL, NULL, NULL, BBFDM_CWMP},
|
||||
{"URN", &DMREAD, DMT_STRING, getdynamic_DeviceInfoSupportedDataModel_URN, NULL, NULL, NULL, BBFDM_CWMP},
|
||||
{"Features", &DMREAD, DMT_STRING, getdynamic_DeviceInfoSupportedDataModel_Features, NULL, NULL, NULL, BBFDM_CWMP},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device. *** */
|
||||
DMOBJ tdynamicDeviceObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/
|
||||
{"X_IOPSYS_EU_Processor", &DMREAD, NULL, NULL, NULL, browseDeviceX_IOPSYS_EU_ProcessorInst, NULL, NULL, NULL, NULL, tdynamicDeviceX_IOPSYS_EU_ProcessorParams, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.X_IOPSYS_EU_Processor.{i}. *** */
|
||||
DMLEAF tdynamicDeviceX_IOPSYS_EU_ProcessorParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"Architecture", &DMREAD, DMT_STRING, getdynamic_DeviceX_IOPSYS_EU_Processor_Architecture, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************
|
||||
* ENTRY METHOD
|
||||
/*************************************************************/
|
||||
int browseDeviceInfoSupportedDataModelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
||||
{
|
||||
json_object *res = NULL, *datamodel_obj = NULL, *arrobj = NULL;
|
||||
char *idx, *idx_last = NULL;
|
||||
int id = 0, j = 0;
|
||||
|
||||
dmubus_call("device", "info", UBUS_ARGS{}, 0, &res);
|
||||
if (res) {
|
||||
dmjson_foreach_obj_in_array(res, arrobj, datamodel_obj, j, 1, "dataModel") {
|
||||
idx = handle_update_instance(1, dmctx, &idx_last, update_instance_without_section, 1, ++id);
|
||||
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)datamodel_obj, idx) == DM_STOP)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int browseDeviceX_IOPSYS_EU_ProcessorInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
||||
{
|
||||
json_object *res = NULL, *processor_obj = NULL, *arrobj = NULL;
|
||||
char *idx, *idx_last = NULL;
|
||||
int id = 0, j = 0;
|
||||
|
||||
dmubus_call("device", "info", UBUS_ARGS{}, 0, &res);
|
||||
if (res) {
|
||||
dmjson_foreach_obj_in_array(res, arrobj, processor_obj, j, 1, "processor") {
|
||||
idx = handle_update_instance(1, dmctx, &idx_last, update_instance_without_section, 1, ++id);
|
||||
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)processor_obj, idx) == DM_STOP)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* GET & SET PARAM
|
||||
/*************************************************************/
|
||||
static int execute_pingtest()
|
||||
{
|
||||
json_object *res;
|
||||
char *host, *min, *avg, *max;
|
||||
|
||||
dmuci_get_varstate_string("cwmp", "@pingtest[0]", "Host", &host);
|
||||
if(host && host[0] == '\0')
|
||||
return 0;
|
||||
|
||||
dmubus_call("device", "ping", UBUS_ARGS{{"host", host, String}}, 1, &res);
|
||||
if (res) {
|
||||
dmuci_set_varstate_value("cwmp", "@pingtest[0]", "DiagnosticState", "Complete");
|
||||
min=dmjson_get_value(res, 1, "min");
|
||||
if(min!=NULL && strlen(min)>0)
|
||||
dmuci_set_varstate_value("cwmp", "@pingtest[0]", "Minimum", min);
|
||||
avg=dmjson_get_value(res, 1, "avg");
|
||||
if(avg!=NULL && strlen(avg)>0)
|
||||
dmuci_set_varstate_value("cwmp", "@pingtest[0]", "Average", avg);
|
||||
max=dmjson_get_value(res, 1, "max");
|
||||
if(max!=NULL && strlen(max)>0)
|
||||
dmuci_set_varstate_value("cwmp", "@pingtest[0]", "Maximum", max);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline char *pingtest_get(char *option, char *def)
|
||||
{
|
||||
char *tmp;
|
||||
dmuci_get_varstate_string("cwmp", "@pingtest[0]", option, &tmp);
|
||||
if(tmp && tmp[0] == '\0')
|
||||
return dmstrdup(def);
|
||||
else
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = pingtest_get("DiagnosticState", "None");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
char *tmp;
|
||||
struct uci_section *curr_section = NULL;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
break;
|
||||
case VALUESET:
|
||||
if (strcmp(value, "Requested") == 0) {
|
||||
curr_section = dmuci_walk_state_section("cwmp", "pingtest", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
|
||||
if(!curr_section)
|
||||
{
|
||||
dmuci_add_state_section("cwmp", "pingtest", &curr_section, &tmp);
|
||||
}
|
||||
dmuci_set_varstate_value("cwmp", "@pingtest[0]", "DiagnosticState", value);
|
||||
execute_pingtest();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = pingtest_get("Host", "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
char *tmp;
|
||||
struct uci_section *curr_section = NULL;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
break;
|
||||
case VALUESET:
|
||||
curr_section = dmuci_walk_state_section("cwmp", "pingtest", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
|
||||
if(!curr_section)
|
||||
{
|
||||
dmuci_add_state_section("cwmp", "pingtest", &curr_section, &tmp);
|
||||
}
|
||||
dmuci_set_varstate_value("cwmp", "@pingtest[0]", "Host", value);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_MinimumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = pingtest_get("Minimum", "0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_AverageResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = pingtest_get("Average", "0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_MaximumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = pingtest_get("Maximum", "0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getdynamic_DeviceInfoSupportedDataModel_URL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = dmjson_get_value((json_object *)data, 1, "url");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getdynamic_DeviceInfoSupportedDataModel_URN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = dmjson_get_value((json_object *)data, 1, "urn");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getdynamic_DeviceInfoSupportedDataModel_Features(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = dmjson_get_value((json_object *)data, 1, "features");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getdynamic_DeviceX_IOPSYS_EU_Processor_Architecture(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = dmjson_get_value((json_object *)data, 1, "model");
|
||||
if (strcasestr(*value, "arm"))
|
||||
*value = "arm";
|
||||
else if(strcasestr(*value,"mips"))
|
||||
*value = "mips";
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* OPERATE
|
||||
/*************************************************************/
|
||||
opr_ret_t dynamicDevicePingOperate(struct dmctx *dmctx, char *path, char *input)
|
||||
{
|
||||
json_object *ubus_res = NULL, *json_res = NULL;
|
||||
|
||||
json_res = json_tokener_parse((const char *)input);
|
||||
char *host = dmjson_get_value(json_res, 1, "host");
|
||||
if(host[0] == '\0')
|
||||
return UBUS_INVALID_ARGUMENTS;
|
||||
|
||||
dmubus_call("device", "ping", UBUS_ARGS{{"host", host, String}}, 1, &ubus_res);
|
||||
if (ubus_res) {
|
||||
char *param_min = dmjson_get_value(ubus_res, 1, "min");
|
||||
char *param_avg = dmjson_get_value(ubus_res, 1, "avg");
|
||||
char *param_max = dmjson_get_value(ubus_res, 1, "max");
|
||||
|
||||
add_list_paramameter(dmctx, dmstrdup("MinimumResponseTime"), param_min, "string", NULL, 0);
|
||||
add_list_paramameter(dmctx, dmstrdup("AverageResponseTime"), param_avg, "string", NULL, 0);
|
||||
add_list_paramameter(dmctx, dmstrdup("MaximumResponseTime"), param_max, "string", NULL, 0);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
opr_ret_t dynamicDeviceRebootOperate(struct dmctx *dmctx, char *path, char *input)
|
||||
{
|
||||
if(0 == dmubus_call_set("system", "reboot", UBUS_ARGS{}, 0))
|
||||
return SUCCESS;
|
||||
else
|
||||
return FAIL;
|
||||
}
|
||||
40
bbfdetest/src/libbbfdetest.h
Normal file
40
bbfdetest/src/libbbfdetest.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2020 iopsys Software Solutions AB
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License version 2.1
|
||||
* as published by the Free Software Foundation
|
||||
*
|
||||
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
*/
|
||||
|
||||
#ifndef __LIBBBFDETEST_H
|
||||
#define __LIBBBFDETEST_H
|
||||
|
||||
DMOBJ tdynamicIPDiagnosticsObj[];
|
||||
DMLEAF tdynamicIPDiagnosticsX_IOPSYS_EU_PingTestParams[];
|
||||
DMOBJ tdynamicDeviceInfobj[];
|
||||
DMLEAF tdynamicDeviceInfoSupportedDataModelTestParams[];
|
||||
DMOBJ tdynamicDeviceObj[];
|
||||
DMLEAF tdynamicDeviceX_IOPSYS_EU_ProcessorParams[];
|
||||
|
||||
int browseDeviceInfoSupportedDataModelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
|
||||
int browseDeviceX_IOPSYS_EU_ProcessorInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
|
||||
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int setdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int setdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_MinimumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_AverageResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int getdynamic_IPDiagnosticsX_IOPSYS_EU_PingTest_MaximumResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int getdynamic_DeviceInfoSupportedDataModel_URL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int getdynamic_DeviceInfoSupportedDataModel_URN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int getdynamic_DeviceInfoSupportedDataModel_Features(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
int getdynamic_DeviceX_IOPSYS_EU_Processor_Architecture(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
|
||||
opr_ret_t dynamicDevicePingOperate(struct dmctx *dmctx, char *path, char *input);
|
||||
opr_ret_t dynamicDeviceRebootOperate(struct dmctx *dmctx, char *path, char *input);
|
||||
|
||||
#endif //__LIBBBFDETEST_H
|
||||
|
||||
Reference in New Issue
Block a user