Commit 53742f4e authored by Håvard Moås's avatar Håvard Moås
Browse files

Update IPFIXLIB to really-really fix bandwith calculation issues. havard.mork@gmail.com

git-svn-id: file:///home/svn/mapi/branches/haavardm-mapi@52 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 401022e7
......@@ -395,8 +395,7 @@ static u_int getMSDistance(unsigned long long new, unsigned long long old) {
static void calculateBitrate(u_int divisor, u_int64_t stamp, u_int64_t *lastupdate,
u_int32_t *rate_best_max, u_int32_t *rate_best_min,
u_int32_t *averager, u_int16_t *avgpos, u_int len,
u_int force) {
u_int32_t *averager, u_int16_t *avgpos, u_int len) {
/* 'divisor' is the number of milliseconds that one slot consists of. */
/* i.e. for a total 1sec interval, there are 10x 100ms-intervals, which */
/* implies value of 100 expected */
......@@ -413,7 +412,7 @@ static void calculateBitrate(u_int divisor, u_int64_t stamp, u_int64_t *lastupda
u_int32_t mult = 100/divisor;
// First: If advancing, then sum up and check for record first.
if(numSlotsAdvance > 0 || force) {
if(numSlotsAdvance > 0) {
u_int32_t sum = 0;
for(i=0; i<BITRATE_AVERAGER_SLOTS; i++) {
sum += averager[i];
......@@ -435,10 +434,6 @@ static void calculateBitrate(u_int divisor, u_int64_t stamp, u_int64_t *lastupda
*rate_best_max = sum;
}
/* If 'force', then all we wanted was to update stats */
if(force)
return;
*lastupdate = stamp;
}
......@@ -467,8 +462,7 @@ static void calculateBitrate(u_int divisor, u_int64_t stamp, u_int64_t *lastupda
}
static void updateBitrateCalculation(np_ctxt_t *npctxt, HashBucket *bkt, u_int len,
unsigned long long stamp, u_int direction,
u_int force) {
unsigned long long stamp, u_int direction) {
// Calculate average bitrate of a period of time
// This is done by continuously updating the bkt->bitrateAverager1sec array
// and summing this at the end of each time slot (which is .1 secs)
......@@ -482,12 +476,12 @@ static void updateBitrateCalculation(np_ctxt_t *npctxt, HashBucket *bkt, u_int l
calculateBitrate(100, stamp, &bkt->src2dstBitrateLastUpdate1sec,
&bkt->src2dstRateMax1sec, &bkt->src2dstRateMin1sec,
bkt->src2dstBitrateAverager1sec,&bkt->src2dstBitrateAverager1secPos,
len, force);
len);
else
calculateBitrate(100, stamp, &bkt->dst2srcBitrateLastUpdate1sec,
&bkt->dst2srcRateMax1sec, &bkt->dst2srcRateMin1sec,
bkt->dst2srcBitrateAverager1sec,&bkt->dst2srcBitrateAverager1secPos,
len, force);
len);
}
if((npctxt->bitrateCalcEnabled & BITRATECALC_100MS) != 0) {
......@@ -495,12 +489,12 @@ static void updateBitrateCalculation(np_ctxt_t *npctxt, HashBucket *bkt, u_int l
calculateBitrate(10, stamp, &bkt->src2dstBitrateLastUpdate100ms,
&bkt->src2dstRateMax100ms, &bkt->src2dstRateMin100ms,
bkt->src2dstBitrateAverager100ms,&bkt->src2dstBitrateAverager100msPos,
len, force);
len);
else
calculateBitrate(10, stamp, &bkt->dst2srcBitrateLastUpdate100ms,
&bkt->dst2srcRateMax100ms, &bkt->dst2srcRateMin100ms,
bkt->dst2srcBitrateAverager100ms,&bkt->dst2srcBitrateAverager100msPos,
len, force);
len);
}
if((npctxt->bitrateCalcEnabled & BITRATECALC_10MS) != 0) {
......@@ -508,12 +502,12 @@ static void updateBitrateCalculation(np_ctxt_t *npctxt, HashBucket *bkt, u_int l
calculateBitrate(1, stamp, &bkt->src2dstBitrateLastUpdate10ms,
&bkt->src2dstRateMax10ms,&bkt->src2dstRateMin10ms,
bkt->src2dstBitrateAverager10ms,&bkt->src2dstBitrateAverager10msPos,
len, force);
len);
else
calculateBitrate(1, stamp, &bkt->dst2srcBitrateLastUpdate10ms,
&bkt->dst2srcRateMax10ms, &bkt->dst2srcRateMin10ms,
bkt->dst2srcBitrateAverager10ms,&bkt->dst2srcBitrateAverager10msPos,
len, force);
len);
}
}
......@@ -664,7 +658,7 @@ void addPktToHash(np_ctxt_t *npctxt,
bkt->src2dstTcpFlags |= flags; /* Do not move this line before updateTcpFlags(...) */
updatePacketSizeStats(npctxt,bkt,len,0);
if(npctxt->bitrateCalcEnabled!=0) {
updateBitrateCalculation(npctxt,bkt,len, stamp,0,0);
updateBitrateCalculation(npctxt,bkt,len, stamp,0);
}
bkt->src2dstOctetDeltaCount = bkt->src2dstOctetDeltaCount + len;
......@@ -689,7 +683,7 @@ void addPktToHash(np_ctxt_t *npctxt,
bkt->dst2srcTcpFlags |= flags; /* Do not move this line before updateTcpFlags(...) */
updatePacketSizeStats(npctxt,bkt,len,1);
if(npctxt->bitrateCalcEnabled!=0) {
updateBitrateCalculation(npctxt,bkt,len, stamp,1,0);
updateBitrateCalculation(npctxt,bkt,len, stamp,1);
}
bkt->dst2srcOctetDeltaCount = bkt->dst2srcOctetDeltaCount + len;
......@@ -766,10 +760,10 @@ void addPktToHash(np_ctxt_t *npctxt,
// Clear the "time slot" buffers that is used to efficiently find highest/lowest
// average xfer amount for a period of time.
// Clear all, also if only one will be used.
memset(bkt->src2dstBitrateAverager1sec, '\0', sizeof(u_int32_t)*BITRATE_AVERAGER_SLOTS);
memset(bkt->src2dstBitrateAverager1sec, 0xFF, sizeof(u_int32_t)*BITRATE_AVERAGER_SLOTS);
memset(bkt->src2dstBitrateAverager100ms, 0xFF, sizeof(u_int32_t)*BITRATE_AVERAGER_SLOTS);
memset(bkt->src2dstBitrateAverager10ms, 0xFF, sizeof(u_int32_t)*BITRATE_AVERAGER_SLOTS);
memset(bkt->dst2srcBitrateAverager1sec, '\0', sizeof(u_int32_t)*BITRATE_AVERAGER_SLOTS);
memset(bkt->dst2srcBitrateAverager1sec, 0xFF, sizeof(u_int32_t)*BITRATE_AVERAGER_SLOTS);
memset(bkt->dst2srcBitrateAverager100ms, 0xFF, sizeof(u_int32_t)*BITRATE_AVERAGER_SLOTS);
memset(bkt->dst2srcBitrateAverager10ms, 0xFF, sizeof(u_int32_t)*BITRATE_AVERAGER_SLOTS);
bkt->src2dstBitrateLastUpdate1sec = stamp;
......@@ -806,7 +800,7 @@ void addPktToHash(np_ctxt_t *npctxt,
bkt->src2dstMaxPktSize = bkt->dst2srcMaxPktSize = 0x0000;
updatePacketSizeStats(npctxt,bkt,len,0);
if(npctxt->bitrateCalcEnabled!=0) {
updateBitrateCalculation(npctxt,bkt,len,stamp,0,0);
updateBitrateCalculation(npctxt,bkt,len,stamp,0);
}
if(src.ipVersion == 4 && proto == IPPROTO_TCP)
......@@ -1041,12 +1035,6 @@ void walkHash(np_ctxt_t *npctxt, int flushHash) {
#endif
myNextBucket = myBucket->next;
// Flush bitrate calculation before proceeding
if(npctxt->bitrateCalcEnabled!=0) {
updateBitrateCalculation(npctxt,myBucket,0,0,0,1);
}
queueBucketToExport(npctxt, myBucket);
numBucketsExported++;
if(numBucketsExported >= npctxt->minNumFlowsPerPacket) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment