1 /*
2 * Copyright (c) 2017, Peter Haag
3 * Copyright (c) 2014, Peter Haag
4 * Copyright (c) 2009, Peter Haag
5 * Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * * Neither the name of the author nor the names of its contributors may be
17 * used to endorse or promote products derived from this software without
18 * specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34
35 // to improve readability - separate some code blocks in functions and make them inline
36 // as it's called for every single flow
37 static inline void UpdateStat(stat_record_t *stat_record, master_record_t *master_record);
38
UpdateStat(stat_record_t * stat_record,master_record_t * master_record)39 static inline void UpdateStat(stat_record_t *stat_record, master_record_t *master_record) {
40
41 switch (master_record->prot) {
42 case IPPROTO_ICMP:
43 case IPPROTO_ICMPV6:
44 stat_record->numflows_icmp += master_record->aggr_flows ? master_record->aggr_flows : 1;
45 stat_record->numpackets_icmp += master_record->dPkts;
46 stat_record->numpackets_icmp += master_record->out_pkts;
47 stat_record->numbytes_icmp += master_record->dOctets;
48 stat_record->numbytes_icmp += master_record->out_bytes;
49 break;
50 case IPPROTO_TCP:
51 stat_record->numflows_tcp += master_record->aggr_flows ? master_record->aggr_flows : 1;
52 stat_record->numpackets_tcp += master_record->dPkts;
53 stat_record->numpackets_tcp += master_record->out_pkts;
54 stat_record->numbytes_tcp += master_record->dOctets;
55 stat_record->numbytes_tcp += master_record->out_bytes;
56 break;
57 case IPPROTO_UDP:
58 stat_record->numflows_udp += master_record->aggr_flows ? master_record->aggr_flows : 1;
59 stat_record->numpackets_udp += master_record->dPkts;
60 stat_record->numpackets_udp += master_record->out_pkts;
61 stat_record->numbytes_udp += master_record->dOctets;
62 stat_record->numbytes_udp += master_record->out_bytes;
63 break;
64 default:
65 stat_record->numflows_other += master_record->aggr_flows ? master_record->aggr_flows : 1;
66 stat_record->numpackets_other += master_record->dPkts;
67 stat_record->numpackets_other += master_record->out_pkts;
68 stat_record->numbytes_other += master_record->dOctets;
69 stat_record->numbytes_other += master_record->out_bytes;
70 }
71 stat_record->numflows += master_record->aggr_flows ? master_record->aggr_flows : 1;
72 stat_record->numpackets += master_record->dPkts;
73 stat_record->numpackets += master_record->out_pkts;
74 stat_record->numbytes += master_record->dOctets;
75 stat_record->numbytes += master_record->out_bytes;
76
77 if ( master_record->first < stat_record->first_seen ) {
78 stat_record->first_seen = master_record->first;
79 stat_record->msec_first = master_record->msec_first;
80 }
81 if ( master_record->first == stat_record->first_seen &&
82 master_record->msec_first < stat_record->msec_first )
83 stat_record->msec_first = master_record->msec_first;
84
85 if ( master_record->last > stat_record->last_seen ) {
86 stat_record->last_seen = master_record->last;
87 stat_record->msec_last = master_record->msec_last;
88 }
89 if ( master_record->last == stat_record->last_seen &&
90 master_record->msec_last > stat_record->msec_last )
91 stat_record->msec_last = master_record->msec_last;
92
93 } // End of UpdateStat
94