db v6: determine 3G AUC IND from VLR name

Each VLR requesting auth tuples should use a distinct IND pool for 3G
auth.  So far we tied the IND to the GSUP peer connection; MSC and SGSN
were always distinct GSUP peers, they ended up using distinct INDs.

However, we have implemented a GSUP proxy, so that, in a distributed
setup, a remotely roaming subscriber has only one direct GSUP peer
proxying for both remote MSC and SGSN. That means as soon as a
subscriber roams to a different site, we would use the GSUP proxy name
to determine the IND instead of the separate MSC and SGSN. The site's
MSC and SGSN appear as the same client, get the same IND bucket, waste
SQNs rapidly and cause auth tuple generation load.

So instead of using the local client as IND, persistently keep a list of
VLR names and assign a different IND to each. Use the
gsup_req->source_name as indicator, which reflects the actual remote
VLR's name (remote MSC or SGSN).

Persist the site <-> IND assignments in the database.

Add an IND test to db_test.c

There was an earlier patch version that separated the IND pools by
cn_domain, but it turned out to add complex semantics, while only
solving one aspect of the "adjacent VLR" problem. We need a solution not
only for CS vs PS, but also for 2,3G vs 4G, and for sites that are
physically adjacent to each other. This patch version does not offer any
automatic solution for that -- as soon as more than 2^IND_bitlen
(usually 32) VLRs show up, it is the responsibility of the admin to
ensure the 'ind' table in the hlr.db does not have unfortunate IND
assignments. So far no VTY commands exist for that, they may be added in
the future.

Related: OS#4319
Change-Id: I6f0a6bbef3a27507605c3b4a0e1a89bdfd468374
This commit is contained in:
Neels Hofmeyr 2019-12-12 04:04:53 +01:00 committed by laforge
parent 608e2e483f
commit 3f9d1977df
18 changed files with 296 additions and 341 deletions

View File

@ -206,7 +206,6 @@ AC_OUTPUT(
tests/Makefile tests/Makefile
tests/auc/Makefile tests/auc/Makefile
tests/auc/gen_ts_55_205_test_sets/Makefile tests/auc/gen_ts_55_205_test_sets/Makefile
tests/gsup_server/Makefile
tests/gsup/Makefile tests/gsup/Makefile
tests/db/Makefile tests/db/Makefile
tests/db_upgrade/Makefile tests/db_upgrade/Makefile

View File

@ -4,6 +4,7 @@
#include <sqlite3.h> #include <sqlite3.h>
#include <osmocom/gsupclient/cni_peer_id.h> #include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsm/gsup.h>
struct hlr; struct hlr;
@ -40,6 +41,9 @@ enum stmt_idx {
DB_STMT_SET_LAST_LU_SEEN_PS, DB_STMT_SET_LAST_LU_SEEN_PS,
DB_STMT_EXISTS_BY_IMSI, DB_STMT_EXISTS_BY_IMSI,
DB_STMT_EXISTS_BY_MSISDN, DB_STMT_EXISTS_BY_MSISDN,
DB_STMT_IND_ADD,
DB_STMT_IND_SELECT,
DB_STMT_IND_DEL,
_NUM_DB_STMT _NUM_DB_STMT
}; };
@ -173,6 +177,9 @@ int db_subscr_lu(struct db_context *dbc, int64_t subscr_id,
int db_subscr_purge(struct db_context *dbc, const char *by_imsi, int db_subscr_purge(struct db_context *dbc, const char *by_imsi,
bool purge_val, bool is_ps); bool purge_val, bool is_ps);
int db_ind(struct db_context *dbc, const struct osmo_cni_peer_id *vlr, unsigned int *ind);
int db_ind_del(struct db_context *dbc, const struct osmo_cni_peer_id *vlr);
/*! Call sqlite3_column_text() and copy result to a char[]. /*! Call sqlite3_column_text() and copy result to a char[].
* \param[out] buf A char[] used as sizeof() arg(!) and osmo_strlcpy() target. * \param[out] buf A char[] used as sizeof() arg(!) and osmo_strlcpy() target.
* \param[in] stmt An sqlite3_stmt*. * \param[in] stmt An sqlite3_stmt*.

View File

@ -42,8 +42,6 @@ struct osmo_gsup_conn {
//struct oap_state oap_state; //struct oap_state oap_state;
struct tlv_parsed ccm; struct tlv_parsed ccm;
unsigned int auc_3g_ind; /*!< IND index used for UMTS AKA SQN */
/* Set when Location Update is received: */ /* Set when Location Update is received: */
bool supports_cs; /* client supports OSMO_GSUP_CN_DOMAIN_CS */ bool supports_cs; /* client supports OSMO_GSUP_CN_DOMAIN_CS */
bool supports_ps; /* client supports OSMO_GSUP_CN_DOMAIN_PS */ bool supports_ps; /* client supports OSMO_GSUP_CN_DOMAIN_PS */

View File

@ -79,8 +79,16 @@ CREATE TABLE auc_3g (
ind_bitlen INTEGER NOT NULL DEFAULT 5 ind_bitlen INTEGER NOT NULL DEFAULT 5
); );
CREATE TABLE ind (
-- 3G auth IND pool to be used for this VLR
ind INTEGER PRIMARY KEY,
-- VLR identification, usually the GSUP source_name
vlr TEXT NOT NULL,
UNIQUE (vlr)
);
CREATE UNIQUE INDEX idx_subscr_imsi ON subscriber (imsi); CREATE UNIQUE INDEX idx_subscr_imsi ON subscriber (imsi);
-- Set HLR database schema version number -- Set HLR database schema version number
-- Note: This constant is currently duplicated in src/db.c and must be kept in sync! -- Note: This constant is currently duplicated in src/db.c and must be kept in sync!
PRAGMA user_version = 5; PRAGMA user_version = 6;

