~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to test/SDKtest/client/DoTest.h

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
/*************************** -*- Mod: C++ -*- *********************
 
25
 
 
26
  DoTest.h
 
27
******************************************************************/
 
28
 
 
29
#ifndef _DoTest_h_
 
30
#define _DoTest_h_
 
31
#include "Defines.h"
 
32
#include "LoadGenerator.h"
 
33
#include "Plugin.h"
 
34
#include "Hist.h"
 
35
#include <unistd.h>
 
36
#include <ctype.h>
 
37
#include <netdb.h>
 
38
#include <sys/socket.h>
 
39
#include <sys/resource.h>
 
40
#include <netinet/in.h>
 
41
#include <netinet/tcp.h>
 
42
#include <arpa/inet.h>
 
43
#include <poll.h>
 
44
#include <fcntl.h>
 
45
#include <sys/time.h>
 
46
 
 
47
#include <openssl/rsa.h>        /* SSLeay stuff */
 
48
#include <openssl/crypto.h>
 
49
#include <openssl/x509.h>
 
50
#include <openssl/pem.h>
 
51
#include <openssl/ssl.h>
 
52
#include <openssl/err.h>
 
53
#include <openssl/rand.h>
 
54
#define CHK_NULL(x) if ((x)==NULL) exit (1)
 
55
#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
 
56
#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(errFp); exit(2); }
 
57
 
 
58
#define DIFF_TIME(start_time,end_time) \
 
59
             (long) (((double) (end_time).tv_sec*1000.0 + \
 
60
             (double)  (end_time).tv_usec / 1000.0) - \
 
61
             ((double) (start_time).tv_sec*1000.0 + \
 
62
             (double)  (start_time).tv_usec / 1000.0))
 
63
 
 
64
enum StatusStatus
 
65
{
 
66
  READING_STATUS_LINE,
 
67
  READING_HEADERS,
 
68
  GOT_ONE_NEWLINE_IN_HEADERS,
 
69
  GOT_TWO_NEWLINES_IN_HEADERS,
 
70
  DONE_READING_HEADERS
 
71
};
 
72
 
 
73
struct StatusLineInfo
 
74
{
 
75
  int status_code;
 
76
  StatusStatus status_line_complete;
 
77
  int buffer_index;
 
78
  char buffer[MAX_STATUS_LEN];
 
79
};
 
80
 
 
81
struct UserInfo
 
82
{
 
83
  struct timeval transaction_start_time;
 
84
  struct timeval connect_time;
 
85
  struct timeval first_byte_time;
 
86
  struct timeval last_read_time;
 
87
  struct timeval transaction_end_time;
 
88
  struct timeval think_time_start;
 
89
 
 
90
  long target_byterate;
 
91
  long think_time;
 
92
  int pollin_count;
 
93
  int read_count;
 
94
  long bytes_read;
 
95
  long bytes_requested;
 
96
  StatusLineInfo status_line_info;
 
97
  char request_sent[MAX_REQUEST_SIZE];
 
98
  struct sockaddr_in *target_addr;
 
99
  int fd;
 
100
 
 
101
  /* for differentiate a completed/non-completed connection */
 
102
  int internal_rid;
 
103
  void *request_id;
 
104
  SSL *m_ssl;
 
105
 
 
106
  /////////////////////
 
107
#ifdef _PLUG_IN
 
108
  struct sockaddr_in dynamic_target_addr;
 
109
  long content_count;
 
110
  TSRequestAction action;
 
111
  TSConnectionStatus conn_status;
 
112
#endif
 
113
  /////////////////////
 
114
 
 
115
  int blocked;
 
116
};
 
117
 
 
118
struct DoTest
 
