Debian Codegraph @

Xpjproject/pjsip/src/test/tsx_uas_test.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 ** UAS tests.
30 **
31 ** This file performs various tests for UAC transactions. Each test will have
32 ** a different Via branch param so that message receiver module and
33 ** transaction user module can identify which test is being carried out.
34 **
35 ** TEST1_BRANCH_ID
36 ** Test that non-INVITE transaction returns 2xx response to the correct
37 ** transport and correctly terminates the transaction.
38 ** This also checks that transaction is destroyed immediately after
39 ** it sends final response when reliable transport is used.
40 **
41 ** TEST2_BRANCH_ID
42 ** As above, for non-2xx final response.
43 **
44 ** TEST3_BRANCH_ID
45 ** Transaction correctly progressing to PROCEEDING state when provisional
46 ** response is sent.
47 **
48 ** TEST4_BRANCH_ID
49 ** Transaction retransmits last response (if any) without notifying
50 ** transaction user upon receiving request retransmissions on TRYING
51 ** state
52 **
53 ** TEST5_BRANCH_ID
54 ** As above, in PROCEEDING state.
55 **
56 ** TEST6_BRANCH_ID
57 ** As above, in COMPLETED state, with first sending provisional response.
58 ** (Only applicable for non-reliable transports).
59 **
60 ** TEST7_BRANCH_ID
61 ** INVITE transaction MUST retransmit non-2xx final response.
62 **
63 ** TEST8_BRANCH_ID
64 ** As above, for INVITE's 2xx final response (this is PJSIP specific).
65 **
66 ** TEST9_BRANCH_ID
67 ** INVITE transaction MUST cease retransmission of final response when
68 ** ACK is received. (Note: PJSIP also retransmit 2xx final response
69 ** until it's terminated by user).
70 ** Transaction also MUST terminate in T4 seconds.
71 ** (Only applicable for non-reliable transports).
72 **
73 ** TEST11_BRANCH_ID
74 ** Test scenario where transport fails before response is sent (i.e.
75 ** in TRYING state).
76 **
77 ** TEST12_BRANCH_ID
78 ** As above, after provisional response is sent but before final
79 ** response is sent (i.e. in PROCEEDING state).
80 **
81 ** TEST13_BRANCH_ID
82 ** As above, for INVITE, after final response has been sent but before
83 ** ACK is received (i.e. in CONNECTED state).
84 **
85 ** TEST14_BRANCH_ID
86 ** When UAS failed to deliver the response with the selected transport,
87 ** it should try contacting the client with other transport or begin
88 ** RFC 3263 server resolution procedure.
89 ** This should be tested on:
90 ** a. TRYING state (when delivering first response).
91 ** b. PROCEEDING state (when failed to retransmit last response
92 ** upon receiving request retransmission).
93 ** c. COMPLETED state.
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 //#define TEST13_BRANCH_ID (PJSIP_RFC3261_BRANCH_ID "-UAS-Test13")
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 /* Must be final */
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 /* Must be non-2xx */
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 /* Since several tsx_uas_test() may run concurrently, keep the global vars
137 * in array indexed according to the test index (tid)
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 /* Static vars, which will be reset on each test. */
147 int recv_count;
148 pj_time_val recv_last;
149 pj_bool_t test_complete;
150
151 /* Loop transport instance. */
152 pjsip_transport *loop;
153
154 /* UAS transaction key. */
155 char key_buf[64];
156 pj_str_t tsx_key;
157
158 /* General timer entry to be used by tests. */
159 //pj_timer_entry timer;
160
161 pj_bool_t modules_registered;
162
163 } g[MAX_TSX_TESTS];
164
165 #define TEST_TIMEOUT_ERROR -30
166
167 /* Widen timing tolerance in CI mode — shared runners can be 5-10x slower. */
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 /* UAC transaction user module. */
174 static pjsip_module tsx_user =
175 {
176 NULL, NULL, /* prev and next */
177 { "Tsx-UAS-User", 12}, /* Name. */
178 -1, /* Id */
179 PJSIP_MOD_PRIORITY_UA_PROXY_LAYER-1,/* Priority */
180 NULL, /* load() */
181 NULL, /* start() */
182 NULL, /* stop() */
183 NULL, /* unload() */
184 NULL, /* on_rx_request() */
185 NULL, /* on_rx_response() */
186 NULL, /* on_tx_request() */
187 NULL, /* on_tx_response() */
188 &tsx_user_on_tsx_state, /* on_tsx_state() */
189 };
190
191 /* Module to send request. */
192 static pjsip_module msg_sender =
193 {
194 NULL, NULL, /* prev and next */
195 { "Msg-Sender", 10}, /* Name. */
196 -1, /* Id */
197 PJSIP_MOD_PRIORITY_UA_PROXY_LAYER-1,/* Priority */
198 NULL, /* load() */
199 NULL, /* start() */
200 NULL, /* stop() */
201 NULL, /* unload() */
202 &on_rx_message, /* on_rx_request() */
203 &on_rx_message, /* on_rx_response() */
204 NULL, /* on_tx_request() */
205 NULL, /* on_tx_response() */
206 NULL, /* on_tsx_state() */
207 };
208
209 /* Timer to send response via transaction. */
210 struct response
211 {
212 pj_str_t tsx_key;
213 pjsip_tx_data *tdata;
214 };
215
216 /* Get test ID from transaction instance */
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 /* Must select specific transport to use for loop */
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 /* Register modules, taking care of multiple re-registration attempts */
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 /* Make sure modules are registered, wait if necessary */
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 /* Unregister modules, taking care of premature unregistration attempt */
286 static void unregister_modules(unsigned tid)
287 {
288 // int new_reg_cnt;
289
290 if (!g[tid].modules_registered)
291 return;
292
293 g[tid].modules_registered = 0;
294
295 // Note:
296 // on_tsx_state() can be called much later during pjsip shutdown
297 // i.e. when transaction layer is being destroyed. If we unregister
298 // the modules, get_tsx_tid() will fail with assertion.
299 // So just let the module registered.
300 return;
301
302 /*
303 pj_enter_critical_section();
304 new_reg_cnt = --modules_reg_cnt;
305 pj_leave_critical_section();
306
307 if (new_reg_cnt == 0) {
308 PJ_TEST_SUCCESS(pjsip_endpt_unregister_module(endpt, &tsx_user),
309 "error ignored", {});
310 PJ_TEST_SUCCESS(pjsip_endpt_unregister_module(endpt, &msg_sender),
311 "error ignored", {});
312 }
313 */
314 }
315
316 /* Timer callback to send response. */
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 // Some tests do expect failure!
336 //PJ_LOG(3,(THIS_FILE," error: timer unable to send response"));
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 /* Utility to send response. */
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 // Some tests do expect failure!
366 //app_perror(" error: unable to send response", status);
367 //g[tid].test_complete = -197;
368 return;
369 }
370 }
371
372 /* Schedule timer to send response for the specified UAS transaction */
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 /* Find and terminate tsx with the specified key. */
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 /* Unused for now */
431 /* Timer callback to terminate transaction. */
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 /* Schedule timer to terminate transaction. */
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 * This is the handler to receive state changed notification from the
461 * transaction. It is used to verify that the transaction behaves according
462 * to the test scenario.
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 * TEST1_BRANCH_ID tests that non-INVITE transaction transmits final
491 * response using correct transport and terminates transaction after
492 * T4 (PJSIP_T4_TIMEOUT, 5 seconds).
493 *
494 * TEST2_BRANCH_ID does similar test for non-2xx final response.
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 /* Check that status code is status_code. */
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 /* Previous state must be completed. */
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 /* Previous state must be TRYING. */
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 * TEST3_BRANCH_ID tests sending provisional response.
529 */
530 if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
531
532 g[tid].test_complete = 1;
533
534 /* Check that status code is status_code. */
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 /* Previous state must be completed. */
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 /* Previous state must be TRYING. */
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 /* Check that status code is status_code. */
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 /* Check that event must be TX_MSG */
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 /* Previous state must be PROCEEDING. */
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 /* Check that status code is status_code. */
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 /* Check that event must be TX_MSG */
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 * TEST4_BRANCH_ID tests receiving retransmissions in TRYING state.
592 */
593 if (tsx->state == PJSIP_TSX_STATE_TRYING) {
594 /* Request is received. */
595 } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
596
597 /* Check that status code is status_code. */
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 /* Previous state. */
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 * TEST5_BRANCH_ID tests receiving retransmissions in PROCEEDING state
625 */
626 if (tsx->state == PJSIP_TSX_STATE_TRYING) {
627 /* Request is received. */
628
629 } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
630
631 /* Check that status code is status_code. */
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 /* Previous state. */
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 /* Check status code. */
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 * TEST6_BRANCH_ID tests receiving retransmissions in COMPLETED state
662 */
663 if (tsx->state == PJSIP_TSX_STATE_TRYING) {
664 /* Request is received. */
665
666 } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
667
668 /* Check that status code is status_code. */
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 /* Previous state. */
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 * TEST7_BRANCH_ID and TEST8_BRANCH_ID test retransmission of
699 * INVITE final response
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 /* Request is received. */
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 /* Check status code. */
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 /* Previous state. */
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 /* Check the number of retransmissions */
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 /* Check that status code is status_code. */
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 /* Previous state. */
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 * TEST9_BRANCH_ID tests that retransmission of INVITE final response
775 * must cease when ACK is received.
776 */
777
778 if (tsx->state == PJSIP_TSX_STATE_TRYING) {
779 /* Request is received. */
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 /* Check status code. */
787 PJ_TEST_EQ(tsx->status_code, TEST9_STATUS_CODE, NULL,
788 g[tid].test_complete = -160);
789
790 /* Previous state. */
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 /* Check that status code is status_code. */
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 /* Previous state. */
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 /* Check that status code is status_code. */
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 /* Previous state. */
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 // PJSIP_SC_TSX_TRANSPORT_ERROR,
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 // PJSIP_SC_TSX_TRANSPORT_ERROR,
864 tsx->status_code));
865 g[tid].test_complete = -170;
866 }
867 }
868 }
869 }
870
871 /* Save transaction key to global variables. */
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 * Message receiver handler.
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 /* Not our message */
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 * TEST1_BRANCH_ID tests that non-INVITE transaction transmits 2xx
916 * final response using correct transport and terminates transaction
917 * after 32 seconds.
918 *
919 * TEST2_BRANCH_ID performs similar test for non-2xx final response.
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 /* On received request, create UAS and respond with final
926 * response.
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 /* Verify the response received. */
944
945 ++g[tid].recv_count;
946
947 /* Verify status code. */
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 /* Verify that no retransmissions is received. */
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 /* TEST3_BRANCH_ID tests provisional response. */
966
967 if (msg->type == PJSIP_REQUEST_MSG) {
968 /* On received request, create UAS and respond with provisional
969 * response, then schedule timer to send final response.
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 /* Verify the response received. */
990
991 ++g[tid].recv_count;
992
993 if (g[tid].recv_count == 1) {
994 /* Verify status code. */
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 /* Verify status code. */
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 /* TEST4_BRANCH_ID: absorbs retransmissions in TRYING state. */
1019 /* TEST5_BRANCH_ID: retransmit last response in PROCEEDING state. */
1020 /* TEST6_BRANCH_ID: retransmit last response in COMPLETED state. */
1021
1022 if (msg->type == PJSIP_REQUEST_MSG) {
1023 /* On received request, create UAS. */
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 /* Verify the response received. */
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 * TEST7_BRANCH_ID and TEST8_BRANCH_ID test the retransmission
1107 * of INVITE final response
1108 */
1109 if (msg->type == PJSIP_REQUEST_MSG) {
1110
1111 /* On received request, create UAS. */
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 * TEST9_BRANCH_ID tests that the retransmission of INVITE final
1192 * response should cease when ACK is received. Transaction also MUST
1193 * terminate in T4 seconds.
1194 */
1195 if (msg->type == PJSIP_REQUEST_MSG) {
1196
1197 /* On received request, create UAS. */
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 /* Let UAS retransmit some messages before we send ACK. */
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 /* On received response, create UAS. */
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 * The generic test framework, used by most of the tests.
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 /* Reset test. */
1376 g[tid].recv_count = 0;
1377 g[tid].test_complete = 0;
1378 g[tid].tsx_key.slen = 0;
1379
1380 /* Init headers. */
1381 target = pj_str(target_uri);
1382 from = pj_str(from_uri);
1383
1384 /* Create request. */
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 /* Set the branch param. Note that other tsx_uas_test() instances may
1394 * be running simultaneously, thus the branch ID needs to be made unique
1395 * by adding tid */
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 /* Must select specific transport to use */
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 /* Schedule first send. */
1411 sent_cnt = 0;
1412 pj_gettimeofday(&next_send);
1413 pj_time_val_normalize(&next_send);
1414
1415 /* Set test completion time. */
1416 pj_gettimeofday(&timeout);
1417 timeout.sec += test_time;
1418
1419 /* Wait until test complete. */
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 /* Add additional reference to tdata to prevent transaction from
1429 * deleting it.
1430 */
1431 pjsip_tx_data_add_ref(tdata);
1432
1433 /* (Re)Send the request. */
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 /* Schedule next send, if any. */
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 /* Allow transaction to destroy itself */
1474 flush_events(500);
1475
1476 /* Make sure transaction has been destroyed. */
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 /* Check tdata reference counter. */
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 /* Destroy txdata */
1492 pjsip_tx_data_dec_ref(tdata);
1493
1494 return PJ_SUCCESS;
1495
1496 }
1497
1498
1499 /*****************************************************************************
1500 **
1501 ** TEST1_BRANCH_ID: Basic 2xx final response
1502 ** TEST2_BRANCH_ID: Basic non-2xx final response
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 /* Test duration must be greater than 32 secs if unreliable transport
1514 * is used.
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 ** TEST3_BRANCH_ID: Sending provisional response
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 ** TEST4_BRANCH_ID: Absorbs retransmissions in TRYING state
1560 ** TEST5_BRANCH_ID: Absorbs retransmissions in PROCEEDING state
1561 ** TEST6_BRANCH_ID: Absorbs retransmissions in COMPLETED state
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 ** TEST7_BRANCH_ID: INVITE non-2xx final response retransmission test
1598 ** TEST8_BRANCH_ID: INVITE 2xx final response retransmission test
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, /* Test duration must be greater than 32 secs */
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, /* Test duration must be greater than 32 secs */
1620 &pjsip_invite_method, 1, 0, 0);
1621 if (status != 0)
1622 return status;
1623
1624 return 0;
1625 }
1626
1627
1628 /*****************************************************************************
1629 **
1630 ** TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must
1631 ** cease when ACK is received
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, /* allow 5 retransmissions */
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 ** TEST10_BRANCH_ID: test transport failure in TRYING state.
1657 ** TEST11_BRANCH_ID: test transport failure in PROCEEDING state.
1658 ** TEST12_BRANCH_ID: test transport failure in CONNECTED state.
1659 ** TEST13_BRANCH_ID: test transport failure in CONFIRMED state.
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 // After #3805 and #3806, transport error will be ignored and
1675 // the tests will time out.
1676 // All tests are valid, but it will take too long to complete,
1677 // so we disable some of the similar ones.
1678 { 0, 0, 10, TEST10_BRANCH_ID,
1679 "test10: failed transport in TRYING state (no delay)" },
1680 //{ 0, 50, 10, TEST10_BRANCH_ID,
1681 // "test10: failed transport in TRYING state (50 ms delay)" },
1682 //{ 1, 0, 1500, TEST11_BRANCH_ID,
1683 // "test11: failed transport in PROCEEDING state (no delay)" },
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 //{ 1, 50, 2500, TEST12_BRANCH_ID,
1689 // "test12: failed transport in COMPLETED state (50 ms delay)" },
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 ** UAS Transaction Test.
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 /* Create loop transport */
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 /* Register modules. */
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 /* TEST1_BRANCH_ID: Basic 2xx final response.
1782 * TEST2_BRANCH_ID: Basic non-2xx final response.
1783 */
1784 status = tsx_basic_final_response_test(tid);
1785 if (status != 0)
1786 goto on_return;
1787
1788 /* TEST3_BRANCH_ID: with provisional response
1789 */
1790 status = tsx_basic_provisional_response_test(tid);
1791 if (status != 0)
1792 goto on_return;
1793
1794 /* TEST4_BRANCH_ID: absorbs retransmissions in TRYING state
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 /* TEST5_BRANCH_ID: retransmit last response in PROCEEDING state
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 /* TEST6_BRANCH_ID: retransmit last response in COMPLETED state
1813 * This only applies to non-reliable transports,
1814 * since UAS transaction is destroyed as soon
1815 * as final response is sent for reliable transports.
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 /* TEST7_BRANCH_ID: INVITE non-2xx final response retransmission test
1827 * TEST8_BRANCH_ID: INVITE 2xx final response retransmission test
1828 */
1829 status = tsx_final_response_retransmission_test(tid);
1830 if (status != 0)
1831 goto on_return;
1832
1833 /* TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must
1834 * cease when ACK is received
1835 * Only applicable for non-reliable transports.
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 /* TEST10_BRANCH_ID: test transport failure in TRYING state.
1844 * TEST11_BRANCH_ID: test transport failure in PROCEEDING state.
1845 * TEST12_BRANCH_ID: test transport failure in CONNECTED state.
1846 * TEST13_BRANCH_ID: test transport failure in CONFIRMED state.
1847 */
1848 /* Only valid for loop-dgram */
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 /* Order must be shutdown then dec_ref so it gets destroyed */
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 }