View File

@ -28,7 +28,7 @@
#include "db_bootstrap.h" #include "db_bootstrap.h"
/* This constant is currently duplicated in sql/hlr.sql and must be kept in sync! */ /* This constant is currently duplicated in sql/hlr.sql and must be kept in sync! */
#define CURRENT_SCHEMA_VERSION 5 #define CURRENT_SCHEMA_VERSION 6
#define SEL_COLUMNS \ #define SEL_COLUMNS \
"id," \ "id," \
@ -93,6 +93,9 @@ static const char *stmt_sql[] = {
[DB_STMT_SET_LAST_LU_SEEN_PS] = "UPDATE subscriber SET last_lu_seen_ps = datetime($val, 'unixepoch') WHERE id = $subscriber_id", [DB_STMT_SET_LAST_LU_SEEN_PS] = "UPDATE subscriber SET last_lu_seen_ps = datetime($val, 'unixepoch') WHERE id = $subscriber_id",
[DB_STMT_EXISTS_BY_IMSI] = "SELECT 1 FROM subscriber WHERE imsi = $imsi", [DB_STMT_EXISTS_BY_IMSI] = "SELECT 1 FROM subscriber WHERE imsi = $imsi",
[DB_STMT_EXISTS_BY_MSISDN] = "SELECT 1 FROM subscriber WHERE msisdn = $msisdn", [DB_STMT_EXISTS_BY_MSISDN] = "SELECT 1 FROM subscriber WHERE msisdn = $msisdn",
[DB_STMT_IND_ADD] = "INSERT INTO ind (vlr) VALUES ($vlr)",
[DB_STMT_IND_SELECT] = "SELECT ind FROM ind WHERE vlr = $vlr",
[DB_STMT_IND_DEL] = "DELETE FROM ind WHERE vlr = $vlr",
}; };
static void sql3_error_log_cb(void *arg, int err_code, const char *msg) static void sql3_error_log_cb(void *arg, int err_code, const char *msg)
@ -487,6 +490,29 @@ static int db_upgrade_v5(struct db_context *dbc)
return rc; return rc;
} }
static int db_upgrade_v6(struct db_context *dbc)
{
int rc;
const char *statements[] = {
"CREATE TABLE ind (\n"
" -- 3G auth IND pool to be used for this VLR\n"
" ind INTEGER PRIMARY KEY,\n"
" -- VLR identification, usually the GSUP source_name\n"
" vlr TEXT NOT NULL,\n"
" UNIQUE (vlr)\n"
")"
,
"PRAGMA user_version = 6",
};
rc = db_run_statements(dbc, statements, ARRAY_SIZE(statements));
if (rc != SQLITE_DONE) {
LOGP(DDB, LOGL_ERROR, "Unable to update HLR database schema to version 6\n");
return rc;
}
return rc;
}
typedef int (*db_upgrade_func_t)(struct db_context *dbc); typedef int (*db_upgrade_func_t)(struct db_context *dbc);
static db_upgrade_func_t db_upgrade_path[] = { static db_upgrade_func_t db_upgrade_path[] = {
db_upgrade_v1, db_upgrade_v1,
@ -494,6 +520,7 @@ static db_upgrade_func_t db_upgrade_path[] = {
db_upgrade_v3, db_upgrade_v3,
db_upgrade_v4, db_upgrade_v4,
db_upgrade_v5, db_upgrade_v5,
db_upgrade_v6,
}; };
static int db_get_user_version(struct db_context *dbc) static int db_get_user_version(struct db_context *dbc)

View File

@ -972,3 +972,106 @@ out:
return ret; return ret;
} }
static int _db_ind_run(struct db_context *dbc, sqlite3_stmt *stmt, const char *vlr, bool reset)
{
int rc;
if (!db_bind_text(stmt, "$vlr", vlr))
return -EIO;
/* execute the statement */
rc = sqlite3_step(stmt);
if (reset)
db_remove_reset(stmt);
return rc;
}
static int _db_ind_add(struct db_context *dbc, const char *vlr)
{
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_IND_ADD];
if (_db_ind_run(dbc, stmt, vlr, true) != SQLITE_DONE) {
LOGP(DDB, LOGL_ERROR, "Cannot create IND entry for %s\n", osmo_quote_str_c(OTC_SELECT, vlr, -1));
return -EIO;
}
return 0;
}
static int _db_ind_del(struct db_context *dbc, const char *vlr)
{
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_IND_DEL];
_db_ind_run(dbc, stmt, vlr, true);
/* We don't really care about the result. If it didn't exist, then that was the goal anyway. */
return 0;
}
static int _db_ind_get(struct db_context *dbc, const char *vlr, unsigned int *ind)
{
int ret = 0;
sqlite3_stmt *stmt = dbc->stmt[DB_STMT_IND_SELECT];
int rc = _db_ind_run(dbc, stmt, vlr, false);
if (rc == SQLITE_DONE) {
/* Does not exist yet */
ret = -ENOENT;
goto out;
} else if (rc != SQLITE_ROW) {
LOGP(DDB, LOGL_ERROR, "Error executing SQL: %d\n", rc);
ret = -EIO;
goto out;
}
OSMO_ASSERT(ind);
*ind = sqlite3_column_int64(stmt, 0);
out:
db_remove_reset(stmt);
return ret;
}
int _db_ind(struct db_context *dbc, const struct osmo_cni_peer_id *vlr,
unsigned int *ind, bool del)
{
const char *vlr_name = NULL;
int rc;
switch (vlr->type) {
case OSMO_CNI_PEER_ID_IPA_NAME:
if (vlr->ipa_name.len < 2 || vlr->ipa_name.val[vlr->ipa_name.len - 1] != '\0') {
LOGP(DDB, LOGL_ERROR, "Expecting VLR ipa_name to be zero terminated; found %s\n",
osmo_ipa_name_to_str(&vlr->ipa_name));
return -ENOTSUP;
}
vlr_name = (const char*)vlr->ipa_name.val;
break;
default:
LOGP(DDB, LOGL_ERROR, "Unsupported osmo_cni_peer_id type: %s\n",
osmo_cni_peer_id_type_name(vlr->type));
return -ENOTSUP;
}
if (del)
return _db_ind_del(dbc, vlr_name);
rc = _db_ind_get(dbc, vlr_name, ind);
if (!rc)
return 0;
/* Does not exist yet, create. */
rc = _db_ind_add(dbc, vlr_name);
if (rc) {
LOGP(DDB, LOGL_ERROR, "Error creating IND entry for %s\n", osmo_quote_str_c(OTC_SELECT, vlr_name, -1));
return rc;
}
/* To be sure, query again from scratch. */
return _db_ind_get(dbc, vlr_name, ind);
}
int db_ind(struct db_context *dbc, const struct osmo_cni_peer_id *vlr, unsigned int *ind)
{
return _db_ind(dbc, vlr, ind, false);
}
int db_ind_del(struct db_context *dbc, const struct osmo_cni_peer_id *vlr)
{
return _db_ind(dbc, vlr, NULL, true);
}

