| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "test.h" |
| 20 |
#include "server.h" |
| 21 |
|
| 22 |
enum |
| 23 |
{ |
| 24 |
NO = 0, |
| 25 |
YES = 1, |
| 26 |
SRV = 3, |
| 27 |
}; |
| 28 |
|
| 29 |
#define NODELAY 0xFFFFFFFF |
| 30 |
#define SRV_DOMAIN "pjsip.lab.domain" |
| 31 |
#define MAX_THREADS 16 |
| 32 |
|
| 33 |
#define STUN_RANDOM_PORT 43478 |
| 34 |
#define TURN_RANDOM_PORT 43479 |
| 35 |
|
| 36 |
#define THIS_FILE "ice_test.c" |
| 37 |
#define INDENT " " |
| 38 |
|
| 39 |
|
| 40 |
enum |
| 41 |
{ |
| 42 |
WRONG_TURN = 1, |
| 43 |
DEL_ON_ERR = 2, |
| 44 |
CLIENT_IPV4 = 4, |
| 45 |
CLIENT_IPV6 = 8 |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
struct test_result |
| 50 |
{ |
| 51 |
pj_status_t start_status; |
| 52 |
pj_status_t init_status; |
| 53 |
pj_status_t nego_status; |
| 54 |
unsigned rx_cnt[4]; |
| 55 |
}; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
struct test_cfg |
| 60 |
{ |
| 61 |
pj_ice_sess_role role; |
| 62 |
unsigned comp_cnt; |
| 63 |
unsigned enable_host; |
| 64 |
unsigned enable_stun; |
| 65 |
unsigned enable_turn; |
| 66 |
unsigned client_flag; |
| 67 |
|
| 68 |
unsigned answer_delay; |
| 69 |
unsigned send_delay; |
| 70 |
unsigned destroy_delay; |
| 71 |
|
| 72 |
struct test_result expected; |
| 73 |
|
| 74 |
pj_bool_t nom_regular; |
| 75 |
pj_ice_sess_trickle trickle; |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
struct ice_ept |
| 80 |
{ |
| 81 |
struct test_cfg cfg; |
| 82 |
pj_ice_strans *ice; |
| 83 |
struct test_result result; |
| 84 |
|
| 85 |
pj_str_t ufrag; |
| 86 |
pj_str_t pass; |
| 87 |
|
| 88 |
|
| 89 |
pj_bool_t last_cand; |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
struct sess_param |
| 94 |
{ |
| 95 |
unsigned worker_cnt; |
| 96 |
unsigned worker_timeout; |
| 97 |
pj_bool_t worker_quit; |
| 98 |
|
| 99 |
pj_bool_t destroy_after_create; |
| 100 |
pj_bool_t destroy_after_one_done; |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
struct test_sess |
| 105 |
{ |
| 106 |
pj_pool_t *pool; |
| 107 |
pj_stun_config *stun_cfg; |
| 108 |
pj_dns_resolver *resolver; |
| 109 |
|
| 110 |
struct sess_param *param; |
| 111 |
|
| 112 |
test_server *server1; |
| 113 |
test_server *server2; |
| 114 |
|
| 115 |
pj_thread_t *worker_threads[MAX_THREADS]; |
| 116 |
|
| 117 |
unsigned server_flag; |
| 118 |
struct ice_ept caller; |
| 119 |
struct ice_ept callee; |
| 120 |
}; |
| 121 |
|
| 122 |
|
| 123 |
static void ice_on_rx_data(pj_ice_strans *ice_st, |
| 124 |
unsigned comp_id, |
| 125 |
void *pkt, pj_size_t size, |
| 126 |
const pj_sockaddr_t *src_addr, |
| 127 |
unsigned src_addr_len); |
| 128 |
static void ice_on_ice_complete(pj_ice_strans *ice_st, |
| 129 |
pj_ice_strans_op op, |
| 130 |
pj_status_t status); |
| 131 |
static void ice_on_new_candidate(pj_ice_strans *ice_st, |
| 132 |
const pj_ice_sess_cand *cand, |
| 133 |
pj_bool_t last); |
| 134 |
|
| 135 |
static void destroy_sess(struct test_sess *sess, unsigned wait_msec); |
| 136 |
|
| 137 |
#if USE_IPV6 |
| 138 |
|
| 139 |
static pj_bool_t enable_ipv6_test() |
| 140 |
{ |
| 141 |
pj_sockaddr addr; |
| 142 |
pj_bool_t retval = PJ_TRUE; |
| 143 |
if (pj_gethostip(pj_AF_INET6(), &addr) == PJ_SUCCESS) { |
| 144 |
const pj_in6_addr *a = &addr.ipv6.sin6_addr; |
| 145 |
if (a->s6_addr[0] == 0xFE && (a->s6_addr[1] & 0xC0) == 0x80) { |
| 146 |
retval = PJ_FALSE; |
| 147 |
PJ_LOG(3,(THIS_FILE, INDENT "Skipping IPv6 test due to link-local " |
| 148 |
"address")); |
| 149 |
} |
| 150 |
} else { |
| 151 |
retval = PJ_FALSE; |
| 152 |
PJ_LOG(3,(THIS_FILE, INDENT "Skipping IPv6 test due to fail getting " |
| 153 |
"IPv6 address")); |
| 154 |
} |
| 155 |
return retval; |
| 156 |
} |
| 157 |
|
| 158 |
#endif |
| 159 |
|
| 160 |
static void set_stun_turn_cfg(struct ice_ept *ept, |
| 161 |
pj_ice_strans_cfg *ice_cfg, |
| 162 |
char *serverip, |
| 163 |
pj_uint16_t stun_server_port, |
| 164 |
pj_uint16_t turn_server_port, |
| 165 |
pj_bool_t use_ipv6) |
| 166 |
{ |
| 167 |
if (ept->cfg.enable_stun & YES) { |
| 168 |
unsigned stun_idx = ice_cfg->stun_tp_cnt++; |
| 169 |
pj_ice_strans_stun_cfg_default(&ice_cfg->stun_tp[stun_idx]); |
| 170 |
|
| 171 |
if ((ept->cfg.enable_stun & SRV) == SRV) { |
| 172 |
ice_cfg->stun_tp[stun_idx].server = pj_str(SRV_DOMAIN); |
| 173 |
} else { |
| 174 |
ice_cfg->stun_tp[stun_idx].server = pj_str(serverip); |
| 175 |
} |
| 176 |
ice_cfg->stun_tp[stun_idx].port = stun_server_port; |
| 177 |
|
| 178 |
ice_cfg->stun_tp[stun_idx].af = GET_AF(use_ipv6); |
| 179 |
} |
| 180 |
ice_cfg->stun.af = GET_AF(use_ipv6); |
| 181 |
if (ept->cfg.enable_host == 0) { |
| 182 |
ice_cfg->stun.max_host_cands = 0; |
| 183 |
} else { |
| 184 |
|
| 185 |
ice_cfg->stun.loop_addr = PJ_TRUE; |
| 186 |
} |
| 187 |
|
| 188 |
if (ept->cfg.enable_turn & YES) { |
| 189 |
unsigned turn_idx = ice_cfg->turn_tp_cnt++; |
| 190 |
pj_ice_strans_turn_cfg_default(&ice_cfg->turn_tp[turn_idx]); |
| 191 |
|
| 192 |
if ((ept->cfg.enable_turn & SRV) == SRV) { |
| 193 |
ice_cfg->turn_tp[turn_idx].server = pj_str(SRV_DOMAIN); |
| 194 |
} else { |
| 195 |
ice_cfg->turn_tp[turn_idx].server = pj_str(serverip); |
| 196 |
} |
| 197 |
ice_cfg->turn_tp[turn_idx].port = turn_server_port; |
| 198 |
ice_cfg->turn_tp[turn_idx].conn_type = PJ_TURN_TP_UDP; |
| 199 |
ice_cfg->turn_tp[turn_idx].auth_cred.type = PJ_STUN_AUTH_CRED_STATIC; |
| 200 |
ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.realm = |
| 201 |
pj_str(SRV_DOMAIN); |
| 202 |
if (ept->cfg.client_flag & WRONG_TURN) |
| 203 |
ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.username = |
| 204 |
pj_str("xxx"); |
| 205 |
else |
| 206 |
ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.username = |
| 207 |
pj_str(TURN_USERNAME); |
| 208 |
|
| 209 |
ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.data_type = |
| 210 |
PJ_STUN_PASSWD_PLAIN; |
| 211 |
ice_cfg->turn_tp[turn_idx].auth_cred.data.static_cred.data = |
| 212 |
pj_str(TURN_PASSWD); |
| 213 |
|
| 214 |
ice_cfg->turn_tp[turn_idx].af = GET_AF(use_ipv6); |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
static int create_ice_strans(struct test_sess *test_sess, |
| 220 |
struct ice_ept *ept, |
| 221 |
pj_ice_strans **p_ice) |
| 222 |
{ |
| 223 |
pj_ice_strans *ice; |
| 224 |
pj_ice_strans_cb ice_cb; |
| 225 |
pj_ice_strans_cfg ice_cfg; |
| 226 |
pj_sockaddr hostip; |
| 227 |
char serveripv4[PJ_INET6_ADDRSTRLEN]; |
| 228 |
char serveripv6[PJ_INET6_ADDRSTRLEN]; |
| 229 |
unsigned flag = (ept->cfg.client_flag)?ept->cfg.client_flag:CLIENT_IPV4; |
| 230 |
|
| 231 |
PJ_TEST_SUCCESS(pj_gethostip(pj_AF_INET(), &hostip), NULL, return -1030); |
| 232 |
|
| 233 |
pj_sockaddr_print(&hostip, serveripv4, sizeof(serveripv4), 0); |
| 234 |
|
| 235 |
if (flag & CLIENT_IPV6) { |
| 236 |
PJ_TEST_SUCCESS(pj_gethostip(pj_AF_INET6(), &hostip), |
| 237 |
NULL, return -1031); |
| 238 |
|
| 239 |
pj_sockaddr_print(&hostip, serveripv6, sizeof(serveripv6), 0); |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
pj_bzero(&ice_cb, sizeof(ice_cb)); |
| 244 |
ice_cb.on_rx_data = &ice_on_rx_data; |
| 245 |
ice_cb.on_ice_complete = &ice_on_ice_complete; |
| 246 |
ice_cb.on_new_candidate = &ice_on_new_candidate; |
| 247 |
|
| 248 |
|
| 249 |
pj_ice_strans_cfg_default(&ice_cfg); |
| 250 |
ice_cfg.opt.trickle = ept->cfg.trickle; |
| 251 |
pj_memcpy(&ice_cfg.stun_cfg, test_sess->stun_cfg, sizeof(pj_stun_config)); |
| 252 |
if ((ept->cfg.enable_stun & SRV)==SRV || (ept->cfg.enable_turn & SRV)==SRV) |
| 253 |
ice_cfg.resolver = test_sess->resolver; |
| 254 |
|
| 255 |
|
| 256 |
#define OR(val1,val2) (val1? val1 : val2) |
| 257 |
|
| 258 |
if (flag & CLIENT_IPV4) { |
| 259 |
set_stun_turn_cfg(ept, &ice_cfg, serveripv4, |
| 260 |
OR(test_sess->server1->stun_server_port, STUN_RANDOM_PORT), |
| 261 |
OR(test_sess->server1->turn_server_port, TURN_RANDOM_PORT), |
| 262 |
PJ_FALSE); |
| 263 |
} |
| 264 |
|
| 265 |
if (flag & CLIENT_IPV6) { |
| 266 |
set_stun_turn_cfg(ept, &ice_cfg, serveripv6, |
| 267 |
OR(test_sess->server2->stun_server_port, STUN_RANDOM_PORT), |
| 268 |
OR(test_sess->server2->turn_server_port, TURN_RANDOM_PORT), |
| 269 |
PJ_TRUE); |
| 270 |
} |
| 271 |
#undef OR |
| 272 |
|
| 273 |
|
| 274 |
PJ_TEST_SUCCESS(pj_ice_strans_create(NULL, &ice_cfg, ept->cfg.comp_cnt, |
| 275 |
(void*)ept, &ice_cb, &ice), |
| 276 |
NULL, return -1040); |
| 277 |
|
| 278 |
pj_create_unique_string(test_sess->pool, &ept->ufrag); |
| 279 |
pj_create_unique_string(test_sess->pool, &ept->pass); |
| 280 |
|
| 281 |
|
| 282 |
*p_ice = ice; |
| 283 |
return 0; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
static int create_sess(pj_stun_config *stun_cfg, |
| 288 |
unsigned server_flag, |
| 289 |
struct test_cfg *caller_cfg, |
| 290 |
struct test_cfg *callee_cfg, |
| 291 |
struct sess_param *test_param, |
| 292 |
struct test_sess **p_sess) |
| 293 |
{ |
| 294 |
pj_pool_t *pool; |
| 295 |
struct test_sess *sess; |
| 296 |
pj_str_t ns_ip; |
| 297 |
pj_uint16_t ns_port; |
| 298 |
unsigned flags; |
| 299 |
int rc; |
| 300 |
|
| 301 |
|
| 302 |
pool = pj_pool_create(stun_cfg->pf, "testsess", 512, 512, NULL); |
| 303 |
sess = PJ_POOL_ZALLOC_T(pool, struct test_sess); |
| 304 |
sess->pool = pool; |
| 305 |
sess->stun_cfg = stun_cfg; |
| 306 |
sess->param = test_param; |
| 307 |
|
| 308 |
pj_memcpy(&sess->caller.cfg, caller_cfg, sizeof(*caller_cfg)); |
| 309 |
sess->caller.result.init_status = sess->caller.result.nego_status = PJ_EPENDING; |
| 310 |
|
| 311 |
pj_memcpy(&sess->callee.cfg, callee_cfg, sizeof(*callee_cfg)); |
| 312 |
sess->callee.result.init_status = sess->callee.result.nego_status = PJ_EPENDING; |
| 313 |
|
| 314 |
|
| 315 |
flags = server_flag; |
| 316 |
if (flags & SERVER_IPV4) { |
| 317 |
PJ_TEST_SUCCESS(create_test_server(stun_cfg, (flags & ~SERVER_IPV6), |
| 318 |
SRV_DOMAIN, &sess->server1), |
| 319 |
NULL, { destroy_sess(sess, 500); return -10; }); |
| 320 |
} |
| 321 |
|
| 322 |
if (flags & SERVER_IPV6) { |
| 323 |
PJ_TEST_SUCCESS(create_test_server(stun_cfg, (flags & ~SERVER_IPV4), |
| 324 |
SRV_DOMAIN, &sess->server2), |
| 325 |
NULL, { destroy_sess(sess, 500); return -11; }); |
| 326 |
} |
| 327 |
|
| 328 |
if (flags & SERVER_IPV4) { |
| 329 |
sess->server1->turn_respond_allocate = |
| 330 |
sess->server1->turn_respond_refresh = PJ_TRUE; |
| 331 |
} |
| 332 |
|
| 333 |
if (flags & SERVER_IPV6) { |
| 334 |
sess->server2->turn_respond_allocate = |
| 335 |
sess->server2->turn_respond_refresh = PJ_TRUE; |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
if ((sess->callee.cfg.enable_stun & SRV)==SRV || |
| 340 |
(sess->callee.cfg.enable_turn & SRV)==SRV || |
| 341 |
(sess->caller.cfg.enable_stun & SRV)==SRV || |
| 342 |
(sess->caller.cfg.enable_turn & SRV)==SRV) |
| 343 |
{ |
| 344 |
PJ_TEST_SUCCESS(pj_dns_resolver_create(stun_cfg->pf, NULL, 0, |
| 345 |
stun_cfg->timer_heap, |
| 346 |
stun_cfg->ioqueue, |
| 347 |
&sess->resolver), |
| 348 |
NULL, { destroy_sess(sess, 500); return -20; }); |
| 349 |
|
| 350 |
if (flags & SERVER_IPV6) { |
| 351 |
ns_ip = pj_str("::1"); |
| 352 |
ns_port = sess->server2->dns_server_port; |
| 353 |
} else { |
| 354 |
ns_ip = pj_str("127.0.0.1"); |
| 355 |
ns_port = sess->server1->dns_server_port; |
| 356 |
} |
| 357 |
|
| 358 |
PJ_TEST_SUCCESS(pj_dns_resolver_set_ns(sess->resolver, 1, &ns_ip, |
| 359 |
&ns_port), |
| 360 |
NULL, { destroy_sess(sess, 500); return -21; }); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
rc = create_ice_strans(sess, &sess->caller, &sess->caller.ice); |
| 365 |
if (rc != 0) { |
| 366 |
destroy_sess(sess, 500); |
| 367 |
return rc; |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
rc = create_ice_strans(sess, &sess->callee, &sess->callee.ice); |
| 372 |
if (rc != 0) { |
| 373 |
destroy_sess(sess, 500); |
| 374 |
return rc; |
| 375 |
} |
| 376 |
|
| 377 |
*p_sess = sess; |
| 378 |
return 0; |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
static void destroy_sess(struct test_sess *sess, unsigned wait_msec) |
| 383 |
{ |
| 384 |
unsigned i; |
| 385 |
|
| 386 |
if (sess->caller.ice) { |
| 387 |
pj_ice_strans_destroy(sess->caller.ice); |
| 388 |
sess->caller.ice = NULL; |
| 389 |
} |
| 390 |
|
| 391 |
if (sess->callee.ice) { |
| 392 |
pj_ice_strans_destroy(sess->callee.ice); |
| 393 |
sess->callee.ice = NULL; |
| 394 |
} |
| 395 |
|
| 396 |
sess->param->worker_quit = PJ_TRUE; |
| 397 |
for (i=0; i<sess->param->worker_cnt; ++i) { |
| 398 |
if (sess->worker_threads[i]) |
| 399 |
pj_thread_join(sess->worker_threads[i]); |
| 400 |
} |
| 401 |
|
| 402 |
poll_events(sess->stun_cfg, wait_msec, PJ_FALSE); |
| 403 |
|
| 404 |
if (sess->resolver) { |
| 405 |
pj_dns_resolver_destroy(sess->resolver, PJ_FALSE); |
| 406 |
sess->resolver = NULL; |
| 407 |
} |
| 408 |
|
| 409 |
if (sess->server1) { |
| 410 |
destroy_test_server(sess->server1); |
| 411 |
sess->server1 = NULL; |
| 412 |
} |
| 413 |
|
| 414 |
if (sess->server2) { |
| 415 |
destroy_test_server(sess->server2); |
| 416 |
sess->server2 = NULL; |
| 417 |
} |
| 418 |
|
| 419 |
pj_pool_safe_release(&sess->pool); |
| 420 |
} |
| 421 |
|
| 422 |
static void ice_on_rx_data(pj_ice_strans *ice_st, |
| 423 |
unsigned comp_id, |
| 424 |
void *pkt, pj_size_t size, |
| 425 |
const pj_sockaddr_t *src_addr, |
| 426 |
unsigned src_addr_len) |
| 427 |
{ |
| 428 |
struct ice_ept *ept; |
| 429 |
|
| 430 |
PJ_UNUSED_ARG(pkt); |
| 431 |
PJ_UNUSED_ARG(size); |
| 432 |
PJ_UNUSED_ARG(src_addr); |
| 433 |
PJ_UNUSED_ARG(src_addr_len); |
| 434 |
|
| 435 |
ept = (struct ice_ept*) pj_ice_strans_get_user_data(ice_st); |
| 436 |
ept->result.rx_cnt[comp_id]++; |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
static void ice_on_ice_complete(pj_ice_strans *ice_st, |
| 441 |
pj_ice_strans_op op, |
| 442 |
pj_status_t status) |
| 443 |
{ |
| 444 |
struct ice_ept *ept; |
| 445 |
|
| 446 |
ept = (struct ice_ept*) pj_ice_strans_get_user_data(ice_st); |
| 447 |
if (!ept) |
| 448 |
return; |
| 449 |
|
| 450 |
switch (op) { |
| 451 |
case PJ_ICE_STRANS_OP_INIT: |
| 452 |
ept->result.init_status = status; |
| 453 |
if (status != PJ_SUCCESS && (ept->cfg.client_flag & DEL_ON_ERR)) { |
| 454 |
pj_ice_strans_destroy(ice_st); |
| 455 |
ept->ice = NULL; |
| 456 |
} |
| 457 |
break; |
| 458 |
case PJ_ICE_STRANS_OP_NEGOTIATION: |
| 459 |
ept->result.nego_status = status; |
| 460 |
break; |
| 461 |
case PJ_ICE_STRANS_OP_KEEP_ALIVE: |
| 462 |
|
| 463 |
break; |
| 464 |
default: |
| 465 |
pj_assert(!"Unknown op"); |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
static void ice_on_new_candidate(pj_ice_strans *ice_st, |
| 470 |
const pj_ice_sess_cand *cand, |
| 471 |
pj_bool_t last) |
| 472 |
{ |
| 473 |
struct ice_ept *ept; |
| 474 |
char buf1[PJ_INET6_ADDRSTRLEN+10]; |
| 475 |
char buf2[PJ_INET6_ADDRSTRLEN+10]; |
| 476 |
|
| 477 |
ept = (struct ice_ept*) pj_ice_strans_get_user_data(ice_st); |
| 478 |
if (!ept) |
| 479 |
return; |
| 480 |
|
| 481 |
ept->last_cand = last; |
| 482 |
|
| 483 |
if (cand) { |
| 484 |
PJ_LOG(4,(THIS_FILE, INDENT "%p: discovered a new candidate " |
| 485 |
"comp=%d, type=%s, addr=%s, baseaddr=%s, end=%d", |
| 486 |
ept->ice, cand->comp_id, |
| 487 |
pj_ice_get_cand_type_name(cand->type), |
| 488 |
pj_sockaddr_print(&cand->addr, buf1, sizeof(buf1), 3), |
| 489 |
pj_sockaddr_print(&cand->base_addr, buf2, sizeof(buf2), 3), |
| 490 |
last)); |
| 491 |
} else if (ept->ice && last) { |
| 492 |
PJ_LOG(4,(THIS_FILE, INDENT "%p: end of candidate", ept->ice)); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
static pj_status_t start_ice(struct ice_ept *ept, const struct ice_ept *remote) |
| 500 |
{ |
| 501 |
pj_ice_sess_cand rcand[32]; |
| 502 |
unsigned rcand_cnt = 0; |
| 503 |
pj_status_t status; |
| 504 |
|
| 505 |
|
| 506 |
if (ept->cfg.trickle == PJ_ICE_SESS_TRICKLE_DISABLED) { |
| 507 |
unsigned i; |
| 508 |
for (i=0; i<remote->cfg.comp_cnt; ++i) { |
| 509 |
unsigned cnt = PJ_ARRAY_SIZE(rcand) - rcand_cnt; |
| 510 |
PJ_TEST_SUCCESS((status=pj_ice_strans_enum_cands(remote->ice, i+1, &cnt, |
| 511 |
rcand+rcand_cnt)), |
| 512 |
NULL, return status); |
| 513 |
rcand_cnt += cnt; |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
PJ_TEST_EQ((status=pj_ice_strans_start_ice(ept->ice, &remote->ufrag, |
| 518 |
&remote->pass, |
| 519 |
rcand_cnt, rcand)), |
| 520 |
ept->cfg.expected.start_status, NULL, |
| 521 |
{return status==PJ_SUCCESS? PJ_EINVALIDOP : status; }); |
| 522 |
|
| 523 |
return status; |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
static int check_pair(const struct ice_ept *ept1, const struct ice_ept *ept2, |
| 529 |
int start_err) |
| 530 |
{ |
| 531 |
unsigned i, min_cnt, max_cnt; |
| 532 |
|
| 533 |
if (ept1->cfg.comp_cnt < ept2->cfg.comp_cnt) { |
| 534 |
min_cnt = ept1->cfg.comp_cnt; |
| 535 |
max_cnt = ept2->cfg.comp_cnt; |
| 536 |
} else { |
| 537 |
min_cnt = ept2->cfg.comp_cnt; |
| 538 |
max_cnt = ept1->cfg.comp_cnt; |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
for (i=0; i<min_cnt; ++i) { |
| 543 |
const pj_ice_sess_check *c1; |
| 544 |
const pj_ice_sess_check *c2; |
| 545 |
|
| 546 |
c1 = pj_ice_strans_get_valid_pair(ept1->ice, i+1); |
| 547 |
if (c1 == NULL) { |
| 548 |
PJ_LOG(3,(THIS_FILE, INDENT "err: unable to get valid pair for ice1 " |
| 549 |
"component %d", i+1)); |
| 550 |
return start_err - 2; |
| 551 |
} |
| 552 |
|
| 553 |
c2 = pj_ice_strans_get_valid_pair(ept2->ice, i+1); |
| 554 |
if (c2 == NULL) { |
| 555 |
PJ_LOG(3,(THIS_FILE, INDENT "err: unable to get valid pair for ice2 " |
| 556 |
"component %d", i+1)); |
| 557 |
return start_err - 4; |
| 558 |
} |
| 559 |
|
| 560 |
if (pj_sockaddr_cmp(&c1->rcand->addr, &c2->lcand->addr) != 0) { |
| 561 |
PJ_LOG(3,(THIS_FILE, INDENT "err: candidate pair does not match " |
| 562 |
"for component %d", i+1)); |
| 563 |
return start_err - 6; |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
for (; i<max_cnt; ++i) { |
| 569 |
if (ept1->cfg.comp_cnt>i && |
| 570 |
pj_ice_strans_get_valid_pair(ept1->ice, i+1) != NULL) |
| 571 |
{ |
| 572 |
PJ_LOG(3,(THIS_FILE, INDENT "err: ice1 shouldn't have valid pair " |
| 573 |
"for component %d", i+1)); |
| 574 |
return start_err - 8; |
| 575 |
} |
| 576 |
if (ept2->cfg.comp_cnt>i && |
| 577 |
pj_ice_strans_get_valid_pair(ept2->ice, i+1) != NULL) |
| 578 |
{ |
| 579 |
PJ_LOG(3,(THIS_FILE, INDENT "err: ice2 shouldn't have valid pair " |
| 580 |
"for component %d", i+1)); |
| 581 |
return start_err - 9; |
| 582 |
} |
| 583 |
} |
| 584 |
|
| 585 |
return 0; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
#define WAIT_UNTIL(timeout,expr, RC) { \ |
| 590 |
pj_time_val t0, t; \ |
| 591 |
pj_gettimeofday(&t0); \ |
| 592 |
RC = -1; \ |
| 593 |
for (;;) { \ |
| 594 |
poll_events(stun_cfg, 10, PJ_FALSE); \ |
| 595 |
pj_gettimeofday(&t); \ |
| 596 |
if (expr) { \ |
| 597 |
RC = PJ_SUCCESS; \ |
| 598 |
break; \ |
| 599 |
} \ |
| 600 |
PJ_TIME_VAL_SUB(t, t0); \ |
| 601 |
if ((unsigned)PJ_TIME_VAL_MSEC(t) >= (timeout)) \ |
| 602 |
break; \ |
| 603 |
} \ |
| 604 |
} |
| 605 |
|
| 606 |
int worker_thread_proc(void *data) |
| 607 |
{ |
| 608 |
pj_status_t rc; |
| 609 |
struct test_sess *sess = (struct test_sess *) data; |
| 610 |
pj_stun_config *stun_cfg = sess->stun_cfg; |
| 611 |
|
| 612 |
|
| 613 |
#define ALL_DONE (sess->param->worker_quit || \ |
| 614 |
(sess->caller.result.nego_status!=PJ_EPENDING && \ |
| 615 |
sess->callee.result.nego_status!=PJ_EPENDING)) |
| 616 |
WAIT_UNTIL(sess->param->worker_timeout, ALL_DONE, rc); |
| 617 |
PJ_UNUSED_ARG(rc); |
| 618 |
return 0; |
| 619 |
} |
| 620 |
|
| 621 |
static int perform_test2(const char *title, |
| 622 |
pj_stun_config *stun_cfg, |
| 623 |
unsigned server_flag, |
| 624 |
struct test_cfg *caller_cfg, |
| 625 |
struct test_cfg *callee_cfg, |
| 626 |
struct sess_param *test_param) |
| 627 |
{ |
| 628 |
pjlib_state pjlib_state; |
| 629 |
struct test_sess *sess; |
| 630 |
unsigned i; |
| 631 |
int rc; |
| 632 |
char add_title1[16]; |
| 633 |
char add_title2[16]; |
| 634 |
pj_bool_t client_mix_test = ((callee_cfg->client_flag & |
| 635 |
(CLIENT_IPV4+CLIENT_IPV6)) != |
| 636 |
(caller_cfg->client_flag & |
| 637 |
(CLIENT_IPV4+CLIENT_IPV6))); |
| 638 |
|
| 639 |
pj_ansi_snprintf(add_title1, sizeof(add_title1), "%s%s%s", |
| 640 |
(server_flag & SERVER_IPV4)?"IPv4":"", |
| 641 |
((server_flag & SERVER_IPV4)&&(server_flag & SERVER_IPV6))?"+":"", |
| 642 |
(server_flag & SERVER_IPV6)?"IPv6":""); |
| 643 |
|
| 644 |
pj_ansi_snprintf(add_title2, sizeof(add_title2), "%s", |
| 645 |
client_mix_test?"Mix test":""); |
| 646 |
|
| 647 |
PJ_LOG(3,(THIS_FILE, INDENT "%s (%s) %s", title, add_title1, add_title2)); |
| 648 |
|
| 649 |
capture_pjlib_state(stun_cfg, &pjlib_state); |
| 650 |
|
| 651 |
rc = create_sess(stun_cfg, server_flag, caller_cfg, callee_cfg, test_param, |
| 652 |
&sess); |
| 653 |
if (rc != 0) |
| 654 |
return rc; |
| 655 |
|
| 656 |
#define ALL_READY (sess->caller.result.init_status!=PJ_EPENDING && \ |
| 657 |
sess->callee.result.init_status!=PJ_EPENDING) |
| 658 |
|
| 659 |
|
| 660 |
WAIT_UNTIL(30000, ALL_READY, rc); |
| 661 |
|
| 662 |
if (!ALL_READY) { |
| 663 |
PJ_LOG(3,(THIS_FILE, INDENT "err: init timed-out")); |
| 664 |
destroy_sess(sess, 500); |
| 665 |
return -100; |
| 666 |
} |
| 667 |
|
| 668 |
if (sess->caller.result.init_status != sess->caller.cfg.expected.init_status) { |
| 669 |
app_perror(INDENT "err: caller init", sess->caller.result.init_status); |
| 670 |
destroy_sess(sess, 500); |
| 671 |
return -102; |
| 672 |
} |
| 673 |
if (sess->callee.result.init_status != sess->callee.cfg.expected.init_status) { |
| 674 |
app_perror(INDENT "err: callee init", sess->callee.result.init_status); |
| 675 |
destroy_sess(sess, 500); |
| 676 |
return -104; |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
if (sess->caller.result.init_status != PJ_SUCCESS || |
| 681 |
sess->callee.result.init_status != PJ_SUCCESS) |
| 682 |
{ |
| 683 |
|
| 684 |
goto on_return; |
| 685 |
} |
| 686 |
|
| 687 |
rc = pj_ice_strans_init_ice(sess->caller.ice, sess->caller.cfg.role, |
| 688 |
&sess->caller.ufrag, &sess->caller.pass); |
| 689 |
if (rc != PJ_SUCCESS) { |
| 690 |
app_perror(INDENT "err: caller pj_ice_strans_init_ice()", rc); |
| 691 |
destroy_sess(sess, 500); |
| 692 |
return -106; |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
rc = pj_ice_strans_init_ice(sess->callee.ice, sess->callee.cfg.role, |
| 697 |
&sess->callee.ufrag, &sess->callee.pass); |
| 698 |
if (rc != PJ_SUCCESS) { |
| 699 |
app_perror(INDENT "err: callee pj_ice_strans_init_ice()", rc); |
| 700 |
destroy_sess(sess, 500); |
| 701 |
return -110; |
| 702 |
} |
| 703 |
|
| 704 |
rc = start_ice(&sess->callee, &sess->caller); |
| 705 |
if (rc != PJ_SUCCESS) { |
| 706 |
int retval = (rc == sess->callee.cfg.expected.start_status)?0:-120; |
| 707 |
destroy_sess(sess, 500); |
| 708 |
return retval; |
| 709 |
} |
| 710 |
|
| 711 |
poll_events(stun_cfg, sess->callee.cfg.answer_delay, PJ_FALSE); |
| 712 |
|
| 713 |
rc = start_ice(&sess->caller, &sess->callee); |
| 714 |
if (rc != PJ_SUCCESS) { |
| 715 |
int retval = (rc == sess->caller.cfg.expected.start_status)?0:-130; |
| 716 |
destroy_sess(sess, 500); |
| 717 |
return retval; |
| 718 |
} |
| 719 |
|
| 720 |
for (i=0; i<sess->param->worker_cnt; ++i) { |
| 721 |
pj_status_t status; |
| 722 |
|
| 723 |
status = pj_thread_create(sess->pool, "worker_thread", |
| 724 |
worker_thread_proc, sess, 0, 0, |
| 725 |
&sess->worker_threads[i]); |
| 726 |
if (status != PJ_SUCCESS) { |
| 727 |
PJ_LOG(3,(THIS_FILE, INDENT "err: create thread")); |
| 728 |
destroy_sess(sess, 500); |
| 729 |
return -135; |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
if (sess->param->destroy_after_create) |
| 734 |
goto on_destroy; |
| 735 |
|
| 736 |
if (sess->param->destroy_after_one_done) { |
| 737 |
while (sess->caller.result.init_status==PJ_EPENDING && |
| 738 |
sess->callee.result.init_status==PJ_EPENDING) |
| 739 |
{ |
| 740 |
if (sess->param->worker_cnt) |
| 741 |
pj_thread_sleep(0); |
| 742 |
else |
| 743 |
poll_events(stun_cfg, 0, PJ_FALSE); |
| 744 |
} |
| 745 |
goto on_destroy; |
| 746 |
} |
| 747 |
|
| 748 |
WAIT_UNTIL(30000, ALL_DONE, rc); |
| 749 |
if (!ALL_DONE) { |
| 750 |
PJ_LOG(3,(THIS_FILE, INDENT "err: negotiation timed-out")); |
| 751 |
destroy_sess(sess, 500); |
| 752 |
return -140; |
| 753 |
} |
| 754 |
|
| 755 |
if (sess->caller.result.nego_status != sess->caller.cfg.expected.nego_status) { |
| 756 |
app_perror(INDENT "err: caller negotiation failed", sess->caller.result.nego_status); |
| 757 |
destroy_sess(sess, 500); |
| 758 |
return -150; |
| 759 |
} |
| 760 |
|
| 761 |
if (sess->callee.result.nego_status != sess->callee.cfg.expected.nego_status) { |
| 762 |
app_perror(INDENT "err: callee negotiation failed", sess->callee.result.nego_status); |
| 763 |
destroy_sess(sess, 500); |
| 764 |
return -160; |
| 765 |
} |
| 766 |
|
| 767 |
|
| 768 |
rc = check_pair(&sess->caller, &sess->callee, -170); |
| 769 |
if (rc != 0) { |
| 770 |
destroy_sess(sess, 500); |
| 771 |
return rc; |
| 772 |
} |
| 773 |
rc = check_pair(&sess->callee, &sess->caller, -180); |
| 774 |
if (rc != 0) { |
| 775 |
destroy_sess(sess, 500); |
| 776 |
return rc; |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
on_destroy: |
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
if (sess->caller.ice) { |
| 787 |
pj_ice_strans_destroy(sess->caller.ice); |
| 788 |
sess->caller.ice = NULL; |
| 789 |
} |
| 790 |
|
| 791 |
if (sess->callee.ice) { |
| 792 |
pj_ice_strans_destroy(sess->callee.ice); |
| 793 |
sess->callee.ice = NULL; |
| 794 |
} |
| 795 |
|
| 796 |
on_return: |
| 797 |
|
| 798 |
poll_events(stun_cfg, 200, PJ_FALSE); |
| 799 |
|
| 800 |
|
| 801 |
destroy_sess(sess, 500); |
| 802 |
|
| 803 |
|
| 804 |
poll_events(stun_cfg, 100, PJ_FALSE); |
| 805 |
|
| 806 |
rc = check_pjlib_state(stun_cfg, &pjlib_state); |
| 807 |
if (rc != 0) { |
| 808 |
return rc; |
| 809 |
} |
| 810 |
|
| 811 |
return rc; |
| 812 |
} |
| 813 |
|
| 814 |
static void set_client_server_flag(unsigned server_flag, |
| 815 |
unsigned caller_flag, |
| 816 |
unsigned callee_flag, |
| 817 |
unsigned *res_server_flag, |
| 818 |
unsigned *res_caller_flag, |
| 819 |
unsigned *res_callee_flag) |
| 820 |
{ |
| 821 |
enum { |
| 822 |
RST_CLT_FLAG = CLIENT_IPV4+CLIENT_IPV6, |
| 823 |
RST_SRV_FLAG = SERVER_IPV4+SERVER_IPV6 |
| 824 |
}; |
| 825 |
|
| 826 |
*res_server_flag = (*res_server_flag & ~RST_SRV_FLAG) | server_flag; |
| 827 |
*res_caller_flag = (*res_caller_flag & ~RST_CLT_FLAG) | caller_flag; |
| 828 |
*res_callee_flag = (*res_callee_flag & ~RST_CLT_FLAG) | callee_flag; |
| 829 |
} |
| 830 |
|
| 831 |
static int perform_test(const char *title, |
| 832 |
pj_stun_config *stun_cfg, |
| 833 |
unsigned server_flag, |
| 834 |
struct test_cfg *caller_cfg, |
| 835 |
struct test_cfg *callee_cfg) |
| 836 |
{ |
| 837 |
struct sess_param test_param; |
| 838 |
int rc; |
| 839 |
int expected_caller_start_ice = caller_cfg->expected.start_status; |
| 840 |
int expected_callee_start_ice = callee_cfg->expected.start_status; |
| 841 |
|
| 842 |
set_client_server_flag(SERVER_IPV4, CLIENT_IPV4, CLIENT_IPV4, |
| 843 |
&server_flag, &caller_cfg->client_flag, |
| 844 |
&callee_cfg->client_flag); |
| 845 |
|
| 846 |
|
| 847 |
pj_bzero(&test_param, sizeof(test_param)); |
| 848 |
|
| 849 |
rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, |
| 850 |
callee_cfg, &test_param); |
| 851 |
|
| 852 |
#if USE_IPV6 |
| 853 |
if (enable_ipv6_test()) { |
| 854 |
|
| 855 |
|
| 856 |
if (rc == PJ_SUCCESS) { |
| 857 |
pj_bzero(&test_param, sizeof(test_param)); |
| 858 |
set_client_server_flag(SERVER_IPV6, CLIENT_IPV6, CLIENT_IPV6, |
| 859 |
&server_flag, &caller_cfg->client_flag, |
| 860 |
&callee_cfg->client_flag); |
| 861 |
|
| 862 |
rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, |
| 863 |
callee_cfg, &test_param); |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
if (rc == PJ_SUCCESS) { |
| 868 |
pj_bzero(&test_param, sizeof(test_param)); |
| 869 |
set_client_server_flag(SERVER_IPV4+SERVER_IPV6, |
| 870 |
CLIENT_IPV4+CLIENT_IPV6, |
| 871 |
CLIENT_IPV4+CLIENT_IPV6, |
| 872 |
&server_flag, |
| 873 |
&caller_cfg->client_flag, |
| 874 |
&callee_cfg->client_flag); |
| 875 |
|
| 876 |
rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, |
| 877 |
callee_cfg, &test_param); |
| 878 |
} |
| 879 |
|
| 880 |
|
| 881 |
if (rc == PJ_SUCCESS) { |
| 882 |
pj_bzero(&test_param, sizeof(test_param)); |
| 883 |
set_client_server_flag(SERVER_IPV4+SERVER_IPV6, |
| 884 |
CLIENT_IPV4, |
| 885 |
CLIENT_IPV6, |
| 886 |
&server_flag, |
| 887 |
&caller_cfg->client_flag, |
| 888 |
&callee_cfg->client_flag); |
| 889 |
caller_cfg->expected.start_status = PJ_ENOTFOUND; |
| 890 |
callee_cfg->expected.start_status = PJ_ENOTFOUND; |
| 891 |
|
| 892 |
rc = perform_test2(title, stun_cfg, server_flag, caller_cfg, |
| 893 |
callee_cfg, &test_param); |
| 894 |
} |
| 895 |
} |
| 896 |
#endif |
| 897 |
callee_cfg->expected.start_status = expected_callee_start_ice; |
| 898 |
caller_cfg->expected.start_status = expected_caller_start_ice; |
| 899 |
|
| 900 |
return rc; |
| 901 |
} |
| 902 |
|
| 903 |
#define ROLE1 PJ_ICE_SESS_ROLE_CONTROLLED |
| 904 |
#define ROLE2 PJ_ICE_SESS_ROLE_CONTROLLING |
| 905 |
|
| 906 |
int ice_test(void *p) |
| 907 |
{ |
| 908 |
unsigned test_id = (unsigned)(uintptr_t)p; |
| 909 |
app_sess_t app_sess; |
| 910 |
unsigned i; |
| 911 |
int rc; |
| 912 |
struct sess_cfg_t { |
| 913 |
const char *title; |
| 914 |
unsigned server_flag; |
| 915 |
struct test_cfg ua1; |
| 916 |
struct test_cfg ua2; |
| 917 |
} sess_cfg[ICE_TEST_ARRAY_COUNT] = |
| 918 |
{ |
| 919 |
|
| 920 |
{ |
| 921 |
"hosts candidates only", |
| 922 |
0x1FFF, |
| 923 |
{ROLE1, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 924 |
{ROLE2, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 925 |
}, |
| 926 |
{ |
| 927 |
"host and srflxes", |
| 928 |
0x1FFF, |
| 929 |
{ROLE1, 1, YES, YES, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 930 |
{ROLE2, 1, YES, YES, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 931 |
}, |
| 932 |
{ |
| 933 |
"host vs relay", |
| 934 |
0x1FFF, |
| 935 |
{ROLE1, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 936 |
{ROLE2, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 937 |
}, |
| 938 |
{ |
| 939 |
"relay vs host", |
| 940 |
0x1FFF, |
| 941 |
{ROLE1, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 942 |
{ROLE2, 1, YES, NO, NO, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 943 |
}, |
| 944 |
{ |
| 945 |
"relay vs relay", |
| 946 |
0x1FFF, |
| 947 |
{ROLE1, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 948 |
{ROLE2, 1, NO, NO, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 949 |
}, |
| 950 |
{ |
| 951 |
"all candidates", |
| 952 |
0x1FFF, |
| 953 |
{ROLE1, 1, YES, YES, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 954 |
{ROLE2, 1, YES, YES, YES, NO, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 955 |
}, |
| 956 |
}; |
| 957 |
|
| 958 |
assert(test_id < ICE_TEST_START_ARRAY+PJ_ARRAY_SIZE(sess_cfg)); |
| 959 |
|
| 960 |
rc = create_stun_config(&app_sess); |
| 961 |
if (rc != PJ_SUCCESS) |
| 962 |
return -7; |
| 963 |
|
| 964 |
|
| 965 |
if (test_id==ICE_TEST_BASIC_HOST) { |
| 966 |
struct sess_cfg_t cfg = |
| 967 |
{ |
| 968 |
"Basic with host candidates", |
| 969 |
0x0, |
| 970 |
|
| 971 |
{ROLE1, 1, YES, NO, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 972 |
{ROLE2, 1, YES, NO, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 973 |
}; |
| 974 |
|
| 975 |
rc = perform_test(cfg.title, &app_sess.stun_cfg, cfg.server_flag, |
| 976 |
&cfg.ua1, &cfg.ua2); |
| 977 |
if (rc != 0) |
| 978 |
goto on_return; |
| 979 |
|
| 980 |
cfg.ua1.comp_cnt = 2; |
| 981 |
cfg.ua2.comp_cnt = 2; |
| 982 |
rc = perform_test("Basic with host candidates, 2 components", |
| 983 |
&app_sess.stun_cfg, cfg.server_flag, |
| 984 |
&cfg.ua1, &cfg.ua2); |
| 985 |
if (rc != 0) |
| 986 |
goto on_return; |
| 987 |
} |
| 988 |
|
| 989 |
|
| 990 |
if (test_id==ICE_TEST_BASIC_SRFLX) { |
| 991 |
struct sess_cfg_t cfg = |
| 992 |
{ |
| 993 |
"Basic with srflx candidates", |
| 994 |
0xFFFF, |
| 995 |
|
| 996 |
{ROLE1, 1, YES, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 997 |
{ROLE2, 1, YES, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 998 |
}; |
| 999 |
|
| 1000 |
rc = perform_test(cfg.title, &app_sess.stun_cfg, cfg.server_flag, |
| 1001 |
&cfg.ua1, &cfg.ua2); |
| 1002 |
if (rc != 0) |
| 1003 |
goto on_return; |
| 1004 |
|
| 1005 |
cfg.ua1.comp_cnt = 2; |
| 1006 |
cfg.ua2.comp_cnt = 2; |
| 1007 |
|
| 1008 |
rc = perform_test("Basic with srflx candidates, 2 components", |
| 1009 |
&app_sess.stun_cfg, cfg.server_flag, |
| 1010 |
&cfg.ua1, &cfg.ua2); |
| 1011 |
if (rc != 0) |
| 1012 |
goto on_return; |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
if (test_id==ICE_TEST_BASIC_RELAY) { |
| 1017 |
struct sess_cfg_t cfg = |
| 1018 |
{ |
| 1019 |
"Basic with relay candidates", |
| 1020 |
0xFFFF, |
| 1021 |
|
| 1022 |
{ROLE1, 1, NO, NO, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 1023 |
{ROLE2, 1, NO, NO, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 1024 |
}; |
| 1025 |
|
| 1026 |
rc = perform_test(cfg.title, &app_sess.stun_cfg, cfg.server_flag, |
| 1027 |
&cfg.ua1, &cfg.ua2); |
| 1028 |
if (rc != 0) |
| 1029 |
goto on_return; |
| 1030 |
|
| 1031 |
cfg.ua1.comp_cnt = 2; |
| 1032 |
cfg.ua2.comp_cnt = 2; |
| 1033 |
|
| 1034 |
rc = perform_test("Basic with relay candidates, 2 components", |
| 1035 |
&app_sess.stun_cfg, cfg.server_flag, |
| 1036 |
&cfg.ua1, &cfg.ua2); |
| 1037 |
if (rc != 0) |
| 1038 |
goto on_return; |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
if (test_id==ICE_TEST_STUN_RES_FAIL) { |
| 1043 |
struct sess_cfg_t cfg = |
| 1044 |
{ |
| 1045 |
"STUN resolution failure", |
| 1046 |
0x0, |
| 1047 |
|
| 1048 |
{ROLE1, 2, NO, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJNATH_ESTUNTIMEDOUT, -1}}, |
| 1049 |
{ROLE2, 2, NO, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJNATH_ESTUNTIMEDOUT, -1}} |
| 1050 |
}; |
| 1051 |
|
| 1052 |
rc = perform_test(cfg.title, &app_sess.stun_cfg, cfg.server_flag, |
| 1053 |
&cfg.ua1, &cfg.ua2); |
| 1054 |
if (rc != 0) |
| 1055 |
goto on_return; |
| 1056 |
|
| 1057 |
cfg.ua1.client_flag |= DEL_ON_ERR; |
| 1058 |
cfg.ua2.client_flag |= DEL_ON_ERR; |
| 1059 |
|
| 1060 |
rc = perform_test("STUN resolution failure with destroy on callback", |
| 1061 |
&app_sess.stun_cfg, cfg.server_flag, |
| 1062 |
&cfg.ua1, &cfg.ua2); |
| 1063 |
if (rc != 0) |
| 1064 |
goto on_return; |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
if (test_id==ICE_TEST_TURN_ALLOC_FAIL) { |
| 1069 |
struct sess_cfg_t cfg = |
| 1070 |
{ |
| 1071 |
"TURN allocation failure", |
| 1072 |
0xFFFF, |
| 1073 |
|
| 1074 |
{ROLE1, 2, NO, NO, YES, WRONG_TURN, 0, 0, 0, {PJ_SUCCESS, PJ_STATUS_FROM_STUN_CODE(401), -1}}, |
| 1075 |
{ROLE2, 2, NO, NO, YES, WRONG_TURN, 0, 0, 0, {PJ_SUCCESS, PJ_STATUS_FROM_STUN_CODE(401), -1}} |
| 1076 |
}; |
| 1077 |
|
| 1078 |
rc = perform_test(cfg.title, &app_sess.stun_cfg, cfg.server_flag, |
| 1079 |
&cfg.ua1, &cfg.ua2); |
| 1080 |
if (rc != 0) |
| 1081 |
goto on_return; |
| 1082 |
|
| 1083 |
cfg.ua1.client_flag |= DEL_ON_ERR; |
| 1084 |
cfg.ua2.client_flag |= DEL_ON_ERR; |
| 1085 |
|
| 1086 |
rc = perform_test("TURN allocation failure with destroy on callback", |
| 1087 |
&app_sess.stun_cfg, cfg.server_flag, |
| 1088 |
&cfg.ua1, &cfg.ua2); |
| 1089 |
if (rc != 0) |
| 1090 |
goto on_return; |
| 1091 |
} |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
if (test_id==ICE_TEST_STUN_FAIL_TURN_DEALLOC) { |
| 1096 |
struct sess_cfg_t cfg = |
| 1097 |
{ |
| 1098 |
"STUN failure, testing TURN deallocation", |
| 1099 |
0xFFFF & (~(CREATE_STUN_SERVER)), |
| 1100 |
|
| 1101 |
{ROLE1, 1, YES, YES, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJNATH_ESTUNTIMEDOUT, -1}}, |
| 1102 |
{ROLE2, 1, YES, YES, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJNATH_ESTUNTIMEDOUT, -1}} |
| 1103 |
}; |
| 1104 |
|
| 1105 |
rc = perform_test(cfg.title, &app_sess.stun_cfg, cfg.server_flag, |
| 1106 |
&cfg.ua1, &cfg.ua2); |
| 1107 |
if (rc != 0) |
| 1108 |
goto on_return; |
| 1109 |
|
| 1110 |
cfg.ua1.client_flag |= DEL_ON_ERR; |
| 1111 |
cfg.ua2.client_flag |= DEL_ON_ERR; |
| 1112 |
|
| 1113 |
rc = perform_test("STUN failure, testing TURN deallocation (cb)", |
| 1114 |
&app_sess.stun_cfg, cfg.server_flag, |
| 1115 |
&cfg.ua1, &cfg.ua2); |
| 1116 |
if (rc != 0) |
| 1117 |
goto on_return; |
| 1118 |
} |
| 1119 |
|
| 1120 |
rc = 0; |
| 1121 |
if (test_id >= ICE_TEST_START_ARRAY) { |
| 1122 |
struct sess_cfg_t *cfg; |
| 1123 |
unsigned delay[] = { 50, 2000 }; |
| 1124 |
unsigned d; |
| 1125 |
|
| 1126 |
i = test_id - ICE_TEST_START_ARRAY; |
| 1127 |
cfg = &sess_cfg[i]; |
| 1128 |
|
| 1129 |
PJ_LOG(3,(THIS_FILE, " %s", cfg->title)); |
| 1130 |
|
| 1131 |
|
| 1132 |
for (d=0; d<PJ_ARRAY_SIZE(delay); ++d) { |
| 1133 |
struct role_t { |
| 1134 |
pj_ice_sess_role ua1; |
| 1135 |
pj_ice_sess_role ua2; |
| 1136 |
} role[] = |
| 1137 |
{ |
| 1138 |
{ ROLE1, ROLE2}, |
| 1139 |
{ ROLE2, ROLE1}, |
| 1140 |
{ ROLE1, ROLE1}, |
| 1141 |
{ ROLE2, ROLE2} |
| 1142 |
}; |
| 1143 |
unsigned j; |
| 1144 |
|
| 1145 |
cfg->ua1.answer_delay = delay[d]; |
| 1146 |
cfg->ua2.answer_delay = delay[d]; |
| 1147 |
|
| 1148 |
|
| 1149 |
for (j=0; j<PJ_ARRAY_SIZE(role); ++j) { |
| 1150 |
unsigned k1; |
| 1151 |
|
| 1152 |
cfg->ua1.role = role[j].ua1; |
| 1153 |
cfg->ua2.role = role[j].ua2; |
| 1154 |
|
| 1155 |
|
| 1156 |
for (k1=1; k1<=2; ++k1) { |
| 1157 |
unsigned k2; |
| 1158 |
|
| 1159 |
cfg->ua1.comp_cnt = k1; |
| 1160 |
|
| 1161 |
for (k2=1; k2<=2; ++k2) { |
| 1162 |
char title[120]; |
| 1163 |
|
| 1164 |
pj_ansi_snprintf(title, sizeof(title), |
| 1165 |
"%s/%s, %dms answer delay, %d vs %d components", |
| 1166 |
pj_ice_sess_role_name(role[j].ua1), |
| 1167 |
pj_ice_sess_role_name(role[j].ua2), |
| 1168 |
delay[d], k1, k2); |
| 1169 |
|
| 1170 |
cfg->ua2.comp_cnt = k2; |
| 1171 |
rc = perform_test(title, &app_sess.stun_cfg, cfg->server_flag, |
| 1172 |
&cfg->ua1, &cfg->ua2); |
| 1173 |
if (rc != 0) |
| 1174 |
goto on_return; |
| 1175 |
} |
| 1176 |
} |
| 1177 |
} |
| 1178 |
} |
| 1179 |
} |
| 1180 |
|
| 1181 |
on_return: |
| 1182 |
destroy_stun_config(&app_sess); |
| 1183 |
return rc; |
| 1184 |
} |
| 1185 |
|
| 1186 |
int ice_one_conc_test(pj_stun_config *stun_cfg, int err_quit) |
| 1187 |
{ |
| 1188 |
struct sess_cfg_t { |
| 1189 |
const char *title; |
| 1190 |
unsigned server_flag; |
| 1191 |
struct test_cfg ua1; |
| 1192 |
struct test_cfg ua2; |
| 1193 |
} cfg = |
| 1194 |
{ |
| 1195 |
"Concurrency test", |
| 1196 |
0x1FFF, |
| 1197 |
|
| 1198 |
{ROLE1, 1, YES, YES, YES, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 1199 |
{ROLE2, 1, YES, YES, YES, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 1200 |
}; |
| 1201 |
struct sess_param test_param; |
| 1202 |
int rc; |
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
cfg.title = " ice test a: immediate destroy"; |
| 1207 |
pj_bzero(&test_param, sizeof(test_param)); |
| 1208 |
test_param.worker_cnt = 4; |
| 1209 |
test_param.worker_timeout = 1000; |
| 1210 |
test_param.destroy_after_create = PJ_TRUE; |
| 1211 |
|
| 1212 |
rc = perform_test2(cfg.title, stun_cfg, cfg.server_flag, |
| 1213 |
&cfg.ua1, &cfg.ua2, &test_param); |
| 1214 |
if (rc != 0 && err_quit) |
| 1215 |
return rc; |
| 1216 |
|
| 1217 |
|
| 1218 |
cfg.title = " ice test b: destroy after 1 success"; |
| 1219 |
test_param.destroy_after_create = PJ_FALSE; |
| 1220 |
test_param.destroy_after_one_done = PJ_TRUE; |
| 1221 |
|
| 1222 |
rc = perform_test2(cfg.title, stun_cfg, cfg.server_flag, |
| 1223 |
&cfg.ua1, &cfg.ua2, &test_param); |
| 1224 |
if (rc != 0 && err_quit) |
| 1225 |
return rc; |
| 1226 |
|
| 1227 |
|
| 1228 |
cfg.title = " ice test c: normal flow"; |
| 1229 |
pj_bzero(&test_param, sizeof(test_param)); |
| 1230 |
test_param.worker_cnt = 4; |
| 1231 |
test_param.worker_timeout = 1000; |
| 1232 |
|
| 1233 |
rc = perform_test2(cfg.title, stun_cfg, cfg.server_flag, |
| 1234 |
&cfg.ua1, &cfg.ua2, &test_param); |
| 1235 |
if (rc != 0 && err_quit) |
| 1236 |
return rc; |
| 1237 |
|
| 1238 |
return 0; |
| 1239 |
} |
| 1240 |
|
| 1241 |
int ice_conc_test(void) |
| 1242 |
{ |
| 1243 |
const unsigned LOOP = 20; |
| 1244 |
app_sess_t app_sess; |
| 1245 |
unsigned i; |
| 1246 |
int rc; |
| 1247 |
|
| 1248 |
rc = create_stun_config(&app_sess); |
| 1249 |
if (rc != PJ_SUCCESS) { |
| 1250 |
return -7; |
| 1251 |
} |
| 1252 |
|
| 1253 |
for (i = 0; i < LOOP; i++) { |
| 1254 |
PJ_LOG(3,(THIS_FILE, INDENT "Test %d of %d", i+1, LOOP)); |
| 1255 |
rc = ice_one_conc_test(&app_sess.stun_cfg, PJ_TRUE); |
| 1256 |
if (rc) |
| 1257 |
break; |
| 1258 |
} |
| 1259 |
|
| 1260 |
|
| 1261 |
goto on_return; |
| 1262 |
|
| 1263 |
on_return: |
| 1264 |
destroy_stun_config(&app_sess); |
| 1265 |
|
| 1266 |
return rc; |
| 1267 |
} |
| 1268 |
|
| 1269 |
struct timer_data |
| 1270 |
{ |
| 1271 |
struct test_sess *sess; |
| 1272 |
unsigned caller_last_cand_cnt[PJ_ICE_MAX_COMP]; |
| 1273 |
unsigned callee_last_cand_cnt[PJ_ICE_MAX_COMP]; |
| 1274 |
}; |
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
static void timer_new_cand(pj_timer_heap_t *th, pj_timer_entry *te) |
| 1279 |
{ |
| 1280 |
struct timer_data *data = (struct timer_data*)te->user_data; |
| 1281 |
struct test_sess *sess = data->sess; |
| 1282 |
struct ice_ept *caller = &sess->caller; |
| 1283 |
struct ice_ept *callee = &sess->callee; |
| 1284 |
pj_bool_t caller_last_cand, callee_last_cand; |
| 1285 |
unsigned i, ncomp; |
| 1286 |
pj_status_t rc; |
| 1287 |
|
| 1288 |
|
| 1289 |
if (!caller->ice || !callee->ice) |
| 1290 |
return; |
| 1291 |
|
| 1292 |
caller_last_cand = caller->last_cand; |
| 1293 |
callee_last_cand = callee->last_cand; |
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
ncomp = PJ_MIN(caller->cfg.comp_cnt, callee->cfg.comp_cnt); |
| 1298 |
for (i = 0; i < ncomp; ++i) { |
| 1299 |
pj_ice_sess_cand cand[PJ_ICE_ST_MAX_CAND]; |
| 1300 |
unsigned j, cnt; |
| 1301 |
|
| 1302 |
|
| 1303 |
cnt = PJ_ICE_ST_MAX_CAND; |
| 1304 |
rc = pj_ice_strans_enum_cands(caller->ice, i+1, &cnt, cand); |
| 1305 |
if (rc != PJ_SUCCESS) { |
| 1306 |
app_perror(INDENT "err: caller pj_ice_strans_enum_cands()", rc); |
| 1307 |
continue; |
| 1308 |
} |
| 1309 |
|
| 1310 |
if (cnt > data->caller_last_cand_cnt[i]) { |
| 1311 |
unsigned new_cnt = cnt - data->caller_last_cand_cnt[i]; |
| 1312 |
|
| 1313 |
|
| 1314 |
rc = pj_ice_strans_update_check_list(callee->ice, |
| 1315 |
&caller->ufrag, |
| 1316 |
&caller->pass, |
| 1317 |
new_cnt, &cand[cnt - new_cnt], |
| 1318 |
caller_last_cand && (i==ncomp-1)); |
| 1319 |
if (rc != PJ_SUCCESS) { |
| 1320 |
app_perror(INDENT "err: callee pj_ice_strans_update_check_list()", rc); |
| 1321 |
continue; |
| 1322 |
} |
| 1323 |
|
| 1324 |
data->caller_last_cand_cnt[i] = cnt; |
| 1325 |
PJ_LOG(4,(THIS_FILE, INDENT "Updated callee with %d new candidates %s", |
| 1326 |
new_cnt, (caller_last_cand?"(last)":""))); |
| 1327 |
|
| 1328 |
for (j = 0; j < new_cnt; ++j) { |
| 1329 |
pj_ice_sess_cand *c = &cand[cnt - new_cnt + j]; |
| 1330 |
char buf1[PJ_INET6_ADDRSTRLEN+10]; |
| 1331 |
char buf2[PJ_INET6_ADDRSTRLEN+10]; |
| 1332 |
PJ_LOG(4,(THIS_FILE, INDENT |
| 1333 |
"%d: comp=%d, type=%s, addr=%s, baseaddr=%s", |
| 1334 |
j+1, c->comp_id, |
| 1335 |
pj_ice_get_cand_type_name(c->type), |
| 1336 |
pj_sockaddr_print(&c->addr, buf1, sizeof(buf1), 3), |
| 1337 |
pj_sockaddr_print(&c->base_addr, buf2, sizeof(buf2), 3) |
| 1338 |
)); |
| 1339 |
} |
| 1340 |
} |
| 1341 |
|
| 1342 |
|
| 1343 |
cnt = PJ_ICE_ST_MAX_CAND; |
| 1344 |
rc = pj_ice_strans_enum_cands(callee->ice, i+1, &cnt, cand); |
| 1345 |
if (rc != PJ_SUCCESS) { |
| 1346 |
app_perror(INDENT "err: caller pj_ice_strans_enum_cands()", rc); |
| 1347 |
continue; |
| 1348 |
} |
| 1349 |
|
| 1350 |
if (cnt > data->callee_last_cand_cnt[i]) { |
| 1351 |
unsigned new_cnt = cnt - data->callee_last_cand_cnt[i]; |
| 1352 |
|
| 1353 |
|
| 1354 |
rc = pj_ice_strans_update_check_list(caller->ice, |
| 1355 |
&callee->ufrag, |
| 1356 |
&callee->pass, |
| 1357 |
new_cnt, &cand[cnt - new_cnt], |
| 1358 |
callee_last_cand && (i==ncomp-1)); |
| 1359 |
if (rc != PJ_SUCCESS) { |
| 1360 |
app_perror(INDENT "err: caller pj_ice_strans_update_check_list()", rc); |
| 1361 |
continue; |
| 1362 |
} |
| 1363 |
|
| 1364 |
data->callee_last_cand_cnt[i] = cnt; |
| 1365 |
PJ_LOG(4,(THIS_FILE, INDENT "Updated caller with %d new candidates %s", |
| 1366 |
new_cnt, (callee_last_cand?"(last)":""))); |
| 1367 |
|
| 1368 |
for (j = 0; j < new_cnt; ++j) { |
| 1369 |
pj_ice_sess_cand *c = &cand[cnt - new_cnt + j]; |
| 1370 |
char buf1[PJ_INET6_ADDRSTRLEN+10]; |
| 1371 |
char buf2[PJ_INET6_ADDRSTRLEN+10]; |
| 1372 |
PJ_LOG(4,(THIS_FILE, INDENT |
| 1373 |
"%d: comp=%d, type=%s, addr=%s, baseaddr=%s", |
| 1374 |
j+1, c->comp_id, |
| 1375 |
pj_ice_get_cand_type_name(c->type), |
| 1376 |
pj_sockaddr_print(&c->addr, buf1, sizeof(buf1), 3), |
| 1377 |
pj_sockaddr_print(&c->base_addr, buf2, sizeof(buf2), 3) |
| 1378 |
)); |
| 1379 |
} |
| 1380 |
} |
| 1381 |
} |
| 1382 |
|
| 1383 |
if (!caller_last_cand || !callee_last_cand) { |
| 1384 |
|
| 1385 |
pj_time_val timeout = {0, 10}; |
| 1386 |
pj_time_val_normalize(&timeout); |
| 1387 |
pj_timer_heap_schedule(th, te, &timeout); |
| 1388 |
|
| 1389 |
} |
| 1390 |
} |
| 1391 |
|
| 1392 |
|
| 1393 |
static int perform_trickle_test(const char *title, |
| 1394 |
pj_stun_config *stun_cfg, |
| 1395 |
unsigned server_flag, |
| 1396 |
struct test_cfg *caller_cfg, |
| 1397 |
struct test_cfg *callee_cfg, |
| 1398 |
struct sess_param *test_param) |
| 1399 |
{ |
| 1400 |
pjlib_state pjlib_state; |
| 1401 |
struct test_sess *sess; |
| 1402 |
struct timer_data timer_data; |
| 1403 |
pj_timer_entry te_new_cand; |
| 1404 |
int rc; |
| 1405 |
|
| 1406 |
PJ_LOG(3,(THIS_FILE, "%s, %d vs %d components", |
| 1407 |
title, caller_cfg->comp_cnt, callee_cfg->comp_cnt)); |
| 1408 |
|
| 1409 |
capture_pjlib_state(stun_cfg, &pjlib_state); |
| 1410 |
|
| 1411 |
rc = create_sess(stun_cfg, server_flag, caller_cfg, callee_cfg, |
| 1412 |
test_param, &sess); |
| 1413 |
if (rc != 0) |
| 1414 |
return rc; |
| 1415 |
|
| 1416 |
|
| 1417 |
rc = pj_ice_strans_init_ice(sess->caller.ice, sess->caller.cfg.role, |
| 1418 |
&sess->caller.ufrag, &sess->caller.pass); |
| 1419 |
if (rc != PJ_SUCCESS) { |
| 1420 |
app_perror(INDENT "err: caller pj_ice_strans_init_ice()", rc); |
| 1421 |
rc = -100; |
| 1422 |
goto on_return; |
| 1423 |
} |
| 1424 |
|
| 1425 |
|
| 1426 |
rc = pj_ice_strans_init_ice(sess->callee.ice, sess->callee.cfg.role, |
| 1427 |
&sess->callee.ufrag, &sess->callee.pass); |
| 1428 |
if (rc != PJ_SUCCESS) { |
| 1429 |
app_perror(INDENT "err: callee pj_ice_strans_init_ice()", rc); |
| 1430 |
rc = -110; |
| 1431 |
goto on_return; |
| 1432 |
} |
| 1433 |
|
| 1434 |
|
| 1435 |
rc = start_ice(&sess->callee, &sess->caller); |
| 1436 |
if (rc != PJ_SUCCESS) { |
| 1437 |
int retval = (rc == sess->callee.cfg.expected.start_status)?0:-120; |
| 1438 |
rc = retval; |
| 1439 |
goto on_return; |
| 1440 |
} |
| 1441 |
|
| 1442 |
|
| 1443 |
rc = start_ice(&sess->caller, &sess->callee); |
| 1444 |
if (rc != PJ_SUCCESS) { |
| 1445 |
int retval = (rc == sess->caller.cfg.expected.start_status)?0:-130; |
| 1446 |
rc = retval; |
| 1447 |
goto on_return; |
| 1448 |
} |
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
{ |
| 1453 |
pj_time_val timeout = {0, 10}; |
| 1454 |
|
| 1455 |
pj_bzero(&timer_data, sizeof(timer_data)); |
| 1456 |
timer_data.sess = sess; |
| 1457 |
|
| 1458 |
pj_time_val_normalize(&timeout); |
| 1459 |
pj_timer_entry_init(&te_new_cand, 0, &timer_data, &timer_new_cand); |
| 1460 |
pj_timer_heap_schedule(stun_cfg->timer_heap, &te_new_cand, &timeout); |
| 1461 |
} |
| 1462 |
|
| 1463 |
WAIT_UNTIL(30000, ALL_DONE, rc); |
| 1464 |
if (!ALL_DONE) { |
| 1465 |
PJ_LOG(3,(THIS_FILE, INDENT "err: negotiation timed-out")); |
| 1466 |
rc = -140; |
| 1467 |
goto on_return; |
| 1468 |
} |
| 1469 |
|
| 1470 |
if (rc != 0) |
| 1471 |
goto on_return; |
| 1472 |
|
| 1473 |
if (sess->caller.result.nego_status != sess->caller.cfg.expected.nego_status) { |
| 1474 |
app_perror(INDENT "err: caller negotiation failed", sess->caller.result.nego_status); |
| 1475 |
rc = -150; |
| 1476 |
goto on_return; |
| 1477 |
} |
| 1478 |
|
| 1479 |
if (sess->callee.result.nego_status != sess->callee.cfg.expected.nego_status) { |
| 1480 |
app_perror(INDENT "err: callee negotiation failed", sess->callee.result.nego_status); |
| 1481 |
rc = -160; |
| 1482 |
goto on_return; |
| 1483 |
} |
| 1484 |
|
| 1485 |
|
| 1486 |
rc = check_pair(&sess->caller, &sess->callee, -170); |
| 1487 |
if (rc != 0) { |
| 1488 |
goto on_return; |
| 1489 |
} |
| 1490 |
rc = check_pair(&sess->callee, &sess->caller, -180); |
| 1491 |
if (rc != 0) { |
| 1492 |
goto on_return; |
| 1493 |
} |
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
if (sess->caller.ice) { |
| 1502 |
pj_ice_strans_destroy(sess->caller.ice); |
| 1503 |
sess->caller.ice = NULL; |
| 1504 |
} |
| 1505 |
|
| 1506 |
if (sess->callee.ice) { |
| 1507 |
pj_ice_strans_destroy(sess->callee.ice); |
| 1508 |
sess->callee.ice = NULL; |
| 1509 |
} |
| 1510 |
|
| 1511 |
on_return: |
| 1512 |
|
| 1513 |
poll_events(stun_cfg, 200, PJ_FALSE); |
| 1514 |
|
| 1515 |
|
| 1516 |
destroy_sess(sess, 500); |
| 1517 |
|
| 1518 |
|
| 1519 |
poll_events(stun_cfg, 100, PJ_FALSE); |
| 1520 |
|
| 1521 |
if (rc == 0) |
| 1522 |
rc = check_pjlib_state(stun_cfg, &pjlib_state); |
| 1523 |
|
| 1524 |
return rc; |
| 1525 |
} |
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
int trickle_ice_test(void) |
| 1530 |
{ |
| 1531 |
app_sess_t app_sess; |
| 1532 |
struct sess_param test_param; |
| 1533 |
unsigned i; |
| 1534 |
int rc; |
| 1535 |
|
| 1536 |
struct sess_cfg_t { |
| 1537 |
const char *title; |
| 1538 |
unsigned server_flag; |
| 1539 |
struct test_cfg ua1; |
| 1540 |
struct test_cfg ua2; |
| 1541 |
} cfg[] = { |
| 1542 |
{ |
| 1543 |
"With host-only", |
| 1544 |
0x1FFF, |
| 1545 |
|
| 1546 |
{ROLE1, 1, YES, NO, NO, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 1547 |
{ROLE2, 1, YES, NO, NO, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 1548 |
}, |
| 1549 |
{ |
| 1550 |
"With turn-only", |
| 1551 |
0x1FFF, |
| 1552 |
|
| 1553 |
{ROLE1, 1, NO, NO, YES, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 1554 |
{ROLE2, 1, NO, NO, YES, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 1555 |
}, |
| 1556 |
{ |
| 1557 |
|
| 1558 |
"With host+turn", |
| 1559 |
0x1FFF, |
| 1560 |
|
| 1561 |
{ROLE1, 1, YES, YES, YES, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}}, |
| 1562 |
{ROLE2, 1, YES, YES, YES, CLIENT_IPV4, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS, PJ_SUCCESS}} |
| 1563 |
}}; |
| 1564 |
|
| 1565 |
PJ_LOG(3,(THIS_FILE, "Trickle ICE")); |
| 1566 |
pj_log_push_indent(); |
| 1567 |
|
| 1568 |
rc = create_stun_config(&app_sess); |
| 1569 |
if (rc != PJ_SUCCESS) { |
| 1570 |
pj_log_pop_indent(); |
| 1571 |
return -10; |
| 1572 |
} |
| 1573 |
|
| 1574 |
for (i = 0; i < PJ_ARRAY_SIZE(cfg) && !rc; ++i) { |
| 1575 |
unsigned c1, c2; |
| 1576 |
cfg[i].ua1.trickle = PJ_ICE_SESS_TRICKLE_FULL; |
| 1577 |
cfg[i].ua2.trickle = PJ_ICE_SESS_TRICKLE_FULL; |
| 1578 |
for (c1 = 1; c1 <= 2 && !rc; ++c1) { |
| 1579 |
for (c2 = 1; c2 <= 2 && !rc; ++c2) { |
| 1580 |
pj_bzero(&test_param, sizeof(test_param)); |
| 1581 |
cfg[i].ua1.comp_cnt = c1; |
| 1582 |
cfg[i].ua2.comp_cnt = c2; |
| 1583 |
rc = perform_trickle_test(cfg[i].title, |
| 1584 |
&app_sess.stun_cfg, |
| 1585 |
cfg[i].server_flag, |
| 1586 |
&cfg[i].ua1, |
| 1587 |
&cfg[i].ua2, |
| 1588 |
&test_param); |
| 1589 |
} |
| 1590 |
} |
| 1591 |
} |
| 1592 |
|
| 1593 |
destroy_stun_config(&app_sess); |
| 1594 |
pj_log_pop_indent(); |
| 1595 |
|
| 1596 |
return rc; |
| 1597 |
} |