Ignore:
Timestamp:
Mar 22, 2007 11:59:03 AM (13 years ago)
Author:
bennylp
Message:

Tested simple ICE with data

File:
1 moved

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/src/pjnath-test/ice_test.c

    r1094 r1095  
    3030    unsigned        rx_rtcp_cnt; 
    3131 
    32     char            rx_rtp_data[32]; 
    33     char            rx_rtcp_data[32]; 
     32    unsigned        rx_rtp_count; 
     33    char            last_rx_rtp_data[32]; 
     34    unsigned        rx_rtcp_count; 
     35    char            last_rx_rtcp_data[32]; 
    3436}; 
    3537 
     
    5557 
    5658    id->rx_rtp_cnt++; 
    57     pj_memcpy(id->rx_rtp_data, pkt, size); 
     59    pj_memcpy(id->last_rx_rtp_data, pkt, size); 
     60    id->last_rx_rtp_data[size] = '\0'; 
    5861 
    5962    PJ_UNUSED_ARG(src_addr); 
     
    7073 
    7174    id->rx_rtcp_cnt++; 
    72     pj_memcpy(id->rx_rtcp_data, pkt, size); 
     75    pj_memcpy(id->last_rx_rtcp_data, pkt, size); 
     76    id->last_rx_rtcp_data[size] = '\0'; 
    7377 
    7478    PJ_UNUSED_ARG(src_addr); 
     
    103107    pj_bzero(&icemt_cb, sizeof(icemt_cb)); 
    104108    icemt_cb.on_ice_complete = &on_ice_complete; 
    105     icemt_cb.on_rx_rtcp = &on_rx_rtp; 
     109    icemt_cb.on_rx_rtp = &on_rx_rtp; 
    106110    icemt_cb.on_rx_rtcp = &on_rx_rtcp; 
    107111 
     
    153157 *   acand      Additional candidates to be added to answerer 
    154158 * 
    155  * The additional candidates are invalid candidates, meaning they 
    156  * won't be reachable by the agents. They are used to "confuse" 
     159 * The additional candidates are normally invalid candidates, meaning  
     160 * they won't be reachable by the agents. They are used to "confuse" 
    157161 * ICE processing. 
    158162 */ 
    159163static int perform_ice_test(const char *title, 
     164                            unsigned wait_before_send, 
     165                            unsigned max_total_time, 
    160166                            unsigned ocand_cnt, 
    161167                            const pj_ice_cand ocand[], 
     
    168174    pj_timestamp t_start, t_end; 
    169175    pj_ice_cand *rcand; 
     176    pj_str_t data_from_offerer, data_from_answerer; 
    170177    unsigned i; 
    171178    pj_status_t status; 
     
    175182    pj_bzero(&icemt_cb, sizeof(icemt_cb)); 
    176183    icemt_cb.on_ice_complete = &on_ice_complete; 
    177     icemt_cb.on_rx_rtcp = &on_rx_rtp; 
     184    icemt_cb.on_rx_rtp = &on_rx_rtp; 
    178185    icemt_cb.on_rx_rtcp = &on_rx_rtcp; 
    179186 
     
    253260#endif 
    254261 
     262    /* Poll for wait_before_send msecs before we send the first data */ 
     263    for (;;) { 
     264        pj_timestamp t_now; 
     265 
     266        handle_events(1); 
     267 
     268        pj_get_timestamp(&t_now); 
     269        if (pj_elapsed_msec(&t_start, &t_now) >= wait_before_send) 
     270            break; 
     271    } 
     272 
     273    /* Send data. It must be successful! */ 
     274    data_from_offerer = pj_str("from offerer"); 
     275    status = pj_ice_send_data(im1->ice, 1, data_from_offerer.ptr, data_from_offerer.slen); 
     276    if (status != PJ_SUCCESS) 
     277        return -47; 
     278 
     279    data_from_answerer = pj_str("from answerer"); 
     280    status = pj_ice_send_data(im2->ice, 1, data_from_answerer.ptr, data_from_answerer.slen); 
     281    if (status != PJ_SUCCESS) 
     282        return -48; 
     283 
     284    /* Poll to allow data to be received */ 
     285    for (;;) { 
     286        pj_timestamp t_now; 
     287        handle_events(1); 
     288        pj_get_timestamp(&t_now); 
     289        if (pj_elapsed_msec(&t_start, &t_now) >= (wait_before_send + 200)) 
     290            break; 
     291    } 
     292 
     293 
    255294    /* Just wait until both completes, or timed out */ 
    256295    while (!id1->complete || !id2->complete) { 
     
    260299 
    261300        pj_get_timestamp(&t_now); 
    262         if (pj_elapsed_msec(&t_start, &t_now) >= 10000) { 
     301        if (pj_elapsed_msec(&t_start, &t_now) >= max_total_time) { 
    263302            PJ_LOG(3,(THIS_FILE, "....error: timed-out")); 
    264303            return -50; 
     
    289328    } 
    290329 
     330    /* Check that data is received in offerer */ 
     331    if (id1->rx_rtp_cnt != 1) { 
     332        PJ_LOG(3,(THIS_FILE, "....error: data not received in offerer")); 
     333        return -80; 
     334    } 
     335    if (pj_strcmp2(&data_from_answerer, id1->last_rx_rtp_data) != 0) { 
     336        PJ_LOG(3,(THIS_FILE, "....error: data mismatch in offerer")); 
     337        return -82; 
     338    } 
     339 
     340    /* And the same in answerer */ 
     341    if (id2->rx_rtp_cnt != 1) { 
     342        PJ_LOG(3,(THIS_FILE, "....error: data not received in answerer")); 
     343        return -84; 
     344    } 
     345    if (pj_strcmp2(&data_from_offerer, id2->last_rx_rtp_data) != 0) { 
     346        PJ_LOG(3,(THIS_FILE, "....error: data mismatch in answerer")); 
     347        return -82; 
     348    } 
     349 
     350 
    291351    /* Done */ 
    292352    PJ_LOG(3,(THIS_FILE, "....success: ICE completed in %d msec",  
     
    299359 
    300360        pj_get_timestamp(&t_now); 
    301         if (pj_elapsed_msec(&t_end, &t_now) > 10000) 
     361        if (pj_elapsed_msec(&t_start, &t_now) > max_total_time) 
    302362            break; 
    303363 
     
    336396 
    337397    /* Direct communication */ 
    338     rc = perform_ice_test("Direct connection", 0, NULL, 0, NULL); 
     398    rc = perform_ice_test("Direct connection", 500, 1000, 0, NULL, 0, NULL); 
    339399    if (rc != 0) 
    340400        goto on_return; 
     
    348408    ocand[0].type = PJ_ICE_CAND_TYPE_HOST; 
    349409 
    350     rc = perform_ice_test("Direct connection with 1 invalid address", 1, ocand, 0, NULL); 
     410    rc = perform_ice_test("Direct connection with 1 invalid address", 500, 1000, 1, ocand, 0, NULL); 
    351411    if (rc != 0) 
    352412        goto on_return; 
     413 
     414    /* Direct communication with two components */ 
     415    rc = perform_ice_test("Direct connection with two components", 500, 1000, 0, NULL, 0, NULL); 
     416    if (rc != 0) 
     417        goto on_return; 
     418 
    353419 
    354420 
Note: See TracChangeset for help on using the changeset viewer.