Browse code

cr: remove obselete cr_prime_route function, use cr_nofallback_route instead

Henning Westerholt authored on 13/01/2010 09:59:44
Showing 7 changed files
... ...
@@ -47,13 +47,10 @@ Henning Westerholt
47 47
               4.2. cr_route(carrier, domain, prefix_matching,
48 48
                       rewrite_user, hash_source, descavp)
49 49
 
50
-              4.3. cr_prime_route(carrier, domain, prefix_matching,
50
+              4.3. cr_nofallback_route(carrier, domain, prefix_matching,
51 51
                       rewrite_user, hash_source, descavp)
52 52
 
53
-              4.4. cr_nofallback_route(carrier, domain, prefix_matching,
54
-                      rewrite_user, hash_source, descavp)
55
-
56
-              4.5. cr_next_domain(carrier, domain, prefix_matching, host,
53
+              4.4. cr_next_domain(carrier, domain, prefix_matching, host,
57 54
                       reply_code, dstavp)
58 55
 
59 56
         5. MI Commands
... ...
@@ -196,13 +193,10 @@ Chapter 1. Admin Guide
196 193
         4.2. cr_route(carrier, domain, prefix_matching, rewrite_user,
197 194
                 hash_source, descavp)
198 195
 
199
-        4.3. cr_prime_route(carrier, domain, prefix_matching,
200
-                rewrite_user, hash_source, descavp)
201
-
202
-        4.4. cr_nofallback_route(carrier, domain, prefix_matching,
196
+        4.3. cr_nofallback_route(carrier, domain, prefix_matching,
203 197
                 rewrite_user, hash_source, descavp)
204 198
 
205
-        4.5. cr_next_domain(carrier, domain, prefix_matching, host,
199
+        4.4. cr_next_domain(carrier, domain, prefix_matching, host,
206 200
                 reply_code, dstavp)
207 201
 
208 202
    5. MI Commands
... ...
@@ -463,13 +457,10 @@ modparam("carrierroute", "match_mode", 10)
463 457
    4.2. cr_route(carrier, domain, prefix_matching, rewrite_user,
464 458
           hash_source, descavp)
465 459
 
466
-   4.3. cr_prime_route(carrier, domain, prefix_matching, rewrite_user,
467
-          hash_source, descavp)
468
-
469
-   4.4. cr_nofallback_route(carrier, domain, prefix_matching,
460
+   4.3. cr_nofallback_route(carrier, domain, prefix_matching,
470 461
           rewrite_user, hash_source, descavp)
471 462
 
472
-   4.5. cr_next_domain(carrier, domain, prefix_matching, host, reply_code,
463
+   4.4. cr_next_domain(carrier, domain, prefix_matching, host, reply_code,
473 464
           dstavp)
474 465
 
475 466
    Previous versions of carrierroute had some more function. All the old
... ...
@@ -477,21 +468,12 @@ modparam("carrierroute", "match_mode", 10)
477 468
 cr_rewrite_uri(domain, hash_source)
478 469
 -> cr_route("default", domain, "$rU", "$rU", hash_source)
479 470
 
480
-cr_prime_balance_uri(domain, hash_source)
481
--> cr_prime_route("default", domain, "$rU", "$rU", hash_source)
482
-
483 471
 cr_rewrite_by_to(domain, hash_source)
484 472
 -> cr_route("default", domain, "$tU", "$rU", hash_source)
485 473
 
486
-cr_prime_balance_by_to(domain, hash_source)
487
--> cr_prime_route("default", domain, "$tU", "$rU", hash_source)
488
-
489 474
 cr_rewrite_by_from(domain, hash_source)
490 475
 -> cr_route("default", domain, "$fU", "$rU", hash_source)
491 476
 
492
-cr_prime_balance_by_from(domain, hash_source)
493
--> cr_prime_route("default", domain, "$fU", "$rU", hash_source)
494
-
495 477
 cr_user_rewrite_uri(uri, domain)
496 478
 -> cr_user_carrier(user, domain, "$avp(tree_avp)")
497 479
 -> cr_route("$avp(tree_avp)", domain, "$rU", "$rU", "call_id")
... ...
@@ -499,7 +481,7 @@ cr_user_rewrite_uri(uri, domain)
499 481
 cr_tree_rewrite_uri(tree, domain)
500 482
 -> cr_route(tree, domain, "$rU", "$rU", "call_id")
501 483
 
502
-4.1. cr_user_carrier(user, domain, dstavp)
484
+4.1.  cr_user_carrier(user, domain, dstavp)
503 485
 
504 486
    This function loads the carrier and stores it in an AVP. It cannot be
505 487
    used in the config file mode, as it needs a mapping of the given user
... ...
@@ -516,7 +498,7 @@ cr_tree_rewrite_uri(tree, domain)
516 498
        string any pseudo-variable could be used as input.
517 499
      * dstavp - Name of the AVP where to store the carrier id.
518 500
 
519
-4.2. cr_route(carrier, domain, prefix_matching, rewrite_user, hash_source,
501
+4.2.  cr_route(carrier, domain, prefix_matching, rewrite_user, hash_source,
520 502
 descavp)
521 503
 
522 504
    This function searches for the longest match for the user given in
... ...
@@ -558,53 +540,7 @@ descavp)
558 540
      * decsavp - Name of the AVP where to store the description. This
559 541
        parameter is optional.
560 542
 
561
-4.3. cr_prime_route(carrier, domain, prefix_matching, rewrite_user,
562
-hash_source, descavp)
563
-
564
-   This function searches for the longest match for the user given in
565
-   prefix_matching at the given domain in the given carrier tree. The
566
-   Request URI is rewritten using rewrite_user and the given hash source
567
-   and algorithm. Returns -1 if there is no data found or an empty rewrite
568
-   host on the longest match is found. On success also the description is
569
-   stored in the given AVP (if obmitted, nothing is stored in an AVP).
570
-   This is useful if you need some additional informations that belongs to
571
-   each gw, like the destination or the number of channels. This function
572
-   is only usable with rewrite_user and prefix_matching containing a valid
573
-   string. This string needs to be numerical if the match_mode parameter
574
-   is set to 10.
575
-
576
-   It uses the prime hash algorithm to calculate the hash values. This
577
-   means that the fuction behaves different then the normal routing
578
-   function. If you don't know what this prime functionality is, you
579
-   should just use the cr_route function. The prime routing algorithm not
580
-   use the configured probabilities in order to route requests, it just
581
-   uses a fixed hash distribution. If one of the hash targets is not
582
-   available, and no backup rule is configured, the function will return
583
-   -1.
584
-
585
-   Please not that this function is deprecated and will be removed in the
586
-   next stable release. Please consider using the cr_nofallback_route
587
-   function instead.
588
-
589
-   Meaning of the parameters is as follows:
590
-     * carrier - The routing tree to be used. Additional to a string any
591
-       pseudo-variable could be used as input.
592
-     * domain - Name of the routing domain to be used. Additional to a
593
-       string any pseudo-variable could be used as input.
594
-     * prefix_matching - User name to be used for prefix matching in the
595
-       routing tree. Additional to a string any pseudo-variable could be
596
-       used as input.
597
-     * rewrite_user - The user name to be used for applying the rewriting
598
-       rule. Usually this is the user part of the request URI. Additional
599
-       to a string any pseudo-variable could be used as input.
600
-     * hash_source - The hash values of the destination set must be a
601
-       contiguous range starting at 1, limited by the configuration
602
-       parameter max_targets. Possible values for hash_source are:
603
-       call_id, from_uri, from_user, to_uri to_user and rand
604
-     * descavp - Name of the AVP where to store the description. This
605
-       parameter is optional.
606
-
607
-4.4. cr_nofallback_route(carrier, domain, prefix_matching, rewrite_user,
543
+4.3.  cr_nofallback_route(carrier, domain, prefix_matching, rewrite_user,
608 544
 hash_source, descavp)
609 545
 
610 546
    This function searches for the longest match for the user given in
... ...
@@ -620,12 +556,12 @@ hash_source, descavp)
620 556
    is set to 10.
621 557
 
622 558
    It uses the standard CRC32 algorithm to calculate the hash values. In
623
-   contrast to the normal cr_route function the backup rules of
624
-   cr_prime_route is used. This means not the configured probabilities
625
-   will be used, only a fixed hash distribution. This makes sense to
626
-   distribute incoming register requests e.g. to a bunch of registrar
627
-   servers. If one of the hash targets is not available and backup rule is
628
-   configured, the function will return -1.
559
+   contrast to the normal cr_route function the backup rules of (now
560
+   obselete) cr_prime_route is used. This means not the configured
561
+   probabilities will be used, only a fixed hash distribution. This makes
562
+   sense to distribute incoming register requests e.g. to a bunch of
563
+   registrar servers. If one of the hash targets is not available and
564
+   backup rule is configured, the function will return -1.
629 565
 
630 566
    Meaning of the parameters is as follows:
631 567
      * carrier - The routing tree to be used. Additional to a string any
... ...
@@ -645,7 +581,7 @@ hash_source, descavp)
645 581
      * descavp - Name of the AVP where to store the description. This
646 582
        parameter is optional.
647 583
 
648
-4.5. cr_next_domain(carrier, domain, prefix_matching, host, reply_code,
584
+4.4.  cr_next_domain(carrier, domain, prefix_matching, host, reply_code,
649 585
 dstavp)
650 586
 
651 587
    This function searches for the longest match for the user given in
... ...
@@ -89,8 +89,6 @@ static cmd_export_t cmds[]={
89 89
 	{"cr_user_carrier",  (cmd_function)cr_load_user_carrier,  3, cr_load_user_carrier_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
90 90
 	{"cr_route",         (cmd_function)cr_route5,              5, cr_route_fixup,             0, REQUEST_ROUTE | FAILURE_ROUTE },
91 91
 	{"cr_route",         (cmd_function)cr_route,              6, cr_route_fixup,             0, REQUEST_ROUTE | FAILURE_ROUTE },
92
-	{"cr_prime_route",   (cmd_function)cr_prime_route5,        5, cr_route_fixup,             0, REQUEST_ROUTE | FAILURE_ROUTE },
93
-	{"cr_prime_route",   (cmd_function)cr_prime_route,        6, cr_route_fixup,             0, REQUEST_ROUTE | FAILURE_ROUTE },
94 92
 	{"cr_nofallback_route",(cmd_function)cr_nofallback_route5,     5, cr_route_fixup,             0, REQUEST_ROUTE | FAILURE_ROUTE },
95 93
 	{"cr_nofallback_route",(cmd_function)cr_nofallback_route,     6, cr_route_fixup,             0, REQUEST_ROUTE | FAILURE_ROUTE },
96 94
 	{"cr_next_domain",   (cmd_function)cr_load_next_domain,   6, cr_load_next_domain_fixup,  0, REQUEST_ROUTE | FAILURE_ROUTE },
... ...
@@ -51,7 +51,6 @@
51 51
 
52 52
 enum hash_algorithm {
53 53
 	alg_crc32 = 1, /*!< hashing algorithm is CRC32 */
54
-	alg_prime, /*!< hashing algorithm is (right 18 digits of hash_source % prime_number) % max_targets + 1 */
55 54
 	alg_crc32_nofallback, /*!< same algorithm as alg_crc32, with only a backup rule, but no fallback tree is chosen
56 55
                            if there is something wrong. */
57 56
 	alg_error
... ...
@@ -394,16 +393,6 @@ static int rewrite_on_rule(struct route_flags *rf_head, flag_t flags, str * dest
394 393
 	}
395 394
 
396 395
 	switch (alg) {
397
-		case alg_prime:
398
-			if ((prob = prime_hash_func(msg, hash_source, rf->max_targets)) < 0) {
399
-				LM_ERR("could not hash message with prime algorithm");
400
-				return -1;
401
-			}
402
-			if ((rr = get_rule_by_hash(rf, prob)) == NULL) {
403
-				LM_CRIT("no route found\n");
404
-				return -1;
405
-			}
406
-			break;
407 396
 		case alg_crc32:
408 397
 			if(rf->dice_max == 0) {
409 398
 				LM_ERR("invalid dice_max value\n");
... ...
@@ -682,41 +671,11 @@ int cr_route5(struct sip_msg * _msg, gparam_t *_carrier,
682 671
 }
683 672
 
684 673
 
685
-/**
686
- * rewrites the request URI of msg after determining the
687
- * new destination URI with the prime hash algorithm.
688
- *
689
- * @param _msg the current SIP message
690
- * @param _carrier the requested carrier
691
- * @param _domain the requested routing domain
692
- * @param _prefix_matching the user to be used for prefix matching
693
- * @param _rewrite_user the localpart of the URI to be rewritten
694
- * @param _hsrc the SIP header used for hashing
695
- * @param _descavp the name of the AVP where the description is stored
696
- *
697
- * @return 1 on success, -1 on failure
698
- */
699
-int cr_prime_route(struct sip_msg * _msg, gparam_t *_carrier,
700
-		gparam_t *_domain, gparam_t *_prefix_matching,
701
-		gparam_t *_rewrite_user, enum hash_source _hsrc,
702
-		gparam_t *_descavp)
703
-{
704
-	return cr_do_route(_msg, _carrier, _domain, _prefix_matching,
705
-		_rewrite_user, _hsrc, alg_prime, _descavp);
706
-}
707
-
708
-int cr_prime_route5(struct sip_msg * _msg, gparam_t *_carrier,
709
-		gparam_t *_domain, gparam_t *_prefix_matching,
710
-		gparam_t *_rewrite_user, enum hash_source _hsrc)
711
-{
712
-	return cr_do_route(_msg, _carrier, _domain, _prefix_matching,
713
-		_rewrite_user, _hsrc, alg_prime, NULL);
714
-}
715 674
 /**
716 675
  * rewrites the request URI of msg after determining the
717 676
  * new destination URI with the crc32 hash algorithm. The difference
718 677
  * to cr_route is that no fallback rule is chosen if there is something
719
- * wrong (like cr_prime_route)
678
+ * wrong (like now obselete cr_prime_route)
720 679
  *
721 680
  * @param _msg the current SIP message
722 681
  * @param _carrier the requested carrier
... ...
@@ -74,34 +74,12 @@ int cr_route5(struct sip_msg * _msg, gparam_t *_carrier,
74 74
 		gparam_t *_rewrite_user, enum hash_source _hsrc);
75 75
 
76 76
 
77
-/**
78
- * rewrites the request URI of msg after determining the
79
- * new destination URI
80
- *
81
- * @param _msg the current SIP message
82
- * @param _carrier the requested carrier
83
- * @param _domain the requested routing domain
84
- * @param _prefix_matching the user to be used for prefix matching
85
- * @param _rewrite_user the localpart of the URI to be rewritten
86
- * @param _hsrc the SIP header used for hashing
87
- * @param _descavp the name of the AVP where the description is stored
88
- *
89
- * @return 1 on success, -1 on failure
90
- */
91
-int cr_prime_route(struct sip_msg * _msg, gparam_t *_carrier,
92
-		gparam_t *_domain, gparam_t *_prefix_matching,
93
-		gparam_t *_rewrite_user, enum hash_source _hsrc,
94
-		gparam_t *_descavp);
95
-int cr_prime_route5(struct sip_msg * _msg, gparam_t *_carrier,
96
-		gparam_t *_domain, gparam_t *_prefix_matching,
97
-		gparam_t *_rewrite_user, enum hash_source _hsrc);
98
-
99 77
 /**
100 78
  *
101 79
  * rewrites the request URI of msg after determining the
102 80
  * new destination URI with the crc32 hash algorithm. The difference
103 81
  * to cr_route is that no fallback rule is chosen if there is something
104
- * wrong (behaves like cr_prime_route)
82
+ * wrong (behaves like now obselete cr_prime_route)
105 83
  *
106 84
  * @param _msg the current SIP message
107 85
  * @param _carrier the requested carrier
... ...
@@ -364,21 +364,12 @@ modparam("carrierroute", "match_mode", 10)
364 364
 cr_rewrite_uri(domain, hash_source)
365 365
 -> cr_route("default", domain, "$rU", "$rU", hash_source)
366 366
 
367
-cr_prime_balance_uri(domain, hash_source)
368
--> cr_prime_route("default", domain, "$rU", "$rU", hash_source)
369
-
370 367
 cr_rewrite_by_to(domain, hash_source)
371 368
 -> cr_route("default", domain, "$tU", "$rU", hash_source)
372 369
 
373
-cr_prime_balance_by_to(domain, hash_source)
374
--> cr_prime_route("default", domain, "$tU", "$rU", hash_source)
375
-
376 370
 cr_rewrite_by_from(domain, hash_source)
377 371
 -> cr_route("default", domain, "$fU", "$rU", hash_source)
378 372
 
379
-cr_prime_balance_by_from(domain, hash_source)
380
--> cr_prime_route("default", domain, "$fU", "$rU", hash_source)
381
-
382 373
 cr_user_rewrite_uri(uri, domain)
383 374
 -> cr_user_carrier(user, domain, "$avp(tree_avp)")
384 375
 -> cr_route("$avp(tree_avp)", domain, "$rU", "$rU", "call_id")
... ...
@@ -491,82 +482,6 @@ cr_tree_rewrite_uri(tree, domain)
491 482
         </listitem>
492 483
 	    </itemizedlist>
493 484
 	</section>
494
-		<section>
495
-	    <title>
496
-		<function moreinfo="none">cr_prime_route(carrier, domain, prefix_matching, rewrite_user, hash_source, descavp)</function>
497
-	    </title>
498
-	    <para>
499
-        This function searches for the longest match for the user given
500
-        in prefix_matching at the given domain in the given carrier tree.
501
-        The Request URI is rewritten using rewrite_user and the given
502
-        hash source and algorithm. Returns -1 if there is no data found
503
-        or an empty rewrite host on the longest match is found. On success
504
-        also the description is stored in the given AVP (if obmitted, nothing
505
-        is stored in an AVP). This is useful if you need some additional
506
-        informations that belongs to each gw, like the destination or the
507
-        number of channels.
508
-        This function is only usable with rewrite_user and prefix_matching
509
-        containing a valid string. This string needs to be numerical if the match_mode
510
-        parameter is set to 10.
511
-            </para>
512
-            <para>
513
-        It uses the prime hash algorithm to calculate the hash values. This
514
-        means that the fuction behaves different then the normal routing
515
-        function. If you don't know what this prime functionality is,
516
-        you should just use the <emphasis>cr_route</emphasis> function. The
517
-        prime routing algorithm not use the configured probabilities in
518
-        order to route requests, it just uses a fixed hash distribution. If
519
-        one of the hash targets is not available, and no backup rule is
520
-        configured, the function will return -1.
521
-	    </para>
522
-	    <para>
523
-	Please not that this function is deprecated and will be removed in
524
-	the next stable release. Please consider using the
525
-	<emphasis>cr_nofallback_route</emphasis> function instead.
526
-	    </para>
527
-	    <para>Meaning of the parameters is as follows:</para>
528
-	    <itemizedlist>
529
-        <listitem>
530
-		      <para><emphasis>carrier</emphasis> - The routing tree to be used. Additional to a string
531
-            any pseudo-variable could be used as input.
532
-  		    </para>
533
-        </listitem>
534
-        <listitem>
535
-		      <para><emphasis>domain</emphasis> - Name of the routing domain to be used.
536
-            Additional to a string any pseudo-variable could
537
-            be used as input.
538
-  		    </para>
539
-        </listitem>
540
-        <listitem>
541
-		      <para><emphasis>prefix_matching</emphasis> - User name to be used for prefix matching
542
-            in the routing tree.
543
-            Additional to a string any pseudo-variable could
544
-            be used as input.
545
-  		    </para>
546
-        </listitem>
547
-        <listitem>
548
-		      <para><emphasis>rewrite_user</emphasis> - The user name to be used for applying the
549
-            rewriting rule. Usually this is the user part of the request
550
-            URI. Additional to a string any pseudo-variable could
551
-            be used as input.
552
-  		    </para>
553
-        </listitem>
554
-        <listitem>
555
-		      <para><emphasis>hash_source</emphasis> - The hash values of the destination set must
556
-            be a contiguous range starting at 1, limited by the
557
-            configuration parameter max_targets. Possible values for
558
-            hash_source are: call_id, from_uri, from_user, to_uri
559
-            to_user and rand
560
-  		    </para>
561
-        </listitem>
562
-        <listitem>
563
-		      <para><emphasis>descavp</emphasis> - Name of the AVP where to store the description.
564
-			This parameter is optional.
565
-  		    </para>
566
-        </listitem>
567
-	    </itemizedlist>
568
-	</section>
569
-
570 485
 		<section>
571 486
 	    <title>
572 487
 		<function moreinfo="none">cr_nofallback_route(carrier, domain, prefix_matching, rewrite_user, hash_source, descavp)</function>
... ...
@@ -588,7 +503,7 @@ cr_tree_rewrite_uri(tree, domain)
588 503
 	    <para>
589 504
 		It uses the standard CRC32 algorithm to calculate the hash values. In contrast
590 505
 		to the normal <emphasis>cr_route</emphasis> function the backup
591
-		rules of cr_prime_route is used. This means not the configured
506
+		rules of (now obselete) cr_prime_route is used. This means not the configured
592 507
 		probabilities will be used, only a fixed hash distribution. This
593 508
 		makes sense to distribute incoming register requests e.g. to a bunch of
594 509
 		registrar servers. If one of the hash targets is not available and
... ...
@@ -69,51 +69,6 @@ int hash_func (struct sip_msg * msg,
69 69
 	return ret;
70 70
 }
71 71
 
72
-int prime_hash_func(struct sip_msg * msg,
73
-                              enum hash_source source, int denominator) {
74
-	str source_string;
75
-	if(source != shs_from_user && source != shs_to_user) {
76
-		LM_ERR("chosen hash source not usable (may contain letters)\n");
77
-		return -1;
78
-	}
79
-	if (determine_source (msg, source, &source_string) == -1) {
80
-		return -1;
81
-	}
82
-
83
-	static const int INT_DIGIT_LIMIT = 18;
84
-	static const int PRIME_NUMBER = 51797;
85
-	uint64_t number = 0;
86
-	uint64_t p10;
87
-	int i, j, limit = 0;
88
-	int ret;
89
-	char source_number_s[INT_DIGIT_LIMIT + 1];
90
-
91
-	i = INT_DIGIT_LIMIT - 1;
92
-	j = source_string.len - 1;
93
-	source_number_s[INT_DIGIT_LIMIT] ='\0';
94
-
95
-	while(i >= 0 && j >= 0) {
96
-		if(isdigit(source_string.s[j])) {
97
-			source_number_s[i] = source_string.s[j];
98
-			i--;
99
-		}
100
-		j--;
101
-	}
102
-	limit = i;
103
-
104
-	for(i=INT_DIGIT_LIMIT - 1, p10=1; i>limit; i--, p10=p10*10) {
105
-		number += (source_number_s[i] - '0') * p10;
106
-	}
107
-
108
-	LM_DBG("source_string is %.*s, source_number_s "
109
-	    "is: %s, number is %llu\n", source_string.len, source_string.s,
110
-	    source_number_s + (limit + 1), (long long unsigned int)number);
111
-	ret = number % PRIME_NUMBER;
112
-	ret = ret % denominator + 1;
113
-	LM_DBG("calculated hash is: %i\n", ret);
114
-	return ret;
115
-}
116
-
117 72
 static int determine_source (struct sip_msg *msg, enum hash_source source,
118 73
                              str *source_string) {
119 74
 	source_string->s = NULL;
... ...
@@ -71,12 +71,4 @@ typedef int (*hash_func_t)(struct sip_msg * msg,
71 71
 int hash_func (struct sip_msg * msg,
72 72
                          enum hash_source source, int denominator);
73 73
 
74
-/*!
75
- * \brief prime hash function
76
- * Returns an integer number between 0 and denominator - 1 based on
77
- * the hash source from the msg. Use the prime number algorithm.
78
-*/
79
-int prime_hash_func (struct sip_msg * msg,
80
-                               enum hash_source source, int denominator);
81
-
82 74
 #endif