Implements AS RTT calc.

This commit is contained in:
Simone Mainardi 2018-02-13 11:15:29 +01:00
parent 1565ee3892
commit 802dabfb32
8 changed files with 38 additions and 39 deletions

View file

@ -21,13 +21,13 @@
#include "ntop_includes.h"
// #define AS_LATENCY_DEBUG 1
// #define AS_RTT_DEBUG 1
/* *************************************** */
AutonomousSystem::AutonomousSystem(NetworkInterface *_iface, IpAddress *ipa) : GenericHashEntry(_iface), GenericTrafficElement() {
asname = NULL;
server_network_latency = 0;
round_trip_time = 0;
ntop->getGeolocation()->getAS(ipa, &asn, &asname);
#ifdef AS_DEBUG
@ -47,27 +47,24 @@ AutonomousSystem::~AutonomousSystem() {
/* *************************************** */
void AutonomousSystem::updateNetworkLatency(bool as_client, u_int32_t latency_msecs) {
void AutonomousSystem::updateRoundTripTime(u_int32_t rtt_msecs) {
/* EWMA formula is EWMA(n) = (alpha_percent * sample + (100 - alpha_percent) * EWMA(n-1)) / 100
We read the EWMA alpha_percent from the preferences
*/
*/
u_int8_t ewma_alpha_percent = ntop->getPrefs()->get_ewma_alpha_percent();
if(as_client) ; /* Currently not relevant, only account for server network latency */
else {
#ifdef AS_LATENCY_DEBUG
u_int32_t old_latency = server_network_latency;
#ifdef AS_RTT_DEBUG
u_int32_t old_rtt = round_trip_time;
#endif
if(server_network_latency)
Utils::update_ewma(latency_msecs, &server_network_latency, ewma_alpha_percent);
else
server_network_latency = latency_msecs;
#ifdef AS_LATENCY_DEBUG
printf("Updating latency EWMA: [asn: %u][sample msecs: %u][old latency: %u][new latency: %u][alpha percent: %u]\n",
asn, latency_msecs, old_latency, server_network_latency, ewma_alpha_percent);
if(round_trip_time)
Utils::update_ewma(rtt_msecs, &round_trip_time, ewma_alpha_percent);
else
round_trip_time = rtt_msecs;
#ifdef AS_RTT_DEBUG
printf("Updating rtt EWMA: [asn: %u][sample msecs: %u][old rtt: %u][new rtt: %u][alpha percent: %u]\n",
asn, rtt_msecs, old_rtt, round_trip_time, ewma_alpha_percent);
#endif
}
}
/* *************************************** */
@ -108,8 +105,8 @@ void AutonomousSystem::lua(lua_State* vm, DetailsLevel details_level, bool asLis
lua_push_int_table_entry(vm, "seen.last", last_seen);
lua_push_int_table_entry(vm, "duration", get_duration());
lua_push_int_table_entry(vm, "num_hosts", getNumHosts());
lua_push_int_table_entry(vm, "server_network_latency", server_network_latency);
lua_push_int_table_entry(vm, "num_hosts", getNumHosts());
lua_push_int_table_entry(vm, "round_trip_time", round_trip_time);
if(details_level >= details_higher)
if(ndpiStats) ndpiStats->lua(iface, vm);