Download && Upload diagnostics: use curl insted of tcpdump to extract data value

This commit is contained in:
Amin Ben Ramdhane 2022-10-17 17:33:19 +00:00
parent 9a3f9c0327
commit 074de2a2ca
10 changed files with 337 additions and 632 deletions

View file

@ -97,7 +97,7 @@ ADD_LIBRARY(bbfdm SHARED ${BBF_API_SOURCES} ${BBF_DM_SOURCES}
${BBF_JSON_PLUGIN_SOURCES} ${BBF_JSON_PLUGIN_SOURCES}
${BBF_VENDOR_EXTENSION_SOURCES}) ${BBF_VENDOR_EXTENSION_SOURCES})
TARGET_LINK_LIBRARIES(bbfdm uci ubus ubox json-c blobmsg_json trace dl curl ${SSL_LIBS}) TARGET_LINK_LIBRARIES(bbfdm uci ubus ubox json-c blobmsg_json dl curl ${SSL_LIBS})
INSTALL(TARGETS bbfdm INSTALL(TARGETS bbfdm
LIBRARY DESTINATION usr/lib) LIBRARY DESTINATION usr/lib)

View file

@ -1075,5 +1075,4 @@ To successfully build libbbfdm or libbbf_ubus, the following libraries are neede
| libubus | https://git.openwrt.org/project/ubus.git | LGPL 2.1 | | libubus | https://git.openwrt.org/project/ubus.git | LGPL 2.1 |
| libjson-c | https://s3.amazonaws.com/json-c_releases | MIT | | libjson-c | https://s3.amazonaws.com/json-c_releases | MIT |
| libcurl | https://dl.uxnr.de/mirror/curl | MIT | | libcurl | https://dl.uxnr.de/mirror/curl | MIT |
| libtrace | https://github.com/apietila/libtrace.git | GPLv2 |
| libwolfssl | https://github.com/wolfSSL/wolfssl | GPL-2.0 | | libwolfssl | https://github.com/wolfSSL/wolfssl | GPL-2.0 |

View file

