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.
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.
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
16
* Author : Richard GAYRAUD - 04 Nov 2003
17
* From Hewlett Packard Company.
29
#include <sys/types.h>
30
#include <sys/socket.h>
31
#include <netinet/in.h>
32
#include <netinet/tcp.h>
35
#include <sys/resource.h>
38
#include <arpa/inet.h>
49
#include "xp_parser.h"
50
#include "scenario.hpp"
55
#include "actions.hpp"
56
#include "variables.hpp"
59
#include "sslcommon.h"
65
#define FD_SETSIZE 65000
69
#define FD_SETSIZE 1024
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
79
#ifdef GLOBALS_FULL_DEFINITION
81
#define _DEFVAL(value) = value
83
#define _DEFVAL(value)
86
/************************** Constants **************************/
93
#define TRANSPORT_TO_STRING(p) ((p==1) ? "TCP" : ((p==2)? "TLS" :"UDP"))
95
#define SIPP_MAXFDS 65536
96
#define SIPP_MAX_MSG_SIZE 65536
98
#define MSG_RETRANS_FIRST 0
99
#define MSG_RETRANS_RETRANSMISSION 1
100
#define MSG_RETRANS_NEVER 2
102
#define DISPLAY_STAT_SCREEN 1
103
#define DISPLAY_REPARTITION_SCREEN 2
104
#define DISPLAY_SCENARIO_SCREEN 3
105
#define DISPLAY_VARIABLE_SCREEN 4
107
#define MAX_RECV_LOOPS 1000
109
/******************** Default parameters ***********************/
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
116
#define DEFAULT_3PCC_PORT 6060
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
124
/************ User controls and command line options ***********/
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];
158
extern char twinSippHost[255];
159
extern char twinSippIp[40];
160
extern int twinSippPort _DEFVAL(DEFAULT_3PCC_PORT);
161
extern bool twinSippMode _DEFVAL(false);
163
extern bool backgroundMode _DEFVAL(false);
164
extern bool signalDump _DEFVAL(false);
166
extern int currentScreenToDisplay _DEFVAL
167
(DISPLAY_SCENARIO_SCREEN);
170
extern SSL *ssl_tcp_multiplex ;
171
extern BIO *twinSipp_bio ;
172
extern SSL *twinSipp_ssl ;
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);
181
/************************ Statistics **************************/
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);
202
/************* Rate Control & Contexts variables **************/
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);
211
/********************** Clock variables ***********************/
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);
217
#define GET_TIME(clock) \
219
struct timezone tzp; \
220
gettimeofday (clock, &tzp); \
223
/*********************** Global Sockets **********************/
225
extern int main_socket _DEFVAL(0);
226
extern int tcp_multiplex _DEFVAL(0);
227
extern int media_socket _DEFVAL(0);
230
extern int twinSippSocket _DEFVAL(0);
231
extern int localTwinSippSocket _DEFVAL(0);
232
extern struct sockaddr_storage twinSipp_sockaddr;
235
extern struct sockaddr_storage remote_sockaddr;
236
extern struct sockaddr_storage remote_rtp_addr;
238
extern short use_remote_sending_addr _DEFVAL(0);
239
extern struct sockaddr_storage remote_sending_sockaddr;
247
/************************** Trace Files ***********************/
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;
260
#define TRACE_MSG(arg) \
263
FILE * s = messagef; \
269
#define LOG_MSG(arg) \
272
FILE * s = logfile; \
278
#define TRACE_TIMEOUT(arg) \
281
FILE * s = timeoutf; \
287
/********************* Mini-Parser Routines *******************/
289
int get_method(char *msg);
290
char * get_peer_tag(char *msg);
291
unsigned long get_reply_code(char *msg);
293
/********************** Network Interfaces ********************/
295
void sipp_customize_socket(int socket);
296
int send_message(int s, void ** comp_state, char * msg);
298
int send_message_tls(SSL *s, void ** comp_state, char * msg);
301
void pollset_remove(int idx);
302
int pollset_add(call * p_call, int socket);
304
#if defined (__hpux) || defined (__alpha)
305
#define sipp_socklen_t int
307
#define sipp_socklen_t socklen_t
310
#define SOCK_ADDR_SIZE(a) \
311
(((a)->ss_family == AF_INET) ? sizeof(struct sockaddr_in) \
312
: sizeof(struct sockaddr_in6))
314
#if defined(__cplusplus) && defined (__hpux)
315
#define _RCAST(type, val) (reinterpret_cast<type> (val))
317
#define _RCAST(type, val) ((type)(val))
320
/********************* Utilities functions *******************/
322
char *strcasestr2 ( char *__haystack, char *__needle);
324
/********************* Reset global kludge *******************/
326
#ifdef GLOBALS_FULL_DEFINITION