/* 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));
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);
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. */
}
}
+ if (table->common->num_flows > 0) {
+ table->common->avg_rate = table->common->rate / table->common->num_flows;
+ }
+
table->common->max_flow_rate = largest_rate;
}