Skip to content

Commit

Permalink
carrierroute: replace faulty warning mechanism
Browse files Browse the repository at this point in the history
- warning log for the same carrier/domain having routes with only 0 probability
is now triggered through counting probabilities per carrier and domain
- kudos also go to Huseyin Dikme
- GH #2653
  • Loading branch information
lbalaceanu committed Mar 12, 2021
1 parent 2b47555 commit 087c00a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/modules/carrierroute/cr_data.c
Expand Up @@ -464,6 +464,7 @@ int add_route(struct route_data_t * rd, int carrier_id,
LM_ERR("could not retrieve domain data\n");
return -1;
}
domain_data->sum_prob = domain_data->sum_prob + prob;

LM_INFO("found carrier and domain, now adding route\n");
return add_route_to_tree(domain_data->tree, scan_prefix, flags, mask, scan_prefix, max_targets, prob, rewrite_hostpart,
Expand Down
47 changes: 13 additions & 34 deletions src/modules/carrierroute/cr_db.c
Expand Up @@ -31,6 +31,7 @@
#include "carrierroute.h"
#include "cr_db.h"
#include "cr_carrier.h"
#include "cr_domain.h"
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -265,9 +266,8 @@ int load_user_carrier(str * user, str * domain) {
*/
int load_route_data_db(struct route_data_t * rd) {
db1_res_t * res = NULL;
db1_res_t * prob_res = NULL;
db_row_t * row = NULL;
int i, ret;
int i, j, ret;
struct carrier_data_t * tmp_carrier_data;
static str query_str;
str tmp_scan_prefix, tmp_rewrite_host, tmp_rewrite_prefix,
Expand Down Expand Up @@ -353,7 +353,6 @@ int load_route_data_db(struct route_data_t * rd) {
}
}
int n = 0;
crboolean query_done = crfalse;
do {
LM_DBG("loading, cycle %d", n++);
for (i = 0; i < RES_ROW_N(res); ++i) {
Expand All @@ -379,6 +378,7 @@ int load_route_data_db(struct route_data_t * rd) {
p_tmp_comment = &tmp_comment;
}


if (add_route(rd,
row->values[COL_CARRIER].val.int_val,
row->values[COL_DOMAIN].val.int_val,
Expand All @@ -398,34 +398,6 @@ int load_route_data_db(struct route_data_t * rd) {
p_tmp_comment) == -1) {
goto errout;
}
if (row->values[COL_PROB].val.double_val == 0 && !query_done) {
int ret_tmp;
char query_tmp[QUERY_LEN];
str query_tmp_str;

memset(query_tmp, 0, QUERY_LEN);
ret_tmp = snprintf(query_tmp, QUERY_LEN, "SELECT * FROM %.*s WHERE %.*s=%d and %.*s=%d and %.*s>%d",
carrierroute_table.len, carrierroute_table.s, columns[COL_CARRIER]->len, columns[COL_CARRIER]->s, row->values[COL_CARRIER].val.int_val,
columns[COL_DOMAIN]->len, columns[COL_DOMAIN]->s, row->values[COL_DOMAIN].val.int_val, columns[COL_PROB]->len, columns[COL_PROB]->s, 0);

if (ret_tmp < 0) {
LM_ERR("error in snprintf while querying prob column");
goto errout;
}
query_tmp_str.s = query_tmp;
query_tmp_str.len = ret_tmp;

if (carrierroute_dbf.raw_query(carrierroute_dbh, &query_tmp_str, &prob_res) < 0) {
LM_ERR("Failed to query carrierroute db table based on prob column.\n");
goto errout;
}
if(RES_ROW_N(prob_res) == 0) {
LM_ERR("Carrierroute db table contains route(s) with only 0 probability.\n");
query_done = crtrue;
}
carrierroute_dbf.free_result(carrierroute_dbh, prob_res);
prob_res = NULL;
}

}
if (DB_CAPABILITY(carrierroute_dbf, DB_CAP_FETCH)) {
Expand All @@ -439,6 +411,16 @@ int load_route_data_db(struct route_data_t * rd) {
}
} while(RES_ROW_N(res) > 0);

for (i = 0; i < rd->carrier_num; ++i) {
for (j = 0; j < rd->carriers[i]->domain_num; ++j) {
if (rd->carriers[i]->domains[j]->sum_prob == 0.0) {
LM_ERR("All routes with carrier id %d (%.*s) and domain id %d (%.*s) have probability 0.\n",
rd->carriers[i]->id, rd->carriers[i]->name->len, rd->carriers[i]->name->s,
rd->carriers[i]->domains[j]->id, rd->carriers[i]->domains[j]->name->len, rd->carriers[i]->domains[j]->name->s);
}
}
}

carrierroute_dbf.free_result(carrierroute_dbh, res);
res = NULL;

Expand Down Expand Up @@ -493,8 +475,5 @@ int load_route_data_db(struct route_data_t * rd) {
if (res) {
carrierroute_dbf.free_result(carrierroute_dbh, res);
}
if (prob_res) {
carrierroute_dbf.free_result(carrierroute_dbh, prob_res);
}
return -1;
}
5 changes: 0 additions & 5 deletions src/modules/carrierroute/cr_db.h
Expand Up @@ -88,9 +88,4 @@ int load_route_data_db (struct route_data_t * rd);

int load_user_carrier(str * user, str * domain);

typedef enum {
crfalse = 0,
crtrue = 1
} crboolean;

#endif
1 change: 1 addition & 0 deletions src/modules/carrierroute/cr_domain.h
Expand Up @@ -40,6 +40,7 @@
struct domain_data_t {
int id; /*!< the numerical id of the routing tree */
str * name; /*!< the name of the routing tree. This points to the name in domain_map to avoid duplication. */
double sum_prob; /*!< sums the probabilities of all entries in the normal tree. Used to warn that (carrier, domain) has only routes with probability 0. */
struct dtrie_node_t * tree; /*!< the root node of the routing tree. Payload is of type (struct route_flags *) */
struct dtrie_node_t * failure_tree; /*!< the root node of the failure routing tree. Payload is of type (struct failure_route_rule *) */
};
Expand Down

0 comments on commit 087c00a

Please sign in to comment.