X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drl%2Fstandard.c;h=5c6a6d8537fe05f1f7bee39599d67e8b6a14388f;hb=d21104e4fb6400d420027b865833cae78697cda3;hp=93cb663e7c167835d2a2c7021b0278630257393b;hpb=f54a05e4b5bef7c5c90663765656a9084d622e82;p=distributedratelimiting.git diff --git a/drl/standard.c b/drl/standard.c index 93cb663..5c6a6d8 100644 --- a/drl/standard.c +++ b/drl/standard.c @@ -106,7 +106,7 @@ standard_flow *standard_table_lookup(standard_flow_table table, const key_flow * dst.s_addr = ntohl(flow->dest_ip); strcpy(sip, inet_ntoa(src)); strcpy(dip, inet_ntoa(dst)); - printlog(LOG_DEBUG, "ALLOC:%s:%hd -> %s:%hd\n", sip, + printlog(LOG_DEBUG, "ALLOC:%s:%hu -> %s:%hu\n", sip, flow->source_port, dip, flow->dest_port); } @@ -137,7 +137,6 @@ int standard_table_sample(standard_flow_table table, const key_flow *key) { void standard_table_remove(standard_flow_table table, standard_flow *flow) { key_flow key; uint32_t hash; - standard_flow *current, *prev; assert(flow); @@ -156,23 +155,23 @@ void standard_table_remove(standard_flow_table table, standard_flow *flow) { /* It's the head of the hash list. */ table->flows[hash] = flow->nexth; } else { + standard_flow *current, *prev; + prev = table->flows[hash]; - current = table->flows[hash]->nexth; - while (current != NULL) { + for (current = table->flows[hash]->nexth; current; current = current->nexth) { if (current == flow) { prev->nexth = flow->nexth; break; } else { prev = current; - current = current->next; } } - //assert(current != NULL); if (current == NULL) { - printlog(LOG_WARN, "Flow %p disappeared?\n", current); + printlog(LOG_CRITICAL, "Flow %p disappeared?\n", flow); } + assert(current != NULL); } /* Remove the flow from the linked list. */ @@ -244,6 +243,15 @@ void standard_table_update_flows(standard_flow_table table, struct timeval now, 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. */ + time_delta = timeval_subtract(now, table->common->last_update); if (time_delta <= 0) { @@ -295,6 +303,28 @@ void standard_table_update_flows(standard_flow_table table, struct timeval now, maxflowrate = current->rate; } + if (current->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; + table->common->num_flows += 1; + } else if (current->rate > 20480) { + table->common->num_flows_20k += 1; + table->common->num_flows_10k += 1; + table->common->num_flows_5k += 1; + table->common->num_flows += 1; + } else if (current->rate > 10240) { + table->common->num_flows_10k += 1; + table->common->num_flows_5k += 1; + table->common->num_flows += 1; + } else if (current->rate > 5120) { + table->common->num_flows_5k += 1; + table->common->num_flows += 1; + } else { + table->common->num_flows += 1; + } + src.s_addr = ntohl(current->source_ip); dst.s_addr = ntohl(current->dest_ip); strcpy(sip, inet_ntoa(src)); @@ -305,6 +335,10 @@ void standard_table_update_flows(standard_flow_table table, struct timeval now, current->rate); } + if (table->common->num_flows > 0) { + table->common->avg_rate = table->common->rate / table->common->num_flows; + } + printlog(LOG_DEBUG, "FLOW:--\n--\n"); table->common->max_flow_rate = maxflowrate;