/src/ntopng/include/Country.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 _COUNTRIES_H_ |
23 | | #define _COUNTRIES_H_ |
24 | | |
25 | | #include "ntop_includes.h" |
26 | | |
27 | | class Score; |
28 | | |
29 | | class Country : 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 | | char *country_name; |
37 | | NetworkStats dirstats; |
38 | | |
39 | 0 | inline void incStats(time_t t, u_int64_t num_pkts, u_int64_t num_bytes) { |
40 | 0 | last_seen = t, sent.incStats(t, num_pkts, num_bytes); |
41 | 0 | } |
42 | | |
43 | | public: |
44 | | Country(NetworkInterface *_iface, const char *country); |
45 | | ~Country(); |
46 | | |
47 | | void set_hash_entry_state_idle(); |
48 | | |
49 | 0 | inline u_int16_t getNumHosts() { return getUses(); } |
50 | 0 | inline u_int32_t key() { return Utils::stringHash(country_name); } |
51 | 0 | inline char *get_country_name() { return country_name; } |
52 | | |
53 | | bool equal(const char *country); |
54 | 0 | inline bool equal(Country *country) { |
55 | 0 | return equal(country->get_country_name()); |
56 | 0 | } |
57 | | |
58 | | inline void incEgress(time_t t, u_int64_t num_pkts, u_int64_t num_bytes, |
59 | 0 | bool broadcast) { |
60 | 0 | incStats(t, num_pkts, num_bytes); |
61 | 0 | dirstats.incEgress(t, num_pkts, num_bytes, broadcast); |
62 | 0 | } |
63 | | |
64 | | inline void incIngress(time_t t, u_int64_t num_pkts, u_int64_t num_bytes, |
65 | 0 | bool broadcast) { |
66 | 0 | incStats(t, num_pkts, num_bytes); |
67 | 0 | dirstats.incIngress(t, num_pkts, num_bytes, broadcast); |
68 | 0 | } |
69 | | |
70 | | inline void incInner(time_t t, u_int64_t num_pkts, u_int64_t num_bytes, |
71 | 0 | bool broadcast) { |
72 | 0 | incStats(t, num_pkts, num_bytes); |
73 | 0 | dirstats.incInner(t, num_pkts, num_bytes, broadcast); |
74 | 0 | } |
75 | | |
76 | | void lua(lua_State *vm, DetailsLevel details_level, bool asListElement); |
77 | | |
78 | | void serialize(json_object *obj, DetailsLevel details_level); |
79 | 0 | inline char *getSerializationKey(char *buf, uint bufsize) { |
80 | 0 | snprintf(buf, bufsize, COUNTRY_SERIALIZED_KEY, iface->get_id(), |
81 | 0 | country_name); |
82 | 0 | return (buf); |
83 | 0 | } |
84 | | }; |
85 | | |
86 | | #endif /* _COUNTRIES_H_ */ |