Coverage Report

Created: 2025-05-16 06:24

/src/ntopng/include/ContinuousPingStats.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 _CONTINUOUS_PING_STATS_H_
23
#define _CONTINUOUS_PING_STATS_H_
24
25
#ifndef WIN32
26
27
struct cp_stats {
28
  u_int32_t num_ping_sent, num_ping_rcvd;
29
  float min_rtt, max_rtt, last_rtt, diff_sum, rtt_sum;
30
};
31
32
/* ***************************************** */
33
34
class ContinuousPingStats {
35
 private:
36
  time_t last_refresh;
37
  struct cp_stats stats;
38
  Ping *pinger;
39
40
 public:
41
0
  ContinuousPingStats(Ping *p) {
42
0
    pinger = p;
43
0
    reset();
44
0
    heartbeat();
45
0
  }
46
47
0
  inline Ping *getPinger() { return (pinger); }
48
0
  inline void getStats(struct cp_stats *out) {
49
0
    memcpy(out, &stats, sizeof(struct cp_stats));
50
0
  }
51
0
  inline void heartbeat() { last_refresh = time(NULL); }
52
0
  inline void incSent() { stats.num_ping_sent++; }
53
0
  inline time_t getLastHeartbeat() { return (last_refresh); }
54
  void update(float rtt);
55
  float getSuccessRate(float *min_rtt, float *max_rtt, float *jitter,
56
                       float *mean);
57
0
  inline void reset() { memset(&stats, 0, sizeof(stats)); }
58
};
59
60
#endif /* WIN32 */
61
62
#endif /* _CONTINUOUS_PING_STATS_H_ */