mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Move TR-143 Data Model to tr143d
This commit is contained in:
parent
3a2ffcf318
commit
694f363934
15 changed files with 59 additions and 4080 deletions
|
|
@ -113,6 +113,7 @@ All supported tools are presented in this file[BBFDM Tools](./tools/README.md)
|
|||
| Device.SSH. | sshmngr | https://dev.iopsys.eu/network/sshmngr.git |
|
||||
| Device.USB. | usbmngr | https://dev.iopsys.eu/system/usbmngr.git |
|
||||
| Device.Bridging. | bridgemngr | https://dev.iopsys.eu/network/bridgemngr.git |
|
||||
| Device.IP.Diagnostics. | tr143 | https://dev.iopsys.eu/bbf/tr143d.git |
|
||||
| Device.IP.Diagnostics.IPLayerCapacityMetrics. | tr471 | https://dev.iopsys.eu/bbf/tr471d.git |
|
||||
| Device.X_IOPSYS_EU_IGMP. | mcastmngr | https://dev.iopsys.eu/hal/mcastmngr.git |
|
||||
| Device.X_IOPSYS_EU_MLD. | mcastmngr | https://dev.iopsys.eu/hal/mcastmngr.git |
|
||||
|
|
|
|||
|
|
@ -1528,14 +1528,14 @@ static int _parse_daemon_output_options(bbfdm_config_t *config, json_object *dae
|
|||
strncpyt(config->out_root_obj, BBFDM_DEFAULT_UBUS_OBJ, sizeof(config->out_root_obj));
|
||||
}
|
||||
|
||||
// for main process ubus object name
|
||||
if (is_micro_service == false) {
|
||||
opt_val = dmjson_get_value(daemon_obj, 2, "output", "name");
|
||||
if (strlen(opt_val)) {
|
||||
strncpyt(config->out_name, opt_val, sizeof(config->out_name));
|
||||
} else {
|
||||
strncpyt(config->out_name, BBFDM_DEFAULT_UBUS_OBJ, sizeof(config->out_name));
|
||||
}
|
||||
opt_val = dmjson_get_value(daemon_obj, 2, "output", "name");
|
||||
if (strlen(opt_val)) {
|
||||
snprintf(config->out_name, sizeof(config->out_name), "%s%s%s",
|
||||
is_micro_service ? config->out_root_obj : opt_val,
|
||||
is_micro_service ? "." : "",
|
||||
is_micro_service ? opt_val : "");
|
||||
} else {
|
||||
snprintf(config->out_name, sizeof(config->out_name), "%s", is_micro_service ? "" : BBFDM_DEFAULT_UBUS_OBJ);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -1842,7 +1842,10 @@ int main(int argc, char **argv)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
snprintf(log_level, sizeof(log_level), "bbfdm.%s", bbfdm_ctx.config.service_name);
|
||||
snprintf(log_level, sizeof(log_level), "bbfdm%s%s",
|
||||
is_micro_service ? "." : "",
|
||||
is_micro_service ? bbfdm_ctx.config.service_name : "");
|
||||
|
||||
openlog(log_level, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
||||
|
||||
if (cli_argc) {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ static uint8_t find_number_of_objects(DM_MAP_OBJ *dynamic_obj)
|
|||
|
||||
static void fill_dotso_micro_service_out_args(bbfdm_config_t *config, DMOBJ *entryobj, char *parent_dm, int *idx)
|
||||
{
|
||||
char ms_name[128] = {0};
|
||||
|
||||
if (!config || !entryobj || !parent_dm || !idx || *idx >= MAX_OBJS)
|
||||
return;
|
||||
|
||||
|
|
@ -45,13 +47,16 @@ static void fill_dotso_micro_service_out_args(bbfdm_config_t *config, DMOBJ *ent
|
|||
|
||||
strncpyt(config->out_objects[(*idx)++], entryobj->obj, sizeof(config->out_objects[0]));
|
||||
|
||||
int len = DM_STRLEN(config->out_name);
|
||||
int len = DM_STRLEN(ms_name);
|
||||
if (len == 0) {
|
||||
snprintf(config->out_name, sizeof(config->out_name), "%s.%s", config->out_root_obj, entryobj->obj);
|
||||
snprintf(ms_name, sizeof(ms_name), "%s.%s", config->out_root_obj, entryobj->obj);
|
||||
} else {
|
||||
snprintf(config->out_name + len, sizeof(config->out_name) - len, "_%s", entryobj->obj);
|
||||
snprintf(ms_name + len, sizeof(ms_name) - len, "_%s", entryobj->obj);
|
||||
}
|
||||
}
|
||||
|
||||
if (DM_STRLEN(config->out_name) == 0)
|
||||
strncpyt(config->out_name, ms_name, sizeof(config->out_name));
|
||||
}
|
||||
|
||||
int load_dotso_plugin(void **lib_handle, const char *file_path, bbfdm_config_t *config, DMOBJ **main_entry)
|
||||
|
|
@ -129,7 +134,7 @@ int free_dotso_plugin(void *lib_handle)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void fill_json_micro_service_out_args(bbfdm_config_t *config, char *parent_dm, char *obj, int idx)
|
||||
static void fill_json_micro_service_out_args(bbfdm_config_t *config, char *parent_dm, char *obj, int idx, char *ms_name, size_t ms_name_len)
|
||||
{
|
||||
if (!config || !obj || idx >= MAX_OBJS)
|
||||
return;
|
||||
|
|
@ -137,11 +142,11 @@ static void fill_json_micro_service_out_args(bbfdm_config_t *config, char *paren
|
|||
strncpyt(config->out_parent_dm, parent_dm, sizeof(config->out_parent_dm));
|
||||
strncpyt(config->out_objects[idx], obj, sizeof(config->out_objects[idx]));
|
||||
|
||||
int len = DM_STRLEN(config->out_name);
|
||||
int len = DM_STRLEN(ms_name);
|
||||
if (len == 0) {
|
||||
snprintf(config->out_name, sizeof(config->out_name), "%s.%s", config->out_root_obj, obj);
|
||||
snprintf(ms_name, ms_name_len, "%s.%s", config->out_root_obj, obj);
|
||||
} else {
|
||||
snprintf(config->out_name + len, sizeof(config->out_name) - len, "_%s", obj);
|
||||
snprintf(ms_name + len, ms_name_len - len, "_%s", obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,6 +155,7 @@ int load_json_plugin(struct list_head *json_plugin, struct list_head *json_list,
|
|||
{
|
||||
DMOBJ *dm_entryobj = NULL;
|
||||
int json_plugin_version = JSON_VERSION_0;
|
||||
char ms_name[128] = {0};
|
||||
uint8_t idx = 0;
|
||||
|
||||
if (!file_path || !strlen(file_path) || !main_entry) {
|
||||
|
|
@ -202,7 +208,7 @@ int load_json_plugin(struct list_head *json_plugin, struct list_head *json_list,
|
|||
|
||||
// Fill out arguments if it is running as micro-service
|
||||
if (is_micro_service == true)
|
||||
fill_json_micro_service_out_args(config, obj_prefix, obj_name, idx);
|
||||
fill_json_micro_service_out_args(config, obj_prefix, obj_name, idx, ms_name, sizeof(ms_name));
|
||||
|
||||
// Remove '.' from object prefix
|
||||
if (obj_prefix[obj_prefix_len - 1] == '.')
|
||||
|
|
@ -227,6 +233,9 @@ int load_json_plugin(struct list_head *json_plugin, struct list_head *json_list,
|
|||
idx++;
|
||||
}
|
||||
|
||||
if (DM_STRLEN(config->out_name) == 0)
|
||||
strncpyt(config->out_name, ms_name, sizeof(config->out_name));
|
||||
|
||||
*main_entry = dm_entryobj;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ ADD_DEFINITIONS(-DBBF_VENDOR_PREFIX="${BBF_VENDOR_PREFIX}")
|
|||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SOURCE_DIR} -I${CMAKE_CURRENT_SOURCE_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/dmtree")
|
||||
|
||||
OPTION(BBF_TR181 "build with tr181 datamodel" ON)
|
||||
OPTION(BBF_TR143 "build with tr143 datamodel" ON)
|
||||
OPTION(BBF_WIFI_DATAELEMENTS "build with wifi dataelements datamodel" ON)
|
||||
|
||||
SET(BBF_DM_SOURCES dmlayer.c)
|
||||
|
|
@ -22,13 +21,7 @@ IF(BBF_TR181)
|
|||
ENDIF(BBF_WIFI_DATAELEMENTS)
|
||||
ENDIF(BBF_TR181)
|
||||
|
||||
IF(BBF_TR143)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/dmtree/tr143")
|
||||
FILE(GLOB BBF_TR143_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dmtree/tr143/*.c)
|
||||
add_compile_definitions(BBF_TR143)
|
||||
ENDIF(BBF_TR143)
|
||||
|
||||
ADD_LIBRARY(bbfdm SHARED ${BBF_DM_SOURCES} ${BBF_TR181_SOURCES} ${BBF_TR143_SOURCES})
|
||||
ADD_LIBRARY(bbfdm SHARED ${BBF_DM_SOURCES} ${BBF_TR181_SOURCES})
|
||||
|
||||
TARGET_LINK_LIBRARIES(bbfdm uci ubus ubox json-c blobmsg_json m bbfdm-api ssl crypto)
|
||||
|
||||
|
|
@ -42,29 +35,27 @@ INSTALL(DIRECTORY DESTINATION etc/bbfdm)
|
|||
INSTALL(DIRECTORY DESTINATION etc/bbfdm/dmmap)
|
||||
INSTALL(DIRECTORY DESTINATION usr/share/bbfdm/plugins)
|
||||
|
||||
IF(BBF_TR143)
|
||||
INSTALL(DIRECTORY DESTINATION usr/share/bbfdm)
|
||||
INSTALL(DIRECTORY DESTINATION usr/libexec/rpcd)
|
||||
FILE(GLOB scripts scripts/*)
|
||||
INSTALL(DIRECTORY DESTINATION usr/share/bbfdm)
|
||||
INSTALL(DIRECTORY DESTINATION usr/libexec/rpcd)
|
||||
FILE(GLOB scripts scripts/*)
|
||||
|
||||
FOREACH(script ${scripts})
|
||||
IF(IS_DIRECTORY ${script})
|
||||
INSTALL(DIRECTORY ${script}
|
||||
DESTINATION usr/share/bbfdm/scripts
|
||||
)
|
||||
ELSE()
|
||||
INSTALL(FILES ${script}
|
||||
PERMISSIONS OWNER_EXECUTE
|
||||
DESTINATION usr/share/bbfdm/scripts
|
||||
)
|
||||
ENDIF()
|
||||
ENDFOREACH()
|
||||
FOREACH(script ${scripts})
|
||||
IF(IS_DIRECTORY ${script})
|
||||
INSTALL(DIRECTORY ${script}
|
||||
DESTINATION usr/share/bbfdm/scripts
|
||||
)
|
||||
ELSE()
|
||||
INSTALL(FILES ${script}
|
||||
PERMISSIONS OWNER_EXECUTE
|
||||
DESTINATION usr/share/bbfdm/scripts
|
||||
)
|
||||
ENDIF()
|
||||
ENDFOREACH()
|
||||
|
||||
INSTALL(FILES scripts/bbf.diag
|
||||
PERMISSIONS OWNER_EXECUTE
|
||||
DESTINATION usr/libexec/rpcd
|
||||
)
|
||||
ENDIF(BBF_TR143)
|
||||
INSTALL(FILES scripts/bbf.diag
|
||||
PERMISSIONS OWNER_EXECUTE
|
||||
DESTINATION usr/libexec/rpcd
|
||||
)
|
||||
|
||||
string(REPLACE "," ";" VENDOR_LIST ${BBF_VENDOR_LIST})
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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 __DIAGNOSTICS_H
|
||||
#define __DIAGNOSTICS_H
|
||||
|
||||
#include "libbbfdm-api/dmcommon.h"
|
||||
|
||||
extern DMOBJ tIPDiagnosticsObj[];
|
||||
extern DMLEAF tIPDiagnosticsParams[];
|
||||
extern DMLEAF tIPDiagnosticsIPPingParams[];
|
||||
extern DMOBJ tIPDiagnosticsTraceRouteObj[];
|
||||
extern DMLEAF tIPDiagnosticsTraceRouteParams[];
|
||||
extern DMLEAF tIPDiagnosticsTraceRouteRouteHopsParams[];
|
||||
extern DMOBJ tIPDiagnosticsDownloadDiagnosticsObj[];
|
||||
extern DMLEAF tIPDiagnosticsDownloadDiagnosticsParams[];
|
||||
extern DMLEAF tIPDiagnosticsDownloadDiagnosticsPerConnectionResultParams[];
|
||||
extern DMOBJ tIPDiagnosticsUploadDiagnosticsObj[];
|
||||
extern DMLEAF tIPDiagnosticsUploadDiagnosticsParams[];
|
||||
extern DMLEAF tIPDiagnosticsUploadDiagnosticsPerConnectionResultParams[];
|
||||
extern DMLEAF tIPDiagnosticsUDPEchoConfigParams[];
|
||||
extern DMLEAF tIPDiagnosticsUDPEchoDiagnosticsParams[];
|
||||
extern DMLEAF tIPDiagnosticsServerSelectionDiagnosticsParams[];
|
||||
|
||||
#endif //__DIAGNOSTICS_H
|
||||
|
|
@ -12,9 +12,6 @@
|
|||
|
||||
#include "dmlayer.h"
|
||||
#include "ip.h"
|
||||
#if defined(BBF_TR143)
|
||||
#include "diagnostics.h"
|
||||
#endif
|
||||
|
||||
struct intf_ip_args
|
||||
{
|
||||
|
|
@ -2211,9 +2208,6 @@ static int operate_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *da
|
|||
DMOBJ tIPObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys, version*/
|
||||
{"Interface", &DMWRITE, addObjIPInterface, delObjIPInterface, NULL, browseIPInterfaceInst, NULL, NULL, tIPInterfaceObj, tIPInterfaceParams, NULL, BBFDM_BOTH, NULL},
|
||||
#if defined(BBF_TR143)
|
||||
{"Diagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tIPDiagnosticsObj, tIPDiagnosticsParams, NULL, BBFDM_BOTH, NULL},
|
||||
#endif
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# Script to activate image in specified time.
|
||||
#
|
||||
# Copyright © 2022 IOPSYS Software Solutions AB
|
||||
# Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
# Author: Amin Ben Romdhane <amin.benromdhane@iopsys.eu>
|
||||
#
|
||||
|
||||
ROOT="$(dirname "${0}")"
|
||||
|
|
|
|||
|
|
@ -1,223 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
. /usr/share/bbfdm/scripts/bbf_api
|
||||
|
||||
ipping_list() {
|
||||
json_add_object "ipping"
|
||||
json_add_string "host" "str"
|
||||
json_add_string "iface" "str"
|
||||
json_add_string "ip_proto" "str"
|
||||
json_add_string "nbr_of_rep" "str"
|
||||
json_add_string "timeout" "str"
|
||||
json_add_string "data_size" "str"
|
||||
json_add_string "dscp" "str"
|
||||
json_add_string "proto" "str"
|
||||
json_add_string "cancel" "str"
|
||||
json_close_object
|
||||
}
|
||||
|
||||
ipping_error() {
|
||||
json_init
|
||||
json_add_string "Status" "$1"
|
||||
json_add_string "IPAddressUsed" ""
|
||||
json_add_int "MinimumResponseTime" "9999"
|
||||
json_add_int "AverageResponseTime" "0"
|
||||
json_add_int "MaximumResponseTime" "0"
|
||||
json_add_int "MinimumResponseTimeDetailed" "999999999"
|
||||
json_add_int "AverageResponseTimeDetailed" "0"
|
||||
json_add_int "MaximumResponseTimeDetailed" "0"
|
||||
json_add_int "SuccessCount" "0"
|
||||
json_add_int "FailureCount" "$2"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$3" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="$1"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.IPAddressUsed=""
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="$2"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime=9999
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTimeDetailed=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTimeDetailed=999999999
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTimeDetailed=0
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
ipping_launch() {
|
||||
input="$1"
|
||||
|
||||
json_load "${input}"
|
||||
|
||||
json_get_var host host
|
||||
json_get_var iface iface
|
||||
json_get_var ip_proto ip_proto
|
||||
json_get_var nbr_of_rep nbr_of_rep
|
||||
json_get_var timeout timeout
|
||||
json_get_var dsize data_size
|
||||
json_get_var dscp dscp
|
||||
json_get_var proto proto
|
||||
json_get_var cancel cancel
|
||||
|
||||
if [ "${proto}" = "both_proto" ]; then
|
||||
old_pid=$(cat /tmp/ipping_pid)
|
||||
[ -n "${old_pid}" ] && {
|
||||
cmd=$(cat /proc/$old_pid/cmdline)
|
||||
}
|
||||
|
||||
if [[ "${cmd}" = *ipping* ]]; then
|
||||
kill -9 $old_pid
|
||||
fi
|
||||
|
||||
if [ "${cancel}" -eq "1" ]; then
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="None"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.IPAddressUsed=""
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="0"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime=9999
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTimeDetailed=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTimeDetailed=999999999
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTimeDetailed=0
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "None"
|
||||
json_add_string "IPAddressUsed" ""
|
||||
json_add_int "MinimumResponseTime" "9999"
|
||||
json_add_int "AverageResponseTime" "0"
|
||||
json_add_int "MaximumResponseTime" "0"
|
||||
json_add_int "MinimumResponseTimeDetailed" "999999999"
|
||||
json_add_int "AverageResponseTimeDetailed" "0"
|
||||
json_add_int "MaximumResponseTimeDetailed" "0"
|
||||
json_add_int "SuccessCount" "0"
|
||||
json_add_int "FailureCount" "0"
|
||||
json_dump
|
||||
|
||||
return
|
||||
else
|
||||
echo $$ > /tmp/ipping_pid
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="Requested_running"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
fi
|
||||
|
||||
# Assign default value
|
||||
[ -z "${nbr_of_rep}" ] && nbr_of_rep=3
|
||||
[ -z "${dsize}" ] && dsize=64
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-I $device" || device=""
|
||||
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
|
||||
if [ "$ip_proto" = "IPv4" ]; then ip_proto="-4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="-6"; else ip_proto=""; fi
|
||||
[ -z "${timeout}" ] && timeout=1 || timeout=$((timeout/1000))
|
||||
|
||||
# Fail if host is empty
|
||||
[ -z "${host}" ] && {
|
||||
ipping_error "Error_Internal" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
micros=1000
|
||||
success_count=0
|
||||
avg_time_sum=0
|
||||
avg_time_sum_det=0
|
||||
min=9999999
|
||||
min_det=999999999
|
||||
max=0
|
||||
max_det=0
|
||||
idx=0
|
||||
|
||||
while [ $idx -lt "${nbr_of_rep}" ]; do
|
||||
idx=$((idx+1))
|
||||
|
||||
res=$(ping -q ${ip_proto} -c 1 -s ${dsize} -W ${timeout} ${device} "${host}" 2>&1)
|
||||
|
||||
ba=$(echo "$res" | grep -E "bad address|unknown host|Name does not resolve")
|
||||
[ -n "$ba" ] && {
|
||||
ipping_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
stc=$(echo "$res" | grep "received")
|
||||
[ -z "$stc" ] && {
|
||||
ipping_error "Error_Other" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
times=$(echo "$res" | grep "min/avg/max")
|
||||
[ -z "$times" ] && continue
|
||||
sc1=$(echo "$stc" | awk '{print $4}')
|
||||
sc1=${sc1:-0}
|
||||
success_count=$((success_count+sc1))
|
||||
times=$(echo "$times" | awk -F'=' '{ print $2 }')
|
||||
min_time=$(echo "$times" | awk -F'[=/ ]' '{ print $2 }')
|
||||
avg_time=$(echo "$times" | awk -F'[=/ ]' '{ print $3 }')
|
||||
max_time=$(echo "$times" | awk -F'[=/ ]' '{ print $4 }')
|
||||
min_time=${min_time:-0}
|
||||
avg_time=${avg_time:-0}
|
||||
max_time=${max_time:-0}
|
||||
min_time_det=$(echo "$min_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
|
||||
avg_time_det=$(echo "$avg_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
|
||||
max_time_det=$(echo "$max_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
|
||||
min_time=$(awk "BEGIN{print $min_time * 1000}")
|
||||
avg_time=$(awk "BEGIN{print $avg_time * 1000}")
|
||||
max_time=$(awk "BEGIN{print $max_time * 1000}")
|
||||
[ "$min_time" -lt $min ] && min=$min_time
|
||||
[ "$max_time" -gt $max ] && max=$max_time
|
||||
avg_time_sum=$((avg_time_sum+avg_time))
|
||||
[ "$min_time_det" -lt $min_det ] && min_det=$min_time_det
|
||||
[ "$max_time_det" -gt $max_det ] && max_det=$max_time_det
|
||||
avg_time_sum_det=$((avg_time_sum_det+avg_time_det))
|
||||
done
|
||||
|
||||
failure_count=$((nbr_of_rep-success_count))
|
||||
[ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0
|
||||
[ $success_count -gt 0 ] && avg_time_det=$((avg_time_sum_det/success_count)) || avg_time_det=0
|
||||
avg_time=$(awk "BEGIN{print int($avg_time / 1000)}")
|
||||
min_time=$(awk "BEGIN{print int($min / 1000)}")
|
||||
max_time=$(awk "BEGIN{print int($max / 1000)}")
|
||||
min_time_det=$min_det
|
||||
max_time_det=$max_det
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "Complete"
|
||||
json_add_string "IPAddressUsed" "${ip_addr_used}"
|
||||
json_add_int "MinimumResponseTime" "${min_time}"
|
||||
json_add_int "AverageResponseTime" "${avg_time}"
|
||||
json_add_int "MaximumResponseTime" "${max_time}"
|
||||
json_add_int "MinimumResponseTimeDetailed" "${min_time_det}"
|
||||
json_add_int "AverageResponseTimeDetailed" "${avg_time_det}"
|
||||
json_add_int "MaximumResponseTimeDetailed" "${max_time_det}"
|
||||
json_add_int "SuccessCount" "${success_count}"
|
||||
json_add_int "FailureCount" "${failure_count}"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "${proto}" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="Complete"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.IPAddressUsed="${ip_addr_used}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount="${success_count}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="${failure_count}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime="${min_time}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTime="${avg_time}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime="${max_time}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTimeDetailed="${min_time_det}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTimeDetailed="${avg_time_det}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTimeDetailed="${max_time_det}"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
if [ "$1" = "list" ]; then
|
||||
ipping_list
|
||||
elif [ -n "$1" ]; then
|
||||
ipping_launch "$1"
|
||||
else
|
||||
ipping_error "Error_Internal" "1"
|
||||
fi
|
||||
|
|
@ -1,243 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
. /usr/share/bbfdm/scripts/bbf_api
|
||||
|
||||
serverselection_list() {
|
||||
json_add_object "serverselection"
|
||||
json_add_string "hostlist" "str"
|
||||
json_add_string "port" "str"
|
||||
json_add_string "iface" "str"
|
||||
json_add_string "ip_proto" "str"
|
||||
json_add_string "nbr_of_rep" "str"
|
||||
json_add_string "timeout" "str"
|
||||
json_add_string "protocol_used" "str"
|
||||
json_add_string "proto" "str"
|
||||
json_add_string "cancel" "str"
|
||||
json_close_object
|
||||
}
|
||||
|
||||
serverselection_error() {
|
||||
json_init
|
||||
json_add_string "Status" "$1"
|
||||
json_add_string "FastestHost" ""
|
||||
json_add_string "IPAddressUsed" ""
|
||||
json_add_int "MinimumResponseTime" "9999"
|
||||
json_add_int "AverageResponseTime" "0"
|
||||
json_add_int "MaximumResponseTime" "0"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$3" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState="$1"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.FastestHost=""
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MinimumResponseTime=9999
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.AverageResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MaximumResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.IPAddressUsed=""
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
serverselection_launch() {
|
||||
input="$1"
|
||||
|
||||
json_load "${input}"
|
||||
|
||||
json_get_var hostlist hostlist
|
||||
json_get_var port port
|
||||
json_get_var iface iface
|
||||
json_get_var ip_proto ip_proto
|
||||
json_get_var nbr_of_rep nbr_of_rep
|
||||
json_get_var timeout timeout
|
||||
json_get_var protocol_used protocol_used
|
||||
json_get_var proto proto
|
||||
json_get_var cancel cancel
|
||||
|
||||
if [ "${proto}" = "both_proto" ]; then
|
||||
old_pid=$(cat /tmp/serverselection_pid)
|
||||
|
||||
[ -n "${old_pid}" ] && {
|
||||
cmd=$(cat /proc/$old_pid/cmdline)
|
||||
}
|
||||
|
||||
if [[ "${cmd}" = *serverselection* ]]; then
|
||||
kill -9 $old_pid
|
||||
fi
|
||||
|
||||
if [ "${cancel}" -eq "1" ]; then
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState="None"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.FastestHost=""
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MinimumResponseTime=9999
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.AverageResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MaximumResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.IPAddressUsed=""
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "None"
|
||||
json_add_string "FastestHost" ""
|
||||
json_add_string "IPAddressUsed" ""
|
||||
json_add_int "MinimumResponseTime" "9999"
|
||||
json_add_int "AverageResponseTime" "0"
|
||||
json_add_int "MaximumResponseTime" "0"
|
||||
json_dump
|
||||
|
||||
return
|
||||
else
|
||||
echo $$ > /tmp/serverselection_pid
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState="Requested_running"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
fi
|
||||
|
||||
# Assign default value
|
||||
[ -z "${nbr_of_rep}" ] && nbr_of_rep=3
|
||||
[ -z "${port}" ] && port=7
|
||||
[ -z "${protocol_used}" ] && protocol_used="ICMP"
|
||||
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
|
||||
[ -z "${timeout}" ] && timeout=1 || timeout=$((timeout/1000))
|
||||
|
||||
# Fail if hostlist is empty
|
||||
[ -z "${hostlist}" ] && {
|
||||
serverselection_error "Error_Internal" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
micros=1000
|
||||
success_count=0
|
||||
avg_time_sum=0
|
||||
avg_time_host=9999999
|
||||
min=9999999
|
||||
max=0
|
||||
i=0
|
||||
|
||||
for host in $(echo "$hostlist" | tr "," "\n"); do
|
||||
if [ "$protocol_used" = "ICMP" ]; then
|
||||
if [ "$ip_proto" = "IPv4" ]; then ip_proto="-4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="-6"; else ip_proto=""; fi
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-I $device" || device=""
|
||||
|
||||
while [ $i -lt "$nbr_of_rep" ]; do
|
||||
i=$((i+1))
|
||||
|
||||
res=$(ping -q ${ip_proto} -c 1 -W ${timeout} ${device} "${host}" 2>&1)
|
||||
|
||||
ba=$(echo "$res" | grep "bad address")
|
||||
[ -n "$ba" ] && {
|
||||
serverselection_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
ba=$(echo "$res" | grep "unknown host")
|
||||
[ -n "$ba" ] && {
|
||||
serverselection_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
stc=$(echo "$res" | grep "received")
|
||||
[ -z "$stc" ] && {
|
||||
serverselection_error "Error_Other" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
times=$(echo "$res" | grep "min/avg/max")
|
||||
[ -z "$times" ] && break
|
||||
|
||||
sc1=$(echo "$stc" | awk '{print $4}')
|
||||
sc1=${sc1:-0}
|
||||
success_count=$((success_count+sc1))
|
||||
times=$(echo "$times" | awk -F'=' '{ print $2 }')
|
||||
min_time=$(echo "$times" | awk -F'[=/ ]' '{ print $2 }')
|
||||
avg_time=$(echo "$times" | awk -F'[=/ ]' '{ print $3 }')
|
||||
max_time=$(echo "$times" | awk -F'[=/ ]' '{ print $4 }')
|
||||
min_time=${min_time:-0}
|
||||
avg_time=${avg_time:-0}
|
||||
max_time=${max_time:-0}
|
||||
min_time=$(echo "$min_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
|
||||
avg_time=$(echo "$avg_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
|
||||
max_time=$(echo "$max_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
|
||||
[ "$min_time" -lt "$min" ] && min="$min_time"
|
||||
[ "$max_time" -gt "$max" ] && max="$max_time"
|
||||
avg_time_sum=$((avg_time_sum+avg_time))
|
||||
done
|
||||
else
|
||||
if [ "$ip_proto" = "IPv4" ]; then ip_proto="--protocol 4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="--protocol 6"; else ip_proto=""; fi
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-i $device" || device=""
|
||||
|
||||
while [ $i -lt "$nbr_of_rep" ]; do
|
||||
i=$((i+1))
|
||||
|
||||
res=$(udpechoclientd -c 1 -t $timeout --host "$host" --port "$port" $ip_proto $device 2>&1)
|
||||
|
||||
ba=$(echo "$res" | grep "Can't Resolve Host Name")
|
||||
[ -n "$ba" ] && {
|
||||
serverselection_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
ba=$(echo "$res" | grep "RCVD")
|
||||
[ -z "$ba" ] && {
|
||||
serverselection_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
times=$(echo "$res" | grep "rtt")
|
||||
[ -z "$times" ] && continue
|
||||
|
||||
sc1=$(echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }')
|
||||
sc1=${sc1:-0}
|
||||
success_count=$((success_count+sc1))
|
||||
max_time=$(echo "$times" | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }')
|
||||
min_time=$(echo "$times" | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }')
|
||||
avg_time=$(echo "$times" | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }')
|
||||
min_time=${min_time:-0}
|
||||
avg_time=${avg_time:-0}
|
||||
max_time=${max_time:-0}
|
||||
min_time=$(echo "$min_time" $micros | awk '{printf "%3.0f\n",$1*$2}')
|
||||
avg_time=$(echo "$avg_time" $micros | awk '{printf "%3.0f\n",$1*$2}')
|
||||
max_time=$(echo "$max_time" $micros | awk '{printf "%3.0f\n",$1*$2}')
|
||||
[ "$min_time" -lt "$min" ] && min="$min_time"
|
||||
[ "$max_time" -gt "$max" ] && max="$max_time"
|
||||
avg_time_sum=$((avg_time_sum+avg_time))
|
||||
done
|
||||
fi
|
||||
|
||||
[ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0
|
||||
[ "$avg_time" != "0" ] && [ $avg_time -lt $avg_time_host ] && avg_time_host="$avg_time" && min_time_host="$min" && max_time_host="$max" && fasthost="$host"
|
||||
success_count=0
|
||||
avg_time_sum=0
|
||||
min=9999999
|
||||
max=0
|
||||
i=0
|
||||
done
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "Complete"
|
||||
json_add_string "FastestHost" "${fasthost}"
|
||||
json_add_string "IPAddressUsed" "${ip_addr_used}"
|
||||
json_add_int "MinimumResponseTime" "${min_time}"
|
||||
json_add_int "AverageResponseTime" "${avg_time}"
|
||||
json_add_int "MaximumResponseTime" "${max_time}"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "${proto}" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState="Complete"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.FastestHost="${fasthost}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.IPAddressUsed="${ip_addr_used}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MinimumResponseTime="${min_time_host}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.AverageResponseTime="${avg_time_host}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MaximumResponseTime="${max_time_host}"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
if [ "$1" = "list" ]; then
|
||||
serverselection_list
|
||||
elif [ -n "$1" ]; then
|
||||
serverselection_launch "$1"
|
||||
else
|
||||
serverselection_error "Error_Internal" "1"
|
||||
fi
|
||||
|
|
@ -1,201 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
. /usr/share/bbfdm/scripts/bbf_api
|
||||
|
||||
udpecho_list() {
|
||||
json_add_object "udpecho"
|
||||
json_add_string "host" "str"
|
||||
json_add_string "port" "str"
|
||||
json_add_string "iface" "str"
|
||||
json_add_string "ip_proto" "str"
|
||||
json_add_string "nbr_of_rep" "str"
|
||||
json_add_string "timeout" "str"
|
||||
json_add_string "data_size" "str"
|
||||
json_add_string "dscp" "str"
|
||||
json_add_string "inter_trans_time" "str"
|
||||
json_add_string "proto" "str"
|
||||
json_add_string "cancel" "str"
|
||||
json_close_object
|
||||
}
|
||||
|
||||
udpecho_error() {
|
||||
json_init
|
||||
json_add_string "Status" "$1"
|
||||
json_add_string "IPAddressUsed" ""
|
||||
json_add_int "SuccessCount" "0"
|
||||
json_add_int "FailureCount" "$2"
|
||||
json_add_int "MinimumResponseTime" "9999"
|
||||
json_add_int "AverageResponseTime" "0"
|
||||
json_add_int "MaximumResponseTime" "0"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$3" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState="$1"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.SuccessCount=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.FailureCount="$2"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime=9999
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.AverageResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime=0
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
udpecho_launch() {
|
||||
input="$1"
|
||||
|
||||
json_load "${input}"
|
||||
|
||||
json_get_var host host
|
||||
json_get_var port port
|
||||
json_get_var iface iface
|
||||
json_get_var ip_proto ip_proto
|
||||
json_get_var nbr_of_rep nbr_of_rep
|
||||
json_get_var timeout timeout
|
||||
json_get_var dsize data_size
|
||||
json_get_var dscp dscp
|
||||
json_get_var inter_time inter_trans_time
|
||||
json_get_var proto proto
|
||||
json_get_var cancel cancel
|
||||
|
||||
[ "${proto}" = "both_proto" ] && {
|
||||
old_pid=$(cat /tmp/udpecho_pid)
|
||||
|
||||
[ -n "${old_pid}" ] && {
|
||||
cmd=$(cat /proc/$old_pid/cmdline)
|
||||
}
|
||||
|
||||
if [[ "${cmd}" = *udpecho* ]]; then
|
||||
kill -9 $old_pid
|
||||
fi
|
||||
|
||||
if [ "${cancel}" -eq "1" ]; then
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState="None"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.SuccessCount="0"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.FailureCount="0"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime="9999"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.AverageResponseTime="0"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime="0"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.IPAddressUsed=""
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "None"
|
||||
json_add_string "IPAddressUsed" ""
|
||||
json_add_int "SuccessCount" "0"
|
||||
json_add_int "FailureCount" "0"
|
||||
json_add_int "MinimumResponseTime" "9999"
|
||||
json_add_int "AverageResponseTime" "0"
|
||||
json_add_int "MaximumResponseTime" "0"
|
||||
json_dump
|
||||
|
||||
return
|
||||
else
|
||||
echo $$ > /tmp/udpecho_pid
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState="Requested_running"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
}
|
||||
|
||||
# Assign default value
|
||||
[ -z "${nbr_of_rep}" ] && nbr_of_rep=1
|
||||
[ -z "${port}" ] && port=7
|
||||
[ -z "${dsize}" ] && dsize=24
|
||||
[ -z "${dscp}" ] && dscp=0
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-i $device" || device=""
|
||||
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
|
||||
if [ "$ip_proto" = "IPv4" ]; then ip_proto="--protocol 4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="--protocol 6"; else ip_proto=""; fi
|
||||
[ -z "${timeout}" ] && timeout=1 || timeout=$((timeout/1000))
|
||||
[ -z "${inter_time}" ] && inter_time=1 || inter_time=$((inter_time/1000))
|
||||
tos=$((dscp<<2))
|
||||
|
||||
# Fail if host is empty
|
||||
[ -z "${host}" ] && {
|
||||
udpecho_error "Error_Internal" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
micros=1000
|
||||
success_count=0
|
||||
avg_time_sum=0
|
||||
min=9999999
|
||||
max=0
|
||||
i=0
|
||||
|
||||
while [ $i -lt "$nbr_of_rep" ]; do
|
||||
i=$((i+1))
|
||||
|
||||
res=$(udpechoclientd -c 1 -t $timeout --host "$host" --data-length "$dsize" --port "$port" $ip_proto $device 2>&1)
|
||||
|
||||
ba=$(echo "$res" | grep "Can't Resolve Host Name")
|
||||
[ -n "$ba" ] && {
|
||||
udpecho_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
ba=$(echo "$res" | grep "RCVD")
|
||||
[[ -z "$ba" && $((nbr_of_rep-i)) == 0 ]] && {
|
||||
udpecho_error "Complete" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
times=$(echo "$res" | grep "rtt")
|
||||
[ -z "$times" ] && continue
|
||||
|
||||
sc1=$(echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }')
|
||||
[ "$sc1" != 0 ] && sc1=1 || sc1=0
|
||||
|
||||
success_count=$((success_count+sc1))
|
||||
max_time=$(echo "$times" | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }')
|
||||
min_time=$(echo "$times" | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }')
|
||||
avg_time=$(echo "$times" | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }')
|
||||
min_time=${min_time:-0}
|
||||
avg_time=${avg_time:-0}
|
||||
max_time=${max_time:-0}
|
||||
min_time=$(echo "$min_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
|
||||
avg_time=$(echo "$avg_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
|
||||
max_time=$(echo "$max_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}')
|
||||
[ "$min_time" -lt "$min" ] && min="$min_time"
|
||||
[ "$max_time" -gt "$max" ] && max="$max_time"
|
||||
avg_time_sum=$((avg_time_sum+avg_time))
|
||||
sleep $inter_time
|
||||
done
|
||||
|
||||
failure_count=$((nbr_of_rep-success_count))
|
||||
[ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0
|
||||
min_time=$min
|
||||
max_time=$max
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "Complete"
|
||||
json_add_string "IPAddressUsed" "${ip_addr_used}"
|
||||
json_add_int "SuccessCount" "${success_count}"
|
||||
json_add_int "FailureCount" "${failure_count}"
|
||||
json_add_int "MinimumResponseTime" "${min_time}"
|
||||
json_add_int "AverageResponseTime" "${avg_time}"
|
||||
json_add_int "MaximumResponseTime" "${max_time}"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "${proto}" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState="Complete"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.IPAddressUsed="${ip_addr_used}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.SuccessCount="${success_count}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.FailureCount="${failure_count}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime="${min_time}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.AverageResponseTime="${avg_time}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime="${max_time}"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
if [ "$1" = "list" ]; then
|
||||
udpecho_list
|
||||
elif [ -n "$1" ]; then
|
||||
udpecho_launch "$1"
|
||||
else
|
||||
udpecho_error "Error_Internal" "1"
|
||||
fi
|
||||
|
|
@ -1,235 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: IMEN Bhiri <imen.bhiri@pivasoftware.com>
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
ROOT="$(dirname "${0}")"
|
||||
. "${ROOT}"/bbf_api
|
||||
|
||||
DOWNLOAD_TIMEOUT=1800
|
||||
|
||||
download_error() {
|
||||
json_init
|
||||
json_add_string "Status" "$1"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$2" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState="$1"
|
||||
}
|
||||
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.Status="complete"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
download_launch() {
|
||||
input="$1"
|
||||
|
||||
json_load "${input}"
|
||||
|
||||
json_get_var url url
|
||||
json_get_var iface iface
|
||||
json_get_var dscp dscp
|
||||
json_get_var eth_prio eth_prio
|
||||
json_get_var ip_proto ip_proto
|
||||
json_get_var num_of_con num_of_con
|
||||
json_get_var enable_per_con enable_per_con
|
||||
json_get_var proto proto
|
||||
|
||||
# Check if a download process is already running
|
||||
download_s=$(uci_get_bbf_dmmap dmmap_diagnostics.download)
|
||||
if [ -z "${download_s}" ]; then
|
||||
[ ! -f /etc/bbfdm/dmmap/dmmap_diagnostics ] && touch /etc/bbfdm/dmmap/dmmap_diagnostics
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics download
|
||||
$UCI_RENAME_BBF_DMMAP dmmap_diagnostics.@download[0]='download'
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.Status="running"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
else
|
||||
Status=$(uci_get_bbf_dmmap dmmap_diagnostics.download.Status)
|
||||
[ "${Status}" = "running" ] && {
|
||||
return
|
||||
}
|
||||
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.Status="running"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
|
||||
# Assign default value
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) || device=$(route -n | grep 'UG[ \t]' | awk '{print $8}')
|
||||
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
|
||||
if [ "$ip_proto" = "IPv4" ]; then ip_proto="--ipv4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="--ipv6"; else ip_proto=""; fi
|
||||
|
||||
# Fail if url is empty
|
||||
[ -z "${url}" ] && {
|
||||
download_error "Error_InitConnectionFailed" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "${url:0:7}" != "http://" ] && [ "${url:0:6}" != "ftp://" ] && {
|
||||
download_error "Error_Other" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
format='{ "size_download": "%{size_download}",
|
||||
"size_header": "%{size_header}",
|
||||
"time_appconnect": "%{time_appconnect}",
|
||||
"time_connect": "%{time_connect}",
|
||||
"time_pretransfer": "%{time_pretransfer}",
|
||||
"time_starttransfer": "%{time_starttransfer}",
|
||||
"time_total": "%{time_total}",
|
||||
"exitcode": "%{exitcode}" }'
|
||||
|
||||
tx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
|
||||
time_start=$(date +"%s.282646") # It should be like that time_start=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
|
||||
res=$(curl ${ip_proto} --fail --silent --max-time ${DOWNLOAD_TIMEOUT} -w "${format}" "${url}" --output /dev/null)
|
||||
time_end=$(date +"%s.282646") # It should be like that time_end=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
|
||||
|
||||
tx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
|
||||
logger -t "bbf_download" "########### ${url} ==> ${res} ###########"
|
||||
json_load "${res}"
|
||||
json_get_var size_download size_download
|
||||
json_get_var size_header size_header
|
||||
json_get_var time_appconnect time_appconnect
|
||||
json_get_var time_connect time_connect
|
||||
json_get_var time_pretransfer time_pretransfer
|
||||
json_get_var time_starttransfer time_starttransfer
|
||||
json_get_var time_total time_total
|
||||
json_get_var exitcode exitcode
|
||||
|
||||
[ "$exitcode" = "6" ] && {
|
||||
download_error "Error_CannotResolveHostName" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" = "7" ] && {
|
||||
download_error "Error_InitConnectionFailed" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" = "22" ] && {
|
||||
download_error "Error_NoResponse" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" = "27" ] && {
|
||||
download_error "Error_IncorrectSize" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" = "28" ] && {
|
||||
download_error "Error_Timeout" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" != "0" ] && {
|
||||
download_error "Error_Other" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
tcp_open_request_time=$(echo "${time_start}" "${time_appconnect}" | awk '{printf "%.6f", $1 + $2}')
|
||||
tcp_open_response_time=$(echo "${time_start}" "${time_connect}" | awk '{printf "%.6f", $1 + $2}')
|
||||
rom_time=$(echo "${time_start}" "${time_pretransfer}" | awk '{printf "%.6f", $1 + $2}')
|
||||
bom_time=$(echo "${time_start}" "${time_starttransfer}" | awk '{printf "%.6f", $1 + $2}')
|
||||
eom_time=$(echo "${time_start}" "${time_total}" | awk '{printf "%.6f", $1 + $2}')
|
||||
|
||||
separator_idx=$(expr index "${tcp_open_request_time}" .)
|
||||
TCPOpenRequestTime_MicroSec=${tcp_open_request_time:$separator_idx}
|
||||
TCPOpenRequestTime_Sec=${tcp_open_request_time:0:$((separator_idx-1))}
|
||||
|
||||
separator_idx=$(expr index "${tcp_open_response_time}" .)
|
||||
TCPOpenResponseTime_MicroSec=${tcp_open_response_time:$separator_idx}
|
||||
TCPOpenResponseTime_Sec=${tcp_open_response_time:0:$((separator_idx-1))}
|
||||
|
||||
separator_idx=$(expr index "${rom_time}" .)
|
||||
ROMTime_MicroSec=${rom_time:$separator_idx}
|
||||
ROMTime_Sec=${rom_time:0:$((separator_idx-1))}
|
||||
|
||||
separator_idx=$(expr index "${bom_time}" .)
|
||||
BOMTime_MicroSec=${bom_time:$separator_idx}
|
||||
BOMTime_Sec=${bom_time:0:$((separator_idx-1))}
|
||||
|
||||
separator_idx=$(expr index "${eom_time}" .)
|
||||
EOMTime_MicroSec=${eom_time:$separator_idx}
|
||||
EOMTime_Sec=${eom_time:0:$((separator_idx-1))}
|
||||
|
||||
TCPOpenRequestTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenRequestTime_MicroSec}Z" -d @"${TCPOpenRequestTime_Sec}")
|
||||
TCPOpenResponseTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenResponseTime_MicroSec}Z" -d @"${TCPOpenResponseTime_Sec}")
|
||||
ROMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${ROMTime_MicroSec}Z" -d @"${ROMTime_Sec}")
|
||||
BOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${BOMTime_MicroSec}Z" -d @"${BOMTime_Sec}")
|
||||
EOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${EOMTime_MicroSec}Z" -d @"${EOMTime_Sec}")
|
||||
|
||||
tx_bytes=$((tx_bytes_end-tx_bytes_start))
|
||||
rx_bytes=$((rx_bytes_end-rx_bytes_start))
|
||||
test_rx_bytes=$((size_download+size_header))
|
||||
period_time=$(echo "${time_end}" "${time_start}" | awk '{printf ($1 - $2) * 1000000}')
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "Complete"
|
||||
json_add_string "IPAddressUsed" "${ip_addr_used}"
|
||||
json_add_string "ROMTime" "${ROMTime}"
|
||||
json_add_string "BOMTime" "${BOMTime}"
|
||||
json_add_string "EOMTime" "${EOMTime}"
|
||||
json_add_int "TestBytesReceived" "${test_rx_bytes}"
|
||||
json_add_int "TotalBytesReceived" "${rx_bytes}"
|
||||
json_add_int "TotalBytesSent" "${tx_bytes}"
|
||||
json_add_int "PeriodOfFullLoading" "${period_time}"
|
||||
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
|
||||
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
|
||||
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
|
||||
json_add_array "DownloadPerConnection"
|
||||
json_add_object ""
|
||||
json_add_string "ROMTime" "${ROMTime}"
|
||||
json_add_string "BOMTime" "${BOMTime}"
|
||||
json_add_string "EOMTime" "${EOMTime}"
|
||||
json_add_int "TestBytesReceived" "${test_rx_bytes}"
|
||||
json_add_int "TotalBytesReceived" "${rx_bytes}"
|
||||
json_add_int "TotalBytesSent" "${tx_bytes}"
|
||||
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
|
||||
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
|
||||
json_close_object
|
||||
fi
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "${proto}" == "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState="Complete"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.IPAddressUsed="${ip_addr_used}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.ROMTime="${ROMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.BOMTime="${BOMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.EOMTime="${EOMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TestBytesReceived="${test_rx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesReceived="${rx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesSent="${tx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.PeriodOfFullLoading="${period_time}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TCPOpenRequestTime="${TCPOpenRequestTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TCPOpenResponseTime="${TCPOpenResponseTime}"
|
||||
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics DownloadPerConnection
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].ROMTime="${ROMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].BOMTime="${BOMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].EOMTime="${EOMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TestBytesReceived="${test_rx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesReceived="${rx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesSent="${tx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TCPOpenRequestTime="${TCPOpenRequestTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TCPOpenResponseTime="${TCPOpenResponseTime}"
|
||||
else
|
||||
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0]
|
||||
fi
|
||||
}
|
||||
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.Status="complete"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
download_launch "$1"
|
||||
else
|
||||
download_error "Error_Internal"
|
||||
fi
|
||||
|
|
@ -1,180 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
ROOT="$(dirname "${0}")"
|
||||
. "${ROOT}"/bbf_api
|
||||
|
||||
get_traceroute_log_file() {
|
||||
IDX=1
|
||||
LOG_FILE="/tmp/traceroute_$IDX.log"
|
||||
|
||||
while [ -e ${LOG_FILE} ]; do
|
||||
IDX=$((IDX+1))
|
||||
LOG_FILE="/tmp/traceroute_$IDX.log";
|
||||
done
|
||||
|
||||
echo ${LOG_FILE}
|
||||
}
|
||||
|
||||
traceroute_error() {
|
||||
json_init
|
||||
json_add_string "Status" "$1"
|
||||
json_add_string "IPAddressUsed" "$2"
|
||||
json_add_int "ResponseTime" "0"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$3" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState="$1"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.IPAddressUsed="$2"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.NumberOfHops=0
|
||||
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
traceroute_launch() {
|
||||
input="$1"
|
||||
|
||||
json_load "${input}"
|
||||
|
||||
json_get_var host host
|
||||
json_get_var iface iface
|
||||
json_get_var ip_proto ip_proto
|
||||
json_get_var cnt nbr_of_tries
|
||||
json_get_var timeout timeout
|
||||
json_get_var dsize data_size
|
||||
json_get_var dscp dscp
|
||||
json_get_var maxhop max_hop_cnt
|
||||
json_get_var proto proto
|
||||
json_get_var cancel cancel
|
||||
|
||||
LOG_FILE=$(get_traceroute_log_file)
|
||||
|
||||
# Assign default value
|
||||
[ -z "${cnt}" ] && cnt=1
|
||||
[ -z "${maxhop}" ] && maxhop=30
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) && device="-i $device" || device=""
|
||||
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
|
||||
if [ "$ip_proto" = "IPv4" ]; then ip_proto="-4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="-6"; else ip_proto=""; fi
|
||||
[ -z "${timeout}" ] && timeout=5 || timeout=$((timeout/1000))
|
||||
|
||||
# Clear all route hops instances
|
||||
[ "$proto" = "both_proto" ] && {
|
||||
old_pid=$(cat /tmp/traceroute_pid)
|
||||
|
||||
[ -n "${old_pid}" ] && {
|
||||
cmd=$(cat /proc/$old_pid/cmdline)
|
||||
}
|
||||
|
||||
if [[ "${cmd}" = *traceroute* ]]; then
|
||||
kill -9 ${old_pid}
|
||||
fi
|
||||
|
||||
res=$($UCI_SHOW_BBF_DMMAP dmmap_diagnostics | grep -E "=RouteHops$" | cut -d= -f 1)
|
||||
for i in $res; do
|
||||
$UCI_DELETE_BBF_DMMAP "${i}"
|
||||
done
|
||||
|
||||
if [ "${cancel}" -eq "1" ]; then
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState="None"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.IPAddressUsed=""
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.NumberOfHops="0"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime="0"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "None"
|
||||
json_add_string "IPAddressUsed" ""
|
||||
json_add_int "ResponseTime" "0"
|
||||
json_dump
|
||||
|
||||
return
|
||||
else
|
||||
echo $$ > /tmp/traceroute_pid
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState="Requested_running"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
}
|
||||
|
||||
# Fail if host is empty
|
||||
[ -z "${host}" ] && {
|
||||
traceroute_error "Error_Internal" "${ip_addr_used}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ -z "${dsize}" ] && dsize="38"
|
||||
|
||||
res=$(traceroute -m ${maxhop} -w ${timeout} -q ${cnt} ${ip_proto} ${device} "${host}" "${dsize}" 2>&1 >"${LOG_FILE}")
|
||||
error_code="$?"
|
||||
|
||||
ba=$(echo "$res" | grep "bad address")
|
||||
[ -n "$ba" ] && {
|
||||
traceroute_error "Error_CannotResolveHostName" "${ip_addr_used}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" != "0" ] && {
|
||||
traceroute_error "Error_Other" "${ip_addr_used}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
i=-2
|
||||
resp_time=0
|
||||
json_init
|
||||
json_add_array "RouteHops"
|
||||
|
||||
while read _ host ip time _; do
|
||||
[ "$host" = "*" ] || [ "$ip" = "*" ] && continue
|
||||
i=$((i+1))
|
||||
[ "$i" = "-1" ] && continue;
|
||||
ip=${ip#(}; ip=${ip%)}
|
||||
time=${time%.*}
|
||||
resp_time="${time}"
|
||||
|
||||
json_add_object ""
|
||||
json_add_string "Host" "${host}"
|
||||
json_add_string "HostAddress" "${ip}"
|
||||
json_add_int "RTTimes" "${time}"
|
||||
json_add_int "ErrorCode" "0"
|
||||
json_close_object
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$proto" = "both_proto" ] && {
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics RouteHops
|
||||
$UCI_RENAME_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i]="route_hops_${i}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].host="${host}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].ip="${ip}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].time="${time}"
|
||||
}
|
||||
|
||||
done < "${LOG_FILE}"
|
||||
|
||||
rm -f "${LOG_FILE}"
|
||||
i=$((i+1))
|
||||
|
||||
json_close_array
|
||||
json_add_string "Status" "Complete"
|
||||
json_add_string "IPAddressUsed" "${ip_addr_used}"
|
||||
json_add_int "ResponseTime" "${resp_time}"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$proto" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState="Complete"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.IPAddressUsed="${ip_addr_used}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.NumberOfHops="${i}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime="${resp_time}"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
traceroute_launch "$1"
|
||||
else
|
||||
traceroute_error "Error_Internal"
|
||||
fi
|
||||
|
|
@ -1,236 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: IMEN Bhiri <imen.bhiri@pivasoftware.com>
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
ROOT="$(dirname "${0}")"
|
||||
. "${ROOT}"/bbf_api
|
||||
|
||||
UPLOAD_TIMEOUT=1800
|
||||
|
||||
upload_error() {
|
||||
json_init
|
||||
json_add_string "Status" "$1"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$2" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState="$1"
|
||||
}
|
||||
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.Status="complete"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
upload_launch() {
|
||||
input="$1"
|
||||
|
||||
json_load "${input}"
|
||||
|
||||
json_get_var url url
|
||||
json_get_var iface iface
|
||||
json_get_var dscp dscp
|
||||
json_get_var eth_prio eth_prio
|
||||
json_get_var file_length file_length
|
||||
json_get_var ip_proto ip_proto
|
||||
json_get_var num_of_con num_of_con
|
||||
json_get_var enable_per_con enable_per_con
|
||||
json_get_var proto proto
|
||||
|
||||
# Check if an upload process is already running
|
||||
upload_s=$(uci_get_bbf_dmmap dmmap_diagnostics.upload)
|
||||
if [ -z "${upload_s}" ]; then
|
||||
[ ! -f /etc/bbfdm/dmmap/dmmap_diagnostics ] && touch /etc/bbfdm/dmmap/dmmap_diagnostics
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics upload
|
||||
$UCI_RENAME_BBF_DMMAP dmmap_diagnostics.@upload[0]='upload'
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.Status="running"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
else
|
||||
Status=$(uci_get_bbf_dmmap dmmap_diagnostics.upload.Status)
|
||||
[ "${Status}" = "running" ] && {
|
||||
return
|
||||
}
|
||||
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.Status="running"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
|
||||
# Assign default value
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.l3_device) || device=$(route -n | grep 'UG[ \t]' | awk '{print $8}')
|
||||
ip_addr_used=$(get_ip_addr_used "${ip_proto}" "${iface}")
|
||||
if [ "$ip_proto" = "IPv4" ]; then ip_proto="--ipv4"; elif [ "$ip_proto" = "IPv6" ]; then ip_proto="--ipv6"; else ip_proto=""; fi
|
||||
|
||||
# Fail if url is empty
|
||||
[ -z "${url}" ] && {
|
||||
upload_error "Error_InitConnectionFailed" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "${url:0:7}" != "http://" ] && [ "${url:0:6}" != "ftp://" ] && {
|
||||
upload_error "Error_Other" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
format='{ "size_upload":"%{size_upload}", "time_appconnect":"%{time_appconnect}", "time_connect":"%{time_connect}", "time_pretransfer":"%{time_pretransfer}", "time_starttransfer":"%{time_starttransfer}", "time_total":"%{time_total}", "exitcode":"%{exitcode}" }'
|
||||
|
||||
len_mb=$((file_length/(1000*1000)))
|
||||
if [ $len_mb -gt 0 ]; then
|
||||
bs="1MB"
|
||||
count="$len_mb"
|
||||
else
|
||||
bs="$file_length"
|
||||
count="1"
|
||||
fi
|
||||
|
||||
tx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
|
||||
time_start=$(date +"%s.282646") # It should be like that time_start=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
|
||||
res=$(dd if=/dev/zero bs="${bs}" count=${count} 2>/dev/null | curl ${ip_proto} --fail --silent --max-time ${UPLOAD_TIMEOUT} -T - "${url}" -w "${format}"|grep -wo '{.*}')
|
||||
time_end=$(date +"%s.282646") # It should be like that time_end=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
|
||||
|
||||
tx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
|
||||
logger -t "bbf_upload" "# ${url} => ${res} #"
|
||||
json_load "${res}"
|
||||
json_get_var size_upload size_upload
|
||||
json_get_var time_appconnect time_appconnect
|
||||
json_get_var time_connect time_connect
|
||||
json_get_var time_pretransfer time_pretransfer
|
||||
json_get_var time_starttransfer time_starttransfer
|
||||
json_get_var time_total time_total
|
||||
json_get_var exitcode exitcode
|
||||
|
||||
[ "$exitcode" = "6" ] && {
|
||||
upload_error "Error_CannotResolveHostName" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" = "7" ] && {
|
||||
upload_error "Error_InitConnectionFailed" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" = "22" ] && {
|
||||
upload_error "Error_NoResponse" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" = "27" ] && {
|
||||
upload_error "Error_IncorrectSize" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" = "28" ] && {
|
||||
upload_error "Error_Timeout" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$exitcode" != "0" ] && {
|
||||
upload_error "Error_Other" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
tcp_open_request_time=$(echo "${time_start}" "${time_appconnect}" | awk '{printf "%.6f", $1 + $2}')
|
||||
tcp_open_response_time=$(echo "${time_start}" "${time_connect}" | awk '{printf "%.6f", $1 + $2}')
|
||||
rom_time=$(echo "${time_start}" "${time_pretransfer}" | awk '{printf "%.6f", $1 + $2}')
|
||||
bom_time=$(echo "${time_start}" "${time_starttransfer}" | awk '{printf "%.6f", $1 + $2}')
|
||||
eom_time=$(echo "${time_start}" "${time_total}" | awk '{printf "%.6f", $1 + $2}')
|
||||
|
||||
separator_idx=$(expr index "${tcp_open_request_time}" .)
|
||||
TCPOpenRequestTime_MicroSec=${tcp_open_request_time:$separator_idx}
|
||||
TCPOpenRequestTime_Sec=${tcp_open_request_time:0:$((separator_idx-1))}
|
||||
|
||||
separator_idx=$(expr index "${tcp_open_response_time}" .)
|
||||
TCPOpenResponseTime_MicroSec=${tcp_open_response_time:$separator_idx}
|
||||
TCPOpenResponseTime_Sec=${tcp_open_response_time:0:$((separator_idx-1))}
|
||||
|
||||
separator_idx=$(expr index "${rom_time}" .)
|
||||
ROMTime_MicroSec=${rom_time:$separator_idx}
|
||||
ROMTime_Sec=${rom_time:0:$((separator_idx-1))}
|
||||
|
||||
separator_idx=$(expr index "${bom_time}" .)
|
||||
BOMTime_MicroSec=${bom_time:$separator_idx}
|
||||
BOMTime_Sec=${bom_time:0:$((separator_idx-1))}
|
||||
|
||||
separator_idx=$(expr index "${eom_time}" .)
|
||||
EOMTime_MicroSec=${eom_time:$separator_idx}
|
||||
EOMTime_Sec=${eom_time:0:$((separator_idx-1))}
|
||||
|
||||
TCPOpenRequestTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenRequestTime_MicroSec}Z" -d @"${TCPOpenRequestTime_Sec}")
|
||||
TCPOpenResponseTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenResponseTime_MicroSec}Z" -d @"${TCPOpenResponseTime_Sec}")
|
||||
ROMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${ROMTime_MicroSec}Z" -d @"${ROMTime_Sec}")
|
||||
BOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${BOMTime_MicroSec}Z" -d @"${BOMTime_Sec}")
|
||||
EOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${EOMTime_MicroSec}Z" -d @"${EOMTime_Sec}")
|
||||
|
||||
tx_bytes=$((tx_bytes_end-tx_bytes_start))
|
||||
rx_bytes=$((rx_bytes_end-rx_bytes_start))
|
||||
period_time=$(echo "${time_end}" "${time_start}" | awk '{printf ($1 - $2) * 1000000}')
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "Complete"
|
||||
json_add_string "IPAddressUsed" "${ip_addr_used}"
|
||||
json_add_string "ROMTime" "${ROMTime}"
|
||||
json_add_string "BOMTime" "${BOMTime}"
|
||||
json_add_string "EOMTime" "${EOMTime}"
|
||||
json_add_int "TestBytesSent" "${size_upload}"
|
||||
json_add_int "TotalBytesReceived" "${rx_bytes}"
|
||||
json_add_int "TotalBytesSent" "${tx_bytes}"
|
||||
json_add_int "PeriodOfFullLoading" "${period_time}"
|
||||
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
|
||||
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
|
||||
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
|
||||
json_add_array "UploadPerConnection"
|
||||
json_add_object ""
|
||||
json_add_string "ROMTime" "${ROMTime}"
|
||||
json_add_string "BOMTime" "${BOMTime}"
|
||||
json_add_string "EOMTime" "${EOMTime}"
|
||||
json_add_int "TestBytesSent" "${size_upload}"
|
||||
json_add_int "TotalBytesReceived" "${rx_bytes}"
|
||||
json_add_int "TotalBytesSent" "${tx_bytes}"
|
||||
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
|
||||
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
|
||||
json_close_object
|
||||
fi
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "${proto}" = "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState="Complete"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.IPAddressUsed="${ip_addr_used}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.ROMTime="${ROMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.BOMTime="${BOMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.EOMTime="${EOMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TestBytesSent="${size_upload}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesReceived="${rx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesSent="${tx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.PeriodOfFullLoading="${period_time}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TCPOpenRequestTime="${TCPOpenRequestTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TCPOpenResponseTime="${TCPOpenResponseTime}"
|
||||
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics UploadPerConnection
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].ROMTime="${ROMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].BOMTime="${BOMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].EOMTime="${EOMTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TestBytesSent="${size_upload}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesReceived="${rx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesSent="${tx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TCPOpenRequestTime="${TCPOpenRequestTime}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TCPOpenResponseTime="${TCPOpenResponseTime}"
|
||||
else
|
||||
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0]
|
||||
fi
|
||||
}
|
||||
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.Status="complete"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
upload_launch "$1"
|
||||
else
|
||||
upload_error "Error_Internal"
|
||||
fi
|
||||
|
|
@ -230,6 +230,14 @@
|
|||
"src/*.c"
|
||||
]
|
||||
},
|
||||
{
|
||||
"repo": "https://dev.iopsys.eu/bbf/tr143d.git",
|
||||
"proto": "git",
|
||||
"version": "devel",
|
||||
"dm_files": [
|
||||
"src/diagnostics.c"
|
||||
]
|
||||
},
|
||||
{
|
||||
"repo": "https://dev.iopsys.eu/bbf/tr471d.git",
|
||||
"proto": "git",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue