| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include "test.h" |
| 21 |
#include <pjsip.h> |
| 22 |
#include <pjlib.h> |
| 23 |
|
| 24 |
#define THIS_FILE "tsx_uas_test.c" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
#define TEST1_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test01") |
| 98 |
#define TEST2_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test02") |
| 99 |
#define TEST3_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test03") |
| 100 |
#define TEST4_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test04") |
| 101 |
#define TEST5_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test05") |
| 102 |
#define TEST6_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test06") |
| 103 |
#define TEST7_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test07") |
| 104 |
#define TEST8_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test08") |
| 105 |
#define TEST9_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test09") |
| 106 |
#define TEST10_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test10") |
| 107 |
#define TEST11_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test11") |
| 108 |
#define TEST12_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test12") |
| 109 |
|
| 110 |
|
| 111 |
#define BRANCH_LEN (7+11) |
| 112 |
|
| 113 |
#define TEST1_STATUS_CODE 200 |
| 114 |
#define TEST2_STATUS_CODE 301 |
| 115 |
#define TEST3_PROVISIONAL_CODE PJSIP_SC_QUEUED |
| 116 |
#define TEST3_STATUS_CODE 202 |
| 117 |
#define TEST4_STATUS_CODE 200 |
| 118 |
#define TEST4_REQUEST_COUNT 2 |
| 119 |
#define TEST5_PROVISIONAL_CODE 100 |
| 120 |
#define TEST5_STATUS_CODE 200 |
| 121 |
#define TEST5_REQUEST_COUNT 2 |
| 122 |
#define TEST5_RESPONSE_COUNT 2 |
| 123 |
#define TEST6_PROVISIONAL_CODE 100 |
| 124 |
#define TEST6_STATUS_CODE 200 |
| 125 |
#define TEST6_REQUEST_COUNT 2 |
| 126 |
#define TEST6_RESPONSE_COUNT 3 |
| 127 |
#define TEST7_STATUS_CODE 301 |
| 128 |
#define TEST8_STATUS_CODE 302 |
| 129 |
#define TEST9_STATUS_CODE 301 |
| 130 |
|
| 131 |
|
| 132 |
#define TEST4_TITLE "test4: absorbing request retransmission" |
| 133 |
#define TEST5_TITLE "test5: retransmit last response in PROCEEDING state" |
| 134 |
#define TEST6_TITLE "test6: retransmit last response in COMPLETED state" |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
static struct tsx_uas_test_global_t |
| 140 |
{ |
| 141 |
char TARGET_URI[128]; |
| 142 |
char FROM_URI[128]; |
| 143 |
struct tsx_test_param *test_param; |
| 144 |
unsigned tp_flag; |
| 145 |
|
| 146 |
|
| 147 |
int recv_count; |
| 148 |
pj_time_val recv_last; |
| 149 |
pj_bool_t test_complete; |
| 150 |
|
| 151 |
|
| 152 |
pjsip_transport *loop; |
| 153 |
|
| 154 |
|
| 155 |
char key_buf[64]; |
| 156 |
pj_str_t tsx_key; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
pj_bool_t modules_registered; |
| 162 |
|
| 163 |
} g[MAX_TSX_TESTS]; |
| 164 |
|
| 165 |
#define TEST_TIMEOUT_ERROR -30 |
| 166 |
|
| 167 |
*/ |
| 168 |
#define MAX_ALLOWED_DIFF (test_app.ut_app.prm_ci_mode ? 2500 : 500) |
| 169 |
|
| 170 |
static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e); |
| 171 |
static pj_bool_t on_rx_message(pjsip_rx_data *rdata); |
| 172 |
|
| 173 |
|
| 174 |
static pjsip_module tsx_user = |
| 175 |
{ |
| 176 |
NULL, NULL, |
| 177 |
{ "Tsx-UAS-User", 12}, |
| 178 |
-1, |
| 179 |
PJSIP_MOD_PRIORITY_UA_PROXY_LAYER-1, |
| 180 |
NULL, |
| 181 |
NULL, |
| 182 |
NULL, |
| 183 |
NULL, |
| 184 |
NULL, |
| 185 |
NULL, |
| 186 |
NULL, |
| 187 |
NULL, |
| 188 |
&tsx_user_on_tsx_state, |
| 189 |
}; |
| 190 |
|
| 191 |
|
| 192 |
static pjsip_module msg_sender = |
| 193 |
{ |
| 194 |
NULL, NULL, |
| 195 |
{ "Msg-Sender", 10}, |
| 196 |
-1, |
| 197 |
PJSIP_MOD_PRIORITY_UA_PROXY_LAYER-1, |
| 198 |
NULL, |
| 199 |
NULL, |
| 200 |
NULL, |
| 201 |
NULL, |
| 202 |
&on_rx_message, |
| 203 |
&on_rx_message, |
| 204 |
NULL, |
| 205 |
NULL, |
| 206 |
NULL, |
| 207 |
}; |
| 208 |
|
| 209 |
|
| 210 |
struct response |
| 211 |
{ |
| 212 |
pj_str_t tsx_key; |
| 213 |
pjsip_tx_data *tdata; |
| 214 |
}; |
| 215 |
|
| 216 |
|
| 217 |
static unsigned get_tsx_tid(const pjsip_transaction *tsx) |
| 218 |
{ |
| 219 |
pj_assert(tsx_user.id >= 0); |
| 220 |
return (unsigned)(uintptr_t)tsx->mod_data[tsx_user.id]; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
static void init_tsx(pjsip_transaction *tsx, unsigned tid) |
| 225 |
{ |
| 226 |
pj_assert(tsx_user.id >= 0); |
| 227 |
tsx->mod_data[tsx_user.id] = (void*)(uintptr_t)tid; |
| 228 |
|
| 229 |
|
| 230 |
if (g[tid].test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { |
| 231 |
pjsip_tpselector tp_sel; |
| 232 |
|
| 233 |
pj_assert(g[tid].loop); |
| 234 |
pj_bzero(&tp_sel, sizeof(tp_sel)); |
| 235 |
tp_sel.type = PJSIP_TPSELECTOR_TRANSPORT; |
| 236 |
tp_sel.u.transport = g[tid].loop; |
| 237 |
pjsip_tsx_set_transport(tsx, &tp_sel); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
static int modules_reg_cnt; |
| 242 |
|
| 243 |
|
| 244 |
static pj_status_t register_modules(unsigned tid) |
| 245 |
{ |
| 246 |
int old_reg_cnt; |
| 247 |
pj_status_t status; |
| 248 |
|
| 249 |
pj_enter_critical_section(); |
| 250 |
old_reg_cnt = modules_reg_cnt++; |
| 251 |
pj_leave_critical_section(); |
| 252 |
|
| 253 |
if (old_reg_cnt==0) { |
| 254 |
PJ_TEST_SUCCESS(status=pjsip_endpt_register_module(endpt, &tsx_user), |
| 255 |
NULL, goto on_error); |
| 256 |
PJ_TEST_SUCCESS(status=pjsip_endpt_register_module(endpt, &msg_sender), |
| 257 |
NULL, { |
| 258 |
pjsip_endpt_unregister_module(endpt, &tsx_user); |
| 259 |
goto on_error; |
| 260 |
}); |
| 261 |
} else { |
| 262 |
unsigned i; |
| 263 |
|
| 264 |
for (i=0; i<20 && (tsx_user.id<0 || msg_sender.id<0); ++i) |
| 265 |
pj_thread_sleep(50); |
| 266 |
|
| 267 |
if (tsx_user.id<0 || msg_sender.id<0) { |
| 268 |
PJ_TEST_SUCCESS(status = PJSIP_ENOTINITIALIZED, |
| 269 |
"other thread failed to register module", |
| 270 |
goto on_error); |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
g[tid].modules_registered = 1; |
| 275 |
return PJ_SUCCESS; |
| 276 |
|
| 277 |
on_error: |
| 278 |
pj_enter_critical_section(); |
| 279 |
modules_reg_cnt--; |
| 280 |
pj_leave_critical_section(); |
| 281 |
|
| 282 |
return status; |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
static void unregister_modules(unsigned tid) |
| 287 |
{ |
| 288 |
|
| 289 |
|
| 290 |
if (!g[tid].modules_registered) |
| 291 |
return; |
| 292 |
|
| 293 |
g[tid].modules_registered = 0; |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
return; |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
static void send_response_timer( pj_timer_heap_t *timer_heap, |
| 318 |
struct pj_timer_entry *entry) |
| 319 |
{ |
| 320 |
pjsip_transaction *tsx; |
| 321 |
struct response *r = (struct response*) entry->user_data; |
| 322 |
pj_status_t status; |
| 323 |
|
| 324 |
PJ_UNUSED_ARG(timer_heap); |
| 325 |
|
| 326 |
tsx = pjsip_tsx_layer_find_tsx(&r->tsx_key, PJ_TRUE); |
| 327 |
if (!tsx) { |
| 328 |
PJ_LOG(3,(THIS_FILE," error: timer unable to find transaction")); |
| 329 |
pjsip_tx_data_dec_ref(r->tdata); |
| 330 |
return; |
| 331 |
} |
| 332 |
|
| 333 |
status = pjsip_tsx_send_msg(tsx, r->tdata); |
| 334 |
if (status != PJ_SUCCESS) { |
| 335 |
|
| 336 |
|
| 337 |
pj_grp_lock_release(tsx->grp_lock); |
| 338 |
pjsip_tx_data_dec_ref(r->tdata); |
| 339 |
return; |
| 340 |
} |
| 341 |
|
| 342 |
pj_grp_lock_release(tsx->grp_lock); |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
static void send_response( pjsip_rx_data *rdata, |
| 347 |
pjsip_transaction *tsx, |
| 348 |
int status_code ) |
| 349 |
{ |
| 350 |
pj_status_t status; |
| 351 |
pjsip_tx_data *tdata; |
| 352 |
unsigned tid = get_tsx_tid(tsx); |
| 353 |
|
| 354 |
status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, |
| 355 |
&tdata); |
| 356 |
if (status != PJ_SUCCESS) { |
| 357 |
app_perror(" error: unable to create response", status); |
| 358 |
g[tid].test_complete = -196; |
| 359 |
return; |
| 360 |
} |
| 361 |
|
| 362 |
status = pjsip_tsx_send_msg(tsx, tdata); |
| 363 |
if (status != PJ_SUCCESS) { |
| 364 |
pjsip_tx_data_dec_ref(tdata); |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
return; |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
static void schedule_send_response( unsigned tid, |
| 374 |
pjsip_rx_data *rdata, |
| 375 |
const pj_str_t *tsx_key_, |
| 376 |
int status_code, |
| 377 |
int msec_delay ) |
| 378 |
{ |
| 379 |
pj_status_t status; |
| 380 |
pjsip_tx_data *tdata; |
| 381 |
pj_timer_entry *t; |
| 382 |
struct response *r; |
| 383 |
pj_time_val delay; |
| 384 |
|
| 385 |
status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, |
| 386 |
&tdata); |
| 387 |
if (status != PJ_SUCCESS) { |
| 388 |
app_perror(" error: unable to create response", status); |
| 389 |
g[tid].test_complete = -198; |
| 390 |
return; |
| 391 |
} |
| 392 |
|
| 393 |
r = PJ_POOL_ALLOC_T(tdata->pool, struct response); |
| 394 |
pj_strdup(tdata->pool, &r->tsx_key, tsx_key_); |
| 395 |
r->tdata = tdata; |
| 396 |
|
| 397 |
delay.sec = 0; |
| 398 |
delay.msec = msec_delay; |
| 399 |
pj_time_val_normalize(&delay); |
| 400 |
|
| 401 |
t = PJ_POOL_ZALLOC_T(tdata->pool, pj_timer_entry); |
| 402 |
t->user_data = r; |
| 403 |
t->cb = &send_response_timer; |
| 404 |
|
| 405 |
status = pjsip_endpt_schedule_timer(endpt, t, &delay); |
| 406 |
if (status != PJ_SUCCESS) { |
| 407 |
pjsip_tx_data_dec_ref(tdata); |
| 408 |
app_perror(" error: unable to schedule timer", status); |
| 409 |
g[tid].test_complete = -199; |
| 410 |
return; |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
static void terminate_our_tsx(unsigned tid, int status_code) |
| 417 |
{ |
| 418 |
pjsip_transaction *tsx; |
| 419 |
|
| 420 |
tsx = pjsip_tsx_layer_find_tsx(&g[tid].tsx_key, PJ_TRUE); |
| 421 |
if (!tsx) { |
| 422 |
PJ_LOG(3,(THIS_FILE," error: timer unable to find transaction")); |
| 423 |
return; |
| 424 |
} |
| 425 |
|
| 426 |
pjsip_tsx_terminate(tsx, status_code); |
| 427 |
pj_grp_lock_release(tsx->grp_lock); |
| 428 |
} |
| 429 |
|
| 430 |
#if 0 |
| 431 |
|
| 432 |
static void terminate_tsx_timer( pj_timer_heap_t *timer_heap, |
| 433 |
struct pj_timer_entry *entry) |
| 434 |
{ |
| 435 |
terminate_our_tsx(entry->id); |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
static void schedule_terminate_tsx( pjsip_transaction *tsx, |
| 441 |
int status_code, |
| 442 |
int msec_delay ) |
| 443 |
{ |
| 444 |
pj_time_val delay; |
| 445 |
|
| 446 |
delay.sec = 0; |
| 447 |
delay.msec = msec_delay; |
| 448 |
pj_time_val_normalize(&delay); |
| 449 |
|
| 450 |
pj_assert(pj_strcmp(&tsx->transaction_key, &g[tid].tsx_key)==0); |
| 451 |
timer.user_data = NULL; |
| 452 |
timer.id = status_code; |
| 453 |
timer.cb = &terminate_tsx_timer; |
| 454 |
pjsip_endpt_schedule_timer(endpt, &timer, &delay); |
| 455 |
} |
| 456 |
#endif |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e) |
| 465 |
{ |
| 466 |
unsigned tid = get_tsx_tid(tsx); |
| 467 |
|
| 468 |
if (g[tid].test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM && |
| 469 |
e->type==PJSIP_EVENT_TSX_STATE) |
| 470 |
{ |
| 471 |
if (e->body.tsx_state.type==PJSIP_EVENT_RX_MSG) { |
| 472 |
PJ_TEST_EQ( e->body.tsx_state.src.rdata->tp_info.transport, |
| 473 |
g[tid].loop, NULL, { |
| 474 |
g[tid].test_complete = -704; |
| 475 |
return; |
| 476 |
}); |
| 477 |
} else if (e->body.tsx_state.type==PJSIP_EVENT_TX_MSG) { |
| 478 |
PJ_TEST_EQ( e->body.tsx_state.src.tdata->tp_info.transport, |
| 479 |
g[tid].loop, NULL, { |
| 480 |
g[tid].test_complete = -706; |
| 481 |
return; |
| 482 |
}); |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
if (pj_strnicmp2(&tsx->branch, TEST1_BRANCH_ID, BRANCH_LEN)==0 || |
| 487 |
pj_strnicmp2(&tsx->branch, TEST2_BRANCH_ID, BRANCH_LEN)==0) |
| 488 |
{ |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
int status_code = (pj_strnicmp2(&tsx->branch, TEST1_BRANCH_ID, BRANCH_LEN)==0) ? |
| 497 |
TEST1_STATUS_CODE : TEST2_STATUS_CODE; |
| 498 |
|
| 499 |
if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { |
| 500 |
|
| 501 |
g[tid].test_complete = 1; |
| 502 |
|
| 503 |
|
| 504 |
if (tsx->status_code != status_code) { |
| 505 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 506 |
g[tid].test_complete = -100; |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { |
| 511 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 512 |
g[tid].test_complete = -101; |
| 513 |
} |
| 514 |
|
| 515 |
} else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { |
| 516 |
|
| 517 |
|
| 518 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { |
| 519 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 520 |
g[tid].test_complete = -102; |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
} |
| 525 |
else |
| 526 |
if (pj_strnicmp2(&tsx->branch, TEST3_BRANCH_ID, BRANCH_LEN)==0) { |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { |
| 531 |
|
| 532 |
g[tid].test_complete = 1; |
| 533 |
|
| 534 |
|
| 535 |
if (tsx->status_code != TEST3_STATUS_CODE) { |
| 536 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 537 |
g[tid].test_complete = -110; |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { |
| 542 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 543 |
g[tid].test_complete = -111; |
| 544 |
} |
| 545 |
|
| 546 |
} else if (tsx->state == PJSIP_TSX_STATE_PROCEEDING) { |
| 547 |
|
| 548 |
|
| 549 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { |
| 550 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 551 |
g[tid].test_complete = -112; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
if (tsx->status_code != TEST3_PROVISIONAL_CODE) { |
| 556 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 557 |
g[tid].test_complete = -113; |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
if (e->body.tsx_state.type != PJSIP_EVENT_TX_MSG) { |
| 562 |
PJ_LOG(3,(THIS_FILE, " error: incorrect event")); |
| 563 |
g[tid].test_complete = -114; |
| 564 |
} |
| 565 |
|
| 566 |
} else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { |
| 567 |
|
| 568 |
|
| 569 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { |
| 570 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 571 |
g[tid].test_complete = -115; |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
if (tsx->status_code != TEST3_STATUS_CODE) { |
| 576 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 577 |
g[tid].test_complete = -116; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
if (e->body.tsx_state.type != PJSIP_EVENT_TX_MSG) { |
| 582 |
PJ_LOG(3,(THIS_FILE, " error: incorrect event")); |
| 583 |
g[tid].test_complete = -117; |
| 584 |
} |
| 585 |
|
| 586 |
} |
| 587 |
|
| 588 |
} else |
| 589 |
if (pj_strnicmp2(&tsx->branch, TEST4_BRANCH_ID, BRANCH_LEN)==0) { |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
if (tsx->state == PJSIP_TSX_STATE_TRYING) { |
| 594 |
|
| 595 |
} else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { |
| 596 |
|
| 597 |
|
| 598 |
if (tsx->status_code != TEST4_STATUS_CODE) { |
| 599 |
PJ_LOG(3,(THIS_FILE, |
| 600 |
" error: incorrect status code %d " |
| 601 |
"(expecting %d)", tsx->status_code, |
| 602 |
TEST4_STATUS_CODE)); |
| 603 |
g[tid].test_complete = -120; |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { |
| 608 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 609 |
g[tid].test_complete = -121; |
| 610 |
} |
| 611 |
|
| 612 |
} else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) |
| 613 |
{ |
| 614 |
PJ_LOG(3,(THIS_FILE, " error: unexpected state %s (122)", |
| 615 |
pjsip_tsx_state_str(tsx->state))); |
| 616 |
g[tid].test_complete = -122; |
| 617 |
|
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
} else |
| 622 |
if (pj_strnicmp2(&tsx->branch, TEST5_BRANCH_ID, BRANCH_LEN)==0) { |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
if (tsx->state == PJSIP_TSX_STATE_TRYING) { |
| 627 |
|
| 628 |
|
| 629 |
} else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { |
| 630 |
|
| 631 |
|
| 632 |
if (tsx->status_code != TEST5_STATUS_CODE) { |
| 633 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 634 |
g[tid].test_complete = -130; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { |
| 639 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 640 |
g[tid].test_complete = -131; |
| 641 |
} |
| 642 |
|
| 643 |
} else if (tsx->state == PJSIP_TSX_STATE_PROCEEDING) { |
| 644 |
|
| 645 |
|
| 646 |
if (tsx->status_code != TEST5_PROVISIONAL_CODE) { |
| 647 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 648 |
g[tid].test_complete = -132; |
| 649 |
} |
| 650 |
|
| 651 |
} else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { |
| 652 |
PJ_LOG(3,(THIS_FILE, " error: unexpected state %s (133)", |
| 653 |
pjsip_tsx_state_str(tsx->state))); |
| 654 |
g[tid].test_complete = -133; |
| 655 |
|
| 656 |
} |
| 657 |
|
| 658 |
} else |
| 659 |
if (pj_strnicmp2(&tsx->branch, TEST6_BRANCH_ID, BRANCH_LEN)==0) { |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
if (tsx->state == PJSIP_TSX_STATE_TRYING) { |
| 664 |
|
| 665 |
|
| 666 |
} else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { |
| 667 |
|
| 668 |
|
| 669 |
if (tsx->status_code != TEST6_STATUS_CODE) { |
| 670 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code %d " |
| 671 |
"(expecting %d)", tsx->status_code, |
| 672 |
TEST6_STATUS_CODE)); |
| 673 |
g[tid].test_complete = -140; |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { |
| 678 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 679 |
g[tid].test_complete = -141; |
| 680 |
} |
| 681 |
|
| 682 |
} else if (tsx->state != PJSIP_TSX_STATE_PROCEEDING && |
| 683 |
tsx->state != PJSIP_TSX_STATE_COMPLETED && |
| 684 |
tsx->state != PJSIP_TSX_STATE_DESTROYED) |
| 685 |
{ |
| 686 |
PJ_LOG(3,(THIS_FILE, " error: unexpected state %s (142)", |
| 687 |
pjsip_tsx_state_str(tsx->state))); |
| 688 |
g[tid].test_complete = -142; |
| 689 |
|
| 690 |
} |
| 691 |
|
| 692 |
|
| 693 |
} else |
| 694 |
if (pj_strnicmp2(&tsx->branch, TEST7_BRANCH_ID, BRANCH_LEN)==0 || |
| 695 |
pj_strnicmp2(&tsx->branch, TEST8_BRANCH_ID, BRANCH_LEN)==0) |
| 696 |
{ |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
int code; |
| 702 |
|
| 703 |
if (pj_strnicmp2(&tsx->branch, TEST7_BRANCH_ID, BRANCH_LEN) == 0) |
| 704 |
code = TEST7_STATUS_CODE; |
| 705 |
else |
| 706 |
code = TEST8_STATUS_CODE; |
| 707 |
|
| 708 |
if (tsx->state == PJSIP_TSX_STATE_TRYING) { |
| 709 |
|
| 710 |
|
| 711 |
} else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { |
| 712 |
|
| 713 |
if (g[tid].test_complete == 0) |
| 714 |
g[tid].test_complete = 1; |
| 715 |
|
| 716 |
|
| 717 |
if (tsx->status_code != PJSIP_SC_TSX_TIMEOUT) { |
| 718 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code %d", |
| 719 |
tsx->status_code)); |
| 720 |
g[tid].test_complete = -150; |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { |
| 725 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 726 |
g[tid].test_complete = -151; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
if (g[tid].tp_flag & PJSIP_TRANSPORT_RELIABLE) { |
| 731 |
|
| 732 |
if (tsx->retransmit_count != 0) { |
| 733 |
PJ_LOG(3,(THIS_FILE, " error: should not retransmit")); |
| 734 |
g[tid].test_complete = -1510; |
| 735 |
} |
| 736 |
|
| 737 |
} else { |
| 738 |
|
| 739 |
if (tsx->retransmit_count != 10) { |
| 740 |
PJ_LOG(3,(THIS_FILE, |
| 741 |
" error: incorrect retransmit count %d " |
| 742 |
"(expecting 10)", |
| 743 |
tsx->retransmit_count)); |
| 744 |
g[tid].test_complete = -1510; |
| 745 |
} |
| 746 |
|
| 747 |
} |
| 748 |
|
| 749 |
} else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { |
| 750 |
|
| 751 |
|
| 752 |
if (tsx->status_code != code) { |
| 753 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 754 |
g[tid].test_complete = -152; |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { |
| 759 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 760 |
g[tid].test_complete = -153; |
| 761 |
} |
| 762 |
|
| 763 |
} else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { |
| 764 |
|
| 765 |
PJ_LOG(3,(THIS_FILE, " error: unexpected state (154)")); |
| 766 |
g[tid].test_complete = -154; |
| 767 |
|
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
} else |
| 772 |
if (pj_strnicmp2(&tsx->branch, TEST9_BRANCH_ID, BRANCH_LEN)==0) { |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
if (tsx->state == PJSIP_TSX_STATE_TRYING) { |
| 779 |
|
| 780 |
|
| 781 |
} else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { |
| 782 |
|
| 783 |
if (g[tid].test_complete == 0) |
| 784 |
g[tid].test_complete = 1; |
| 785 |
|
| 786 |
|
| 787 |
PJ_TEST_EQ(tsx->status_code, TEST9_STATUS_CODE, NULL, |
| 788 |
g[tid].test_complete = -160); |
| 789 |
|
| 790 |
|
| 791 |
PJ_TEST_EQ(e->body.tsx_state.prev_state, PJSIP_TSX_STATE_CONFIRMED, |
| 792 |
NULL, g[tid].test_complete = -161); |
| 793 |
|
| 794 |
} else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { |
| 795 |
|
| 796 |
|
| 797 |
if (tsx->status_code != TEST9_STATUS_CODE) { |
| 798 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 799 |
g[tid].test_complete = -162; |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { |
| 804 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 805 |
g[tid].test_complete = -163; |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
} else if (tsx->state == PJSIP_TSX_STATE_CONFIRMED) { |
| 810 |
|
| 811 |
|
| 812 |
if (tsx->status_code != TEST9_STATUS_CODE) { |
| 813 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 814 |
g[tid].test_complete = -164; |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { |
| 819 |
PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); |
| 820 |
g[tid].test_complete = -165; |
| 821 |
} |
| 822 |
|
| 823 |
} else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { |
| 824 |
|
| 825 |
PJ_LOG(3,(THIS_FILE, " error: unexpected state (166)")); |
| 826 |
g[tid].test_complete = -166; |
| 827 |
|
| 828 |
} |
| 829 |
|
| 830 |
|
| 831 |
} else |
| 832 |
if (pj_strnicmp2(&tsx->branch, TEST10_BRANCH_ID, BRANCH_LEN)==0 || |
| 833 |
pj_strnicmp2(&tsx->branch, TEST12_BRANCH_ID, BRANCH_LEN)==0) |
| 834 |
{ |
| 835 |
if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { |
| 836 |
|
| 837 |
if (!g[tid].test_complete) |
| 838 |
g[tid].test_complete = 1; |
| 839 |
|
| 840 |
if (tsx->status_code != PJSIP_SC_REQUEST_TIMEOUT) { |
| 841 |
PJ_LOG(3,(THIS_FILE," error: incorrect status code" |
| 842 |
" (expecting %d, got %d)", |
| 843 |
PJSIP_SC_REQUEST_TIMEOUT, |
| 844 |
|
| 845 |
tsx->status_code)); |
| 846 |
g[tid].test_complete = -170; |
| 847 |
} |
| 848 |
} |
| 849 |
} else |
| 850 |
if (pj_strnicmp2(&tsx->branch, TEST11_BRANCH_ID, BRANCH_LEN)==0) |
| 851 |
{ |
| 852 |
if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { |
| 853 |
|
| 854 |
if (!g[tid].test_complete) |
| 855 |
g[tid].test_complete = 1; |
| 856 |
|
| 857 |
if (tsx->status_code != PJSIP_SC_REQUEST_TIMEOUT && |
| 858 |
tsx->status_code != PJSIP_SC_OK) |
| 859 |
{ |
| 860 |
PJ_LOG(3,(THIS_FILE," error: incorrect status code" |
| 861 |
" (expecting %d, got %d)", |
| 862 |
PJSIP_SC_REQUEST_TIMEOUT, |
| 863 |
|
| 864 |
tsx->status_code)); |
| 865 |
g[tid].test_complete = -170; |
| 866 |
} |
| 867 |
} |
| 868 |
} |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
static void save_key(pjsip_transaction *tsx) |
| 873 |
{ |
| 874 |
pj_str_t key; |
| 875 |
unsigned tid = get_tsx_tid(tsx); |
| 876 |
|
| 877 |
g[tid].tsx_key.ptr = g[tid].key_buf; |
| 878 |
g[tid].tsx_key.slen = 0; |
| 879 |
pj_strdup(tsx->pool, &key, &tsx->transaction_key); |
| 880 |
pj_strcpy(&g[tid].tsx_key, &key); |
| 881 |
} |
| 882 |
|
| 883 |
#define DIFF(a,b) ((a<b) ? (b-a) : (a-b)) |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
static pj_bool_t on_rx_message(pjsip_rx_data *rdata) |
| 889 |
{ |
| 890 |
pjsip_msg *msg = rdata->msg_info.msg; |
| 891 |
pj_str_t branch_param = rdata->msg_info.via->branch_param; |
| 892 |
pj_status_t status; |
| 893 |
pjsip_to_hdr *to_hdr = rdata->msg_info.to; |
| 894 |
pjsip_sip_uri *target = (pjsip_sip_uri*)pjsip_uri_get_uri(to_hdr->uri); |
| 895 |
pjsip_from_hdr *from_hdr = rdata->msg_info.from; |
| 896 |
pjsip_sip_uri *from_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(from_hdr->uri); |
| 897 |
unsigned tid; |
| 898 |
|
| 899 |
if (pj_strcmp2(&from_uri->user, "tsx_uas_test")) { |
| 900 |
|
| 901 |
return PJ_FALSE; |
| 902 |
} |
| 903 |
|
| 904 |
tid = (unsigned)pj_strtol(&target->user); |
| 905 |
|
| 906 |
if (g[tid].test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { |
| 907 |
PJ_TEST_EQ(rdata->tp_info.transport, g[tid].loop, NULL, |
| 908 |
{g[tid].test_complete = -602; return PJ_TRUE;}); |
| 909 |
} |
| 910 |
|
| 911 |
if (pj_strnicmp2(&branch_param, TEST1_BRANCH_ID, BRANCH_LEN) == 0 || |
| 912 |
pj_strnicmp2(&branch_param, TEST2_BRANCH_ID, BRANCH_LEN) == 0) |
| 913 |
{ |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
int status_code = (pj_strnicmp2(&branch_param, TEST1_BRANCH_ID, BRANCH_LEN) == 0) ? |
| 922 |
TEST1_STATUS_CODE : TEST2_STATUS_CODE; |
| 923 |
|
| 924 |
if (msg->type == PJSIP_REQUEST_MSG) { |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
pjsip_transaction *tsx; |
| 929 |
|
| 930 |
status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); |
| 931 |
if (status != PJ_SUCCESS) { |
| 932 |
app_perror(" error: unable to create transaction", status); |
| 933 |
g[tid].test_complete = -110; |
| 934 |
return PJ_TRUE; |
| 935 |
} |
| 936 |
init_tsx(tsx, tid); |
| 937 |
pjsip_tsx_recv_msg(tsx, rdata); |
| 938 |
|
| 939 |
save_key(tsx); |
| 940 |
send_response(rdata, tsx, status_code); |
| 941 |
|
| 942 |
} else { |
| 943 |
|
| 944 |
|
| 945 |
++g[tid].recv_count; |
| 946 |
|
| 947 |
|
| 948 |
if (msg->line.status.code != status_code) { |
| 949 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 950 |
g[tid].test_complete = -113; |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
if (g[tid].recv_count > 1) { |
| 955 |
PJ_LOG(3,(THIS_FILE, " error: retransmission received")); |
| 956 |
g[tid].test_complete = -114; |
| 957 |
} |
| 958 |
|
| 959 |
} |
| 960 |
return PJ_TRUE; |
| 961 |
|
| 962 |
} else if (pj_strnicmp2(&branch_param, TEST3_BRANCH_ID, |
| 963 |
BRANCH_LEN) == 0) { |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
if (msg->type == PJSIP_REQUEST_MSG) { |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
pjsip_transaction *tsx; |
| 972 |
|
| 973 |
status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); |
| 974 |
if (status != PJ_SUCCESS) { |
| 975 |
app_perror(" error: unable to create transaction", status); |
| 976 |
g[tid].test_complete = -116; |
| 977 |
return PJ_TRUE; |
| 978 |
} |
| 979 |
init_tsx(tsx, tid); |
| 980 |
pjsip_tsx_recv_msg(tsx, rdata); |
| 981 |
|
| 982 |
save_key(tsx); |
| 983 |
|
| 984 |
send_response(rdata, tsx, TEST3_PROVISIONAL_CODE); |
| 985 |
schedule_send_response(tid, rdata, &tsx->transaction_key, |
| 986 |
TEST3_STATUS_CODE, 2000); |
| 987 |
|
| 988 |
} else { |
| 989 |
|
| 990 |
|
| 991 |
++g[tid].recv_count; |
| 992 |
|
| 993 |
if (g[tid].recv_count == 1) { |
| 994 |
|
| 995 |
if (msg->line.status.code != TEST3_PROVISIONAL_CODE) { |
| 996 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 997 |
g[tid].test_complete = -123; |
| 998 |
} |
| 999 |
} else if (g[tid].recv_count == 2) { |
| 1000 |
|
| 1001 |
if (msg->line.status.code != TEST3_STATUS_CODE) { |
| 1002 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); |
| 1003 |
g[tid].test_complete = -124; |
| 1004 |
} |
| 1005 |
} else { |
| 1006 |
PJ_LOG(3,(THIS_FILE, " error: retransmission received")); |
| 1007 |
g[tid].test_complete = -125; |
| 1008 |
} |
| 1009 |
|
| 1010 |
} |
| 1011 |
return PJ_TRUE; |
| 1012 |
|
| 1013 |
} else if (pj_strnicmp2(&branch_param, TEST4_BRANCH_ID, BRANCH_LEN) == 0 || |
| 1014 |
pj_strnicmp2(&branch_param, TEST5_BRANCH_ID, BRANCH_LEN) == 0 || |
| 1015 |
pj_strnicmp2(&branch_param, TEST6_BRANCH_ID, BRANCH_LEN) == 0) |
| 1016 |
{ |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
if (msg->type == PJSIP_REQUEST_MSG) { |
| 1023 |
|
| 1024 |
pjsip_transaction *tsx; |
| 1025 |
|
| 1026 |
PJ_LOG(4,(THIS_FILE, " received request (probably retransmission)")); |
| 1027 |
|
| 1028 |
status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); |
| 1029 |
if (status != PJ_SUCCESS) { |
| 1030 |
app_perror(" error: unable to create transaction", status); |
| 1031 |
g[tid].test_complete = -130; |
| 1032 |
return PJ_TRUE; |
| 1033 |
} |
| 1034 |
init_tsx(tsx, tid); |
| 1035 |
pjsip_tsx_recv_msg(tsx, rdata); |
| 1036 |
save_key(tsx); |
| 1037 |
|
| 1038 |
if (pj_strnicmp2(&branch_param, TEST4_BRANCH_ID, BRANCH_LEN) == 0) { |
| 1039 |
|
| 1040 |
} else if (pj_strnicmp2(&branch_param, TEST5_BRANCH_ID, BRANCH_LEN) == 0) { |
| 1041 |
send_response(rdata, tsx, TEST5_PROVISIONAL_CODE); |
| 1042 |
|
| 1043 |
} else if (pj_strnicmp2(&branch_param, TEST6_BRANCH_ID, BRANCH_LEN) == 0) { |
| 1044 |
PJ_LOG(4,(THIS_FILE, " sending provisional response")); |
| 1045 |
send_response(rdata, tsx, TEST6_PROVISIONAL_CODE); |
| 1046 |
PJ_LOG(4,(THIS_FILE, " sending final response")); |
| 1047 |
send_response(rdata, tsx, TEST6_STATUS_CODE); |
| 1048 |
} |
| 1049 |
|
| 1050 |
} else { |
| 1051 |
|
| 1052 |
|
| 1053 |
PJ_LOG(4,(THIS_FILE, " received response number %d", g[tid].recv_count)); |
| 1054 |
|
| 1055 |
++g[tid].recv_count; |
| 1056 |
|
| 1057 |
if (pj_strnicmp2(&branch_param, TEST4_BRANCH_ID, BRANCH_LEN) == 0) { |
| 1058 |
PJ_LOG(3,(THIS_FILE, " error: not expecting response!")); |
| 1059 |
g[tid].test_complete = -132; |
| 1060 |
|
| 1061 |
} else if (pj_strnicmp2(&branch_param, TEST5_BRANCH_ID, BRANCH_LEN) == 0) { |
| 1062 |
|
| 1063 |
if (rdata->msg_info.msg->line.status.code!=TEST5_PROVISIONAL_CODE) { |
| 1064 |
PJ_LOG(3,(THIS_FILE, " error: incorrect status code!")); |
| 1065 |
g[tid].test_complete = -133; |
| 1066 |
|
| 1067 |
} |
| 1068 |
if (g[tid].recv_count > TEST5_RESPONSE_COUNT) { |
| 1069 |
PJ_LOG(3,(THIS_FILE, " error: not expecting response!")); |
| 1070 |
g[tid].test_complete = -134; |
| 1071 |
} |
| 1072 |
|
| 1073 |
} else if (pj_strnicmp2(&branch_param, TEST6_BRANCH_ID, BRANCH_LEN) == 0) { |
| 1074 |
|
| 1075 |
int code = rdata->msg_info.msg->line.status.code; |
| 1076 |
|
| 1077 |
switch (g[tid].recv_count) { |
| 1078 |
case 1: |
| 1079 |
if (code != TEST6_PROVISIONAL_CODE) { |
| 1080 |
PJ_LOG(3,(THIS_FILE, " error: invalid code!")); |
| 1081 |
g[tid].test_complete = -135; |
| 1082 |
} |
| 1083 |
break; |
| 1084 |
case 2: |
| 1085 |
case 3: |
| 1086 |
if (code != TEST6_STATUS_CODE) { |
| 1087 |
PJ_LOG(3,(THIS_FILE, " error: invalid code %d " |
| 1088 |
"(expecting %d)", code, TEST6_STATUS_CODE)); |
| 1089 |
g[tid].test_complete = -136; |
| 1090 |
} |
| 1091 |
break; |
| 1092 |
default: |
| 1093 |
PJ_LOG(3,(THIS_FILE, " error: not expecting response")); |
| 1094 |
g[tid].test_complete = -137; |
| 1095 |
break; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
} |
| 1099 |
return PJ_TRUE; |
| 1100 |
|
| 1101 |
|
| 1102 |
} else if (pj_strnicmp2(&branch_param, TEST7_BRANCH_ID, BRANCH_LEN) == 0 || |
| 1103 |
pj_strnicmp2(&branch_param, TEST8_BRANCH_ID, BRANCH_LEN) == 0) |
| 1104 |
{ |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
if (msg->type == PJSIP_REQUEST_MSG) { |
| 1110 |
|
| 1111 |
|
| 1112 |
pjsip_transaction *tsx; |
| 1113 |
|
| 1114 |
status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); |
| 1115 |
if (status != PJ_SUCCESS) { |
| 1116 |
app_perror(" error: unable to create transaction", status); |
| 1117 |
g[tid].test_complete = -140; |
| 1118 |
return PJ_TRUE; |
| 1119 |
} |
| 1120 |
init_tsx(tsx, tid); |
| 1121 |
pjsip_tsx_recv_msg(tsx, rdata); |
| 1122 |
save_key(tsx); |
| 1123 |
|
| 1124 |
if (pj_strnicmp2(&branch_param, TEST7_BRANCH_ID, BRANCH_LEN) == 0) { |
| 1125 |
|
| 1126 |
send_response(rdata, tsx, TEST7_STATUS_CODE); |
| 1127 |
|
| 1128 |
} else { |
| 1129 |
|
| 1130 |
send_response(rdata, tsx, TEST8_STATUS_CODE); |
| 1131 |
|
| 1132 |
} |
| 1133 |
|
| 1134 |
} else { |
| 1135 |
int code; |
| 1136 |
|
| 1137 |
++g[tid].recv_count; |
| 1138 |
|
| 1139 |
if (pj_strnicmp2(&branch_param, TEST7_BRANCH_ID, BRANCH_LEN) == 0) |
| 1140 |
code = TEST7_STATUS_CODE; |
| 1141 |
else |
| 1142 |
code = TEST8_STATUS_CODE; |
| 1143 |
|
| 1144 |
if (g[tid].recv_count==1) { |
| 1145 |
|
| 1146 |
if (rdata->msg_info.msg->line.status.code != code) { |
| 1147 |
PJ_LOG(3,(THIS_FILE," error: invalid status code %d", |
| 1148 |
rdata->msg_info.msg->line.status.code)); |
| 1149 |
g[tid].test_complete = -141; |
| 1150 |
} |
| 1151 |
|
| 1152 |
g[tid].recv_last = rdata->pkt_info.timestamp; |
| 1153 |
|
| 1154 |
} else { |
| 1155 |
|
| 1156 |
pj_time_val now; |
| 1157 |
unsigned msec, msec_expected; |
| 1158 |
|
| 1159 |
now = rdata->pkt_info.timestamp; |
| 1160 |
|
| 1161 |
PJ_TIME_VAL_SUB(now, g[tid].recv_last); |
| 1162 |
|
| 1163 |
msec = now.sec*1000 + now.msec; |
| 1164 |
msec_expected = (1 << (g[tid].recv_count-2)) * pjsip_cfg()->tsx.t1; |
| 1165 |
if (msec_expected > pjsip_cfg()->tsx.t2) |
| 1166 |
msec_expected = pjsip_cfg()->tsx.t2; |
| 1167 |
|
| 1168 |
if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) { |
| 1169 |
PJ_LOG(3,(THIS_FILE, |
| 1170 |
" error: incorrect retransmission " |
| 1171 |
"time (%d ms expected, %d ms received", |
| 1172 |
msec_expected, msec)); |
| 1173 |
g[tid].test_complete = -142; |
| 1174 |
} |
| 1175 |
|
| 1176 |
if (g[tid].recv_count > 11) { |
| 1177 |
PJ_LOG(3,(THIS_FILE," error: too many responses (%d)", |
| 1178 |
g[tid].recv_count)); |
| 1179 |
g[tid].test_complete = -143; |
| 1180 |
} |
| 1181 |
|
| 1182 |
g[tid].recv_last = rdata->pkt_info.timestamp; |
| 1183 |
} |
| 1184 |
|
| 1185 |
} |
| 1186 |
return PJ_TRUE; |
| 1187 |
|
| 1188 |
} else if (pj_strnicmp2(&branch_param, TEST9_BRANCH_ID, BRANCH_LEN) == 0) { |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
if (msg->type == PJSIP_REQUEST_MSG) { |
| 1196 |
|
| 1197 |
|
| 1198 |
pjsip_transaction *tsx; |
| 1199 |
|
| 1200 |
status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); |
| 1201 |
if (status != PJ_SUCCESS) { |
| 1202 |
app_perror(" error: unable to create transaction", status); |
| 1203 |
g[tid].test_complete = -150; |
| 1204 |
return PJ_TRUE; |
| 1205 |
} |
| 1206 |
init_tsx(tsx, tid); |
| 1207 |
pjsip_tsx_recv_msg(tsx, rdata); |
| 1208 |
save_key(tsx); |
| 1209 |
send_response(rdata, tsx, TEST9_STATUS_CODE); |
| 1210 |
|
| 1211 |
|
| 1212 |
} else { |
| 1213 |
|
| 1214 |
++g[tid].recv_count; |
| 1215 |
|
| 1216 |
PJ_TEST_EQ(rdata->msg_info.msg->line.status.code, TEST9_STATUS_CODE, |
| 1217 |
NULL, g[tid].test_complete = -151); |
| 1218 |
|
| 1219 |
if (g[tid].recv_count==1) { |
| 1220 |
|
| 1221 |
g[tid].recv_last = rdata->pkt_info.timestamp; |
| 1222 |
|
| 1223 |
} else if (g[tid].recv_count < 5) { |
| 1224 |
|
| 1225 |
|
| 1226 |
pj_time_val now; |
| 1227 |
unsigned msec, msec_expected; |
| 1228 |
|
| 1229 |
now = rdata->pkt_info.timestamp; |
| 1230 |
|
| 1231 |
PJ_TIME_VAL_SUB(now, g[tid].recv_last); |
| 1232 |
|
| 1233 |
msec = now.sec*1000 + now.msec; |
| 1234 |
msec_expected = (1 << (g[tid].recv_count-2)) * pjsip_cfg()->tsx.t1; |
| 1235 |
if (msec_expected > pjsip_cfg()->tsx.t2) |
| 1236 |
msec_expected = pjsip_cfg()->tsx.t2; |
| 1237 |
|
| 1238 |
if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) { |
| 1239 |
PJ_LOG(3,(THIS_FILE, |
| 1240 |
" error: incorrect retransmission " |
| 1241 |
"time (%d ms expected, %d ms received", |
| 1242 |
msec_expected, msec)); |
| 1243 |
g[tid].test_complete = -152; |
| 1244 |
} |
| 1245 |
|
| 1246 |
g[tid].recv_last = rdata->pkt_info.timestamp; |
| 1247 |
|
| 1248 |
} else if (g[tid].recv_count == 5) { |
| 1249 |
pjsip_tx_data *tdata; |
| 1250 |
pjsip_sip_uri *uri; |
| 1251 |
pjsip_via_hdr *via; |
| 1252 |
|
| 1253 |
status = pjsip_endpt_create_request_from_hdr( |
| 1254 |
endpt, &pjsip_ack_method, |
| 1255 |
rdata->msg_info.to->uri, |
| 1256 |
rdata->msg_info.from, |
| 1257 |
rdata->msg_info.to, |
| 1258 |
NULL, |
| 1259 |
rdata->msg_info.cid, |
| 1260 |
rdata->msg_info.cseq->cseq, |
| 1261 |
NULL, |
| 1262 |
&tdata); |
| 1263 |
if (status != PJ_SUCCESS) { |
| 1264 |
app_perror(" error: unable to create ACK", status); |
| 1265 |
g[tid].test_complete = -153; |
| 1266 |
return PJ_TRUE; |
| 1267 |
} |
| 1268 |
|
| 1269 |
uri=(pjsip_sip_uri*)pjsip_uri_get_uri(tdata->msg->line.req.uri); |
| 1270 |
pj_strdup2(tdata->pool, &uri->transport_param, |
| 1271 |
g[tid].test_param->tp_type); |
| 1272 |
uri->port = g[tid].test_param->port; |
| 1273 |
|
| 1274 |
via = (pjsip_via_hdr*) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); |
| 1275 |
pj_strdup(tdata->pool, &via->branch_param, |
| 1276 |
&rdata->msg_info.via->branch_param); |
| 1277 |
|
| 1278 |
if (g[tid].test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { |
| 1279 |
pjsip_tpselector tp_sel; |
| 1280 |
|
| 1281 |
pj_bzero(&tp_sel, sizeof(tp_sel)); |
| 1282 |
tp_sel.type = PJSIP_TPSELECTOR_TRANSPORT; |
| 1283 |
tp_sel.u.transport = g[tid].loop; |
| 1284 |
pjsip_tx_data_set_transport(tdata, &tp_sel); |
| 1285 |
} |
| 1286 |
|
| 1287 |
status = pjsip_endpt_send_request_stateless(endpt, tdata, |
| 1288 |
NULL, NULL); |
| 1289 |
if (status != PJ_SUCCESS) { |
| 1290 |
app_perror(" error: unable to send ACK", status); |
| 1291 |
g[tid].test_complete = -154; |
| 1292 |
} |
| 1293 |
|
| 1294 |
} else { |
| 1295 |
PJ_LOG(3,(THIS_FILE," error: too many responses (%d)", |
| 1296 |
g[tid].recv_count)); |
| 1297 |
g[tid].test_complete = -155; |
| 1298 |
} |
| 1299 |
|
| 1300 |
} |
| 1301 |
return PJ_TRUE; |
| 1302 |
|
| 1303 |
} else if (pj_strnicmp2(&branch_param, TEST10_BRANCH_ID, BRANCH_LEN) == 0 || |
| 1304 |
pj_strnicmp2(&branch_param, TEST11_BRANCH_ID, BRANCH_LEN) == 0 || |
| 1305 |
pj_strnicmp2(&branch_param, TEST12_BRANCH_ID, BRANCH_LEN) == 0) |
| 1306 |
{ |
| 1307 |
int test_num, code1, code2; |
| 1308 |
|
| 1309 |
if (pj_strnicmp2(&branch_param, TEST10_BRANCH_ID, BRANCH_LEN) == 0) |
| 1310 |
test_num=10, code1 = 100, code2 = 0; |
| 1311 |
else if (pj_strnicmp2(&branch_param, TEST11_BRANCH_ID, BRANCH_LEN) == 0) |
| 1312 |
test_num=11, code1 = 100, code2 = 200; |
| 1313 |
else |
| 1314 |
test_num=12, code1 = 200, code2 = 0; |
| 1315 |
|
| 1316 |
PJ_UNUSED_ARG(test_num); |
| 1317 |
|
| 1318 |
if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG) { |
| 1319 |
|
| 1320 |
|
| 1321 |
pjsip_transaction *tsx; |
| 1322 |
|
| 1323 |
status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); |
| 1324 |
if (status != PJ_SUCCESS) { |
| 1325 |
app_perror(" error: unable to create transaction", status); |
| 1326 |
g[tid].test_complete = -150; |
| 1327 |
return PJ_TRUE; |
| 1328 |
} |
| 1329 |
init_tsx(tsx, tid); |
| 1330 |
pjsip_tsx_recv_msg(tsx, rdata); |
| 1331 |
save_key(tsx); |
| 1332 |
|
| 1333 |
schedule_send_response(tid, rdata, &g[tid].tsx_key, code1, 1000); |
| 1334 |
|
| 1335 |
if (code2) |
| 1336 |
schedule_send_response(tid, rdata, &g[tid].tsx_key, code2, 2000); |
| 1337 |
|
| 1338 |
} else { |
| 1339 |
|
| 1340 |
} |
| 1341 |
|
| 1342 |
return PJ_TRUE; |
| 1343 |
} |
| 1344 |
|
| 1345 |
return PJ_FALSE; |
| 1346 |
} |
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
static int perform_test( unsigned tid, |
| 1352 |
char *target_uri, char *from_uri, |
| 1353 |
char *branch_param, int test_time, |
| 1354 |
const pjsip_method *method, |
| 1355 |
int request_cnt, int request_interval_msec, |
| 1356 |
int expecting_timeout) |
| 1357 |
{ |
| 1358 |
pjsip_tx_data *tdata; |
| 1359 |
pj_str_t target, from; |
| 1360 |
pjsip_via_hdr *via; |
| 1361 |
char branch_buf[BRANCH_LEN+20]; |
| 1362 |
pj_time_val timeout, next_send; |
| 1363 |
int sent_cnt; |
| 1364 |
pjsip_tpselector tp_sel; |
| 1365 |
pj_status_t status; |
| 1366 |
|
| 1367 |
PJ_TEST_EQ(strlen(branch_param), BRANCH_LEN, NULL, return -99); |
| 1368 |
|
| 1369 |
if (test_time > 0) { |
| 1370 |
PJ_LOG(3,(THIS_FILE, |
| 1371 |
" please standby, this will take at most %d seconds..", |
| 1372 |
test_time)); |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
g[tid].recv_count = 0; |
| 1377 |
g[tid].test_complete = 0; |
| 1378 |
g[tid].tsx_key.slen = 0; |
| 1379 |
|
| 1380 |
|
| 1381 |
target = pj_str(target_uri); |
| 1382 |
from = pj_str(from_uri); |
| 1383 |
|
| 1384 |
|
| 1385 |
status = pjsip_endpt_create_request( endpt, method, &target, |
| 1386 |
&from, &target, NULL, NULL, -1, |
| 1387 |
NULL, &tdata); |
| 1388 |
if (status != PJ_SUCCESS) { |
| 1389 |
app_perror(" Error: unable to create request", status); |
| 1390 |
return -10; |
| 1391 |
} |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
via = (pjsip_via_hdr*) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); |
| 1397 |
pj_ansi_snprintf(branch_buf, sizeof(branch_buf), |
| 1398 |
"%s-%02d", branch_param, tid); |
| 1399 |
pj_strdup2(tdata->pool, &via->branch_param, branch_buf); |
| 1400 |
|
| 1401 |
|
| 1402 |
if (g[tid].test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { |
| 1403 |
pj_assert(g[tid].loop); |
| 1404 |
pj_bzero(&tp_sel, sizeof(tp_sel)); |
| 1405 |
tp_sel.type = PJSIP_TPSELECTOR_TRANSPORT; |
| 1406 |
tp_sel.u.transport = g[tid].loop; |
| 1407 |
pjsip_tx_data_set_transport(tdata, &tp_sel); |
| 1408 |
} |
| 1409 |
|
| 1410 |
|
| 1411 |
sent_cnt = 0; |
| 1412 |
pj_gettimeofday(&next_send); |
| 1413 |
pj_time_val_normalize(&next_send); |
| 1414 |
|
| 1415 |
|
| 1416 |
pj_gettimeofday(&timeout); |
| 1417 |
timeout.sec += test_time; |
| 1418 |
|
| 1419 |
|
| 1420 |
while (!g[tid].test_complete) { |
| 1421 |
pj_time_val now, poll_delay = {0, 10}; |
| 1422 |
|
| 1423 |
pjsip_endpt_handle_events(endpt, &poll_delay); |
| 1424 |
|
| 1425 |
pj_gettimeofday(&now); |
| 1426 |
|
| 1427 |
if (sent_cnt < request_cnt && PJ_TIME_VAL_GTE(now, next_send)) { |
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
pjsip_tx_data_add_ref(tdata); |
| 1432 |
|
| 1433 |
|
| 1434 |
PJ_LOG(4,(THIS_FILE, " (re)sending request %d", sent_cnt)); |
| 1435 |
|
| 1436 |
status = pjsip_endpt_send_request_stateless(endpt, tdata, 0, 0); |
| 1437 |
if (status != PJ_SUCCESS) { |
| 1438 |
app_perror(" Error: unable to send request", status); |
| 1439 |
pjsip_tx_data_dec_ref(tdata); |
| 1440 |
return -20; |
| 1441 |
} |
| 1442 |
|
| 1443 |
|
| 1444 |
sent_cnt++; |
| 1445 |
if (sent_cnt < request_cnt) { |
| 1446 |
pj_gettimeofday(&next_send); |
| 1447 |
next_send.msec += request_interval_msec; |
| 1448 |
pj_time_val_normalize(&next_send); |
| 1449 |
} |
| 1450 |
} |
| 1451 |
|
| 1452 |
if (now.sec > timeout.sec) { |
| 1453 |
if (!expecting_timeout) |
| 1454 |
PJ_LOG(3,(THIS_FILE, " Error: test has timed out")); |
| 1455 |
pjsip_tx_data_dec_ref(tdata); |
| 1456 |
return TEST_TIMEOUT_ERROR; |
| 1457 |
} |
| 1458 |
} |
| 1459 |
|
| 1460 |
if (g[tid].test_complete < 0) { |
| 1461 |
pjsip_transaction *tsx; |
| 1462 |
|
| 1463 |
tsx = pjsip_tsx_layer_find_tsx(&g[tid].tsx_key, PJ_TRUE); |
| 1464 |
if (tsx) { |
| 1465 |
pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED); |
| 1466 |
pj_grp_lock_release(tsx->grp_lock); |
| 1467 |
flush_events(1000); |
| 1468 |
} |
| 1469 |
pjsip_tx_data_dec_ref(tdata); |
| 1470 |
return g[tid].test_complete; |
| 1471 |
} |
| 1472 |
|
| 1473 |
|
| 1474 |
flush_events(500); |
| 1475 |
|
| 1476 |
|
| 1477 |
if (pjsip_tsx_layer_find_tsx(&g[tid].tsx_key, PJ_FALSE) != NULL) { |
| 1478 |
PJ_LOG(3,(THIS_FILE, " Error: transaction has not been destroyed")); |
| 1479 |
pjsip_tx_data_dec_ref(tdata); |
| 1480 |
return -40; |
| 1481 |
} |
| 1482 |
|
| 1483 |
|
| 1484 |
if (pj_atomic_get(tdata->ref_cnt) != 1) { |
| 1485 |
PJ_LOG(3,(THIS_FILE, " Error: tdata reference counter is %ld", |
| 1486 |
pj_atomic_get(tdata->ref_cnt))); |
| 1487 |
pjsip_tx_data_dec_ref(tdata); |
| 1488 |
return -50; |
| 1489 |
} |
| 1490 |
|
| 1491 |
|
| 1492 |
pjsip_tx_data_dec_ref(tdata); |
| 1493 |
|
| 1494 |
return PJ_SUCCESS; |
| 1495 |
|
| 1496 |
} |
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
static int tsx_basic_final_response_test(unsigned tid) |
| 1507 |
{ |
| 1508 |
unsigned duration; |
| 1509 |
int status; |
| 1510 |
|
| 1511 |
PJ_LOG(3,(THIS_FILE," test1: basic sending 2xx final response")); |
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
duration = (g[tid].tp_flag & PJSIP_TRANSPORT_RELIABLE) ? 1 : 33; |
| 1517 |
|
| 1518 |
status = perform_test(tid, g[tid].TARGET_URI, g[tid].FROM_URI, TEST1_BRANCH_ID, |
| 1519 |
duration, &pjsip_options_method, 1, 0, 0); |
| 1520 |
if (status != 0) |
| 1521 |
return status; |
| 1522 |
|
| 1523 |
PJ_LOG(3,(THIS_FILE," test2: basic sending non-2xx final response")); |
| 1524 |
|
| 1525 |
status = perform_test(tid, g[tid].TARGET_URI, g[tid].FROM_URI, TEST2_BRANCH_ID, |
| 1526 |
duration, &pjsip_options_method, 1, 0, 0); |
| 1527 |
if (status != 0) |
| 1528 |
return status; |
| 1529 |
|
| 1530 |
return 0; |
| 1531 |
} |
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
static int tsx_basic_provisional_response_test(unsigned tid) |
| 1541 |
{ |
| 1542 |
unsigned duration; |
| 1543 |
int status; |
| 1544 |
|
| 1545 |
PJ_LOG(3,(THIS_FILE," test3: basic sending 2xx final response")); |
| 1546 |
|
| 1547 |
duration = (g[tid].tp_flag & PJSIP_TRANSPORT_RELIABLE) ? 1 : 33; |
| 1548 |
duration += 2; |
| 1549 |
|
| 1550 |
status = perform_test(tid, g[tid].TARGET_URI, g[tid].FROM_URI, TEST3_BRANCH_ID, duration, |
| 1551 |
&pjsip_options_method, 1, 0, 0); |
| 1552 |
|
| 1553 |
return status; |
| 1554 |
} |
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
static int tsx_retransmit_last_response_test(unsigned tid, |
| 1566 |
const char *title, |
| 1567 |
char *branch_id, |
| 1568 |
int request_cnt, |
| 1569 |
int status_code) |
| 1570 |
{ |
| 1571 |
int status; |
| 1572 |
|
| 1573 |
PJ_LOG(3,(THIS_FILE," %s", title)); |
| 1574 |
|
| 1575 |
status = perform_test(tid, g[tid].TARGET_URI, g[tid].FROM_URI, branch_id, 5, |
| 1576 |
&pjsip_options_method, |
| 1577 |
request_cnt, 1000, 1); |
| 1578 |
if (status && status != TEST_TIMEOUT_ERROR) |
| 1579 |
return status; |
| 1580 |
if (!status) { |
| 1581 |
PJ_LOG(3,(THIS_FILE, " error: expecting timeout")); |
| 1582 |
return -31; |
| 1583 |
} |
| 1584 |
|
| 1585 |
terminate_our_tsx(tid, status_code); |
| 1586 |
flush_events(100); |
| 1587 |
|
| 1588 |
if (g[tid].test_complete != 1) |
| 1589 |
return g[tid].test_complete; |
| 1590 |
|
| 1591 |
flush_events(100); |
| 1592 |
return 0; |
| 1593 |
} |
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
static int tsx_final_response_retransmission_test(unsigned tid) |
| 1603 |
{ |
| 1604 |
int status; |
| 1605 |
|
| 1606 |
PJ_LOG(3,(THIS_FILE, |
| 1607 |
" test7: INVITE non-2xx final response retransmission")); |
| 1608 |
|
| 1609 |
status = perform_test(tid, g[tid].TARGET_URI, g[tid].FROM_URI, TEST7_BRANCH_ID, |
| 1610 |
33, |
| 1611 |
&pjsip_invite_method, 1, 0, 0); |
| 1612 |
if (status != 0) |
| 1613 |
return status; |
| 1614 |
|
| 1615 |
PJ_LOG(3,(THIS_FILE, |
| 1616 |
" test8: INVITE 2xx final response retransmission")); |
| 1617 |
|
| 1618 |
status = perform_test(tid, g[tid].TARGET_URI, g[tid].FROM_URI, TEST8_BRANCH_ID, |
| 1619 |
33, |
| 1620 |
&pjsip_invite_method, 1, 0, 0); |
| 1621 |
if (status != 0) |
| 1622 |
return status; |
| 1623 |
|
| 1624 |
return 0; |
| 1625 |
} |
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
static int tsx_ack_test(unsigned tid) |
| 1636 |
{ |
| 1637 |
int status; |
| 1638 |
|
| 1639 |
PJ_LOG(3,(THIS_FILE, |
| 1640 |
" test9: receiving ACK for non-2xx final response")); |
| 1641 |
|
| 1642 |
status = perform_test(tid, g[tid].TARGET_URI, g[tid].FROM_URI, TEST9_BRANCH_ID, |
| 1643 |
20, |
| 1644 |
&pjsip_invite_method, 1, 0, 0); |
| 1645 |
if (status != 0) |
| 1646 |
return status; |
| 1647 |
|
| 1648 |
|
| 1649 |
return 0; |
| 1650 |
} |
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
static int tsx_transport_failure_test(unsigned tid) |
| 1664 |
{ |
| 1665 |
struct test_desc |
| 1666 |
{ |
| 1667 |
int result; |
| 1668 |
int transport_delay; |
| 1669 |
int fail_delay; |
| 1670 |
char *branch_id; |
| 1671 |
char *title; |
| 1672 |
} tests[] = |
| 1673 |
{ |
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
{ 0, 0, 10, TEST10_BRANCH_ID, |
| 1679 |
"test10: failed transport in TRYING state (no delay)" }, |
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
{ 1, 50, 1500, TEST11_BRANCH_ID, |
| 1685 |
"test11: failed transport in PROCEEDING state (50 ms delay)" }, |
| 1686 |
{ 1, 0, 2500, TEST12_BRANCH_ID, |
| 1687 |
"test12: failed transport in COMPLETED state (no delay)" }, |
| 1688 |
|
| 1689 |
|
| 1690 |
}; |
| 1691 |
int i, status; |
| 1692 |
|
| 1693 |
for (i=0; i<(int)PJ_ARRAY_SIZE(tests); ++i) { |
| 1694 |
pj_time_val fail_time, end_test, now; |
| 1695 |
|
| 1696 |
PJ_LOG(3,(THIS_FILE, " %s", tests[i].title)); |
| 1697 |
pjsip_loop_set_failure(g[tid].loop, 0, NULL); |
| 1698 |
pjsip_loop_set_delay(g[tid].loop, tests[i].transport_delay); |
| 1699 |
|
| 1700 |
status = perform_test(tid, g[tid].TARGET_URI, g[tid].FROM_URI, tests[i].branch_id, |
| 1701 |
0, &pjsip_invite_method, 1, 0, 1); |
| 1702 |
if (status && status != TEST_TIMEOUT_ERROR) |
| 1703 |
return status; |
| 1704 |
if (!status) { |
| 1705 |
PJ_LOG(3,(THIS_FILE, " error: expecting timeout")); |
| 1706 |
return -40; |
| 1707 |
} |
| 1708 |
|
| 1709 |
pj_gettimeofday(&fail_time); |
| 1710 |
fail_time.msec += tests[i].fail_delay; |
| 1711 |
pj_time_val_normalize(&fail_time); |
| 1712 |
|
| 1713 |
do { |
| 1714 |
pj_time_val interval = { 0, 10 }; |
| 1715 |
pj_gettimeofday(&now); |
| 1716 |
pjsip_endpt_handle_events(endpt, &interval); |
| 1717 |
} while (PJ_TIME_VAL_LT(now, fail_time)); |
| 1718 |
|
| 1719 |
pjsip_loop_set_failure(g[tid].loop, 1, NULL); |
| 1720 |
PJ_LOG(5,(THIS_FILE, " transport loop fail mode set")); |
| 1721 |
|
| 1722 |
end_test = now; |
| 1723 |
end_test.sec += 33; |
| 1724 |
|
| 1725 |
do { |
| 1726 |
pj_time_val interval = { 0, 10 }; |
| 1727 |
pj_gettimeofday(&now); |
| 1728 |
pjsip_endpt_handle_events(endpt, &interval); |
| 1729 |
} while (!g[tid].test_complete && PJ_TIME_VAL_LT(now, end_test)); |
| 1730 |
|
| 1731 |
if (g[tid].test_complete != tests[i].result) { |
| 1732 |
PJ_LOG(3,(THIS_FILE, " error: expecting timeout")); |
| 1733 |
return -41; |
| 1734 |
} |
| 1735 |
} |
| 1736 |
|
| 1737 |
pjsip_endpt_stop_handle_events(endpt); |
| 1738 |
|
| 1739 |
return 0; |
| 1740 |
} |
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
int tsx_uas_test(unsigned tid) |
| 1749 |
{ |
| 1750 |
#define ERR(rc__) { status=rc__; goto on_return; } |
| 1751 |
struct tsx_test_param *param = &tsx_test[tid]; |
| 1752 |
int status; |
| 1753 |
|
| 1754 |
g[tid].test_param = param; |
| 1755 |
g[tid].tp_flag = pjsip_transport_get_flag_from_type((pjsip_transport_type_e)param->type); |
| 1756 |
|
| 1757 |
|
| 1758 |
g[tid].loop = NULL; |
| 1759 |
if (g[tid].test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { |
| 1760 |
PJ_TEST_SUCCESS(pjsip_loop_start(endpt, &g[tid].loop), |
| 1761 |
NULL, return -50); |
| 1762 |
pjsip_transport_add_ref(g[tid].loop); |
| 1763 |
} |
| 1764 |
|
| 1765 |
pj_ansi_snprintf(g[tid].TARGET_URI, sizeof(g[tid].TARGET_URI), |
| 1766 |
"sip:%[email protected]:%d;transport=%s", |
| 1767 |
tid, param->port, param->tp_type); |
| 1768 |
pj_ansi_snprintf(g[tid].FROM_URI, sizeof(g[tid].FROM_URI), |
| 1769 |
"sip:[email protected]:%d;transport=%s", |
| 1770 |
param->port, param->tp_type); |
| 1771 |
|
| 1772 |
|
| 1773 |
if ((status=register_modules(tid)) != PJ_SUCCESS) { |
| 1774 |
if (g[tid].loop) { |
| 1775 |
pjsip_transport_dec_ref(g[tid].loop); |
| 1776 |
g[tid].loop = NULL; |
| 1777 |
} |
| 1778 |
return -20; |
| 1779 |
} |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
status = tsx_basic_final_response_test(tid); |
| 1785 |
if (status != 0) |
| 1786 |
goto on_return; |
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
status = tsx_basic_provisional_response_test(tid); |
| 1791 |
if (status != 0) |
| 1792 |
goto on_return; |
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
status = tsx_retransmit_last_response_test(tid, TEST4_TITLE, |
| 1797 |
TEST4_BRANCH_ID, |
| 1798 |
TEST4_REQUEST_COUNT, |
| 1799 |
TEST4_STATUS_CODE); |
| 1800 |
if (status != 0) |
| 1801 |
goto on_return; |
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
status = tsx_retransmit_last_response_test(tid, TEST5_TITLE, |
| 1806 |
TEST5_BRANCH_ID, |
| 1807 |
TEST5_REQUEST_COUNT, |
| 1808 |
TEST5_STATUS_CODE); |
| 1809 |
if (status != 0) |
| 1810 |
goto on_return; |
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
if ((g[tid].tp_flag & PJSIP_TRANSPORT_RELIABLE) == 0) { |
| 1818 |
status = tsx_retransmit_last_response_test(tid, TEST6_TITLE, |
| 1819 |
TEST6_BRANCH_ID, |
| 1820 |
TEST6_REQUEST_COUNT, |
| 1821 |
TEST6_STATUS_CODE); |
| 1822 |
if (status != 0) |
| 1823 |
goto on_return; |
| 1824 |
} |
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
status = tsx_final_response_retransmission_test(tid); |
| 1830 |
if (status != 0) |
| 1831 |
goto on_return; |
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
if ((g[tid].tp_flag & PJSIP_TRANSPORT_RELIABLE) == 0) { |
| 1838 |
status = tsx_ack_test(tid); |
| 1839 |
if (status != 0) |
| 1840 |
goto on_return; |
| 1841 |
} |
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
if (param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { |
| 1850 |
status = tsx_transport_failure_test(tid); |
| 1851 |
if (status != 0) |
| 1852 |
goto on_return; |
| 1853 |
} |
| 1854 |
|
| 1855 |
status = 0; |
| 1856 |
|
| 1857 |
on_return: |
| 1858 |
|
| 1859 |
if (g[tid].loop) { |
| 1860 |
|
| 1861 |
pjsip_transport_shutdown(g[tid].loop); |
| 1862 |
pjsip_transport_dec_ref(g[tid].loop); |
| 1863 |
g[tid].loop = NULL; |
| 1864 |
} |
| 1865 |
|
| 1866 |
unregister_modules(tid); |
| 1867 |
return status; |
| 1868 |
} |