View File

@ -317,43 +317,6 @@ static int osmo_gsup_server_closed_cb(struct ipa_server_conn *conn)
return 0; return 0;
} }
/* Add conn to the clients list in a way that conn->auc_3g_ind takes the lowest
* unused integer and the list of clients remains sorted by auc_3g_ind.
* Keep this function non-static to allow linking in a unit test. */
void osmo_gsup_server_add_conn(struct llist_head *clients,
struct osmo_gsup_conn *conn)
{
struct osmo_gsup_conn *c;
struct osmo_gsup_conn *prev_conn;
c = llist_first_entry_or_null(clients, struct osmo_gsup_conn, list);
/* Is the first index, 0, unused? */
if (!c || c->auc_3g_ind > 0) {
conn->auc_3g_ind = 0;
llist_add(&conn->list, clients);
return;
}
/* Look for a gap later on */
prev_conn = NULL;
llist_for_each_entry(c, clients, list) {
/* skip first item, we know it has auc_3g_ind == 0. */
if (!prev_conn) {
prev_conn = c;
continue;
}
if (c->auc_3g_ind > prev_conn->auc_3g_ind + 1)
break;
prev_conn = c;
}
OSMO_ASSERT(prev_conn);
conn->auc_3g_ind = prev_conn->auc_3g_ind + 1;
llist_add(&conn->list, &prev_conn->list);
}
static void update_fd_settings(int fd) static void update_fd_settings(int fd)
{ {
int ret; int ret;
@ -386,10 +349,9 @@ static int osmo_gsup_server_accept_cb(struct ipa_server_link *link, int fd)
/* link data structure with server structure */ /* link data structure with server structure */
conn->server = gsups; conn->server = gsups;
osmo_gsup_server_add_conn(&gsups->clients, conn); llist_add_tail(&conn->list, &gsups->clients);
LOGP(DLGSUP, LOGL_INFO, "New GSUP client %s:%d (IND=%u)\n", LOGP(DLGSUP, LOGL_INFO, "New GSUP client %s:%d\n", conn->conn->addr, conn->conn->port);
conn->conn->addr, conn->conn->port, conn->auc_3g_ind);
update_fd_settings(fd); update_fd_settings(fd);

View File

@ -281,13 +281,14 @@ int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val,
***********************************************************************/ ***********************************************************************/
/* process an incoming SAI request */ /* process an incoming SAI request */
static int rx_send_auth_info(unsigned int auc_3g_ind, struct osmo_gsup_req *req) static int rx_send_auth_info(struct osmo_gsup_req *req)
{ {
struct osmo_gsup_message gsup_out = { struct osmo_gsup_message gsup_out = {
.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT, .message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT,
}; };
bool separation_bit = false; bool separation_bit = false;
int num_auth_vectors = OSMO_GSUP_MAX_NUM_AUTH_INFO; int num_auth_vectors = OSMO_GSUP_MAX_NUM_AUTH_INFO;
unsigned int auc_3g_ind;
int rc; int rc;
subscr_create_on_demand(req->gsup.imsi); subscr_create_on_demand(req->gsup.imsi);
@ -298,6 +299,14 @@ static int rx_send_auth_info(unsigned int auc_3g_ind, struct osmo_gsup_req *req)
if (req->gsup.num_auth_vectors > 0 && if (req->gsup.num_auth_vectors > 0 &&
req->gsup.num_auth_vectors <= OSMO_GSUP_MAX_NUM_AUTH_INFO) req->gsup.num_auth_vectors <= OSMO_GSUP_MAX_NUM_AUTH_INFO)
num_auth_vectors = req->gsup.num_auth_vectors; num_auth_vectors = req->gsup.num_auth_vectors;
rc = db_ind(g_hlr->dbc, &req->source_name, &auc_3g_ind);
if (rc) {
LOG_GSUP_REQ(req, LOGL_ERROR,
"Unable to determine 3G auth IND for source %s (rc=%d),"
" generating tuples with IND = 0\n",
osmo_cni_peer_id_to_str(&req->source_name), rc);
auc_3g_ind = 0;
}
rc = db_get_auc(g_hlr->dbc, req->gsup.imsi, auc_3g_ind, rc = db_get_auc(g_hlr->dbc, req->gsup.imsi, auc_3g_ind,
gsup_out.auth_vectors, gsup_out.auth_vectors,
@ -517,7 +526,7 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
switch (req->gsup.message_type) { switch (req->gsup.message_type) {
/* requests sent to us */ /* requests sent to us */
case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST: case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:
rx_send_auth_info(conn->auc_3g_ind, req); rx_send_auth_info(req);
break; break;
case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST: case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST:
rx_upd_loc_req(conn, req); rx_upd_loc_req(conn, req);

View File

@ -116,8 +116,8 @@ static void show_one_conn(struct vty *vty, const struct osmo_gsup_conn *conn)
rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR); rc = osmo_gsup_conn_ccm_get(conn, (uint8_t **) &name, IPAC_IDTAG_SERNR);
OSMO_ASSERT(rc); OSMO_ASSERT(rc);
vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u, 3G_IND=%u%s", vty_out(vty, " '%s' from %s:%5u, CS=%u, PS=%u%s",
name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps, conn->auc_3g_ind, name, isc->addr, isc->port, conn->supports_cs, conn->supports_ps,
VTY_NEWLINE); VTY_NEWLINE);
} }

View File

@ -1,6 +1,5 @@
SUBDIRS = \ SUBDIRS = \
auc \ auc \
gsup_server \
db \ db \
gsup \ gsup \
db_upgrade \ db_upgrade \

View File

@ -918,6 +918,50 @@ static void test_subscr_sqn()
comment_end(); comment_end();
} }
static void test_ind()
{
comment_start();
#define ASSERT_IND(VLR, IND) do { \
unsigned int ind; \
struct osmo_cni_peer_id vlr; \
OSMO_ASSERT(!osmo_cni_peer_id_set_str(&vlr, OSMO_CNI_PEER_ID_IPA_NAME, VLR)); \
ASSERT_RC(db_ind(dbc, &vlr, &ind), 0); \
fprintf(stderr, "%s ind = %u\n\n", osmo_quote_str((char*)vlr.ipa_name.val, vlr.ipa_name.len), ind); \
if (ind != (IND)) \
fprintf(stderr, " ERROR: expected " #IND "\n"); \
} while (0)
#define IND_DEL(VLR) do { \
struct osmo_cni_peer_id vlr; \
OSMO_ASSERT(!osmo_cni_peer_id_set_str(&vlr, OSMO_CNI_PEER_ID_IPA_NAME, VLR)); \
ASSERT_RC(db_ind_del(dbc, &vlr), 0); \
fprintf(stderr, "%s ind deleted\n\n", osmo_quote_str((char*)vlr.ipa_name.val, vlr.ipa_name.len)); \
} while (0)
ASSERT_IND("msc-23", 1);
ASSERT_IND("sgsn-11", 2);
ASSERT_IND("msc-42", 3);
ASSERT_IND("sgsn-22", 4);
ASSERT_IND("msc-0x17", 5);
ASSERT_IND("sgsn-0xaa", 6);
ASSERT_IND("msc-42", 3);
ASSERT_IND("sgsn-22", 4);
ASSERT_IND("msc-0x17", 5);
ASSERT_IND("sgsn-0xaa", 6);
ASSERT_IND("sgsn-0xbb", 7);
ASSERT_IND("msc-0x2a", 8);
ASSERT_IND("msc-42", 3);
ASSERT_IND("sgsn-22", 4);
ASSERT_IND("msc-23", 1);
ASSERT_IND("sgsn-11", 2);
IND_DEL("msc-0x17"); /* dropped IND == 5 */
ASSERT_IND("msc-0x2a", 8); /* known CS remains where it is */
ASSERT_IND("any-unknown", 9); /* new VLR takes a new IND from the end */
comment_end();
}
static struct { static struct {
bool verbose; bool verbose;
} cmdline_opts = { } cmdline_opts = {
@ -1002,6 +1046,7 @@ int main(int argc, char **argv)
test_subscr_aud(); test_subscr_aud();
test_subscr_aud_invalid_len(); test_subscr_aud_invalid_len();
test_subscr_sqn(); test_subscr_sqn();
test_ind();
printf("Done\n"); printf("Done\n");
db_close(dbc); db_close(dbc);

View File

@ -1613,3 +1613,83 @@ db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> -ENOENT
===== test_subscr_sqn: SUCCESS ===== test_subscr_sqn: SUCCESS
===== test_ind
db_ind(dbc, &vlr, &ind) --> 0
"msc-23\0" ind = 1
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-11\0" ind = 2
db_ind(dbc, &vlr, &ind) --> 0
"msc-42\0" ind = 3
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-22\0" ind = 4
db_ind(dbc, &vlr, &ind) --> 0
"msc-0x17\0" ind = 5
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-0xaa\0" ind = 6
db_ind(dbc, &vlr, &ind) --> 0
"msc-42\0" ind = 3
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-22\0" ind = 4
db_ind(dbc, &vlr, &ind) --> 0
"msc-0x17\0" ind = 5
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-0xaa\0" ind = 6
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-0xbb\0" ind = 7
db_ind(dbc, &vlr, &ind) --> 0
"msc-0x2a\0" ind = 8
db_ind(dbc, &vlr, &ind) --> 0
"msc-42\0" ind = 3
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-22\0" ind = 4
db_ind(dbc, &vlr, &ind) --> 0
"msc-23\0" ind = 1
db_ind(dbc, &vlr, &ind) --> 0
"sgsn-11\0" ind = 2
db_ind_del(dbc, &vlr) --> 0
"msc-0x17\0" ind deleted
db_ind(dbc, &vlr, &ind) --> 0
"msc-0x2a\0" ind = 8
db_ind(dbc, &vlr, &ind) --> 0
"any-unknown\0" ind = 9
===== test_ind: SUCCESS

View File

@ -85,6 +85,7 @@ DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 2
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 3 DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 3
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 4 DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 4
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 5 DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 5
DDB Database <PATH>test.db' has been upgraded to HLR DB schema version 6
DMAIN Cmdline option --db-check: Database was opened successfully, quitting. DMAIN Cmdline option --db-check: Database was opened successfully, quitting.
Resulting db: Resulting db:
@ -117,6 +118,13 @@ algo_id_3g|ind_bitlen|k|op|opc|sqn|subscriber_id
5|5|44444444444444444444444444444444|44444444444444444444444444444444||0|5 5|5|44444444444444444444444444444444|44444444444444444444444444444444||0|5
5|5|55555555555555555555555555555555||55555555555555555555555555555555|0|6 5|5|55555555555555555555555555555555||55555555555555555555555555555555|0|6
Table: ind
name|type|notnull|dflt_value|pk
ind|INTEGER|0||1
vlr|TEXT|1||0
Table ind contents:
Table: subscriber Table: subscriber
name|type|notnull|dflt_value|pk name|type|notnull|dflt_value|pk
ggsn_number|VARCHAR(15)|0||0 ggsn_number|VARCHAR(15)|0||0
@ -171,5 +179,5 @@ osmo-hlr --database $db --db-check --config-file $srcdir/osmo-hlr.cfg
rc = 0 rc = 0
DMAIN hlr starting DMAIN hlr starting
DDB using database: <PATH>test.db DDB using database: <PATH>test.db
DDB Database <PATH>test.db' has HLR DB schema version 5 DDB Database <PATH>test.db' has HLR DB schema version 6
DMAIN Cmdline option --db-check: Database was opened successfully, quitting. DMAIN Cmdline option --db-check: Database was opened successfully, quitting.

View File

@ -1,44 +0,0 @@
AM_CPPFLAGS = \
$(all_includes) \
$(NULL)
AM_CFLAGS = \
-Wall \
-ggdb3 \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(LIBOSMOGSM_CFLAGS) \
$(LIBOSMOABIS_CFLAGS) \
$(NULL)
AM_LDFLAGS = \
-no-install \
$(NULL)
EXTRA_DIST = \
gsup_server_test.ok \
gsup_server_test.err \
$(NULL)
noinst_PROGRAMS = \
gsup_server_test \
$(NULL)
gsup_server_test_SOURCES = \
gsup_server_test.c \
$(NULL)
gsup_server_test_LDADD = \
$(top_srcdir)/src/gsup_server.c \
$(top_srcdir)/src/gsup_router.c \
$(top_srcdir)/src/gsup_send.c \
$(top_srcdir)/src/gsupclient/cni_peer_id.c \
$(top_srcdir)/src/gsupclient/gsup_req.c \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOABIS_LIBS) \
$(NULL)
.PHONY: update_exp
update_exp:
$(builddir)/gsup_server_test >"$(srcdir)/gsup_server_test.ok" 2>"$(srcdir)/gsup_server_test.err"

View File

@ -1,145 +0,0 @@
/* (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdio.h>
#include <osmocom/core/utils.h>
#include <osmocom/hlr/gsup_server.h>
#define comment_start() printf("\n===== %s\n", __func__)
#define comment_end() printf("===== %s: SUCCESS\n\n", __func__)
#define btw(fmt, args...) printf("\n" fmt "\n", ## args)
#define VERBOSE_ASSERT(val, expect_op, fmt) \
do { \
printf(#val " == " fmt "\n", (val)); \
OSMO_ASSERT((val) expect_op); \
} while (0)
void osmo_gsup_server_add_conn(struct llist_head *clients,
struct osmo_gsup_conn *conn);
static void test_add_conn(void)
{
struct llist_head _list;
struct llist_head *clients = &_list;
struct osmo_gsup_conn conn_inst[23] = {};
struct osmo_gsup_conn *conn;
unsigned int i;
comment_start();
INIT_LLIST_HEAD(clients);
btw("Add 10 items");
for (i = 0; i < 10; i++) {
osmo_gsup_server_add_conn(clients, &conn_inst[i]);
printf("conn_inst[%u].auc_3g_ind == %u\n", i, conn_inst[i].auc_3g_ind);
OSMO_ASSERT(clients->next == &conn_inst[0].list);
}
btw("Expecting a list of 0..9");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i);
OSMO_ASSERT(conn == &conn_inst[i]);
i++;
}
btw("Punch two holes in the sequence in arbitrary order,"
" a larger one from 2..4 and a single one at 7.");
llist_del(&conn_inst[4].list);
llist_del(&conn_inst[2].list);
llist_del(&conn_inst[3].list);
llist_del(&conn_inst[7].list);
btw("Expecting a list of 0,1, 5,6, 8,9");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
i++;
}
btw("Add conns, expecting them to take the open slots");
osmo_gsup_server_add_conn(clients, &conn_inst[12]);
VERBOSE_ASSERT(conn_inst[12].auc_3g_ind, == 2, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[13]);
VERBOSE_ASSERT(conn_inst[13].auc_3g_ind, == 3, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[14]);
VERBOSE_ASSERT(conn_inst[14].auc_3g_ind, == 4, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[17]);
VERBOSE_ASSERT(conn_inst[17].auc_3g_ind, == 7, "%u");
osmo_gsup_server_add_conn(clients, &conn_inst[18]);
VERBOSE_ASSERT(conn_inst[18].auc_3g_ind, == 10, "%u");
btw("Expecting a list of 0..10");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i);
i++;
}
btw("Does it also work for the first item?");
llist_del(&conn_inst[0].list);
btw("Expecting a list of 1..10");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i + 1);
i++;
}
btw("Add another conn, should take auc_3g_ind == 0");
osmo_gsup_server_add_conn(clients, &conn_inst[20]);
VERBOSE_ASSERT(conn_inst[20].auc_3g_ind, == 0, "%u");
btw("Expecting a list of 0..10");
i = 0;
llist_for_each_entry(conn, clients, list) {
printf("conn[%u].auc_3g_ind == %u\n", i, conn->auc_3g_ind);
OSMO_ASSERT(conn->auc_3g_ind == i);
i++;
}
btw("If a client reconnects, it will (likely) get the same auc_3g_ind");
VERBOSE_ASSERT(conn_inst[5].auc_3g_ind, == 5, "%u");
llist_del(&conn_inst[5].list);
conn_inst[5].auc_3g_ind = 423;
osmo_gsup_server_add_conn(clients, &conn_inst[5]);
VERBOSE_ASSERT(conn_inst[5].auc_3g_ind, == 5, "%u");
comment_end();
}
int main(int argc, char **argv)
{
printf("test_gsup_server.c\n");
test_add_conn();
printf("Done\n");
return 0;
}

View File

@ -1,94 +0,0 @@
test_gsup_server.c
===== test_add_conn
Add 10 items
conn_inst[0].auc_3g_ind == 0
conn_inst[1].auc_3g_ind == 1
conn_inst[2].auc_3g_ind == 2
conn_inst[3].auc_3g_ind == 3
conn_inst[4].auc_3g_ind == 4
conn_inst[5].auc_3g_ind == 5
conn_inst[6].auc_3g_ind == 6
conn_inst[7].auc_3g_ind == 7
conn_inst[8].auc_3g_ind == 8
conn_inst[9].auc_3g_ind == 9
Expecting a list of 0..9
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 2
conn[3].auc_3g_ind == 3
conn[4].auc_3g_ind == 4
conn[5].auc_3g_ind == 5
conn[6].auc_3g_ind == 6
conn[7].auc_3g_ind == 7
conn[8].auc_3g_ind == 8
conn[9].auc_3g_ind == 9
Punch two holes in the sequence in arbitrary order, a larger one from 2..4 and a single one at 7.
Expecting a list of 0,1, 5,6, 8,9
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 5
conn[3].auc_3g_ind == 6
conn[4].auc_3g_ind == 8
conn[5].auc_3g_ind == 9
Add conns, expecting them to take the open slots
conn_inst[12].auc_3g_ind == 2
conn_inst[13].auc_3g_ind == 3
conn_inst[14].auc_3g_ind == 4
conn_inst[17].auc_3g_ind == 7
conn_inst[18].auc_3g_ind == 10
Expecting a list of 0..10
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 2
conn[3].auc_3g_ind == 3
conn[4].auc_3g_ind == 4
conn[5].auc_3g_ind == 5
conn[6].auc_3g_ind == 6
conn[7].auc_3g_ind == 7
conn[8].auc_3g_ind == 8
conn[9].auc_3g_ind == 9
conn[10].auc_3g_ind == 10
Does it also work for the first item?
Expecting a list of 1..10
conn[0].auc_3g_ind == 1
conn[1].auc_3g_ind == 2
conn[2].auc_3g_ind == 3
conn[3].auc_3g_ind == 4
conn[4].auc_3g_ind == 5
conn[5].auc_3g_ind == 6
conn[6].auc_3g_ind == 7
conn[7].auc_3g_ind == 8
conn[8].auc_3g_ind == 9
conn[9].auc_3g_ind == 10
Add another conn, should take auc_3g_ind == 0
conn_inst[20].auc_3g_ind == 0
Expecting a list of 0..10
conn[0].auc_3g_ind == 0
conn[1].auc_3g_ind == 1
conn[2].auc_3g_ind == 2
conn[3].auc_3g_ind == 3
conn[4].auc_3g_ind == 4
conn[5].auc_3g_ind == 5
conn[6].auc_3g_ind == 6
conn[7].auc_3g_ind == 7
conn[8].auc_3g_ind == 8
conn[9].auc_3g_ind == 9
conn[10].auc_3g_ind == 10
If a client reconnects, it will (likely) get the same auc_3g_ind
conn_inst[5].auc_3g_ind == 5
conn_inst[5].auc_3g_ind == 5
===== test_add_conn: SUCCESS
Done

View File

@ -22,13 +22,6 @@ cat $abs_srcdir/gsup/gsup_test.err > experr
AT_CHECK([$abs_top_builddir/tests/gsup/gsup_test], [], [expout], [experr]) AT_CHECK([$abs_top_builddir/tests/gsup/gsup_test], [], [expout], [experr])
AT_CLEANUP AT_CLEANUP
AT_SETUP([gsup_server])
AT_KEYWORDS([gsup_server])
cat $abs_srcdir/gsup_server/gsup_server_test.ok > expout
cat $abs_srcdir/gsup_server/gsup_server_test.err > experr
AT_CHECK([$abs_top_builddir/tests/gsup_server/gsup_server_test], [], [expout], [experr])
AT_CLEANUP
AT_SETUP([db]) AT_SETUP([db])
AT_KEYWORDS([db]) AT_KEYWORDS([db])
cat $abs_srcdir/db/db_test.ok > expout cat $abs_srcdir/db/db_test.ok > expout