diag_sand_packet.h (16931B)
1 /** 2 * \file diag_sand_packet.h 3 * 4 * Header for diag command 'dnx packet'. 5 */ 6 /* 7 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 8 * 9 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 10 */ 11 12 #ifndef DIAG_SAND_PACKET_INCLUDED 13 #define DIAG_SAND_PACKET_INCLUDED 14 15 /* 16 * Dependencies (includes) 17 * { 18 */ 19 #include <soc/sand/sand_pparse.h> 20 #include <appl/diag/shell.h> 21 #include <appl/diag/sand/diag_sand_framework.h> 22 23 #include <bcm/sat.h> 24 /* 25 * } 26 * Dependencies (includes) 27 */ 28 29 #define SAND_PACKET_DEFAULT_SIZE_BYTES 128 30 31 #define TAGGED_PACKET_LENGTH 68 32 #define UNTAGGED_PACKET_LENGTH 64 33 34 /* 35 * Flags controlling packet send behavior 36 * { 37 */ 38 /* 39 * signal cache will be cleared before send, otherwise left untouched 40 */ 41 #define SAND_PACKET_RESUME 0x01 42 /* 43 * Initiate recording receive packets in dedicated global queue 44 */ 45 #define SAND_PACKET_RX 0x02 46 /* 47 * Send packet stream from SAT port 48 */ 49 #define SAND_PACKET_SAT 0x04 50 /* 51 * Stop running SAT stream 52 */ 53 #define SAND_PACKET_STOP 0x08 54 55 /* 56 * Flag that indicates that a SA field will be incremented during sending packet stream 57 */ 58 #define SAND_PACKET_STREAM_SA_INCREMENTAL_FIELD 0x01 59 /* 60 * } 61 */ 62 63 #define SAND_STREAM_TIME_MAX 3600 64 /* 65 * In order to avoid changing granularity on SDK level use BY_BCM 66 */ 67 #define SAT_GRANULARITY_SET_BY_BCM 0 68 /* 69 * In order to granularity adopted to rate use BY_DIAG 70 */ 71 #define SAT_GRANULARITY_SET_BY_DIAG -1 72 73 typedef struct 74 { 75 int gtf_id; 76 int rate_unit; 77 int rate; 78 int burst; 79 int granularity; /* clocks per cycle */ 80 int duration; 81 int running; 82 } sand_packet_stream_t; 83 84 typedef struct 85 { 86 int ctf_id; 87 bcm_field_entry_t entry_id; 88 } sand_packet_collector_t; 89 90 typedef struct 91 { 92 rhentry_t entry; 93 rhlist_t *proto_list; 94 int core_id; 95 int header_size; 96 int packet_size; 97 uint32 flags; 98 sand_packet_stream_t stream; 99 sand_packet_collector_t collector; 100 } sand_packet_t; 101 102 #define PACKET_GRANULARITY(packet_h_mac) (((sand_packet_t *)packet_h_mac)->stream.granularity) 103 #define PACKET_DURATION(packet_h_mac) (((sand_packet_t *)packet_h_mac)->stream.duration) 104 #define PACKET_RATE(packet_h_mac) (((sand_packet_t *)packet_h_mac)->stream.rate) 105 #define PACKET_BURST(packet_h_mac) (((sand_packet_t *)packet_h_mac)->stream.burst) 106 #define PACKET_GTF_ID(packet_h_mac) (((sand_packet_t *)packet_h_mac)->stream.gtf_id) 107 #define PACKET_PROTO_LIST(packet_h_mac) (((sand_packet_t *)packet_h_mac)->proto_list) 108 #define PACKET_SIZE(packet_h_mac) (((sand_packet_t *)packet_h_mac)->packet_size) 109 #define PACKET_CORE(packet_h_mac) (((sand_packet_t *)packet_h_mac)->core_id) 110 111 #define PACKET_CTF_ID(packet_h_mac) (((sand_packet_t *)packet_h_mac)->collector.ctf_id) 112 113 shr_error_e diag_sand_packet_sat_rx_get_stats( 114 int unit, 115 int ctf_id, 116 uint64 *rcv_packet_count_p, 117 uint64 *err_packet_count_p, 118 uint64 *ooo_packet_count_p); 119 120 shr_error_e diag_sand_packet_sat_rx_start( 121 int unit); 122 123 shr_error_e diag_sand_packet_sat_rx_destroy( 124 int unit); 125 126 shr_error_e diag_sand_packet_sat_rx_create( 127 int unit, 128 rhhandle_t packet_h, 129 uint32 out_port); 130 131 /** 132 * \brief 133 * Generate gtf for SAT packet streaming 134 * \param [in] unit - Unit # 135 * \param [in] core_id - core id #* 136 * \param [in] packet_handle - handle to the object which holds all packet/stream related params 137 * \param [in] pkt_length - full packet length (units: bytes) 138 * \param [in] time - time period for stream (units: seconds) 139 * \param [in] rate_unit - unit for rate parameter - either kbits or packets per second 140 * \param [in] rate - stream rate (units: kbits per second) 141 * \param [in] burst - stream burst size (units: bytes) 142 * \param [in] granularity - globally clocks per cycle, 143 * Special values 144 * SAT_GRANULARITY_SET_BY_DIAG - when there is a need to have optimized flat flow with high 145 * rates, not to be used when multiple flows with different rates 146 * are in use. If there is a need for multiple, for the first 147 * stream use BY_DIAG, for the rest BY_BCM 148 * SAT_GRANULARITY_SET_BY_BCM - for multiple flows with lower rates 149 * 150 * \retval _SHR_E_NONE for success 151 * \retval shr_error_e Standard error handling 152 * \see 153 * diag_sand_packet_create 154 */ 155 shr_error_e diag_sand_packet_stream_create( 156 int unit, 157 int core_id, 158 rhhandle_t packet_handle, 159 int pkt_length, 160 int time, 161 int rate_unit, 162 int rate, 163 int burst, 164 int granularity); 165 166 /** 167 * \brief 168 * Fetch statistics for SAT packet streaming 169 * \param [in] unit - Unit # 170 * \param [in] packet_handle - handle to the object which holds all packet/stream related params 171 * \param [out] bytes_count_p - pointer to byte count after running SAT stream 172 * \param [out] packet_count_p - pointer to packet count after running SAT stream 173 * 174 * \retval _SHR_E_NONE for success 175 * \retval shr_error_e Standard error handling 176 * \see 177 * diag_sand_packet_create 178 */ 179 shr_error_e diag_sand_packet_stream_get_stats( 180 int unit, 181 rhhandle_t packet_handle, 182 uint64 *bytes_count_p, 183 uint64 *packet_count_p); 184 185 /** 186 * \brief 187 * Start streams for all packet handles in array 188 * \param [in] unit - Unit # 189 * \param [in] packet_handles - pointer to array of handles to the object which holds all packet/stream related params 190 * \param [in] stream_nof - number of streams 191 * 192 * \retval _SHR_E_NONE for success 193 * \retval shr_error_e Standard error handling 194 * \see 195 * diag_sand_packet_send 196 */ 197 shr_error_e diag_sand_packet_stream_send( 198 int unit, 199 rhhandle_t * packet_handles, 200 int stream_nof); 201 202 /** 203 * \brief 204 * Send packet from port 205 * \param [in] unit - Unit # 206 * \param [in] src_port - port id, if you don't know what to do use 0 - default CPU IN_TM_PORT 207 * \param [in] packet_length - full packet length including headers and payload. O - no payload 208 * \param [in] data_string - data to be sent 209 * \param [in] flags - misc flags controlling packet tx 210 * 211 * \retval _SHR_E_NONE for success 212 * \retval shr_error_e Standard error handling 213 * \see 214 * diag_sand_packet_create 215 */ 216 shr_error_e diag_sand_packet_tx( 217 int unit, 218 bcm_port_t src_port, 219 int packet_length, 220 char *data_string, 221 uint32 flags); 222 223 /** 224 * \brief 225 * Allocate new packet object to be used by other diag_sand_packet* APIs 226 * \param [in] unit - Unit # 227 * \param [in,out] packet_handle_p - pointer to packet control handle allocated 228 * 229 * \retval _SHR_E_NONE for success 230 * \retval _SHR_E_MEMORY problem with allocating new object 231 * \retval shr_error_e Standard error handling 232 * \remark 233 * Each invocation will create new packet, do not forget to free it using diag_sand_packet_free 234 * \see 235 * diag_sand_packet_free 236 */ 237 shr_error_e diag_sand_packet_create( 238 int unit, 239 rhhandle_t * packet_handle_p); 240 241 /** 242 * \brief 243 * Add proto to header stack of packet, order of adding will be reflected in packet structure, handle to added header an output 244 * \param [in] unit - Unit # 245 * \param [in] packet_handle - packet control handle 246 * \param [in] proto - name of protocol to be used when adding header, see NetworkStructures.xml for the list of supported ones. 247 * 248 * \retval _SHR_E_NONE for success 249 * \retval _SHR_E_PARAM problem with protocol 250 * \retval shr_error_e Standard error handling 251 * \remark 252 * use "sig struct pkt" to list all supported protocols 253 * \see 254 * NetworkStructures.xml 255 */ 256 shr_error_e diag_sand_packet_proto_add( 257 int unit, 258 rhhandle_t packet_handle, 259 char *proto); 260 261 /** 262 * \brief 263 * Add field that need to be different from default value(provided by NetworkStructures.xml). Input value is provided by string 264 * \param [in] unit - Unit # 265 * \param [in] packet_handle - handle to the packet, the field is added to, 266 * \param [in] field_name - name of protocol field, including protocol name itself. E.g. VLAN.VID, ETH.DA. 267 * Field name may be complex one and actually be subfield of a field. e.g. IPv6.sip.low 268 * \param [in] str_value - pointer to the string representing value of field specified by field_name, 269 * string size should match field definition and in anyway not bigger than DSIG_MAX_SIZE_STR 270 * \retval _SHR_E_NONE for success 271 * \retval _SHR_E_PARAM problem with field name 272 * \retval shr_error_e Standard error handling 273 * \remark 274 * use "sig struct pkt" to list all supported protocols 275 * Add second time same field to the same header will replace previous value, useful for testing different values of specific qualifiers 276 * \see 277 * NetworkStructures.xml 278 */ 279 shr_error_e diag_sand_packet_field_add_str( 280 int unit, 281 rhhandle_t packet_handle, 282 char *field_name, 283 char *str_value); 284 285 /** 286 * \brief 287 * Add field that need to be different from default value(provided by NetworkStructures.xml). Input value is provided by uint32 array 288 * \param [in] unit - Unit # 289 * \param [in] packet_handle - handle to the packet, the field is added to, obtained from diag_sand_packet_proto_add 290 * \param [in] field_name - name of protocol field, including protocol name itself. E.g. VLAN.VID, ETH.DA. 291 * Field name may be complex one and actually be subfield of a field. e.g. IPv6.sip.low 292 * \param [in] uint32_value - pointer to uint32 array representing value of field specified by field_name, size should match field definition 293 * \param [in] bit_size - size(in bits) should match field definition 294 * \retval _SHR_E_NONE for success 295 * \retval _SHR_E_PARAM problem with field name 296 * \retval shr_error_e Standard error handling 297 * \remark 298 * use "sig struct pkt" to list all supported protocols 299 * Add second time same field to the same header will replace previous value, useful for testing different values of specific qualifiers 300 * \see 301 * NetworkStructures.xml 302 */ 303 shr_error_e diag_sand_packet_field_add_uint32( 304 int unit, 305 rhhandle_t packet_handle, 306 char *field_name, 307 uint32 *uint32_value, 308 int bit_size); 309 310 /** 311 * \brief 312 * Frees packet control structure and all underlying allocated objects 313 * \param [in] unit - Unit # 314 * \param [in] packet_handle - packet control handle 315 * 316 * \retval _SHR_E_NONE for success 317 * \retval shr_error_e Standard error handling 318 * \remark 319 * If the handle is NULL - no error will be issued and no log will be recorder 320 * \see 321 * diag_sand_packet_create 322 */ 323 void diag_sand_packet_free( 324 int unit, 325 rhhandle_t packet_handle); 326 327 /** 328 * \brief 329 * Send the packet. For adapter there is no need to define the port, it is just presented to the beginning of the pipe 330 * \param [in] unit - Unit # 331 * \param [in] src_port - src port for CPU packet 332 * \param [in] packet_handle - packet control handle 333 * \param [in] flags - misc flags controlling packet tx 334 * 335 * \retval _SHR_E_NONE for success 336 * \retval shr_error_e Standard error handling 337 * \remark 338 * Packet control structure may be used multiple times, until diag_sand_packet_free is called, 339 * useful to have one field modification where others stay constant 340 * \see 341 */ 342 shr_error_e diag_sand_packet_send( 343 int unit, 344 bcm_port_t src_port, 345 rhhandle_t packet_handle, 346 uint32 flags); 347 348 /** 349 * \brief 350 * Given name of packet-prototype in TestCases.xml, get the value of the first occurrence 351 * of the specified unsigned integer field under specified protocol. 352 * Also get 'length' of packet. Note that if any of protocol/filed pointers is null, 353 * only 'length' is returned. 354 * \param [in] unit - 355 * Identifier of HW platform. 356 * \param [in] packet_n - 357 * char *. Name of packet-prototype within file TestCases.xml 358 * \param [in] proto_n - 359 * char *. Name of protocol within packet-prototype 'packet_n'. 360 * If NULL, get only '*length_p'. 361 * \param [in] field_n - 362 * char *. Name of field within protocol within packet-prototype 'packet_n'. 363 * If NULL, get only '*length_p'. 364 * \param [out] lenght_p - 365 * Pointer to uint32. This procedure loads pointed memory by the length of the packet, including 366 * PTCH (but not including CRC). If NULL then no data is retrieved. 367 * \param [out] uint32_field_val_p - 368 * Pointer to uint32. This procedure loads pointed memory by the integer value corresponding to the 369 * value specified within the given name of packet-prototype. 370 * \return 371 * \retval Zero - On success 372 * \retval Error - Identifier as per shr_error_e 373 * \remark 374 * If any of the specified inputs does not exist (e.g., no such 'packet_n') then a 'not found' 375 * error is returned. 376 * \see 377 * None 378 */ 379 shr_error_e diag_sand_packet_proto_get_uint_field( 380 int unit, 381 char *packet_n, 382 char *proto_n, 383 char *field_n, 384 uint32 *lenght_p, 385 uint32 *uint32_field_val_p); 386 /** 387 * \brief 388 * Create the packet and assign all the available parameters from the XML case 389 * \param [in] unit - Unit # 390 * \param [in] packet_n - packet case name from XML file 391 * \param [in] packet_h - pointer to packet handle, if provided it is not free by send and may be used further, 392 * should be freed by caller 393 * \param [out] src_port_p - pointer where source port should be assigned 394 * \retval _SHR_E_NONE for success 395 * \retval shr_error_e Standard error handling 396 * \remark 397 * XML case may be added/modified on the fly without need for restart, each invocation looks in actual file 398 * \see 399 */ 400 shr_error_e diag_sand_packet_load( 401 int unit, 402 char *packet_n, 403 rhhandle_t packet_h, 404 bcm_port_t * src_port_p); 405 406 /** 407 * \brief 408 * Send the packet defined by XML packet case 409 * \param [in] unit - Unit # 410 * \param [in] packet_n - packet case name from XML file 411 * \param [in] packet_h_p - pointer to packet handle, if provided it is not free by send and may be used further, 412 * should be freed by caller 413 * \param [in] flags - misc flags controlling packet tx 414 * 415 * \retval _SHR_E_NONE for success 416 * \retval shr_error_e Standard error handling 417 * \remark 418 * XML case may be added/modified on the fly without need for restart, each invocation looks in actual file 419 * \see 420 */ 421 shr_error_e diag_sand_packet_send_by_case( 422 int unit, 423 char *packet_n, 424 rhhandle_t * packet_h_p, 425 uint32 flags); 426 427 /** 428 * \brief 429 * Send simple packet only to allow meaningful output for different visibility commands tests 430 * \param [in] unit - Unit # 431 * 432 * \retval _SHR_E_NONE for success 433 * \retval shr_error_e Standard error handling 434 */ 435 shr_error_e diag_sand_packet_send_simple( 436 int unit); 437 438 /** 439 * \brief 440 * Prints the content of last packet sent on specific unit/core 441 * \param [in] unit - Unit # 442 * \param [in] core - Core # 443 * \return shr_error_e Standard error handling 444 * \remark 445 * * None 446 * \see 447 * * None 448 */ 449 shr_error_e diag_sand_packet_last_show( 450 int unit, 451 int core); 452 453 /** 454 * \brief 455 * Prints the information tree after parsing 456 * \param [in] unit - Unit # 457 * \param [in] pit - Parsed information tree holding all the data to be printed 458 * \param [in] sand_control - Control structure for DNX shell framework 459 * \return shr_error_e Standard error handling 460 * \remark 461 * * None 462 * \see 463 * * None 464 */ 465 shr_error_e packet_decode_info_print( 466 int unit, 467 rhlist_t * pit, 468 sh_sand_control_t * sand_control); 469 470 /* 471 * } 472 * PParse defines and macros 473 */ 474 475 /* 476 * Return number of packet in rx list 477 */ 478 int diag_sand_rx_nof( 479 int unit); 480 481 /* 482 * Start recording received packets into rx list 483 */ 484 shr_error_e diag_sand_rx_start( 485 int unit); 486 487 /* 488 * Stop recording received packets into rx list 489 */ 490 shr_error_e diag_sand_rx_stop( 491 int unit); 492 493 /* 494 * Clear all packets from rx list 495 */ 496 shr_error_e diag_sand_rx_clean( 497 int unit); 498 499 /* 500 * Dump all packets from rx list on the screen 501 */ 502 shr_error_e diag_sand_rx_dump( 503 int unit, 504 sh_sand_control_t * sand_control); 505 506 /* 507 * Compare packet constructed as the the one for tx with the packet in rx list and return number of matches 508 */ 509 shr_error_e diag_sand_rx_compare( 510 int unit, 511 rhhandle_t packet_handle, 512 int *pkt_match_count_p); 513 514 /* 515 * Definitions for legacy command list in DPP only 516 * { 517 */ 518 cmd_result_t cmd_sand_packet( 519 int unit, 520 args_t * args); 521 522 void diag_sand_packet_flags_set( 523 int unit, 524 rhhandle_t * packet_h_p, 525 uint32 flags); 526 527 extern const char cmd_sand_packet_usage[]; 528 /* 529 * } 530 */ 531 532 /* 533 * Definitions for shell framework 534 */ 535 extern sh_sand_man_t sh_sand_packet_man; 536 extern sh_sand_cmd_t sh_sand_packet_cmds[]; 537 538 extern char *example_data_string; 539 540 #endif /* DIAG_SAND_PACKET_INCLUDED */