~ubuntu-branches/ubuntu/lucid/sip-tester/lucid

« back to all changes in this revision

Viewing changes to sipp.hpp

  • Committer: Bazaar Package Importer
  • Author(s): ARAKI Yasuhiro
  • Date: 2005-04-11 11:53:53 UTC
  • Revision ID: james.westby@ubuntu.com-20050411115353-o33qn3noyjwjgnpd
Tags: upstream-1.1rc1
ImportĀ upstreamĀ versionĀ 1.1rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  This program is free software; you can redistribute it and/or modify
 
3
 *  it under the terms of the GNU General Public License as published by
 
4
 *  the Free Software Foundation; either version 2 of the License, or
 
5
 *  (at your option) any later version.
 
6
 *
 
7
 *  This program is distributed in the hope that it will be useful,
 
8
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
 *  GNU General Public License for more details.
 
11
 *
 
12
 *  You should have received a copy of the GNU General Public License
 
13
 *  along with this program; if not, write to the Free Software
 
14
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
 
15
 *
 
16
 *  Author : Richard GAYRAUD - 04 Nov 2003
 
17
 *           From Hewlett Packard Company.
 
18
 */
 
19
 
 
20
#ifndef __SIPP__
 
21
#define __SIPP__
 
22
 
 
23
/* Std C includes */
 
24
 
 
25
#include <stdio.h>
 
26
#include <stdlib.h>
 
27
#include <string.h>
 
28
#include <pthread.h>
 
29
#include <sys/types.h>
 
30
#include <sys/socket.h>
 
31
#include <netinet/in.h>
 
32
#include <netinet/tcp.h>
 
33
#include <sys/time.h>
 
34
#include <sys/poll.h>
 
35
#include <sys/resource.h>
 
36
#include <fcntl.h>
 
37
#include <unistd.h>
 
38
#include <arpa/inet.h>
 
39
#include <errno.h>
 
40
#include <netdb.h>
 
41
#include <ctype.h>
 
42
#include <signal.h>
 
43
#include <time.h>
 
44
#include <vector>
 
45
#include <string>
 
46
 
 
47
/* Sipp includes */
 
48
 
 
49
#include "xp_parser.h"
 
50
#include "scenario.hpp"
 
51
#include "screen.hpp"
 
52
#include "call.hpp"
 
53
#include "comp.h"
 
54
#include "stat.hpp"
 
55
#include "actions.hpp"
 
56
#include "variables.hpp"
 
57
/* Open SSL stuff */
 
58
#ifdef _USE_OPENSSL
 
59
#include "sslcommon.h" 
 
60
#endif
 
61
 
 
62
 
 
63
#ifndef __CYGWIN
 
64
#ifndef FD_SETSIZE
 
65
#define FD_SETSIZE 65000
 
66
#endif
 
67
#else
 
68
#ifndef FD_SETSIZE
 
69
#define FD_SETSIZE 1024
 
70
#endif
 
71
#endif
 
72
 
 
73
/* 
 
74
 * If this files is included in the Main, then extern definitions
 
75
 * are removed, and the _DEFAULT macro becomes '= value;'. Else 
 
76
 * extern definition does not contain default values assignment
 
77
 */
 
78
 
 
79
#ifdef GLOBALS_FULL_DEFINITION
 
80
#define extern
 
81
#define _DEFVAL(value) = value
 
82
#else
 
83
#define _DEFVAL(value)
 
84
#endif
 
85
 
 
86
/************************** Constants **************************/
 
87
 
 
88
#define T_UDP                      0
 
89
#define T_TCP                      1
 
90
#ifdef _USE_OPENSSL
 
91
#define T_TLS                      2
 
92
#endif
 
93
#define TRANSPORT_TO_STRING(p)     ((p==1) ? "TCP" : ((p==2)? "TLS" :"UDP"))
 
94
 
 
95
#define SIPP_MAXFDS                65536
 
