Coverage Report

Created: 2025-05-16 06:24

/src/ntopng/include/AggregatedFlowsStats.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *
3
 * (C) 2019-25 - ntop.org
4
 *
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 *
20
 */
21
22
#ifndef _FLOWS_STATS_H_
23
#define _FLOWS_STATS_H_
24
25
#include "ntop_includes.h"
26
27
/* *************************************** */
28
29
class AggregatedFlowsStats {
30
 private:
31
  std::set<std::string> clients, servers;
32
  u_int32_t num_flows, tot_score;
33
  u_int64_t tot_sent, tot_rcvd;
34
  u_int8_t l4_proto;
35
  FlowsHostInfo* client;
36
  FlowsHostInfo* server;
37
  u_int16_t vlan_id;
38
  u_int16_t srv_port;
39
  char* proto_name;
40
  char* info_key;
41
  u_int64_t key;
42
  u_int64_t proto_key;
43
  bool is_not_guessed;
44
  u_int32_t flow_device_ip;
45
46
 public:
47
  AggregatedFlowsStats(const IpAddress* c, const IpAddress* s, u_int8_t _l4_proto,
48
             u_int64_t bytes_sent, u_int64_t bytes_rcvd, u_int32_t score);
49
50
  ~AggregatedFlowsStats();
51
52
53
  /* Getters */
54
0
  inline u_int8_t getL4Protocol() { return (l4_proto); };
55
0
  inline u_int16_t getSrvPort() { return (srv_port); };
56
0
  inline u_int16_t getVlanId() { return vlan_id; };
57
0
  inline u_int16_t getCliVLANId() { return (client ? client->getVLANId() : 0); };
58
0
  inline u_int16_t getSrvVLANId() { return (server ? server->getVLANId() : 0); };
59
0
  inline u_int32_t getNumClients() { return (clients.size()); };
60
0
  inline u_int32_t getNumServers() { return (servers.size()); };
61
0
  inline u_int32_t getNumFlows() { return (num_flows); };
62
0
  inline u_int32_t getTotalScore() { return (tot_score); };
63
0
  inline u_int64_t getKey() { return key; };
64
0
  inline u_int64_t getProtoKey() { return proto_key; };
65
0
  inline u_int64_t getTotalSent() { return (tot_sent); };
66
0
  inline u_int64_t getTotalRcvd() { return (tot_rcvd); };
67
0
  inline char* getProtoName() { return (proto_name ? proto_name : (char *)""); };
68
0
  inline char* getInfoKey() { return (info_key ? info_key : (char *)""); };
69
 
70
0
  inline const char* getCliIP(char* buf, u_int len) { return (client ? client->getIP(buf, len) : (char *)""); };
71
0
  inline const char* getSrvIP(char* buf, u_int len) { return (server ? server->getIP(buf, len) : (char *)""); };
72
  
73
0
  inline IpAddress* getClientIPaddr() { return(client ? client->getIPaddr() : NULL); }
74
0
  inline IpAddress* getServerIPaddr() { return(server ? server->getIPaddr() : NULL); }
75
76
0
  inline const char* getCliName(char* buf, u_int len) {
77
0
    return (client ? client->getHostName(buf, len) : (char *)"");
78
0
  };
79
0
  inline const char* getSrvName(char* buf, u_int len) {
80
0
    return (server ? server->getHostName(buf, len) : (char *)"");
81
0
  };
82
0
  inline const char* getCliIPHex(char* buf, u_int len) {
83
0
    return (client ? client->getIPHex(buf, len) : (char *)"");
84
0
  };
85
0
  inline const char* getSrvIPHex(char* buf, u_int len) {
86
0
    return (server ? server->getIPHex(buf, len) : (char *)"");
87
0
  };
88
0
  inline const char* getFlowDeviceIP(char* buf, u_int len) {
89
0
    return (flow_device_ip != 0 ? Utils::intoaV4(flow_device_ip, buf, len) : (char *)"");
90
0
  };
91
0
  inline bool isNotGuessed() { return(is_not_guessed); };
92
93
  /* Setters */
94
0
  inline void setProtoName(char* _proto_name) {
95
0
    if (proto_name) { free(proto_name); }
96
0
    proto_name = strdup(_proto_name);
97
0
  };
98
0
  inline void setInfoKey(string _key) { 
99
0
    if (info_key) { free(info_key); }
100
0
    info_key = strdup(_key.c_str());
101
0
  };
102
0
  inline void setProtoKey(u_int64_t _key) { proto_key = _key; };
103
0
  inline void setKey(u_int64_t _key) { key = _key; };
104
0
  inline void setVlanId(u_int16_t _vlan_id) { vlan_id = _vlan_id; };
105
0
  inline void setClient(IpAddress* _ip, Host* _host) {
106
0
    if(!client) { client = new (std::nothrow) FlowsHostInfo(_ip, _host); }
107
0
  };
108
0
  inline void setServer(IpAddress* _ip, Host* _host) {
109
0
    if(!server) { server = new (std::nothrow) FlowsHostInfo(_ip, _host); }
110
0
  };
111
0
  inline void setSrvPort(u_int16_t _srv_port) { srv_port = _srv_port; };
112
0
  inline void setFlowDeviceIP(u_int32_t _flow_device_ip) { flow_device_ip = _flow_device_ip; };
113
114
  void setFlowIPVLANDeviceIP(Flow *f);
115
116
0
  inline bool isCliInMem() { return (client->isHostInMem()); };
117
0
  inline bool isSrvInMem() { return (server->isHostInMem()); };
118
0
  inline void setIsNotGuessed(bool isNotGuessed) { is_not_guessed = isNotGuessed; };
119
120
  void incFlowStats(const IpAddress* _client, const IpAddress* _server,
121
                           u_int64_t bytes_sent, u_int64_t bytes_rcvd,
122
                           u_int32_t score);
123
};
124
125
struct aggregated_stats {
126
  std::unordered_map<u_int64_t, AggregatedFlowsStats *> count;
127
  std::unordered_map<string, AggregatedFlowsStats *> info_count;
128
  IpAddress *ip_addr;
129
  u_int16_t vlan_id;
130
  u_int32_t flow_device_ip;
131
  u_int32_t in_if_index;
132
  u_int32_t out_if_index;
133
};
134
135
#endif /* _FLOWS_STATS_H_ */