Changeset 2188 for pjproject/trunk/pjsip/src/test-pjsip/transport_test.c
- Timestamp:
- Aug 4, 2008 10:52:51 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/test-pjsip/transport_test.c
r2039 r2188 642 642 return 0; 643 643 } 644 645 /////////////////////////////////////////////////////////////////////////////// 646 /* 647 * Transport load testing 648 */ 649 static pj_bool_t load_on_rx_request(pjsip_rx_data *rdata); 650 651 static struct mod_load_test 652 { 653 pjsip_module mod; 654 pj_uint32_t next_seq; 655 pj_bool_t err; 656 } mod_load = 657 { 658 { 659 NULL, NULL, /* prev and next */ 660 { "mod-load-test", 13}, /* Name. */ 661 -1, /* Id */ 662 PJSIP_MOD_PRIORITY_TSX_LAYER-1, /* Priority */ 663 NULL, /* load() */ 664 NULL, /* start() */ 665 NULL, /* stop() */ 666 NULL, /* unload() */ 667 &load_on_rx_request, /* on_rx_request() */ 668 NULL, /* on_rx_response() */ 669 NULL, /* tsx_handler() */ 670 } 671 }; 672 673 674 static pj_bool_t load_on_rx_request(pjsip_rx_data *rdata) 675 { 676 if (rdata->msg_info.cseq->cseq != mod_load.next_seq) { 677 PJ_LOG(1,("THIS_FILE", " err: expecting cseq %u, got %u", 678 mod_load.next_seq, rdata->msg_info.cseq->cseq)); 679 mod_load.err = PJ_TRUE; 680 mod_load.next_seq = rdata->msg_info.cseq->cseq + 1; 681 } else 682 mod_load.next_seq++; 683 return PJ_TRUE; 684 } 685 686 int transport_load_test(char *target_url) 687 { 688 enum { COUNT = 2000 }; 689 unsigned i; 690 pj_status_t status; 691 692 /* exhaust packets */ 693 do { 694 pj_time_val delay = {1, 0}; 695 i = 0; 696 pjsip_endpt_handle_events2(endpt, &delay, &i); 697 } while (i != 0); 698 699 PJ_LOG(3,(THIS_FILE, " transport load test...")); 700 701 if (mod_load.mod.id == -1) { 702 status = pjsip_endpt_register_module( endpt, &mod_load.mod); 703 if (status != PJ_SUCCESS) { 704 app_perror("error registering module", status); 705 return -1; 706 } 707 } 708 mod_load.err = PJ_FALSE; 709 mod_load.next_seq = 0; 710 711 for (i=0; i<COUNT && !mod_load.err; ++i) { 712 pj_str_t target, from, call_id; 713 pjsip_tx_data *tdata; 714 715 target = pj_str(target_url); 716 from = pj_str("<sip:user@host>"); 717 call_id = pj_str("thecallid"); 718 status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, 719 &target, &from, 720 &target, &from, &call_id, 721 i, NULL, &tdata ); 722 if (status != PJ_SUCCESS) { 723 app_perror("error creating request", status); 724 goto on_return; 725 } 726 727 status = pjsip_endpt_send_request_stateless(endpt, tdata, NULL, NULL); 728 if (status != PJ_SUCCESS) { 729 app_perror("error sending request", status); 730 goto on_return; 731 } 732 } 733 734 do { 735 pj_time_val delay = {1, 0}; 736 i = 0; 737 pjsip_endpt_handle_events2(endpt, &delay, &i); 738 } while (i != 0); 739 740 if (mod_load.next_seq != COUNT) { 741 PJ_LOG(1,("THIS_FILE", " err: expecting %u msg, got only %u", 742 COUNT, mod_load.next_seq)); 743 status = -2; 744 goto on_return; 745 } 746 747 on_return: 748 if (mod_load.mod.id != -1) { 749 pjsip_endpt_unregister_module( endpt, &mod_load.mod); 750 mod_load.mod.id = -1; 751 } 752 if (status != PJ_SUCCESS || mod_load.err) { 753 return -2; 754 } 755 PJ_LOG(3,(THIS_FILE, " success")); 756 return 0; 757 } 758 759
Note: See TracChangeset
for help on using the changeset viewer.