96
#define SIPP_MAX_MSG_SIZE          65536
 
97
 
 
98
#define MSG_RETRANS_FIRST          0
 
99
#define MSG_RETRANS_RETRANSMISSION 1
 
100
#define MSG_RETRANS_NEVER          2
 
101
 
 
102
#define DISPLAY_STAT_SCREEN        1
 
103
#define DISPLAY_REPARTITION_SCREEN 2
 
104
#define DISPLAY_SCENARIO_SCREEN    3
 
105
#define DISPLAY_VARIABLE_SCREEN    4
 
106
 
 
107
#define MAX_RECV_LOOPS             1000
 
108
 
 
109
/******************** Default parameters ***********************/
 
110
 
 
111
#define DEFAULT_RATE                 10.0
 
112
#define DEFAULT_RATE_PERIOD_S        1.0
 
113
#define DEFAULT_TRANSPORT            T_UDP
 
114
#define DEFAULT_PORT                 5060  
 
115
#ifdef __3PCC__
 
116
#define DEFAULT_3PCC_PORT            6060
 
117
#endif
 
118
#define DEFAULT_SERVICE              ((char *)"service")
 
119
#define DEFAULT_AUTH_PASSWORD        ((char *)"password")
 
120
#define DEFAULT_REPORT_FREQ          1000
 
121
#define DEFAULT_REPORT_FREQ_DUMP_LOG 60000
 
122
#define DEFAULT_TIMER_RESOLUTION     200
 
123
 
 
124
/************ User controls and command line options ***********/
 
125
 
 
126
extern int                duration                _DEFVAL(0);
 
127
extern double             rate                    _DEFVAL(DEFAULT_RATE);
 
128
extern double             rate_period_s           _DEFVAL(DEFAULT_RATE_PERIOD_S);
 
129
extern int                transport               _DEFVAL(DEFAULT_TRANSPORT);
 
130
extern int                retrans_enabled         _DEFVAL(1);
 
131
extern int                default_behavior        _DEFVAL(1);
 
132
extern int                multisocket             _DEFVAL(0);
 
133
extern int                compression             _DEFVAL(0);
 
134
extern void             * monosocket_comp_state   _DEFVAL(0);
 
135
extern char             * service                 _DEFVAL(DEFAULT_SERVICE);
 
136
extern char             * auth_password           _DEFVAL(DEFAULT_AUTH_PASSWORD);
 
137
extern unsigned long      report_freq             _DEFVAL(DEFAULT_REPORT_FREQ);
 
138
extern unsigned long      report_freq_dumpLog     _DEFVAL
 
139
                                                (DEFAULT_REPORT_FREQ_DUMP_LOG);
 
140
extern char               local_ip[40];
 
141
extern char               local_ip_escaped[42];
 
142
extern int                local_port              _DEFVAL(0);
 
143
extern char               media_ip[40];
 
144
extern char               media_ip_escaped[42];
 
145
extern int                media_port              _DEFVAL(0);
 
146
extern char               remote_ip[40];
 
147
extern char               remote_ip_escaped[42];
 
148
extern int                remote_port             _DEFVAL(DEFAULT_PORT);
 
149
extern unsigned int       pid                     _DEFVAL(0);
 
150
extern int                print_all_responses     _DEFVAL(0);
 
151
extern unsigned long      stop_after              _DEFVAL(0xffffffff);
 
152
extern int                quitting                _DEFVAL(0);
 
153
extern int                interrupt               _DEFVAL(0);
 
154
extern int                paused                  _DEFVAL(0);
 
155
extern int                lose_packets            _DEFVAL(0);
 
156
extern char               remote_host[255]; 
 
157
#ifdef __3PCC__
 
158
extern char               twinSippHost[255];
 
159
extern char               twinSippIp[40];
 
160
extern int                twinSippPort            _DEFVAL(DEFAULT_3PCC_PORT);
 
161
extern bool               twinSippMode            _DEFVAL(false);
 
