Module: sip-router
Branch: master
Commit: f6673e2930b6c4e28af60f8ed4c2ea233c944ab4
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f6673e2…
Author: Ovidiu Sas <osas(a)voipembedded.com>
Committer: Ovidiu Sas <osas(a)voipembedded.com>
Date: Wed Sep 29 11:11:36 2010 -0400
utils/kamctl: new lcr function: eval_weights
- evaluates the probability of a GW being selected based on given weigths
---
utils/kamctl/kamctl | 32 ++++++++++++++++++++++++++++++--
utils/kamctl/kamctl.base | 1 +
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/utils/kamctl/kamctl b/utils/kamctl/kamctl
index be65363..48db7dd 100755
--- a/utils/kamctl/kamctl
+++ b/utils/kamctl/kamctl
@@ -1114,15 +1114,15 @@ trusted() {
### LCR management
#
lcr() {
- require_dbengine
- require_ctlengine
case $1 in
show_gws)
+ require_dbengine
mecho "lcr gateways"
QUERY="select * FROM $GW_TABLE ORDER BY $LCR_ID_COLUMN, $LCR_GW_GRPID_COLUMN;
"
$DBROCMD "$QUERY"
;;
show_routes)
+ require_dbengine
mecho "lcr routes"
QUERY="select * FROM $LCR_TABLE ORDER BY $LCR_ID_COLUMN, $LCR_PREFIX_COLUMN;
"
$DBROCMD "$QUERY"
@@ -1136,6 +1136,34 @@ lcr() {
dump_routes)
$RPCCMD lcr.dump_lcrs
;;
+ eval_weights)
+ shift
+ $AWK 'BEGIN {
+ if (ARGC < 2) {
+ printf("Usage: lcr eval_weights <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);
+ }
+ }' $@
+ ;;
*)
usage_lcr
exit 1
diff --git a/utils/kamctl/kamctl.base b/utils/kamctl/kamctl.base
index 1949711..11c398d 100644
--- a/utils/kamctl/kamctl.base
+++ b/utils/kamctl/kamctl.base
@@ -354,6 +354,7 @@ cat <<EOF
lcr dump_gws....... show in memory gateways
lcr dump_routes.... show in memory routes
lcr reload ........ reload lcr gateways and routes
+ lcr eval_weights .. evaluates probability for given GW's weights
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_lcr"