X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drl%2Fsamplehold.c;h=9a309955629cfa71ae8d6801962f45e0414f3c26;hb=8675c0b77ad3e361f4255ce61881a79061c5238d;hp=8c566d4d9a4b85ce02536b0c3a80a04b3e93ae24;hpb=f83340496f632165030cc92cd98408a87082f6b1;p=distributedratelimiting.git diff --git a/drl/samplehold.c b/drl/samplehold.c index 8c566d4..9a30995 100644 --- a/drl/samplehold.c +++ b/drl/samplehold.c @@ -86,14 +86,14 @@ sampled_flow_table sampled_table_create(uint32_t (*hash_function)(const key_flow /* Allocate the backing and give it a little bit extra to deal with variance. */ table->largest = NULL; - table->backing = malloc(sizeof(sampled_flow) * table->capacity * 1.05); + table->backing = malloc(sizeof(sampled_flow) * table->capacity * SAMPLEHOLD_BONUS_FACTOR); if (table->backing == NULL) { free(table); return NULL; } - memset(table->backing, 0, sizeof(sampled_flow) * table->capacity); + memset(table->backing, 0, sizeof(sampled_flow) * table->capacity * SAMPLEHOLD_BONUS_FACTOR); srand(time(NULL)); @@ -279,6 +279,15 @@ void sampled_table_update_flows(sampled_flow_table table, struct timeval now, do struct in_addr src, dst; char sip[22], dip[22]; + /* Reset statistics. */ + table->common->num_flows = 0; + table->common->num_flows_5k = 0; + table->common->num_flows_10k = 0; + table->common->num_flows_20k = 0; + table->common->num_flows_50k = 0; + table->common->avg_rate = 0; + /* End statistics. */ + /* Update common aggregate information. */ time_delta = timeval_subtract(now, table->common->last_update); @@ -340,6 +349,22 @@ void sampled_table_update_flows(sampled_flow_table table, struct timeval now, do table->largest = &table->backing[i]; } + if (table->backing[i].rate > 51200) { + table->common->num_flows_50k += 1; + table->common->num_flows_20k += 1; + table->common->num_flows_10k += 1; + table->common->num_flows_5k += 1; + } else if (table->backing[i].rate > 20480) { + table->common->num_flows_20k += 1; + table->common->num_flows_10k += 1; + table->common->num_flows_5k += 1; + } else if (table->backing[i].rate > 10240) { + table->common->num_flows_10k += 1; + table->common->num_flows_5k += 1; + } else if (table->backing[i].rate > 5120) { + table->common->num_flows_5k += 1; + } + table->common->num_flows += 1; /* Print debugging info. */ @@ -354,6 +379,10 @@ void sampled_table_update_flows(sampled_flow_table table, struct timeval now, do } } + if (table->common->num_flows > 0) { + table->common->avg_rate = table->common->rate / table->common->num_flows; + } + table->common->max_flow_rate = largest_rate; }