Skip to content

Commit

Permalink
[qrouting]sort_alg field added to dr_carriers table and sort_alg, sor…
Browse files Browse the repository at this point in the history
…t_profile fileds added to dr_rules table, sorting related cbs moved to dr_sorting_cbs.h
  • Loading branch information
tallicamike authored and razvancrainea committed Feb 11, 2020
1 parent 888053b commit c33f0cc
Show file tree
Hide file tree
Showing 30 changed files with 690 additions and 183 deletions.
17 changes: 15 additions & 2 deletions db/schema/dr_carriers.xml
Expand Up @@ -9,7 +9,7 @@

<table id="dr_carriers" xmlns:db="http://docbook.org/ns/docbook">
<name>dr_carriers</name>
<version>2</version>
<version>3</version>
<type db="mysql">&MYSQL_TABLE_TYPE;</type>
<description>
<db:para>This table is used by the Dynamic Routing module to define
Expand Down Expand Up @@ -50,7 +50,20 @@
<type>unsigned int</type>
<size>&flag_len;</size>
<default>0</default>
<description>Flags (for different purposes) of the carriers
<description>Flags of the carriers (for different purposes:
use only first gw from cr (set the first bit of the flag);
disable gateway (set the second bit of the flag);
</description>
</column>

<column id="sorting_alg">
<name>sort_alg</name>
<type>CHAR</type>
<default>0</default>
<description>The sorting algorithm to be employed inside the carrier
(if set) when do_routing is called. Possible values: 'O'/'o' - no sorting should be done,
'W'/'w' - weight based sorting should be done and 'Q'/'q' quality-based sorting should be done (quality
based sorting is provided by the qrouting module)
</description>
</column>

Expand Down
22 changes: 21 additions & 1 deletion db/schema/dr_rules.xml
Expand Up @@ -9,7 +9,7 @@

<table id="dr_rules" xmlns:db="http://docbook.org/ns/docbook">
<name>dr_rules</name>
<version>3</version>
<version>4</version>
<type db="mysql">&MYSQL_TABLE_TYPE;</type>
<description>
<db:para>This table is used by the Dynamic Routing module to store
Expand Down Expand Up @@ -81,6 +81,26 @@
<description>Reference to the GWs/destinations to be used when
rule matches.</description>
</column>

<column id="sorting_alg">
<name>sort_alg</name>
<type>CHAR</type>
<default>0</default>
<description>The sorting algorithm to be employed inside the rule (if set)
when do_routing is called. Possible values: 'O'/'o' - no sorting should be done,
'W'/'w' - weight based sorting should be done and 'Q'/'q' quality-based sorting should be done (quality
based sorting is provided by the qrouting module). More options may be available in the future.
</description>
</column>
<column id="sorting_profile">
<name>sort_profile</name>
<type>unsigned int</type>
<size>10</size>
<default>0</default>
<description>The id of the sorting profile employed by the chosen algorithm. Available
only for qrouting now, the sorting_profile id is found in qr_profiles table.
</description>
</column>

<column id="attrs">
<name>attrs</name>
Expand Down
2 changes: 2 additions & 0 deletions modules/drouting/dr_api.h
Expand Up @@ -53,6 +53,7 @@ typedef str * (*get_cr_name_f) (pcr_t *cr);
typedef pgw_t * (*get_gw_from_cr_f) (pcr_t *cr, int n); /* gets the n-th
gateway from the
carrier */
typedef void * (*get_qr_rule_handle_f) (rt_info_t *);
struct dr_binds {
create_head_f create_head;
free_head_f free_head;
Expand All @@ -63,6 +64,7 @@ struct dr_binds {
get_cr_name_f get_cr_name;
get_cr_n_gw_f get_cr_n_gw;
get_gw_from_cr_f get_gw_from_cr;
get_qr_rule_handle_f get_qr_rule_handle;
};

typedef int (*load_dr_api_f)(struct dr_binds *drb);
Expand Down
11 changes: 9 additions & 2 deletions modules/drouting/dr_api_internal.c
Expand Up @@ -44,6 +44,7 @@ static str * get_gw_name(pgw_t * gw);
static str * get_cr_name(pcr_t * cr);
static int get_cr_n_gw(pcr_t * cr); /* gets the number of gateways from a carrier */
static pgw_t * get_gw_from_cr (pcr_t *cr, int n);
static void * get_qr_rule_handle(rt_info_t *rule);


static str * get_gw_name(pgw_t *gw) {
Expand All @@ -54,16 +55,21 @@ static int get_cr_n_gw(pcr_t * cr) {
return cr->pgwa_len;
}

static pgw_t * get_gw_from_cr(pcr_t *cr, int n) {
static inline pgw_t * get_gw_from_cr(pcr_t *cr, int n) {
if(cr->pgwa_len > n)
return cr->pgwl[n].dst.gw; /* a carrier cannot contain another carrier */
return NULL; /* provided index was bigger than the vector */
}

static str *get_cr_name(pcr_t * cr) {
static inline str *get_cr_name(pcr_t * cr) {
return &cr->id;
}

static inline void * get_qr_rule_handle(rt_info_t *rule) {
return rule->qr_handler;
}


/* Warning this function assumes the lock is already taken */
rt_info_t* find_rule_by_prefix_unsafe(ptree_t *pt, ptree_node_t *noprefix,
str prefix, unsigned int grp_id, unsigned int *matched_len)
Expand Down Expand Up @@ -97,6 +103,7 @@ int load_dr (struct dr_binds *drb)
drb->get_cr_n_gw = get_cr_n_gw;
drb->get_cr_name = get_cr_name;
drb->get_gw_from_cr = get_gw_from_cr;
drb->get_qr_rule_handle = get_qr_rule_handle;
return 0;
}

Expand Down
7 changes: 5 additions & 2 deletions modules/drouting/dr_cb.c
Expand Up @@ -33,6 +33,9 @@
#include "../../mem/mem.h"
#include "dr_cb.h"

unsigned char sort_algs[N_MAX_SORT_CBS] = {0,'O','W','Q'};



#define POINTER_CLOSED_MARKER ((void *)(-1))

Expand Down Expand Up @@ -243,9 +246,9 @@ int run_indexed_callback(struct dr_callback **dr_sort_cbs_lst, sort_cb_type type
return -1;
}
if(params != NULL) {
param = (struct dr_cb_params *) shm_malloc(sizeof(struct dr_cb_params));
param = (struct dr_cb_params *) pkg_malloc(sizeof(struct dr_cb_params));
if(param == NULL) {
LM_ERR("no more shm memory\n");
LM_ERR("no more pkg memory\n");
return -1;
}
}
Expand Down
11 changes: 11 additions & 0 deletions modules/drouting/dr_cb.h
Expand Up @@ -63,6 +63,17 @@ struct dr_sort_params {
};


#include "prefix_tree.h"
#include "dr_sorting_cbs.h"

#define POINTER_CLOSED_MARKER ((void *)(-1))



struct dr_cb_params {
void **param; /* parameter passed at callback registration*/
};


/* callback function prototype */
typedef void (dr_cb) (void *param);
Expand Down
15 changes: 15 additions & 0 deletions modules/drouting/dr_db_def.c
Expand Up @@ -60,6 +60,17 @@ str state_drd_col = str_init(STATE_DRD_COL);
#define PRIORITY_DRR_COL "priority"
#define ROUTEID_DRR_COL "routeid"
#define DSTLIST_DRR_COL "gwlist"
#define SORT_ALG_DRR_COL "sort_alg"
#define SORT_PROFILE_DRR_COL "sort_profile"
/*TODO: gotoqr */
#define WARN_TH_ASR_DRR_COL "warn_threshold_asr"
#define WARN_TH_CCR_DRR_COL "warn_threshold_ccr"
#define WARN_TH_AST_DRR_COL "warn_threshold_ast"
#define WARN_TH_ACD_DRR_COL "warn_threshold_acd"
#define DSBL_TH_ASR_DRR_COL "dsbl_threshold_asr"
#define DSBL_TH_CCR_DRR_COL "dsbl_threshold_ccr"
#define DSBL_TH_AST_DRR_COL "dsbl_threshold_ast"
#define DSBL_TH_ACD_DRR_COL "dsbl_threshold_acd"
#define ATTRS_DRR_COL "attrs"
str drr_table = str_init("dr_rules");
str rule_id_drr_col = str_init(RULE_ID_DRR_COL);
Expand All @@ -69,19 +80,23 @@ str time_drr_col = str_init(TIME_DRR_COL);
str priority_drr_col = str_init(PRIORITY_DRR_COL);
str routeid_drr_col = str_init(ROUTEID_DRR_COL);
str dstlist_drr_col = str_init(DSTLIST_DRR_COL);
str sort_alg_drr_col = str_init(SORT_ALG_DRR_COL);
str sort_profile_drr_col = str_init(SORT_PROFILE_DRR_COL);
str attrs_drr_col = str_init(ATTRS_DRR_COL);

/* DR carrier table related defs */
#define ID_DRC_COL "id"
#define CID_DRC_COL "carrierid"
#define FLAGS_DRC_COL "flags"
#define SORT_ALG_DRC_COL "sort_alg"
#define GWLIST_DRC_COL "gwlist"
#define ATTRS_DRC_COL "attrs"
#define STATE_DRC_COL "state"
str drc_table = str_init("dr_carriers");
str id_drc_col = str_init(ID_DRC_COL);
str cid_drc_col = str_init(CID_DRC_COL);
str flags_drc_col = str_init(FLAGS_DRC_COL);
str sort_alg_drc_col = str_init(SORT_ALG_DRC_COL);
str gwlist_drc_col = str_init(GWLIST_DRC_COL);
str attrs_drc_col = str_init(ATTRS_DRC_COL);
str state_drc_col = str_init(STATE_DRC_COL);
Expand Down
3 changes: 3 additions & 0 deletions modules/drouting/dr_db_def.h
Expand Up @@ -52,13 +52,16 @@ extern str time_drr_col;
extern str priority_drr_col;
extern str routeid_drr_col;
extern str dstlist_drr_col;
extern str sort_alg_drr_col;
extern str sort_profile_drr_col;
extern str attrs_drr_col;

/* DR carrier table related defs */
extern str drc_table;
extern str id_drc_col;
extern str cid_drc_col;
extern str flags_drc_col;
extern str sort_alg_drc_col;
extern str gwlist_drc_col;
extern str attrs_drc_col;
extern str state_drc_col;
Expand Down

0 comments on commit c33f0cc

Please sign in to comment.