diff --git a/src/bbl.h b/src/bbl.h index e9d1d120..e1dfb79c 100644 --- a/src/bbl.h +++ b/src/bbl.h @@ -449,8 +449,8 @@ typedef struct bbl_ctx_ /* Global Stats */ struct { - uint32_t setup_time; // Time between first session started and last session established - double cps; // PPPoE setup rate in calls per second + uint32_t setup_time; /* Time between first session started and last session established */ + double cps; /* PPPoE setup rate in calls per second */ double cps_min; double cps_avg; double cps_max; diff --git a/src/bbl_ctrl.c b/src/bbl_ctrl.c index aa3e43cb..f56e9254 100644 --- a/src/bbl_ctrl.c +++ b/src/bbl_ctrl.c @@ -289,8 +289,10 @@ bbl_ctrl_igmp_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argument bbl_session_s *session = NULL; bbl_igmp_group_s *group = NULL; uint32_t delay = 0; + uint32_t ms; + struct timespec time_diff; - int ms, i, i2; + int i, i2; if(session_id == 0) { /* session-id is mandatory */ @@ -321,7 +323,8 @@ bbl_ctrl_igmp_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argument json_object_set(record, "state", json_string("idle")); if(group->last_mc_rx_time.tv_sec && group->leave_tx_time.tv_sec) { timespec_sub(&time_diff, &group->last_mc_rx_time, &group->leave_tx_time); - ms = round(time_diff.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds + ms = time_diff.tv_nsec / 1000000; // convert nanoseconds to milliseconds + if(time_diff.tv_nsec % 1000000) ms++; // simple roundup function delay = (time_diff.tv_sec * 1000) + ms; json_object_set(record, "leave-delay-ms", json_integer(delay)); } @@ -333,7 +336,8 @@ bbl_ctrl_igmp_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argument json_object_set(record, "state", json_string("active")); if(group->first_mc_rx_time.tv_sec) { timespec_sub(&time_diff, &group->first_mc_rx_time, &group->join_tx_time); - ms = round(time_diff.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds + ms = time_diff.tv_nsec / 1000000; // convert nanoseconds to milliseconds + if(time_diff.tv_nsec % 1000000) ms++; // simple roundup function delay = (time_diff.tv_sec * 1000) + ms; json_object_set(record, "join-delay-ms", json_integer(delay)); } @@ -342,7 +346,8 @@ bbl_ctrl_igmp_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argument json_object_set(record, "state", json_string("joining")); if(group->first_mc_rx_time.tv_sec) { timespec_sub(&time_diff, &group->first_mc_rx_time, &group->join_tx_time); - ms = round(time_diff.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds + ms = time_diff.tv_nsec / 1000000; // convert nanoseconds to milliseconds + if(time_diff.tv_nsec % 1000000) ms++; // simple roundup function delay = (time_diff.tv_sec * 1000) + ms; json_object_set(record, "join-delay-ms", json_integer(delay)); } diff --git a/src/bbl_stats.c b/src/bbl_stats.c index b9c38a36..76990f96 100644 --- a/src/bbl_stats.c +++ b/src/bbl_stats.c @@ -16,7 +16,7 @@ extern const char banner[]; void bbl_stats_update_cps (bbl_ctx_s *ctx) { struct timespec time_diff = {0}; - int ms; + uint32_t ms; double x, y; /* Session setup time and rate */ @@ -27,7 +27,8 @@ bbl_stats_update_cps (bbl_ctx_s *ctx) { &ctx->stats.last_session_established, &ctx->stats.first_session_tx); - ms = round(time_diff.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds + ms = time_diff.tv_nsec / 1000000; // convert nanoseconds to milliseconds + if(time_diff.tv_nsec % 1000000) ms++; // simple roundup function ctx->stats.setup_time = (time_diff.tv_sec * 1000) + ms; // Setup time in milliseconds x = ctx->sessions_established_max;