From 8308233819cc09d2e34b3703cf16c84c099d6973 Mon Sep 17 00:00:00 2001 From: dhruvecosmob Date: Fri, 27 Aug 2021 13:44:49 +0300 Subject: [PATCH] [mod_sofia] Add a unit-test for the 3pcc telephone event. --- .../mod_sofia/test/conf-sipp/freeswitch.xml | 7 + .../mod_sofia/test/sipp-based-tests.c | 124 +++++++++++++- .../sipp-scenarios/uac_telephone_event.xml | 159 ++++++++++++++++++ 3 files changed, 281 insertions(+), 9 deletions(-) create mode 100644 src/mod/endpoints/mod_sofia/test/sipp-scenarios/uac_telephone_event.xml diff --git a/src/mod/endpoints/mod_sofia/test/conf-sipp/freeswitch.xml b/src/mod/endpoints/mod_sofia/test/conf-sipp/freeswitch.xml index f75764a5f0..d20625f77f 100644 --- a/src/mod/endpoints/mod_sofia/test/conf-sipp/freeswitch.xml +++ b/src/mod/endpoints/mod_sofia/test/conf-sipp/freeswitch.xml @@ -584,6 +584,13 @@ + + + + + + + diff --git a/src/mod/endpoints/mod_sofia/test/sipp-based-tests.c b/src/mod/endpoints/mod_sofia/test/sipp-based-tests.c index 5f24da0fa8..3f591754fe 100644 --- a/src/mod/endpoints/mod_sofia/test/sipp-based-tests.c +++ b/src/mod/endpoints/mod_sofia/test/sipp-based-tests.c @@ -37,6 +37,23 @@ int test_success = 0; int test_sofia_debug = 1; +static const char *test_wait_for_chan_var(switch_channel_t *channel, const char *seq) +{ + int loop_count = 50; + const char *var=NULL; + do { + if (!strcmp(switch_channel_get_variable(channel, "sip_cseq"),seq)){ + switch_sleep(100 * 1000); + var = switch_channel_get_variable(channel, "rtp_local_sdp_str"); + break; + } + + switch_sleep(100 * 1000); + } while(loop_count--); + + return var; +} + static switch_bool_t has_ipv6() { switch_stream_handle_t stream = { 0 }; @@ -73,9 +90,9 @@ static void unregister_gw() switch_safe_free(stream.data); } -static int start_sipp_uac(const char *ip, int remote_port,const char *scenario_uac, const char *extra) +static int start_sipp_uac(const char *ip, int remote_port, const char *dialed_number, const char *scenario_uac, const char *extra) { - char *cmd = switch_mprintf("sipp %s:%d -nr -p 5062 -m 1 -s 1001 -recv_timeout 10000 -timeout 10s -sf %s -bg %s", ip, remote_port, scenario_uac, extra); + char *cmd = switch_mprintf("sipp %s:%d -nr -p 5062 -m 1 -s %s -recv_timeout 10000 -timeout 10s -sf %s -bg %s", ip, remote_port, dialed_number, scenario_uac, extra); int sys_ret = switch_system(cmd, SWITCH_TRUE); printf("%s\n", cmd); @@ -199,9 +216,98 @@ FST_CORE_EX_BEGIN("./conf-sipp", SCF_VG | SCF_USE_SQL) } FST_TEARDOWN_END() + FST_TEST_BEGIN(uac_telephone_event_check) + { + const char *local_ip_v4 = switch_core_get_variable("local_ip_v4"); + char *channel_data = NULL; + char uuid[100] = ""; + int sipp_ret; + int sdp_count = 0 , loop_count =50; + switch_stream_handle_t stream = { 0 }; + + sipp_ret = start_sipp_uac(local_ip_v4, 5080, "1212121212", "sipp-scenarios/uac_telephone_event.xml", ""); + if (sipp_ret < 0 || sipp_ret == 127) { + fst_requires(0); /* sipp not found */ + } + + do { + SWITCH_STANDARD_STREAM(stream); + switch_api_execute("show", "channels", NULL, &stream); + if (!strncmp((char *)stream.data, "uuid,", 5)) { + channel_data = switch_mprintf("%s", (char *)stream.data); + switch_safe_free(stream.data); + break; + } + + switch_safe_free(stream.data); + switch_sleep(100 * 1000); + } while (loop_count--); + + if (channel_data) { + char *temp = NULL; + int i; + + if ((temp = strchr(channel_data, '\n'))) { + temp++; + for (i = 0; temp[i] != ',' && i < 99; i++){ + uuid[i] = temp[i]; + } + uuid[i] = '\0'; + } + + if (!zstr(uuid)) { + switch_core_session_t *session = switch_core_session_locate(uuid); + switch_channel_t *channel; + const char *sdp_str1 = NULL, *sdp_str2 = NULL; + + fst_requires(session); + channel = switch_core_session_get_channel(session); + + sdp_str1 = test_wait_for_chan_var(channel,"1"); + sdp_str2 = test_wait_for_chan_var(channel,"2"); + + if (sdp_str1 && sdp_str2 && (strstr(sdp_str1,"telephone-event")) && (strstr(sdp_str2,"telephone-event"))){ + temp = NULL; + sdp_count = 1; + + if ((temp = strstr(sdp_str2,"RTP/AVP"))) { + int count = 0; + + for (i = 7; temp[i] != '\n' && i < 99; i++) { + /* checking for payload-type 101.*/ + if(temp[i++] == '1' && temp[i++] == '0' && temp[i++] == '1') { + count++; + } + } + + if (count > 1) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Duplicate entry of payload in SDP.\n"); + sdp_count = 0; + } + } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Telephone-event missing in SDP.\n"); + } + + switch_core_session_rwunlock(session); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Uuid not found in Channel Data.\n"); + } + + free(channel_data); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to find Channel Data.\n"); + } + + fst_check(sdp_count == 1); + /* sipp should timeout, attempt kill, just in case.*/ + kill_sipp(); + } + FST_TEST_END() + FST_TEST_BEGIN(uac_digest_leak_udp) { - switch_core_session_t *session; + switch_core_session_t *session; switch_call_cause_t cause; switch_status_t status; switch_channel_t *channel; @@ -211,7 +317,7 @@ FST_CORE_EX_BEGIN("./conf-sipp", SCF_VG | SCF_USE_SQL) switch_event_bind("sofia", SWITCH_EVENT_CUSTOM, NULL, event_handler, NULL); status = switch_ivr_originate(NULL, &session, &cause, "loopback/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); - sipp_ret = start_sipp_uac(local_ip_v4, 5080, "sipp-scenarios/uac_digest_leak.xml", ""); + sipp_ret = start_sipp_uac(local_ip_v4, 5080, "1001", "sipp-scenarios/uac_digest_leak.xml", ""); if (sipp_ret < 0 || sipp_ret == 127) { fst_requires(0); /* sipp not found */ } @@ -250,7 +356,7 @@ FST_CORE_EX_BEGIN("./conf-sipp", SCF_VG | SCF_USE_SQL) FST_TEST_BEGIN(uac_digest_leak_tcp) { - switch_core_session_t *session; + switch_core_session_t *session; switch_call_cause_t cause; switch_status_t status; switch_channel_t *channel; @@ -260,7 +366,7 @@ FST_CORE_EX_BEGIN("./conf-sipp", SCF_VG | SCF_USE_SQL) switch_event_bind("sofia", SWITCH_EVENT_CUSTOM, NULL, event_handler, NULL); status = switch_ivr_originate(NULL, &session, &cause, "loopback/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); - sipp_ret = start_sipp_uac(local_ip_v4, 5080, "sipp-scenarios/uac_digest_leak-tcp.xml", "-t t1"); + sipp_ret = start_sipp_uac(local_ip_v4, 5080, "1001", "sipp-scenarios/uac_digest_leak-tcp.xml", "-t t1"); if (sipp_ret < 0 || sipp_ret == 127) { fst_requires(0); /* sipp not found */ } @@ -299,7 +405,7 @@ FST_CORE_EX_BEGIN("./conf-sipp", SCF_VG | SCF_USE_SQL) FST_TEST_BEGIN(uac_digest_leak_udp_ipv6) { - switch_core_session_t *session; + switch_core_session_t *session; switch_call_cause_t cause; switch_status_t status; switch_channel_t *channel; @@ -318,9 +424,9 @@ FST_CORE_EX_BEGIN("./conf-sipp", SCF_VG | SCF_USE_SQL) status = switch_ivr_originate(NULL, &session, &cause, "loopback/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); if (!ipv6) { - sipp_ret = start_sipp_uac(local_ip_v6, 6060, "sipp-scenarios/uac_digest_leak-ipv6.xml", "-i [::1]"); + sipp_ret = start_sipp_uac(local_ip_v6, 6060, "1001", "sipp-scenarios/uac_digest_leak-ipv6.xml", "-i [::1]"); } else { - sipp_ret = start_sipp_uac(ipv6, 6060, "sipp-scenarios/uac_digest_leak-ipv6.xml", "-i [::1] -mi [::1]"); + sipp_ret = start_sipp_uac(ipv6, 6060, "1001", "sipp-scenarios/uac_digest_leak-ipv6.xml", "-i [::1] -mi [::1]"); } if (sipp_ret < 0 || sipp_ret == 127) { diff --git a/src/mod/endpoints/mod_sofia/test/sipp-scenarios/uac_telephone_event.xml b/src/mod/endpoints/mod_sofia/test/sipp-scenarios/uac_telephone_event.xml new file mode 100644 index 0000000000..c3e905de93 --- /dev/null +++ b/src/mod/endpoints/mod_sofia/test/sipp-scenarios/uac_telephone_event.xml @@ -0,0 +1,159 @@ + + + + + + ;tag=[call_number] + To: sut + Call-ID: [call_id] + CSeq: 1 INVITE + Contact: sip:t_sipp@[local_ip]:[local_port] + Max-Forwards: 70 + Subject: Performance Test + Content-Type: application/sdp + Content-Length: [len] + + v=0 + o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip] + s=- + c=IN IP[local_ip_type] [local_ip] + t=0 0 + m=audio [auto_media_port] RTP/AVP 8 0 18 101 + a=rtpmap:8 PCMA/8000 + a=rtpmap:0 PCMU/8000 + a=rtpmap:18 G729/8000 + a=fmtp:18 annexb=no + a=rtpmap:101 telephone-event/8000 + a=fmtp:101 0-11,16 + a=sendrecv + a=ptime:20 + ]]> + + + + + + + + + + + + + + + + + + ;tag=[call_number] + To: sut [peer_tag_param] + Call-ID: [call_id] + CSeq: 1 ACK + Contact: sip:t_sipp@[local_ip]:[local_port] + Max-Forwards: 70 + Subject: Performance Test + Content-Length: 0 + + ]]> + + + + + + ;tag=[call_number] + To: sut + Call-ID: [call_id] + CSeq: 2 INVITE + Contact: sip:t_sipp@[local_ip]:[local_port] + Max-Forwards: 70 + Subject: Performance Test + Content-Length: [len] + + ]]> + + + + + + + + + + + ;tag=[call_number] + To: sut [peer_tag_param] + Call-ID: [call_id] + CSeq: 2 ACK + Contact: sip:t_sipp@[local_ip]:[local_port] + Max-Forwards: 70 + Subject: Performance Test + Content-Type: application/sdp + Content-Length: [len] + + v=0 + o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip] + s= + c=IN IP[local_ip_type] [local_ip] + t=0 0 + m=audio [auto_media_port] RTP/AVP 8 0 101 + a=rtpmap:8 PCMA/8000 + a=rtpmap:0 PCMU/8000 + a=rtpmap:101 telephone-event/8000 + a=fmtp:101 0-15 + a=sendrecv + a=ptime:20 + + ]]> + + + + ;tag=[call_number] + To: sut [peer_tag_param] + Call-ID: [call_id] + CSeq: 3 BYE + Contact: sip:t_sipp@[local_ip]:[local_port] + Max-Forwards: 70 + Subject: Performance Test + Content-Length: 0 + + ]]> + + + + + + + + + + + + + +