-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c33f0cc
commit 7190693
Showing
20 changed files
with
689 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE database PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN" | ||
"http://opensips.org/pub/opensips/dbschema/dtd/1.1/dbschema.dtd" [ | ||
|
||
<!ENTITY % entities SYSTEM "entities.xml"> | ||
%entities; | ||
|
||
]> | ||
|
||
<database xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<name>Quality Routing</name> | ||
<xi:include href="qr_profiles.xml"/> | ||
</database> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE table PUBLIC "-//opensips.org//DTD DBSchema V1.1//EN" | ||
"http://opensips.org/pub/opensips/dbschema/dtd/1.1/dbschema.dtd" [ | ||
|
||
<!ENTITY % entities SYSTEM "entities.xml"> | ||
%entities; | ||
|
||
]> | ||
|
||
<table id="qr_profiles" xmlns:db="http://docbook.org/ns/docbook"> | ||
<name>qr_profiles</name> | ||
<version>1</version> | ||
<type db="mysql">&MYSQL_TABLE_TYPE;</type> | ||
<description> | ||
<db:para>This table is used by the Quality Routing module to store | ||
information about the thresholds for warnings and disabling destinations. A profile is | ||
associated with a drouting rule. | ||
More information can be found at: &OPENSIPS_MOD_DOC;qrouting.html. | ||
</db:para> | ||
</description> | ||
<column id="id"> | ||
<name>id</name> | ||
<type>unsigned int</type> | ||
<size>&table_id_len;</size> | ||
<autoincrement/> | ||
<natural/> | ||
<primary/> | ||
<type db="dbtext">int,auto</type> | ||
<description>Table primary key | ||
</description> | ||
</column> | ||
<column id="profile_name"> | ||
<name>profile_name</name> | ||
<type>string</type> | ||
<size>64</size> | ||
<description> The name of the profile</description> | ||
</column> | ||
<column id="warn_threshold_asr"> | ||
<name>warn_threshold_asr</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The warning threshold for answer seizure ratio</description> | ||
</column> | ||
<column id="warn_threshold_ccr"> | ||
<name>warn_threshold_ccr</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The warning threshold for call completion ratio</description> | ||
</column> | ||
<column id="warn_threshold_pdd"> | ||
<name>warn_threshold_pdd</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The warning threshold for post dial delay</description> | ||
</column> | ||
<column id="warn_threshold_ast"> | ||
<name>warn_threshold_ast</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The warning threshold for average setup time</description> | ||
</column> | ||
<column id="warn_threshold_acd"> | ||
<name>warn_threshold_acd</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The warning threshold for average call duration</description> | ||
</column> | ||
<column id="dsbl_threshold_asr"> | ||
<name>dsbl_threshold_asr</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The disable threshold for answer seizure ratio</description> | ||
</column> | ||
<column id="dsbl_threshold_ccr"> | ||
<name>dsbl_threshold_ccr</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The disable threshold for call completion ratio</description> | ||
</column> | ||
<column id="dsbl_threshold_pdd"> | ||
<name>dsbl_threshold_pdd</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The disable threshold for post dial delay</description> | ||
</column> | ||
<column id="dsbl_threshold_ast"> | ||
<name>dsbl_threshold_ast</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The disable threshold for average setup time</description> | ||
</column> | ||
<column id="dsbl_threshold_acd"> | ||
<name>dsbl_threshold_acd</name> | ||
<type>double</type> | ||
<default>-1</default> | ||
<description>The disable threshold for average call duration</description> | ||
</column> | ||
|
||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
/** | ||
* | ||
* qrouting module: qr_load.c | ||
* | ||
* Copyright (C) 2004-2005 FhG Fokus | ||
* Copyright (C) 2006-2010 Voice Sistem SRL | ||
* Copyright (C) 2014 OpenSIPS Foundation | ||
* | ||
* This file is part of opensips, a free SIP server. | ||
* | ||
* opensips is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version | ||
* | ||
* opensips is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
* | ||
* History | ||
* ------- | ||
* 2014-10-13 initial version (Mihai Tiganus) | ||
*/ | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
#include "../../ut.h" | ||
#include "../../mem/shm_mem.h" | ||
|
||
#include "qr_load.h" | ||
#include "qr_stats.h" | ||
|
||
#define check_val( _col, _val, _type, _not_null, _is_empty_str) \ | ||
do{\ | ||
if ((_val)->type!=_type) { \ | ||
LM_ERR("column %.*s has a bad type\n", _col.len, _col.s); \ | ||
goto error;\ | ||
} \ | ||
if (_not_null && (_val)->nul) { \ | ||
LM_ERR("column %.*s is null\n", _col.len, _col.s); \ | ||
goto error;\ | ||
} \ | ||
if (_is_empty_str && VAL_STRING(_val)==0) { \ | ||
LM_ERR("column %.*s (str) is empty\n", _col.len, _col.s); \ | ||
goto error;\ | ||
} \ | ||
}while(0) | ||
|
||
str qr_profiles_table = str_init("qr_profiles"); | ||
str id_qp_col = str_init(ID_QP_COL); | ||
str profile_name_qp_col = str_init(PROFILE_NAME_QP_COL); | ||
str warn_asr_qp_col = str_init(WARN_ASR_QP_COL); | ||
str warn_ccr_qp_col = str_init(WARN_CCR_QP_COL); | ||
str warn_pdd_qp_col = str_init(WARN_PDD_QP_COL); | ||
str warn_ast_qp_col = str_init(WARN_AST_QP_COL); | ||
str warn_acd_qp_col = str_init(WARN_ACD_QP_COL); | ||
str dsbl_asr_qp_col = str_init(DSBL_ASR_QP_COL); | ||
str dsbl_ccr_qp_col = str_init(DSBL_CCR_QP_COL); | ||
str dsbl_pdd_qp_col = str_init(DSBL_PDD_QP_COL); | ||
str dsbl_ast_qp_col = str_init(DSBL_AST_QP_COL); | ||
str dsbl_acd_qp_col = str_init(DSBL_ACD_QP_COL); | ||
|
||
int qr_load(db_func_t *qr_dbf, db_con_t* qr_db_hdl) { | ||
int int_vals[N_INT_VALS]; | ||
char *str_vals[N_STR_VALS]; | ||
double double_vals[N_DOUBLE_VALS]; | ||
|
||
db_key_t columns[12]; | ||
db_res_t *res = 0; | ||
db_row_t *row = 0; | ||
int i, n, no_rows = 0; | ||
int db_cols = 0; | ||
|
||
memset(double_vals, 0, N_DOUBLE_VALS*sizeof(double)); | ||
memset(int_vals, 0, N_INT_VALS*sizeof(int)); | ||
memset(str_vals, 0, N_STR_VALS*sizeof(char*)); | ||
|
||
columns[0] = &id_qp_col; | ||
columns[1] = &profile_name_qp_col; | ||
columns[2] = &warn_asr_qp_col; | ||
columns[3] = &warn_ccr_qp_col; | ||
columns[4] = &warn_pdd_qp_col; | ||
columns[5] = &warn_ast_qp_col; | ||
columns[6] = &warn_acd_qp_col; | ||
columns[7] = &dsbl_asr_qp_col; | ||
columns[8] = &dsbl_ccr_qp_col; | ||
columns[9] = &dsbl_pdd_qp_col; | ||
columns[10] = &dsbl_ast_qp_col; | ||
columns[11] = &dsbl_acd_qp_col; | ||
|
||
db_cols = 12; | ||
|
||
if (qr_dbf->use_table( qr_db_hdl, &qr_profiles_table) < 0) { | ||
LM_ERR("cannot select table \"%.*s\"\n", qr_profiles_table.len, | ||
qr_profiles_table.s); | ||
goto error; | ||
} | ||
|
||
if (DB_CAPABILITY(*qr_dbf, DB_CAP_FETCH)) { | ||
if ( qr_dbf->query( qr_db_hdl, 0, 0, 0, columns, 0, db_cols, 0, 0 ) < 0) { | ||
LM_ERR("DB query failed\n"); | ||
goto error; | ||
} | ||
|
||
no_rows = estimate_available_rows( 4+64+10*sizeof(double), db_cols); | ||
if (no_rows==0) no_rows = 10; | ||
if(qr_dbf->fetch_result(qr_db_hdl, &res, no_rows )<0) { | ||
LM_ERR("Error fetching rows\n"); | ||
goto error; | ||
} | ||
} else { | ||
if ( qr_dbf->query(qr_db_hdl,0,0,0,columns,0,db_cols,0,&res) < 0) { | ||
LM_ERR("DB query failed\n"); | ||
goto error; | ||
} | ||
} | ||
|
||
LM_DBG("%d records found in table %.*s\n", | ||
RES_ROW_N(res), qr_profiles_table.len,qr_profiles_table.s); | ||
|
||
n = 0; | ||
do { | ||
for(i = 0; i < RES_ROW_N(res); i++) { | ||
row = RES_ROWS(res) + i; | ||
|
||
check_val(id_qp_col, ROW_VALUES(row), DB_INT, 1, 1); | ||
int_vals[INT_VALS_ID] = VAL_INT(ROW_VALUES(row)); | ||
|
||
check_val(profile_name_qp_col, ROW_VALUES(row)+1, DB_STRING, 1, 1); | ||
str_vals[STR_VALS_PROFILE_NAME] = (char*)VAL_STRING(ROW_VALUES(row)+1); | ||
|
||
check_val(warn_asr_qp_col, ROW_VALUES(row)+2, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_WARN_ASR] = VAL_DOUBLE(ROW_VALUES(row)+2); | ||
|
||
check_val(warn_ccr_qp_col, ROW_VALUES(row)+3, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_WARN_CCR] = VAL_DOUBLE(ROW_VALUES(row)+3); | ||
|
||
check_val(warn_pdd_qp_col, ROW_VALUES(row)+4, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_WARN_PDD] = VAL_DOUBLE(ROW_VALUES(row)+4); | ||
|
||
check_val(warn_ast_qp_col, ROW_VALUES(row)+5, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_WARN_AST] = VAL_DOUBLE(ROW_VALUES(row)+5); | ||
|
||
check_val(warn_acd_qp_col, ROW_VALUES(row)+6, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_WARN_ACD] = VAL_DOUBLE(ROW_VALUES(row)+6); | ||
|
||
check_val(dsbl_asr_qp_col, ROW_VALUES(row)+7, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_DSBL_ASR] = VAL_DOUBLE(ROW_VALUES(row)+7); | ||
|
||
check_val(dsbl_ccr_qp_col, ROW_VALUES(row)+8, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_DSBL_CCR] = VAL_DOUBLE(ROW_VALUES(row)+8); | ||
|
||
check_val(dsbl_pdd_qp_col, ROW_VALUES(row)+9, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_DSBL_PDD] = VAL_DOUBLE(ROW_VALUES(row)+9); | ||
|
||
check_val(dsbl_ast_qp_col, ROW_VALUES(row)+10, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_DSBL_AST] = VAL_DOUBLE(ROW_VALUES(row)+10); | ||
|
||
check_val(dsbl_acd_qp_col, ROW_VALUES(row)+11, DB_DOUBLE, 1, 1); | ||
double_vals[DOUBLE_VALS_DSBL_ACD] = VAL_DOUBLE(ROW_VALUES(row)+11); | ||
n++; | ||
LM_DBG("qr_profile row: %d %s %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n", | ||
int_vals[INT_VALS_ID], str_vals[STR_VALS_PROFILE_NAME], | ||
double_vals[DOUBLE_VALS_WARN_ASR], double_vals[DOUBLE_VALS_WARN_CCR], | ||
double_vals[DOUBLE_VALS_WARN_PDD], double_vals[DOUBLE_VALS_WARN_AST], | ||
double_vals[DOUBLE_VALS_WARN_ACD], double_vals[DOUBLE_VALS_DSBL_ASR], | ||
double_vals[DOUBLE_VALS_DSBL_CCR], double_vals[DOUBLE_VALS_DSBL_PDD], | ||
double_vals[DOUBLE_VALS_DSBL_AST], double_vals[DOUBLE_VALS_DSBL_ACD]); | ||
} | ||
if (DB_CAPABILITY(*qr_dbf, DB_CAP_FETCH)) { | ||
if(qr_dbf->fetch_result(qr_db_hdl, &res, no_rows)<0) { | ||
LM_ERR( "fetching rows (1)\n"); | ||
goto error; | ||
} | ||
} else { | ||
break; | ||
} | ||
|
||
} while(RES_ROW_N(res)); | ||
return 0; | ||
error: | ||
return -1; | ||
|
||
} | ||
|
Oops, something went wrong.