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