ft_export.h (16382B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: ft_export.h 8 * Purpose: Function declarations for flowtracker Export routines. 9 */ 10 11 #ifndef _BCM_INT_FT_EXPORT_H_ 12 #define _BCM_INT_FT_EXPORT_H_ 13 14 #include <soc/defs.h> 15 #include <shared/bsl.h> 16 17 #if defined(BCM_FLOWTRACKER_SUPPORT) 18 19 #include <shared/bitop.h> 20 21 #include <soc/helix5.h> 22 #include <soc/drv.h> 23 #include <soc/debug.h> 24 #include <soc/shared/shr_pkt.h> 25 26 #include <soc/mem.h> 27 #include <soc/format.h> 28 29 #include <bcm/module.h> 30 #include <soc/scache.h> 31 32 #include <bcm/error.h> 33 #include <bcm/flowtracker.h> 34 #include <bcm/collector.h> 35 36 #include <bcm_int/esw/collector.h> 37 38 39 /* 40 * Global defines. 41 */ 42 #define BCMI_FT_MAX_COLLECTORS 8 43 #define BCMI_FT_COLLECTOR_ID_INVALID -1 44 45 #define BCMI_FT_IPFIX_PACKET_BUILD_MAX_SIZE 128 46 #define BCMI_FT_IPFIX_MAX_RECORDS_PER_PACKET 128 47 #define BCMI_FT_IPFIX_RECORD_SIZE (1024 / 8) 48 49 #define BCMI_FT_MAX_TEMPLATES 1024 50 #define BCMI_FT_TEMPLATE_ID_INVALID -1 51 #define BCMI_FT_TEMPLATE_MAX_ELEMS 128 52 53 #define BCMI_FT_CB_MAX 3 54 55 /* Maximum name length of export elements. */ 56 #define BCMI_FT_EXPORT_ELEMENT_NAME_LEN_MAX 30 57 58 /* Structures */ 59 60 typedef struct bcmi_ft_collector_info_s { 61 62 bcm_collector_t cmn_coll_id; 63 int cmn_export_prof_id; 64 int num_records; 65 66 /* Software handle for collector. */ 67 bcm_flowtracker_collector_t coll_hw_id; 68 69 /* Number of groups associated with collector. */ 70 int in_use; 71 72 /* Collector information structure. */ 73 bcm_flowtracker_collector_info_t collector_info; 74 75 /* IPFIX header */ 76 int ipfix_hdr_use_custom; 77 bcm_collector_ipfix_header_t ipfix_hdr; 78 79 } bcmi_ft_collector_info_t; 80 81 typedef struct bcmi_ft_template_info_s { 82 /* Template ID. */ 83 bcm_flowtracker_export_template_t template_id; 84 85 /* Number of groups associated with template. */ 86 int in_use; 87 88 /* IPFIX Template Set Id. */ 89 uint16 set_id; 90 91 /* Num elements. */ 92 int num_elements; 93 94 /* List of export elements. */ 95 bcm_flowtracker_export_element_info_t export_elements[BCMI_FT_TEMPLATE_MAX_ELEMS]; 96 97 } bcmi_ft_template_info_t; 98 99 100 /* Index into array of profile structures */ 101 typedef enum bcmi_ft_export_cb_state_e { 102 BCMI_FT_CALLBACK_STATE_INVALID = 0, 103 BCMI_FT_CALLBACK_STATE_ACTIVE, 104 BCMI_FT_CALLBACK_STATE_REGISTERED, 105 BCMI_FT_CALLBACK_STATE_UNREGISTERED 106 } bcmi_ft_export_cb_state_t; 107 108 typedef struct bcmi_ft_cb_entry_s { 109 VOL bcmi_ft_export_cb_state_t state; 110 111 bcm_flowtracker_export_record_cb_f callback; 112 bcm_flowtracker_collector_callback_options_t callback_options; 113 114 void *userdata; 115 } bcmi_ft_cb_entry_t; 116 117 typedef struct bcmi_ft_export_cb_ctrl_s { 118 /* per unit profiles array is indexed by _bcm_ipfix_profile_id_t */ 119 bcmi_ft_cb_entry_t callback_entry[BCMI_FT_CB_MAX]; 120 sal_thread_t pid; /* export fifo processing thread process id */ 121 VOL sal_usecs_t interval; /* export fifo processing polling interval */ 122 int dma_chan; /* export fifo DMA channel number */ 123 124 int bad_handled; /* Records not properly handled. */ 125 int owned; /* Records owned succesfully. */ 126 } bcmi_ft_export_cb_ctrl_t; 127 128 129 130 /* 131 * FT Export (IPFIX) Packet build 132 */ 133 typedef struct bcmi_ft_pkt_build_s { 134 /* Flags */ 135 uint32 flags; 136 137 /* Checksum of IP header excluding length */ 138 uint32 ip_base_checksum; 139 140 /* UDP psuedo header checksum */ 141 uint32 udp_base_checksum; 142 143 /* Software handle for collector */ 144 uint16 id; 145 146 /* Length of the IPFIX encapsulation */ 147 uint16 encap_length; 148 149 /* Max size of the packet that can be sent to collector */ 150 uint16 mtu; 151 152 /* Offset to start of IP header in the encap */ 153 uint16 ip_offset; 154 155 /* Offset to start of UDP header in the encap */ 156 uint16 udp_offset; 157 158 /* Offset to start of IPFIX header in the encap */ 159 uint16 ipfix_offset; 160 161 /* IPFIX encapsulation */ 162 uint8 encap[BCMI_FT_IPFIX_PACKET_BUILD_MAX_SIZE]; 163 } bcmi_ft_pkt_build_t; 164 165 166 typedef struct bcmi_ft_export_satet_s { 167 /* IPFIX export Record length (bytes). */ 168 int record_length; 169 170 /* Max collectors supported by device. */ 171 int max_collectors; 172 173 /* Max templates. */ 174 int max_templates; 175 176 /* Max information elements in a template. */ 177 int max_elements; 178 179 /* Template valid bitmap. */ 180 SHR_BITDCL template_bitmap[SHR_BITALLOCSIZE(BCMI_FT_MAX_TEMPLATES)]; 181 182 /* Per collector info. */ 183 bcmi_ft_collector_info_t collector_info[BCMI_FT_MAX_COLLECTORS]; 184 185 /* Templates info. */ 186 bcmi_ft_template_info_t *template_info[BCMI_FT_MAX_TEMPLATES]; 187 188 /* DMA Collector Id. */ 189 bcm_flowtracker_collector_t dma_collector_id; 190 191 /* Export Callback functions' state */ 192 bcmi_ft_export_cb_ctrl_t *export_cb_ctrl; 193 194 /* IPFIX observation domain id. */ 195 int ipfix_observation_domain_id; 196 197 } bcmi_ft_export_state_t; 198 199 200 201 202 /* Export software state. */ 203 extern bcmi_ft_export_state_t *bcmi_ft_export_state[BCM_MAX_NUM_UNITS]; 204 205 206 207 208 /* 209 * Function Macros 210 */ 211 #define BCMI_FT_EXPORT_INFO(unit) \ 212 (bcmi_ft_export_state[unit]) 213 214 #define BCMI_FT_COLLECTOR_INFO(unit, id) \ 215 &(BCMI_FT_EXPORT_INFO(unit)->collector_info[id]) 216 217 #define BCMI_FT_TEMPLATE_BITMAP(unit) \ 218 (BCMI_FT_EXPORT_INFO(unit)->template_bitmap) 219 220 #define BCMI_FT_TEMPLATE_INFO(unit, id) \ 221 (BCMI_FT_EXPORT_INFO(unit)->template_info[id]) 222 223 #define BCMI_FT_CB_CTRL(unit) \ 224 (BCMI_FT_EXPORT_INFO(unit) == NULL ? NULL : (BCMI_FT_EXPORT_INFO(unit)->export_cb_ctrl)) 225 226 227 228 229 230 /* Function Declarations */ 231 232 extern void 233 bcma_ft_dump_export_entry(int unit, 234 bcm_flowtracker_export_record_t *data); 235 236 extern int 237 bcma_ft_export_fifo_control(int unit, sal_usecs_t interval); 238 239 extern int 240 bcma_ft_export_dma_collector_get(int unit, 241 bcm_collector_t *id); 242 243 extern int 244 bcma_ft_setid_template_id_get(int unit, uint16 setid, 245 bcm_flowtracker_export_template_t *template_id); 246 extern int 247 bcmi_ft_export_init(int unit); 248 249 extern int 250 bcmi_ft_export_cleanup(int unit); 251 252 /* 253 * Function: 254 * bcmi_ft_collector_create 255 * Purpose: 256 * Create flowtracker collector id. 257 * Description : 258 * Routine to create a flowtracker collector 259 * Parameters: 260 * unit - (IN) BCM device id 261 * options - (IN) options for group creation 262 * collector_id - (OUT) FT collector id. 263 * collector_info - (IN) Collector info. 264 * 265 * Returns: 266 * BCM_E_XXX 267 */ 268 extern int 269 bcmi_ft_collector_create( 270 int unit, 271 uint32 options, 272 bcm_flowtracker_collector_t *collector_id, 273 bcm_flowtracker_collector_info_t *collector_info); 274 275 276 /* 277 * Function: 278 * bcmi_ft_collector_get 279 * Purpose: 280 * Fetch flowtracker collector info. 281 * Description : 282 * Routine to create a flowtracker collector 283 * Parameters: 284 * unit - (IN) BCM device id 285 * collector_id - (OUT) FT collector id. 286 * collector_info - (IN) Collector info. 287 * 288 * Returns: 289 * BCM_E_XXX 290 */ 291 extern int 292 bcmi_ft_collector_get( 293 int unit, 294 bcm_flowtracker_collector_t collector_d, 295 bcm_flowtracker_collector_info_t *collector_info); 296 297 /* 298 * Function: 299 * bcmi_ft_collector_get_all 300 * Purpose: 301 * Fetch all flowtracker collectors info. 302 * Description : 303 * Routine to create a flowtracker collector 304 * Parameters: 305 * unit - (IN) BCM device id 306 * max_size - (OUT) Max collectors to read. 307 * collector_list - (OUT) Collector id list. 308 * list_size (OUT) - Num of collectors read. 309 * 310 * Returns: 311 * BCM_E_XXX 312 */ 313 extern int 314 bcmi_ft_collector_get_all( 315 int unit, 316 int max_size, 317 bcm_flowtracker_collector_t *collector_list, 318 int *list_size); 319 320 /* 321 * Function: 322 * bcmi_ft_collector_destroy 323 * Purpose: 324 * Destroy flowtracker collector. 325 * Description : 326 * Routine to destroy a flowtracker collector 327 * Parameters: 328 * unit - (IN) BCM device id 329 * collector_d - (OUT) FT collector id. 330 * 331 * Returns: 332 * BCM_E_XXX 333 */ 334 extern int 335 bcmi_ft_collector_destroy( 336 int unit, 337 bcm_flowtracker_collector_t collector_d); 338 339 /* 340 * Function: 341 * bcm_flowtracker_export_template_validate 342 * Purpose: 343 * Validate the template and return the list supported by the 344 * device. 345 * Parameters: 346 * unit - (IN) Unit number. 347 * flow_group_id - (IN) Flowtracker flow group software ID. 348 * max_in_export_elements - (IN) Max number of export elements intended in the tempate. 349 * in_export_elements - (IN) List of export elements intended to be in the template. 350 * max_out_export_elements - (IN) Max number of export elements in the supportable tempate. 351 * out_export_elements - (OUT) List of export elements in the template supportable by hardware. 352 * actual_out_export_elements - (OUT) Actual number of export elements in the supportable tempate. 353 * Returns: 354 * BCM_E_xxx 355 * Notes: 356 */ 357 extern int 358 bcmi_ft_export_template_validate( 359 int unit, 360 bcm_flowtracker_group_t flow_group_id, 361 int max_in_export_elements, 362 bcm_flowtracker_export_element_info_t *in_export_elements, 363 int max_out_export_elements, 364 bcm_flowtracker_export_element_info_t *out_export_elements, 365 int *actual_out_export_elements); 366 /* 367 * Function: 368 * bcmi_ft_template_create 369 * Purpose: 370 * Create flowtracker export template. 371 * Description : 372 * Routine to create a flowtracker template 373 * Parameters: 374 * unit - (IN) BCM device id 375 * options - (IN) options for template creation 376 * template_id - (OUT) FT template id. 377 * set_id - (IN) IPFIX template set id 378 * num_export_elements - (IN) Number of information elements. 379 * list_of_export_elements - (IN) List of IPFIX information elems. 380 * 381 * Returns: 382 * BCM_E_XXX 383 */ 384 extern int 385 bcmi_ft_template_create( 386 int unit, 387 uint32 options, 388 bcm_flowtracker_export_template_t *template_id, 389 uint16 set_id, 390 int num_export_elements, 391 bcm_flowtracker_export_element_info_t *list_of_export_elements); 392 393 394 /* 395 * Function: 396 * bcmi_ft_template_get 397 * Purpose: 398 * Ftech flowtracker export template. 399 * Description : 400 * Routine to get flowtracker template info. 401 * Parameters: 402 * unit - (IN) BCM device id 403 * template_id - (IN) FT template id. 404 * *set_id - (OUT) IPFIX template set id 405 * max_size - (IN) Max num of elements 406 * list_of_export_elements - (OUT) List of IPFIX information elems. 407 * num_export_elements - (OUT) Actual Number of information elements. 408 * 409 * Returns: 410 * BCM_E_XXX 411 */ 412 extern int 413 bcmi_ft_template_get( 414 int unit, 415 bcm_flowtracker_export_template_t template_id, 416 uint16 *set_id, 417 int max_elems, 418 bcm_flowtracker_export_element_info_t *list_of_elems, 419 int *num_elems); 420 421 422 /* 423 * Function: 424 * bcmi_ft_template_destroy 425 * Purpose: 426 * Destroy flowtracker export template. 427 * Description : 428 * Routine to destroy a flowtracker template 429 * Parameters: 430 * unit - (IN) BCM device id 431 * template_id - (OUT) FT template id. 432 * 433 * Returns: 434 * BCM_E_XXX 435 */ 436 extern int 437 bcmi_ft_template_destroy( 438 int unit, 439 bcm_flowtracker_export_template_t template_id); 440 441 442 /* 443 * Function: 444 * bcmi_ft_flow_group_collector_add 445 * Purpose: 446 * Attach a collector a flow group. 447 * Description : 448 * Routine to associate a collector to an flowtracker group. 449 * Parameters: 450 * unit - (IN) BCM device id 451 * group_id- (IN) FT group Id. 452 * collector_id - (OUT) FT Collector Id. 453 * template_id - (IN) IPFIX template Id. 454 * 455 * Returns: 456 * BCM_E_XXX 457 */ 458 extern int 459 bcmi_ft_flow_group_collector_add( 460 int unit, 461 bcm_flowtracker_group_t flow_group_id, 462 bcm_flowtracker_collector_t collector_id, 463 bcm_flowtracker_export_template_t template_id); 464 465 466 /* 467 * Function: 468 * bcmi_ft_flow_group_collector_delete 469 * Purpose: 470 * Detach a collector a flow group. 471 * Description : 472 * Routine to dissociate a collector to an flowtracker group. 473 * Parameters: 474 * unit - (IN) BCM device id 475 * group_id- (IN) FT group Id. 476 * collector_id - (OUT) FT Collector Id. 477 * template_id - (IN) IPFIX template Id. 478 * 479 * Returns: 480 * BCM_E_XXX 481 */ 482 extern int 483 bcmi_ft_flow_group_collector_delete( 484 int unit, 485 bcm_flowtracker_group_t flow_group_id, 486 bcm_flowtracker_collector_t collector_id, 487 bcm_flowtracker_export_template_t template_id); 488 489 490 /* 491 * Function: 492 * bcmi_ft_flow_group_collector_get_all 493 * Purpose: 494 * Get collector attached to a flow group. 495 * Description : 496 * Routine to fetch collector and template id 497 * associated a flowtracker group. 498 * Parameters: 499 * unit - (IN) BCM device id 500 * group_id - (IN) FT group Id. 501 * max_list_size - (IN) max list of collectors 502 * list_of_collectors - (OUT) FT Collector Id list. 503 * list_of_templates - (OUT) FT Template Id list. 504 * list_size - (IN) Actual list size. 505 * 506 * Returns: 507 * BCM_E_XXX 508 */ 509 extern int 510 bcmi_ft_flow_group_collector_get_all( 511 int unit, 512 bcm_flowtracker_group_t flow_group_id, 513 int max_list_size, 514 bcm_flowtracker_collector_t *list_of_collectors, 515 bcm_flowtracker_export_template_t *list_of_templates, 516 int *list_size); 517 518 519 /* 520 * Function: 521 * bcmi_ft_group_collector_attach 522 * Purpose: 523 * Associate flow group to a collector with an export template. 524 * Parameters: 525 * unit - (IN) BCM device number 526 * flow_group_id - (IN) Flow group Id 527 * collector_id - (IN) Collector Id 528 * template_id - (IN) Template Id 529 * Returns: 530 * BCM_E_XXX - BCM error code. 531 */ 532 extern int 533 bcmi_ft_group_collector_attach( 534 int unit, 535 bcm_flowtracker_group_t flow_group_id, 536 bcm_flowtracker_collector_t collector_id, 537 int export_profile_id, 538 bcm_flowtracker_export_template_t template_id); 539 540 /* 541 * Function: 542 * bcmi_ft_group_collector_detach 543 * Purpose: 544 * Dis-associate flow group from a collector with an export template. 545 * Parameters: 546 * unit - (IN) BCM device number 547 * flow_group_id - (IN) Flow group Id 548 * collector_id - (IN) Collector Id 549 * template_id - (IN) Template Id 550 * Returns: 551 * BCM_E_XXX - BCM error code. 552 */ 553 extern int 554 bcmi_ft_group_collector_detach( 555 int unit, 556 bcm_flowtracker_group_t flow_group_id, 557 bcm_flowtracker_collector_t collector_id, 558 int export_profile_id, 559 bcm_flowtracker_export_template_t template_id); 560 561 /* 562 * Function: 563 * bcmi_ft_group_collector_attach_get_all 564 * Purpose: 565 * Get list of all collectors, templates attached to a flow group 566 * Parameters: 567 * unit - (IN) BCM device number 568 * flow_group_id - (IN) Flow group Id 569 * max_list_size - (IN) Size of the list arrays 570 * list_of_collectors - (OUT) Collector list 571 * list_of_templates - (OUT) Template list 572 * list_size - (OUT) Number of elements in the lists 573 * Returns: 574 * BCM_E_XXX - BCM error code. 575 */ 576 extern int 577 bcmi_ft_group_collector_attach_get_all( 578 int unit, 579 bcm_flowtracker_group_t flow_group_id, 580 int max_list_size, 581 bcm_flowtracker_collector_t *list_of_collectors, 582 int *list_of_export_profile_ids, 583 bcm_flowtracker_export_template_t *list_of_templates, 584 int *list_size); 585 586 587 extern int 588 bcmi_ft_export_record_register( 589 int unit, 590 bcm_flowtracker_collector_t collector_id, 591 bcm_flowtracker_collector_callback_options_t callback_options, 592 bcm_flowtracker_export_record_cb_f callback, 593 void *userdata); 594 595 extern int 596 bcmi_ft_export_record_unregister( 597 int unit, 598 bcm_flowtracker_collector_t collector_id, 599 bcm_flowtracker_collector_callback_options_t callback_options, 600 bcm_flowtracker_export_record_cb_f callback_fn); 601 602 603 #ifdef BCM_WARM_BOOT_SUPPORT 604 605 extern int 606 bcmi_ft_export_warmboot_alloc(int unit, soc_scache_handle_t scache_handle); 607 608 extern int 609 bcmi_ft_export_warmboot_sync(int unit, soc_scache_handle_t scache_handle); 610 611 extern int 612 bcmi_ft_export_warmboot_recover(int unit, soc_scache_handle_t scache_handle); 613 614 #endif /* BCM_WARM_BOOT_SUPPORT */ 615 616 617 #endif /* BCM_FLOWTRACKER_SUPPORT */ 618 619 #endif /* _BCM_INT_FT_GROUP_H_ */