Coverage Report

Created: 2024-02-25 06:37

/src/ntopng/include/ObservationPoint.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *
3
 * (C) 2013-24 - 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 _OBSERVATION_POINT_H
23
#define _OBSERVATION_POINT_H
24
25
#include "ntop_includes.h"
26
27
class Score;
28
29
class ObservationPoint : public GenericHashEntry,
30
                         public GenericTrafficElement,
31
                         public Score {
32
 private:
33
  /* Note: country name can be more then 2 chars, see
34
   * https://www.iso.org/iso-3166-country-codes.html
35
   */
36
  u_int16_t obs_point;
37
  NetworkStats dirstats;
38
  u_int64_t num_flows;
39
  ndpi_bitmap *exporter_list;
40
  std::atomic<bool> delete_requested;
41
  bool remove_entry;
42
43
0
  inline void incSentStats(time_t t, u_int64_t num_pkts, u_int64_t num_bytes) {
44
0
    if (first_seen == 0)
45
0
      first_seen = t, last_seen = iface->getTimeLastPktRcvd();
46
0
    sent.incStats(t, num_pkts, num_bytes);
47
0
  }
48
49
0
  inline void incRcvdStats(time_t t, u_int64_t num_pkts, u_int64_t num_bytes) {
50
0
    rcvd.incStats(t, num_pkts, num_bytes);
51
0
  }
52
53
 public:
54
  ObservationPoint(NetworkInterface *_iface, u_int16_t obs_point);
55
  ~ObservationPoint();
56
57
  void set_hash_entry_state_idle();
58
  bool is_hash_entry_state_idle_transition_ready();
59
60
0
  inline u_int64_t getNumFlows() { return num_flows; }
61
0
  inline u_int16_t getNumHosts() { return getUses(); }
62
0
  inline u_int32_t key() { return obs_point; }
63
0
  inline u_int32_t getObsPoint() { return obs_point; }
64
0
  inline void addProbeIp(u_int32_t probe_ip) {
65
0
    ndpi_bitmap_set(exporter_list, probe_ip);
66
0
  }
67
68
0
  bool equal(u_int16_t _obs_point) { return (obs_point == _obs_point); }
69
0
  inline bool equal(ObservationPoint *_obs_point) {
70
0
    return (obs_point == _obs_point->key());
71
0
  }
72
73
0
  inline void incFlows() { num_flows++; }
74
75
  inline void incStats(time_t when, u_int16_t proto_id, u_int64_t sent_packets,
76
                       u_int64_t sent_bytes, u_int64_t rcvd_packets,
77
0
                       u_int64_t rcvd_bytes) {
78
0
    if (!remove_entry) {
79
0
      if (ndpiStats || (ndpiStats = new nDPIStats()))
80
0
        ndpiStats->incStats(when, proto_id, sent_packets, sent_bytes,
81
0
                            rcvd_packets, rcvd_bytes);
82
0
      incSentStats(when, sent_packets, sent_bytes);
83
0
      incRcvdStats(when, rcvd_packets, rcvd_bytes);
84
0
    }
85
0
  }
86
87
  virtual void updateStats(const struct timeval *tv);
88
89
  void lua(lua_State *vm, DetailsLevel details_level, bool asListElement);
90
91
0
  inline void serialize(json_object *obj, DetailsLevel details_level) {
92
0
    if (!remove_entry) {
93
0
      GenericHashEntry::getJSONObject(obj, details_level);
94
0
      GenericTrafficElement::getJSONObject(obj, iface);
95
0
      json_object_object_add(obj, "flows", json_object_new_int64(num_flows));
96
0
    }
97
0
  }
98
0
  inline char *getSerializationKey(char *buf, uint bufsize) {
99
0
    snprintf(buf, bufsize, OBS_POINT_SERIALIZED_KEY, iface->get_id(),
100
0
             obs_point);
101
0
    return (buf);
102
0
  }
103
104
0
  inline void setDeleteRequested(bool to_be_deleted) {
105
0
    delete_requested = to_be_deleted;
106
0
  }
107
0
  inline void deleteObsStats() { remove_entry = true; }
108
};
109
110
#endif /* _OBSERVATION_POINT_H */