Changeset 1096 for pjproject/trunk/pjnath/src/pjnath-test/ice_test.c
- Timestamp:
- Mar 22, 2007 9:00:53 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath-test/ice_test.c
r1095 r1096 38 38 static pj_stun_config stun_cfg; 39 39 40 static void on_ice_complete(pj_ice mt *icemt,40 static void on_ice_complete(pj_ice_st *icest, 41 41 pj_status_t status) 42 42 { 43 struct ice_data *id = (struct ice_data*) ice mt->user_data;43 struct ice_data *id = (struct ice_data*) icest->user_data; 44 44 id->complete = PJ_TRUE; 45 45 id->err_code = status; … … 49 49 50 50 51 static void on_rx_rtp(pj_icemt *icemt, 52 void *pkt, pj_size_t size, 53 const pj_sockaddr_t *src_addr, 54 unsigned src_addr_len) 55 { 56 struct ice_data *id = (struct ice_data*) icemt->user_data; 57 58 id->rx_rtp_cnt++; 59 pj_memcpy(id->last_rx_rtp_data, pkt, size); 60 id->last_rx_rtp_data[size] = '\0'; 61 62 PJ_UNUSED_ARG(src_addr); 63 PJ_UNUSED_ARG(src_addr_len); 64 } 65 66 67 static void on_rx_rtcp(pj_icemt *icemt, 51 static void on_rx_data(pj_ice_st *icest, 52 unsigned comp_id, unsigned cand_id, 68 53 void *pkt, pj_size_t size, 69 54 const pj_sockaddr_t *src_addr, 70 55 unsigned src_addr_len) 71 56 { 72 struct ice_data *id = (struct ice_data*) icemt->user_data; 73 74 id->rx_rtcp_cnt++; 75 pj_memcpy(id->last_rx_rtcp_data, pkt, size); 76 id->last_rx_rtcp_data[size] = '\0'; 77 57 struct ice_data *id = (struct ice_data*) icest->user_data; 58 59 if (comp_id == 1) { 60 id->rx_rtp_cnt++; 61 pj_memcpy(id->last_rx_rtp_data, pkt, size); 62 id->last_rx_rtp_data[size] = '\0'; 63 } else if (comp_id == 2) { 64 id->rx_rtcp_cnt++; 65 pj_memcpy(id->last_rx_rtcp_data, pkt, size); 66 id->last_rx_rtcp_data[size] = '\0'; 67 } else { 68 pj_assert(!"Invalid component ID"); 69 } 70 71 PJ_UNUSED_ARG(cand_id); 78 72 PJ_UNUSED_ARG(src_addr); 79 73 PJ_UNUSED_ARG(src_addr_len); … … 98 92 static int ice_basic_create_destroy_test() 99 93 { 100 pj_icemt *im; 101 pj_ice *ice; 102 pj_icemt_cb icemt_cb; 94 pj_ice_st *im; 95 pj_ice_st_cb icest_cb; 103 96 pj_status_t status; 104 97 105 98 PJ_LOG(3,(THIS_FILE, "...basic create/destroy")); 106 99 107 pj_bzero(&icemt_cb, sizeof(icemt_cb)); 108 icemt_cb.on_ice_complete = &on_ice_complete; 109 icemt_cb.on_rx_rtp = &on_rx_rtp; 110 icemt_cb.on_rx_rtcp = &on_rx_rtcp; 111 112 status = pj_icemt_create(&stun_cfg, NULL, PJ_ICE_ROLE_CONTROLLING, 113 &icemt_cb, 0, PJ_FALSE, PJ_FALSE, NULL, &im); 100 pj_bzero(&icest_cb, sizeof(icest_cb)); 101 icest_cb.on_ice_complete = &on_ice_complete; 102 icest_cb.on_rx_data = &on_rx_data; 103 104 status = pj_ice_st_create(&stun_cfg, NULL, NULL, &icest_cb, &im); 114 105 if (status != PJ_SUCCESS) 115 106 return -10; 116 107 117 ice = im->ice; 118 119 pj_icemt_destroy(im); 108 pj_ice_st_destroy(im); 120 109 121 110 return 0; … … 123 112 124 113 125 static pj_status_t set_remote_list(pj_icemt *src, pj_icemt *dst) 126 { 127 unsigned i, count; 128 unsigned cand_id[PJ_ICE_MAX_CAND]; 114 static pj_status_t start_ice(pj_ice_st *ist, pj_ice_st *remote) 115 { 116 unsigned count; 129 117 pj_ice_cand cand[PJ_ICE_MAX_CAND]; 130 118 pj_status_t status; 131 119 132 count = PJ_ARRAY_SIZE(cand _id);133 status = pj_ice_ enum_cands(src->ice, &count, cand_id);120 count = PJ_ARRAY_SIZE(cand); 121 status = pj_ice_st_enum_cands(remote, &count, cand); 134 122 if (status != PJ_SUCCESS) 135 123 return status; 136 124 137 for (i=0; i<count; ++i) { 138 pj_ice_cand *p_cand; 139 status = pj_ice_get_cand(src->ice, cand_id[i], &p_cand); 140 if (status != PJ_SUCCESS) 141 return status; 142 143 pj_memcpy(&cand[i], p_cand, sizeof(pj_ice_cand)); 144 } 145 146 status = pj_ice_create_check_list(dst->ice, count, cand); 147 return status; 148 } 125 return pj_ice_st_start_ice(ist, &remote->ice->rx_ufrag, &remote->ice->rx_pass, 126 count, cand); 127 } 128 149 129 150 130 … … 163 143 static int perform_ice_test(const char *title, 164 144 unsigned wait_before_send, 165 unsigned max_total_time, 166 unsigned ocand_cnt, 167 const pj_ice_cand ocand[], 168 unsigned acand_cnt, 169 const pj_ice_cand acand[]) 170 { 171 pj_icemt *im1, *im2; 172 pj_icemt_cb icemt_cb; 145 unsigned max_total_time) 146 { 147 pj_ice_st *im1, *im2; 148 pj_ice_st_cb icest_cb; 173 149 struct ice_data *id1, *id2; 174 150 pj_timestamp t_start, t_end; 175 151 pj_ice_cand *rcand; 176 152 pj_str_t data_from_offerer, data_from_answerer; 177 unsigned i;178 153 pj_status_t status; 179 154 180 155 PJ_LOG(3,(THIS_FILE, "...%s", title)); 181 156 182 pj_bzero(&icemt_cb, sizeof(icemt_cb)); 183 icemt_cb.on_ice_complete = &on_ice_complete; 184 icemt_cb.on_rx_rtp = &on_rx_rtp; 185 icemt_cb.on_rx_rtcp = &on_rx_rtcp; 157 pj_bzero(&icest_cb, sizeof(icest_cb)); 158 icest_cb.on_ice_complete = &on_ice_complete; 159 icest_cb.on_rx_data = &on_rx_data; 186 160 187 161 /* Create first ICE */ 188 status = pj_icemt_create(&stun_cfg, "offerer", PJ_ICE_ROLE_CONTROLLING, 189 &icemt_cb, 0, PJ_FALSE, PJ_FALSE, NULL, &im1); 162 status = pj_ice_st_create(&stun_cfg, "offerer", NULL, &icest_cb, &im1); 190 163 if (status != PJ_SUCCESS) 191 164 return -20; … … 195 168 im1->user_data = id1; 196 169 197 /* Add additional candidates*/198 for (i=0; i<ocand_cnt; ++i) {199 status = pj_ice_add_cand(im1->ice, 1, ocand[i].type, 65535, 200 &ocand[i].foundation, &ocand[i].addr,201 &ocand[i].base_addr, &ocand[i].srv_addr, 202 sizeof(pj_sockaddr_in), NULL); 203 if (status != PJ_SUCCESS) 204 return -22; 205 } 170 /* Add first component */ 171 status = pj_ice_st_add_comp(im1, 1); 172 if (status != PJ_SUCCESS) 173 return -21; 174 175 /* Add host candidate */ 176 status = pj_ice_st_add_host_interface(im1, 1, 65535, NULL, NULL, PJ_FALSE, NULL); 177 if (status != PJ_SUCCESS) 178 return -21; 206 179 207 180 /* Create second ICE */ 208 status = pj_icemt_create(&stun_cfg, "answerer", PJ_ICE_ROLE_CONTROLLED, 209 &icemt_cb, 0, PJ_FALSE, PJ_FALSE, NULL, &im2); 181 status = pj_ice_st_create(&stun_cfg, "answerer", NULL, &icest_cb, &im2); 210 182 if (status != PJ_SUCCESS) 211 183 return -25; … … 215 187 im2->user_data = id2; 216 188 217 /* Add additional candidates */ 218 for (i=0; i<acand_cnt; ++i) { 219 status = pj_ice_add_cand(im1->ice, 1, acand[i].type, 65535, 220 &acand[i].foundation, &acand[i].addr, 221 &acand[i].base_addr, &acand[i].srv_addr, 222 sizeof(pj_sockaddr_in), NULL); 223 if (status != PJ_SUCCESS) 224 return -22; 225 } 226 227 /* Set credentials */ 228 { 229 pj_str_t u1 = pj_str("offerer"); 230 pj_str_t p1 = pj_str("pass1"); 231 pj_str_t u2 = pj_str("answerer"); 232 pj_str_t p2 = pj_str("pass2"); 233 234 pj_ice_set_credentials(im1->ice, &u1, &p1, &u2, &p2); 235 pj_ice_set_credentials(im2->ice, &u2, &p2, &u1, &p1); 236 } 237 238 /* Send offer to im2 */ 239 status = set_remote_list(im1, im2); 189 /* Add first component */ 190 status = pj_ice_st_add_comp(im2, 1); 191 if (status != PJ_SUCCESS) 192 return -26; 193 194 /* Add host candidate */ 195 status = pj_ice_st_add_host_interface(im2, 1, 65535, NULL, NULL, PJ_FALSE, NULL); 196 if (status != PJ_SUCCESS) 197 return -27; 198 199 /* Init ICE on im1 */ 200 status = pj_ice_st_init_ice(im1, PJ_ICE_ROLE_CONTROLLING, NULL, NULL); 201 if (status != PJ_SUCCESS) 202 return -29; 203 204 /* Init ICE on im2 */ 205 status = pj_ice_st_init_ice(im2, PJ_ICE_ROLE_CONTROLLED, NULL, NULL); 206 if (status != PJ_SUCCESS) 207 return -29; 208 209 /* Start ICE on im2 */ 210 status = start_ice(im2, im1); 240 211 if (status != PJ_SUCCESS) 241 212 return -30; 242 213 243 /* S end answer toim1 */244 status = s et_remote_list(im2, im1);214 /* Start ICE on im1 */ 215 status = start_ice(im1, im2); 245 216 if (status != PJ_SUCCESS) 246 217 return -35; … … 248 219 /* Mark start time */ 249 220 pj_get_timestamp(&t_start); 250 251 /* Both can start now */252 status = pj_ice_start_check(im1->ice);253 if (status != PJ_SUCCESS)254 return -40;255 256 #if 1257 status = pj_ice_start_check(im2->ice);258 if (status != PJ_SUCCESS)259 return -45;260 #endif261 221 262 222 /* Poll for wait_before_send msecs before we send the first data */ … … 366 326 367 327 368 pj_ice mt_destroy(im1);369 pj_ice mt_destroy(im2);328 pj_ice_st_destroy(im1); 329 pj_ice_st_destroy(im2); 370 330 return 0; 371 331 } … … 378 338 pj_ioqueue_t *ioqueue; 379 339 pj_timer_heap_t *timer_heap; 380 pj_ice_cand ocand[PJ_ICE_MAX_CAND];381 pj_ice_cand acand[PJ_ICE_MAX_CAND];382 pj_str_t s;383 340 384 341 pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); … … 396 353 397 354 /* Direct communication */ 398 rc = perform_ice_test("Direct connection", 500, 1000 , 0, NULL, 0, NULL);355 rc = perform_ice_test("Direct connection", 500, 1000); 399 356 if (rc != 0) 400 357 goto on_return; 401 358 402 359 /* Direct communication with invalid address */ 403 pj_bzero(ocand, sizeof(ocand)); 404 pj_sockaddr_in_init(&ocand[0].addr.ipv4, pj_cstr(&s, "127.0.0.127"), 1234); 405 pj_sockaddr_in_init(&ocand[0].base_addr.ipv4, pj_cstr(&s, "127.0.0.128"), 1234); 406 ocand[0].comp_id = 1; 407 ocand[0].foundation = pj_str("H2"); 408 ocand[0].type = PJ_ICE_CAND_TYPE_HOST; 409 410 rc = perform_ice_test("Direct connection with 1 invalid address", 500, 1000, 1, ocand, 0, NULL); 360 rc = perform_ice_test("Direct connection with 1 invalid address", 500, 1000); 411 361 if (rc != 0) 412 362 goto on_return; 413 363 414 364 /* Direct communication with two components */ 415 rc = perform_ice_test("Direct connection with two components", 500, 1000 , 0, NULL, 0, NULL);365 rc = perform_ice_test("Direct connection with two components", 500, 1000); 416 366 if (rc != 0) 417 367 goto on_return;
Note: See TracChangeset
for help on using the changeset viewer.