1 /** 2 * @file common.h 3 * @brief Data structures used by the Flowgrind daemon and controller 4 */ 5 6 /* 7 * Copyright (C) 2013-2014 Alexander Zimmermann <alexander.zimmermann@netapp.com> 8 * Copyright (C) 2010-2013 Christian Samsel <christian.samsel@rwth-aachen.de> 9 * Copyright (C) 2009 Tim Kosse <tim.kosse@gmx.de> 10 * Copyright (C) 2007-2008 Daniel Schaffrath <daniel.schaffrath@mac.com> 11 * 12 * This file is part of Flowgrind. 13 * 14 * Flowgrind is free software: you can redistribute it and/or modify 15 * it under the terms of the GNU General Public License as published by 16 * the Free Software Foundation, either version 3 of the License, or 17 * (at your option) any later version. 18 * 19 * Flowgrind is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License 25 * along with Flowgrind. If not, see <http://www.gnu.org/licenses/>. 26 * 27 */ 28 29 #ifndef _COMMON_H_ 30 #define _COMMON_H_ 31 32 #ifdef HAVE_CONFIG_H 33 #include "config.h" 34 #endif /* HAVE_CONFIG_H */ 35 36 #include <sys/time.h> 37 #include <time.h> 38 #include <stdint.h> 39 40 #include "gitversion.h" 41 42 #ifdef GITVERSION 43 /** Flowgrind version number. */ 44 #define FLOWGRIND_VERSION GITVERSION 45 #elif defined PACKAGE_VERSION 46 #define FLOWGRIND_VERSION PACKAGE_VERSION 47 #else /* GITVERSION */ 48 #define FLOWGRIND_VERSION "(n/a)" 49 #endif /* GITVERSION */ 50 51 /** XML-RPC API version in integer representation. */ 52 #define FLOWGRIND_API_VERSION 3 53 54 /** Daemon's default listen port. */ 55 #define DEFAULT_LISTEN_PORT 5999 56 57 /** Maximal number of parallel flows supported by one controller. */ 58 #define MAX_FLOWS_CONTROLLER 2048 59 60 /** Maximal number of parallel flows supported by one daemon instance. 61 * This is currenty limited by the file descriptor number which can 62 * be added to an fd_set. As we currently may need up to two FDs per 63 * destination, we limit this to half of FD_SETSIZE. 64 */ 65 #define MAX_FLOWS_DAEMON FD_SETSIZE >> 1 66 67 /** Max number of arbitrary extra socket options which may sent to the deamon. */ 68 #define MAX_EXTRA_SOCKET_OPTIONS 10 69 70 /** Ensures extra options are limited in length on both controller and deamon. */ 71 #define MAX_EXTRA_SOCKET_OPTION_VALUE_LENGTH 100 72 73 #ifndef TCP_CA_NAME_MAX 74 /** Max size of the congestion control algorithm specifier string. */ 75 #define TCP_CA_NAME_MAX 16 76 #endif /* TCP_CA_NAME_MAX */ 77 78 /** Minium block (message) size we can send. */ 79 #define MIN_BLOCK_SIZE (signed) sizeof (struct block) 80 81 /** Flowgrind's copyright year. */ 82 #define FLOWGRIND_COPYRIGHT "Copyright (C) 2007 - 2021 Flowgrind authors." 83 84 /** Standard GPL3 no warranty message. */ 85 #define FLOWGRIND_COPYING \ 86 "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n" \ 87 "This is free software: you are free to change and redistribute it.\n" \ 88 "There is NO WARRANTY, to the extent permitted by law." 89 90 /** Flowgrind's authors in a printable string. */ 91 #define FLOWGRIND_AUTHORS \ 92 "Written by Arnd Hannemann, Tim Kosse, Christian Samsel, Daniel Schaffrath\n" \ 93 "and Alexander Zimmermann." 94 95 /** Flow endpoint types. */ 96 enum endpoint_t { 97 /** Endpoint that opens the connection. */ 98 SOURCE = 0, 99 /** Endpoint that accepts the connection. */ 100 DESTINATION, 101 }; 102 103 /** I/O operation types. */ 104 enum io_t { 105 /** Write operation. */ 106 WRITE = 0, 107 /** Read operation. */ 108 READ, 109 }; 110 111 /** Report types. */ 112 enum report_t { 113 /** Intermediated interval report. */ 114 INTERVAL = 0, 115 /** Final report. */ 116 FINAL, 117 }; 118 119 /* XXX add a brief description doxygen. */ 120 enum extra_socket_option_level { 121 level_sol_socket, 122 level_sol_tcp, 123 level_ipproto_ip, 124 level_ipproto_sctp, 125 level_ipproto_tcp, 126 level_ipproto_udp, 127 }; 128 129 /** Stochastic distributions for traffic generation. */ 130 enum distribution_t { 131 /** No stochastic distribution. */ 132 CONSTANT = 0, 133 /** Normal distribution. */ 134 NORMAL, 135 /** Weibull distribution. */ 136 WEIBULL, 137 /** Uniform distribution. */ 138 UNIFORM, 139 /** Exponential distribution. */ 140 EXPONENTIAL, 141 /** Pareto distribution. */ 142 PARETO, 143 /** Log Normal distribution. */ 144 LOGNORMAL, 145 }; 146 147 /** Flowgrind's data block layout. */ 148 struct block { 149 /** Size of our request or response block. */ 150 int32_t this_block_size; 151 152 /** 153 * Size of the response block we request. 154 * 155 * 0 indicates that we don't request a response block. <BR> 156 * -1 indicates this is a response block (needed for parsing data). */ 157 int32_t request_block_size; 158 159 /** Sending timestap for calculating delay and RTT. */ 160 struct timespec data; 161 /** Used to access 64bit timespec on 32bit arch. */ 162 struct timespec data2; 163 }; 164 165 /** Options for stochastic traffic generation. */ 166 struct trafgen_options { 167 /** The stochastic distribution to draw values from. */ 168 enum distribution_t distribution; 169 /** First mathemathical parameter of the distribution. */ 170 double param_one; 171 /** Second mathematical parameter of the distribution, if required. */ 172 double param_two; 173 174 }; 175 176 /** 177 * Settings that describe a flow between from a endpoint's perspective. 178 * 179 * These options can be specified for each of the two endpoints. 180 */ 181 struct flow_settings { 182 /** The interface address for the flow (used by daemon). */ 183 char bind_address[1000]; 184 185 /** Flow ID maintained by controller. */ 186 int flow_id; 187 /** Delay of flow in seconds (option -Y). */ 188 double delay[2]; 189 /** Duration of flow in seconds (option -T). */ 190 double duration[2]; 191 192 /** Interval to report flow on screen (option -i). */ 193 double reporting_interval; 194 195 /** Request sender buffer in bytes (option -B). */ 196 int requested_send_buffer_size; 197 /** Request receiver buffer, advertised window in bytes (option -W). */ 198 int requested_read_buffer_size; 199 200 /** Application buffer size in bytes (option -U). */ 201 int maximum_block_size; 202 203 /** Dump traffic using libpcap (option -M). */ 204 int traffic_dump; 205 /** Sets SO_DEBUG on test socket (option -O). */ 206 int so_debug; 207 /** Sets ROUTE_RECORD on test socket (option -O). */ 208 int route_record; 209 /** 210 * Do not iterate through select() to continue sending in case 211 * block size did not suffice to fill sending queue (pushy) (option -P). 212 */ 213 int pushy; 214 /** Shutdown socket after test flow (option -N). */ 215 int shutdown; 216 217 /** Send at specified rate per second (option -R). */ 218 const char *write_rate_str; 219 /** The actual rate we should send. */ 220 int write_rate; 221 222 /** Random seed to use (default: read /dev/urandom) (option -J). */ 223 unsigned random_seed; 224 225 /** Stop flow if it is experiencing local congestion (option -C). */ 226 int flow_control; 227 228 /** Enumerate bytes in payload instead of sending zeros (option -E). */ 229 int byte_counting; 230 231 /** Sets SO_DEBUG on test socket (option -O). */ 232 int cork; 233 /** Disable nagle algorithm on test socket (option -O). */ 234 int nonagle; 235 /** Set congestion control algorithm ALG on test socket (option -O). */ 236 char cc_alg[TCP_CA_NAME_MAX]; 237 /** Set TCP_ELCN (20) on test socket (option -O). */ 238 int elcn; 239 /** Set TCP_LCD (21) on test socket (option -O). */ 240 int lcd; 241 /** Set TCP_MTCP (15) on test socket (option -O). */ 242 int mtcp; 243 /** DSCP value for TOS byte (option -D). */ 244 int dscp; 245 /** Set IP_MTU_DISCOVER on test socket (option -O). */ 246 int ipmtudiscover; 247 248 /** Stochastic traffic generation settings for the request size. */ 249 struct trafgen_options request_trafgen_options; 250 /** Stochastic traffic generation settings for the response size. */ 251 struct trafgen_options response_trafgen_options; 252 /** Stochastic traffic generation settings for the interpacket gap. */ 253 struct trafgen_options interpacket_gap_trafgen_options; 254 255 /* XXX add a brief description doxygen + is this obsolete? */ 256 struct extra_socket_options { 257 int level; 258 int optname; 259 int optlen; 260 char optval[MAX_EXTRA_SOCKET_OPTION_VALUE_LENGTH]; 261 } extra_socket_options[MAX_EXTRA_SOCKET_OPTIONS]; 262 int num_extra_socket_options; 263 }; 264 265 /* Flowgrinds view on the tcp_info struct for 266 * serialization / deserialization */ 267 struct fg_tcp_info { 268 int tcpi_snd_cwnd; 269 int tcpi_snd_ssthresh; 270 int tcpi_unacked; 271 int tcpi_sacked; 272 int tcpi_lost; 273 int tcpi_retrans; 274 int tcpi_retransmits; 275 int tcpi_fackets; 276 int tcpi_reordering; 277 int tcpi_rtt; 278 int tcpi_rttvar; 279 int tcpi_rto; 280 int tcpi_backoff; 281 int tcpi_snd_mss; 282 int tcpi_ca_state; 283 }; 284 285 /* Report (measurement sample) of a flow */ 286 struct report { 287 int id; 288 /** Daemon endpoint - either source or destination */ 289 enum endpoint_t endpoint; 290 /** Report type - either INTERVAL or FINAL report */ 291 enum report_t type; 292 struct timespec begin; 293 struct timespec end; 294 #ifdef HAVE_UNSIGNED_LONG_LONG_INT 295 unsigned long long bytes_read; 296 unsigned long long bytes_written; 297 #else /* HAVE_UNSIGNED_LONG_LONG_INT */ 298 long bytes_read; 299 long bytes_written; 300 #endif /* HAVE_UNSIGNED_LONG_LONG_INT */ 301 unsigned request_blocks_read; 302 unsigned request_blocks_written; 303 unsigned response_blocks_read; 304 unsigned response_blocks_written; 305 306 /* TODO Create an array for IAT / RTT and delay */ 307 308 /** Minimum inter-arrival time. */ 309 double iat_min; 310 /** Maximum inter-arrival time. */ 311 double iat_max; 312 /** Accumulated inter-arrival time. */ 313 double iat_sum; 314 /** Minimum one-way delay. */ 315 double delay_min; 316 /** Maximum one-way delay. */ 317 double delay_max; 318 /** Accumulated one-way delay. */ 319 double delay_sum; 320 /** Minimum round-trip time. */ 321 double rtt_min; 322 /** Maximum round-trip time. */ 323 double rtt_max; 324 /** Accumulated round-trip time. */ 325 double rtt_sum; 326 327 /* on the Daemon this is filled from the os specific 328 * tcp_info struct */ 329 struct fg_tcp_info tcp_info; 330 331 /** Discovered Path MTU */ 332 unsigned pmtu; 333 /** Interface MTU */ 334 unsigned imtu; 335 336 int status; 337 338 struct report* next; 339 }; 340 341 #endif /* _COMMON_H_*/ 342