@ -11,7 +11,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <libtrace.h>
#ifdef LOPENSSL #ifdef LOPENSSL
#include <openssl/sha.h> #include <openssl/sha.h>
@ -31,12 +30,8 @@
#include "dmentry.h" #include "dmentry.h"
#include "dmdiagnostics.h" #include "dmdiagnostics.h"
#define READ_BUF_SIZE (1024 * 16) #define READ_BUF_SIZE (1024 * 16)
static int read_next;
struct diagnostic_stats diag_stats = {0};
char *get_diagnostics_option(char *sec_name, char *option) char *get_diagnostics_option(char *sec_name, char *option)
{ {
char *value; char *value;
@ -682,359 +677,3 @@ end:
return res; return res;
} }
static void libtrace_cleanup(libtrace_t *trace, libtrace_packet_t *packet)
{
if (trace)
trace_destroy(trace);
if (packet)
trace_destroy_packet(packet);
}
static void set_stats_value(char *diag_type)
{
char buf[16] = {0};
set_diagnostics_option(diag_type, "ROMtime", ((diag_stats.romtime)[0] != 0) ? diag_stats.romtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option(diag_type, "BOMtime", ((diag_stats.bomtime)[0] != 0) ? diag_stats.bomtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option(diag_type, "EOMtime", ((diag_stats.eomtime)[0] != 0) ? diag_stats.eomtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option(diag_type, "TCPOpenRequestTime", ((diag_stats.tcpopenrequesttime)[0] != 0) ? diag_stats.tcpopenrequesttime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option(diag_type, "TCPOpenResponseTime",((diag_stats.tcpopenresponsetime)[0] != 0) ? diag_stats.tcpopenresponsetime : "0001-01-01T00:00:00.000000Z");
snprintf(buf, sizeof(buf), "%d", diag_stats.test_bytes_received);
set_diagnostics_option(diag_type, "TestBytesReceived", buf);
}
static int get_tcp_flag_from_packet(libtrace_packet_t *packet, libtrace_tcp_t **tcp, char *tcp_flag, char **nexthdr)
{
uint8_t proto;
uint32_t remaining;
*tcp = trace_get_transport(packet, &proto, &remaining);
if (*tcp == NULL)
return -1;
*nexthdr = trace_get_payload_from_tcp(*tcp, &remaining);
if ((*tcp)->ecn_ns) strcat(tcp_flag, "ECN_NS ");
if ((*tcp)->cwr) strcat(tcp_flag, "CWR ");
if ((*tcp)->ece) strcat(tcp_flag, "ECE ");
if ((*tcp)->fin) strcat(tcp_flag, "FIN ");
if ((*tcp)->syn) strcat(tcp_flag, "SYN ");
if ((*tcp)->rst) strcat(tcp_flag, "RST ");
if ((*tcp)->psh) strcat(tcp_flag, "PSH ");
if ((*tcp)->ack) strcat(tcp_flag, "ACK ");
if ((*tcp)->urg) strcat(tcp_flag, "URG ");
return 0;
}
static void http_download_per_packet(libtrace_packet_t *packet)
{
libtrace_tcp_t *tcp = NULL;
char *nexthdr, tcp_flag[16] = {0}, s_now[20] = {0};
struct tm http_download_lt;
if (get_tcp_flag_from_packet(packet, &tcp, tcp_flag, &nexthdr))
return;
struct timeval http_download_ts = trace_get_timeval(packet);
gmtime_r(&(http_download_ts.tv_sec), &http_download_lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &http_download_lt);
if (strcmp(tcp_flag, "SYN ") == 0 && diag_stats.random_seq == 0) {
snprintf(diag_stats.tcpopenrequesttime, sizeof(diag_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && diag_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == diag_stats.random_seq) {
snprintf(diag_stats.tcpopenresponsetime, sizeof(diag_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strncmp(nexthdr, "GET", 3) == 0) {
snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
diag_stats.get_ack = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == diag_stats.get_ack && diag_stats.ack_seq == 0) {
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
char *val = strstr(nexthdr, "Content-Length");
if (val) {
char *pch, *pchr;
diag_stats.test_bytes_received = strlen(nexthdr);
val += strlen("Content-Length: ");
pch = strtok_r(val, " \r\n\t", &pchr);
diag_stats.test_bytes_received += DM_STRTOL(pch);
diag_stats.first_data = 1;
return;
}
}
if ((strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == diag_stats.ack_seq) {
snprintf(diag_stats.eomtime, sizeof(diag_stats.eomtime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
return;
}
}
static void ftp_download_per_packet(libtrace_packet_t *packet)
{
libtrace_tcp_t *tcp = NULL;
char *nexthdr, tcp_flag[16] = {0}, s_now[20] = {0};
struct tm ftp_download_lt;
if (get_tcp_flag_from_packet(packet, &tcp, tcp_flag, &nexthdr))
return;
struct timeval ftp_download_ts = trace_get_timeval(packet);
gmtime_r(&(ftp_download_ts.tv_sec), &ftp_download_lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &ftp_download_lt);
if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_SIZE_RESPONSE) && strncmp(nexthdr, FTP_SIZE_RESPONSE, strlen(FTP_SIZE_RESPONSE)) == 0) {
char *val = strstr(nexthdr,"213");
char *pch, *pchr;
val += strlen("213 ");
pch =strtok_r(val, " \r\n\t", &pchr);
diag_stats.test_bytes_received = DM_STRTOL(pch);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) {
diag_stats.ftp_syn = 1;
return;
}
if (diag_stats.random_seq == 0 && strcmp(tcp_flag, "SYN ") == 0 && diag_stats.ftp_syn == 1) {
snprintf(diag_stats.tcpopenrequesttime, sizeof(diag_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && diag_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == diag_stats.random_seq) {
snprintf(diag_stats.tcpopenresponsetime, sizeof(diag_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_RETR_REQUEST) && strncmp(nexthdr, FTP_RETR_REQUEST, strlen(FTP_RETR_REQUEST)) == 0) {
snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == diag_stats.random_seq && diag_stats.ack_seq == 0) {
diag_stats.ack_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
diag_stats.first_data = 1;
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == diag_stats.ack_seq) {
if (diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
diag_stats.first_data = 1;
}
snprintf(diag_stats.eomtime, sizeof(diag_stats.eomtime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
read_next = 0;
return;
}
}
static void http_upload_per_packet(libtrace_packet_t *packet)
{
libtrace_tcp_t *tcp = NULL;
char *nexthdr, tcp_flag[16] = {0}, s_now[20] = {0};
struct tm http_upload_lt;
if (get_tcp_flag_from_packet(packet, &tcp, tcp_flag, &nexthdr))
return;
struct timeval http_upload_ts = trace_get_timeval(packet);
gmtime_r(&(http_upload_ts.tv_sec), &http_upload_lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &http_upload_lt);
if (strcmp(tcp_flag, "SYN ") == 0 && diag_stats.random_seq == 0) {
snprintf(diag_stats.tcpopenrequesttime, sizeof(diag_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && diag_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == diag_stats.random_seq) {
snprintf(diag_stats.tcpopenresponsetime, sizeof(diag_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strncmp(nexthdr, "PUT", 3) == 0) {
snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
if (strstr(nexthdr, "Expect: 100-continue")) {
diag_stats.tmp = 1;
diag_stats.ack_seq = ntohl(tcp->ack_seq);
} else
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && diag_stats.tmp == 1 && strstr(nexthdr, "100 Continue")) {
diag_stats.tmp = 2;
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && diag_stats.tmp == 2 && ntohl(tcp->seq) == diag_stats.ack_seq) {
diag_stats.tmp = 0;
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.tmp == 0 && diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
diag_stats.first_data = 1;
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.tmp == 0) {
if (diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
diag_stats.first_data = 1;
}
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->seq) == diag_stats.ack_seq && diag_stats.tmp == 0) {
snprintf(diag_stats.eomtime, sizeof(diag_stats.eomtime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
read_next = 0;
return;
}
}
static void ftp_upload_per_packet(libtrace_packet_t *packet)
{
libtrace_tcp_t *tcp = NULL;
char *nexthdr, tcp_flag[16] = {0}, s_now[20] = {0};
struct tm ftp_upload_lt;
if (get_tcp_flag_from_packet(packet, &tcp, tcp_flag, &nexthdr))
return;
if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) {
diag_stats.ftp_syn = 1;
return;
}
struct timeval ftp_upload_ts = trace_get_timeval(packet);
gmtime_r(&(ftp_upload_ts.tv_sec), &ftp_upload_lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &ftp_upload_lt);
if (strcmp(tcp_flag, "SYN ") == 0 && diag_stats.ftp_syn == 1) {
diag_stats.random_seq = ntohl(tcp->seq);
snprintf(diag_stats.tcpopenrequesttime, sizeof(diag_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
return;
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && diag_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == diag_stats.random_seq) {
snprintf(diag_stats.tcpopenresponsetime, sizeof(diag_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_STOR_REQUEST) && strncmp(nexthdr, FTP_STOR_REQUEST, strlen(FTP_STOR_REQUEST)) == 0) {
snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == diag_stats.random_seq && diag_stats.ack_seq == 0) {
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
diag_stats.first_data = 1;
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == diag_stats.ack_seq) {
if (diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
diag_stats.first_data = 1;
}
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && DM_STRLEN(nexthdr) > strlen(FTP_TRANSFERT_COMPLETE) && strncmp(nexthdr, FTP_TRANSFERT_COMPLETE, strlen(FTP_TRANSFERT_COMPLETE)) == 0) {
snprintf(diag_stats.eomtime, sizeof(diag_stats.eomtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
read_next = 0;
return;
}
}
int extract_stats(char *dump_file, int proto, int diagnostic_type)
{
libtrace_t *trace = NULL;
libtrace_packet_t *packet = trace_create_packet();
read_next = 1;
if (packet == NULL) {
libtrace_cleanup(trace, packet);
return -1;
}
trace = trace_create(dump_file);
if (!trace)
return -1;
if (trace_is_err(trace)) {
libtrace_cleanup(trace, packet);
return -1;
}
if (trace_start(trace) == -1) {
libtrace_cleanup(trace, packet);
return 1;
}
if (proto == DIAGNOSTIC_HTTP && diagnostic_type == DOWNLOAD_DIAGNOSTIC) {
while (trace_read_packet(trace,packet) > 0 && read_next == 1) {
http_download_per_packet(packet);
continue;
}
set_stats_value("download");
} else if (proto == DIAGNOSTIC_FTP && diagnostic_type == DOWNLOAD_DIAGNOSTIC) {
while (trace_read_packet(trace,packet) > 0 && read_next == 1) {
ftp_download_per_packet(packet);
continue;
}
set_stats_value("download");
} else if (proto == DIAGNOSTIC_HTTP && diagnostic_type == UPLOAD_DIAGNOSTIC) {
while (trace_read_packet(trace,packet) > 0 && read_next == 1) {
http_upload_per_packet(packet);
continue;
}
set_stats_value("upload");
} else {
while (trace_read_packet(trace,packet) > 0 && read_next == 1) {
ftp_upload_per_packet(packet);
continue;
}
set_stats_value("upload");
}
libtrace_cleanup(trace, packet);
return 0;
}

View file

@ -30,27 +30,6 @@
#define DMMAP_DIAGNOSTIGS "dmmap_diagnostics" #define DMMAP_DIAGNOSTIGS "dmmap_diagnostics"
#define CONFIG_BACKUP "/tmp/bbf_config_backup" #define CONFIG_BACKUP "/tmp/bbf_config_backup"
#define MAX_TIME_WINDOW 5 #define MAX_TIME_WINDOW 5
#define DOWNLOAD_DUMP_FILE "/tmp/download_dump"
#define UPLOAD_DUMP_FILE "/tmp/upload_dump"
struct diagnostic_stats
{
char romtime[default_date_size];
char bomtime[default_date_size];
char eomtime[default_date_size];
char tcpopenrequesttime[default_date_size];
char tcpopenresponsetime[default_date_size];
int test_bytes_received;
int tmp;
int first_data;
uint16_t ip_len;
uint32_t ack_seq;
uint32_t random_seq;
uint32_t get_ack;
uint32_t ftp_syn;
};
extern struct diagnostic_stats diag_stats;
enum diagnostic_protocol { enum diagnostic_protocol {
DIAGNOSTIC_HTTP = 1, DIAGNOSTIC_HTTP = 1,
@ -79,6 +58,4 @@ 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 *file_size, const char *checksum_algorithm, const char *checksum,
const char *bank_id, const char *command, const char *obj_path, const char *commandKey); 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 #endif

View file

@ -13,6 +13,9 @@
#include "dmbbfcommon.h" #include "dmbbfcommon.h"
#include "diagnostics.h" #include "diagnostics.h"
#define DOWNLOAD_DIAGNOSTIC_PATH "/usr/share/bbfdm/download"
#define UPLOAD_DIAGNOSTIC_PATH "/usr/share/bbfdm/upload"
/************************************************************* /*************************************************************
* COMMON FUNCTIONS * COMMON FUNCTIONS
**************************************************************/ **************************************************************/
@ -684,19 +687,19 @@ static int get_IPDiagnosticsDownloadDiagnostics_IPAddressUsed(char *refparam, st
static int get_IPDiagnosticsDownloadDiagnostics_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsDownloadDiagnostics_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("download", "ROMtime", "0001-01-01T00:00:00.000000Z"); *value = get_diagnostics_option_fallback_def("download", "ROMTime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
static int get_IPDiagnosticsDownloadDiagnostics_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsDownloadDiagnostics_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("download", "BOMtime", "0001-01-01T00:00:00.000000Z"); *value = get_diagnostics_option_fallback_def("download", "BOMTime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
static int get_IPDiagnosticsDownloadDiagnostics_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsDownloadDiagnostics_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("download", "EOMtime", "0001-01-01T00:00:00.000000Z"); *value = get_diagnostics_option_fallback_def("download", "EOMTime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
@ -786,25 +789,25 @@ static int set_IPDiagnosticsDownloadDiagnostics_EnablePerConnectionResults(char
static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("download", "ROMtime", "0001-01-01T00:00:00.000000Z"); *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ROMtime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("download", "BOMtime", "0001-01-01T00:00:00.000000Z"); *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "BOMtime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("download", "EOMtime", "0001-01-01T00:00:00.000000Z"); *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "EOMtime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TestBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TestBytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("download", "TestBytesReceived", "0"); *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "TestBytesReceived", "0");
return 0; return 0;
} }
@ -822,13 +825,13 @@ static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TotalBytesSen
static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenRequestTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("download", "TCPOpenRequestTime", "0001-01-01T00:00:00.000000Z"); *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "TCPOpenRequestTime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsDownloadDiagnosticsPerConnectionResult_TCPOpenResponseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("download", "TCPOpenResponseTime", "0001-01-01T00:00:00.000000Z"); *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "TCPOpenResponseTime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
@ -1027,19 +1030,19 @@ static int get_IPDiagnosticsUploadDiagnostics_IPAddressUsed(char *refparam, stru
static int get_IPDiagnosticsUploadDiagnostics_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsUploadDiagnostics_ROMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("upload", "ROMtime", "0001-01-01T00:00:00.000000Z"); *value = get_diagnostics_option_fallback_def("upload", "ROMTime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
static int get_IPDiagnosticsUploadDiagnostics_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsUploadDiagnostics_BOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("upload", "BOMtime", "0001-01-01T00:00:00.000000Z"); *value = get_diagnostics_option_fallback_def("upload", "BOMTime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
static int get_IPDiagnosticsUploadDiagnostics_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) static int get_IPDiagnosticsUploadDiagnostics_EOMTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{ {
*value = get_diagnostics_option_fallback_def("upload", "EOMtime", "0001-01-01T00:00:00.000000Z"); *value = get_diagnostics_option_fallback_def("upload", "EOMTime", "0001-01-01T00:00:00.000000Z");
return 0; return 0;
} }
@ -1917,10 +1920,11 @@ 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) static int operate_IPDiagnostics_DownloadDiagnostics(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{ {
json_object *res = NULL; char input[2048] = {0};
char *bytes_received = NULL; char output[2048] = {0};
char cmd[2096] = {0};
char *download_url = dmjson_get_value((json_object *)value, 1, "DownloadURL"); char *download_url = dmjson_get_value((json_object *)value, 1, "DownloadURL");
if (download_url[0] == '\0') if (download_url[0] == '\0')
return CMD_INVALID_ARGUMENTS; return CMD_INVALID_ARGUMENTS;
@ -1936,65 +1940,58 @@ static int operate_IPDiagnostics_DownloadDiagnostics(char *refparam, struct dmct
char *download_proto = dmjson_get_value((json_object *)value, 1, "ProtocolVersion"); 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_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 *download_enable_per_connection_results = dmjson_get_value((json_object *)value, 1, "EnablePerConnectionResults");
char *proto = (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto";
dmubus_call_blocking("bbf.diag", "download", snprintf(input, sizeof(input), "'{\"url\": \"%s\",\"iface\":\"%s\",\"dscp\":\"%s\",\"eth_prio\":\"%s\",\"ip_proto\":\"%s\",\"num_of_con\":\"%s\",\"enable_per_con\":\"%s\",\"proto\":\"%s\"}'",
UBUS_ARGS{ download_url,
{"url", download_url, String}, download_interface,
{"iface", download_interface, String}, download_dscp,
{"dscp", download_dscp, String}, download_ethernet_priority,
{"eth_prio", download_ethernet_priority, String}, download_proto,
{"ip_proto", download_proto, String}, download_num_of_connections,
{"num_of_con", download_num_of_connections, String}, download_enable_per_connection_results,
{"enable_per_con", download_enable_per_connection_results, String}, (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto");
{"proto", proto, String}
},
8, &res);
if (res == NULL) { snprintf(cmd, sizeof(cmd), "sh %s %s", DOWNLOAD_DIAGNOSTIC_PATH, input);
if (file_exists(DOWNLOAD_DUMP_FILE))
remove(DOWNLOAD_DUMP_FILE);
FILE *pp = popen(cmd, "r");
if (pp != NULL) {
fgets(output, sizeof(output) , pp);
pclose(pp);
} else {
return CMD_FAIL; return CMD_FAIL;
} }
json_object *res = (DM_STRLEN(output)) ? json_tokener_parse(output) : NULL;
if (res == NULL)
return CMD_FAIL;
char *status = dmjson_get_value(res, 1, "Status"); char *status = dmjson_get_value(res, 1, "Status");
char *ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed"); char *ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed");
char *rom_time = dmjson_get_value(res, 1, "ROMTime");
char *bom_time = dmjson_get_value(res, 1, "BOMTime");
char *eom_time = dmjson_get_value(res, 1, "EOMTime");
char *test_bytes_received = dmjson_get_value(res, 1, "TestBytesReceived");
char *total_bytes_received = dmjson_get_value(res, 1, "TotalBytesReceived"); char *total_bytes_received = dmjson_get_value(res, 1, "TotalBytesReceived");
char *total_bytes_sent = dmjson_get_value(res, 1, "TotalBytesSent"); 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"); char *period_of_full_loading = dmjson_get_value(res, 1, "PeriodOfFullLoading");
char *tcp_open_request_time = dmjson_get_value(res, 1, "TCPOpenRequestTime");
if (DM_LSTRCMP(status, "Complete") == 0) { char *tcp_open_response_time = dmjson_get_value(res, 1, "TCPOpenResponseTime");
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) {
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("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("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("ROMTime"), rom_time[0] != 0 ? dmstrdup(rom_time) : "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("BOMTime"), bom_time[0] != 0 ? dmstrdup(bom_time) : "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("EOMTime"), eom_time[0] != 0 ? dmstrdup(eom_time) : "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("TestBytesReceived"), dmstrdup(test_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("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("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("TestBytesReceivedUnderFullLoading"), dmstrdup(test_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("TotalBytesReceivedUnderFullLoading"), dmstrdup(total_bytes_received), 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("TotalBytesSentUnderFullLoading"), dmstrdup(total_bytes_sent), 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("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("TCPOpenRequestTime"), tcp_open_request_time[0] != 0 ? dmstrdup(tcp_open_request_time) : "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("TCPOpenResponseTime"), tcp_open_response_time[0] != 0 ? dmstrdup(tcp_open_response_time) : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
if (res != NULL) if (res != NULL)
json_object_put(res); json_object_put(res);
@ -2057,9 +2054,11 @@ 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) static int operate_IPDiagnostics_UploadDiagnostics(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{ {
json_object *res = NULL; char input[2048] = {0};
char output[2048] = {0};
char cmd[2096] = {0};
char *upload_url = dmjson_get_value((json_object *)value, 1, "UploadURL"); char *upload_url = dmjson_get_value((json_object *)value, 1, "UploadURL");
if (upload_url[0] == '\0') if (upload_url[0] == '\0')
return CMD_INVALID_ARGUMENTS; return CMD_INVALID_ARGUMENTS;
@ -2079,54 +2078,50 @@ static int operate_IPDiagnostics_UploadDiagnostics(char *refparam, struct dmctx
char *upload_proto = dmjson_get_value((json_object *)value, 1, "ProtocolVersion"); 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_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 *upload_enable_per_connection_results = dmjson_get_value((json_object *)value, 1, "EnablePerConnectionResults");
char *proto = (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto";
dmubus_call_blocking("bbf.diag", "upload", snprintf(input, sizeof(input), "'{\"url\": \"%s\",\"iface\":\"%s\",\"dscp\":\"%s\",\"eth_prio\":\"%s\",\"file_length\":\"%s\",\"ip_proto\":\"%s\",\"num_of_con\":\"%s\",\"enable_per_con\":\"%s\",\"proto\":\"%s\"}'",
UBUS_ARGS{ upload_url,
{"url", upload_url, String}, upload_interface,
{"iface", upload_interface, String}, upload_dscp,
{"dscp", upload_dscp, String}, upload_ethernet_priority,
{"eth_prio", upload_ethernet_priority, String}, upload_test_file_length,
{"file_length", upload_test_file_length, String}, upload_proto,
{"ip_proto", upload_proto, String}, upload_num_of_connections,
{"num_of_con", upload_num_of_connections, String}, upload_enable_per_connection_results,
{"enable_per_con", upload_enable_per_connection_results, String}, (bbfdatamodel_type == BBFDM_USP) ? "usp" : "both_proto");
{"proto", proto, String}
},
9, &res);
if (res == NULL) { snprintf(cmd, sizeof(cmd), "sh %s %s", UPLOAD_DIAGNOSTIC_PATH, input);
if (file_exists(UPLOAD_DUMP_FILE))
remove(UPLOAD_DUMP_FILE);
FILE *pp = popen(cmd, "r");
if (pp != NULL) {
fgets(output, sizeof(output) , pp);
pclose(pp);
} else {
return CMD_FAIL; return CMD_FAIL;
} }
json_object *res = (DM_STRLEN(output)) ? json_tokener_parse(output) : NULL;
if (res == NULL)
return CMD_FAIL;
char *upload_status = dmjson_get_value(res, 1, "Status"); char *upload_status = dmjson_get_value(res, 1, "Status");
char *upload_ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed"); char *upload_ip_address_used = dmjson_get_value(res, 1, "IPAddressUsed");
char *upload_rom_time = dmjson_get_value(res, 1, "ROMTime");
char *upload_bom_time = dmjson_get_value(res, 1, "BOMTime");
char *upload_eom_time = dmjson_get_value(res, 1, "EOMTime");
char *upload_test_bytes_sent = dmjson_get_value(res, 1, "TestBytesSent"); 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_received = dmjson_get_value(res, 1, "TotalBytesReceived");
char *upload_total_bytes_sent = dmjson_get_value(res, 1, "TotalBytesSent"); char *upload_total_bytes_sent = dmjson_get_value(res, 1, "TotalBytesSent");
char *upload_period_of_full_loading = dmjson_get_value(res, 1, "PeriodOfFullLoading"); char *upload_period_of_full_loading = dmjson_get_value(res, 1, "PeriodOfFullLoading");
char *upload_tcp_open_request_time = dmjson_get_value(res, 1, "TCPOpenRequestTime");
if (DM_LSTRCMP(upload_status, "Complete") == 0) { char *upload_tcp_open_response_time = dmjson_get_value(res, 1, "TCPOpenResponseTime");
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;
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(upload_status), DMT_TYPE[DMT_STRING], NULL); 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("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("ROMTime"), upload_rom_time[0] != 0 ? dmstrdup(upload_rom_time) : "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("BOMTime"), upload_bom_time[0] != 0 ? dmstrdup(upload_bom_time) : "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("EOMTime"), upload_eom_time[0] != 0 ? dmstrdup(upload_eom_time) : "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("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("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("TotalBytesSent"), dmstrdup(upload_total_bytes_sent), DMT_TYPE[DMT_UNINT], NULL);
@ -2134,8 +2129,8 @@ static int operate_IPDiagnostics_UploadDiagnostics(char *refparam, struct dmctx
add_list_parameter(ctx, dmstrdup("TotalBytesReceivedUnderFullLoading"), dmstrdup(upload_total_bytes_received), 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("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("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("TCPOpenRequestTime"), upload_tcp_open_request_time[0] != 0 ? dmstrdup(upload_tcp_open_request_time) : "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("TCPOpenResponseTime"), upload_tcp_open_response_time[0] != 0 ? dmstrdup(upload_tcp_open_response_time) : "0001-01-01T00:00:00.000000Z", DMT_TYPE[DMT_TIME], NULL);
if (res != NULL) if (res != NULL)
json_object_put(res); json_object_put(res);

View file

@ -26,7 +26,6 @@ libbbf_ubus_la_LIBADD = \
$(LIBUBOX_LIBS) \ $(LIBUBOX_LIBS) \
$(LIBUBUS_LIBS) \ $(LIBUBUS_LIBS) \
$(LIBJSON_LIBS) \ $(LIBJSON_LIBS) \
$(LIBTRACE_LIBS) \
$(LBLOBMSG_LIBS) \ $(LBLOBMSG_LIBS) \
$(LIBCURL_LIBS) \ $(LIBCURL_LIBS) \
-L../bin/ -L../bin/

View file

@ -22,9 +22,6 @@ AC_SUBST([LIBUCI_LDFLAGS])
LIBUCI_LIBS='-luci' LIBUCI_LIBS='-luci'
AC_SUBST([LIBUCI_LIBS]) AC_SUBST([LIBUCI_LIBS])
LIBTRACE_LIBS='-ltrace'
AC_SUBST([LIBTRACE_LIBS])
AC_ARG_WITH([libubox-include-path], AC_ARG_WITH([libubox-include-path],
[AS_HELP_STRING([--with-libubox-include-path], [AS_HELP_STRING([--with-libubox-include-path],
[location of the libubox library headers])], [location of the libubox library headers])],

View file

@ -10,8 +10,6 @@ case "$1" in
"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" }, "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" }, "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" }, "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) call)
@ -34,12 +32,6 @@ case "$1" in
serverselection) serverselection)
sh ${BBF_SCRIPTS}/serverselection "${input}" sh ${BBF_SCRIPTS}/serverselection "${input}"
;; ;;
download)
sh ${BBF_SCRIPTS}/download "${input}"
;;
upload)
sh ${BBF_SCRIPTS}/upload "${input}"
;;
esac esac
;; ;;
esac esac

View file

@ -8,8 +8,6 @@
ROOT="$(dirname $0)" ROOT="$(dirname $0)"
. ${ROOT}/bbf_api . ${ROOT}/bbf_api
CAPTURE_FILE="/tmp/download_dump"
download_error() { download_error() {
json_init json_init
json_add_string "Status" "$1" json_add_string "Status" "$1"
@ -67,81 +65,130 @@ download_launch() {
return return
} }
# Disable acceleration on Broadcom devices to capture all packets with tcpdump [ "${url:0:7}" != "http://" -a "${url:0:6}" != "ftp://" ] && {
[ -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 $ip_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" ] && {
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}" download_error "Error_Other" "${proto}"
kill $PID 2> /dev/null
return return
} }
fi
tx_bytes=$((tx_bytes_after-tx_bytes_before)) format='{ "size_download": "%{size_download}",
rx_bytes=$((rx_bytes_after-rx_bytes_before)) "size_header": "%{size_header}",
periodtime=$(($((time2-time1))*1000000)) "time_appconnect": "%{time_appconnect}",
"time_connect": "%{time_connect}",
"time_pretransfer": "%{time_pretransfer}",
"time_starttransfer": "%{time_starttransfer}",
"time_total": "%{time_total}",
"exitcode": "%{exitcode}" }'
tx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
rx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
time_start=$(date +"%s.282646") # It should be like that time_start=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
res=$(curl $ip_proto --fail --silent -w "$format" $url --output /dev/null)
time_end=$(date +"%s.282646") # It should be like that time_end=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
tx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
rx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
json_load "${res}"
json_get_var size_download size_download
json_get_var size_header size_header
json_get_var time_appconnect time_appconnect
json_get_var time_connect time_connect
json_get_var time_pretransfer time_pretransfer
json_get_var time_starttransfer time_starttransfer
json_get_var time_total time_total
json_get_var exitcode exitcode
[ "$exitcode" = "6" ] && {
download_error "Error_CannotResolveHostName" "${proto}"
return
}
[ "$exitcode" = "7" ] && {
download_error "Error_InitConnectionFailed" "${proto}"
return
}
[ "$exitcode" = "22" ] && {
download_error "Error_NoResponse" "${proto}"
return
}
[ "$exitcode" = "27" ] && {
download_error "Error_IncorrectSize" "${proto}"
return
}
[ "$exitcode" = "28" ] && {
download_error "Error_Timeout" "${proto}"
return
}
[ "$exitcode" != "0" ] && {
download_error "Error_Other" "${proto}"
return
}
tcp_open_request_time=$(echo ${time_start} ${time_appconnect} | awk '{printf "%.6f", $1 + $2}')
tcp_open_response_time=$(echo ${time_start} ${time_connect} | awk '{printf "%.6f", $1 + $2}')
rom_time=$(echo ${time_start} ${time_pretransfer} | awk '{printf "%.6f", $1 + $2}')
bom_time=$(echo ${time_start} ${time_starttransfer} | awk '{printf "%.6f", $1 + $2}')
eom_time=$(echo ${time_start} ${time_total} | awk '{printf "%.6f", $1 + $2}')
separator_idx=$(expr index ${tcp_open_request_time} .)
TCPOpenRequestTime_MicroSec=${tcp_open_request_time:$separator_idx}
TCPOpenRequestTime_Sec=${tcp_open_request_time:0:$(($separator_idx-1))}
separator_idx=$(expr index ${tcp_open_response_time} .)
TCPOpenResponseTime_MicroSec=${tcp_open_response_time:$separator_idx}
TCPOpenResponseTime_Sec=${tcp_open_response_time:0:$(($separator_idx-1))}
separator_idx=$(expr index ${rom_time} .)
ROMTime_MicroSec=${rom_time:$separator_idx}
ROMTime_Sec=${rom_time:0:$(($separator_idx-1))}
separator_idx=$(expr index ${bom_time} .)
BOMTime_MicroSec=${bom_time:$separator_idx}
BOMTime_Sec=${bom_time:0:$(($separator_idx-1))}
separator_idx=$(expr index ${eom_time} .)
EOMTime_MicroSec=${eom_time:$separator_idx}
EOMTime_Sec=${eom_time:0:$(($separator_idx-1))}
TCPOpenRequestTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenRequestTime_MicroSec}Z" -d @$TCPOpenRequestTime_Sec)
TCPOpenResponseTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenResponseTime_MicroSec}Z" -d @$TCPOpenResponseTime_Sec)
ROMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${ROMTime_MicroSec}Z" -d @$ROMTime_Sec)
BOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${BOMTime_MicroSec}Z" -d @$BOMTime_Sec)
EOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${EOMTime_MicroSec}Z" -d @$EOMTime_Sec)
tx_bytes=$((tx_bytes_end-tx_bytes_start))
rx_bytes=$((rx_bytes_end-rx_bytes_start))
test_rx_bytes=$((size_download+size_header))
period_time=$(echo ${time_end} ${time_start} | awk '{printf ($1 - $2) * 1000000}')
json_init json_init
json_add_string "Status" "Complete" json_add_string "Status" "Complete"
json_add_string "IPAddressUsed" "${ip_addr_used}" json_add_string "IPAddressUsed" "${ip_addr_used}"
json_add_string "ROMTime" "${ROMTime}"
json_add_string "BOMTime" "${BOMTime}"
json_add_string "EOMTime" "${EOMTime}"
json_add_int "TestBytesReceived" "${test_rx_bytes}"
json_add_int "TotalBytesReceived" "${rx_bytes}" json_add_int "TotalBytesReceived" "${rx_bytes}"
json_add_int "TotalBytesSent" "${tx_bytes}" json_add_int "TotalBytesSent" "${tx_bytes}"
json_add_int "PeriodOfFullLoading" "${periodtime}" json_add_int "PeriodOfFullLoading" "${period_time}"
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
json_add_array "DownloadPerConnection" json_add_array "DownloadPerConnection"
json_add_object "" json_add_object ""
json_add_string "ROMTime" "${ROMTime}"
json_add_string "BOMTime" "${BOMTime}"
json_add_string "EOMTime" "${EOMTime}"
json_add_int "TestBytesReceived" "${test_rx_bytes}"
json_add_int "TotalBytesReceived" "${rx_bytes}" json_add_int "TotalBytesReceived" "${rx_bytes}"
json_add_int "TotalBytesSent" "${tx_bytes}" json_add_int "TotalBytesSent" "${tx_bytes}"
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
json_close_object json_close_object
fi fi
json_dump json_dump
@ -150,26 +197,31 @@ download_launch() {
[ "${proto}" == "both_proto" ] && { [ "${proto}" == "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState="Complete" $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.IPAddressUsed="${ip_addr_used}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.ROMTime="${ROMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.BOMTime="${BOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.EOMTime="${EOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TestBytesReceived="${test_rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesReceived="${rx_bytes}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesReceived="${rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesSent="${tx_bytes}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesSent="${tx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.PeriodOfFullLoading="${periodtime}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.PeriodOfFullLoading="${period_time}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TCPOpenRequestTime="${TCPOpenRequestTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TCPOpenResponseTime="${TCPOpenResponseTime}"
perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.download.EnablePerConnection) perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.download.EnablePerConnection)
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
$UCI_ADD_BBF_DMMAP dmmap_diagnostics DownloadPerConnection $UCI_ADD_BBF_DMMAP dmmap_diagnostics DownloadPerConnection
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].ROMTime="${ROMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].BOMTime="${BOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].EOMTime="${EOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TestBytesReceived="${test_rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesReceived="${rx_bytes}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesReceived="${rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesSent="${tx_bytes}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesSent="${tx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TCPOpenRequestTime="${TCPOpenRequestTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TCPOpenResponseTime="${TCPOpenResponseTime}"
else else
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0] $UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0]
fi 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_SET_BBF_DMMAP dmmap_diagnostics.download.Status="complete"
$UCI_COMMIT_BBF_DMMAP $UCI_COMMIT_BBF_DMMAP
} }

View file

@ -8,8 +8,6 @@
ROOT="$(dirname $0)" ROOT="$(dirname $0)"
. ${ROOT}/bbf_api . ${ROOT}/bbf_api
CAPTURE_FILE="/tmp/upload_dump"
upload_error() { upload_error() {
json_init json_init
json_add_string "Status" "$1" json_add_string "Status" "$1"
@ -68,83 +66,136 @@ upload_launch() {
return return
} }
# Disable acceleration on Broadcom devices to capture all packets with tcpdump [ "${url:0:7}" != "http://" -a "${url:0:6}" != "ftp://" ] && {
[ -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}" upload_error "Error_Other" "${proto}"
kill $PID 2> /dev/null
return return
} }
format='{ "size_upload": "%{size_upload}",
"time_appconnect": "%{time_appconnect}",
"time_connect": "%{time_connect}",
"time_pretransfer": "%{time_pretransfer}",
"time_starttransfer": "%{time_starttransfer}",
"time_total": "%{time_total}",
"exitcode": "%{exitcode}" }'
len_mb=$((file_length/(1000*1000)))
if [ $len_mb -gt 0 ]; then
bs="1MB"
count="$len_mb"
else
bs="$file_length"
count="1"
fi fi
tx_bytes=$((tx_bytes_after-tx_bytes_before)) tx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
rx_bytes=$((rx_bytes_after-rx_bytes_before)) rx_bytes_start=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
periodtime=$(($((time2-time1))*1000000))
time_start=$(date +"%s.282646") # It should be like that time_start=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
res=$(dd if=/dev/zero bs=$bs count=$count 2>/dev/null | curl $ip_proto --fail --silent -T - $url -w "$format")
time_end=$(date +"%s.282646") # It should be like that time_end=$(date +"%s.%6N") but since OpenWrt busybox has limitations and doesn't support nonoseconds so keep it hardcoded
tx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes)
rx_bytes_end=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes)
json_load "${res}"
json_get_var size_upload size_upload
json_get_var time_appconnect time_appconnect
json_get_var time_connect time_connect
json_get_var time_pretransfer time_pretransfer
json_get_var time_starttransfer time_starttransfer
json_get_var time_total time_total
json_get_var exitcode exitcode
[ "$exitcode" = "6" ] && {
upload_error "Error_CannotResolveHostName" "${proto}"
return
}
[ "$exitcode" = "7" ] && {
upload_error "Error_InitConnectionFailed" "${proto}"
return
}
[ "$exitcode" = "22" ] && {
upload_error "Error_NoResponse" "${proto}"
return
}
[ "$exitcode" = "27" ] && {
upload_error "Error_IncorrectSize" "${proto}"
return
}
[ "$exitcode" = "28" ] && {
upload_error "Error_Timeout" "${proto}"
return
}
[ "$exitcode" != "0" ] && {
upload_error "Error_Other" "${proto}"
return
}
tcp_open_request_time=$(echo ${time_start} ${time_appconnect} | awk '{printf "%.6f", $1 + $2}')
tcp_open_response_time=$(echo ${time_start} ${time_connect} | awk '{printf "%.6f", $1 + $2}')
rom_time=$(echo ${time_start} ${time_pretransfer} | awk '{printf "%.6f", $1 + $2}')
bom_time=$(echo ${time_start} ${time_starttransfer} | awk '{printf "%.6f", $1 + $2}')
eom_time=$(echo ${time_start} ${time_total} | awk '{printf "%.6f", $1 + $2}')
separator_idx=$(expr index ${tcp_open_request_time} .)
TCPOpenRequestTime_MicroSec=${tcp_open_request_time:$separator_idx}
TCPOpenRequestTime_Sec=${tcp_open_request_time:0:$(($separator_idx-1))}
separator_idx=$(expr index ${tcp_open_response_time} .)
TCPOpenResponseTime_MicroSec=${tcp_open_response_time:$separator_idx}
TCPOpenResponseTime_Sec=${tcp_open_response_time:0:$(($separator_idx-1))}
separator_idx=$(expr index ${rom_time} .)
ROMTime_MicroSec=${rom_time:$separator_idx}
ROMTime_Sec=${rom_time:0:$(($separator_idx-1))}
separator_idx=$(expr index ${bom_time} .)
BOMTime_MicroSec=${bom_time:$separator_idx}
BOMTime_Sec=${bom_time:0:$(($separator_idx-1))}
separator_idx=$(expr index ${eom_time} .)
EOMTime_MicroSec=${eom_time:$separator_idx}
EOMTime_Sec=${eom_time:0:$(($separator_idx-1))}
TCPOpenRequestTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenRequestTime_MicroSec}Z" -d @$TCPOpenRequestTime_Sec)
TCPOpenResponseTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${TCPOpenResponseTime_MicroSec}Z" -d @$TCPOpenResponseTime_Sec)
ROMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${ROMTime_MicroSec}Z" -d @$ROMTime_Sec)
BOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${BOMTime_MicroSec}Z" -d @$BOMTime_Sec)
EOMTime=$(date -u +"%Y-%m-%dT%H:%M:%S.${EOMTime_MicroSec}Z" -d @$EOMTime_Sec)
tx_bytes=$((tx_bytes_end-tx_bytes_start))
rx_bytes=$((rx_bytes_end-rx_bytes_start))
period_time=$(echo ${time_end} ${time_start} | awk '{printf ($1 - $2) * 1000000}')
json_init json_init
json_add_string "Status" "Complete" json_add_string "Status" "Complete"
json_add_string "IPAddressUsed" "${ip_addr_used}" json_add_string "IPAddressUsed" "${ip_addr_used}"
json_add_string "TestBytesSent" "${file_length}" json_add_string "ROMTime" "${ROMTime}"
json_add_string "BOMTime" "${BOMTime}"
json_add_string "EOMTime" "${EOMTime}"
json_add_int "TestBytesSent" "${size_upload}"
json_add_int "TotalBytesReceived" "${rx_bytes}" json_add_int "TotalBytesReceived" "${rx_bytes}"
json_add_int "TotalBytesSent" "${tx_bytes}" json_add_int "TotalBytesSent" "${tx_bytes}"
json_add_int "PeriodOfFullLoading" "${periodtime}" json_add_int "PeriodOfFullLoading" "${period_time}"
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
json_add_array "UploadPerConnection" json_add_array "UploadPerConnection"
json_add_object "" json_add_object ""
json_add_int "TestBytesSent" "${file_length}" json_add_string "ROMTime" "${ROMTime}"
json_add_string "BOMTime" "${BOMTime}"
json_add_string "EOMTime" "${EOMTime}"
json_add_int "TestBytesSent" "${size_upload}"
json_add_int "TotalBytesReceived" "${rx_bytes}" json_add_int "TotalBytesReceived" "${rx_bytes}"
json_add_int "TotalBytesSent" "${tx_bytes}" json_add_int "TotalBytesSent" "${tx_bytes}"
json_add_string "TCPOpenRequestTime" "${TCPOpenRequestTime}"
json_add_string "TCPOpenResponseTime" "${TCPOpenResponseTime}"
json_close_object json_close_object
fi fi
json_dump json_dump
@ -152,28 +203,32 @@ upload_launch() {
# Store data in dmmap_diagnostics for both protocols (cwmp/usp) # Store data in dmmap_diagnostics for both protocols (cwmp/usp)
[ "${proto}" == "both_proto" ] && { [ "${proto}" == "both_proto" ] && {
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState="Complete" $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.IPAddressUsed="${ip_addr_used}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.ROMTime="${ROMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.BOMTime="${BOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.EOMTime="${EOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TestBytesSent="${size_upload}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesReceived="${rx_bytes}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesReceived="${rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesSent="${tx_bytes}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesSent="${tx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.PeriodOfFullLoading="${periodtime}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.PeriodOfFullLoading="${period_time}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TCPOpenRequestTime="${TCPOpenRequestTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TCPOpenResponseTime="${TCPOpenResponseTime}"
perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.upload.EnablePerConnection) perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.upload.EnablePerConnection)
if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then if [ "$enable_per_con" = "true" ] || [ "$enable_per_con" = "1" ]; then
$UCI_ADD_BBF_DMMAP dmmap_diagnostics UploadPerConnection $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].ROMTime="${ROMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].BOMTime="${BOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].EOMTime="${EOMTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TestBytesSent="${size_upload}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesReceived="${rx_bytes}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesReceived="${rx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesSent="${tx_bytes}" $UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesSent="${tx_bytes}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TCPOpenRequestTime="${TCPOpenRequestTime}"
$UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TCPOpenResponseTime="${TCPOpenResponseTime}"
else else
$UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0] $UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0]
fi 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_SET_BBF_DMMAP dmmap_diagnostics.upload.Status="complete"
$UCI_COMMIT_BBF_DMMAP $UCI_COMMIT_BBF_DMMAP
} }