1
/* $Id: transport_udp_test.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#define THIS_FILE "transport_udp_test.c"
31
int transport_udp_test(void)
33
enum { SEND_RECV_LOOP = 8 };
34
pjsip_transport *udp_tp, *tp;
35
pj_sockaddr_in addr, rem_addr;
38
int rtt[SEND_RECV_LOOP], min_rtt;
41
pj_sockaddr_in_init(&addr, NULL, TEST_UDP_PORT);
43
/* Start UDP transport. */
44
status = pjsip_udp_transport_start( endpt, &addr, NULL, 1, &udp_tp);
45
if (status != PJ_SUCCESS) {
46
app_perror(" Error: unable to start UDP transport", status);
50
/* UDP transport must have initial reference counter set to 1. */
51
if (pj_atomic_get(udp_tp->ref_cnt) != 1)
54
/* Test basic transport attributes */
55
status = generic_transport_test(udp_tp);
56
if (status != PJ_SUCCESS)
59
/* Test that transport manager is returning the correct
62
pj_sockaddr_in_init(&rem_addr, pj_cstr(&s, "1.1.1.1"), 80);
63
status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_UDP,
64
&rem_addr, sizeof(rem_addr),
66
if (status != PJ_SUCCESS)
71
/* pjsip_endpt_acquire_transport() adds reference, so we need
74
pjsip_transport_dec_ref(tp);
76
/* Check again that reference counter is 1. */
77
if (pj_atomic_get(udp_tp->ref_cnt) != 1)
80
/* Basic transport's send/receive loopback test. */
81
pj_sockaddr_in_init(&rem_addr, pj_cstr(&s, "127.0.0.1"), TEST_UDP_PORT);
82
for (i=0; i<SEND_RECV_LOOP; ++i) {
83
status = transport_send_recv_test(PJSIP_TRANSPORT_UDP, tp,
84
"sip:alice@127.0.0.1:"TEST_UDP_PORT_STR,
91
for (i=0; i<SEND_RECV_LOOP; ++i)
92
if (rtt[i] < min_rtt) min_rtt = rtt[i];
94
report_ival("udp-rtt-usec", min_rtt, "usec",
95
"Best UDP transport round trip time, in microseconds "
96
"(time from sending request until response is received. "
97
"Tests were performed on local machine only)");
100
/* Multi-threaded round-trip test. */
101
status = transport_rt_test(PJSIP_TRANSPORT_UDP, tp,
102
"sip:alice@127.0.0.1:"TEST_UDP_PORT_STR,
108
PJ_LOG(3,(THIS_FILE, " note: %d packet(s) was lost", pkt_lost));
110
/* Check again that reference counter is 1. */
111
if (pj_atomic_get(udp_tp->ref_cnt) != 1)
114
/* Destroy this transport. */
115
pjsip_transport_dec_ref(udp_tp);
117
/* Force destroy this transport. */
118
status = pjsip_transport_destroy(udp_tp);
119
if (status != PJ_SUCCESS)
123
PJ_LOG(3,(THIS_FILE, " Flushing events, 1 second..."));