X-Git-Url: http://git.onelab.eu/?p=distributedratelimiting.git;a=blobdiff_plain;f=drl%2Festimate.c;h=8b3bb9ab97a0d9c6820d338af3b423c4ce0741b9;hp=17a0fd89b5b69c646d1fbf193be1b5ae1c686e35;hb=5196115d2999ca57181ef592e7907d7afb14c1b3;hpb=f54a05e4b5bef7c5c90663765656a9084d622e82 diff --git a/drl/estimate.c b/drl/estimate.c index 17a0fd8..8b3bb9a 100644 --- a/drl/estimate.c +++ b/drl/estimate.c @@ -18,8 +18,12 @@ #include "ratetypes.h" /* needs util and pthread.h */ #include "logging.h" +#define PRINT_COUNTER_RESET (0) + extern uint8_t system_loglevel; -static int printcounter = 8; +static int printcounter = PRINT_COUNTER_RESET - 1; + +uint8_t do_enforcement = 0; /** * Called for each identity each estimate interval. Uses flow table information @@ -101,8 +105,8 @@ static double allocate_fps_over_limit(identity_t *ident) { if (ident->common.max_flow_rate > 0) { ideal_weight = (double) ident->locallimit / (double) ident->common.max_flow_rate; - printlog(LOG_DEBUG, "%.3f %d %d FlowCount, TotalRate, MaxRate\n", - ideal_weight, ident->common.rate, ident->common.max_flow_rate); + printlog(LOG_DEBUG, "%.3f %d %d %d FlowCount, Limit, MaxRate, TotalRate\n", + ideal_weight, ident->locallimit, ident->common.max_flow_rate, ident->common.rate); } else { ideal_weight = 1; } @@ -118,7 +122,7 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight) { common_accounting_t *ftable = &ident->common; /* Common flow table info */ uint32_t local_rate = ftable->rate; uint32_t ideallocal = 0; - double peer_weights; /* sum of weights of all other limiters */ + double peer_weights; /* sum of weights of all other limiters */ double idealweight = 0; double last_portion = 0; double this_portion = 0; @@ -233,8 +237,10 @@ static uint32_t allocate_fps(identity_t *ident, double total_weight) { } if (printcounter <= 0) { - printlog(LOG_WARN, "%d %.1f %.1f %.1f\n", local_rate, idealweight, ident->localweight, total_weight); - printcounter = 8; + printlog(LOG_WARN, "%d %.2f %.2f %.2f %d %d %d %d %d %d ", local_rate, idealweight, + ident->localweight, total_weight, ftable->num_flows, ftable->num_flows_5k, ftable->num_flows_10k, + ftable->num_flows_20k, ftable->num_flows_50k, ftable->avg_rate); + printcounter = PRINT_COUNTER_RESET; } else { printcounter -= 1; } @@ -370,16 +376,22 @@ static void enforce(limiter_t *limiter, identity_t *ident) { printf("FPS: Setting local limit to %d\n", ident->locallimit); } printlog(LOG_DEBUG, "%d Limit ID:%d\n", ident->locallimit, ident->id); - printlog(LOG_WARN, "%d\n", ident->locallimit); + + if (printcounter == PRINT_COUNTER_RESET) { + printlog(LOG_WARN, "%d\n", ident->locallimit); + } snprintf(cmd, CMD_BUFFER_SIZE, "/sbin/tc class change dev eth0 parent 1:%x classid 1:%x htb rate 8bit ceil %dbps quantum 1600", ident->htb_parent, ident->htb_node, ident->locallimit); - ret = system(cmd); + if (do_enforcement) { + ret = system(cmd); - if (ret) { - /* FIXME: call failed. What to do? */ + if (ret) { + /* FIXME: call failed. What to do? */ + printlog(LOG_CRITICAL, "***TC call failed?***\n"); + } } break; @@ -423,10 +435,13 @@ static void enforce(limiter_t *limiter, identity_t *ident) { ident->leaves[i]->xid, ident->leaves[i]->xid, (100 * ident->leaves[i]->drop_prob)); #endif - ret = system(cmd); + if (do_enforcement) { + ret = system(cmd); - if (ret) { - /* FIXME: call failed. What to do? */ + if (ret) { + /* FIXME: call failed. What to do? */ + printlog(LOG_CRITICAL, "***TC call failed?***\n"); + } } } @@ -496,6 +511,7 @@ void handle_estimation(void *arg) { sigemptyset(&signal_mask); sigaddset(&signal_mask, SIGHUP); + sigaddset(&signal_mask, SIGUSR1); pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); /* Determine the number of intervals we should wait before hitting the