1 /*--------------------------------------------------------------- 2 * Copyrighta (c) 2019 3 * Broadcom Corporation 4 * All Rights Reserved. 5 *--------------------------------------------------------------- 6 * Permission is hereby granted, free of charge, to any person 7 * obtaining a copy of this software 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 name of Broadcom Coporation, 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 * 42 * payloads.h 43 * Iperf 2 packet or socket payloads/protocols 44 * 45 * by Robert J. McMahon (rjmcmahon@rjmcmahon.com, bob.mcmahon@broadcom.com) 46 * ------------------------------------------------------------------- 47 */ 48 #ifndef PAYLOADSC_H 49 #define PAYLOADSC_H 50 51 #ifdef __cplusplus 52 extern "C" { 53 #endif 54 /* 55 * Message header flags 56 */ 57 58 #define TAPBYTESSLOP 512 59 60 /* key for permit */ 61 #define HEADER_KEYCHECK 0x10000000 62 #define HEADER_KEYL1 0x01000000 63 #define HEADER_KEYL2 0x02000000 64 #define HEADER_KEYLEN_MASK 0x0000FFFE // Lower bit used by V1 hdr 65 #define DEFAULT_PERMITKEY_LEN 16 66 #define MIN_PERMITKEY_LEN 4 67 #define MAX_PERMITKEY_LEN 128 68 69 /* 70 * base flags, keep compatible with older versions 71 */ 72 #define HEADER_VERSION1 0x80000000 73 #define HEADER_EXTEND 0x40000000 74 #define HEADER_UDPTESTS 0x20000000 75 #define HEADER_SEQNO64B 0x08000000 76 #define HEADER_VERSION2 0x04000000 77 #define HEADER_AVOID2 0x02000000 78 #define HEADER_AVOID1 0x01000000 79 #define HEADER_V2PEERDETECT 0x02000000 80 #define HEADER32_SMALL_TRIPTIMES 0x00020000 81 #define HEADER_LEN_BIT 0x00010000 82 #define HEADER_LEN_MASK 0x000001FE 83 #define MAX_HEADER_LEN 256 84 #define SERVER_HEADER_EXTEND 0x40000000 85 #define RUN_NOW 0x00000001 86 #define HEADER16_SMALL_TRIPTIMES 0x0002 // use is 16 bits and not 32 bits 87 88 // newer flags available per HEADER_EXTEND 89 // Below flags are used to pass test settings in *every* UDP packet 90 // and not just during the header exchange 91 #define HEADER_ISOCH 0x0001 92 #define HEADER_L2ETHPIPV6 0x0002 93 #define HEADER_L2LENCHECK 0x0004 94 #define HEADER_NOUDPFIN 0x0008 95 #define HEADER_TRIPTIME 0x0010 96 #define HEADER_UNUSED2 0x0020 97 #define HEADER_ISOCH_SETTINGS 0x0040 98 #define HEADER_UNITS_PPS 0x0080 99 #define HEADER_BWSET 0x0100 100 #define HEADER_FQRATESET 0x0200 101 #define HEADER_REVERSE 0x0400 102 #define HEADER_FULLDUPLEX 0x0800 103 #define HEADER_EPOCH_START 0x1000 104 #define HEADER_PERIODICBURST 0x2000 105 #define HEADER_WRITEPREFETCH 0x4000 106 107 // later features 108 #define HDRXACKMAX 2500000 // default 2.5 seconds, units microseconds 109 #define HDRXACKMIN 10000 // default 10 ms, units microseconds 110 111 /* 112 * Structures used for test messages which 113 * are exchanged between the client and the Server/Listener 114 */ 115 enum MsgType { 116 CLIENTHDR = 0x1, 117 CLIENTHDRACK, 118 CLIENTTCPHDR, 119 SERVERHDR, 120 SERVERHDRACK 121 }; 122 123 #define MINIPERFPAYLOAD 18 124 // Minimum IPv4 frame size = 18 (Ethernet) + 20 (IPv4) + 8 (UDP) + 18 (payload) = 64 bytes 125 // Minimum IPv6 frame size = 18 (Ethernet) + 40 (IPv6) + 8 (UDP) + 18 (payload) = 84 bytes 126 127 /* 128 * Structures below will be passed as network i/o 129 * between the client, listener and server 130 * and must be packed by the compilers 131 * Align on 32 bits (4 bytes) 132 */ 133 #pragma pack(push,4) 134 struct UDP_datagram { 135 // used to reference the 4 byte ID number we place in UDP datagrams 136 // Support 64 bit seqno on machines that support them 137 uint32_t id; 138 uint32_t tv_sec; 139 uint32_t tv_usec; 140 uint32_t id2; 141 }; 142 143 struct hdr_typelen { 144 int32_t type; 145 int32_t length; 146 }; 147 148 struct TCP_datagram { 149 // used to reference write ids and timestamps in TCP payloads 150 struct hdr_typelen typelen; 151 uint32_t id; 152 uint32_t id2; 153 uint32_t tv_sec; 154 uint32_t tv_usec; 155 uint32_t reserved1; 156 uint32_t reserved2; 157 }; 158 159 /* 160 * The client_hdr structure is sent from clients 161 * to servers to alert them of things that need 162 * to happen. Order must be perserved in all 163 * future releases for backward compatibility. 164 * 1.7 has flags, numThreads, mPort, and bufferlen 165 */ 166 struct client_hdr_v1 { 167 /* 168 * flags is a bitmap for different options 169 * the most significant bits are for determining 170 * which information is available. So 1.7 uses 171 * 0x80000000 and the next time information is added 172 * the 1.7 bit will be set and 0x40000000 will be 173 * set signifying additional information. If no 174 * information bits are set then the header is ignored. 175 * The lowest order diferentiates between dualtest and 176 * tradeoff modes, wheither the speaker needs to start 177 * immediately or after the audience finishes. 178 */ 179 int32_t flags; 180 int32_t numThreads; 181 int32_t mPort; 182 int32_t mBufLen; 183 int32_t mWinBand; 184 int32_t mAmount; 185 }; 186 187 struct client_hdrext_isoch_settings { 188 int32_t FPSl; 189 int32_t FPSu; 190 int32_t Meanl; 191 int32_t Meanu; 192 int32_t Variancel; 193 int32_t Varianceu; 194 int32_t BurstIPGl; 195 int32_t BurstIPGu; 196 }; 197 198 struct client_hdrext { 199 int32_t type; 200 int32_t length; 201 int16_t upperflags; 202 int16_t lowerflags; 203 uint32_t version_u; 204 uint32_t version_l; 205 uint16_t reserved; 206 uint16_t tos; 207 uint32_t lRate; 208 uint32_t uRate; 209 uint32_t TCPWritePrefetch; 210 }; 211 212 struct client_hdrext_starttime_fq { 213 uint32_t reserved; 214 uint32_t start_tv_sec; 215 uint32_t start_tv_usec; 216 uint32_t fqratel; 217 uint32_t fqrateu; 218 }; 219 220 /* 221 * TCP Isoch/burst payload structure 222 * 223 * 0 7 8 15 16 23 24 31 224 * +--------+--------+--------+--------+ 225 * 1 | type | 226 * +--------+--------+--------+--------+ 227 * 2 | len | 228 * +--------+--------+--------+--------+ 229 * 3 | flags | 230 * +--------+--------+--------+--------+ 231 * 4 | isoch burst period (s) | 232 * +--------+--------+--------+--------+ 233 * 5 | isoch burst period (us) | 234 * +--------+--------+--------+--------+ 235 * 6 | isoch start timestamp (s) | 236 * +--------+--------+--------+--------+ 237 * 7 | isoch start timestamp (us) | 238 * +--------+--------+--------+--------+ 239 * 8 | burst id | 240 * +--------+--------+--------+--------+ 241 * 9 | burtsize | 242 * +--------+--------+--------+--------+ 243 * 10 | burst bytes remaining | 244 * +--------+--------+--------+--------+ 245 * 11 | seqno lower | 246 * +--------+--------+--------+--------+ 247 * 12 | seqno upper | 248 * +--------+--------+--------+--------+ 249 * 13 | tv_sec (write) | 250 * +--------+--------+--------+--------+ 251 * 14 | tv_usec (write) | 252 * +--------+--------+--------+--------+ 253 * 15 | tv_sec (read) | 254 * +--------+--------+--------+--------+ 255 * 16 | tv_usec (read) | 256 * +--------+--------+--------+--------+ 257 * 17 | tv_sec (write-ack) | 258 * +--------+--------+--------+--------+ 259 * 18 | tv_usec (write-ack) | 260 * +--------+--------+--------+--------+ 261 * 19 | tv_sec (read-ack) | 262 * +--------+--------+--------+--------+ 263 * 20 | tv_usec (read-ack) | 264 * +--------+--------+--------+--------+ 265 * 21 | reserved | 266 * +--------+--------+--------+--------+ 267 * 22 | reserved | 268 * +--------+--------+--------+--------+ 269 * 23 | reserved | 270 * +--------+--------+--------+--------+ 271 * 24 | reserved | 272 * +--------+--------+--------+--------+ 273 * 274 */ 275 struct TCP_oneway_triptime { 276 uint32_t write_tv_sec; 277 uint32_t write_tv_usec; 278 uint32_t read_tv_sec; 279 uint32_t read_tv_usec; 280 }; 281 282 struct TCP_burst_payload { 283 uint32_t flags; 284 struct hdr_typelen typelen; 285 uint32_t start_tv_sec; 286 uint32_t start_tv_usec; 287 struct TCP_oneway_triptime send_tt; 288 uint32_t burst_period_s; 289 uint32_t burst_period_us; 290 uint32_t burst_id; 291 uint32_t burst_size; 292 uint32_t seqno_lower; 293 uint32_t seqno_upper; 294 struct TCP_oneway_triptime writeacktt; 295 uint32_t reserved1; 296 uint32_t reserved2; 297 uint32_t reserved3; 298 uint32_t reserved4; 299 }; 300 301 /* 302 * UDP Full Isoch payload structure 303 * 304 * 0 7 8 15 16 23 24 31 305 * +--------+--------+--------+--------+ 306 * 0x00 1 | seqno lower | 307 * +--------+--------+--------+--------+ 308 * 0x04 2 | tv_sec | 309 * +--------+--------+--------+--------+ 310 * 0x08 3 | tv_usec | 311 * +--------+--------+--------+--------+ 312 * 4 | seqno upper | 313 * +--------+--------+--------+--------+ 314 * 5 | flags (v1) | 315 * +--------+--------+--------+--------+ 316 * 6 | numThreads (v1) | 317 * +--------+--------+--------+--------+ 318 * 7 | mPort (v1) | 319 * +--------+--------+--------+--------+ 320 * 8 | bufferLen (v1) | 321 * +--------+--------+--------+--------+ 322 * 9 | mWinBand (v1) | 323 * +--------+--------+--------+--------+ 324 * 10 | mAmount (v1) | 325 * +--------+--------+--------+--------+ 326 * 11 | up flags | low flags | 327 * +--------+--------+--------+--------+ 328 * 12 | iperf version major | 329 * +--------+--------+--------+--------+ 330 * 13 | iperf version minor | 331 * +--------+--------+--------+--------+ 332 * 14 | reserved | TOS | 333 * +--------+--------+--------+--------+ 334 * 15 | rate | 335 * +--------+--------+--------+--------+ 336 * 16 | rate units | 337 * +--------+--------+--------+--------+ 338 * 17 | realtime (0.13) | 339 * +--------+--------+--------+--------+ 340 * 18 | isoch burst period (us) | 341 * +--------+--------+--------+--------+ 342 * 19 | isoch start timestamp (s) | 343 * +--------+--------+--------+--------+ 344 * 20 | isoch start timestamp (us) | 345 * +--------+--------+--------+--------+ 346 * 21 | isoch prev frameid | 347 * +--------+--------+--------+--------+ 348 * 22 | isoch frameid | 349 * +--------+--------+--------+--------+ 350 * 23 | isoch burtsize | 351 * +--------+--------+--------+--------+ 352 * 24 | isoch bytes remaining | 353 * +--------+--------+--------+--------+ 354 * 25 | isoch reserved | 355 * +--------+--------+--------+--------+ 356 * 26 | reserved (0.14 start) | 357 * +--------+--------+--------+--------+ 358 * 28 | start tv_sec (0.14) | 359 * +--------+--------+--------+--------+ 360 * 29 | start tv_usec | 361 * +--------+--------+--------+--------+ 362 * 27 | fqratel | 363 * +--------+--------+--------+--------+ 364 * 28 | fqrateu | 365 * +--------+--------+--------+--------+ 366 * 29 | FPSl | 367 * +--------+--------+--------+--------+ 368 * 30 | FPSu | 369 * +--------+--------+--------+--------+ 370 * 31 | Meanl | 371 * +--------+--------+--------+--------+ 372 * 32 | Meanu | 373 * +--------+--------+--------+--------+ 374 * 33 | Variancel | 375 * +--------+--------+--------+--------+ 376 * 34 | Varianceu | 377 * +--------+--------+--------+--------+ 378 * 35 | BurstIPGl | 379 * +--------+--------+--------+--------+ 380 * 36 | BurstIPG | 381 * +--------+--------+--------+--------+ 382 * 383 */ 384 struct isoch_payload { 385 uint32_t burstperiod; //period units microseconds 386 uint32_t start_tv_sec; 387 uint32_t start_tv_usec; 388 uint32_t prevframeid; 389 uint32_t frameid; 390 uint32_t burstsize; 391 uint32_t remaining; 392 uint32_t reserved; 393 }; 394 395 struct permitKey { 396 uint16_t length; 397 char value[MAX_PERMITKEY_LEN]; 398 }; 399 400 struct client_udp_testhdr { 401 struct UDP_datagram seqno_ts; 402 struct client_hdr_v1 base; 403 struct client_hdrext extend; 404 struct isoch_payload isoch; 405 struct client_hdrext_starttime_fq start_fq; 406 struct client_hdrext_isoch_settings isoch_settings; 407 }; 408 409 struct client_udpsmall_testhdr { 410 struct UDP_datagram seqno_ts; 411 uint16_t flags; 412 }; 413 414 struct client_hdr_ack_ts { 415 uint32_t sent_tv_sec; 416 uint32_t sent_tv_usec; 417 uint32_t sentrx_tv_sec; 418 uint32_t sentrx_tv_usec; 419 uint32_t ack_tv_sec; 420 uint32_t ack_tv_usec; 421 }; 422 423 struct client_hdr_ack { 424 struct hdr_typelen typelen; 425 uint32_t flags; 426 uint32_t version_u; 427 uint32_t version_l; 428 uint32_t reserved1; 429 uint32_t reserved2; 430 struct client_hdr_ack_ts ts; 431 }; 432 433 /* 434 * TCP first payload structure 435 * 436 * 0 7 8 15 16 23 24 31 437 * +--------+--------+--------+--------+ 438 * 0x00 1 | flags (v1) | 439 * +--------+--------+--------+--------+ 440 * 2 | numThreads (v1) | 441 * +--------+--------+--------+--------+ 442 * 3 | mPort (v1) | 443 * +--------+--------+--------+--------+ 444 * 4 | bufferLen (v1) | 445 * +--------+--------+--------+--------+ 446 * 5 | mWinBand (v1) | 447 * +--------+--------+--------+--------+ 448 * 6 | mAmount (v1) | 449 * +--------+--------+--------+--------+ 450 * 7 | type (0.13) | 451 * +--------+--------+--------+--------+ 452 * 8 | len (0.13) | 453 * +--------+--------+--------+--------+ 454 * 9 | flags (0.13) | 455 * +--------+--------+--------+--------+ 456 * 10 | iperf version major | 457 * +--------+--------+--------+--------+ 458 * 11 | iperf version minor | 459 * +--------+--------+--------+--------+ 460 * 12 | reserved | TOS | 461 * +--------+--------+--------+--------+ 462 * 13 | rate | 463 * +--------+--------+--------+--------+ 464 * 14 | rate units | 465 * +--------+--------+--------+--------+ 466 * 15 | write prefetch (0.13) | 467 * +--------+--------+--------+--------+ 468 * 16 | reserved (0.14 start) | 469 * +--------+--------+--------+--------+ 470 * 17 | start tv_sec (0.14) | 471 * +--------+--------+--------+--------+ 472 * 18 | start tv_usec | 473 * +--------+--------+--------+--------+ 474 * 19 | fqratel | 475 * +--------+--------+--------+--------+ 476 * 20 | fqrateu | 477 * +--------+--------+--------+--------+ 478 * 21 | FPSl | 479 * +--------+--------+--------+--------+ 480 * 22 | FPSu | 481 * +--------+--------+--------+--------+ 482 * 23 | Meanl | 483 * +--------+--------+--------+--------+ 484 * 24 | Meanu | 485 * +--------+--------+--------+--------+ 486 * 25 | Variancel | 487 * +--------+--------+--------+--------+ 488 * 26 | Varianceu | 489 * +--------+--------+--------+--------+ 490 * 27 | BurstIPGl | 491 * +--------+--------+--------+--------+ 492 * 28 | BurstIPG | 493 * +--------+--------+--------+--------+ 494 */ 495 struct client_tcp_testhdr { 496 struct client_hdr_v1 base; 497 struct client_hdrext extend; 498 struct client_hdrext_starttime_fq start_fq; 499 struct client_hdrext_isoch_settings isoch_settings; 500 struct permitKey permitkey; 501 }; 502 503 /* 504 * The server_hdr structure facilitates the server 505 * report of jitter and loss on the client side. 506 * It piggy_backs on the existing clear to close 507 * packet. 508 */ 509 struct server_hdr_v1 { 510 /* 511 * flags is a bitmap for different options 512 * the most significant bits are for determining 513 * which information is available. So 1.7 uses 514 * 0x80000000 and the next time information is added 515 * the 1.7 bit will be set and 0x40000000 will be 516 * set signifying additional information. If no 517 * information bits are set then the header is ignored. 518 */ 519 int32_t flags; 520 int32_t total_len1; 521 int32_t total_len2; 522 int32_t stop_sec; 523 int32_t stop_usec; 524 int32_t error_cnt; 525 int32_t outorder_cnt; 526 int32_t datagrams; 527 int32_t jitter1; 528 int32_t jitter2; 529 }; 530 531 struct server_hdr_extension { 532 int32_t minTransit1; 533 int32_t minTransit2; 534 int32_t maxTransit1; 535 int32_t maxTransit2; 536 int32_t sumTransit1; 537 int32_t sumTransit2; 538 int32_t meanTransit1; 539 int32_t meanTransit2; 540 int32_t m2Transit1; 541 int32_t m2Transit2; 542 int32_t vdTransit1; 543 int32_t vdTransit2; 544 int32_t cntTransit; 545 int32_t cntIPG; 546 int32_t IPGsum; 547 }; 548 549 // Extension for 64bit datagram counts 550 struct server_hdr_extension2 { 551 int32_t error_cnt2; 552 int32_t outorder_cnt2; 553 int32_t datagrams2; 554 }; 555 556 struct server_hdr { 557 struct server_hdr_v1 base; 558 struct server_hdr_extension extend; 559 struct server_hdr_extension2 extend2; 560 }; 561 562 #pragma pack(pop) 563 564 #define SIZEOF_UDPHDRMSG_V1 (sizeof(struct client_hdrv1) + sizeof(struct UDP_datagram)) 565 #define SIZEOF_UDPHDRMSG_EXT (sizeof(struct client_udp_testhdr)) 566 #define SIZEOF_TCPHDRMSG_V1 (sizeof(struct client_hdr_v1)) 567 #define SIZEOF_TCPHDRMSG_EXT (sizeof(struct client_tcp_testhdr)) 568 #define MINMBUFALLOCSIZE (int) (sizeof(struct client_tcp_testhdr)) 569 #define MINTRIPTIMEPLAYOAD (int) (sizeof(struct client_udp_testhdr) - sizeof(struct client_hdrext_isoch_settings)) 570 #ifdef __cplusplus 571 } /* end extern "C" */ 572 #endif 573 574 #endif // PAYLOADS 575