Exposes interarrival times via lua flow functions

This commit is contained in:
Simone Mainardi 2019-09-30 19:25:49 +02:00
parent 8834a945ef
commit 7edfdf3944
3 changed files with 35 additions and 26 deletions

View file

@ -219,7 +219,6 @@ class Flow : public GenericHashEntry {
void setBittorrentHash(char *hash);
bool isLowGoodput() const;
static void updatePacketStats(InterarrivalStats *stats, const struct timeval *when, bool update_iat);
void dumpPacketStats(lua_State* vm, bool cli2srv_direction);
bool isReadyToBeMarkedAsIdle();
bool isBlacklistedFlow() const;
inline bool isDeviceAllowedProtocol() const {
@ -249,6 +248,7 @@ class Flow : public GenericHashEntry {
void lua_get_protocols(lua_State* vm) const;
void lua_get_bytes(lua_State* vm) const;
void lua_get_dir_traffic(lua_State* vm, bool cli2srv) const;
void lua_get_dir_iat(lua_State* vm, bool cli2srv) const;
void lua_get_packets(lua_State* vm) const;
void lua_get_throughput(lua_State* vm) const;
void lua_get_time(lua_State* vm) const;

View file

@ -388,6 +388,8 @@ typedef enum {
flow_lua_method_get_bytes,
flow_lua_method_get_cli2srv_traffic,
flow_lua_method_get_srv2cli_traffic,
flow_lua_method_get_cli2srv_iat,
flow_lua_method_get_srv2cli_iat,
flow_lua_method_get_packets,
flow_lua_method_get_time,
flow_lua_method_get_cli_ip,

View file

@ -1863,10 +1863,9 @@ void Flow::lua(lua_State* vm, AddressTree * ptree,
lua_get_throughput(vm);
/* ********************* */
dumpPacketStats(vm, true);
dumpPacketStats(vm, false);
/* Interarrival Times */
lua_get_dir_iat(vm, true /* Client to Server */);
lua_get_dir_iat(vm, false /* Server to Client */);
if((!mask_flow) && (details_level >= details_higher)) {
lua_get_geoloc(vm, true /* Client */, true /* Coordinates */, false /* Country and City */);
@ -2472,27 +2471,6 @@ void Flow::updatePacketStats(InterarrivalStats *stats,
/* *************************************** */
void Flow::dumpPacketStats(lua_State* vm, bool cli2srv_direction) {
InterarrivalStats *s = cli2srv_direction ? getCli2SrvIATStats() : getSrv2CliIATStats();
if(s) {
lua_newtable(vm);
lua_push_uint64_table_entry(vm, "min", s->getMin());
lua_push_uint64_table_entry(vm, "max", s->getMax());
lua_push_float_table_entry(vm, "avg", s->getAvg());
lua_push_float_table_entry(vm, "stddev", s->getStdDev());
// ntop->getTrace()->traceEvent(TRACE_NORMAL, "%u / %.1f / %u", s->getMin(), s->getAvg(), s->getMax());
lua_pushstring(vm, cli2srv_direction ? "interarrival.cli2srv" : "interarrival.srv2cli");
lua_insert(vm, -2);
lua_settable(vm, -3);
}
}
/* *************************************** */
bool Flow::isBlacklistedFlow() const {
bool res = ((cli_host && cli_host->isBlacklisted())
|| (srv_host && srv_host->isBlacklisted())
@ -4285,6 +4263,25 @@ void Flow::lua_get_dir_traffic(lua_State* vm, bool cli2srv) const {
/* ***************************************************** */
void Flow::lua_get_dir_iat(lua_State* vm, bool cli2srv) const {
InterarrivalStats *s = cli2srv ? getCli2SrvIATStats() : getSrv2CliIATStats();
if(s) {
lua_newtable(vm);
lua_push_uint64_table_entry(vm, "min", s->getMin());
lua_push_uint64_table_entry(vm, "max", s->getMax());
lua_push_float_table_entry(vm, "avg", s->getAvg());
lua_push_float_table_entry(vm, "stddev", s->getStdDev());
lua_pushstring(vm, cli2srv ? "interarrival.cli2srv" : "interarrival.srv2cli");
lua_insert(vm, -2);
lua_settable(vm, -3);
}
}
/* ***************************************************** */
void Flow::lua_get_packets(lua_State* vm) const {
lua_push_uint64_table_entry(vm, "packets", stats.cli2srv_packets + stats.srv2cli_packets);
lua_push_uint64_table_entry(vm, "packets.last",
@ -4546,6 +4543,14 @@ bool Flow::lua(lua_State* vm, FlowLuaMethod flm) const {
lua_get_dir_traffic(vm, false /* Server to Client */);
break;
case flow_lua_method_get_cli2srv_iat:
lua_get_dir_iat(vm, true /* Client to Server */);
break;
case flow_lua_method_get_srv2cli_iat:
lua_get_dir_iat(vm, false /* Server to Client */);
break;
case flow_lua_method_get_packets:
lua_get_packets(vm);
break;
@ -4628,6 +4633,8 @@ std::map<FlowLuaMethod, std::string> Flow::initLuaMethodIdToName() {
m[flow_lua_method_get_bytes] = "getBytes";
m[flow_lua_method_get_cli2srv_traffic] = "getClient2ServerTraffic";
m[flow_lua_method_get_srv2cli_traffic] = "getServer2ClientTraffic";
m[flow_lua_method_get_cli2srv_iat] = "getClient2ServerIAT";
m[flow_lua_method_get_srv2cli_iat] = "getServer2ClientIAT";
m[flow_lua_method_get_packets] = "getPackets";
m[flow_lua_method_get_time] = "getTime";
m[flow_lua_method_get_cli_ip] = "getClientIp";