]> sjero.net Git - iperf/blob - include/Settings.hpp
4c3aede9b0f6e3c9e97593336098de8926a6638a
[iperf] / include / Settings.hpp
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 // server/client mode
73 typedef enum ThreadMode {
74     kMode_Unknown = 0,
75     kMode_Server,
76     kMode_Client,
77     kMode_Reporter,
78     kMode_Listener
79 } ThreadMode;
80
81 // report mode
82 typedef enum ReportMode {
83     kReport_Default = 0,
84     kReport_CSV,
85     //kReport_XML,
86     kReport_MAXIMUM
87 } ReportMode;
88
89 // test mode
90 typedef enum TestMode {
91     kTest_Normal = 0,
92     kTest_DualTest,
93     kTest_TradeOff,
94     kTest_Unknown
95 } TestMode;
96
97 #include "Reporter.h"
98 /*
99  * The thread_Settings is a structure that holds all
100  * options for a given execution of either a client
101  * or server. By using this structure rather than
102  * a global structure or class we can have multiple
103  * clients or servers running with different settings.
104  * In version 2.0 and above this structure contains 
105  * all the information needed for a thread to execute
106  * and contains only C elements so it can be manipulated
107  * by either C or C++.
108  */
109 typedef struct thread_Settings {
110     // Pointers
111     char*  mFileName;               // -F
112     char*  mHost;                   // -c
113     char*  mLocalhost;              // -B
114     char*  mOutputFileName;         // -o
115     FILE*  Extractor_file;
116     ReportHeader*  reporthdr;
117     MultiHeader*   multihdr;
118     struct thread_Settings *runNow;
119     struct thread_Settings *runNext;
120     // int's
121     int mThreads;                   // -P
122     int mTOS;                       // -S
123     int mSock;
124     int Extractor_size;
125     int mBufLen;                    // -l
126     int mMSS;                       // -M
127     int mTCPWin;                    // -w
128     /*   flags is a BitMask of old bools
129         bool   mBufLenSet;              // -l
130         bool   mCompat;                 // -C
131         bool   mDaemon;                 // -D
132         bool   mDomain;                 // -V
133         bool   mFileInput;              // -F or -I
134         bool   mNodelay;                // -N
135         bool   mPrintMSS;               // -m
136         bool   mRemoveService;          // -R
137         bool   mStdin;                  // -I
138         bool   mStdout;                 // -o
139         bool   mSuggestWin;             // -W
140         bool   mUDP;                    // -u
141         bool   mMode_time;
142         bool   mReportSettings;
143         bool   mMulticast;
144         bool   mNoSettingsReport;       // -x s
145         bool   mNoConnectionReport;     // -x c
146         bool   mNoDataReport;           // -x d
147         bool   mNoServerReport;         // -x 
148         bool   mNoMultReport;           // -x m
149         bool   mSinlgeClient;           // -1 */
150     int flags; 
151     // enums (which should be special int's)
152     ThreadMode mThreadMode;         // -s or -c
153     ReportMode mReportMode;
154     TestMode mMode;                 // -r or -d
155     // Hopefully int64_t's
156     max_size_t mUDPRate;            // -b or -u
157     max_size_t mAmount;             // -n or -t
158     // doubles
159     double mInterval;               // -i
160     // shorts
161     unsigned short mListenPort;     // -L
162     unsigned short mPort;           // -p
163     // chars
164     char   mFormat;                 // -f
165     int mTTL;                    // -T
166     char pad1[2];
167     // structs or miscellaneous
168     iperf_sockaddr peer;
169     Socklen_t size_peer;
170     iperf_sockaddr local;
171     Socklen_t size_local;
172     nthread_t mTID;
173 } thread_Settings;
174
175 /*
176  * Due to the use of thread_Settings in C and C++
177  * we are unable to use bool values. To provide
178  * the functionality of bools we use the following
179  * bitmask over an assumed 32 bit int. This will
180  * work fine on 64bit machines we will just be ignoring
181  * the upper 32bits.
182  *
183  * To add a flag simply define it as the next bit then
184  * add the 3 support functions below.
185  */
186 #define FLAG_BUFLENSET      0x00000001
187 #define FLAG_COMPAT         0x00000002
188 #define FLAG_DAEMON         0x00000004
189 #define FLAG_DOMAIN         0x00000008
190 #define FLAG_FILEINPUT      0x00000010
191 #define FLAG_NODELAY        0x00000020
192 #define FLAG_PRINTMSS       0x00000040
193 #define FLAG_REMOVESERVICE  0x00000080
194 #define FLAG_STDIN          0x00000100
195 #define FLAG_STDOUT         0x00000200
196 #define FLAG_SUGGESTWIN     0x00000400
197 #define FLAG_UDP            0x00000800
198 #define FLAG_MODETIME       0x00001000
199 #define FLAG_REPORTSETTINGS 0x00002000
200 #define FLAG_MULTICAST      0x00004000
201 #define FLAG_NOSETTREPORT   0x00008000
202 #define FLAG_NOCONNREPORT   0x00010000
203 #define FLAG_NODATAREPORT   0x00020000
204 #define FLAG_NOSERVREPORT   0x00040000
205 #define FLAG_NOMULTREPORT   0x00080000
206 #define FLAG_SINGLECLIENT   0x00100000
207 #define FLAG_SINGLEUDP      0x00200000
208
209 #define isBuflenSet(settings)      ((settings->flags & FLAG_BUFLENSET) != 0)
210 #define isCompat(settings)         ((settings->flags & FLAG_COMPAT) != 0)
211 #define isDaemon(settings)         ((settings->flags & FLAG_DAEMON) != 0)
212 #define isIPV6(settings)           ((settings->flags & FLAG_DOMAIN) != 0)
213 #define isFileInput(settings)      ((settings->flags & FLAG_FILEINPUT) != 0)
214 #define isNoDelay(settings)        ((settings->flags & FLAG_NODELAY) != 0)
215 #define isPrintMSS(settings)       ((settings->flags & FLAG_PRINTMSS) != 0)
216 #define isRemoveService(settings)  ((settings->flags & FLAG_REMOVESERVICE) != 0)
217 #define isSTDIN(settings)          ((settings->flags & FLAG_STDIN) != 0)
218 #define isSTDOUT(settings)         ((settings->flags & FLAG_STDOUT) != 0)
219 #define isSuggestWin(settings)     ((settings->flags & FLAG_SUGGESTWIN) != 0)
220 #define isUDP(settings)            ((settings->flags & FLAG_UDP) != 0)
221 #define isModeTime(settings)       ((settings->flags & FLAG_MODETIME) != 0)
222 #define isReport(settings)         ((settings->flags & FLAG_REPORTSETTINGS) != 0)
223 #define isMulticast(settings)      ((settings->flags & FLAG_MULTICAST) != 0)
224 // Active Low for Reports
225 #define isSettingsReport(settings) ((settings->flags & FLAG_NOSETTREPORT) == 0)
226 #define isConnectionReport(settings)  ((settings->flags & FLAG_NOCONNREPORT) == 0)
227 #define isDataReport(settings)     ((settings->flags & FLAG_NODATAREPORT) == 0)
228 #define isServerReport(settings)   ((settings->flags & FLAG_NOSERVREPORT) == 0)
229 #define isMultipleReport(settings) ((settings->flags & FLAG_NOMULTREPORT) == 0)
230 // end Active Low
231 #define isSingleClient(settings)   ((settings->flags & FLAG_SINGLECLIENT) != 0)
232 #define isSingleUDP(settings)      ((settings->flags & FLAG_SINGLEUDP) != 0)
233
234 #define setBuflenSet(settings)     settings->flags |= FLAG_BUFLENSET
235 #define setCompat(settings)        settings->flags |= FLAG_COMPAT
236 #define setDaemon(settings)        settings->flags |= FLAG_DAEMON
237 #define setIPV6(settings)          settings->flags |= FLAG_DOMAIN
238 #define setFileInput(settings)     settings->flags |= FLAG_FILEINPUT
239 #define setNoDelay(settings)       settings->flags |= FLAG_NODELAY
240 #define setPrintMSS(settings)      settings->flags |= FLAG_PRINTMSS
241 #define setRemoveService(settings) settings->flags |= FLAG_REMOVESERVICE
242 #define setSTDIN(settings)         settings->flags |= FLAG_STDIN
243 #define setSTDOUT(settings)        settings->flags |= FLAG_STDOUT
244 #define setSuggestWin(settings)    settings->flags |= FLAG_SUGGESTWIN
245 #define setUDP(settings)           settings->flags |= FLAG_UDP
246 #define setModeTime(settings)      settings->flags |= FLAG_MODETIME
247 #define setReport(settings)        settings->flags |= FLAG_REPORTSETTINGS
248 #define setMulticast(settings)     settings->flags |= FLAG_MULTICAST
249 #define setNoSettReport(settings)  settings->flags |= FLAG_NOSETTREPORT
250 #define setNoConnReport(settings)  settings->flags |= FLAG_NOCONNREPORT
251 #define setNoDataReport(settings)  settings->flags |= FLAG_NODATAREPORT
252 #define setNoServReport(settings)  settings->flags |= FLAG_NOSERVREPORT
253 #define setNoMultReport(settings)  settings->flags |= FLAG_NOMULTREPORT
254 #define setSingleClient(settings)  settings->flags |= FLAG_SINGLECLIENT
255 #define setSingleUDP(settings)     settings->flags |= FLAG_SINGLEUDP
256
257 #define unsetBuflenSet(settings)   settings->flags &= ~FLAG_BUFLENSET
258 #define unsetCompat(settings)      settings->flags &= ~FLAG_COMPAT
259 #define unsetDaemon(settings)      settings->flags &= ~FLAG_DAEMON
260 #define unsetIPV6(settings)        settings->flags &= ~FLAG_DOMAIN
261 #define unsetFileInput(settings)   settings->flags &= ~FLAG_FILEINPUT
262 #define unsetNoDelay(settings)     settings->flags &= ~FLAG_NODELAY
263 #define unsetPrintMSS(settings)    settings->flags &= ~FLAG_PRINTMSS
264 #define unsetRemoveService(settings)  settings->flags &= ~FLAG_REMOVESERVICE
265 #define unsetSTDIN(settings)       settings->flags &= ~FLAG_STDIN
266 #define unsetSTDOUT(settings)      settings->flags &= ~FLAG_STDOUT
267 #define unsetSuggestWin(settings)  settings->flags &= ~FLAG_SUGGESTWIN
268 #define unsetUDP(settings)         settings->flags &= ~FLAG_UDP
269 #define unsetModeTime(settings)    settings->flags &= ~FLAG_MODETIME
270 #define unsetReport(settings)      settings->flags &= ~FLAG_REPORTSETTINGS
271 #define unsetMulticast(settings)   settings->flags &= ~FLAG_MULTICAST
272 #define unsetNoSettReport(settings)   settings->flags &= ~FLAG_NOSETTREPORT
273 #define unsetNoConnReport(settings)   settings->flags &= ~FLAG_NOCONNREPORT
274 #define unsetNoDataReport(settings)   settings->flags &= ~FLAG_NODATAREPORT
275 #define unsetNoServReport(settings)   settings->flags &= ~FLAG_NOSERVREPORT
276 #define unsetNoMultReport(settings)   settings->flags &= ~FLAG_NOMULTREPORT
277 #define unsetSingleClient(settings)   settings->flags &= ~FLAG_SINGLECLIENT
278 #define unsetSingleUDP(settings)      settings->flags &= ~FLAG_SINGLEUDP
279
280
281 #define HEADER_VERSION1 0x80000000
282 #define RUN_NOW         0x00000001
283
284 // used to reference the 4 byte ID number we place in UDP datagrams
285 // use int32_t if possible, otherwise a 32 bit bitfield (e.g. on J90) 
286 typedef struct UDP_datagram {
287 #ifdef HAVE_INT32_T
288     int32_t id;
289     u_int32_t tv_sec;
290     u_int32_t tv_usec;
291 #else
292     signed   int id      : 32;
293     unsigned int tv_sec  : 32;
294     unsigned int tv_usec : 32;
295 #endif
296 } UDP_datagram;
297
298 /*
299  * The client_hdr structure is sent from clients
300  * to servers to alert them of things that need
301  * to happen. Order must be perserved in all 
302  * future releases for backward compatibility.
303  * 1.7 has flags, numThreads, mPort, and bufferlen
304  */
305 typedef struct client_hdr {
306
307 #ifdef HAVE_INT32_T
308
309     /*
310      * flags is a bitmap for different options
311      * the most significant bits are for determining
312      * which information is available. So 1.7 uses
313      * 0x80000000 and the next time information is added
314      * the 1.7 bit will be set and 0x40000000 will be
315      * set signifying additional information. If no 
316      * information bits are set then the header is ignored.
317      * The lowest order diferentiates between dualtest and
318      * tradeoff modes, wheither the speaker needs to start 
319      * immediately or after the audience finishes.
320      */
321     int32_t flags;
322     int32_t numThreads;
323     int32_t mPort;
324     int32_t bufferlen;
325     int32_t mWinBand;
326     int32_t mAmount;
327 #else
328     signed int flags      : 32;
329     signed int numThreads : 32;
330     signed int mPort      : 32;
331     signed int bufferlen  : 32;
332     signed int mWinBand   : 32;
333     signed int mAmount    : 32;
334 #endif
335 } client_hdr;
336
337 /*
338  * The server_hdr structure facilitates the server
339  * report of jitter and loss on the client side.
340  * It piggy_backs on the existing clear to close
341  * packet.
342  */
343 typedef struct server_hdr {
344
345 #ifdef HAVE_INT32_T
346
347     /*
348      * flags is a bitmap for different options
349      * the most significant bits are for determining
350      * which information is available. So 1.7 uses
351      * 0x80000000 and the next time information is added
352      * the 1.7 bit will be set and 0x40000000 will be
353      * set signifying additional information. If no 
354      * information bits are set then the header is ignored.
355      */
356     int32_t flags;
357     int32_t total_len1;
358     int32_t total_len2;
359     int32_t stop_sec;
360     int32_t stop_usec;
361     int32_t error_cnt;
362     int32_t outorder_cnt;
363     int32_t datagrams;
364     int32_t jitter1;
365     int32_t jitter2;
366 #else
367     signed int flags        : 32;
368     signed int total_len1   : 32;
369     signed int total_len2   : 32;
370     signed int stop_sec     : 32;
371     signed int stop_usec    : 32;
372     signed int error_cnt    : 32;
373     signed int outorder_cnt : 32;
374     signed int datagrams    : 32;
375     signed int jitter1      : 32;
376     signed int jitter2      : 32;
377 #endif
378
379 } server_hdr;
380
381     // set to defaults
382     void Settings_Initialize( thread_Settings* main );
383
384     // copy structure
385     void Settings_Copy( thread_Settings* from, thread_Settings** into );
386
387     // free associated memory
388     void Settings_Destroy( thread_Settings *mSettings );
389
390     // parse settings from user's environment variables
391     void Settings_ParseEnvironment( thread_Settings *mSettings );
392
393     // parse settings from app's command line
394     void Settings_ParseCommandLine( int argc, char **argv, thread_Settings *mSettings );
395
396     // convert to lower case for [KMG]bits/sec
397     void Settings_GetLowerCaseArg(const char *,char *);
398
399     // convert to upper case for [KMG]bytes/sec
400     void Settings_GetUpperCaseArg(const char *,char *);
401
402     // generate settings for listener instance
403     void Settings_GenerateListenerSettings( thread_Settings *client, thread_Settings **listener);
404
405     // generate settings for speaker instance
406     void Settings_GenerateClientSettings( thread_Settings *server, 
407                                           thread_Settings **client,
408                                           client_hdr *hdr );
409
410     // generate client header for server
411     void Settings_GenerateClientHdr( thread_Settings *client, client_hdr *hdr );
412
413 #ifdef __cplusplus
414 } /* end extern "C" */
415 #endif
416
417 #endif // SETTINGS_H