Skip to content

Commit

Permalink
Merge pull request #532 from piorek94/agg_zero_division_fix
Browse files Browse the repository at this point in the history
fix zero division issue in aggregation mode
  • Loading branch information
phaag authored May 24, 2024
2 parents 2ac8675 + 825ec11 commit daf20df
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions src/nfdump/nflowcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,12 @@ static uint64_t order_pps_in(FlowHashRecord_t *record) {
if (unlikely(record->msecLast == 0)) return 0;

uint64_t duration = record->msecLast - record->msecFirst;
uint64_t packets = record->inPackets;
return (1000LL * packets) / duration;
if (duration == 0)
return 0;
else {
uint64_t packets = record->inPackets;
return (1000LL * packets) / duration;
}

} // End of order_pps_in

Expand All @@ -631,8 +635,12 @@ static uint64_t order_pps_out(FlowHashRecord_t *record) {
if (unlikely(record->msecLast == 0)) return 0;

uint64_t duration = record->msecLast - record->msecFirst;
uint64_t packets = record->outPackets;
return (1000LL * packets) / duration;
if (duration == 0)
return 0;
else {
uint64_t packets = record->outPackets;
return (1000LL * packets) / duration;
}

} // End of order_pps_out

Expand All @@ -641,8 +649,12 @@ static uint64_t order_pps_inout(FlowHashRecord_t *record) {
if (unlikely(record->msecLast == 0)) return 0;

uint64_t duration = record->msecLast - record->msecFirst;
uint64_t packets = record->inPackets + record->outPackets;
return (1000LL * packets) / duration;
if (duration == 0)
return 0;
else {
uint64_t packets = record->inPackets + record->outPackets;
return (1000LL * packets) / duration;
}

} // End of order_pps_inout

Expand All @@ -651,8 +663,12 @@ static uint64_t order_bps_in(FlowHashRecord_t *record) {
if (unlikely(record->msecLast == 0)) return 0;

uint64_t duration = record->msecLast - record->msecFirst;
uint64_t bytes = record->inBytes;
return (8000LL * bytes) / duration; /* 8 bits per Octet - x 1000 for msec */
if (duration == 0)
return 0;
else {
uint64_t bytes = record->inBytes;
return (8000LL * bytes) / duration; /* 8 bits per Octet - x 1000 for msec */
}

} // End of order_bps_in

Expand All @@ -661,8 +677,12 @@ static uint64_t order_bps_out(FlowHashRecord_t *record) {
if (unlikely(record->msecLast == 0)) return 0;

uint64_t duration = record->msecLast - record->msecFirst;
uint64_t bytes = record->outBytes;
return (8000LL * bytes) / duration; /* 8 bits per Octet - x 1000 for msec */
if (duration == 0)
return 0;
else {
uint64_t bytes = record->outBytes;
return (8000LL * bytes) / duration; /* 8 bits per Octet - x 1000 for msec */
}

} // End of order_bps_out

Expand All @@ -671,8 +691,12 @@ static uint64_t order_bps_inout(FlowHashRecord_t *record) {
if (unlikely(record->msecLast == 0)) return 0;

uint64_t duration = record->msecLast - record->msecFirst;
uint64_t bytes = record->inBytes + record->outBytes;
return (8000LL * bytes) / duration; /* 8 bits per Octet - x 1000 for msec */
if (duration == 0)
return 0;
else {
uint64_t bytes = record->inBytes + record->outBytes;
return (8000LL * bytes) / duration; /* 8 bits per Octet - x 1000 for msec */
}

} // End of order_bps_inout

Expand Down

0 comments on commit daf20df

Please sign in to comment.