/src/ntopng/include/PacketStats.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * (C) 2013-26 - 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 _PACKETS_STATS_H_ |
23 | | #define _PACKETS_STATS_H_ |
24 | | |
25 | | #include "ntop_includes.h" |
26 | | |
27 | | class PacketStats { |
28 | | private: |
29 | | u_int64_t upTo64, upTo128, upTo256, upTo512, upTo1024, upTo1518, upTo2500, |
30 | | upTo6500, upTo9000, above9000; |
31 | | u_int64_t syn, synack, finack, rst; |
32 | | |
33 | | /* Function to increase TCP flag stats when the flags are |
34 | | read from a single TCP segment. Call this for packet interfaces */ |
35 | | void incFlagStatsSingleSegment(u_int8_t flags); |
36 | | /* Function to increase TCP flag stats when the flags are cumulative, |
37 | | i.e., when they are the logical OR among the flags detected across |
38 | | multiple TCP segments. Call this for non-packet interfaces such |
39 | | the ZMQ */ |
40 | | void incFlagStatsCumulative(u_int8_t flags); |
41 | | |
42 | | public: |
43 | | PacketStats(); |
44 | | |
45 | | void resetStats(); |
46 | | void incFlagStats(u_int8_t flags, bool cumulative_flags); |
47 | | void incStats(u_int num_pkts, u_int pkt_len); |
48 | | json_object* getJSONObject(); |
49 | | void lua(lua_State* vm, const char* label); |
50 | | |
51 | 0 | inline u_int64_t getNumSYN() { return (syn); } |
52 | 0 | inline u_int64_t getNumSYNACK() { return (synack); } |
53 | 0 | inline u_int64_t getNumFINACK() { return (finack); } |
54 | 0 | inline u_int64_t getNumRST() { return (rst); } |
55 | | |
56 | 0 | inline void sum(PacketStats* s) const { |
57 | 0 | s->upTo64 += upTo64, s->upTo128 += upTo128, s->upTo128 += upTo128, |
58 | 0 | s->upTo256 += upTo256, s->upTo512 += upTo512, s->upTo1024 += upTo1024, |
59 | 0 | s->upTo1518 += upTo1518, s->upTo2500 += upTo2500, |
60 | 0 | s->upTo6500 += upTo6500, s->upTo9000 += upTo9000, |
61 | 0 | s->above9000 += above9000, s->syn += syn, s->synack += synack, |
62 | 0 | s->finack += finack, s->rst += rst; |
63 | 0 | }; |
64 | | }; |
65 | | |
66 | | #endif /* _PACKETS_STATS_H_ */ |