nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*---------------------------------------------------------------
2 * Copyright (c) 1999,2000,2001,2002,2003
3 * The Board of Trustees of the University of Illinois
4 * All Rights Reserved.
5 *---------------------------------------------------------------
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software (Iperf) and associated
8 * documentation files (the "Software"), to deal in the Software
9 * without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute,
11 * sublicense, and/or sell copies of the Software, and to permit
12 * persons to whom the Software is furnished to do
13 * so, subject to the following conditions:
14 *
15 *
16 * Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and
18 * the following disclaimers.
19 *
20 *
21 * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimers in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 *
27 * Neither the names of the University of Illinois, NCSA,
28 * nor the names of its contributors may be used to endorse
29 * or promote products derived from this Software without
30 * specific prior written permission.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
34 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35 * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
36 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
37 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
38 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE
39 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 * ________________________________________________________________
41 * National Laboratory for Applied Network Research
42 * National Center for Supercomputing Applications
43 * University of Illinois at Urbana-Champaign
44 * http://www.ncsa.uiuc.edu
45 * ________________________________________________________________
46 *
47 * Settings.hpp
48 * by Mark Gates <mgates@nlanr.net>
49 * & Ajay Tirumala <tirumala@ncsa.uiuc.edu>
50 * -------------------------------------------------------------------
51 * Stores and parses the initial values for all the global variables.
52 * -------------------------------------------------------------------
53 * headers
54 * uses
55 * <stdlib.h>
56 * <assert.h>
57 * ------------------------------------------------------------------- */
58  
59 #ifndef SETTINGS_H
60 #define SETTINGS_H
61  
62 #include "headers.h"
63 #include "Thread.h"
64  
65 /* -------------------------------------------------------------------
66 * constants
67 * ------------------------------------------------------------------- */
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71  
72 /* Smallest report interval supported. Units is seconds */
73 #define SMALLEST_INTERVAL 0.005
74  
75 // server/client mode
76 typedef enum ThreadMode {
77 kMode_Unknown = 0,
78 kMode_Server,
79 kMode_Client,
80 kMode_Reporter,
81 kMode_Listener
82 } ThreadMode;
83  
84 // report mode
85 typedef enum ReportMode {
86 kReport_Default = 0,
87 kReport_CSV,
88 //kReport_XML,
89 kReport_MAXIMUM
90 } ReportMode;
91  
92 // test mode
93 typedef enum TestMode {
94 kTest_Normal = 0,
95 kTest_DualTest,
96 kTest_TradeOff,
97 kTest_Unknown
98 } TestMode;
99  
100 // rate request units
101 typedef enum RateUnits {
102 kRate_BW = 0,
103 kRate_PPS
104 } RateUnits;
105  
106 #include "Reporter.h"
107 /*
108 * The thread_Settings is a structure that holds all
109 * options for a given execution of either a client
110 * or server. By using this structure rather than
111 * a global structure or class we can have multiple
112 * clients or servers running with different settings.
113 * In version 2.0 and above this structure contains
114 * all the information needed for a thread to execute
115 * and contains only C elements so it can be manipulated
116 * by either C or C++.
117 */
118 typedef struct thread_Settings {
119 // Pointers
120 char* mFileName; // -F
121 char* mHost; // -c
122 char* mLocalhost; // -B
123 char* mOutputFileName; // -o
124 FILE* Extractor_file;
125 ReportHeader* reporthdr;
126 MultiHeader* multihdr;
127 struct thread_Settings *runNow;
128 struct thread_Settings *runNext;
129 // int's
130 int mThreads; // -P
131 int mTOS; // -S
132 int mSock;
133 int Extractor_size;
134 int mBufLen; // -l
135 int mMSS; // -M
136 int mTCPWin; // -w
137 /* flags is a BitMask of old bools
138 bool mBufLenSet; // -l
139 bool mCompat; // -C
140 bool mDaemon; // -D
141 bool mDomain; // -V
142 bool mFileInput; // -F or -I
143 bool mNodelay; // -N
144 bool mPrintMSS; // -m
145 bool mRemoveService; // -R
146 bool mStdin; // -I
147 bool mStdout; // -o
148 bool mSuggestWin; // -W
149 bool mUDP; // -u
150 bool mMode_time;
151 bool mReportSettings;
152 bool mMulticast;
153 bool mNoSettingsReport; // -x s
154 bool mNoConnectionReport; // -x c
155 bool mNoDataReport; // -x d
156 bool mNoServerReport; // -x
157 bool mNoMultReport; // -x m
158 bool mSinlgeClient; // -1 */
159 int flags;
160 // enums (which should be special int's)
161 ThreadMode mThreadMode; // -s or -c
162 ReportMode mReportMode;
163 TestMode mMode; // -r or -d
164 // Hopefully int64_t's
165 max_size_t mUDPRate; // -b or -u
166 RateUnits mUDPRateUnits; // -b is either bw or pps
167 max_size_t mAmount; // -n or -t
168 // doubles
169 double mInterval; // -i
170 // shorts
171 unsigned short mListenPort; // -L
172 unsigned short mPort; // -p
173 unsigned short mBindPort; // -B
174 // chars
175 char mFormat; // -f
176 int mTTL; // -T
177 char pad1[2];
178 // structs or miscellaneous
179 iperf_sockaddr peer;
180 Socklen_t size_peer;
181 iperf_sockaddr local;
182 Socklen_t size_local;
183 nthread_t mTID;
184 char* mCongestion;
185 #if defined( HAVE_WIN32_THREAD )
186 HANDLE mHandle;
187 #endif
188 } thread_Settings;
189  
190 /*
191 * Due to the use of thread_Settings in C and C++
192 * we are unable to use bool values. To provide
193 * the functionality of bools we use the following
194 * bitmask over an assumed 32 bit int. This will
195 * work fine on 64bit machines we will just be ignoring
196 * the upper 32bits.
197 *
198 * To add a flag simply define it as the next bit then
199 * add the 3 support functions below.
200 */
201 #define FLAG_BUFLENSET 0x00000001
202 #define FLAG_COMPAT 0x00000002
203 #define FLAG_DAEMON 0x00000004
204 #define FLAG_DOMAIN 0x00000008
205 #define FLAG_FILEINPUT 0x00000010
206 #define FLAG_NODELAY 0x00000020
207 #define FLAG_PRINTMSS 0x00000040
208 #define FLAG_REMOVESERVICE 0x00000080
209 #define FLAG_STDIN 0x00000100
210 #define FLAG_STDOUT 0x00000200
211 #define FLAG_SUGGESTWIN 0x00000400
212 #define FLAG_UDP 0x00000800
213 #define FLAG_MODETIME 0x00001000
214 #define FLAG_REPORTSETTINGS 0x00002000
215 #define FLAG_MULTICAST 0x00004000
216 #define FLAG_NOSETTREPORT 0x00008000
217 #define FLAG_NOCONNREPORT 0x00010000
218 #define FLAG_NODATAREPORT 0x00020000
219 #define FLAG_NOSERVREPORT 0x00040000
220 #define FLAG_NOMULTREPORT 0x00080000
221 #define FLAG_SINGLECLIENT 0x00100000
222 #define FLAG_SINGLEUDP 0x00200000
223 #define FLAG_CONGESTION 0x00400000
224 #define FLAG_REALTIME 0x00800000
225 #define FLAG_BWSET 0x01000000
226 #define FLAG_ENHANCEDREPORT 0x02000000
227 #define FLAG_SERVERMODETIME 0x04000000
228  
229 #define isBuflenSet(settings) ((settings->flags & FLAG_BUFLENSET) != 0)
230 #define isCompat(settings) ((settings->flags & FLAG_COMPAT) != 0)
231 #define isDaemon(settings) ((settings->flags & FLAG_DAEMON) != 0)
232 #define isIPV6(settings) ((settings->flags & FLAG_DOMAIN) != 0)
233 #define isFileInput(settings) ((settings->flags & FLAG_FILEINPUT) != 0)
234 #define isNoDelay(settings) ((settings->flags & FLAG_NODELAY) != 0)
235 #define isPrintMSS(settings) ((settings->flags & FLAG_PRINTMSS) != 0)
236 #define isRemoveService(settings) ((settings->flags & FLAG_REMOVESERVICE) != 0)
237 #define isSTDIN(settings) ((settings->flags & FLAG_STDIN) != 0)
238 #define isSTDOUT(settings) ((settings->flags & FLAG_STDOUT) != 0)
239 #define isSuggestWin(settings) ((settings->flags & FLAG_SUGGESTWIN) != 0)
240 #define isUDP(settings) ((settings->flags & FLAG_UDP) != 0)
241 #define isModeTime(settings) ((settings->flags & FLAG_MODETIME) != 0)
242 #define isReport(settings) ((settings->flags & FLAG_REPORTSETTINGS) != 0)
243 #define isMulticast(settings) ((settings->flags & FLAG_MULTICAST) != 0)
244 // Active Low for Reports
245 #define isSettingsReport(settings) ((settings->flags & FLAG_NOSETTREPORT) == 0)
246 #define isConnectionReport(settings) ((settings->flags & FLAG_NOCONNREPORT) == 0)
247 #define isDataReport(settings) ((settings->flags & FLAG_NODATAREPORT) == 0)
248 #define isServerReport(settings) ((settings->flags & FLAG_NOSERVREPORT) == 0)
249 #define isMultipleReport(settings) ((settings->flags & FLAG_NOMULTREPORT) == 0)
250 // end Active Low
251 #define isSingleClient(settings) ((settings->flags & FLAG_SINGLECLIENT) != 0)
252 #define isSingleUDP(settings) ((settings->flags & FLAG_SINGLEUDP) != 0)
253 #define isCongestionControl(settings) ((settings->flags & FLAG_CONGESTION) != 0)
254 #define isRealtime(settings) ((settings->flags & FLAG_REALTIME) != 0)
255 #define isBWSet(settings) ((settings->flags & FLAG_BWSET) != 0)
256 #define isEnhanced(settings) ((settings->flags & FLAG_ENHANCEDREPORT) != 0)
257 #define isServerModeTime(settings) ((settings->flags & FLAG_SERVERMODETIME) != 0)
258  
259 #define setBuflenSet(settings) settings->flags |= FLAG_BUFLENSET
260 #define setCompat(settings) settings->flags |= FLAG_COMPAT
261 #define setDaemon(settings) settings->flags |= FLAG_DAEMON
262 #define setIPV6(settings) settings->flags |= FLAG_DOMAIN
263 #define setFileInput(settings) settings->flags |= FLAG_FILEINPUT
264 #define setNoDelay(settings) settings->flags |= FLAG_NODELAY
265 #define setPrintMSS(settings) settings->flags |= FLAG_PRINTMSS
266 #define setRemoveService(settings) settings->flags |= FLAG_REMOVESERVICE
267 #define setSTDIN(settings) settings->flags |= FLAG_STDIN
268 #define setSTDOUT(settings) settings->flags |= FLAG_STDOUT
269 #define setSuggestWin(settings) settings->flags |= FLAG_SUGGESTWIN
270 #define setUDP(settings) settings->flags |= FLAG_UDP
271 #define setModeTime(settings) settings->flags |= FLAG_MODETIME
272 #define setReport(settings) settings->flags |= FLAG_REPORTSETTINGS
273 #define setMulticast(settings) settings->flags |= FLAG_MULTICAST
274 #define setNoSettReport(settings) settings->flags |= FLAG_NOSETTREPORT
275 #define setNoConnReport(settings) settings->flags |= FLAG_NOCONNREPORT
276 #define setNoDataReport(settings) settings->flags |= FLAG_NODATAREPORT
277 #define setNoServReport(settings) settings->flags |= FLAG_NOSERVREPORT
278 #define setNoMultReport(settings) settings->flags |= FLAG_NOMULTREPORT
279 #define setSingleClient(settings) settings->flags |= FLAG_SINGLECLIENT
280 #define setSingleUDP(settings) settings->flags |= FLAG_SINGLEUDP
281 #define setCongestionControl(settings) settings->flags |= FLAG_CONGESTION
282 #define setRealtime(settings) settings->flags |= FLAG_REALTIME
283 #define setBWSet(settings) settings->flags |= FLAG_BWSET
284 #define setEnhanced(settings) settings->flags |= FLAG_ENHANCEDREPORT
285 #define setServerModeTime(settings) settings->flags |= FLAG_SERVERMODETIME
286  
287 #define unsetBuflenSet(settings) settings->flags &= ~FLAG_BUFLENSET
288 #define unsetCompat(settings) settings->flags &= ~FLAG_COMPAT
289 #define unsetDaemon(settings) settings->flags &= ~FLAG_DAEMON
290 #define unsetIPV6(settings) settings->flags &= ~FLAG_DOMAIN
291 #define unsetFileInput(settings) settings->flags &= ~FLAG_FILEINPUT
292 #define unsetNoDelay(settings) settings->flags &= ~FLAG_NODELAY
293 #define unsetPrintMSS(settings) settings->flags &= ~FLAG_PRINTMSS
294 #define unsetRemoveService(settings) settings->flags &= ~FLAG_REMOVESERVICE
295 #define unsetSTDIN(settings) settings->flags &= ~FLAG_STDIN
296 #define unsetSTDOUT(settings) settings->flags &= ~FLAG_STDOUT
297 #define unsetSuggestWin(settings) settings->flags &= ~FLAG_SUGGESTWIN
298 #define unsetUDP(settings) settings->flags &= ~FLAG_UDP
299 #define unsetModeTime(settings) settings->flags &= ~FLAG_MODETIME
300 #define unsetReport(settings) settings->flags &= ~FLAG_REPORTSETTINGS
301 #define unsetMulticast(settings) settings->flags &= ~FLAG_MULTICAST
302 #define unsetNoSettReport(settings) settings->flags &= ~FLAG_NOSETTREPORT
303 #define unsetNoConnReport(settings) settings->flags &= ~FLAG_NOCONNREPORT
304 #define unsetNoDataReport(settings) settings->flags &= ~FLAG_NODATAREPORT
305 #define unsetNoServReport(settings) settings->flags &= ~FLAG_NOSERVREPORT
306 #define unsetNoMultReport(settings) settings->flags &= ~FLAG_NOMULTREPORT
307 #define unsetSingleClient(settings) settings->flags &= ~FLAG_SINGLECLIENT
308 #define unsetSingleUDP(settings) settings->flags &= ~FLAG_SINGLEUDP
309 #define unsetCongestionControl(settings) settings->flags &= ~FLAG_CONGESTION
310 #define unsetRealtime(settings) settings->flags &= ~FLAG_REALTIME
311 #define unsetBWSet(settings) settings->flags &= ~FLAG_BWSET
312 #define unsetEnhanced(settings) settings->flags &= ~FLAG_ENHANCEDREPORT
313 #define unsetServerModeTime(settings) settings->flags &= ~FLAG_SERVERMODETIME
314  
315  
316 #define HEADER_VERSION1 0x80000000
317 #define RUN_NOW 0x00000001
318 #define UNITS_PPS 0x00000002
319  
320 // used to reference the 4 byte ID number we place in UDP datagrams
321 // use int32_t if possible, otherwise a 32 bit bitfield (e.g. on J90)
322 typedef struct UDP_datagram {
323 #ifdef HAVE_INT32_T
324 int32_t id;
325 u_int32_t tv_sec;
326 u_int32_t tv_usec;
327 #else
328 signed int id : 32;
329 unsigned int tv_sec : 32;
330 unsigned int tv_usec : 32;
331 #endif
332 } UDP_datagram;
333  
334 /*
335 * The client_hdr structure is sent from clients
336 * to servers to alert them of things that need
337 * to happen. Order must be perserved in all
338 * future releases for backward compatibility.
339 * 1.7 has flags, numThreads, mPort, and bufferlen
340 */
341 typedef struct client_hdr {
342  
343 #ifdef HAVE_INT32_T
344  
345 /*
346 * flags is a bitmap for different options
347 * the most significant bits are for determining
348 * which information is available. So 1.7 uses
349 * 0x80000000 and the next time information is added
350 * the 1.7 bit will be set and 0x40000000 will be
351 * set signifying additional information. If no
352 * information bits are set then the header is ignored.
353 * The lowest order diferentiates between dualtest and
354 * tradeoff modes, wheither the speaker needs to start
355 * immediately or after the audience finishes.
356 */
357 int32_t flags;
358 int32_t numThreads;
359 int32_t mPort;
360 int32_t bufferlen;
361 int32_t mWindowSize;
362 int32_t mAmount;
363 int32_t mRate;
364 int32_t mUDPRateUnits;
365 int32_t mRealtime;
366 #else
367 signed int flags : 32;
368 signed int numThreads : 32;
369 signed int mPort : 32;
370 signed int bufferlen : 32;
371 signed int mWindowSize : 32;
372 signed int mAmount : 32;
373 signed int mRate : 32;
374 signed int mUDPRateUnits : 32;
375 signed int mRealtime : 32;
376 #endif
377 } client_hdr;
378  
379 /*
380 * The server_hdr structure facilitates the server
381 * report of jitter and loss on the client side.
382 * It piggy_backs on the existing clear to close
383 * packet.
384 */
385 typedef struct server_hdr {
386  
387 #ifdef HAVE_INT32_T
388  
389 /*
390 * flags is a bitmap for different options
391 * the most significant bits are for determining
392 * which information is available. So 1.7 uses
393 * 0x80000000 and the next time information is added
394 * the 1.7 bit will be set and 0x40000000 will be
395 * set signifying additional information. If no
396 * information bits are set then the header is ignored.
397 */
398 int32_t flags;
399 int32_t total_len1;
400 int32_t total_len2;
401 int32_t stop_sec;
402 int32_t stop_usec;
403 int32_t error_cnt;
404 int32_t outorder_cnt;
405 int32_t datagrams;
406 int32_t jitter1;
407 int32_t jitter2;
408 int32_t minTransit1;
409 int32_t minTransit2;
410 int32_t maxTransit1;
411 int32_t maxTransit2;
412 int32_t sumTransit1;
413 int32_t sumTransit2;
414 int32_t meanTransit1;
415 int32_t meanTransit2;
416 int32_t m2Transit1;
417 int32_t m2Transit2;
418 int32_t vdTransit1;
419 int32_t vdTransit2;
420 int32_t cntTransit;
421 int32_t IPGcnt;
422 int32_t IPGsum;
423 #else
424 signed int flags : 32;
425 signed int total_len1 : 32;
426 signed int total_len2 : 32;
427 signed int stop_sec : 32;
428 signed int stop_usec : 32;
429 signed int error_cnt : 32;
430 signed int outorder_cnt : 32;
431 signed int datagrams : 32;
432 signed int jitter1 : 32;
433 signed int jitter2 : 32;
434 signed int minTransit1 : 32;
435 signed int minTransit2 : 32;
436 signed int maxTransit1 : 32;
437 signed int maxTransit2 : 32;
438 signed int sumTransit1 : 32;
439 signed int sumTransit2 : 32;
440 signed int meanTransit1 : 32;
441 signed int meanTransit2 : 32;
442 signed int m2Transit1 : 32;
443 signed int m2Transit2 : 32;
444 signed int vdTransit1 : 32;
445 signed int vdTransit2 : 32;
446 signed int cntTransit : 32;
447 signed int IPGcnt : 32;
448 signed int IPGsum : 32;
449 #endif
450  
451 } server_hdr;
452  
453 // set to defaults
454 void Settings_Initialize( thread_Settings* main );
455  
456 // copy structure
457 void Settings_Copy( thread_Settings* from, thread_Settings** into );
458  
459 // free associated memory
460 void Settings_Destroy( thread_Settings *mSettings );
461  
462 // parse settings from user's environment variables
463 void Settings_ParseEnvironment( thread_Settings *mSettings );
464  
465 // parse settings from app's command line
466 void Settings_ParseCommandLine( int argc, char **argv, thread_Settings *mSettings );
467  
468 // convert to lower case for [KMG]bits/sec
469 void Settings_GetLowerCaseArg(const char *,char *);
470  
471 // convert to upper case for [KMG]bytes/sec
472 void Settings_GetUpperCaseArg(const char *,char *);
473  
474 // generate settings for listener instance
475 void Settings_GenerateListenerSettings( thread_Settings *client, thread_Settings **listener);
476  
477 // generate settings for speaker instance
478 void Settings_GenerateClientSettings( thread_Settings *server,
479 thread_Settings **client,
480 client_hdr *hdr );
481  
482 // generate client header for server
483 void Settings_GenerateClientHdr( thread_Settings *client, client_hdr *hdr );
484  
485 #ifdef __cplusplus
486 } /* end extern "C" */
487 #endif
488  
489 #endif // SETTINGS_H