119
{
 
120
 
 
121
  // Stats variables
 
122
  int report_no;                /* Each report is labeled with a number */
 
123
  int fd_limit;
 
124
 
 
125
  double total_bytes_read;      /* total bytes read; only from successful resp */
 
126
  double total_bytes_requested; /* the bytes requested (excluding headers) */
 
127
  double total_bytes_read_including_partial_docs;
 
128
  long finished_requests;       /* number of successful requests */
 
129
  long requests_made;
 
130
  long failed_requests;         /* number of failed requests */
 
131
  long last_finished;           /* number of finished requests at last report */
 
132
 
 
133
  struct timeval start_time;    /* start time */
 
134
  struct timeval stop_time;     /* stop time */
 
135
  struct timeval reporting_time;        /* current time */
 
136
  struct timeval last_reporting_time;   /* time of the last report */
 
137
 
 
138
  long elapsed_time;            /* Time since start */
 
139
  long time_since_last_report;  /* Time since last report */
 
140
  double total_round_trip_time; /* Sum of all latencies */
 
141
  double total_first_byte_latency;      /* Sum of all first-byte latencies */
 
142
  double total_connect_time;    /* Sum of all connect times */
 
143
  long max_round_trip_time;     /* Max of all latencies */
 
144
  long min_round_trip_time;     /* Min of all latencies */
 
145
  long max_first_byte_latency;  /* Max First Byte Latency */
 
146
  long min_first_byte_latency;  /* Min First Byte Latency */
 
147
  long max_connect_time;        /* Max of all connect times */
 
148
  long min_connect_time;        /* Min of all connect times */
 
149
 
 
150
  long round_trip_time_cutoff;
 
151
  /* It will report how many latencies were above this cutoff (in msec) */
 
152
  long above_round_trip_time_cutoff;    /* Req above latency cutoff */
 
153
  long first_byte_latency_cutoff;
 
154
  /* It will report how many first byte latencies were above
 
155
     this cutoff (in msec) */
 
156
  long above_first_byte_latency_cutoff; /* Req above first-byte cutoff */
 
157
  long connect_time_cutoff;
 
158
  /* It will report how many connect times were above
 
159
     this cutoff (in msec) */
 
160
  long above_connect_time_cutoff;       /* Req above connect cutoff */
 
161
 
 
162
  int QOS_docsize;
 
163
 
 
164
  histogram round_trip_histogram;
 
165
  histogram first_byte_histogram;
 
166
  histogram connect_histogram;
 
167
 
 
168
  long generated_thinktime;     /* Total number of reqs generated */
 
169
  long thinktime_generated[MAX_THTSTIMES];     /* Number of reqs with
 
170
                                                   each thinktime */
 
171
  double total_actual_thinktime;
 
172
 
 
173
  long generated_target_byterate;       /* Total number of reqs generated */
 
174
  long target_byterate_generated[MAX_TARGET_BYTERATES];
 
175
  /* Number of reqs with each target_byterate */
 
176
  long num_limited_byterate;
 
177
  // number of transactions that had limited target_byterate
 
178
  double total_limited_byterate_error;
 
179
  // Total error among all the limited byterate trans
 
180
  int reporting_interval;
 
181
 
 
182
  int connections_open;
 
183
  int max_connections_open;
 
184
 
 
185
  double histogram_max;
 
186
  double histogram_resolution;
 
187
  // Config
 
188
  int num_thinktimes;           /* Number of thinktimes in the distribution */
 
189
  long *thinktimes;             /* actual thinktimes */
 
190
  double *cumulative_thinktime_prob;
 
191
  /* Cumulative probability of selecting different thinktimes
 
192
     cumulative_size_prob[num_thinktimes-1] must be 1.0 */
 
193
 
 
194
  int num_target_byterates;     /* Number of thinktimes in the distribution */
 
195
  long *target_byterates;       /* actual thinktimes */
 
196
  double *cumulative_target_byterate_prob;
 
197
  /* Cumulative probability of selecting different
 
198
     target_byterates
 
199
     cumulative_target_byterate_prob[num_thinktimes-1]
 
200
     must be 1.0 */
 
201
 
 
202
  UserInfo *user_info;
 
203
  int debug;                    /* Debugging Messages */
 
204
  int ssl;                      /* ssl flad  */
 
205
 
 
206
  int client_id;                /* Among all the client processes running what
 
207
                                   is my Id */
 
208
  LoadGenerator *load_generator;
 
209
  TSPlugin *plug_in;
 
210
  long warmup;
 
211
  // =0: real test, > 0 : warmup; create only warmup number of
 
212
  // requests
 
213
  int users;
 
214
  int poll_timeout;
 
215
  int keepalive;
 
216
 
 
217
  int request_rate;
 
218
  struct timeval rr_time;
 
219
  int total_reqs_last_poll;
 
220
 
 
221
  struct pollfd *poll_vector;
 
222
  char read_buf[MAX_READBUF_SIZE];
 
223
 
 
224
  X509 *server_cert;
 
225
  SSL_CTX *ctx;
 
226
  SSL_METHOD *meth;
 
227
 
 
228
  FILE *errFp;
 
229
  char *str;
 
230
  int err1;
 
231
  int flag_connect;
 
232
  int flag_write;
 
233
  int flag_read;
 
234
  int tempint;
 
235
  int randBuff[64];
 
236
 
 
237
  // Generate thinktime (in msecs from give distribution )
 
238
  long generate_think_time();
 
239
 
 
240
  long generate_target_byterate();
 
241
  long compute_bytes_to_read(int user, struct timeval current_time);
 
242
  // User i just finished, update stats
 
243
  void update_completion_stats(int i);
 
244
  int create_new_connection_and_send_request(int user, struct timeval current_time);
 
245
  void initialize_stats();
 
246
  void print_stats(int all);
 
247
  long get_request_rate(struct timeval t);
 
248
  void actual_test(int rr_flag);
 
249
    DoTest(int adebug,
 
250
           int assl,
 
251
           int aclient_id,
 
252
           LoadGenerator * aload_generator,
 
253
           long awarmup,
 
254
           int ausers,
 
255
           int apoll_timeout,
 
256
           int akeepalive,
 
257
           int anum_thinktimes,
 
258
           long *athinktimes,
 
259
           double *acumulative_thinktime_prob,
 
260
           int anum_target_byterates,
 
261
           long *atarget_byterates,
 
262
           double *acumulative_target_byterates_prob,
 
263
           int areporting_interval,
 
264
           double ahistogram_max,
 
265
           double ahistogram_resolution,
 
266
           long around_trip_time_cutoff,
 
267
           long afirst_byte_latency_cutoff,
 
268
           long aconnect_time_cutoff, int aQOS_docsize, TSPlugin * aplug_in, int arequest_rate);
 
269
  void report(char *metric, char *units, char *combiner, double value);
 
270
 
 
271
   ~DoTest()
 
272
  {
 
273
  }
 
274
};
 
275
 
 
276
extern DoTest *do_test;
 
277
 
 
278
#endif // #ifndef DoTest_h_