162
#endif
 
163
extern bool               backgroundMode          _DEFVAL(false);        
 
164
extern bool               signalDump              _DEFVAL(false);        
 
165
 
 
166
extern int                currentScreenToDisplay  _DEFVAL
 
167
                                                  (DISPLAY_SCENARIO_SCREEN);
 
168
#ifdef _USE_OPENSSL
 
169
extern BIO                  *bio ;
 
170
extern SSL                  *ssl_tcp_multiplex ;
 
171
extern BIO                  *twinSipp_bio ;
 
172
extern SSL                  *twinSipp_ssl ;
 
173
#endif
 
174
 
 
175
// extern field file management
 
176
typedef std::vector<std::string>    IN_FILE_CONTENTS;
 
177
extern IN_FILE_CONTENTS   fileContents;
 
178
extern int                numLinesInFile          _DEFVAL(0);
 
179
 
 
180
 
 
181
/************************ Statistics **************************/
 
182
 
 
183
extern unsigned long total_calls                  _DEFVAL(0);
 
184
extern unsigned long last_report_calls            _DEFVAL(0);
 
185
extern unsigned long rtd_sum                      _DEFVAL(0);
 
186
extern unsigned long rtd_nb                       _DEFVAL(0);
 
187
extern unsigned long call_duration_sum            _DEFVAL(0);
 
188
extern unsigned long call_duration_nb             _DEFVAL(0);
 
189
extern unsigned long nb_net_send_errors           _DEFVAL(0);
 
190
extern unsigned long nb_net_cong                  _DEFVAL(0);
 
191
extern unsigned long nb_net_recv_errors           _DEFVAL(0);
 
192
extern bool          cpu_max                      _DEFVAL(false);
 
193
extern int           open_calls_peak              _DEFVAL(0);
 
194
extern unsigned long open_calls_peak_time         _DEFVAL(0);
 
195
extern int           open_calls_user_setting      _DEFVAL(0);
 
196
extern int           nb_out_of_the_blue           _DEFVAL(0);
 
197
extern int           resynch_send                 _DEFVAL(0);
 
198
extern int           resynch_recv                 _DEFVAL(0);
 
199
extern unsigned long rtp_pckts                    _DEFVAL(0);
 
200
extern unsigned long rtp_bytes                    _DEFVAL(0);
 
201
 
 
202
/************* Rate Control & Contexts variables **************/
 
203
 
 
204
extern int           open_calls                   _DEFVAL(0);
 
205
extern unsigned int  open_calls_allowed           _DEFVAL(0);
 
206
extern unsigned long last_rate_change_time        _DEFVAL(1);
 
207
extern unsigned long last_report_time             _DEFVAL(1);
 
208
extern unsigned long last_dump_time               _DEFVAL(1);
 
209
extern unsigned long calls_since_last_rate_change _DEFVAL(0);
 
210
 
 
211
/********************** Clock variables ***********************/
 
212
 
 
213
extern unsigned long clock_tick                   _DEFVAL(1);
 
214
extern unsigned long scheduling_loops             _DEFVAL(0);
 
215
extern unsigned long last_timer_cycle             _DEFVAL(0);
 
216
 
 
217
#define GET_TIME(clock)       \
 
218
{                             \
 
219
  struct timezone tzp;        \
 
220
  gettimeofday (clock, &tzp); \
 
221
}
 
222
 
 
223
/*********************** Global Sockets  **********************/
 
224
 
 
225
extern int           main_socket                  _DEFVAL(0);
 
226
extern int           tcp_multiplex                _DEFVAL(0);
 
227
extern int           media_socket                 _DEFVAL(0);
 
228
 
 
229
#ifdef __3PCC__
 
230
extern int           twinSippSocket               _DEFVAL(0);
 
231
extern int           localTwinSippSocket          _DEFVAL(0);
 
232
extern struct        sockaddr_storage twinSipp_sockaddr;
 
233
#endif
 
