blob: 0d178151ff67a89e737dd20155355f3019ab0742 [file] [log] [blame]
Benny Prijonoff1df042008-06-06 14:47:10 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijonoff1df042008-06-06 14:47:10 +00005 *
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.
10 *
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.
15 *
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
19 */
20#ifndef __PJNATH_TEST_SERVER_H__
21#define __PJNATH_TEST_SERVER_H__
22
23#include <pjnath.h>
24#include <pjlib-util.h>
25#include <pjlib.h>
26
27#define DNS_SERVER_PORT 55533
28#define STUN_SERVER_PORT 33478
29#define TURN_SERVER_PORT 33479
30
31#define TURN_USERNAME "auser"
32#define TURN_PASSWD "apass"
33
34#define MAX_TURN_ALLOC 16
35#define MAX_TURN_PERM 16
36
37enum test_server_flags
38{
39 CREATE_DNS_SERVER = (1 << 0),
40 CREATE_A_RECORD_FOR_DOMAIN = (1 << 1),
41
42 CREATE_STUN_SERVER = (1 << 5),
43 CREATE_STUN_SERVER_DNS_SRV = (1 << 6),
44
45 CREATE_TURN_SERVER = (1 << 10),
46 CREATE_TURN_SERVER_DNS_SRV = (1 << 11),
47
48};
49
50typedef struct test_server test_server;
51
52/* TURN allocation */
53typedef struct turn_allocation
54{
55 test_server *test_srv;
56 pj_pool_t *pool;
57 pj_activesock_t *sock;
58 pj_ioqueue_op_key_t send_key;
59 pj_sockaddr client_addr;
60 pj_sockaddr alloc_addr;
61 unsigned perm_cnt;
62 pj_sockaddr perm[MAX_TURN_PERM];
Benny Prijono7925fb32009-05-12 10:14:52 +000063 unsigned chnum[MAX_TURN_PERM];
Benny Prijonoff1df042008-06-06 14:47:10 +000064 pj_stun_msg *data_ind;
65} turn_allocation;
66
67/*
68 * Server installation for testing.
69 * This comprises of DNS server, STUN server, and TURN server.
70 */
71struct test_server
72{
73 pj_pool_t *pool;
74 pj_uint32_t flags;
75 pj_stun_config *stun_cfg;
76 pj_ioqueue_op_key_t send_key;
77
78 pj_dns_server *dns_server;
79
80 pj_activesock_t *stun_sock;
81
82 pj_activesock_t *turn_sock;
83 unsigned turn_alloc_cnt;
84 turn_allocation turn_alloc[MAX_TURN_ALLOC];
85 pj_bool_t turn_respond_allocate;
86 pj_bool_t turn_respond_refresh;
87
88 struct turn_stat {
89 unsigned rx_allocate_cnt;
90 unsigned rx_refresh_cnt;
91 unsigned rx_send_ind_cnt;
92 } turn_stat;
93
94 pj_str_t domain;
95 pj_str_t username;
96 pj_str_t passwd;
97
98};
99
100
101pj_status_t create_test_server(pj_stun_config *stun_cfg,
102 pj_uint32_t flags,
103 const char *domain,
104 test_server **p_test_srv);
105void destroy_test_server(test_server *test_srv);
106void test_server_poll_events(test_server *test_srv);
107
108
109#endif /* __PJNATH_TEST_SERVER_H__ */
110