Changeset 4728 for pjproject/trunk/pjsip/src/test/tsx_uas_test.c
- Timestamp:
- Feb 4, 2014 10:13:56 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/test/tsx_uas_test.c
r4420 r4728 1 1 /* $Id$ */ 2 /* 2 /* 3 3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 4 4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> … … 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 */ 20 20 … … 31 31 ** 32 32 ** This file performs various tests for UAC transactions. Each test will have 33 ** a different Via branch param so that message receiver module and 33 ** a different Via branch param so that message receiver module and 34 34 ** transaction user module can identify which test is being carried out. 35 35 ** … … 48 48 ** 49 49 ** TEST4_BRANCH_ID 50 ** Transaction retransmits last response (if any) without notifying 50 ** Transaction retransmits last response (if any) without notifying 51 51 ** transaction user upon receiving request retransmissions on TRYING 52 52 ** state … … 67 67 ** TEST9_BRANCH_ID 68 68 ** INVITE transaction MUST cease retransmission of final response when 69 ** ACK is received. (Note: PJSIP also retransmit 2xx final response 69 ** ACK is received. (Note: PJSIP also retransmit 2xx final response 70 70 ** until it's terminated by user). 71 71 ** Transaction also MUST terminate in T4 seconds. … … 117 117 #define TEST4_REQUEST_COUNT 2 118 118 #define TEST5_PROVISIONAL_CODE 100 119 #define TEST5_STATUS_CODE 200 119 #define TEST5_STATUS_CODE 200 120 120 #define TEST5_REQUEST_COUNT 2 121 121 #define TEST5_RESPONSE_COUNT 2 … … 147 147 148 148 /* UAC transaction user module. */ 149 static pjsip_module tsx_user = 149 static pjsip_module tsx_user = 150 150 { 151 151 NULL, NULL, /* prev and next */ … … 165 165 166 166 /* Module to send request. */ 167 static pjsip_module msg_sender = 167 static pjsip_module msg_sender = 168 168 { 169 169 NULL, NULL, /* prev and next */ … … 242 242 pjsip_tx_data *tdata; 243 243 244 status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, 244 status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, 245 245 &tdata); 246 246 if (status != PJ_SUCCESS) { … … 272 272 pj_time_val delay; 273 273 274 status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, 274 status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, 275 275 &tdata); 276 276 if (status != PJ_SUCCESS) { … … 354 354 { 355 355 if (pj_stricmp2(&tsx->branch, TEST1_BRANCH_ID)==0 || 356 pj_stricmp2(&tsx->branch, TEST2_BRANCH_ID)==0) 356 pj_stricmp2(&tsx->branch, TEST2_BRANCH_ID)==0) 357 357 { 358 358 /* … … 375 375 test_complete = -100; 376 376 } 377 377 378 378 /* Previous state must be completed. */ 379 379 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { … … 406 406 test_complete = -110; 407 407 } 408 408 409 409 /* Previous state must be completed. */ 410 410 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { … … 466 466 /* Check that status code is status_code. */ 467 467 if (tsx->status_code != TEST4_STATUS_CODE) { 468 PJ_LOG(3,(THIS_FILE, 468 PJ_LOG(3,(THIS_FILE, 469 469 " error: incorrect status code %d " 470 470 "(expecting %d)", tsx->status_code, … … 472 472 test_complete = -120; 473 473 } 474 474 475 475 /* Previous state. */ 476 476 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { … … 479 479 } 480 480 481 } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) 481 } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) 482 482 { 483 483 PJ_LOG(3,(THIS_FILE, " error: unexpected state %s (122)", … … 503 503 test_complete = -130; 504 504 } 505 505 506 506 /* Previous state. */ 507 507 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { … … 538 538 if (tsx->status_code != TEST6_STATUS_CODE) { 539 539 PJ_LOG(3,(THIS_FILE, " error: incorrect status code %d " 540 "(expecting %d)", tsx->status_code, 540 "(expecting %d)", tsx->status_code, 541 541 TEST6_STATUS_CODE)); 542 542 test_complete = -140; 543 543 } 544 544 545 545 /* Previous state. */ 546 546 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { … … 551 551 } else if (tsx->state != PJSIP_TSX_STATE_PROCEEDING && 552 552 tsx->state != PJSIP_TSX_STATE_COMPLETED && 553 tsx->state != PJSIP_TSX_STATE_DESTROYED) 553 tsx->state != PJSIP_TSX_STATE_DESTROYED) 554 554 { 555 555 PJ_LOG(3,(THIS_FILE, " error: unexpected state %s (142)", … … 562 562 } else 563 563 if (pj_stricmp2(&tsx->branch, TEST7_BRANCH_ID)==0 || 564 pj_stricmp2(&tsx->branch, TEST8_BRANCH_ID)==0) 564 pj_stricmp2(&tsx->branch, TEST8_BRANCH_ID)==0) 565 565 { 566 566 /* … … 588 588 test_complete = -150; 589 589 } 590 590 591 591 /* Previous state. */ 592 592 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { … … 606 606 607 607 if (tsx->retransmit_count != 10) { 608 PJ_LOG(3,(THIS_FILE, 608 PJ_LOG(3,(THIS_FILE, 609 609 " error: incorrect retransmit count %d " 610 610 "(expecting 10)", … … 622 622 test_complete = -152; 623 623 } 624 624 625 625 /* Previous state. */ 626 626 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { … … 657 657 test_complete = -160; 658 658 } 659 659 660 660 /* Previous state. */ 661 661 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_CONFIRMED) { … … 671 671 test_complete = -162; 672 672 } 673 673 674 674 /* Previous state. */ 675 675 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { … … 686 686 test_complete = -164; 687 687 } 688 688 689 689 /* Previous state. */ 690 690 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { … … 704 704 if (pj_stricmp2(&tsx->branch, TEST10_BRANCH_ID)==0 || 705 705 pj_stricmp2(&tsx->branch, TEST11_BRANCH_ID)==0 || 706 pj_stricmp2(&tsx->branch, TEST12_BRANCH_ID)==0) 706 pj_stricmp2(&tsx->branch, TEST12_BRANCH_ID)==0) 707 707 { 708 708 if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 709 709 710 710 if (!test_complete) 711 711 test_complete = 1; … … 741 741 742 742 if (pj_stricmp2(&branch_param, TEST1_BRANCH_ID) == 0 || 743 pj_stricmp2(&branch_param, TEST2_BRANCH_ID) == 0) 743 pj_stricmp2(&branch_param, TEST2_BRANCH_ID) == 0) 744 744 { 745 745 /* 746 * TEST1_BRANCH_ID tests that non-INVITE transaction transmits 2xx 747 * final response using correct transport and terminates transaction 746 * TEST1_BRANCH_ID tests that non-INVITE transaction transmits 2xx 747 * final response using correct transport and terminates transaction 748 748 * after 32 seconds. 749 749 * … … 754 754 755 755 if (msg->type == PJSIP_REQUEST_MSG) { 756 /* On received request, create UAS and respond with final 757 * response. 756 /* On received request, create UAS and respond with final 757 * response. 758 758 */ 759 759 pjsip_transaction *tsx; … … 811 811 812 812 send_response(rdata, tsx, TEST3_PROVISIONAL_CODE); 813 schedule_send_response(rdata, &tsx->transaction_key, 813 schedule_send_response(rdata, &tsx->transaction_key, 814 814 TEST3_STATUS_CODE, 2000); 815 815 … … 841 841 } else if (pj_stricmp2(&branch_param, TEST4_BRANCH_ID) == 0 || 842 842 pj_stricmp2(&branch_param, TEST5_BRANCH_ID) == 0 || 843 pj_stricmp2(&branch_param, TEST6_BRANCH_ID) == 0) 843 pj_stricmp2(&branch_param, TEST6_BRANCH_ID) == 0) 844 844 { 845 845 … … 878 878 } else { 879 879 /* Verify the response received. */ 880 880 881 881 PJ_LOG(4,(THIS_FILE, " received response number %d", recv_count)); 882 882 … … 893 893 test_complete = -133; 894 894 895 } 895 } 896 896 if (recv_count > TEST5_RESPONSE_COUNT) { 897 897 PJ_LOG(3,(THIS_FILE, " error: not expecting response!")); … … 929 929 930 930 } else if (pj_stricmp2(&branch_param, TEST7_BRANCH_ID) == 0 || 931 pj_stricmp2(&branch_param, TEST8_BRANCH_ID) == 0) 931 pj_stricmp2(&branch_param, TEST8_BRANCH_ID) == 0) 932 932 { 933 933 … … 972 972 973 973 if (recv_count==1) { 974 974 975 975 if (rdata->msg_info.msg->line.status.code != code) { 976 976 PJ_LOG(3,(THIS_FILE," error: invalid status code")); … … 988 988 989 989 PJ_TIME_VAL_SUB(now, recv_last); 990 990 991 991 msec = now.sec*1000 + now.msec; 992 992 msec_expected = (1 << (recv_count-2)) * pjsip_cfg()->tsx.t1; … … 1017 1017 1018 1018 /* 1019 * TEST9_BRANCH_ID tests that the retransmission of INVITE final 1019 * TEST9_BRANCH_ID tests that the retransmission of INVITE final 1020 1020 * response should cease when ACK is received. Transaction also MUST 1021 1021 * terminate in T4 seconds. … … 1060 1060 1061 1061 PJ_TIME_VAL_SUB(now, recv_last); 1062 1062 1063 1063 msec = now.sec*1000 + now.msec; 1064 1064 msec_expected = (1 << (recv_count-2)) * pjsip_cfg()->tsx.t1; … … 1082 1082 1083 1083 status = pjsip_endpt_create_request_from_hdr( 1084 endpt, &pjsip_ack_method, 1084 endpt, &pjsip_ack_method, 1085 1085 rdata->msg_info.to->uri, 1086 1086 rdata->msg_info.from, 1087 1087 rdata->msg_info.to, 1088 NULL, 1088 NULL, 1089 1089 rdata->msg_info.cid, 1090 1090 rdata->msg_info.cseq->cseq, … … 1121 1121 } else if (pj_stricmp2(&branch_param, TEST10_BRANCH_ID) == 0 || 1122 1122 pj_stricmp2(&branch_param, TEST11_BRANCH_ID) == 0 || 1123 pj_stricmp2(&branch_param, TEST12_BRANCH_ID) == 0) 1123 pj_stricmp2(&branch_param, TEST12_BRANCH_ID) == 0) 1124 1124 { 1125 1125 int test_num, code1, code2; … … 1132 1132 test_num=12, code1 = 200, code2 = 0; 1133 1133 1134 PJ_UNUSED_ARG(test_num); 1135 1134 1136 if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG) { 1135 1137 … … 1146 1148 pjsip_tsx_recv_msg(tsx, rdata); 1147 1149 save_key(tsx); 1148 1150 1149 1151 schedule_send_response(rdata, &tsx_key, code1, 1000); 1150 1152 … … 1162 1164 } 1163 1165 1164 /* 1165 * The generic test framework, used by most of the tests. 1166 /* 1167 * The generic test framework, used by most of the tests. 1166 1168 */ 1167 static int perform_test( char *target_uri, char *from_uri, 1168 char *branch_param, int test_time, 1169 static int perform_test( char *target_uri, char *from_uri, 1170 char *branch_param, int test_time, 1169 1171 const pjsip_method *method, 1170 1172 int request_cnt, int request_interval_msec, … … 1178 1180 pj_status_t status; 1179 1181 1180 PJ_LOG(3,(THIS_FILE, 1182 PJ_LOG(3,(THIS_FILE, 1181 1183 " please standby, this will take at most %d seconds..", 1182 1184 test_time)); … … 1193 1195 /* Create request. */ 1194 1196 status = pjsip_endpt_create_request( endpt, method, &target, 1195 &from, &target, NULL, NULL, -1, 1197 &from, &target, NULL, NULL, -1, 1196 1198 NULL, &tdata); 1197 1199 if (status != PJ_SUCCESS) { … … 1369 1371 1370 1372 status = perform_test(TARGET_URI, FROM_URI, branch_id, 5, 1371 &pjsip_options_method, 1373 &pjsip_options_method, 1372 1374 request_cnt, 1000, 1); 1373 1375 if (status && status != TEST_TIMEOUT_ERROR) … … 1423 1425 /***************************************************************************** 1424 1426 ** 1425 ** TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must 1427 ** TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must 1426 1428 ** cease when ACK is received 1427 1429 ** … … 1464 1466 char *branch_id; 1465 1467 char *title; 1466 } tests[] = 1468 } tests[] = 1467 1469 { 1468 1470 { 0, 10, TEST10_BRANCH_ID, "test10: failed transport in TRYING state (no delay)" }, … … 1538 1540 tp_flag = pjsip_transport_get_flag_from_type((pjsip_transport_type_e)param->type); 1539 1541 1540 pj_ansi_sprintf(TARGET_URI, "sip:bob@127.0.0.1:%d;transport=%s", 1542 pj_ansi_sprintf(TARGET_URI, "sip:bob@127.0.0.1:%d;transport=%s", 1541 1543 param->port, param->tp_type); 1542 pj_ansi_sprintf(FROM_URI, "sip:alice@127.0.0.1:%d;transport=%s", 1544 pj_ansi_sprintf(FROM_URI, "sip:alice@127.0.0.1:%d;transport=%s", 1543 1545 param->port, param->tp_type); 1544 1546 1545 1547 /* Check if loop transport is configured. */ 1546 status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_LOOP_DGRAM, 1548 status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_LOOP_DGRAM, 1547 1549 &addr, sizeof(addr), NULL, &loop); 1548 1550 if (status != PJ_SUCCESS) { … … 1562 1564 } 1563 1565 1564 /* TEST1_BRANCH_ID: Basic 2xx final response. 1565 * TEST2_BRANCH_ID: Basic non-2xx final response. 1566 /* TEST1_BRANCH_ID: Basic 2xx final response. 1567 * TEST2_BRANCH_ID: Basic non-2xx final response. 1566 1568 */ 1567 1569 status = tsx_basic_final_response_test(); … … 1578 1580 */ 1579 1581 status = tsx_retransmit_last_response_test(TEST4_TITLE, 1580 TEST4_BRANCH_ID, 1582 TEST4_BRANCH_ID, 1581 1583 TEST4_REQUEST_COUNT, 1582 1584 TEST4_STATUS_CODE); … … 1587 1589 */ 1588 1590 status = tsx_retransmit_last_response_test(TEST5_TITLE, 1589 TEST5_BRANCH_ID, 1591 TEST5_BRANCH_ID, 1590 1592 TEST5_REQUEST_COUNT, 1591 1593 TEST5_STATUS_CODE); … … 1600 1602 if ((tp_flag & PJSIP_TRANSPORT_RELIABLE) == 0) { 1601 1603 status = tsx_retransmit_last_response_test(TEST6_TITLE, 1602 TEST6_BRANCH_ID, 1604 TEST6_BRANCH_ID, 1603 1605 TEST6_REQUEST_COUNT, 1604 1606 TEST6_STATUS_CODE); … … 1614 1616 return status; 1615 1617 1616 /* TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must 1618 /* TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must 1617 1619 * cease when ACK is received 1618 1620 * Only applicable for non-reliable transports.
Note: See TracChangeset
for help on using the changeset viewer.