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