diff options
author | Benny Prijono <bennylp@teluu.com> | 2006-01-10 13:31:40 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2006-01-10 13:31:40 +0000 |
commit | 4dc1b31807de4da871158d4af5d0a8e752e47111 (patch) | |
tree | c0f4461767fe1d55cb542d3e89fc243c2255abd5 /pjsip/src/test-pjsip/tsx_uas_test.c | |
parent | 8757a26cbbabd54c5662bf9b492214fe937dc93a (diff) |
Renamed pjsip_url to pjsip_sip_uri
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@119 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/test-pjsip/tsx_uas_test.c')
-rw-r--r-- | pjsip/src/test-pjsip/tsx_uas_test.c | 725 |
1 files changed, 661 insertions, 64 deletions
diff --git a/pjsip/src/test-pjsip/tsx_uas_test.c b/pjsip/src/test-pjsip/tsx_uas_test.c index fc587825..bed6fd08 100644 --- a/pjsip/src/test-pjsip/tsx_uas_test.c +++ b/pjsip/src/test-pjsip/tsx_uas_test.c @@ -45,24 +45,31 @@ ** ** TEST4_BRANCH_ID ** Transaction retransmits last response (if any) without notifying - ** transaction user upon receiving request retransmissions on: - ** a. TRYING state. - ** a. PROCEEDING state. - ** b. COMPLETED state. + ** transaction user upon receiving request retransmissions on TRYING + ** state ** ** TEST5_BRANCH_ID - ** INVITE transaction MUST retransmit final response. (Note: PJSIP also - ** retransmit 2xx final response until it's terminated by user). + ** As above, in PROCEEDING state. ** ** TEST6_BRANCH_ID - ** INVITE transaction MUST cease retransmission of final response when - * ACK is received. (Note: PJSIP also retransmit 2xx final response - * until it's terminated by user). + ** As above, in COMPLETED state, with first sending provisional response. ** ** TEST7_BRANCH_ID - ** Test where INVITE UAS transaction never receives ACK + ** INVITE transaction MUST retransmit non-2xx final response. ** ** TEST8_BRANCH_ID + ** As above, for INVITE's 2xx final response (this is PJSIP specific). + ** + ** TEST9_BRANCH_ID + ** INVITE transaction MUST cease retransmission of final response when + ** ACK is received. (Note: PJSIP also retransmit 2xx final response + ** until it's terminated by user). + ** Transaction also MUST terminate in T4 seconds. + ** + ** TEST10_BRANCH_ID + ** Test where INVITE UAS transaction never receives ACK + ** + ** TEST11_BRANCH_ID ** When UAS failed to deliver the response with the selected transport, ** it should try contacting the client with other transport or begin ** RFC 3263 server resolution procedure. @@ -72,7 +79,7 @@ ** upon receiving request retransmission). ** c. COMPLETED state. ** - ** TEST9_BRANCH_ID + ** TEST12_BRANCH_ID ** Variant of previous test, where transaction fails to deliver the ** response using any kind of transports. Transaction should report ** transport error to its transaction user. @@ -86,12 +93,37 @@ static char *TEST4_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test4"; static char *TEST5_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test5"; static char *TEST6_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test6"; static char *TEST7_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test7"; +static char *TEST8_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test8"; +static char *TEST9_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test9"; +static char *TEST10_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test10"; +static char *TEST11_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test11"; +static char *TEST12_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-UAS-Test12"; #define TEST1_STATUS_CODE 200 #define TEST2_STATUS_CODE 301 #define TEST3_PROVISIONAL_CODE PJSIP_SC_QUEUED #define TEST3_STATUS_CODE 202 +#define TEST4_STATUS_CODE 200 +#define TEST4_REQUEST_COUNT 2 +#define TEST5_PROVISIONAL_CODE 100 +#define TEST5_STATUS_CODE 200 +#define TEST5_REQUEST_COUNT 2 +#define TEST5_RESPONSE_COUNT 2 +#define TEST6_PROVISIONAL_CODE 100 +#define TEST6_STATUS_CODE 200 /* Must be final */ +#define TEST6_REQUEST_COUNT 2 +#define TEST6_RESPONSE_COUNT 3 +#define TEST7_STATUS_CODE 301 +#define TEST8_STATUS_CODE 302 + + +#define TEST4_TITLE "test4: absorbing request retransmission" +#define TEST5_TITLE "test5: retransmit last response in PROCEEDING state" +#define TEST6_TITLE "test6: retransmit last response in COMPLETED state" + +#define TEST_TIMEOUT_ERROR -30 +#define MAX_ALLOWED_DIFF 150 static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e); static pj_bool_t on_rx_message(pjsip_rx_data *rdata); @@ -161,6 +193,7 @@ struct response pjsip_tx_data *tdata; }; +/* Timer callback to send response. */ static void send_response_timer( pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry) { @@ -183,6 +216,31 @@ static void send_response_timer( pj_timer_heap_t *timer_heap, } } +/* Utility to send response. */ +static void send_response( pjsip_rx_data *rdata, + pjsip_transaction *tsx, + int status_code ) +{ + pj_status_t status; + pjsip_tx_data *tdata; + + status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, + &tdata); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create response", status); + test_complete = -196; + return; + } + + status = pjsip_tsx_send_msg(tsx, tdata); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to send response", status); + pjsip_tx_data_dec_ref(tdata); + test_complete = -197; + return; + } +} + /* Schedule timer to send response for the specified UAS transaction */ static void schedule_send_response( pjsip_rx_data *rdata, const pj_str_t *tsx_key, @@ -222,6 +280,49 @@ static void schedule_send_response( pjsip_rx_data *rdata, } } + +/* Find and terminate tsx with the specified key. */ +static void terminate_our_tsx(int status_code) +{ + pjsip_transaction *tsx; + + tsx = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_TRUE); + if (!tsx) { + PJ_LOG(3,(THIS_FILE," error: timer unable to find transaction")); + return; + } + + pjsip_tsx_terminate(tsx, status_code); + pj_mutex_unlock(tsx->mutex); +} + +/* Timer callback to terminate transaction. */ +static void terminate_tsx_timer( pj_timer_heap_t *timer_heap, + struct pj_timer_entry *entry) +{ + terminate_our_tsx(entry->id); +} + + +/* Schedule timer to terminate transaction. */ +static void schedule_terminate_tsx( pjsip_transaction *tsx, + int status_code, + int msec_delay ) +{ + pj_time_val delay; + + delay.sec = 0; + delay.msec = msec_delay; + pj_time_val_normalize(&delay); + + pj_assert(pj_strcmp(&tsx->transaction_key, &tsx_key)==0); + timer.user_data = NULL; + timer.id = status_code; + timer.cb = &terminate_tsx_timer; + pjsip_endpt_schedule_timer(endpt, &timer, &delay); +} + + /* * This is the handler to receive state changed notification from the * transaction. It is used to verify that the transaction behaves according @@ -331,6 +432,148 @@ static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e) } + } else + if (pj_strcmp2(&tsx->branch, TEST4_BRANCH_ID)==0) { + /* + * TEST4_BRANCH_ID tests receiving retransmissions in TRYING state. + */ + if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { + + /* Check that status code is status_code. */ + if (tsx->status_code != TEST4_STATUS_CODE) { + PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); + test_complete = -120; + } + + /* Previous state. */ + if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { + PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); + test_complete = -121; + } + + } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) + { + PJ_LOG(3,(THIS_FILE, " error: unexpected state")); + test_complete = -122; + + } + + + } else + if (pj_strcmp2(&tsx->branch, TEST5_BRANCH_ID)==0) { + /* + * TEST5_BRANCH_ID tests receiving retransmissions in PROCEEDING state + */ + if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { + + /* Check that status code is status_code. */ + if (tsx->status_code != TEST5_STATUS_CODE) { + PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); + test_complete = -130; + } + + /* Previous state. */ + if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { + PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); + test_complete = -131; + } + + } else if (tsx->state == PJSIP_TSX_STATE_PROCEEDING) { + + /* Check status code. */ + if (tsx->status_code != TEST5_PROVISIONAL_CODE) { + PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); + test_complete = -132; + } + + } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { + PJ_LOG(3,(THIS_FILE, " error: unexpected state")); + test_complete = -133; + + } + + } else + if (pj_strcmp2(&tsx->branch, TEST6_BRANCH_ID)==0) { + /* + * TEST6_BRANCH_ID tests receiving retransmissions in COMPLETED state + */ + if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { + + /* Check that status code is status_code. */ + if (tsx->status_code != TEST6_STATUS_CODE) { + PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); + test_complete = -140; + } + + /* Previous state. */ + if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { + PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); + test_complete = -141; + } + + } else if (tsx->state != PJSIP_TSX_STATE_PROCEEDING && + tsx->state != PJSIP_TSX_STATE_COMPLETED && + tsx->state != PJSIP_TSX_STATE_DESTROYED) + { + PJ_LOG(3,(THIS_FILE, " error: unexpected state")); + test_complete = -142; + + } + + + } else + if (pj_strcmp2(&tsx->branch, TEST7_BRANCH_ID)==0 || + pj_strcmp2(&tsx->branch, TEST8_BRANCH_ID)==0) + { + /* + * TEST7_BRANCH_ID and TEST8_BRANCH_ID test retransmission of + * INVITE final response + */ + int code; + + if (pj_strcmp2(&tsx->branch, TEST7_BRANCH_ID) == 0) + code = TEST7_STATUS_CODE; + else + code = TEST8_STATUS_CODE; + + if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { + + if (test_complete == 0) + test_complete = 1; + + /* Check status code. */ + if (tsx->status_code != PJSIP_SC_TSX_TIMEOUT) { + PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); + test_complete = -150; + } + + /* Previous state. */ + if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { + PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); + test_complete = -151; + } + + } else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { + + /* Check that status code is status_code. */ + if (tsx->status_code != code) { + PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); + test_complete = -152; + } + + /* Previous state. */ + if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { + PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); + test_complete = -153; + } + + } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { + + PJ_LOG(3,(THIS_FILE, " error: unexpected state")); + test_complete = -154; + + } + } } @@ -344,6 +587,8 @@ static void save_key(pjsip_transaction *tsx) pj_strcpy(&tsx_key, &key); } +#define DIFF(a,b) ((a<b) ? (b-a) : (a-b)) + /* * Message receiver handler. */ @@ -371,7 +616,6 @@ static pj_bool_t on_rx_message(pjsip_rx_data *rdata) * response. */ pjsip_transaction *tsx; - pjsip_tx_data *tdata; status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); if (status != PJ_SUCCESS) { @@ -381,22 +625,7 @@ static pj_bool_t on_rx_message(pjsip_rx_data *rdata) } save_key(tsx); - - status = pjsip_endpt_create_response(endpt, rdata, - status_code, NULL, - &tdata); - if (status != PJ_SUCCESS) { - app_perror(" error: unable to create response", status); - test_complete = -111; - return PJ_TRUE; - } - - status = pjsip_tsx_send_msg(tsx, tdata); - if (status != PJ_SUCCESS) { - app_perror(" error: unable to send response", status); - test_complete = -112; - return PJ_TRUE; - } + send_response(rdata, tsx, status_code); } else { /* Verify the response received. */ @@ -427,7 +656,6 @@ static pj_bool_t on_rx_message(pjsip_rx_data *rdata) * response, then schedule timer to send final response. */ pjsip_transaction *tsx; - pjsip_tx_data *tdata; status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); if (status != PJ_SUCCESS) { @@ -438,22 +666,7 @@ static pj_bool_t on_rx_message(pjsip_rx_data *rdata) save_key(tsx); - status = pjsip_endpt_create_response(endpt, rdata, - TEST3_PROVISIONAL_CODE, NULL, - &tdata); - if (status != PJ_SUCCESS) { - app_perror(" error: unable to create response", status); - test_complete = -121; - return PJ_TRUE; - } - - status = pjsip_tsx_send_msg(tsx, tdata); - if (status != PJ_SUCCESS) { - app_perror(" error: unable to send response", status); - test_complete = -122; - return PJ_TRUE; - } - + send_response(rdata, tsx, TEST3_PROVISIONAL_CODE); schedule_send_response(rdata, &tsx->transaction_key, TEST3_STATUS_CODE, 2000); @@ -482,6 +695,255 @@ static pj_bool_t on_rx_message(pjsip_rx_data *rdata) } return PJ_TRUE; + } else if (pj_strcmp2(&branch_param, TEST4_BRANCH_ID) == 0 || + pj_strcmp2(&branch_param, TEST5_BRANCH_ID) == 0 || + pj_strcmp2(&branch_param, TEST6_BRANCH_ID) == 0) + { + + /* TEST4_BRANCH_ID: absorbs retransmissions in TRYING state. */ + /* TEST5_BRANCH_ID: retransmit last response in PROCEEDING state. */ + /* TEST6_BRANCH_ID: retransmit last response in COMPLETED state. */ + + if (msg->type == PJSIP_REQUEST_MSG) { + /* On received response, create UAS. */ + pjsip_transaction *tsx; + + status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create transaction", status); + test_complete = -130; + return PJ_TRUE; + } + + save_key(tsx); + + if (pj_strcmp2(&branch_param, TEST4_BRANCH_ID) == 0) { + + } else if (pj_strcmp2(&branch_param, TEST5_BRANCH_ID) == 0) { + send_response(rdata, tsx, TEST5_PROVISIONAL_CODE); + + } else if (pj_strcmp2(&branch_param, TEST6_BRANCH_ID) == 0) { + send_response(rdata, tsx, TEST6_PROVISIONAL_CODE); + send_response(rdata, tsx, TEST6_STATUS_CODE); + } + + } else { + /* Verify the response received. */ + + ++recv_count; + + if (pj_strcmp2(&branch_param, TEST4_BRANCH_ID) == 0) { + PJ_LOG(3,(THIS_FILE, " error: not expecting response!")); + test_complete = -132; + + } else if (pj_strcmp2(&branch_param, TEST5_BRANCH_ID) == 0) { + + if (rdata->msg_info.msg->line.status.code!=TEST5_PROVISIONAL_CODE) { + PJ_LOG(3,(THIS_FILE, " error: incorrect status code!")); + test_complete = -133; + + } + if (recv_count > TEST5_RESPONSE_COUNT) { + PJ_LOG(3,(THIS_FILE, " error: not expecting response!")); + test_complete = -134; + } + + } else if (pj_strcmp2(&branch_param, TEST6_BRANCH_ID) == 0) { + + int code = rdata->msg_info.msg->line.status.code; + + switch (recv_count) { + case 1: + if (code != TEST6_PROVISIONAL_CODE) { + PJ_LOG(3,(THIS_FILE, " error: invalid code!")); + test_complete = -135; + } + break; + case 2: + case 3: + if (code != TEST6_STATUS_CODE) { + PJ_LOG(3,(THIS_FILE, " error: invalid code!")); + test_complete = -136; + } + break; + default: + PJ_LOG(3,(THIS_FILE, " error: not expecting response")); + test_complete = -137; + break; + } + } + } + return PJ_TRUE; + + + } else if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0 || + pj_strcmp2(&branch_param, TEST8_BRANCH_ID) == 0) + { + + /* + * TEST7_BRANCH_ID and TEST8_BRANCH_ID test the retransmission + * of INVITE final response + */ + if (msg->type == PJSIP_REQUEST_MSG) { + + /* On received response, create UAS. */ + pjsip_transaction *tsx; + + status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create transaction", status); + test_complete = -140; + return PJ_TRUE; + } + + save_key(tsx); + + if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) { + + send_response(rdata, tsx, TEST7_STATUS_CODE); + + } else { + + send_response(rdata, tsx, TEST8_STATUS_CODE); + + } + + } else { + int code; + + ++recv_count; + + if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) + code = TEST7_STATUS_CODE; + else + code = TEST8_STATUS_CODE; + + if (recv_count==1) { + + if (rdata->msg_info.msg->line.status.code != code) { + PJ_LOG(3,(THIS_FILE," error: invalid status code")); + test_complete = -141; + } + + recv_last = rdata->pkt_info.timestamp; + + } else { + + pj_time_val now; + unsigned msec, msec_expected; + + now = rdata->pkt_info.timestamp; + + PJ_TIME_VAL_SUB(now, recv_last); + + msec = now.sec*1000 + now.msec; + msec_expected = (1 << (recv_count-2)) * PJSIP_T1_TIMEOUT; + if (msec_expected > PJSIP_T2_TIMEOUT) + msec_expected = PJSIP_T2_TIMEOUT; + + if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) { + PJ_LOG(3,(THIS_FILE, + " error: incorrect retransmission " + "time (%d ms expected, %d ms received", + msec_expected, msec)); + test_complete = -142; + } + + if (recv_count > 11) { + PJ_LOG(3,(THIS_FILE," error: too many responses (%d)", + recv_count)); + test_complete = -143; + } + + recv_last = rdata->pkt_info.timestamp; + } + + } + return PJ_TRUE; + + } else if (pj_strcmp2(&branch_param, TEST9_BRANCH_ID)) { + + /* + * TEST9_BRANCH_ID tests that the retransmission of INVITE final + * response should cease when ACK is received. Transaction also MUST + * terminate in T4 seconds. + */ + if (msg->type == PJSIP_REQUEST_MSG) { + + /* On received response, create UAS. */ + pjsip_transaction *tsx; + + status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create transaction", status); + test_complete = -140; + return PJ_TRUE; + } + + save_key(tsx); + + if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) { + + send_response(rdata, tsx, TEST7_STATUS_CODE); + + } else { + + send_response(rdata, tsx, TEST8_STATUS_CODE); + + } + + } else { + int code; + + ++recv_count; + + if (pj_strcmp2(&branch_param, TEST7_BRANCH_ID) == 0) + code = TEST7_STATUS_CODE; + else + code = TEST8_STATUS_CODE; + + if (recv_count==1) { + + if (rdata->msg_info.msg->line.status.code != code) { + PJ_LOG(3,(THIS_FILE," error: invalid status code")); + test_complete = -141; + } + + recv_last = rdata->pkt_info.timestamp; + + } else { + + pj_time_val now; + unsigned msec, msec_expected; + + now = rdata->pkt_info.timestamp; + + PJ_TIME_VAL_SUB(now, recv_last); + + msec = now.sec*1000 + now.msec; + msec_expected = (1 << (recv_count-2)) * PJSIP_T1_TIMEOUT; + if (msec_expected > PJSIP_T2_TIMEOUT) + msec_expected = PJSIP_T2_TIMEOUT; + + if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) { + PJ_LOG(3,(THIS_FILE, + " error: incorrect retransmission " + "time (%d ms expected, %d ms received", + msec_expected, msec)); + test_complete = -142; + } + + if (recv_count > 11) { + PJ_LOG(3,(THIS_FILE," error: too many responses (%d)", + recv_count)); + test_complete = -143; + } + + recv_last = rdata->pkt_info.timestamp; + } + + } + return PJ_TRUE; } return PJ_FALSE; @@ -492,12 +954,15 @@ static pj_bool_t on_rx_message(pjsip_rx_data *rdata) */ static int perform_test( char *target_uri, char *from_uri, char *branch_param, int test_time, - const pjsip_method *method ) + const pjsip_method *method, + int request_cnt, int request_interval_msec, + int expecting_timeout) { pjsip_tx_data *tdata; pj_str_t target, from; pjsip_via_hdr *via; - pj_time_val timeout; + pj_time_val timeout, next_send; + int sent_cnt; pj_status_t status; PJ_LOG(3,(THIS_FILE, @@ -526,17 +991,10 @@ static int perform_test( char *target_uri, char *from_uri, via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); via->branch_param = pj_str(branch_param); - /* Add additional reference to tdata to prevent transaction from - * deleting it. - */ - pjsip_tx_data_add_ref(tdata); - - /* Send the first message. */ - status = pjsip_endpt_send_request_stateless(endpt, tdata, NULL, NULL); - if (status != PJ_SUCCESS) { - app_perror(" Error: unable to send request", status); - return -20; - } + /* Schedule first send. */ + sent_cnt = 0; + pj_gettimeofday(&next_send); + pj_time_val_normalize(&next_send); /* Set test completion time. */ pj_gettimeofday(&timeout); @@ -549,10 +1007,35 @@ static int perform_test( char *target_uri, char *from_uri, pjsip_endpt_handle_events(endpt, &poll_delay); pj_gettimeofday(&now); + + if (sent_cnt < request_cnt && PJ_TIME_VAL_GTE(now, next_send)) { + /* Add additional reference to tdata to prevent transaction from + * deleting it. + */ + pjsip_tx_data_add_ref(tdata); + + /* (Re)Send the request. */ + status = pjsip_endpt_send_request_stateless(endpt, tdata, 0, 0); + if (status != PJ_SUCCESS) { + app_perror(" Error: unable to send request", status); + pjsip_tx_data_dec_ref(tdata); + return -20; + } + + /* Schedule next send, if any. */ + sent_cnt++; + if (sent_cnt < request_cnt) { + pj_gettimeofday(&next_send); + next_send.msec += request_interval_msec; + pj_time_val_normalize(&next_send); + } + } + if (now.sec > timeout.sec) { - PJ_LOG(3,(THIS_FILE, " Error: test has timed out")); + if (!expecting_timeout) + PJ_LOG(3,(THIS_FILE, " Error: test has timed out")); pjsip_tx_data_dec_ref(tdata); - return -30; + return TEST_TIMEOUT_ERROR; } } @@ -612,7 +1095,7 @@ static int tsx_basic_final_response_test(void) "sip:129.0.0.1;transport=loop-dgram", TEST1_BRANCH_ID, 33, /* Test duration must be greater than 32 secs */ - &pjsip_options_method); + &pjsip_options_method, 1, 0, 0); if (status != 0) return status; @@ -622,7 +1105,7 @@ static int tsx_basic_final_response_test(void) "sip:129.0.0.1;transport=loop-dgram", TEST2_BRANCH_ID, 33, /* Test duration must be greater than 32 secs */ - &pjsip_options_method); + &pjsip_options_method, 1, 0, 0); if (status != 0) return status; @@ -646,13 +1129,92 @@ static int tsx_basic_provisional_response_test(void) "sip:129.0.0.1;transport=loop-dgram", TEST3_BRANCH_ID, 35, - &pjsip_options_method); + &pjsip_options_method, 1, 0, 0); + return status; } /***************************************************************************** ** + ** TEST4_BRANCH_ID: Absorbs retransmissions in TRYING state + ** TEST5_BRANCH_ID: Absorbs retransmissions in PROCEEDING state + ** TEST6_BRANCH_ID: Absorbs retransmissions in COMPLETED state + ** + ***************************************************************************** + */ +static int tsx_retransmit_last_response_test(const char *title, + char *branch_id, + int request_cnt, + int status_code) +{ + int status; + + PJ_LOG(3,(THIS_FILE," %s", title)); + + status = perform_test("sip:129.0.0.1;transport=loop-dgram", + "sip:129.0.0.1;transport=loop-dgram", + branch_id, + 5, + &pjsip_options_method, + request_cnt, 1000, 1); + if (status && status != TEST_TIMEOUT_ERROR) + return status; + if (!status) { + PJ_LOG(3,(THIS_FILE, " error: expecting timeout")); + return -31; + } + + terminate_our_tsx(status_code); + flush_events(100); + + if (test_complete != 1) + return test_complete; + + flush_events(100); + return 0; +} + +/***************************************************************************** + ** + ** TEST7_BRANCH_ID: INVITE non-2xx final response retransmission test + ** TEST8_BRANCH_ID: INVITE 2xx final response retransmission test + ** + ***************************************************************************** + */ +static int tsx_final_response_retransmission_test(void) +{ + int status; + + PJ_LOG(3,(THIS_FILE, + " test7: INVITE non-2xx final response retransmission")); + + status = perform_test("sip:129.0.0.1;transport=loop-dgram", + "sip:129.0.0.1;transport=loop-dgram", + TEST7_BRANCH_ID, + 33, /* Test duration must be greater than 32 secs */ + &pjsip_invite_method, 1, 0, 0); + if (status != 0) + return status; + + PJ_LOG(3,(THIS_FILE, + " test8: INVITE 2xx final response retransmission")); + + status = perform_test("sip:129.0.0.1;transport=loop-dgram", + "sip:129.0.0.1;transport=loop-dgram", + TEST8_BRANCH_ID, + 33, /* Test duration must be greater than 32 secs */ + &pjsip_invite_method, 1, 0, 0); + if (status != 0) + return status; + + return 0; +} + + + +/***************************************************************************** + ** ** UAS Transaction Test. ** ***************************************************************************** @@ -689,7 +1251,6 @@ int tsx_uas_test(void) status = tsx_basic_final_response_test(); if (status != 0) return status; -#endif /* TEST3_BRANCH_ID: with provisional response */ @@ -697,6 +1258,42 @@ int tsx_uas_test(void) if (status != 0) return status; + /* TEST4_BRANCH_ID: absorbs retransmissions in TRYING state + */ + status = tsx_retransmit_last_response_test(TEST4_TITLE, + TEST4_BRANCH_ID, + TEST4_REQUEST_COUNT, + TEST4_STATUS_CODE); + if (status != 0) + return status; + + /* TEST5_BRANCH_ID: retransmit last response in PROCEEDING state + */ + status = tsx_retransmit_last_response_test(TEST5_TITLE, + TEST5_BRANCH_ID, + TEST5_REQUEST_COUNT, + TEST5_STATUS_CODE); + if (status != 0) + return status; + + /* TEST6_BRANCH_ID: retransmit last response in PROCEEDING state + */ + status = tsx_retransmit_last_response_test(TEST6_TITLE, + TEST6_BRANCH_ID, + TEST6_REQUEST_COUNT, + TEST6_STATUS_CODE); + if (status != 0) + return status; + + /* TEST7_BRANCH_ID: INVITE non-2xx final response retransmission test + * TEST8_BRANCH_ID: INVITE 2xx final response retransmission test + */ + + status = tsx_final_response_retransmission_test(); + if (status != 0) + return status; + +#endif pjsip_transport_dec_ref(loop); return 0; |