Module: sip-router Branch: master Commit: 2800504202dfb773baed7212949918848f0ea716 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=28005042...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Wed Sep 29 13:56:05 2010 +0300
modules/lcr: added awk version of lcr_weight_test script
---
modules/lcr/utils/lcr_weight_test.awk | 37 +++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/modules/lcr/utils/lcr_weight_test.awk b/modules/lcr/utils/lcr_weight_test.awk new file mode 100755 index 0000000..fdb9a37 --- /dev/null +++ b/modules/lcr/utils/lcr_weight_test.awk @@ -0,0 +1,37 @@ +#!/usr/bin/awk -f + +# This script can be used to find out actual probabilities +# that correspond to a list of LCR gateway weights. + +BEGIN { + + if (ARGC < 2) { + printf("Usage: lcr_weight_test.php <list of weights (integers 1-254)>\n"); + exit; + } + + iters = 100000; + + for (i = 1; i < ARGC; i++) { + counts[i] = 0; + } + + for (i = 1; i <= iters; i++) { + for (j = 1; j < ARGC; j++) { + elem[j] = ARGV[j] * rshift(int(2147483647 * rand()), 8); + }; + at = 1; + max = elem[at]; + for (j = 2; j < ARGC; j++) { + if (elem[j] > max) { + max = elem[j]; + at = j; + } + } + counts[at] = counts[at] + 1; + } + + for (i = 1; i < ARGC; i++) { + printf("weight %d probability %.4f\n", ARGV[i], counts[i]/iters); + } +}