mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
T#8859: Improvement in diagnostics datamodel operations
This commit is contained in:
parent
4ef5f49dda
commit
0c8d4bcf69
27 changed files with 1582 additions and 1114 deletions
|
|
@ -125,6 +125,7 @@ INSTALL(FILES ${libbbfdm_headers}
|
|||
|
||||
FILE(GLOB scripts scripts/*)
|
||||
INSTALL(FILES ${scripts}
|
||||
PERMISSIONS OWNER_EXECUTE
|
||||
DESTINATION usr/share/bbfdm
|
||||
)
|
||||
|
||||
|
|
|
|||
121
dmdiagnostics.c
121
dmdiagnostics.c
|
|
@ -35,7 +35,7 @@
|
|||
#define READ_BUF_SIZE (1024 * 16)
|
||||
|
||||
static int read_next;
|
||||
static struct diagnostic_stats diag_stats = {0};
|
||||
struct diagnostic_stats diag_stats = {0};
|
||||
|
||||
char *get_diagnostics_option(char *sec_name, char *option)
|
||||
{
|
||||
|
|
@ -68,24 +68,18 @@ void reset_diagnostic_state(char *sec_name)
|
|||
}
|
||||
}
|
||||
|
||||
void init_diagnostics_operation(char *sec_name, char *operation_path)
|
||||
char *get_diagnostics_interface_option(struct dmctx *ctx, char *value)
|
||||
{
|
||||
check_create_dmmap_package(DMMAP_DIAGNOSTIGS);
|
||||
struct uci_section *section = dmuci_walk_section_bbfdm(DMMAP_DIAGNOSTIGS, sec_name, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
|
||||
if (section)
|
||||
dmuci_delete_by_section_bbfdm(section, NULL, NULL);
|
||||
char *linker = NULL;
|
||||
|
||||
dmcmd("/bin/sh", 2, operation_path, "stop");
|
||||
}
|
||||
if (!value || *value == 0)
|
||||
return "";
|
||||
|
||||
void remove_unused_diagnostic_sections(char *sec_name)
|
||||
{
|
||||
struct uci_section *s = NULL, *stmp = NULL;
|
||||
if (strncmp(value, "Device.IP.Interface.", 20) != 0)
|
||||
return "";
|
||||
|
||||
check_create_dmmap_package(DMMAP_DIAGNOSTIGS);
|
||||
uci_path_foreach_sections_safe(bbfdm, DMMAP_DIAGNOSTIGS, sec_name, stmp, s) {
|
||||
dmuci_delete_by_section_bbfdm(s, NULL, NULL);
|
||||
}
|
||||
adm_entry_get_linker_value(ctx, value, &linker);
|
||||
return linker ? linker : "";
|
||||
}
|
||||
|
||||
void set_diagnostics_interface_option(struct dmctx *ctx, char *sec_name, char *value)
|
||||
|
|
@ -987,7 +981,7 @@ static void ftp_upload_per_packet(libtrace_packet_t *packet)
|
|||
}
|
||||
}
|
||||
|
||||
static int extract_stats(char *dump_file, int proto, int diagnostic_type)
|
||||
int extract_stats(char *dump_file, int proto, int diagnostic_type)
|
||||
{
|
||||
libtrace_t *trace = NULL;
|
||||
libtrace_packet_t *packet = trace_create_packet();
|
||||
|
|
@ -1044,98 +1038,3 @@ static int extract_stats(char *dump_file, int proto, int diagnostic_type)
|
|||
libtrace_cleanup(trace, packet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *get_default_gateway_device(void)
|
||||
{
|
||||
FILE *f = fopen(PROC_ROUTE, "r");
|
||||
if (f != NULL) {
|
||||
char line[100] = {0}, *p = NULL, *c = NULL, *saveptr = NULL;
|
||||
char *device = NULL;
|
||||
|
||||
while(fgets(line, sizeof(line), f)) {
|
||||
p = strtok_r(line, " \t", &saveptr);
|
||||
c = strtok_r(NULL, " \t", &saveptr);
|
||||
if (p && c && strcmp(c, "00000000") == 0) {
|
||||
device = dmstrdup(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
return device ? device : "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
int start_upload_download_diagnostic(int diagnostic_type)
|
||||
{
|
||||
char *url, *interface, *device, *size, *status;
|
||||
|
||||
if (diagnostic_type == DOWNLOAD_DIAGNOSTIC) {
|
||||
url = get_diagnostics_option("download", "url");
|
||||
interface = get_diagnostics_option("download", "interface");
|
||||
} else {
|
||||
url = get_diagnostics_option("upload", "url");
|
||||
size = get_diagnostics_option("upload", "TestFileLength");
|
||||
interface = get_diagnostics_option("upload", "interface");
|
||||
}
|
||||
|
||||
if (strncmp(url, HTTP_URI, strlen(HTTP_URI)) != 0 &&
|
||||
strncmp(url, FTP_URI, strlen(FTP_URI)) != 0 &&
|
||||
strchr(url,'@') != NULL)
|
||||
return -1;
|
||||
|
||||
device = (interface && *interface) ? get_device(interface) : get_default_gateway_device();
|
||||
if (device[0] == '\0')
|
||||
return -1;
|
||||
|
||||
if (diagnostic_type == DOWNLOAD_DIAGNOSTIC) {
|
||||
// Commit and Free uci_ctx_bbfdm
|
||||
commit_and_free_uci_ctx_bbfdm(DMMAP_DIAGNOSTIGS);
|
||||
|
||||
dmcmd("/bin/sh", 4, DOWNLOAD_DIAGNOSTIC_PATH, "run", url, device);
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
dmuci_init_bbfdm();
|
||||
|
||||
url = get_diagnostics_option("download", "url");
|
||||
status = get_diagnostics_option("download", "DiagnosticState");
|
||||
if (status && strcmp(status, "Complete") == 0) {
|
||||
memset(&diag_stats, 0, sizeof(diag_stats));
|
||||
if (strncmp(url, HTTP_URI, strlen(HTTP_URI)) == 0)
|
||||
extract_stats(DOWNLOAD_DUMP_FILE, DIAGNOSTIC_HTTP, DOWNLOAD_DIAGNOSTIC);
|
||||
if (strncmp(url, FTP_URI, strlen(FTP_URI)) == 0)
|
||||
extract_stats(DOWNLOAD_DUMP_FILE, DIAGNOSTIC_FTP, DOWNLOAD_DIAGNOSTIC);
|
||||
|
||||
if (file_exists(DOWNLOAD_DUMP_FILE))
|
||||
remove(DOWNLOAD_DUMP_FILE);
|
||||
|
||||
} else if (status && strncmp(status, "Error_", strlen("Error_")) == 0)
|
||||
return -1;
|
||||
} else {
|
||||
// Commit and Free uci_ctx_bbfdm
|
||||
commit_and_free_uci_ctx_bbfdm(DMMAP_DIAGNOSTIGS);
|
||||
|
||||
dmcmd("/bin/sh", 5, UPLOAD_DIAGNOSTIC_PATH, "run", url, device, size);
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
dmuci_init_bbfdm();
|
||||
|
||||
url = get_diagnostics_option("upload", "url");
|
||||
status = get_diagnostics_option("upload", "DiagnosticState");
|
||||
if (status && strcmp(status, "Complete") == 0) {
|
||||
memset(&diag_stats, 0, sizeof(diag_stats));
|
||||
if (strncmp(url, HTTP_URI, strlen(HTTP_URI)) == 0)
|
||||
extract_stats(UPLOAD_DUMP_FILE, DIAGNOSTIC_HTTP, UPLOAD_DIAGNOSTIC);
|
||||
if (strncmp(url, FTP_URI, strlen(FTP_URI)) == 0)
|
||||
extract_stats(UPLOAD_DUMP_FILE, DIAGNOSTIC_FTP, UPLOAD_DIAGNOSTIC);
|
||||
|
||||
if (file_exists(UPLOAD_DUMP_FILE))
|
||||
remove(UPLOAD_DUMP_FILE);
|
||||
|
||||
} else if (status && strncmp(status, "Error_", strlen("Error_")) == 0)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@
|
|||
#define DMMAP_DIAGNOSTIGS "dmmap_diagnostics"
|
||||
#define CONFIG_BACKUP "/tmp/bbf_config_backup"
|
||||
#define MAX_TIME_WINDOW 5
|
||||
#define DOWNLOAD_DUMP_FILE "/tmp/download_dump"
|
||||
#define UPLOAD_DUMP_FILE "/tmp/upload_dump"
|
||||
|
||||
struct diagnostic_stats
|
||||
{
|
||||
|
|
@ -48,6 +50,8 @@ struct diagnostic_stats
|
|||
uint32_t ftp_syn;
|
||||
};
|
||||
|
||||
extern struct diagnostic_stats diag_stats;
|
||||
|
||||
enum diagnostic_protocol {
|
||||
DIAGNOSTIC_HTTP = 1,
|
||||
DIAGNOSTIC_FTP
|
||||
|
|
@ -62,10 +66,8 @@ char *get_diagnostics_option(char *sec_name, char *option);
|
|||
char *get_diagnostics_option_fallback_def(char *sec_name, char *option, char *default_value);
|
||||
void set_diagnostics_option(char *sec_name, char *option, char *value);
|
||||
void reset_diagnostic_state(char *sec_name);
|
||||
void init_diagnostics_operation(char *sec_name, char *operation_path);
|
||||
void remove_unused_diagnostic_sections(char *sec_name);
|
||||
char *get_diagnostics_interface_option(struct dmctx *ctx, char *value);
|
||||
void set_diagnostics_interface_option(struct dmctx *ctx, char *sec_name, char *value);
|
||||
int start_upload_download_diagnostic(int diagnostic_type);
|
||||
int bbf_upload_log(const char *url, const char *username, const char *password,
|
||||
char *config_name, const char *command, const char *obj_path);
|
||||
int bbf_config_backup(const char *url, const char *username, const char *password,
|
||||
|
|
@ -77,4 +79,6 @@ int bbf_fw_image_download(const char *url, const char *auto_activate, const char
|
|||
const char *file_size, const char *checksum_algorithm, const char *checksum,
|
||||
const char *bank_id, const char *command, const char *obj_path, const char *commandKey);
|
||||
|
||||
int extract_stats(char *dump_file, int proto, int diagnostic_type);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ static int set_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, void
|
|||
return 0;
|
||||
case VALUESET:
|
||||
if (DM_LSTRCMP(value, "Requested") == 0) {
|
||||
IPPING_STOP
|
||||
set_diagnostics_option("ipping", "DiagnosticState", value);
|
||||
bbf_set_end_session_flag(ctx, BBF_END_SESSION_IPPING_DIAGNOSTIC);
|
||||
}
|
||||
|
|
@ -74,7 +73,6 @@ static int set_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data,
|
|||
|
||||
return 0;
|
||||
case VALUESET:
|
||||
IPPING_STOP
|
||||
reset_diagnostic_state("ipping");
|
||||
set_diagnostics_interface_option(ctx, "ipping", value);
|
||||
return 0;
|
||||
|
|
@ -96,7 +94,6 @@ static int set_ip_ping_protocolversion(char *refparam, struct dmctx *ctx, void *
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
IPPING_STOP
|
||||
reset_diagnostic_state("ipping");
|
||||
set_diagnostics_option("ipping", "ProtocolVersion", value);
|
||||
return 0;
|
||||
|
|
@ -118,7 +115,6 @@ static int set_ip_ping_host(char *refparam, struct dmctx *ctx, void *data, char
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
IPPING_STOP
|
||||
reset_diagnostic_state("ipping");
|
||||
set_diagnostics_option("ipping", "Host", value);
|
||||
return 0;
|
||||
|
|
@ -140,7 +136,6 @@ static int set_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, void
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
IPPING_STOP
|
||||
reset_diagnostic_state("ipping");
|
||||
set_diagnostics_option("ipping", "NumberOfRepetitions", value);
|
||||
return 0;
|
||||
|
|
@ -162,7 +157,6 @@ static int set_ip_ping_timeout(char *refparam, struct dmctx *ctx, void *data, ch
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
IPPING_STOP
|
||||
reset_diagnostic_state("ipping");
|
||||
set_diagnostics_option("ipping", "Timeout", value);
|
||||
return 0;
|
||||
|
|
@ -184,7 +178,6 @@ static int set_ip_ping_block_size(char *refparam, struct dmctx *ctx, void *data,
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
IPPING_STOP
|
||||
reset_diagnostic_state("ipping");
|
||||
set_diagnostics_option("ipping", "DataBlockSize", value);
|
||||
return 0;
|
||||
|
|
@ -206,7 +199,6 @@ static int set_ip_ping_DSCP(char *refparam, struct dmctx *ctx, void *data, char
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
IPPING_STOP
|
||||
reset_diagnostic_state("ipping");
|
||||
set_diagnostics_option("ipping", "DSCP", value);
|
||||
return 0;
|
||||
|
|
@ -287,7 +279,6 @@ static int set_IPDiagnosticsTraceRoute_DiagnosticsState(char *refparam, struct d
|
|||
return 0;
|
||||
case VALUESET:
|
||||
if (DM_LSTRCMP(value, "Requested") == 0) {
|
||||
TRACEROUTE_STOP
|
||||
set_diagnostics_option("traceroute", "DiagnosticState", value);
|
||||
bbf_set_end_session_flag(ctx, BBF_END_SESSION_TRACEROUTE_DIAGNOSTIC);
|
||||
}
|
||||
|
|
@ -317,7 +308,6 @@ static int set_IPDiagnosticsTraceRoute_Interface(char *refparam, struct dmctx *c
|
|||
|
||||
return 0;
|
||||
case VALUESET:
|
||||
TRACEROUTE_STOP
|
||||
reset_diagnostic_state("traceroute");
|
||||
set_diagnostics_interface_option(ctx, "traceroute", value);
|
||||
return 0;
|
||||
|
|
@ -339,7 +329,6 @@ static int set_IPDiagnosticsTraceRoute_ProtocolVersion(char *refparam, struct dm
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
TRACEROUTE_STOP
|
||||
reset_diagnostic_state("traceroute");
|
||||
set_diagnostics_option("traceroute", "ProtocolVersion", value);
|
||||
return 0;
|
||||
|
|
@ -361,7 +350,6 @@ static int set_IPDiagnosticsTraceRoute_Host(char *refparam, struct dmctx *ctx, v
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
TRACEROUTE_STOP
|
||||
reset_diagnostic_state("traceroute");
|
||||
set_diagnostics_option("traceroute", "Host", value);
|
||||
return 0;
|
||||
|
|
@ -383,7 +371,6 @@ static int set_IPDiagnosticsTraceRoute_NumberOfTries(char *refparam, struct dmct
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
TRACEROUTE_STOP
|
||||
reset_diagnostic_state("traceroute");
|
||||
set_diagnostics_option("traceroute", "NumberOfTries", value);
|
||||
return 0;
|
||||
|
|
@ -405,7 +392,6 @@ static int set_IPDiagnosticsTraceRoute_Timeout(char *refparam, struct dmctx *ctx
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
TRACEROUTE_STOP
|
||||
reset_diagnostic_state("traceroute");
|
||||
set_diagnostics_option("traceroute", "Timeout", value);
|
||||
return 0;
|
||||
|
|
@ -427,7 +413,6 @@ static int set_IPDiagnosticsTraceRoute_DataBlockSize(char *refparam, struct dmct
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
TRACEROUTE_STOP
|
||||
reset_diagnostic_state("traceroute");
|
||||
set_diagnostics_option("traceroute", "DataBlockSize", value);
|
||||
return 0;
|
||||
|
|
@ -449,7 +434,6 @@ static int set_IPDiagnosticsTraceRoute_DSCP(char *refparam, struct dmctx *ctx, v
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
TRACEROUTE_STOP
|
||||
reset_diagnostic_state("traceroute");
|
||||
set_diagnostics_option("traceroute", "DSCP", value);
|
||||
return 0;
|
||||
|
|
@ -471,7 +455,6 @@ static int set_IPDiagnosticsTraceRoute_MaxHopCount(char *refparam, struct dmctx
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
TRACEROUTE_STOP
|
||||
reset_diagnostic_state("traceroute");
|
||||
set_diagnostics_option("traceroute", "MaxHops", value);
|
||||
return 0;
|
||||
|
|
@ -540,7 +523,6 @@ static int set_IPDiagnosticsDownloadDiagnostics_DiagnosticsState(char *refparam,
|
|||
return 0;
|
||||
case VALUESET:
|
||||
if (DM_LSTRCMP(value, "Requested") == 0) {
|
||||
DOWNLOAD_DIAGNOSTIC_STOP
|
||||
set_diagnostics_option("download", "DiagnosticState", value);
|
||||
bbf_set_end_session_flag(ctx, BBF_END_SESSION_DOWNLOAD_DIAGNOSTIC);
|
||||
}
|
||||
|
|
@ -570,7 +552,6 @@ static int set_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct
|
|||
|
||||
return 0;
|
||||
case VALUESET:
|
||||
DOWNLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("download");
|
||||
set_diagnostics_interface_option(ctx, "download", value);
|
||||
return 0;
|
||||
|
|
@ -592,7 +573,6 @@ static int set_IPDiagnosticsDownloadDiagnostics_DownloadURL(char *refparam, stru
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
DOWNLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("download");
|
||||
set_diagnostics_option("download", "url", value);
|
||||
return 0;
|
||||
|
|
@ -626,7 +606,6 @@ static int set_IPDiagnosticsDownloadDiagnostics_DSCP(char *refparam, struct dmct
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
DOWNLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("download");
|
||||
set_diagnostics_option("download", "DSCP", value);
|
||||
return 0;
|
||||
|
|
@ -648,7 +627,6 @@ static int set_IPDiagnosticsDownloadDiagnostics_EthernetPriority(char *refparam,
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
DOWNLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("download");
|
||||
set_diagnostics_option("download", "ethernetpriority", value);
|
||||
return 0;
|
||||
|
|
@ -670,7 +648,6 @@ static int set_IPDiagnosticsDownloadDiagnostics_ProtocolVersion(char *refparam,
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
DOWNLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("download");
|
||||
set_diagnostics_option("download", "ProtocolVersion", value);
|
||||
return 0;
|
||||
|
|
@ -692,7 +669,6 @@ static int set_IPDiagnosticsDownloadDiagnostics_NumberOfConnections(char *refpar
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
DOWNLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("download");
|
||||
set_diagnostics_option("download", "NumberOfConnections", value);
|
||||
return 0;
|
||||
|
|
@ -801,7 +777,6 @@ static int set_IPDiagnosticsDownloadDiagnostics_EnablePerConnectionResults(char
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
DOWNLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("download");
|
||||
set_diagnostics_option("download", "EnablePerConnection", value);
|
||||
return 0;
|
||||
|
|
@ -876,7 +851,6 @@ static int set_IPDiagnosticsUploadDiagnostics_DiagnosticsState(char *refparam, s
|
|||
return 0;
|
||||
case VALUESET:
|
||||
if (DM_LSTRCMP(value, "Requested") == 0) {
|
||||
UPLOAD_DIAGNOSTIC_STOP
|
||||
set_diagnostics_option("upload", "DiagnosticState", value);
|
||||
bbf_set_end_session_flag(ctx, BBF_END_SESSION_UPLOAD_DIAGNOSTIC);
|
||||
}
|
||||
|
|
@ -906,7 +880,6 @@ static int set_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct d
|
|||
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UPLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("upload");
|
||||
set_diagnostics_interface_option(ctx, "upload", value);
|
||||
return 0;
|
||||
|
|
@ -928,7 +901,6 @@ static int set_IPDiagnosticsUploadDiagnostics_UploadURL(char *refparam, struct d
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UPLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("upload");
|
||||
set_diagnostics_option("upload", "url", value);
|
||||
return 0;
|
||||
|
|
@ -956,7 +928,6 @@ static int set_IPDiagnosticsUploadDiagnostics_DSCP(char *refparam, struct dmctx
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UPLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("upload");
|
||||
set_diagnostics_option("upload", "DSCP", value);
|
||||
return 0;
|
||||
|
|
@ -978,7 +949,6 @@ static int set_IPDiagnosticsUploadDiagnostics_EthernetPriority(char *refparam, s
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UPLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("upload");
|
||||
set_diagnostics_option("upload", "ethernetpriority", value);
|
||||
return 0;
|
||||
|
|
@ -1000,7 +970,6 @@ static int set_IPDiagnosticsUploadDiagnostics_TestFileLength(char *refparam, str
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UPLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("upload");
|
||||
set_diagnostics_option("upload", "TestFileLength", value);
|
||||
return 0;
|
||||
|
|
@ -1022,7 +991,6 @@ static int set_IPDiagnosticsUploadDiagnostics_ProtocolVersion(char *refparam, st
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UPLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("upload");
|
||||
set_diagnostics_option("upload", "ProtocolVersion", value);
|
||||
return 0;
|
||||
|
|
@ -1044,7 +1012,6 @@ static int set_IPDiagnosticsUploadDiagnostics_NumberOfConnections(char *refparam
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UPLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("upload");
|
||||
set_diagnostics_option("upload", "NumberOfConnections", value);
|
||||
return 0;
|
||||
|
|
@ -1153,7 +1120,6 @@ static int set_IPDiagnosticsUploadDiagnostics_EnablePerConnectionResults(char *r
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UPLOAD_DIAGNOSTIC_STOP
|
||||
reset_diagnostic_state("upload");
|
||||
set_diagnostics_option("upload", "EnablePerConnection", value);
|
||||
return 0;
|
||||
|
|
@ -1229,7 +1195,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_DiagnosticsState(char *refparam,
|
|||
return 0;
|
||||
case VALUESET:
|
||||
if (DM_LSTRCMP(value, "Requested") == 0) {
|
||||
UDPECHO_STOP;
|
||||
set_diagnostics_option("udpechodiag", "DiagnosticState", value);
|
||||
bbf_set_end_session_flag(ctx, BBF_END_SESSION_UDPECHO_DIAGNOSTIC);
|
||||
}
|
||||
|
|
@ -1259,7 +1224,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_Interface(char *refparam, struct
|
|||
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UDPECHO_STOP;
|
||||
reset_diagnostic_state("udpechodiag");
|
||||
set_diagnostics_interface_option(ctx, "udpechodiag", value);
|
||||
return 0;
|
||||
|
|
@ -1281,7 +1245,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_Host(char *refparam, struct dmctx
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UDPECHO_STOP;
|
||||
reset_diagnostic_state("udpechodiag");
|
||||
set_diagnostics_option("udpechodiag", "Host", value);
|
||||
return 0;
|
||||
|
|
@ -1303,7 +1266,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_Port(char *refparam, struct dmctx
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UDPECHO_STOP;
|
||||
reset_diagnostic_state("udpechodiag");
|
||||
set_diagnostics_option("udpechodiag", "port", value);
|
||||
return 0;
|
||||
|
|
@ -1325,7 +1287,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_NumberOfRepetitions(char *refpara
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UDPECHO_STOP;
|
||||
reset_diagnostic_state("udpechodiag");
|
||||
set_diagnostics_option("udpechodiag", "NumberOfRepetitions", value);
|
||||
return 0;
|
||||
|
|
@ -1347,7 +1308,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_Timeout(char *refparam, struct dm
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UDPECHO_STOP;
|
||||
reset_diagnostic_state("udpechodiag");
|
||||
set_diagnostics_option("udpechodiag", "Timeout", value);
|
||||
return 0;
|
||||
|
|
@ -1369,7 +1329,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_DataBlockSize(char *refparam, str
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UDPECHO_STOP;
|
||||
reset_diagnostic_state("udpechodiag");
|
||||
set_diagnostics_option("udpechodiag", "DataBlockSize", value);
|
||||
return 0;
|
||||
|
|
@ -1391,7 +1350,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_DSCP(char *refparam, struct dmctx
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UDPECHO_STOP;
|
||||
reset_diagnostic_state("udpechodiag");
|
||||
set_diagnostics_option("udpechodiag", "DSCP", value);
|
||||
return 0;
|
||||
|
|
@ -1413,7 +1371,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_InterTransmissionTime(char *refpa
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UDPECHO_STOP;
|
||||
reset_diagnostic_state("udpechodiag");
|
||||
set_diagnostics_option("udpechodiag", "InterTransmissionTime", value);
|
||||
return 0;
|
||||
|
|
@ -1435,7 +1392,6 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_ProtocolVersion(char *refparam, s
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
UDPECHO_STOP;
|
||||
reset_diagnostic_state("udpechodiag");
|
||||
set_diagnostics_option("udpechodiag", "ProtocolVersion", value);
|
||||
return 0;
|
||||
|
|
@ -1498,7 +1454,6 @@ static int set_IPDiagnosticsServerSelectionDiagnostics_DiagnosticsState(char *re
|
|||
return 0;
|
||||
case VALUESET:
|
||||
if (DM_LSTRCMP(value, "Requested") == 0) {
|
||||
SERVERSELECTION_STOP
|
||||
set_diagnostics_option("serverselection", "DiagnosticState", value);
|
||||
bbf_set_end_session_flag(ctx, BBF_END_SESSION_SERVERSELECTION_DIAGNOSTIC);
|
||||
}
|
||||
|
|
@ -1528,7 +1483,6 @@ static int set_IPDiagnosticsServerSelectionDiagnostics_Interface(char *refparam,
|
|||
|
||||
return 0;
|
||||
case VALUESET:
|
||||
SERVERSELECTION_STOP
|
||||
reset_diagnostic_state("serverselection");
|
||||
set_diagnostics_interface_option(ctx, "serverselection", value);
|
||||
return 0;
|
||||
|
|
@ -1550,7 +1504,6 @@ static int set_IPDiagnosticsServerSelectionDiagnostics_ProtocolVersion(char *ref
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
SERVERSELECTION_STOP
|
||||
reset_diagnostic_state("serverselection");
|
||||
set_diagnostics_option("serverselection", "ProtocolVersion", value);
|
||||
return 0;
|
||||
|
|
@ -1572,7 +1525,6 @@ static int set_IPDiagnosticsServerSelectionDiagnostics_Protocol(char *refparam,
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
SERVERSELECTION_STOP
|
||||
reset_diagnostic_state("serverselection");
|
||||
set_diagnostics_option("serverselection", "Protocol", value);
|
||||
return 0;
|
||||
|
|
@ -1594,7 +1546,6 @@ static int set_IPDiagnosticsServerSelectionDiagnostics_HostList(char *refparam,
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
SERVERSELECTION_STOP
|
||||
reset_diagnostic_state("serverselection");
|
||||
set_diagnostics_option("serverselection", "HostList", value);
|
||||
return 0;
|
||||
|
|
@ -1616,7 +1567,6 @@ static int set_IPDiagnosticsServerSelectionDiagnostics_NumberOfRepetitions(char
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
SERVERSELECTION_STOP
|
||||
reset_diagnostic_state("serverselection");
|
||||
set_diagnostics_option("serverselection", "NumberOfRepetitions", value);
|
||||
return 0;
|
||||
|
|
@ -1638,7 +1588,6 @@ static int set_IPDiagnosticsServerSelectionDiagnostics_Timeout(char *refparam, s
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
SERVERSELECTION_STOP
|
||||
reset_diagnostic_state("serverselection");
|
||||
set_diagnostics_option("serverselection", "Timeout", value);
|
||||
return 0;
|
||||
|
|
@ -1755,55 +1704,60 @@ static int get_operate_args_IPDiagnostics_IPPing(char *refparam, struct dmctx *c
|
|||
|
||||
static int operate_IPDiagnostics_IPPing(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
init_diagnostics_operation("ipping", IPPING_PATH);
|
||||
json_object *res = NULL;
|
||||
|
||||
char *ipping_host = dmjson_get_value((json_object *)value, 1, "Host");
|
||||
if (ipping_host[0] == '\0')
|
||||
return CMD_INVALID_ARGUMENTS;
|
||||
char *ipping_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *ip_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *ipping_interface = get_diagnostics_interface_option(ctx, ip_interface);
|
||||
char *ipping_proto = dmjson_get_value((json_object *)value, 1, "ProtocolVersion");
|
||||
char *ipping_nbofrepetition = dmjson_get_value((json_object *)value, 1, "NumberOfRepetitions");
|
||||
char *ipping_timeout = dmjson_get_value((json_object *)value, 1, "Timeout");
|
||||
char *ipping_datablocksize = dmjson_get_value((json_object *)value, 1, "DataBlockSize");
|
||||
char *ipping_dscp = dmjson_get_value((json_object *)value, 1, "DSCP");
|
||||
char *proto = (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto";
|
||||
|
||||
set_diagnostics_option("ipping", "Host", ipping_host);
|
||||
set_diagnostics_interface_option(ctx, "ipping", ipping_interface);
|
||||
set_diagnostics_option("ipping", "ProtocolVersion", ipping_proto);
|
||||
set_diagnostics_option("ipping", "NumberOfRepetitions", ipping_nbofrepetition);
|
||||
set_diagnostics_option("ipping", "Timeout", ipping_timeout);
|
||||
set_diagnostics_option("ipping", "DataBlockSize", ipping_datablocksize);
|
||||
set_diagnostics_option("ipping", "DSCP", ipping_dscp);
|
||||
dmubus_call_blocking("bbf.diag", "ipping",
|
||||
UBUS_ARGS{
|
||||
{"host", ipping_host, String},
|
||||
{"iface", ipping_interface, String},
|
||||
{"ip_proto", ipping_proto, String},
|
||||
{"nbr_of_rep", ipping_nbofrepetition, String},
|
||||
{"timeout", ipping_timeout, String},
|
||||
{"data_size", ipping_datablocksize, String},
|
||||
{"dscp", ipping_dscp, String},
|
||||
{"proto", proto, String}
|
||||
},
|
||||
8, &res);
|
||||
|
||||
// Commit and Free uci_ctx_bbfdm
|
||||
commit_and_free_uci_ctx_bbfdm(DMMAP_DIAGNOSTIGS);
|
||||
if (res == NULL)
|
||||
return CMD_FAIL;
|
||||
|
||||
dmcmd("/bin/sh", 2, IPPING_PATH, "run");
|
||||
char *ipping_status = dmjson_get_value(res, 1, "Status");
|
||||
char *ipping_ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed");
|
||||
char *ipping_success_count = dmjson_get_value(res, 1, "SuccessCount");
|
||||
char *ipping_failure_count = dmjson_get_value(res, 1, "FailureCount");
|
||||
char *ipping_average_response_time = dmjson_get_value(res, 1, "AverageResponseTime");
|
||||
char *ipping_minimum_response_time = dmjson_get_value(res, 1, "MinimumResponseTime");
|
||||
char *ipping_maximum_response_time = dmjson_get_value(res, 1, "MaximumResponseTime");
|
||||
char *ipping_average_response_time_detailed = dmjson_get_value(res, 1, "AverageResponseTimeDetailed");
|
||||
char *ipping_minimum_response_time_detailed = dmjson_get_value(res, 1, "MinimumResponseTimeDetailed");
|
||||
char *ipping_maximum_response_time_detailed = dmjson_get_value(res, 1, "MaximumResponseTimeDetailed");
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
dmuci_init_bbfdm();
|
||||
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(ipping_status), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), dmstrdup(ipping_ip_address_used), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("SuccessCount"), dmstrdup(ipping_success_count), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("FailureCount"), dmstrdup(ipping_failure_count), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("AverageResponseTime"), dmstrdup(ipping_average_response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MinimumResponseTime"), dmstrdup(ipping_minimum_response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MaximumResponseTime"), dmstrdup(ipping_maximum_response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("AverageResponseTimeDetailed"), dmstrdup(ipping_average_response_time_detailed), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MinimumResponseTimeDetailed"), dmstrdup(ipping_minimum_response_time_detailed), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MaximumResponseTimeDetailed"), dmstrdup(ipping_maximum_response_time_detailed), DMT_TYPE[DMT_UNINT], NULL);
|
||||
|
||||
char *ipping_status = get_diagnostics_option("ipping", "DiagnosticState");
|
||||
char *ipping_ip_address_used = get_diagnostics_option("ipping", "IPAddressUsed");
|
||||
char *ipping_success_count = get_diagnostics_option("ipping", "SuccessCount");
|
||||
char *ipping_failure_count = get_diagnostics_option("ipping", "FailureCount");
|
||||
char *ipping_average_response_time = get_diagnostics_option("ipping", "AverageResponseTime");
|
||||
char *ipping_minimum_response_time = get_diagnostics_option("ipping", "MinimumResponseTime");
|
||||
char *ipping_maximum_response_time = get_diagnostics_option("ipping", "MaximumResponseTime");
|
||||
char *ipping_average_response_time_detailed = get_diagnostics_option("ipping", "AverageResponseTimeDetailed");
|
||||
char *ipping_minimum_response_time_detailed = get_diagnostics_option("ipping", "MinimumResponseTimeDetailed");
|
||||
char *ipping_maximum_response_time_detailed = get_diagnostics_option("ipping", "MaximumResponseTimeDetailed");
|
||||
|
||||
add_list_parameter(ctx, dmstrdup("Status"), ipping_status, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), ipping_ip_address_used, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("SuccessCount"), ipping_success_count, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("FailureCount"), ipping_failure_count, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("AverageResponseTime"), ipping_average_response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MinimumResponseTime"), ipping_minimum_response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MaximumResponseTime"), ipping_maximum_response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("AverageResponseTimeDetailed"), ipping_average_response_time_detailed, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MinimumResponseTimeDetailed"), ipping_minimum_response_time_detailed, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MaximumResponseTimeDetailed"), ipping_maximum_response_time_detailed, DMT_TYPE[DMT_UNINT], NULL);
|
||||
if (res != NULL)
|
||||
json_object_put(res);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
|
@ -1840,69 +1794,72 @@ static int get_operate_args_IPDiagnostics_TraceRoute(char *refparam, struct dmct
|
|||
|
||||
static int operate_IPDiagnostics_TraceRoute(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
json_object *res = NULL, *arr_route_hops = NULL, *route_hops_obj = NULL;
|
||||
char *route_hops_host[2] = {0};
|
||||
char *route_hops_host_address[2] = {0};
|
||||
char *route_hops_rttimes[2] = {0};
|
||||
char *route_hops_errorcode = NULL;
|
||||
int i = 1;
|
||||
|
||||
init_diagnostics_operation("traceroute", TRACEROUTE_PATH);
|
||||
remove_unused_diagnostic_sections("RouteHops");
|
||||
int idx = 0;
|
||||
|
||||
char *host = dmjson_get_value((json_object *)value, 1, "Host");
|
||||
if (host[0] == '\0')
|
||||
return CMD_INVALID_ARGUMENTS;
|
||||
|
||||
char *interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *proto = dmjson_get_value((json_object *)value, 1, "ProtocolVersion");
|
||||
char *ip_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *interface = get_diagnostics_interface_option(ctx, ip_interface);
|
||||
char *ip_proto = dmjson_get_value((json_object *)value, 1, "ProtocolVersion");
|
||||
char *nboftries = dmjson_get_value((json_object *)value, 1, "NumberOfTries");
|
||||
char *timeout = dmjson_get_value((json_object *)value, 1, "Timeout");
|
||||
char *datablocksize = dmjson_get_value((json_object *)value, 1, "DataBlockSize");
|
||||
char *dscp = dmjson_get_value((json_object *)value, 1, "DSCP");
|
||||
char *maxhops = dmjson_get_value((json_object *)value, 1, "MaxHopCount");
|
||||
char *proto = (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto";
|
||||
|
||||
set_diagnostics_option("traceroute", "Host", host);
|
||||
set_diagnostics_interface_option(ctx, "traceroute", interface);
|
||||
set_diagnostics_option("traceroute", "ProtocolVersion", proto);
|
||||
set_diagnostics_option("traceroute", "NumberOfTries", nboftries);
|
||||
set_diagnostics_option("traceroute", "Timeout", timeout);
|
||||
set_diagnostics_option("traceroute", "DataBlockSize", datablocksize);
|
||||
set_diagnostics_option("traceroute", "DSCP", dscp);
|
||||
set_diagnostics_option("traceroute", "MaxHops", maxhops);
|
||||
dmubus_call_blocking("bbf.diag", "traceroute",
|
||||
UBUS_ARGS{
|
||||
{"host", host, String},
|
||||
{"iface", interface, String},
|
||||
{"ip_proto", ip_proto, String},
|
||||
{"nbr_of_tries", nboftries, String},
|
||||
{"timeout", timeout, String},
|
||||
{"data_size", datablocksize, String},
|
||||
{"dscp", dscp, String},
|
||||
{"max_hop_cnt", maxhops, String},
|
||||
{"proto", proto, String}
|
||||
},
|
||||
9, &res);
|
||||
|
||||
// Commit and Free uci_ctx_bbfdm
|
||||
commit_and_free_uci_ctx_bbfdm(DMMAP_DIAGNOSTIGS);
|
||||
if (res == NULL)
|
||||
return CMD_FAIL;
|
||||
|
||||
dmcmd("/bin/sh", 2, TRACEROUTE_PATH, "run");
|
||||
char *status = dmjson_get_value(res, 1, "Status");
|
||||
char *ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed");
|
||||
char *response_time = dmjson_get_value(res, 1, "ResponseTime");
|
||||
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(status), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), dmstrdup(ip_address_used), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("ResponseTime"), dmstrdup(response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
dmuci_init_bbfdm();
|
||||
dmjson_foreach_obj_in_array(res, arr_route_hops, route_hops_obj, idx, 1, "RouteHops") {
|
||||
int i = idx + 1;
|
||||
|
||||
char *status = get_diagnostics_option("traceroute", "DiagnosticState");
|
||||
char *ip_address_used = get_diagnostics_option("traceroute", "IPAddressUsed");
|
||||
char *response_time = get_diagnostics_option("traceroute", "ResponseTime");
|
||||
add_list_parameter(ctx, dmstrdup("Status"), status, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), ip_address_used, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("ResponseTime"), response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
|
||||
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "RouteHops", s) {
|
||||
dmasprintf(&route_hops_host[0], "RouteHops.%d.Host", i);
|
||||
dmasprintf(&route_hops_host_address[0], "RouteHops.%d.HostAddress", i);
|
||||
dmasprintf(&route_hops_rttimes[0], "RouteHops.%d.RTTimes", i);
|
||||
dmasprintf(&route_hops_errorcode, "RouteHops.%d.ErrorCode", i);
|
||||
|
||||
dmuci_get_value_by_section_string(s, "host", &route_hops_host[1]);
|
||||
dmuci_get_value_by_section_string(s, "ip", &route_hops_host_address[1]);
|
||||
dmuci_get_value_by_section_string(s, "time", &route_hops_rttimes[1]);
|
||||
route_hops_host[1] = dmjson_get_value(route_hops_obj, 1, "Host");
|
||||
route_hops_host_address[1] = dmjson_get_value(route_hops_obj, 1, "HostAddress");
|
||||
route_hops_rttimes[1] = dmjson_get_value(route_hops_obj, 1, "RTTimes");
|
||||
|
||||
add_list_parameter(ctx, route_hops_host[0], route_hops_host[1], DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, route_hops_host_address[0], route_hops_host_address[1], DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, route_hops_rttimes[0], route_hops_rttimes[1], DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, route_hops_host[0], dmstrdup(route_hops_host[1]), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, route_hops_host_address[0], dmstrdup(route_hops_host_address[1]), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, route_hops_rttimes[0], dmstrdup(route_hops_rttimes[1]), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, route_hops_errorcode, "0", DMT_TYPE[DMT_UNINT], NULL);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (res != NULL)
|
||||
json_object_put(res);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -1960,58 +1917,102 @@ static int get_operate_args_IPDiagnostics_DownloadDiagnostics(char *refparam, st
|
|||
|
||||
static int operate_IPDiagnostics_DownloadDiagnostics(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
init_diagnostics_operation("download", DOWNLOAD_DIAGNOSTIC_PATH);
|
||||
json_object *res = NULL;
|
||||
char *bytes_received = NULL;
|
||||
|
||||
char *download_url = dmjson_get_value((json_object *)value, 1, "DownloadURL");
|
||||
TRACE("Downaload::download_url=%s", download_url);
|
||||
if (download_url[0] == '\0')
|
||||
return CMD_INVALID_ARGUMENTS;
|
||||
char *download_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
|
||||
if (strncmp(download_url, HTTP_URI, strlen(HTTP_URI)) != 0 &&
|
||||
strncmp(download_url, FTP_URI, strlen(FTP_URI)) != 0 &&
|
||||
strchr(download_url,'@') != NULL)
|
||||
return CMD_INVALID_ARGUMENTS;
|
||||
|
||||
char *ip_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *download_interface = get_diagnostics_interface_option(ctx, ip_interface);
|
||||
char *download_dscp = dmjson_get_value((json_object *)value, 1, "DSCP");
|
||||
char *download_ethernet_priority = dmjson_get_value((json_object *)value, 1, "EthernetPriority");
|
||||
char *download_proto = dmjson_get_value((json_object *)value, 1, "ProtocolVersion");
|
||||
char *download_num_of_connections = dmjson_get_value((json_object *)value, 1, "NumberOfConnections");
|
||||
char *download_enable_per_connection_results = dmjson_get_value((json_object *)value, 1, "EnablePerConnectionResults");
|
||||
char *proto = (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto";
|
||||
|
||||
set_diagnostics_option("download", "url", download_url);
|
||||
set_diagnostics_interface_option(ctx, "download", download_interface);
|
||||
set_diagnostics_option("download", "DSCP", download_dscp);
|
||||
set_diagnostics_option("download", "ethernetpriority", download_ethernet_priority);
|
||||
set_diagnostics_option("download", "ProtocolVersion", download_proto);
|
||||
set_diagnostics_option("download", "NumberOfConnections", download_num_of_connections);
|
||||
set_diagnostics_option("download", "EnablePerConnection", download_enable_per_connection_results);
|
||||
TRACE("Downaload::download_url=%s && ip_interface=%s && download_interface=%s && download_dscp=%s && download_ethernet_priority=%s && download_proto=%s && proto=%s",
|
||||
download_url,
|
||||
ip_interface,
|
||||
download_interface,
|
||||
download_dscp,
|
||||
download_ethernet_priority,
|
||||
download_proto,
|
||||
proto);
|
||||
|
||||
dmubus_call_blocking("bbf.diag", "download",
|
||||
UBUS_ARGS{
|
||||
{"url", download_url, String},
|
||||
{"iface", download_interface, String},
|
||||
{"dscp", download_dscp, String},
|
||||
{"eth_prio", download_ethernet_priority, String},
|
||||
{"ip_proto", download_proto, String},
|
||||
{"num_of_con", download_num_of_connections, String},
|
||||
{"enable_per_con", download_enable_per_connection_results, String},
|
||||
{"proto", proto, String}
|
||||
},
|
||||
8, &res);
|
||||
|
||||
TRACE("Downaload::res=%p", res);
|
||||
|
||||
if (res == NULL) {
|
||||
if (file_exists(DOWNLOAD_DUMP_FILE))
|
||||
remove(DOWNLOAD_DUMP_FILE);
|
||||
|
||||
if (start_upload_download_diagnostic(DOWNLOAD_DIAGNOSTIC) == -1)
|
||||
return CMD_FAIL;
|
||||
}
|
||||
|
||||
char *status = get_diagnostics_option("download", "DiagnosticState");
|
||||
char *ip_address_used = get_diagnostics_option("download", "IPAddressUsed");
|
||||
char *romtime = get_diagnostics_option("download", "ROMtime");
|
||||
char *bomtime = get_diagnostics_option("download", "BOMtime");
|
||||
char *eomtime = get_diagnostics_option("download", "EOMtime");
|
||||
char *test_bytes_received = get_diagnostics_option("download", "TestBytesReceived");
|
||||
char *total_bytes_received = get_diagnostics_option("download", "TotalBytesReceived");
|
||||
char *total_bytes_sent = get_diagnostics_option("download", "TotalBytesSent");
|
||||
char *test_bytes_received_under_full_loading = get_diagnostics_option("download", "TestBytesReceived");
|
||||
char *total_bytes_received_under_full_loading = get_diagnostics_option("download", "TotalBytesReceived");
|
||||
char *total_bytes_sent_under_full_loading = get_diagnostics_option("download", "TotalBytesSent");
|
||||
char *period_of_full_loading = get_diagnostics_option("download", "PeriodOfFullLoading");
|
||||
char *tcp_open_request_time = get_diagnostics_option("download", "TCPOpenRequestTime");
|
||||
char *tcp_open_response_time = get_diagnostics_option("download", "TCPOpenResponseTime");
|
||||
char *status = dmjson_get_value(res, 1, "Status");
|
||||
char *ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed");
|
||||
char *total_bytes_received = dmjson_get_value(res, 1, "TotalBytesReceived");
|
||||
char *total_bytes_sent = dmjson_get_value(res, 1, "TotalBytesSent");
|
||||
char *total_bytes_received_under_full_loading = dmjson_get_value(res, 1, "TotalBytesReceived");
|
||||
char *total_bytes_sent_under_full_loading = dmjson_get_value(res, 1, "TotalBytesSent");
|
||||
char *period_of_full_loading = dmjson_get_value(res, 1, "PeriodOfFullLoading");
|
||||
|
||||
add_list_parameter(ctx, dmstrdup("Status"), status, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), ip_address_used, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("ROMTime"), romtime, DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("BOMTime"), bomtime, DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("EOMTime"), eomtime, DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TestBytesReceived"), test_bytes_received, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesReceived"), total_bytes_received, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesSent"), total_bytes_sent, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TestBytesReceivedUnderFullLoading"), test_bytes_received_under_full_loading, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesReceivedUnderFullLoading"), total_bytes_received_under_full_loading, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesSentUnderFullLoading"), total_bytes_sent_under_full_loading, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("PeriodOfFullLoading"), period_of_full_loading, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TCPOpenRequestTime"), tcp_open_request_time, DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TCPOpenResponseTime"), tcp_open_response_time, DMT_TYPE[DMT_TIME], NULL);
|
||||
TRACE("Downaload::status=%s", status);
|
||||
if (DM_LSTRCMP(status, "Complete") == 0) {
|
||||
TRACE("Downaload::extract data");
|
||||
memset(&diag_stats, 0, sizeof(diag_stats));
|
||||
if (DM_LSTRNCMP(download_url, HTTP_URI, strlen(HTTP_URI)) == 0)
|
||||
extract_stats(DOWNLOAD_DUMP_FILE, DIAGNOSTIC_HTTP, DOWNLOAD_DIAGNOSTIC);
|
||||
if (DM_LSTRNCMP(download_url, FTP_URI, strlen(FTP_URI)) == 0)
|
||||
extract_stats(DOWNLOAD_DUMP_FILE, DIAGNOSTIC_FTP, DOWNLOAD_DIAGNOSTIC);
|
||||
|
||||
if (file_exists(DOWNLOAD_DUMP_FILE))
|
||||
remove(DOWNLOAD_DUMP_FILE);
|
||||
} else if (DM_LSTRNCMP(status, "Error_", strlen("Error_")) == 0) {
|
||||
TRACE("Downaload::Status error");
|
||||
return CMD_FAIL;
|
||||
}
|
||||
|
||||
dmasprintf(&bytes_received, "%d", diag_stats.test_bytes_received);
|
||||
|
||||
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(status), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), dmstrdup(ip_address_used), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("ROMTime"), (diag_stats.romtime)[0] != 0 ? diag_stats.romtime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("BOMTime"), (diag_stats.bomtime)[0] != 0 ? diag_stats.bomtime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("EOMTime"), (diag_stats.eomtime)[0] != 0 ? diag_stats.eomtime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TestBytesReceived"), bytes_received, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesReceived"), dmstrdup(total_bytes_received), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesSent"), dmstrdup(total_bytes_sent), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TestBytesReceivedUnderFullLoading"), bytes_received, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesReceivedUnderFullLoading"), dmstrdup(total_bytes_received_under_full_loading), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesSentUnderFullLoading"), dmstrdup(total_bytes_sent_under_full_loading), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("PeriodOfFullLoading"), dmstrdup(period_of_full_loading), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TCPOpenRequestTime"), (diag_stats.tcpopenrequesttime)[0] != 0 ? diag_stats.tcpopenrequesttime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TCPOpenResponseTime"), (diag_stats.tcpopenresponsetime)[0] != 0 ? diag_stats.tcpopenresponsetime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
|
||||
if (res != NULL)
|
||||
json_object_put(res);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
|
@ -2071,64 +2072,88 @@ static int get_operate_args_IPDiagnostics_UploadDiagnostics(char *refparam, stru
|
|||
|
||||
static int operate_IPDiagnostics_UploadDiagnostics(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
init_diagnostics_operation("upload", UPLOAD_DIAGNOSTIC_PATH);
|
||||
json_object *res = NULL;
|
||||
|
||||
char *upload_url = dmjson_get_value((json_object *)value, 1, "UploadURL");
|
||||
if (upload_url[0] == '\0')
|
||||
return CMD_INVALID_ARGUMENTS;
|
||||
|
||||
if (strncmp(upload_url, HTTP_URI, strlen(HTTP_URI)) != 0 &&
|
||||
strncmp(upload_url, FTP_URI, strlen(FTP_URI)) != 0 &&
|
||||
strchr(upload_url,'@') != NULL)
|
||||
return CMD_INVALID_ARGUMENTS;
|
||||
|
||||
char *upload_test_file_length = dmjson_get_value((json_object *)value, 1, "TestFileLength");
|
||||
if (upload_test_file_length[0] == '\0')
|
||||
return CMD_INVALID_ARGUMENTS;
|
||||
|
||||
char *upload_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *ip_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *upload_interface = get_diagnostics_interface_option(ctx, ip_interface);
|
||||
char *upload_dscp = dmjson_get_value((json_object *)value, 1, "DSCP");
|
||||
char *upload_ethernet_priority = dmjson_get_value((json_object *)value, 1, "EthernetPriority");
|
||||
char *upload_proto = dmjson_get_value((json_object *)value, 1, "ProtocolVersion");
|
||||
char *upload_num_of_connections = dmjson_get_value((json_object *)value, 1, "NumberOfConnections");
|
||||
char *upload_enable_per_connection_results = dmjson_get_value((json_object *)value, 1, "EnablePerConnectionResults");
|
||||
char *proto = (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto";
|
||||
|
||||
set_diagnostics_option("upload", "url", upload_url);
|
||||
set_diagnostics_option("upload", "TestFileLength", upload_test_file_length);
|
||||
set_diagnostics_interface_option(ctx, "upload", upload_interface);
|
||||
set_diagnostics_option("upload", "DSCP", upload_dscp);
|
||||
set_diagnostics_option("upload", "ethernetpriority", upload_ethernet_priority);
|
||||
set_diagnostics_option("upload", "ProtocolVersion", upload_proto);
|
||||
set_diagnostics_option("upload", "NumberOfConnections", upload_num_of_connections);
|
||||
set_diagnostics_option("upload", "EnablePerConnection", upload_enable_per_connection_results);
|
||||
dmubus_call_blocking("bbf.diag", "upload",
|
||||
UBUS_ARGS{
|
||||
{"url", upload_url, String},
|
||||
{"iface", upload_interface, String},
|
||||
{"dscp", upload_dscp, String},
|
||||
{"eth_prio", upload_ethernet_priority, String},
|
||||
{"file_length", upload_test_file_length, String},
|
||||
{"ip_proto", upload_proto, String},
|
||||
{"num_of_con", upload_num_of_connections, String},
|
||||
{"enable_per_con", upload_enable_per_connection_results, String},
|
||||
{"proto", proto, String}
|
||||
},
|
||||
9, &res);
|
||||
|
||||
if (start_upload_download_diagnostic(UPLOAD_DIAGNOSTIC) == -1)
|
||||
if (res == NULL) {
|
||||
if (file_exists(UPLOAD_DUMP_FILE))
|
||||
remove(UPLOAD_DUMP_FILE);
|
||||
|
||||
return CMD_FAIL;
|
||||
}
|
||||
|
||||
char *upload_status = dmjson_get_value(res, 1, "Status");
|
||||
char *upload_ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed");
|
||||
char *upload_test_bytes_sent = dmjson_get_value(res, 1, "TestBytesSent");
|
||||
char *upload_total_bytes_received = dmjson_get_value(res, 1, "TotalBytesReceived");
|
||||
char *upload_total_bytes_sent = dmjson_get_value(res, 1, "TotalBytesSent");
|
||||
char *upload_period_of_full_loading = dmjson_get_value(res, 1, "PeriodOfFullLoading");
|
||||
|
||||
if (DM_LSTRCMP(upload_status, "Complete") == 0) {
|
||||
memset(&diag_stats, 0, sizeof(diag_stats));
|
||||
if (DM_LSTRNCMP(upload_url, HTTP_URI, strlen(HTTP_URI)) == 0)
|
||||
extract_stats(UPLOAD_DUMP_FILE, DIAGNOSTIC_HTTP, UPLOAD_DIAGNOSTIC);
|
||||
if (DM_LSTRNCMP(upload_url, FTP_URI, strlen(FTP_URI)) == 0)
|
||||
extract_stats(UPLOAD_DUMP_FILE, DIAGNOSTIC_FTP, UPLOAD_DIAGNOSTIC);
|
||||
|
||||
if (file_exists(UPLOAD_DUMP_FILE))
|
||||
remove(UPLOAD_DUMP_FILE);
|
||||
|
||||
} else if (DM_LSTRNCMP(upload_status, "Error_", strlen("Error_")) == 0)
|
||||
return CMD_FAIL;
|
||||
|
||||
char *upload_status = get_diagnostics_option("upload", "DiagnosticState");
|
||||
char *upload_ip_address_used = get_diagnostics_option("upload", "IPAddressUsed");
|
||||
char *upload_romtime = get_diagnostics_option("upload", "ROMtime");
|
||||
char *upload_bomtime = get_diagnostics_option("upload", "BOMtime");
|
||||
char *upload_eomtime = get_diagnostics_option("upload", "EOMtime");
|
||||
char *upload_test_bytes_sent = get_diagnostics_option("upload", "TestBytesSent");
|
||||
char *upload_total_bytes_received = get_diagnostics_option("upload", "TotalBytesReceived");
|
||||
char *upload_total_bytes_sent = get_diagnostics_option("upload", "TotalBytesSent");
|
||||
char *upload_test_bytes_sent_under_full_loading = get_diagnostics_option("upload", "TestBytesSent");
|
||||
char *upload_total_bytes_received_under_full_loading = get_diagnostics_option("upload", "TotalBytesReceived");
|
||||
char *upload_total_bytes_sent_under_full_loading = get_diagnostics_option("upload", "TotalBytesSent");
|
||||
char *upload_period_of_full_loading = get_diagnostics_option("upload", "PeriodOfFullLoading");
|
||||
char *upload_tcp_open_request_time = get_diagnostics_option("upload", "TCPOpenRequestTime");
|
||||
char *upload_tcp_open_response_time = get_diagnostics_option("upload", "TCPOpenResponseTime");
|
||||
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(upload_status), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), dmstrdup(upload_ip_address_used), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("ROMTime"), (diag_stats.romtime)[0] != 0 ? diag_stats.romtime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("BOMTime"), (diag_stats.bomtime)[0] != 0 ? diag_stats.bomtime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("EOMTime"), (diag_stats.eomtime)[0] != 0 ? diag_stats.eomtime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TestBytesSent"), dmstrdup(upload_test_bytes_sent), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesReceived"), dmstrdup(upload_total_bytes_received), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesSent"), dmstrdup(upload_total_bytes_sent), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TestBytesSentUnderFullLoading"), dmstrdup(upload_test_bytes_sent), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesReceivedUnderFullLoading"), dmstrdup(upload_total_bytes_received), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesSentUnderFullLoading"), dmstrdup(upload_total_bytes_sent), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("PeriodOfFullLoading"), dmstrdup(upload_period_of_full_loading), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TCPOpenRequestTime"), (diag_stats.tcpopenrequesttime)[0] != 0 ? diag_stats.tcpopenrequesttime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TCPOpenResponseTime"), (diag_stats.tcpopenresponsetime)[0] != 0 ? diag_stats.tcpopenresponsetime : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
|
||||
|
||||
add_list_parameter(ctx, dmstrdup("Status"), upload_status, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), upload_ip_address_used, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("ROMTime"), upload_romtime, DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("BOMTime"), upload_bomtime, DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("EOMTime"), upload_eomtime, DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TestBytesSent"), upload_test_bytes_sent, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesReceived"), upload_total_bytes_received, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesSent"), upload_total_bytes_sent, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TestBytesSentUnderFullLoading"), upload_test_bytes_sent_under_full_loading, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesReceivedUnderFullLoading"), upload_total_bytes_received_under_full_loading, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TotalBytesSentUnderFullLoading"), upload_total_bytes_sent_under_full_loading, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("PeriodOfFullLoading"), upload_period_of_full_loading, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TCPOpenRequestTime"), upload_tcp_open_request_time, DMT_TYPE[DMT_TIME], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("TCPOpenResponseTime"), upload_tcp_open_response_time, DMT_TYPE[DMT_TIME], NULL);
|
||||
if (res != NULL)
|
||||
json_object_put(res);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
|
@ -2175,54 +2200,59 @@ static int get_operate_args_IPDiagnostics_UDPEchoDiagnostics(char *refparam, str
|
|||
|
||||
static int operate_IPDiagnostics_UDPEchoDiagnostics(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
init_diagnostics_operation("udpechodiag", UDPECHO_PATH);
|
||||
json_object *res = NULL;
|
||||
|
||||
char *udpecho_host = dmjson_get_value((json_object *)value, 1, "Host");
|
||||
if (udpecho_host[0] == '\0')
|
||||
return CMD_INVALID_ARGUMENTS;
|
||||
|
||||
char *udpecho_port = dmjson_get_value((json_object *)value, 1, "Port");
|
||||
char *udpecho_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *ip_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *udpecho_interface = get_diagnostics_interface_option(ctx, ip_interface);
|
||||
char *udpecho_proto = dmjson_get_value((json_object *)value, 1, "ProtocolVersion");
|
||||
char *udpecho_nbofrepetition = dmjson_get_value((json_object *)value, 1, "NumberOfRepetitions");
|
||||
char *udpecho_timeout = dmjson_get_value((json_object *)value, 1, "Timeout");
|
||||
char *udpecho_datablocksize = dmjson_get_value((json_object *)value, 1, "DataBlockSize");
|
||||
char *udpecho_dscp = dmjson_get_value((json_object *)value, 1, "DSCP");
|
||||
char *udpecho_inter_transmission_time = dmjson_get_value((json_object *)value, 1, "InterTransmissionTime");
|
||||
char *proto = (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto";
|
||||
|
||||
set_diagnostics_option("udpechodiag", "Host", udpecho_host);
|
||||
set_diagnostics_option("udpechodiag", "port", udpecho_port);
|
||||
set_diagnostics_interface_option(ctx, "udpechodiag", udpecho_interface);
|
||||
set_diagnostics_option("udpechodiag", "ProtocolVersion", udpecho_proto);
|
||||
set_diagnostics_option("udpechodiag", "NumberOfRepetitions", udpecho_nbofrepetition);
|
||||
set_diagnostics_option("udpechodiag", "Timeout", udpecho_timeout);
|
||||
set_diagnostics_option("udpechodiag", "DataBlockSize", udpecho_datablocksize);
|
||||
set_diagnostics_option("udpechodiag", "DSCP", udpecho_dscp);
|
||||
set_diagnostics_option("udpechodiag", "InterTransmissionTime", udpecho_inter_transmission_time);
|
||||
dmubus_call_blocking("bbf.diag", "udpecho",
|
||||
UBUS_ARGS{
|
||||
{"host", udpecho_host, String},
|
||||
{"port", udpecho_port, String},
|
||||
{"iface", udpecho_interface, String},
|
||||
{"ip_proto", udpecho_proto, String},
|
||||
{"nbr_of_rep", udpecho_nbofrepetition, String},
|
||||
{"timeout", udpecho_timeout, String},
|
||||
{"data_size", udpecho_datablocksize, String},
|
||||
{"dscp", udpecho_dscp, String},
|
||||
{"inter_trans_time", udpecho_inter_transmission_time, String},
|
||||
{"proto", proto, String}
|
||||
},
|
||||
10, &res);
|
||||
|
||||
// Commit and Free uci_ctx_bbfdm
|
||||
commit_and_free_uci_ctx_bbfdm(DMMAP_DIAGNOSTIGS);
|
||||
if (res == NULL)
|
||||
return CMD_FAIL;
|
||||
|
||||
dmcmd("/bin/sh", 2, UDPECHO_PATH, "run");
|
||||
char *status = dmjson_get_value(res, 1, "Status");
|
||||
char *ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed");
|
||||
char *udpecho_success_count = dmjson_get_value(res, 1, "SuccessCount");
|
||||
char *udpecho_failure_count = dmjson_get_value(res, 1, "FailureCount");
|
||||
char *udpecho_average_response_time = dmjson_get_value(res, 1, "AverageResponseTime");
|
||||
char *udpecho_minimum_response_time = dmjson_get_value(res, 1, "MinimumResponseTime");
|
||||
char *udpecho_maximum_response_time = dmjson_get_value(res, 1, "MaximumResponseTime");
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
dmuci_init_bbfdm();
|
||||
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(status), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), dmstrdup(ip_address_used), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("SuccessCount"), dmstrdup(udpecho_success_count), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("FailureCount"), dmstrdup(udpecho_failure_count), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("AverageResponseTime"), dmstrdup(udpecho_average_response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MinimumResponseTime"), dmstrdup(udpecho_minimum_response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MaximumResponseTime"), dmstrdup(udpecho_maximum_response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
|
||||
char *status = get_diagnostics_option("udpechodiag", "DiagnosticState");
|
||||
char *ip_address_used = get_diagnostics_option("udpechodiag", "IPAddressUsed");
|
||||
char *udpecho_success_count = get_diagnostics_option("udpechodiag", "SuccessCount");
|
||||
char *udpecho_failure_count = get_diagnostics_option("udpechodiag", "FailureCount");
|
||||
char *udpecho_average_response_time = get_diagnostics_option("udpechodiag", "AverageResponseTime");
|
||||
char *udpecho_minimum_response_time = get_diagnostics_option("udpechodiag", "MinimumResponseTime");
|
||||
char *udpecho_maximum_response_time = get_diagnostics_option("udpechodiag", "MaximumResponseTime");
|
||||
|
||||
add_list_parameter(ctx, dmstrdup("Status"), status, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), ip_address_used, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("SuccessCount"), udpecho_success_count, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("FailureCount"), udpecho_failure_count, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("AverageResponseTime"), udpecho_average_response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MinimumResponseTime"), udpecho_minimum_response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MaximumResponseTime"), udpecho_maximum_response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
if (res != NULL)
|
||||
json_object_put(res);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
|
@ -2256,48 +2286,53 @@ static int get_operate_args_IPDiagnostics_ServerSelectionDiagnostics(char *refpa
|
|||
|
||||
static int operate_IPDiagnostics_ServerSelectionDiagnostics(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
init_diagnostics_operation("serverselection", SERVERSELECTION_PATH);
|
||||
json_object *res = NULL;
|
||||
|
||||
char *hostlist = dmjson_get_value((json_object *)value, 1, "HostList");
|
||||
if (hostlist[0] == '\0')
|
||||
return CMD_INVALID_ARGUMENTS;
|
||||
|
||||
char *port = dmjson_get_value((json_object *)value, 1, "Port");
|
||||
char *proto = dmjson_get_value((json_object *)value, 1, "Protocol");
|
||||
char *protocol_used = dmjson_get_value((json_object *)value, 1, "Protocol");
|
||||
char *protocol_version = dmjson_get_value((json_object *)value, 1, "ProtocolVersion");
|
||||
char *interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *ip_interface = dmjson_get_value((json_object *)value, 1, "Interface");
|
||||
char *interface = get_diagnostics_interface_option(ctx, ip_interface);
|
||||
char *nbofrepetition = dmjson_get_value((json_object *)value, 1, "NumberOfRepetitions");
|
||||
char *timeout = dmjson_get_value((json_object *)value, 1, "Timeout");
|
||||
char *proto = (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto";
|
||||
|
||||
set_diagnostics_option("serverselection", "HostList", hostlist);
|
||||
set_diagnostics_interface_option(ctx, "serverselection", interface);
|
||||
set_diagnostics_option("serverselection", "ProtocolVersion", protocol_version);
|
||||
set_diagnostics_option("serverselection", "NumberOfRepetitions", nbofrepetition);
|
||||
set_diagnostics_option("serverselection", "port", port);
|
||||
set_diagnostics_option("serverselection", "Protocol", proto);
|
||||
set_diagnostics_option("serverselection", "Timeout", timeout);
|
||||
dmubus_call_blocking("bbf.diag", "serverselection",
|
||||
UBUS_ARGS{
|
||||
{"hostlist", hostlist, String},
|
||||
{"port", port, String},
|
||||
{"iface", interface, String},
|
||||
{"ip_proto", protocol_version, String},
|
||||
{"nbr_of_rep", nbofrepetition, String},
|
||||
{"timeout", timeout, String},
|
||||
{"protocol_used", protocol_used, String},
|
||||
{"proto", proto, String}
|
||||
},
|
||||
8, &res);
|
||||
|
||||
// Commit and Free uci_ctx_bbfdm
|
||||
commit_and_free_uci_ctx_bbfdm(DMMAP_DIAGNOSTIGS);
|
||||
if (res == NULL)
|
||||
return CMD_FAIL;
|
||||
|
||||
dmcmd("/bin/sh", 2, SERVERSELECTION_PATH, "run");
|
||||
char *status = dmjson_get_value(res, 1, "Status");
|
||||
char *fasthost = dmjson_get_value(res, 1, "FastestHost");
|
||||
char *average_response_time = dmjson_get_value(res, 1, "AverageResponseTime");
|
||||
char *minimum_response_time = dmjson_get_value(res, 1, "MinimumResponseTime");
|
||||
char *maximum_response_time = dmjson_get_value(res, 1, "MaximumResponseTime");
|
||||
char *ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed");
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
dmuci_init_bbfdm();
|
||||
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(status), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("FastestHost"), dmstrdup(fasthost), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("AverageResponseTime"), dmstrdup(average_response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MinimumResponseTime"), dmstrdup(minimum_response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MaximumResponseTime"), dmstrdup(maximum_response_time), DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), dmstrdup(ip_address_used), DMT_TYPE[DMT_STRING], NULL);
|
||||
|
||||
char *status = get_diagnostics_option("serverselection", "DiagnosticState");
|
||||
char *fasthost = get_diagnostics_option("serverselection", "FastestHost");
|
||||
char *average_response_time = get_diagnostics_option("serverselection", "AverageResponseTime");
|
||||
char *minimum_response_time = get_diagnostics_option("serverselection", "MinimumResponseTime");
|
||||
char *maximum_response_time = get_diagnostics_option("serverselection", "MaximumResponseTime");
|
||||
char *ip_address_used = get_diagnostics_option("serverselection", "IPAddressUsed");
|
||||
|
||||
add_list_parameter(ctx, dmstrdup("Status"), status, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("FastestHost"), fasthost, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("AverageResponseTime"), average_response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MinimumResponseTime"), minimum_response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("MaximumResponseTime"), maximum_response_time, DMT_TYPE[DMT_UNINT], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("IPAddressUsed"), ip_address_used, DMT_TYPE[DMT_STRING], NULL);
|
||||
if (res != NULL)
|
||||
json_object_put(res);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1415,7 +1415,8 @@ static int operate_DeviceInfoFirmwareImage_Activate(char *refparam, struct dmctx
|
|||
for (int i = 0; i < MAX_TIME_WINDOW && DM_STRLEN(start_time[i]); i++) {
|
||||
char buffer[512] = {0};
|
||||
time_t t_time = time(NULL);
|
||||
t_time = t_time + DM_STRTOL(start_time[i]);
|
||||
long int start_t = (DM_STRTOL(start_time[i]) > 60) ? DM_STRTOL(start_time[i]) : 60;
|
||||
t_time += start_t;
|
||||
struct tm *tm_local = localtime(&t_time);
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "%d %d %d %d * sh %s '%s' '%s' '%ld' '%d' '%s' '%s'\n",
|
||||
|
|
|
|||
|
|
@ -634,7 +634,6 @@ static int set_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmct
|
|||
return 0;
|
||||
case VALUESET:
|
||||
if (DM_LSTRCMP(value, "Requested") == 0) {
|
||||
NSLOOKUP_STOP
|
||||
set_diagnostics_option("nslookup", "DiagnosticState", value);
|
||||
bbf_set_end_session_flag(ctx, BBF_END_SESSION_NSLOOKUP_DIAGNOSTIC);
|
||||
}
|
||||
|
|
@ -657,7 +656,6 @@ static int set_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx,
|
|||
|
||||
return 0;
|
||||
case VALUESET:
|
||||
NSLOOKUP_STOP
|
||||
reset_diagnostic_state("nslookup");
|
||||
set_diagnostics_interface_option(ctx, "nslookup", value);
|
||||
return 0;
|
||||
|
|
@ -673,7 +671,6 @@ static int set_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx,
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
NSLOOKUP_STOP
|
||||
reset_diagnostic_state("nslookup");
|
||||
set_diagnostics_option("nslookup", "HostName", value);
|
||||
return 0;
|
||||
|
|
@ -689,7 +686,6 @@ static int set_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ct
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
NSLOOKUP_STOP
|
||||
reset_diagnostic_state("nslookup");
|
||||
set_diagnostics_option("nslookup", "DNSServer", value);
|
||||
return 0;
|
||||
|
|
@ -705,7 +701,6 @@ static int set_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, vo
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
NSLOOKUP_STOP
|
||||
reset_diagnostic_state("nslookup");
|
||||
set_diagnostics_option("nslookup", "Timeout", value);
|
||||
return 0;
|
||||
|
|
@ -721,7 +716,6 @@ static int set_nslookupdiagnostics_number_of_repetitions(char *refparam, struct
|
|||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
NSLOOKUP_STOP
|
||||
reset_diagnostic_state("nslookup");
|
||||
set_diagnostics_option("nslookup", "NumberOfRepetitions", value);
|
||||
return 0;
|
||||
|
|
@ -762,17 +756,14 @@ static int get_operate_args_DNSDiagnostics_NSLookupDiagnostics(char *refparam, s
|
|||
|
||||
static int operate_DNSDiagnostics_NSLookupDiagnostics(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
json_object *res = NULL, *arr_result = NULL, *result_obj = NULL;
|
||||
char *nslookup_status[2] = {0};
|
||||
char *nslookup_answer_type[2] = {0};
|
||||
char *nslookup_hostname_returned[2] = {0};
|
||||
char *nslookup_ip_addresses[2] = {0};
|
||||
char *nslookup_dns_server_ip[2] = {0};
|
||||
char *nslookup_response_time[2] = {0};
|
||||
int i = 1;
|
||||
|
||||
init_diagnostics_operation("nslookup", NSLOOKUP_PATH);
|
||||
remove_unused_diagnostic_sections("NSLookupResult");
|
||||
int idx = 0;
|
||||
|
||||
char *hostname = dmjson_get_value((json_object *)value, 1, "HostName");
|
||||
if (hostname[0] == '\0')
|
||||
|
|
@ -781,27 +772,30 @@ static int operate_DNSDiagnostics_NSLookupDiagnostics(char *refparam, struct dmc
|
|||
char *dnsserver = dmjson_get_value((json_object *)value, 1, "DNSServer");
|
||||
char *timeout = dmjson_get_value((json_object *)value, 1, "Timeout");
|
||||
char *nbofrepetition = dmjson_get_value((json_object *)value, 1, "NumberOfRepetitions");
|
||||
char *proto = (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto";
|
||||
|
||||
set_diagnostics_option("nslookup", "HostName", hostname);
|
||||
set_diagnostics_interface_option(ctx, "nslookup", interface);
|
||||
set_diagnostics_option("nslookup", "DNSServer", dnsserver);
|
||||
set_diagnostics_option("nslookup", "Timeout", timeout);
|
||||
set_diagnostics_option("nslookup", "NumberOfRepetitions", nbofrepetition);
|
||||
dmubus_call_blocking("bbf.diag", "nslookup",
|
||||
UBUS_ARGS{
|
||||
{"host", hostname, String},
|
||||
{"dns_serevr", dnsserver, String},
|
||||
{"iface", interface, String},
|
||||
{"nbr_of_rep", nbofrepetition, String},
|
||||
{"timeout", timeout, String},
|
||||
{"proto", proto, String}
|
||||
},
|
||||
6, &res);
|
||||
|
||||
// Commit and Free uci_ctx_bbfdm
|
||||
commit_and_free_uci_ctx_bbfdm(DMMAP_DIAGNOSTIGS);
|
||||
if (res == NULL)
|
||||
return CMD_FAIL;
|
||||
|
||||
dmcmd("/bin/sh", 2, NSLOOKUP_PATH, "run");
|
||||
char *status = dmjson_get_value(res, 1, "Status");
|
||||
char *success_count = dmjson_get_value(res, 1, "SuccessCount");
|
||||
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(status), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("SuccessCount"), dmstrdup(success_count), DMT_TYPE[DMT_UNINT], NULL);
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
dmuci_init_bbfdm();
|
||||
dmjson_foreach_obj_in_array(res, arr_result, result_obj, idx, 1, "NSLookupResult") {
|
||||
int i = idx + 1;
|
||||
|
||||
char *status = get_diagnostics_option("nslookup", "DiagnosticState");
|
||||
char *success_count = get_diagnostics_option("nslookup", "SuccessCount");
|
||||
add_list_parameter(ctx, dmstrdup("Status"), status, DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, dmstrdup("SuccessCount"), success_count, DMT_TYPE[DMT_UNINT], NULL);
|
||||
|
||||
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "NSLookupResult", s) {
|
||||
dmasprintf(&nslookup_status[0], "Result.%d.Status", i);
|
||||
dmasprintf(&nslookup_answer_type[0], "Result.%d.AnswerType", i);
|
||||
dmasprintf(&nslookup_hostname_returned[0], "Result.%d.HostNameReturned", i);
|
||||
|
|
@ -809,22 +803,24 @@ static int operate_DNSDiagnostics_NSLookupDiagnostics(char *refparam, struct dmc
|
|||
dmasprintf(&nslookup_dns_server_ip[0], "Result.%d.DNSServerIP", i);
|
||||
dmasprintf(&nslookup_response_time[0], "Result.%d.ResponseTime", i);
|
||||
|
||||
dmuci_get_value_by_section_string(s, "Status", &nslookup_status[1]);
|
||||
dmuci_get_value_by_section_string(s, "AnswerType", &nslookup_answer_type[1]);
|
||||
dmuci_get_value_by_section_string(s, "HostNameReturned", &nslookup_hostname_returned[1]);
|
||||
dmuci_get_value_by_section_string(s, "IPAddresses", &nslookup_ip_addresses[1]);
|
||||
dmuci_get_value_by_section_string(s, "DNSServerIP", &nslookup_dns_server_ip[1]);
|
||||
dmuci_get_value_by_section_string(s, "ResponseTime", &nslookup_response_time[1]);
|
||||
nslookup_status[1] = dmjson_get_value(result_obj, 1, "Status");
|
||||
nslookup_answer_type[1] = dmjson_get_value(result_obj, 1, "AnswerType");
|
||||
nslookup_hostname_returned[1] = dmjson_get_value(result_obj, 1, "HostNameReturned");
|
||||
nslookup_ip_addresses[1] = dmjson_get_value(result_obj, 1, "IPAddresses");
|
||||
nslookup_dns_server_ip[1] = dmjson_get_value(result_obj, 1, "DNSServerIP");
|
||||
nslookup_response_time[1] = dmjson_get_value(result_obj, 1, "ResponseTime");
|
||||
|
||||
add_list_parameter(ctx, nslookup_status[0], nslookup_status[1], DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_answer_type[0], nslookup_answer_type[1], DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_hostname_returned[0], nslookup_hostname_returned[1], DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_ip_addresses[0], nslookup_ip_addresses[1], DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_dns_server_ip[0], nslookup_dns_server_ip[1], DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_response_time[0], nslookup_response_time[1], DMT_TYPE[DMT_UNINT], NULL);
|
||||
i++;
|
||||
add_list_parameter(ctx, nslookup_status[0], dmstrdup(nslookup_status[1]), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_answer_type[0], dmstrdup(nslookup_answer_type[1]), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_hostname_returned[0], dmstrdup(nslookup_hostname_returned[1]), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_ip_addresses[0], dmstrdup(nslookup_ip_addresses[1]), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_dns_server_ip[0], dmstrdup(nslookup_dns_server_ip[1]), DMT_TYPE[DMT_STRING], NULL);
|
||||
add_list_parameter(ctx, nslookup_response_time[0], dmstrdup(nslookup_response_time[1]), DMT_TYPE[DMT_UNINT], NULL);
|
||||
}
|
||||
|
||||
if (res != NULL)
|
||||
json_object_put(res);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ For these modes and based on the firmware bank id, the required firmware image w
|
|||
|
||||
Definition of WhenIdle may vary for each deployment and customer, to make it customizable [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) script is used. It is assumed that customer shall overwrite this file using customer-config to match with there requirement.
|
||||
|
||||
In this mode, [bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh) script calls this script [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) to determine the idle state of the device. [bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh) assumes the device as idle if the exit status of the above script is 0, or if the [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) is not present in the predefined path "/usr/share/bbfdm/".
|
||||
In this mode, [bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh) script calls this script [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) to determine the idle state of the device. [bbf_activate_handler.sh](/scripts/bbf_activate_handler.sh) assumes the device as idle if the exit status of the above script is 0, or if the [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) is not present in the predefined path "ACTIVATE_HANDLER_FILE@dmcommon.h".
|
||||
|
||||
|
||||
If the exit code from the idle script is zero then firmware image can be activated. Otherwise, it has to wait for next time slot which is defined by 'RETRY_TIME' variable.
|
||||
|
|
@ -88,7 +88,7 @@ If the exit code from the idle script is zero then firmware image can be activat
|
|||
|
||||
> Note4: If 1 or more TimeWindow.{i}.Mode is set to 'WhenIdle' and all of them fails to get the idle state. The latest TimeWindow instance will force the device to activate the firmware image.
|
||||
|
||||
> Note5: If the idle script [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) not present in the pre-defined path "/usr/share/bbfdm/", then the device is assumed to be in ideal state and the firmware shall be activated instantly.
|
||||
> Note5: If the idle script [bbf_check_idle.sh](/scripts/bbf_check_idle.sh) not present in the pre-defined path "ACTIVATE_HANDLER_FILE@dmcommon.h", then the device is assumed to be in ideal state and the firmware shall be activated instantly.
|
||||
|
||||
> Note6: It is very likely that TimeWindow with 'WhenIdle' mode might not find any suitable Idle state, in that case firmware shall not be activated. If users/operators want to make sure that firmware gets activated at the end, then they can add a TimeWindow with 'AnyTime/Immediate' mode at the end, to activate the firmware.
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ install_libbbf_test
|
|||
|
||||
supervisorctl status all
|
||||
supervisorctl update
|
||||
supervisorctl restart all
|
||||
sleep 3
|
||||
supervisorctl status all
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ function install_libbbf()
|
|||
|
||||
echo "installing libbbf"
|
||||
exec_cmd_verbose make install
|
||||
ln -sf /usr/share/bbfdm/bbf.diag /usr/libexec/rpcd/bbf.diag
|
||||
cd ..
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -170,24 +170,6 @@ enum option_type_enum {
|
|||
OPTION_HEX
|
||||
};
|
||||
|
||||
#define IPPING_PATH "/usr/share/bbfdm/ipping_launch"
|
||||
#define IPPING_STOP dmcmd("/bin/sh", 2, IPPING_PATH, "stop");
|
||||
#define DOWNLOAD_DIAGNOSTIC_PATH "/usr/share/bbfdm/download_launch"
|
||||
#define DOWNLOAD_DUMP_FILE "/tmp/download_dump"
|
||||
#define DOWNLOAD_DIAGNOSTIC_STOP dmcmd("/bin/sh", 2, DOWNLOAD_DIAGNOSTIC_PATH, "stop");
|
||||
#define UPLOAD_DIAGNOSTIC_PATH "/usr/share/bbfdm/upload_launch"
|
||||
#define UPLOAD_DUMP_FILE "/tmp/upload_dump"
|
||||
#define UPLOAD_DIAGNOSTIC_STOP dmcmd("/bin/sh", 2, UPLOAD_DIAGNOSTIC_PATH, "stop");
|
||||
#define NSLOOKUP_PATH "/usr/share/bbfdm/nslookup_launch"
|
||||
#define NSLOOKUP_LOG_FILE "/tmp/nslookup.log"
|
||||
#define NSLOOKUP_STOP dmcmd("/bin/sh", 2, NSLOOKUP_PATH, "stop");
|
||||
#define TRACEROUTE_PATH "/usr/share/bbfdm/traceroute_launch"
|
||||
#define TRACEROUTE_STOP dmcmd("/bin/sh", 2, TRACEROUTE_PATH, "stop");
|
||||
#define UDPECHO_PATH "/usr/share/bbfdm/udpecho_launch"
|
||||
#define UDPECHO_STOP dmcmd("/bin/sh", 2, UDPECHO_PATH, "stop");
|
||||
#define SERVERSELECTION_PATH "/usr/share/bbfdm/serverselection_launch"
|
||||
#define SERVERSELECTION_STOP dmcmd("/bin/sh", 2, SERVERSELECTION_PATH, "stop");
|
||||
|
||||
#define sysfs_foreach_file(path,dir,ent) \
|
||||
if ((dir = opendir(path)) == NULL) return 0; \
|
||||
while ((ent = readdir (dir)) != NULL) \
|
||||
|
|
|
|||
45
scripts/bbf.diag
Executable file
45
scripts/bbf.diag
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/sh
|
||||
|
||||
BBF_SCRIPTS="/usr/share/bbfdm"
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
case "$1" in
|
||||
list)
|
||||
echo '{ "ipping" : { "host": "str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "data_size": "str", "dscp": "str", "proto": "str" },
|
||||
"nslookup" : { "host": "str", "dns_serevr": "str", "iface": "str", "nbr_of_rep": "str", "timeout": "str", "proto": "str" },
|
||||
"traceroute" : { "host": "str", "iface": "str", "ip_proto": "str", "nbr_of_tries": "str", "timeout": "str", "data_size": "str", "dscp": "str", "max_hop_cnt":"str", "proto": "str" },
|
||||
"udpecho" : { "host": "str", "port":"str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "data_size": "str", "dscp": "str", "inter_trans_time":"str", "proto": "str" },
|
||||
"serverselection" : { "hostlist": "str", "port":"str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "protocol_used": "str", "proto": "str" },
|
||||
"download" : { "url": "str", "iface":"str", "dscp": "str", "eth_prio": "str", "ip_proto": "str", "num_of_con": "str", "enable_per_con": "str", "proto": "str" },
|
||||
"upload" : { "url": "str", "iface":"str", "dscp": "str", "eth_prio": "str", "file_length":"str", "ip_proto": "str", "num_of_con": "str", "enable_per_con": "str", "proto": "str" }
|
||||
}'
|
||||
;;
|
||||
call)
|
||||
|
||||
# read the arguments
|
||||
read -r input
|
||||
case "$2" in
|
||||
ipping)
|
||||
sh ${BBF_SCRIPTS}/ipping "${input}"
|
||||
;;
|
||||
nslookup)
|
||||
sh ${BBF_SCRIPTS}/nslookup "${input}"
|
||||
;;
|
||||
traceroute)
|
||||
sh ${BBF_SCRIPTS}/traceroute "${input}"
|
||||
;;
|
||||
udpecho)
|
||||
sh ${BBF_SCRIPTS}/udpecho "${input}"
|
||||
;;
|
||||
serverselection)
|
||||
sh ${BBF_SCRIPTS}/serverselection "${input}"
|
||||
;;
|
||||
download)
|
||||
sh ${BBF_SCRIPTS}/download "${input}"
|
||||
;;
|
||||
upload)
|
||||
sh ${BBF_SCRIPTS}/upload "${input}"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
|
@ -6,7 +6,9 @@
|
|||
# Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
#
|
||||
|
||||
CHECK_IDLE_FILE="/usr/share/bbfdm/bbf_check_idle.sh"
|
||||
ROOT="$(dirname $0)"
|
||||
|
||||
CHECK_IDLE_FILE="${ROOT}/bbf_check_idle.sh"
|
||||
RETRY_TIME=300
|
||||
START_TIME=$(date +%s)
|
||||
MODE="${1}"
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ UCI_GET_BBF_DMMAP="uci -q -c /etc/bbfdm/dmmap get"
|
|||
UCI_SET_BBF_DMMAP="uci -q -c /etc/bbfdm/dmmap set"
|
||||
UCI_ADD_BBF_DMMAP="uci -q -c /etc/bbfdm/dmmap add"
|
||||
UCI_DELETE_BBF_DMMAP="uci -q -c /etc/bbfdm/dmmap delete"
|
||||
UCI_RENAME_BBF_DMMAP="uci -q -c /etc/bbfdm/dmmap rename"
|
||||
UCI_COMMIT_BBF_DMMAP="uci -q -c /etc/bbfdm/dmmap commit"
|
||||
UCI_SHOW_BBF_DMMAP="uci -q -c /etc/bbfdm/dmmap show"
|
||||
|
||||
|
|
|
|||
190
scripts/download
Executable file
190
scripts/download
Executable file
|
|
@ -0,0 +1,190 @@
|
|||
#!/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
|
||||
|
||||
CAPTURE_FILE="/tmp/download_dump"
|
||||
|
||||
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
|
||||
|
||||
logger -t "usp" "download" "url=${url} && iface=${iface} && dscp=${dscp} && eth_prio=${eth_prio} && ip_proto=${ip_proto} && num_of_con=${num_of_con} && enable_per_con=${enable_per_con} && proto=${proto}"
|
||||
|
||||
# Check if a download process is already running
|
||||
download_s=$(uci_get_bbf_dmmap dmmap_diagnostics.download)
|
||||
logger -t "usp" "download" "download_s=$download_s"
|
||||
if [ -z "${download_s}" ]; then
|
||||
logger -t "usp" "download" "Create a download diagnostics section"
|
||||
[ ! -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
|
||||
logger -t "usp" "download" "there is a download diagnostics section"
|
||||
Status=$(uci_get_bbf_dmmap dmmap_diagnostics.download.Status)
|
||||
logger -t "usp" "download" "Status=$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 @.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
|
||||
}
|
||||
|
||||
# Disable acceleration on Broadcom devices to capture all packets with tcpdump
|
||||
[ -e /usr/sbin/fcctl ] && { fcctl disable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; }
|
||||
|
||||
FREE_SIZE=`free | grep Mem | awk '{print $4}'`
|
||||
FREE_SIZE_BYTE=$((${FREE_SIZE}/1000))
|
||||
|
||||
logger -t "usp" "download" "tcpdump -i $device -C ${FREE_SIZE_BYTE} tcp -w ${CAPTURE_FILE}"
|
||||
tcpdump -i "$device" -C ${FREE_SIZE_BYTE} tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 &
|
||||
PID=$!
|
||||
sleep 1
|
||||
|
||||
if [ ${url:0:7} = http:// -o ${url:0:6} = ftp:// ]; then
|
||||
|
||||
tx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
|
||||
time1=$(date +%s)
|
||||
logger -t "usp" "download" "curl $ip_proto --fail --silent -o /dev/null $url"
|
||||
curl $ip_proto --fail --silent -o /dev/null "$url"
|
||||
error_code="$?"
|
||||
time2=$(date +%s)
|
||||
logger -t "usp" "download" "error_code=$error_code"
|
||||
|
||||
tx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
|
||||
[ "$error_code" = "6" ] && {
|
||||
download_error "Error_CannotResolveHostName" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" = "7" ] && {
|
||||
download_error "Error_InitConnectionFailed" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" = "22" ] && {
|
||||
download_error "Error_NoResponse" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" = "27" ] && {
|
||||
download_error "Error_IncorrectSize" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" = "28" ] && {
|
||||
download_error "Error_Timeout" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" != "0" ] && {
|
||||
download_error "Error_Other" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
fi
|
||||
|
||||
tx_bytes=$((tx_bytes_after-tx_bytes_before))
|
||||
rx_bytes=$((rx_bytes_after-rx_bytes_before))
|
||||
periodtime=$(($((time2-time1))*1000000))
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "Complete"
|
||||
json_add_string "IPAddressUsed" "${ip_addr_used}"
|
||||
json_add_int "TotalBytesReceived" "${rx_bytes}"
|
||||
json_add_int "TotalBytesSent" "${tx_bytes}"
|
||||
json_add_int "PeriodOfFullLoading" "${periodtime}"
|
||||
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
|
||||
json_add_array "DownloadPerConnection"
|
||||
json_add_object ""
|
||||
json_add_int "TotalBytesReceived" "${rx_bytes}"
|
||||
json_add_int "TotalBytesSent" "${tx_bytes}"
|
||||
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.TotalBytesReceived="${rx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesSent="${tx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.PeriodOfFullLoading="${periodtime}"
|
||||
perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.download.EnablePerConnection)
|
||||
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].TotalBytesReceived="${rx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesSent="${tx_bytes}"
|
||||
else
|
||||
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0]
|
||||
fi
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
sleep 1
|
||||
kill $PID >/dev/null 2>&1
|
||||
|
||||
# Enable acceleration on Broadcom devices after killing the tcpdump pid
|
||||
[ -e /usr/sbin/fcctl ] && { fcctl enable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; }
|
||||
|
||||
$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,94 +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/bbfdm/bbf_api
|
||||
|
||||
CAPTURE_FILE="/tmp/download_dump"
|
||||
|
||||
download_launch() {
|
||||
url=$1
|
||||
device=$2
|
||||
|
||||
[ "$url" = "" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; return; }
|
||||
interface=$(uci_get_bbf_dmmap dmmap_diagnostics.download.interface)
|
||||
protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.download.ProtocolVersion Any)
|
||||
if [ "$protocol" = "IPv4" ]; then proto="--ipv4"; elif [ "$protocol" = "IPv6" ]; then proto="--ipv6"; else proto=""; fi
|
||||
ip_addr_used=$(get_ip_addr_used $protocol $interface)
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.IPAddressUsed="$ip_addr_used"
|
||||
# Disable acceleration on Broadcom devices to capture all packets with tcpdump
|
||||
[ -e /usr/sbin/fcctl ] && { fcctl disable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; }
|
||||
|
||||
FREE_SIZE=`free | grep Mem | awk '{print $4}'`
|
||||
FREE_SIZE_BYTE=$((${FREE_SIZE}/1000))
|
||||
|
||||
tcpdump -i "$device" -C ${FREE_SIZE_BYTE} tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 &
|
||||
PID=$!
|
||||
sleep 1
|
||||
if [ ${url:0:7} = http:// -o ${url:0:6} = ftp:// ]; then
|
||||
|
||||
tx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
time1=$(date +%s)
|
||||
curl $proto --fail --silent -o /dev/null "$url"
|
||||
error_code="$?"
|
||||
time2=$(date +%s)
|
||||
tx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
[ "$error_code" = "6" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" = "7" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" = "22" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_NoResponse; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" = "27" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_IncorrectSize; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" = "28" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_Timeout; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" != "0" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
fi
|
||||
tx_bytes=$((tx_bytes_after-tx_bytes_before))
|
||||
rx_bytes=$((rx_bytes_after-rx_bytes_before))
|
||||
periodtime=$(($((time2-time1))*1000000))
|
||||
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Complete
|
||||
$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=$periodtime
|
||||
perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.download.EnablePerConnection)
|
||||
if [ "$perconnection" = "true" ] || [ "$perconnection" = "1" ]; then
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics DownloadPerConnection
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesReceived=$rx_bytes
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesSent=$tx_bytes
|
||||
else
|
||||
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0]
|
||||
fi
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
sleep 1
|
||||
kill $PID >/dev/null 2>&1
|
||||
# Enable acceleration on Broadcom devices after killing the tcpdump pid
|
||||
[ -e /usr/sbin/fcctl ] && { fcctl enable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; }
|
||||
}
|
||||
|
||||
download_stop_diagnostic() {
|
||||
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0]
|
||||
pids=$(pgrep -f download_launch.*run)
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 "$pids" >/dev/null 2>&1
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=None
|
||||
fi
|
||||
pids=$(pgrep -f download_launch.*run)
|
||||
if [ -n "$pids" ]; then
|
||||
kids=$(grep -l "PPid.*$pids" /proc/*/task/*/status | grep -o "[0-9]*")
|
||||
for kid in $kids; do
|
||||
kill -9 "$kid" >/dev/null 2>&1
|
||||
done
|
||||
kill -9 "$pids" >/dev/null 2>&1
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=None
|
||||
fi
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
if [ "$1" = "run" ] ; then
|
||||
download_launch "$2" "$3"
|
||||
elif [ "$1" = "stop" ]; then
|
||||
download_stop_diagnostic
|
||||
else
|
||||
return
|
||||
fi
|
||||
169
scripts/ipping
Executable file
169
scripts/ipping
Executable file
|
|
@ -0,0 +1,169 @@
|
|||
#!/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
|
||||
|
||||
ROOT="$(dirname $0)"
|
||||
. ${ROOT}/bbf_api
|
||||
|
||||
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.SuccessCount=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="$cnt"
|
||||
$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
|
||||
|
||||
# Assign default value
|
||||
[ -z "${nbr_of_rep}" ] && nbr_of_rep=3
|
||||
[ -z "${dsize}" ] && dsize=64
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.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 "bad address")
|
||||
[ -n "$ba" ] && {
|
||||
ipping_error "Error_CannotResolveHostName" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
ba=$(echo "$res" | grep "unknown host")
|
||||
[ -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 [ -n "$1" ]; then
|
||||
ipping_launch "$1"
|
||||
else
|
||||
ipping_error "Error_Internal" "1"
|
||||
fi
|
||||
|
|
@ -1,115 +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/bbfdm/bbf_api
|
||||
|
||||
ipping_error()
|
||||
{
|
||||
cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.NumberOfRepetitions 3)
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="$cnt"
|
||||
$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() {
|
||||
host=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.Host)
|
||||
cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.NumberOfRepetitions 3)
|
||||
dsize=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.DataBlockSize 64)
|
||||
timeout=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.Timeout 1000)
|
||||
interface=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.interface)
|
||||
protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.ProtocolVersion Any)
|
||||
[ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-I $device" || device=""
|
||||
if [ "$protocol" = "IPv4" ]; then proto="-4"; elif [ "$protocol" = "IPv6" ]; then proto="-6"; else proto=""; fi
|
||||
ip_addr_used=$(get_ip_addr_used $protocol $interface)
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.IPAddressUsed="$ip_addr_used"
|
||||
[ "$host" = "" ] && return
|
||||
timeout=$((timeout/1000))
|
||||
[ "$timeout" = "0" ] && timeout="1"
|
||||
micros=1000
|
||||
success_count=0
|
||||
avg_time_sum=0
|
||||
avg_time_sum_det=0
|
||||
min=9999999
|
||||
min_det=999999999
|
||||
max=0
|
||||
max_det=0
|
||||
i=0
|
||||
|
||||
while [ $i -lt "$cnt" ]; do
|
||||
i=$((i+1))
|
||||
res=$(ping -q $proto -c 1 -s $dsize -W $timeout $device $host 2>&1)
|
||||
ba=$(echo "$res" | grep "bad address")
|
||||
[ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState=Error_CannotResolveHostName; ipping_error; return; }
|
||||
ba=$(echo "$res" | grep "unknown host")
|
||||
[ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState=Error_CannotResolveHostName; ipping_error; return; }
|
||||
stc=$(echo "$res" | grep "received")
|
||||
[ -z "$stc" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState=Error_Other; ipping_error; 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=$((cnt-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
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="Complete"
|
||||
$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.AverageResponseTime="$avg_time"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime="$min_time"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime="$max_time"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTimeDetailed="$avg_time_det"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTimeDetailed="$min_time_det"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTimeDetailed="$max_time_det"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
ipping_stop_diagnostic() {
|
||||
pids=$(pgrep -f ipping_launch)
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 "$pids" >/dev/null 2>&1
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState=None
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" = "run" ]; then
|
||||
ipping_launch
|
||||
elif [ "$1" = "stop" ]; then
|
||||
ipping_stop_diagnostic
|
||||
else
|
||||
return
|
||||
fi
|
||||
162
scripts/nslookup
Executable file
162
scripts/nslookup
Executable file
|
|
@ -0,0 +1,162 @@
|
|||
#!/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_nslookup_log_file() {
|
||||
IDX=1
|
||||
LOG_FILE="/tmp/nslookup_$IDX.log"
|
||||
|
||||
while [ -e ${LOG_FILE} ]; do
|
||||
IDX=$((IDX+1))
|
||||
LOG_FILE="/tmp/nslookup_$IDX.log";
|
||||
done
|
||||
|
||||
echo ${LOG_FILE}
|
||||
}
|
||||
|
||||
nslookup_error() {
|
||||
json_init
|
||||
json_add_string "Status" "$1"
|
||||
json_add_int "SuccessCount" "0"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$3" == "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.DiagnosticState="$1"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.SuccessCount=0
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
nslookup_launch() {
|
||||
input="$1"
|
||||
|
||||
json_load "${input}"
|
||||
|
||||
json_get_var hostname host
|
||||
json_get_var dnsserver dns_serevr
|
||||
json_get_var iface iface
|
||||
json_get_var cnt nbr_of_rep
|
||||
json_get_var proto proto
|
||||
|
||||
LOG_FILE=$(get_nslookup_log_file)
|
||||
|
||||
# Assign default value
|
||||
[ -z "${cnt}" ] && cnt=1
|
||||
|
||||
# Fail if hostname is empty
|
||||
[ -z "${hostname}" ] && {
|
||||
nslookup_error "Error_Internal" "${cnt}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
i=0
|
||||
|
||||
while [ $i -lt "${cnt}" ]; do
|
||||
i=$((i+1))
|
||||
|
||||
nslookup -debug $hostname $dnsserver >>${LOG_FILE} 2>&1
|
||||
error_code="$?"
|
||||
|
||||
nxd=$(cat ${LOG_FILE} | grep "NXDOMAIN")
|
||||
[ -n "$nxd" ] && {
|
||||
nslookup_error "Error_DNSServerNotResolved" "${cnt}" "${proto}"
|
||||
return;
|
||||
}
|
||||
|
||||
[ "$error_code" != "0" ] && {
|
||||
nslookup_error "Error_Other" "${cnt}" "${proto}"
|
||||
return;
|
||||
}
|
||||
|
||||
echo "++++++++++++++++++++++++++++++" >>${LOG_FILE}
|
||||
done
|
||||
|
||||
AnswerType="Authoritative"
|
||||
success_count=0
|
||||
address=""
|
||||
j=0
|
||||
json_init
|
||||
json_add_array "NSLookupResult"
|
||||
|
||||
while IFS= read line; do
|
||||
[ -z "$line" ] && continue;
|
||||
server=$(echo "$line" | tr -d '\t' | tr -d ' ' | grep "Server:" | awk -F':' '{print $2}')
|
||||
|
||||
if [ -n "$server" ] && [ "$server" = "0.0.0.0" ]; then
|
||||
status="Error_DNSServerNotAvailable"
|
||||
continue
|
||||
elif [ -n "$server" ]; then
|
||||
dns_server_ip=$server
|
||||
continue
|
||||
fi
|
||||
|
||||
var=$(echo "$line" | tr -d '\t' | tr -d ' ' | grep "Name:" | awk -F':' '{print $2}')
|
||||
[ -n "$var" ] && { HostNameReturned=$var; status="Success"; success_count=$((success_count+1)); continue; }
|
||||
|
||||
var=$(echo "$line" | tr -d '\t' | tr -d ' ' | grep "name=" | awk -F'=' '{print $2}')
|
||||
[ -n "$var" ] && { HostNameReturned=$var; status="Success"; address="$hostname"; success_count=$((success_count+1)); continue; }
|
||||
|
||||
var=$(echo "$line" | grep "Address: " | awk -F':' '{print substr($0, index($0,$2))}' | tr -d '\t' | tr -d ' ')
|
||||
[ -n "$var" ] && { [ -z "$address" ] && address="$var" || address="$address,$var"; continue; }
|
||||
|
||||
var=$(echo "$line" | grep "completed" | awk -F'in' '{print $2}' | tr -d 'ms:\t ')
|
||||
[ -n "$var" ] && { ResponseTime=$var; continue; }
|
||||
|
||||
echo "$line" | grep 'connection timed out' >/dev/null 2>&1 && { AnswerType="None"; status="Error_Timeout"; continue; }
|
||||
echo "$line" | grep 'Non-authoritative' >/dev/null 2>&1 && { AnswerType="NonAuthoritative"; continue; }
|
||||
|
||||
if echo "$line" | grep '++++++++++++++++++++++' >/dev/null 2>&1; then
|
||||
|
||||
json_add_object ""
|
||||
json_add_string "Status" "${status}"
|
||||
json_add_string "AnswerType" "${AnswerType}"
|
||||
json_add_string "HostNameReturned" "${HostNameReturned}"
|
||||
json_add_string "IPAddresses" "${address}"
|
||||
json_add_string "DNSServerIP" "${dns_server_ip}"
|
||||
json_add_string "ResponseTime" "${ResponseTime}"
|
||||
json_close_object
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$proto" == "both_proto" ] && {
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics NSLookupResult
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].Status="${status}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].AnswerType="${AnswerType}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].HostNameReturned="${HostNameReturned}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].IPAddresses="${address}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].DNSServerIP="${dns_server_ip}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].ResponseTime="${ResponseTime}"
|
||||
j=$((j+1))
|
||||
}
|
||||
|
||||
address=""
|
||||
AnswerType="Authoritative"
|
||||
fi
|
||||
|
||||
done <${LOG_FILE}
|
||||
rm -f ${LOG_FILE}
|
||||
|
||||
json_close_array
|
||||
json_add_string "Status" "Complete"
|
||||
json_add_int "SuccessCount" "${success_count}"
|
||||
json_dump
|
||||
|
||||
# Store data in dmmap_diagnostics for both protocols (cwmp/usp)
|
||||
[ "$proto" == "both_proto" ] && {
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.DiagnosticState="Complete"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.SuccessCount="${success_count}"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
nslookup_launch "$1"
|
||||
else
|
||||
nslookup_error "Error_Internal" "1"
|
||||
fi
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/bbfdm/bbf_api
|
||||
|
||||
LOG_FILE="/tmp/nslookup.log"
|
||||
|
||||
nslookup_launch() {
|
||||
address=""
|
||||
hostname=$(uci_get_bbf_dmmap dmmap_diagnostics.nslookup.HostName)
|
||||
dnsserver=$(uci_get_bbf_dmmap dmmap_diagnostics.nslookup.DNSServer)
|
||||
cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.nslookup.NumberOfRepetitions 1)
|
||||
[ "$hostname" = "" ] && return
|
||||
i=0
|
||||
j=0
|
||||
success_count=0
|
||||
[ -e "${LOG_FILE}" ] && rm ${LOG_FILE}
|
||||
while [ $i -lt "$cnt" ]; do
|
||||
i=$((i+1))
|
||||
nslookup -debug $hostname $dnsserver >>${LOG_FILE} 2>&1
|
||||
error_code="$?"
|
||||
nxd=$(cat ${LOG_FILE} | grep "NXDOMAIN")
|
||||
[ -n "$nxd" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.DiagnosticState=Error_DNSServerNotResolved; $UCI_COMMIT_BBF_DMMAP; return; }
|
||||
[ "$error_code" != "0" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; return; }
|
||||
echo "++++++++++++++++++++++++++++++" >>${LOG_FILE}
|
||||
done
|
||||
|
||||
AnswerType="Authoritative"
|
||||
while IFS= read line; do
|
||||
[ -z "$line" ] && continue;
|
||||
server=$(echo "$line" | tr -d '\t' | tr -d ' ' | grep "Server:" | awk -F':' '{print $2}')
|
||||
|
||||
if [ -n "$server" ] && [ "$server" = "0.0.0.0" ]; then
|
||||
status="Error_DNSServerNotAvailable"
|
||||
continue
|
||||
elif [ -n "$server" ]; then
|
||||
dns_server_ip=$server
|
||||
continue
|
||||
fi
|
||||
|
||||
var=$(echo "$line" | tr -d '\t' | tr -d ' ' | grep "Name:" | awk -F':' '{print $2}')
|
||||
[ -n "$var" ] && { HostNameReturned=$var; status="Success"; success_count=$((success_count+1)); continue; }
|
||||
|
||||
var=$(echo "$line" | tr -d '\t' | tr -d ' ' | grep "name=" | awk -F'=' '{print $2}')
|
||||
[ -n "$var" ] && { HostNameReturned=$var; status="Success"; address="$hostname"; success_count=$((success_count+1)); continue; }
|
||||
|
||||
var=$(echo "$line" | grep "Address: " | awk -F':' '{print substr($0, index($0,$2))}' | tr -d '\t' | tr -d ' ')
|
||||
[ -n "$var" ] && { [ -z "$address" ] && address="$var" || address="$address,$var"; continue; }
|
||||
|
||||
var=$(echo "$line" | grep "completed" | awk -F'in' '{print $2}' | tr -d 'ms:\t ')
|
||||
[ -n "$var" ] && { ResponseTime=$var; continue; }
|
||||
|
||||
echo "$line" | grep 'connection timed out' >/dev/null 2>&1 && { AnswerType="None"; status="Error_Timeout"; continue; }
|
||||
echo "$line" | grep 'Non-authoritative' >/dev/null 2>&1 && { AnswerType="NonAuthoritative"; continue; }
|
||||
|
||||
if echo "$line" | grep '++++++++++++++++++++++' >/dev/null 2>&1; then
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics NSLookupResult
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].Status="$status"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].AnswerType="$AnswerType"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].HostNameReturned="$HostNameReturned"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].IPAddresses="$address"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].DNSServerIP="$dns_server_ip"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].ResponseTime="$ResponseTime"
|
||||
j=$((j+1))
|
||||
address=""
|
||||
AnswerType="Authoritative"
|
||||
fi
|
||||
done <${LOG_FILE}
|
||||
rm -f ${LOG_FILE}
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.SuccessCount=$success_count
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.DiagnosticState=Complete
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
nslookup_stop_diagnostic() {
|
||||
pids=$(pgrep -f nslookup_launch)
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 "$pids" >/dev/null 2>&1
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.DiagnosticState=None
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" = "run" ]; then
|
||||
nslookup_launch
|
||||
elif [ "$1" = "stop" ]; then
|
||||
nslookup_stop_diagnostic
|
||||
else
|
||||
return
|
||||
fi
|
||||
190
scripts/serverselection
Executable file
190
scripts/serverselection
Executable file
|
|
@ -0,0 +1,190 @@
|
|||
#!/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
|
||||
|
||||
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_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
|
||||
|
||||
# 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}")
|
||||
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 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
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.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
|
||||
[[ "$host" == *"."* ]] && ip_proto="4" || ip_proto="6"
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.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" --protocol "$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 [ -n "$1" ]; then
|
||||
serverselection_launch "$1"
|
||||
else
|
||||
serverselection_error "Error_Internal" "1"
|
||||
fi
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/bbfdm/bbf_api
|
||||
|
||||
serverselection_launch() {
|
||||
hostlist=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.HostList)
|
||||
cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.NumberOfRepetitions 3)
|
||||
timeout=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.Timeout 1000)
|
||||
port=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.port 7)
|
||||
interface=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.interface)
|
||||
protoversion=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.ProtocolVersion Any)
|
||||
protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.Protocol ICMP)
|
||||
if [ "$protoversion" = "IPv4" ]; then proto="-4"; elif [ "$protoversion" = "IPv6" ]; then proto="-6"; else proto=""; fi
|
||||
ip_addr_used=$(get_ip_addr_used $protoversion $interface)
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.IPAddressUsed="$ip_addr_used"
|
||||
[ "$hostlist" = "" ] && return
|
||||
timeout=$((timeout/1000))
|
||||
[ "$timeout" = "0" ] && timeout="1"
|
||||
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" = "ICMP" ]; then
|
||||
[ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-I $device" || device=""
|
||||
while [ $i -lt "$cnt" ]; do
|
||||
i=$((i+1))
|
||||
res=$(ping -q $proto -c 1 -W $timeout $device $host 2>&1)
|
||||
ba=$(echo "$res" | grep "bad address")
|
||||
[ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; return; }
|
||||
ba=$(echo "$res" | grep "unknown host")
|
||||
[ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; return; }
|
||||
stc=$(echo "$res" | grep "received")
|
||||
[ -z "$stc" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; 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
|
||||
[[ "$host" == *"."* ]] && proto="4" || proto="6"
|
||||
[ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-i $device" || device=""
|
||||
while [ $i -lt "$cnt" ]; do
|
||||
i=$((i+1))
|
||||
res=$(udpechoclientd -c 1 -t $timeout --host "$host" --port "$port" --protocol "$proto" $device 2>&1)
|
||||
ba=$(echo "$res" | grep "Can't Resolve Host Name")
|
||||
[ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; return; }
|
||||
ba=$(echo "$res" | grep "RCVD")
|
||||
[ -z "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; 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
|
||||
$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.AverageResponseTime="$avg_time_host"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MinimumResponseTime="$min_time_host"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MaximumResponseTime="$max_time_host"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
serverselection_stop_diagnostic() {
|
||||
pids=$(pgrep -f serverselection_launch)
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 "$pids" >/dev/null 2>&1
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=None
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" = "run" ]; then
|
||||
serverselection_launch
|
||||
elif [ "$1" = "stop" ]; then
|
||||
serverselection_stop_diagnostic
|
||||
else
|
||||
return
|
||||
fi
|
||||
137
scripts/traceroute
Executable file
137
scripts/traceroute
Executable file
|
|
@ -0,0 +1,137 @@
|
|||
#!/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" ""
|
||||
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=""
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime=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
|
||||
|
||||
LOG_FILE=$(get_traceroute_log_file)
|
||||
|
||||
# Assign default value
|
||||
[ -z "${cnt}" ] && cnt=1
|
||||
[ -z "${dsize}" ] && dsize=64
|
||||
[ -z "${maxhop}" ] && maxhop=30
|
||||
[ -n "${iface}" ] && device=$(ifstatus "${iface}" | jsonfilter -e @.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))
|
||||
|
||||
# Fail if host is empty
|
||||
[ -z "${host}" ] && {
|
||||
traceroute_error "Error_Internal" "${nbr_of_rep}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
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" "${cnt}" "${proto}"
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" != "0" ] && {
|
||||
traceroute_error "Error_Other" "${cnt}" "${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_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 "NumberOfHops" "${i}"
|
||||
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.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" "1"
|
||||
fi
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/bbfdm/bbf_api
|
||||
|
||||
traceroute_launch() {
|
||||
host=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.Host)
|
||||
cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.NumberOfTries 3)
|
||||
dsize=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.DataBlockSize 64)
|
||||
timeout=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.Timeout 5000)
|
||||
maxhop=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.MaxHops 30)
|
||||
interface=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.interface)
|
||||
protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.ProtocolVersion Any)
|
||||
[ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-i $device" || device=""
|
||||
if [ "$protocol" = "IPv4" ]; then proto="-4"; elif [ "$protocol" = "IPv6" ]; then proto="-6"; else proto=""; fi
|
||||
ip_addr_used=$(get_ip_addr_used $protocol $interface)
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.IPAddressUsed="$ip_addr_used"
|
||||
[ "$host" = "" ] && return
|
||||
timeout=$((timeout/1000))
|
||||
[ "$timeout" = "0" ] && timeout="1"
|
||||
i=-2
|
||||
rm -f /tmp/traceres
|
||||
res=$(traceroute -m $maxhop -w $timeout -q $cnt $proto $device $host $dsize 2>&1 >/tmp/traceres)
|
||||
error_code="$?"
|
||||
ba=$(echo "$res" | grep "bad address")
|
||||
[ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; return; }
|
||||
[ "$error_code" != "0" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; return; }
|
||||
while read _ host ip time _; do
|
||||
[ "$host" = "*" ] && [ "$ip" = "*" ] && continue
|
||||
i=$((i+1))
|
||||
[ "$i" = "-1" ] && continue;
|
||||
ip=${ip#(}; ip=${ip%)}
|
||||
time=${time%.*}
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics RouteHops
|
||||
$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 < /tmp/traceres
|
||||
rm -f /tmp/traceres
|
||||
i=$((i+1))
|
||||
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState=Complete
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.NumberOfHops=$i
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime="$($UCI_GET_BBF_DMMAP dmmap_diagnostics.@RouteHops[-1].time)"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
traceroute_stop() {
|
||||
pids=$(pgrep -f traceroute_launch)
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 "$pids" >/dev/null 2>&1
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState=None
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" = "run" ]; then
|
||||
traceroute_launch
|
||||
elif [ "$1" = "stop" ]; then
|
||||
traceroute_stop
|
||||
else
|
||||
return
|
||||
fi
|
||||
148
scripts/udpecho
Executable file
148
scripts/udpecho
Executable file
|
|
@ -0,0 +1,148 @@
|
|||
#!/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
|
||||
|
||||
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
|
||||
|
||||
# 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 @.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="4"; 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
|
||||
}
|
||||
|
||||
[[ "$host" == *"."* ]] && ip_proto="4" || ip_proto="6"
|
||||
|
||||
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" --protocol "$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 [ -n "$1" ]; then
|
||||
udpecho_launch "$1"
|
||||
else
|
||||
udpecho_error "Error_Internal" "1"
|
||||
fi
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2022 iopsys Software Solutions AB
|
||||
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
||||
|
||||
. /usr/share/bbfdm/bbf_api
|
||||
|
||||
udpecho_error()
|
||||
{
|
||||
cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.NumberOfRepetitions 1)
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.SuccessCount=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.FailureCount="$cnt"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.AverageResponseTime=0
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime=9999
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime=0
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
udpecho_launch() {
|
||||
host=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.Host)
|
||||
port=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.port 7)
|
||||
timeout=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.Timeout 1000)
|
||||
cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.NumberOfRepetitions 1)
|
||||
dsize=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.DataBlockSize 24)
|
||||
dscp=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.DSCP 0)
|
||||
interface=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.interface)
|
||||
protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.ProtocolVersion Any)
|
||||
inter_time=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.InterTransmissionTime 1000)
|
||||
[ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-i $device" || device=""
|
||||
if [ "$protocol" = "IPv4" ]; then proto="4"; elif [ "$protocol" = "IPv6" ]; then proto="6"; else proto="4"; fi
|
||||
ip_addr_used=$(get_ip_addr_used $protocol $interface)
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.IPAddressUsed="$ip_addr_used"
|
||||
tos=$((dscp<<2))
|
||||
inter_time=$((inter_time/1000))
|
||||
[ "$inter_time" = "0" ] && inter_time="1"
|
||||
timeout=$((timeout/1000))
|
||||
[ "$timeout" = "0" ] && timeout="1"
|
||||
[ "$host" = "" ] && return
|
||||
[[ "$host" == *"."* ]] && proto="4" || proto="6"
|
||||
micros=1000
|
||||
success_count=0
|
||||
avg_time_sum=0
|
||||
min=9999999
|
||||
max=0
|
||||
i=0
|
||||
|
||||
while [ $i -lt "$cnt" ]; do
|
||||
i=$((i+1))
|
||||
res=$(udpechoclientd -c 1 -t $timeout --host "$host" --data-length "$dsize" --port "$port" --protocol "$proto" $device 2>&1)
|
||||
ba=$(echo "$res" | grep "Can't Resolve Host Name")
|
||||
[ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState=Error_CannotResolveHostName; udpecho_error; return; }
|
||||
ba=$(echo "$res" | grep "RCVD")
|
||||
[[ -z "$ba" && $((cnt-i)) == 0 ]] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState=Complete; udpecho_error; 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=$((cnt-success_count))
|
||||
[ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0
|
||||
min_time=$min
|
||||
max_time=$max
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState=Complete
|
||||
$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.AverageResponseTime="$avg_time"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime="$min_time"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime="$max_time"
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
udpecho_stop_diagnostic() {
|
||||
pids=$(pgrep -f udpecho_launch)
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 "$pids" >/dev/null 2>&1
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState=None
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" = "run" ]; then
|
||||
udpecho_launch
|
||||
elif [ "$1" = "stop" ]; then
|
||||
udpecho_stop_diagnostic
|
||||
else
|
||||
return
|
||||
fi
|
||||
185
scripts/upload
Executable file
185
scripts/upload
Executable file
|
|
@ -0,0 +1,185 @@
|
|||
#!/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
|
||||
|
||||
CAPTURE_FILE="/tmp/upload_dump"
|
||||
|
||||
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 @.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
|
||||
}
|
||||
|
||||
# Disable acceleration on Broadcom devices to capture all packets with tcpdump
|
||||
[ -e /usr/sbin/fcctl ] && { fcctl disable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; }
|
||||
|
||||
FREE_SIZE=`free | grep Mem | awk '{print $4}'`
|
||||
FREE_SIZE_BYTE=$((${FREE_SIZE}/1000))
|
||||
|
||||
tcpdump -i "$device" -C ${FREE_SIZE_BYTE} tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 &
|
||||
PID=$!
|
||||
sleep 1
|
||||
|
||||
if [ ${url:0:7} = http:// -o ${url:0:6} = ftp:// ]; then
|
||||
|
||||
tx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
|
||||
time1=$(date +%s)
|
||||
dd if=/dev/zero bs="$file_length" count=1 2>/dev/null | curl $ip_proto --fail --silent -T - "$url"
|
||||
error_code="$?"
|
||||
time2=$(date +%s)
|
||||
|
||||
tx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
|
||||
[ "$error_code" = "6" ] && {
|
||||
upload_error "Error_CannotResolveHostName" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" = "7" ] && {
|
||||
upload_error "Error_InitConnectionFailed" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" = "22" ] && {
|
||||
upload_error "Error_NoResponse" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" = "27" ] && {
|
||||
upload_error "Error_IncorrectSize" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" = "28" ] && {
|
||||
upload_error "Error_Timeout" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
|
||||
[ "$error_code" != "0" ] && {
|
||||
upload_error "Error_Other" "${proto}"
|
||||
kill $PID 2> /dev/null
|
||||
return
|
||||
}
|
||||
fi
|
||||
|
||||
tx_bytes=$((tx_bytes_after-tx_bytes_before))
|
||||
rx_bytes=$((rx_bytes_after-rx_bytes_before))
|
||||
periodtime=$(($((time2-time1))*1000000))
|
||||
|
||||
json_init
|
||||
json_add_string "Status" "Complete"
|
||||
json_add_string "IPAddressUsed" "${ip_addr_used}"
|
||||
json_add_string "TestBytesSent" "${file_length}"
|
||||
json_add_int "TotalBytesReceived" "${rx_bytes}"
|
||||
json_add_int "TotalBytesSent" "${tx_bytes}"
|
||||
json_add_int "PeriodOfFullLoading" "${periodtime}"
|
||||
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
|
||||
json_add_array "UploadPerConnection"
|
||||
json_add_object ""
|
||||
json_add_int "TestBytesSent" "${file_length}"
|
||||
json_add_int "TotalBytesReceived" "${rx_bytes}"
|
||||
json_add_int "TotalBytesSent" "${tx_bytes}"
|
||||
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.TestBytesSent="${file_length}"
|
||||
$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="${periodtime}"
|
||||
perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.upload.EnablePerConnection)
|
||||
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].TestBytesSent="${file_length}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesReceived="${rx_bytes}"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesSent="${tx_bytes}"
|
||||
else
|
||||
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0]
|
||||
fi
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
sleep 3
|
||||
kill $PID >/dev/null 2>&1
|
||||
|
||||
# Enable acceleration on Broadcom devices after killing the tcpdump pid
|
||||
[ -e /usr/sbin/fcctl ] && { fcctl enable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; }
|
||||
|
||||
$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
|
||||
|
|
@ -1,97 +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/bbfdm/bbf_api
|
||||
|
||||
CAPTURE_FILE="/tmp/upload_dump"
|
||||
|
||||
upload_launch() {
|
||||
url=$1
|
||||
device=$2
|
||||
size=$3
|
||||
|
||||
[ "$url" = "" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; return; }
|
||||
interface=$(uci_get_bbf_dmmap dmmap_diagnostics.upload.interface)
|
||||
protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.upload.ProtocolVersion Any)
|
||||
if [ "$protocol" = "IPv4" ]; then proto="--ipv4"; elif [ "$protocol" = "IPv6" ]; then proto="--ipv6"; else proto=""; fi
|
||||
ip_addr_used=$(get_ip_addr_used $protocol $interface)
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.IPAddressUsed="$ip_addr_used"
|
||||
# Disable acceleration on Broadcom devices to capture all packets with tcpdump
|
||||
[ -e /usr/sbin/fcctl ] && { fcctl disable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; }
|
||||
|
||||
FREE_SIZE=`free | grep Mem | awk '{print $4}'`
|
||||
FREE_SIZE_BYTE=$((${FREE_SIZE}/1000))
|
||||
|
||||
tcpdump -i "$device" -C ${FREE_SIZE_BYTE} tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 &
|
||||
PID=$!
|
||||
sleep 1
|
||||
if [ ${url:0:7} = http:// -o ${url:0:6} = ftp:// ]; then
|
||||
tx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
time1=$(date +%s)
|
||||
dd if=/dev/zero bs="$size" count=1 2>/dev/null | curl $proto --fail --silent -T - "$url"
|
||||
error_code="$?"
|
||||
time2=$(date +%s)
|
||||
tx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
|
||||
rx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
|
||||
|
||||
[ "$error_code" = "6" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" = "7" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" = "22" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_NoResponse; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" = "27" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_IncorrectSize; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" = "28" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_Timeout; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
[ "$error_code" != "0" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; }
|
||||
fi
|
||||
tx_bytes=$((tx_bytes_after-tx_bytes_before))
|
||||
rx_bytes=$((rx_bytes_after-rx_bytes_before))
|
||||
periodtime=$(($((time2-time1))*1000000))
|
||||
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Complete
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TestBytesSent="$size"
|
||||
$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="$periodtime"
|
||||
perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.upload.EnablePerConnection)
|
||||
if [ "$perconnection" = "true" ] || [ "$perconnection" = "1" ]; then
|
||||
$UCI_ADD_BBF_DMMAP dmmap_diagnostics UploadPerConnection
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TestBytesSent="$size"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesReceived="$rx_bytes"
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesSent="$tx_bytes"
|
||||
else
|
||||
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0]
|
||||
fi
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
sleep 3
|
||||
kill $PID >/dev/null 2>&1
|
||||
# Enable acceleration on Broadcom devices after killing the tcpdump pid
|
||||
[ -e /usr/sbin/fcctl ] && { fcctl enable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; }
|
||||
}
|
||||
|
||||
upload_stop_diagnostic() {
|
||||
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0]
|
||||
pids=$(pgrep -f upload_launch.*run)
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 "$pids" >/dev/null 2>&1
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=None
|
||||
fi
|
||||
pids=$(pgrep -f upload_launch.*run)
|
||||
if [ -n "$pids" ]; then
|
||||
kids=$(grep -l "PPid.*$pids" /proc/*/task/*/status | grep -o "[0-9]*")
|
||||
for kid in $kids; do
|
||||
kill -9 "$kid" >/dev/null 2>&1
|
||||
done
|
||||
kill -9 "$pids" >/dev/null 2>&1
|
||||
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=None
|
||||
fi
|
||||
$UCI_COMMIT_BBF_DMMAP
|
||||
}
|
||||
|
||||
if [ "$1" = "run" ] ; then
|
||||
upload_launch "$2" "$3" "$4"
|
||||
elif [ "$1" = "stop" ]; then
|
||||
upload_stop_diagnostic
|
||||
else
|
||||
return
|
||||
fi
|
||||
Loading…
Add table
Reference in a new issue