234
 
 
235
extern struct        sockaddr_storage remote_sockaddr;
 
236
extern struct        sockaddr_storage remote_rtp_addr;
 
237
 
 
238
extern short         use_remote_sending_addr      _DEFVAL(0);
 
239
extern struct        sockaddr_storage remote_sending_sockaddr;
 
240
 
 
241
enum E_Alter_YesNo
 
242
  {
 
243
    E_ALTER_YES=0,
 
244
    E_ALTER_NO
 
245
  };
 
246
 
 
247
/************************** Trace Files ***********************/
 
248
 
 
249
extern FILE * screenf                             _DEFVAL(0);
 
250
extern FILE * logfile                             _DEFVAL(0);
 
251
extern FILE * messagef                            _DEFVAL(0);
 
252
extern FILE * timeoutf                            _DEFVAL(0);
 
253
extern int    useMessagef                         _DEFVAL(0);
 
254
extern int    useScreenf                          _DEFVAL(0);
 
255
extern int    useLogf                             _DEFVAL(0);
 
256
extern int    useTimeoutf                         _DEFVAL(0);
 
257
extern int    dumpInFile                          _DEFVAL(0);
 
258
extern char * scenario_file;
 
259
 
 
260
#define TRACE_MSG(arg)      \
 
261
{                           \
 
262
  if(messagef) {            \
 
263
    FILE * s = messagef;    \
 
264
    fprintf arg;            \
 
265
    fflush(messagef);       \
 
266
  }                         \
 
267
}
 
268
 
 
269
#define LOG_MSG(arg)        \
 
270
{                           \
 
271
  if(logfile) {             \
 
272
    FILE * s = logfile;     \
 
273
    fprintf arg;            \
 
274
    fflush(logfile);        \
 
275
  }                         \
 
276
}
 
277
 
 
278
#define TRACE_TIMEOUT(arg)  \
 
279
{                           \
 
280
  if(timeoutf) {            \
 
281
    FILE * s = timeoutf;    \
 
282
    fprintf arg;            \
 
283
    fflush(timeoutf);       \
 
284
  }                         \
 
285
}
 
286
 
 
287
/********************* Mini-Parser Routines *******************/
 
288
 
 
289
int get_method(char *msg);
 
290
char * get_peer_tag(char *msg);
 
291
unsigned long get_reply_code(char *msg);
 
292
 
 
293
/********************** Network Interfaces ********************/
 
294
 
 
295
void sipp_customize_socket(int socket);
 
296
int send_message(int s, void ** comp_state, char * msg);
 
297
#ifdef _USE_OPENSSL
 
298
int send_message_tls(SSL *s, void ** comp_state, char * msg);
 
299
#endif
 
300
 
 
301
void pollset_remove(int idx);
 
302
int pollset_add(call * p_call, int socket);
 
303
 
 
304
#if defined (__hpux) || defined (__alpha)
 
305
#define sipp_socklen_t  int
 
306
#else
 
307
#define sipp_socklen_t  socklen_t
 
308
#endif
 
309
 
 
310
#define SOCK_ADDR_SIZE(a) \
 
311
  (((a)->ss_family == AF_INET) ? sizeof(struct sockaddr_in) \
 
312
                               : sizeof(struct sockaddr_in6))
 
313
 
 
314
#if defined(__cplusplus) && defined (__hpux)
 
315
#define _RCAST(type, val) (reinterpret_cast<type> (val))
 
316
#else
 
317
#define _RCAST(type, val) ((type)(val))
 
318
#endif
 
319
 
 
320
/********************* Utilities functions  *******************/
 
321
 
 
322
char *strcasestr2 ( char *__haystack, char *__needle);
 
323
 
 
324
/********************* Reset global kludge  *******************/
 
325
 
 
326
#ifdef GLOBALS_FULL_DEFINITION
 
327
#undef extern
 
328
#endif
 
329
 
 
330
#endif // __SIPP__