Ignore:
Timestamp:
Jun 28, 2006 4:46:49 PM (18 years ago)
Author:
bennylp
Message:

Major improvements in PJSIP to support TCP. The changes fall into these categories: (1) the TCP transport implementation itself (*.[hc]), (2) bug-fix in SIP transaction when using reliable transports, (3) support for TCP transport in PJSUA-LIB/PJSUA, and (4) changes in PJSIP-TEST to support TCP testing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/test-pjsip/tsx_uac_test.c

    r555 r563  
    9292#define      TEST5_RETRANSMIT_CNT   3 
    9393 
     94static char TARGET_URI[128]; 
     95static char FROM_URI[128]; 
     96static unsigned tp_flag; 
     97static struct tsx_test_param *test_param; 
    9498 
    9599static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e); 
     
    141145 
    142146/* General timer entry to be used by tests. */ 
    143 static pj_timer_entry timer; 
     147static struct my_timer 
     148{ 
     149    pj_timer_entry  entry; 
     150    char            key_buf[1024]; 
     151    pj_str_t        tsx_key; 
     152} timer; 
    144153 
    145154/* 
     
    167176                test_complete = -710; 
    168177            } 
     178 
     179 
     180            /* If transport is reliable, then there must not be any 
     181             * retransmissions. 
     182             */ 
     183            if (tp_flag & PJSIP_TRANSPORT_RELIABLE) { 
     184                if (recv_count != 1) { 
     185                    PJ_LOG(3,(THIS_FILE,  
     186                           "    error: there were %d (re)transmissions", 
     187                           recv_count)); 
     188                    test_complete = -715; 
     189                } 
     190            } else { 
     191                /* Check the number of transmissions, which must be 
     192                 * 6 for INVITE and 10 for non-INVITE  
     193                 */ 
     194                if (tsx->method.id==PJSIP_INVITE_METHOD && recv_count != 7) { 
     195                    PJ_LOG(3,(THIS_FILE,  
     196                           "    error: there were %d (re)transmissions", 
     197                           recv_count)); 
     198                    test_complete = -716; 
     199                } else 
     200                if (tsx->method.id==PJSIP_OPTIONS_METHOD && recv_count != 11) { 
     201                    PJ_LOG(3,(THIS_FILE,  
     202                           "    error: there were %d (re)transmissions", 
     203                           recv_count)); 
     204                    test_complete = -717; 
     205                } else 
     206                if (tsx->method.id!=PJSIP_INVITE_METHOD &&  
     207                    tsx->method.id!=PJSIP_OPTIONS_METHOD) 
     208                { 
     209                    PJ_LOG(3,(THIS_FILE, "    error: unexpected method")); 
     210                    test_complete = -718; 
     211                } 
     212            } 
    169213        } 
    170214 
     
    516560                                    struct pj_timer_entry *entry) 
    517561{ 
    518     pjsip_transaction *tsx = entry->user_data; 
     562    struct my_timer *m = (struct my_timer *)entry; 
     563    pjsip_transaction *tsx = pjsip_tsx_layer_find_tsx(&m->tsx_key, PJ_FALSE); 
    519564    int status_code = entry->id; 
    520565 
     
    721766            pjsip_transport_add_ref(r->res_addr.transport); 
    722767 
    723         timer.cb = &send_response_callback; 
    724         timer.user_data = r; 
    725         pjsip_endpt_schedule_timer(endpt, &timer, &delay); 
     768        timer.entry.cb = &send_response_callback; 
     769        timer.entry.user_data = r; 
     770        pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); 
    726771 
    727772        return PJ_TRUE; 
     
    769814                                     rdata); 
    770815 
    771                 timer.user_data = pjsip_tsx_layer_find_tsx(&key, PJ_FALSE); 
    772                 timer.id = 301; 
    773                 timer.cb = &terminate_tsx_callback; 
    774  
    775                 pjsip_endpt_schedule_timer(endpt, &timer, &delay); 
     816                pj_strcpy(&timer.tsx_key, &key); 
     817                timer.entry.id = 301; 
     818                timer.entry.cb = &terminate_tsx_callback; 
     819 
     820                pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); 
    776821            } 
    777822 
     
    842887                pjsip_transport_add_ref(r->res_addr.transport); 
    843888 
    844             timer.cb = &send_response_callback; 
    845             timer.user_data = r; 
    846             pjsip_endpt_schedule_timer(endpt, &timer, &delay); 
     889            timer.entry.cb = &send_response_callback; 
     890            timer.entry.user_data = r; 
     891            pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); 
    847892 
    848893        } else if (method->id == PJSIP_ACK_METHOD) { 
     
    860905                                     rdata); 
    861906 
    862                 timer.user_data = pjsip_tsx_layer_find_tsx(&key, PJ_FALSE); 
    863                 timer.id = 302; 
    864                 timer.cb = &terminate_tsx_callback; 
    865  
    866                 pjsip_endpt_schedule_timer(endpt, &timer, &delay); 
     907                pj_strcpy(&timer.tsx_key, &key); 
     908                timer.entry.id = 302; 
     909                timer.entry.cb = &terminate_tsx_callback; 
     910 
     911                pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); 
    867912            } 
    868913 
     
    9811026        pjsip_tx_data_dec_ref(tdata); 
    9821027        return test_complete; 
    983     } 
    984  
    985     /* Allow transaction to destroy itself */ 
    986     flush_events(500); 
     1028 
     1029    } else { 
     1030        pj_time_val now; 
     1031 
     1032        /* Allow transaction to destroy itself */ 
     1033        flush_events(500); 
     1034 
     1035        /* Wait until test completes */ 
     1036        pj_gettimeofday(&now); 
     1037 
     1038        if (PJ_TIME_VAL_LT(now, timeout)) { 
     1039            pj_time_val interval; 
     1040            interval = timeout; 
     1041            PJ_TIME_VAL_SUB(interval, now); 
     1042            flush_events(PJ_TIME_VAL_MSEC(interval)); 
     1043        } 
     1044    } 
    9871045 
    9881046    /* Make sure transaction has been destroyed. */ 
     
    10531111 
    10541112        /* Do the test. */ 
    1055         status = perform_tsx_test(-500, "sip:bob@127.0.0.1;transport=loop-dgram", 
    1056                                   "sip:alice@127.0.0.1;transport=loop-dgram",  
     1113        status = perform_tsx_test(-500, TARGET_URI, FROM_URI,  
    10571114                                  TEST1_BRANCH_ID, 
    10581115                                  35, sub_test[i].method); 
     
    10941151 
    10951152    status = perform_tsx_test(-800,  
    1096                               "sip:bob@unresolved-host;transport=loop-dgram", 
    1097                               "sip:alice@127.0.0.1;transport=loop-dgram",  
    1098                               TEST2_BRANCH_ID, 10,  
     1153                              "sip:bob@unresolved-host", 
     1154                              FROM_URI,  TEST2_BRANCH_ID, 10,  
    10991155                              &pjsip_options_method); 
    11001156    if (status != 0) 
     
    11061162    PJ_LOG(3,(THIS_FILE, "   variant b: error via callback")); 
    11071163 
    1108     /* Set loop transport to return delayed error. */ 
    1109     pjsip_loop_set_failure(loop, 2, NULL); 
    1110     pjsip_loop_set_send_callback_delay(loop, 10, NULL); 
    1111  
    1112     status = perform_tsx_test(-800, "sip:bob@127.0.0.1;transport=loop-dgram", 
    1113                               "sip:alice@127.0.0.1;transport=loop-dgram",  
    1114                               TEST2_BRANCH_ID, 2,  
    1115                               &pjsip_options_method); 
    1116     if (status != 0) 
    1117         return status; 
    1118  
    1119     /* Restore loop transport settings. */ 
    1120     pjsip_loop_set_failure(loop, 0, NULL); 
    1121     pjsip_loop_set_send_callback_delay(loop, 0, NULL); 
     1164    /* This only applies to "loop-dgram" transport */ 
     1165    if (test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { 
     1166        /* Set loop transport to return delayed error. */ 
     1167        pjsip_loop_set_failure(loop, 2, NULL); 
     1168        pjsip_loop_set_send_callback_delay(loop, 10, NULL); 
     1169 
     1170        status = perform_tsx_test(-800, TARGET_URI, FROM_URI,  
     1171                                  TEST2_BRANCH_ID, 2,  
     1172                                  &pjsip_options_method); 
     1173        if (status != 0) 
     1174            return status; 
     1175 
     1176        /* Restore loop transport settings. */ 
     1177        pjsip_loop_set_failure(loop, 0, NULL); 
     1178        pjsip_loop_set_send_callback_delay(loop, 0, NULL); 
     1179    } 
    11221180 
    11231181    return status; 
     
    11441202 
    11451203    /* Start the test. */ 
    1146     status = perform_tsx_test(-900, "sip:127.0.0.1;transport=loop-dgram", 
    1147                               "sip:127.0.0.1;transport=loop-dgram", 
     1204    status = perform_tsx_test(-900, TARGET_URI, FROM_URI, 
    11481205                              TEST3_BRANCH_ID, 2, &pjsip_options_method); 
    11491206 
     
    11871244 
    11881245        /* Start the test. */ 
    1189         status = perform_tsx_test(-1000, "sip:127.0.0.1;transport=loop-dgram", 
    1190                                   "sip:127.0.0.1;transport=loop-dgram", 
     1246        status = perform_tsx_test(-1000, TARGET_URI, FROM_URI, 
    11911247                                  TEST4_BRANCH_ID, 6, &pjsip_options_method); 
    11921248 
     
    12191275 
    12201276    /* Do the test. */ 
    1221     status = perform_tsx_test(-1100, "sip:bob@127.0.0.1;transport=loop-dgram", 
    1222                               "sip:alice@127.0.0.1;transport=loop-dgram",  
     1277    status = perform_tsx_test(-1100, TARGET_URI, FROM_URI,  
    12231278                              TEST5_BRANCH_ID, 
    12241279                              6, &pjsip_options_method); 
     
    12501305    for (i=0; i<PJ_ARRAY_SIZE(delay); ++i) { 
    12511306         
    1252         PJ_LOG(3,(THIS_FILE, "   variant %c: with %d ms transport delay", 
    1253                              ('a'+i), delay[i])); 
    1254  
    1255         pjsip_loop_set_delay(loop, delay[i]); 
    1256  
    1257         status = perform_tsx_test(-1200,  
    1258                                   "sip:bob@127.0.0.1;transport=loop-dgram", 
    1259                                   "sip:alice@127.0.0.1;transport=loop-dgram", 
    1260                                   branch_id, 
    1261                                   10, method); 
     1307        if (test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { 
     1308            PJ_LOG(3,(THIS_FILE, "   variant %c: with %d ms transport delay", 
     1309                                 ('a'+i), delay[i])); 
     1310 
     1311            pjsip_loop_set_delay(loop, delay[i]); 
     1312        } 
     1313 
     1314        status = perform_tsx_test(-1200, TARGET_URI, FROM_URI, 
     1315                                  branch_id, 10, method); 
    12621316        if (status != 0) 
    12631317            return status; 
     1318 
     1319        if (test_param->type != PJSIP_TRANSPORT_LOOP_DGRAM) 
     1320            break; 
    12641321    } 
    12651322 
     
    12771334 ***************************************************************************** 
    12781335 */ 
    1279 int tsx_uac_test(void) 
     1336int tsx_uac_test(struct tsx_test_param *param) 
    12801337{ 
    12811338    pj_sockaddr_in addr; 
    12821339    pj_status_t status; 
     1340 
     1341    timer.tsx_key.ptr = timer.key_buf; 
     1342 
     1343    test_param = param; 
     1344 
     1345    /* Get transport flag */ 
     1346    tp_flag = pjsip_transport_get_flag_from_type(test_param->type); 
     1347 
     1348    pj_ansi_sprintf(TARGET_URI, "sip:bob@127.0.0.1:%d;transport=%s",  
     1349                    param->port, param->tp_type); 
     1350    pj_ansi_sprintf(FROM_URI, "sip:alice@127.0.0.1:%d;transport=%s",  
     1351                    param->port, param->tp_type); 
    12831352 
    12841353    /* Check if loop transport is configured. */ 
     
    13171386        return status; 
    13181387 
    1319     /* TEST4_BRANCH_ID: Transport failed after several retransmissions */ 
    1320     status = tsx_retransmit_fail_test(); 
    1321     if (status != 0) 
    1322         return status; 
    1323  
    1324     /* TEST5_BRANCH_ID: Terminate transaction after several retransmissions */ 
    1325     status = tsx_terminate_after_retransmit_test(); 
    1326     if (status != 0) 
    1327         return status; 
     1388    /* TEST4_BRANCH_ID: Transport failed after several retransmissions. 
     1389     *                  Only applies to loop transport. 
     1390     */ 
     1391    if (test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { 
     1392        status = tsx_retransmit_fail_test(); 
     1393        if (status != 0) 
     1394            return status; 
     1395    } 
     1396 
     1397    /* TEST5_BRANCH_ID: Terminate transaction after several retransmissions  
     1398     *                  Only applicable to non-reliable transports. 
     1399     */ 
     1400    if ((tp_flag & PJSIP_TRANSPORT_RELIABLE) == 0) { 
     1401        status = tsx_terminate_after_retransmit_test(); 
     1402        if (status != 0) 
     1403            return status; 
     1404    } 
    13281405 
    13291406    /* TEST6_BRANCH_ID: Successfull non-invite transaction */ 
     
    13531430        return status; 
    13541431 
    1355  
    13561432    pjsip_transport_dec_ref(loop); 
     1433    flush_events(500); 
     1434 
     1435    /* Unregister modules. */ 
     1436    status = pjsip_endpt_unregister_module(endpt, &tsx_user); 
     1437    if (status != PJ_SUCCESS) { 
     1438        app_perror("   Error: unable to unregister module", status); 
     1439        return -31; 
     1440    } 
     1441    status = pjsip_endpt_unregister_module(endpt, &msg_receiver); 
     1442    if (status != PJ_SUCCESS) { 
     1443        app_perror("   Error: unable to unregister module", status); 
     1444        return -41; 
     1445    } 
     1446 
    13571447    return 0; 
    13581448} 
Note: See TracChangeset for help on using the changeset viewer.