osmo-bsc/tests/codec_pref/codec_pref_test.c

616 lines
16 KiB
C
Raw Normal View History

/*
* (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* Author: Philipp Maier
*
* 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 Affero 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 <osmocom/bsc/osmo_bsc.h>
#include <osmocom/bsc/bsc_msc_data.h>
#include <osmocom/bsc/gsm_04_80.h>
#include <osmocom/core/application.h>
#include <osmocom/bsc/codec_pref.h>
#include <stdio.h>
void *ctx = NULL;
#define MSC_AUDIO_SUPPORT_MAX 5
#define N_CONFIG_VARIANTS 9
/* Make sure that there is some memory to put our test configuration. */
static void init_msc_config(struct bsc_msc_data *msc)
{
unsigned int i;
msc->audio_support = talloc_zero_array(ctx, struct gsm_audio_support *, MSC_AUDIO_SUPPORT_MAX);
msc->audio_length = MSC_AUDIO_SUPPORT_MAX;
for (i = 0; i < MSC_AUDIO_SUPPORT_MAX; i++) {
msc->audio_support[i] = talloc_zero(msc->audio_support, struct gsm_audio_support);
}
}
/* Free memory that we have used for the test configuration. */
static void free_msc_config(struct bsc_msc_data *msc)
{
talloc_free(msc->audio_support);
}
/* The speech codec list is sent by the MS and lists the voice codec settings
* that the MS is able to support. The BSC must select one of this codecs
* depending on what the MSC is able to support. The following function
* generates some realistically made up speech codec lists. */
static void make_scl_config(struct gsm0808_speech_codec_list *scl, uint8_t config_no)
{
OSMO_ASSERT(config_no < N_CONFIG_VARIANTS);
switch (config_no) {
case 0:
/* FR1 only */
scl->codec[0].type = GSM0808_SCT_FR1;
scl->len = 1;
break;
case 1:
/* HR1 only */
scl->codec[0].type = GSM0808_SCT_HR1;
scl->len = 1;
break;
case 2:
/* FR2 only */
scl->codec[0].type = GSM0808_SCT_FR2;
scl->len = 1;
break;
case 3:
/* FR3 only */
scl->codec[0].type = GSM0808_SCT_FR3;
scl->len = 1;
break;
case 4:
/* HR3 only */
scl->codec[0].type = GSM0808_SCT_HR3;
scl->len = 1;
break;
case 5:
/* FR1 and HR1 */
scl->codec[0].type = GSM0808_SCT_FR1;
scl->codec[1].type = GSM0808_SCT_HR1;
scl->len = 2;
break;
case 6:
/* FR1, FR2 and HR1 */
scl->codec[0].type = GSM0808_SCT_FR1;
scl->codec[1].type = GSM0808_SCT_FR2;
scl->codec[2].type = GSM0808_SCT_HR1;
scl->len = 3;
break;
case 7:
/* FR1, FR3 and HR3 */
scl->codec[0].type = GSM0808_SCT_FR1;
scl->codec[1].type = GSM0808_SCT_FR3;
scl->codec[2].type = GSM0808_SCT_HR3;
scl->len = 3;
break;
case 8:
/* FR1, FR2, FR3, HR1 and HR3 */
scl->codec[0].type = GSM0808_SCT_FR1;
scl->codec[1].type = GSM0808_SCT_FR2;
scl->codec[2].type = GSM0808_SCT_FR3;
scl->codec[3].type = GSM0808_SCT_HR1;
scl->codec[4].type = GSM0808_SCT_HR3;
scl->len = 5;
break;
}
}
/* The channel type element which is sent to the BSC by the MSC lists all the
* codecs that the MSC is able to support. The following function generates
* a realistic permitted speech settings */
static void make_ct_config(struct gsm0808_channel_type *ct, uint8_t config_no)
{
OSMO_ASSERT(config_no < N_CONFIG_VARIANTS);
switch (config_no) {
case 0:
/* FR1 only */
ct->perm_spch[0] = GSM0808_PERM_FR1;
ct->perm_spch_len = 1;
break;
case 1:
/* HR1 only */
ct->perm_spch[0] = GSM0808_PERM_HR1;
ct->perm_spch_len = 1;
break;
case 2:
/* FR2 only */
ct->perm_spch[0] = GSM0808_PERM_FR2;
ct->perm_spch_len = 1;
break;
case 3:
/* FR3 only */
ct->perm_spch[0] = GSM0808_PERM_FR3;
ct->perm_spch_len = 1;
break;
case 4:
/* HR3 only */
ct->perm_spch[0] = GSM0808_PERM_HR3;
ct->perm_spch_len = 1;
break;
case 5:
/* FR1 and HR1 */
ct->perm_spch[0] = GSM0808_PERM_FR1;
ct->perm_spch[1] = GSM0808_PERM_HR1;
ct->perm_spch_len = 2;
break;
case 6:
/* FR1, FR2 and HR1 */
ct->perm_spch[0] = GSM0808_PERM_FR1;
ct->perm_spch[1] = GSM0808_PERM_FR2;
ct->perm_spch[2] = GSM0808_PERM_HR1;
ct->perm_spch_len = 3;
break;
case 7:
/* FR1, FR3 and HR3 */
ct->perm_spch[0] = GSM0808_PERM_FR1;
ct->perm_spch[1] = GSM0808_PERM_FR3;
ct->perm_spch[2] = GSM0808_PERM_HR3;
ct->perm_spch_len = 3;
break;
case 8:
/* FR1, FR2, FR3, HR1 and HR3 */
ct->perm_spch[0] = GSM0808_PERM_FR1;
ct->perm_spch[1] = GSM0808_PERM_FR2;
ct->perm_spch[2] = GSM0808_PERM_FR3;
ct->perm_spch[3] = GSM0808_PERM_HR1;
ct->perm_spch[4] = GSM0808_PERM_HR3;
ct->perm_spch_len = 5;
break;
}
}
/* Generate some realistic MSC configuration which one also could find in the
* real world. This configuration acts as a filter. While the MSC could in
* theory advertise codecs more codecs as we are able to support we have to
* make sure that only the codecs we have support for are considered. */
static void make_msc_config(struct bsc_msc_data *msc, uint8_t config_no)
{
/* 1 = FR1/HR1
* 2 = FR2/HR2
* 3 = FR2/HR3
* Note: HR2 is deprecated */
OSMO_ASSERT(config_no < N_CONFIG_VARIANTS);
switch (config_no) {
case 0:
/* FR1 only */
msc->audio_support[0]->ver = 1;
msc->audio_support[0]->hr = 0;
msc->audio_length = 1;
break;
case 1:
/* HR1 only */
msc->audio_support[0]->ver = 1;
msc->audio_support[0]->hr = 1;
msc->audio_length = 1;
break;
case 2:
/* FR2 only */
msc->audio_support[0]->ver = 2;
msc->audio_support[0]->hr = 0;
msc->audio_length = 1;
break;
case 3:
/* FR3 only */
msc->audio_support[0]->ver = 3;
msc->audio_support[0]->hr = 0;
msc->audio_length = 1;
break;
case 4:
/* HR3 only */
msc->audio_support[0]->ver = 3;
msc->audio_support[0]->hr = 1;
msc->audio_length = 1;
break;
case 5:
/* FR1 and HR1 */
msc->audio_support[0]->ver = 1;
msc->audio_support[0]->hr = 0;
msc->audio_support[1]->ver = 1;
msc->audio_support[1]->hr = 1;
msc->audio_length = 2;
break;
case 6:
/* FR1, FR2 and HR1 */
msc->audio_support[0]->ver = 1;
msc->audio_support[0]->hr = 0;
msc->audio_support[1]->ver = 2;
msc->audio_support[1]->hr = 0;
msc->audio_support[2]->ver = 1;
msc->audio_support[2]->hr = 1;
msc->audio_length = 3;
break;
case 7:
/* FR1, FR3 and HR3 */
msc->audio_support[0]->ver = 1;
msc->audio_support[0]->hr = 0;
msc->audio_support[1]->ver = 3;
msc->audio_support[1]->hr = 0;
msc->audio_support[2]->ver = 3;
msc->audio_support[2]->hr = 1;
msc->audio_length = 3;
break;
case 8:
/* FR1, FR2, FR3, HR1 and HR3 */
msc->audio_support[0]->ver = 1;
msc->audio_support[0]->hr = 0;
msc->audio_support[1]->ver = 2;
msc->audio_support[1]->hr = 0;
msc->audio_support[2]->ver = 3;
msc->audio_support[2]->hr = 0;
msc->audio_support[3]->ver = 1;
msc->audio_support[3]->hr = 1;
msc->audio_support[4]->ver = 3;
msc->audio_support[4]->hr = 1;
msc->audio_length = 5;
break;
}
}
/* Generate a realitically looking bts codec configuration */
static void make_bts_config(struct gsm_bts *bts, uint8_t config_no)
{
/* Note: FR is supported by all BTSs, so there is no flag for it */
OSMO_ASSERT(config_no < N_CONFIG_VARIANTS);
bts->codec.hr = 0;
bts->codec.efr = 0;
bts->codec.amr = 0;
switch (config_no) {
case 0:
/* FR1 (implicit) only */
break;
case 1:
/* HR1 only (+FR implicit) */
bts->codec.hr = 1;
break;
case 2:
/* FR2 only (+FR implicit) */
bts->codec.efr = 1;
break;
case 3:
/* FR3 only (+FR implicit) */
bts->codec.amr = 1;
break;
case 4:
/* HR3 only (+FR implicit) */
bts->codec.amr = 1;
break;
case 5:
/* FR1 (implicit) and HR1 */
bts->codec.hr = 1;
break;
case 6:
/* FR1 (implicit), FR2 and HR1 */
bts->codec.efr = 1;
bts->codec.hr = 1;
break;
case 7:
/* FR1 (implicit), FR3 and HR3 */
bts->codec.amr = 1;
break;
case 8:
/* FR1 (implicit), FR2, FR3, HR1 and HR3 */
bts->codec.hr = 1;
bts->codec.efr = 1;
bts->codec.amr = 1;
break;
}
}
/* Try execute match_codec_pref(), display input and output parameters */
static int test_match_codec_pref(const struct gsm0808_channel_type *ct, const struct gsm0808_speech_codec_list *scl,
const struct bsc_msc_data *msc, struct gsm_bts *bts)
{
int rc;
unsigned int i;
large refactoring: use FSMs for lchans; add inter-BSC HO Add FSMs: - timeslot_fsm: handle dynamic timeslots and OML+RSL availability. - lchan_fsm: handle an individual lchan activation, RTP stream and release, signal the appropriate calling FSMs on success, failure, release. - mgw_endpoint_fsm: handle one entire endpoint with several CI. - assignment_fsm: BSSMAP Assignment Request. - handover_fsm: all of intra, inter-MO and inter-MT handover. Above FSMs absorb large parts of the gscon FSM. The gscon FSM was surpassing the maximum amount events (32), and it is more logical to treat assignment, handover and MGW procedures in separate FSMs. - Add logging macros for each FSM type: - LOG_TS() - LOG_LCHAN() - LOG_MGWEP(), LOG_CI() - LOG_ASSIGNMENT() - LOG_HO() These log with the osmo_fsm_inst where present. New style decision: logging without a final newline char is awkward, especially for gsmtap logging and when other logs interleave LOGPC() calls; we have various cases where the final \n goes missing, and also this invokes the log category checking N times instead of once. So I decided to make these macros *always* append a newline, but only if there is no final newline yet. I hope that the compiler optimizes the strlen() of the constant format strings away. Thus I can log with or without typing "\n" and always get an \n termination anyway. General: - replace osmo_timers, state enums and program-wide osmo_signal_dispatch() with dedicated FSM timeouts, states and events. - introduce a common way to handle Tnnn timers: gsm_timers.h/.c: struct T_def. These can be used (with some macro magic) to define a state's timeout once, and not make mistakes for each osmo_fsm_inst_state_chg(). Details: bsc_subscr_conn_fsm.c: - move most states of this FSM to lchan_fsm, assignment_fsm, handover_fsm and mgw_endpoint_fsm. - There is exactly one state for an ongoing Assignment, with all details handled in conn->assignment.fi. The state relies on the assignment_fsm's timeout. - There is one state for an ongoing Handover; except for an incoming Handover from a remote BSS, the gscon remains in ST_INIT until the new lchan and conn are both established. - move bssmap_add_lcls_status() to osmo_bsc_lcls.c abis_rsl.c: - move all dynamic timeslot logic away into timeslot_fsm. Only keep plain send/receive functions in abis_rsl.c - reduce some rsl functions to merely send a message, rename to "_tx_". - rsl_ipacc_mdcx(): add '_tx_' in the name; move parts that change the lchan state out into the lchan_fsm, the lchan->abis_ip.* are now set there prior to invoking this function. - move all timers and error/release handling away into various FSMs. - tweak ipa_smod_s_for_lchan() and ipa_rtp_pt_for_lchan() to not require an lchan passed, but just mode,type that they require. Rename to ipacc_speech_mode*() and ipacc_payload_type(). - add rsl_forward_layer3_info, used for inter-BSC HO MO, to just send the RR message received during BSSMAP Handover Command. - move various logging to LOG_LCHAN() in order to log with the lchan FSM instance. One drawback is that the lchan FSM is limited to one logging category, i.e. this moves some logging from DRR to DRSL. It might actually make sense to combine those categories. - lose LOGP...LOGPC logging cascades: they are bad for gsmtap logging and for performance. - handle_classmark_chg(): change logging, move cm2 len check out of the cm3 condition (I hope that's correct). - gsm48_send_ho_cmd(): split off gsm48_make_ho_cmd() which doesn't send right away, so that during inter-bsc HO we can make an RR Handover Command to send via the MSC to the remote BSS. assignment_fsm.c: - the Chan Mode Modify in case of re-using the same lchan is not implemented yet, because this was also missing in the previous implementation (OS#3357). osmo_bsc_api.c: - simplify bsc_mr_config() and move to lchan_fsm.c, the only caller; rename to lchan_mr_config(). (bsc_mr_config() used to copy the values to mr_bts_lv twice, once by member assignment and then again with a memcpy.) - During handover, we used to copy the MR config from the old lchan. Since we may handover between FR and HR, rather set the MR Config anew every time, so that FR rates are always available on FR lchans, and never on HR lchans. Depends: I03ee7ce840ecfa0b6a33358e7385528aabd4873f (libosmocore), I1f2918418c38918c5ac70acaa51a47adfca12b5e (libosmocore) Change-Id: I82e3f918295daa83274a4cf803f046979f284366
2018-05-14 16:14:15 +00:00
bool full_rate;
enum gsm48_chan_mode chan_mode;
printf("Determining channel mode and rate:\n");
printf(" * MS: speech codec list (%u items):\n", scl->len);
for (i = 0; i < scl->len; i++)
printf(" codec[%u]->type=%s\n", i, gsm0808_speech_codec_type_name(scl->codec[i].type));
printf(" * MSC: channel type permitted speech (%u items):\n", ct->perm_spch_len);
for (i = 0; i < ct->perm_spch_len; i++)
printf(" perm_spch[%u]=%s\n", i, gsm0808_permitted_speech_name(ct->perm_spch[i]));
printf(" * BSS: audio support settings (%u items):\n", msc->audio_length);
for (i = 0; i < msc->audio_length; i++)
if (msc->audio_support[i]->hr)
printf(" audio_support[%u]=HR%u\n", i, msc->audio_support[i]->ver);
else
printf(" audio_support[%u]=FR%u\n", i, msc->audio_support[i]->ver);
printf(" * BTS: audio support settings:\n");
printf(" (GSM-FR implicitly supported)\n");
printf(" codec->hr=%u\n", bts->codec.hr);
printf(" codec->efr=%u\n", bts->codec.efr);
printf(" codec->amr=%u\n", bts->codec.amr);
large refactoring: use FSMs for lchans; add inter-BSC HO Add FSMs: - timeslot_fsm: handle dynamic timeslots and OML+RSL availability. - lchan_fsm: handle an individual lchan activation, RTP stream and release, signal the appropriate calling FSMs on success, failure, release. - mgw_endpoint_fsm: handle one entire endpoint with several CI. - assignment_fsm: BSSMAP Assignment Request. - handover_fsm: all of intra, inter-MO and inter-MT handover. Above FSMs absorb large parts of the gscon FSM. The gscon FSM was surpassing the maximum amount events (32), and it is more logical to treat assignment, handover and MGW procedures in separate FSMs. - Add logging macros for each FSM type: - LOG_TS() - LOG_LCHAN() - LOG_MGWEP(), LOG_CI() - LOG_ASSIGNMENT() - LOG_HO() These log with the osmo_fsm_inst where present. New style decision: logging without a final newline char is awkward, especially for gsmtap logging and when other logs interleave LOGPC() calls; we have various cases where the final \n goes missing, and also this invokes the log category checking N times instead of once. So I decided to make these macros *always* append a newline, but only if there is no final newline yet. I hope that the compiler optimizes the strlen() of the constant format strings away. Thus I can log with or without typing "\n" and always get an \n termination anyway. General: - replace osmo_timers, state enums and program-wide osmo_signal_dispatch() with dedicated FSM timeouts, states and events. - introduce a common way to handle Tnnn timers: gsm_timers.h/.c: struct T_def. These can be used (with some macro magic) to define a state's timeout once, and not make mistakes for each osmo_fsm_inst_state_chg(). Details: bsc_subscr_conn_fsm.c: - move most states of this FSM to lchan_fsm, assignment_fsm, handover_fsm and mgw_endpoint_fsm. - There is exactly one state for an ongoing Assignment, with all details handled in conn->assignment.fi. The state relies on the assignment_fsm's timeout. - There is one state for an ongoing Handover; except for an incoming Handover from a remote BSS, the gscon remains in ST_INIT until the new lchan and conn are both established. - move bssmap_add_lcls_status() to osmo_bsc_lcls.c abis_rsl.c: - move all dynamic timeslot logic away into timeslot_fsm. Only keep plain send/receive functions in abis_rsl.c - reduce some rsl functions to merely send a message, rename to "_tx_". - rsl_ipacc_mdcx(): add '_tx_' in the name; move parts that change the lchan state out into the lchan_fsm, the lchan->abis_ip.* are now set there prior to invoking this function. - move all timers and error/release handling away into various FSMs. - tweak ipa_smod_s_for_lchan() and ipa_rtp_pt_for_lchan() to not require an lchan passed, but just mode,type that they require. Rename to ipacc_speech_mode*() and ipacc_payload_type(). - add rsl_forward_layer3_info, used for inter-BSC HO MO, to just send the RR message received during BSSMAP Handover Command. - move various logging to LOG_LCHAN() in order to log with the lchan FSM instance. One drawback is that the lchan FSM is limited to one logging category, i.e. this moves some logging from DRR to DRSL. It might actually make sense to combine those categories. - lose LOGP...LOGPC logging cascades: they are bad for gsmtap logging and for performance. - handle_classmark_chg(): change logging, move cm2 len check out of the cm3 condition (I hope that's correct). - gsm48_send_ho_cmd(): split off gsm48_make_ho_cmd() which doesn't send right away, so that during inter-bsc HO we can make an RR Handover Command to send via the MSC to the remote BSS. assignment_fsm.c: - the Chan Mode Modify in case of re-using the same lchan is not implemented yet, because this was also missing in the previous implementation (OS#3357). osmo_bsc_api.c: - simplify bsc_mr_config() and move to lchan_fsm.c, the only caller; rename to lchan_mr_config(). (bsc_mr_config() used to copy the values to mr_bts_lv twice, once by member assignment and then again with a memcpy.) - During handover, we used to copy the MR config from the old lchan. Since we may handover between FR and HR, rather set the MR Config anew every time, so that FR rates are always available on FR lchans, and never on HR lchans. Depends: I03ee7ce840ecfa0b6a33358e7385528aabd4873f (libosmocore), I1f2918418c38918c5ac70acaa51a47adfca12b5e (libosmocore) Change-Id: I82e3f918295daa83274a4cf803f046979f284366
2018-05-14 16:14:15 +00:00
rc = match_codec_pref(&chan_mode, &full_rate, ct, scl, msc->audio_support, msc->audio_length, &bts->codec);
printf(" * result: rc=%i, full_rate=%i, chan_mode=%s\n", rc, full_rate, gsm48_chan_mode_name(chan_mode));
printf("\n");
return rc;
}
/* MS, MSC and local MSC settings are the same */
static void test_one_to_one(void)
{
unsigned int i;
struct gsm0808_channel_type ct_msc;
struct gsm0808_speech_codec_list scl_ms;
struct bsc_msc_data msc_local;
struct gsm_bts bts_local;
int rc;
printf("============== test_one_to_one ==============\n\n");
init_msc_config(&msc_local);
for (i = 0; i < N_CONFIG_VARIANTS; i++) {
make_msc_config(&msc_local, i);
make_scl_config(&scl_ms, i);
make_ct_config(&ct_msc, i);
make_bts_config(&bts_local, i);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
}
free_msc_config(&msc_local);
}
/* Network supports all combinations, MS varies */
static void test_ms(void)
{
unsigned int i;
struct gsm0808_channel_type ct_msc;
struct gsm0808_speech_codec_list scl_ms;
struct bsc_msc_data msc_local;
struct gsm_bts bts_local;
int rc;
printf("============== test_ms ==============\n\n");
init_msc_config(&msc_local);
make_msc_config(&msc_local, 8);
make_ct_config(&ct_msc, 8);
make_bts_config(&bts_local, 8);
for (i = 0; i < N_CONFIG_VARIANTS; i++) {
make_scl_config(&scl_ms, i);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
}
free_msc_config(&msc_local);
}
/* BSS and MS support all combinations, MSC varies */
static void test_ct(void)
{
unsigned int i;
struct gsm0808_channel_type ct_msc;
struct gsm0808_speech_codec_list scl_ms;
struct bsc_msc_data msc_local;
struct gsm_bts bts_local;
int rc;
printf("============== test_ct ==============\n\n");
init_msc_config(&msc_local);
make_msc_config(&msc_local, 8);
make_scl_config(&scl_ms, 8);
make_bts_config(&bts_local, 8);
for (i = 0; i < N_CONFIG_VARIANTS; i++) {
make_ct_config(&ct_msc, i);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
}
free_msc_config(&msc_local);
}
/* MSC and MS support all combinations, BSS varies */
static void test_msc(void)
{
unsigned int i;
struct gsm0808_channel_type ct_msc;
struct gsm0808_speech_codec_list scl_ms;
struct bsc_msc_data msc_local;
struct gsm_bts bts_local;
int rc;
printf("============== test_msc ==============\n\n");
init_msc_config(&msc_local);
make_ct_config(&ct_msc, 8);
make_scl_config(&scl_ms, 8);
make_bts_config(&bts_local, 8);
for (i = 0; i < N_CONFIG_VARIANTS; i++) {
make_msc_config(&msc_local, 8);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
}
free_msc_config(&msc_local);
}
/* Some mixed configurations that are supposed to work */
static void test_selected_working(void)
{
struct gsm0808_channel_type ct_msc;
struct gsm0808_speech_codec_list scl_ms;
struct bsc_msc_data msc_local;
struct gsm_bts bts_local;
int rc;
printf("============== test_selected_working ==============\n\n");
init_msc_config(&msc_local);
make_scl_config(&scl_ms, 6);
make_ct_config(&ct_msc, 5);
make_msc_config(&msc_local, 7);
make_bts_config(&bts_local, 8);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
make_scl_config(&scl_ms, 0);
make_ct_config(&ct_msc, 5);
make_msc_config(&msc_local, 7);
make_bts_config(&bts_local, 8);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
make_scl_config(&scl_ms, 1);
make_ct_config(&ct_msc, 5);
make_msc_config(&msc_local, 6);
make_bts_config(&bts_local, 8);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
make_scl_config(&scl_ms, 6);
make_ct_config(&ct_msc, 5);
make_msc_config(&msc_local, 7);
make_bts_config(&bts_local, 4);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
make_scl_config(&scl_ms, 0);
make_ct_config(&ct_msc, 5);
make_msc_config(&msc_local, 7);
make_bts_config(&bts_local, 2);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
make_scl_config(&scl_ms, 1);
make_ct_config(&ct_msc, 5);
make_msc_config(&msc_local, 6);
make_bts_config(&bts_local, 1);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == 0);
free_msc_config(&msc_local);
}
/* Some mixed configurations that can not work */
static void test_selected_non_working(void)
{
struct gsm0808_channel_type ct_msc;
struct gsm0808_speech_codec_list scl_ms;
struct bsc_msc_data msc_local;
struct gsm_bts bts_local;
int rc;
printf("============== test_selected_non_working ==============\n\n");
init_msc_config(&msc_local);
make_scl_config(&scl_ms, 1);
make_ct_config(&ct_msc, 5);
make_msc_config(&msc_local, 7);
make_bts_config(&bts_local, 8);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == -1);
make_scl_config(&scl_ms, 1);
make_ct_config(&ct_msc, 5);
make_msc_config(&msc_local, 7);
make_bts_config(&bts_local, 8);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == -1);
make_scl_config(&scl_ms, 1);
make_ct_config(&ct_msc, 4);
make_msc_config(&msc_local, 6);
make_bts_config(&bts_local, 8);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == -1);
make_scl_config(&scl_ms, 1);
make_ct_config(&ct_msc, 2);
make_msc_config(&msc_local, 7);
make_bts_config(&bts_local, 8);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == -1);
make_scl_config(&scl_ms, 1);
make_ct_config(&ct_msc, 5);
make_msc_config(&msc_local, 4);
make_bts_config(&bts_local, 8);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == -1);
make_scl_config(&scl_ms, 8);
make_ct_config(&ct_msc, 4);
make_msc_config(&msc_local, 6);
make_bts_config(&bts_local, 7);
rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
OSMO_ASSERT(rc == -1);
free_msc_config(&msc_local);
}
static const struct log_info_cat log_categories[] = {
[DMSC] = {
.name = "DMSC",
.description = "Mobile Switching Center",
.enabled = 1,.loglevel = LOGL_NOTICE,
},
};
static const struct log_info log_info = {
.cat = log_categories,
.num_cat = ARRAY_SIZE(log_categories),
};
int main(int argc, char **argv)
{
ctx = talloc_named_const(NULL, 0, "codec_pref_test");
msgb_talloc_ctx_init(ctx, 0);
osmo_init_logging2(ctx, &log_info);
test_one_to_one();
test_ms();
test_ct();
test_msc();
test_selected_working();
test_selected_non_working();
printf("Testing execution completed.\n");
talloc_free(ctx);
return 0;
}