-/**
- * Determines the amount of FPS weight to allocate to the identity during each
- * estimate interval. Note that total_weight includes local weight.
- */
-static uint32_t allocate_fps_old(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 idealweight = 0;
- double last_portion = 0;
- double this_portion = 0;
-
- static int dampen = 0;
- int dampen_increase = 0;
-
- double ideal_under = 0;
- double ideal_over = 0;
-
- int regime = 0;
-
- /* two cases:
- 1. the aggregate is < limit
- 2. the aggregate is >= limit
- */
- peer_weights = total_weight - ident->last_localweight;
- if (peer_weights < 0) {
- peer_weights = 0;
- }
-
- if (dampen == 1) {
- int64_t rate_delta =
- (int64_t) ftable->inst_rate - (int64_t) ftable->last_inst_rate;
- double threshold =
- (double) ident->limit * (double) LARGE_INCREASE_PERCENTAGE / 10;
-
- if (rate_delta > threshold) {
- dampen_increase = 1;
- printlog(LOG_DEBUG, "DAMPEN: delta(%.3f) thresh(%.3f)\n",
- rate_delta, threshold);
- }
- }
-
- if (local_rate <= 0) {
- idealweight = 0;
- } else if (dampen_increase == 0 &&
- (ident->locallimit <= 0 || local_rate < close_enough(ident->locallimit) || ident->flowstart)) {
- /* We're under the limit - all flows are bottlenecked. */
- idealweight = allocate_fps_under_limit(ident, local_rate, peer_weights);
- ideal_over = allocate_fps_over_limit(ident);
- ideal_under = idealweight;
-
- if (ideal_over < idealweight) {
- idealweight = ideal_over;
- regime = 3;
- dampen = 2;
- } else {
- regime = 1;
- dampen = 0;
- }
-
- /* Apply EWMA */
- ident->localweight = (ident->localweight * ident->ewma_weight +
- idealweight * (1 - ident->ewma_weight));
-
- } else {
- idealweight = allocate_fps_over_limit(ident);
-
- /* Apply EWMA */
- ident->localweight = (ident->localweight * ident->ewma_weight +
- idealweight * (1 - ident->ewma_weight));
-
- /* This is the portion of the total weight in the system that was caused
- * by this limiter in the last interval. */
- last_portion = ident->last_localweight / total_weight;
-
- /* This is the fraction of the total weight in the system that our
- * proposed value for idealweight would use. */
- this_portion = ident->localweight / (peer_weights + ident->localweight);
-
- /* Dampen the large increase the first time... */
- if (dampen == 0 && (this_portion - last_portion > LARGE_INCREASE_PERCENTAGE)) {
- ident->localweight = ident->last_localweight + (LARGE_INCREASE_PERCENTAGE * total_weight);
- dampen = 1;
- } else {
- dampen = 2;
- }
-
- ideal_under = allocate_fps_under_limit(ident, local_rate, peer_weights);
- ideal_over = idealweight;
-
- regime = 2;
- }
-
- /* Convert weight into a rate - add in our new local weight */
- ident->total_weight = total_weight = ident->localweight + peer_weights;
-
- /* compute local allocation:
- if there is traffic elsewhere, use the weights
- otherwise do a L/n allocation */
- if (total_weight > 0) {
- //if (peer_weights > 0) {
- ideallocal = (uint32_t) (ident->localweight * ident->limit / total_weight);
- } else {
- ideallocal = ident->limit / (ident->comm.remote_node_count + 1);
- }
-
- printlog(LOG_DEBUG, "%.3f ActualWeight\n", ident->localweight);
-
- printlog(LOG_DEBUG, "%.3f %.3f %.3f %.3f Under / Over / Actual / Rate\n",
- ideal_under / (ideal_under + peer_weights),
- ideal_over / (ideal_over + peer_weights),
- ident->localweight / (ident->localweight + peer_weights),
- (double) local_rate / (double) ident->limit);
-
- printlog(LOG_DEBUG, "%.3f %.3f IdealUnd IdealOve\n",ideal_under,ideal_over);
-
- if (system_loglevel == LOG_DEBUG) {
- printf("local_rate: %d, idealweight: %.3f, localweight: %.3f, total_weight: %.3f\n",
- local_rate, idealweight, ident->localweight, total_weight);
- }
-
-#if 0
- if (printcounter <= 0) {
- struct timeval tv;
- double time_now;
-
- gettimeofday(&tv, NULL);
- time_now = (double) tv.tv_sec + (double) ((double) tv.tv_usec / (double) 1000000);
-
- printlog(LOG_WARN, "%.2f %d %.2f %.2f %.2f %d %d %d %d %d %d %d %d ", time_now, ftable->inst_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,
- ftable->max_flow_rate, ftable->max_flow_rate_flow_hash);
-
- printcounter = PRINT_COUNTER_RESET;
- } else {
- printcounter -= 1;
- }
-
- //printf("Dampen: %d, dampen_increase: %d, peer_weights: %.3f, regime: %d\n",
- // dampen, dampen_increase, peer_weights, regime);
-
- if (regime == 3) {
- printlog(LOG_DEBUG, "MIN: min said to use flow counting, which was %.3f when other method said %.3f.\n",
- ideal_over, ideal_under);
- }
- See print_statistics()
-#endif
-
- printlog(LOG_DEBUG, "ideallocal is %d\n", ideallocal);
-
- return(ideallocal);
-}
-