collector.h (13993B)
1 /* 2 * 3 * 4 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 * 6 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 7 * 8 * DO NOT EDIT THIS FILE! 9 * This file is auto-generated. 10 * Edits to this file will be lost when it is regenerated. 11 */ 12 13 #ifndef __BCM_COLLECTOR_H__ 14 #define __BCM_COLLECTOR_H__ 15 16 #include <bcm/types.h> 17 18 #ifndef BCM_HIDE_DISPATCHABLE 19 20 /* Initializes the Collector module. */ 21 extern int bcm_collector_init( 22 int unit); 23 24 /* Detaches the Collector module. */ 25 extern int bcm_collector_detach( 26 int unit); 27 28 #endif /* BCM_HIDE_DISPATCHABLE */ 29 30 /* 31 * Wire formats that are supported for exporting stats data to the 32 * collector 33 */ 34 typedef enum bcm_collector_wire_format_e { 35 bcmCollectorWireFormatIpfix = 0, /* Ipfix wire format. */ 36 bcmCollectorWireFormatProtoBuf = 1, /* Protocol Buffer wire format . */ 37 bcmCollectorWireFormatCount = 2 /* Last Value. Not Usable. */ 38 } bcm_collector_wire_format_t; 39 40 /* Export profile flags. */ 41 #define BCM_COLLECTOR_EXPORT_PROFILE_FLAGS_USE_NUM_RECORDS (1 << 0) /* Use num_records field 42 in export profile 43 instead of 44 max_packet_length. */ 45 46 /* PROTOBUF system ID flag. */ 47 #define BCM_COLLECTOR_PROTOBUF_MAX_SYSTEM_ID_LENGTH 32 /* Max ProtoBuf system Id 48 length. */ 49 50 /* Export profile information of stats data sent to the collector. */ 51 typedef struct bcm_collector_export_profile_s { 52 uint32 flags; /* Export profile flags, see 53 BCM_COLLECTOR_EXPORT_PROFILE_FLAGS_XXX. */ 54 bcm_collector_wire_format_t wire_format; /* wire format of export profile. */ 55 uint32 export_interval; /* export interval of export profile in 56 micro seconds. */ 57 uint32 max_packet_length; /* Maximum length of export packet sent 58 to collector. */ 59 int num_records; /* Number of records to be sent in one 60 packet, can be used instead of 61 max_packet_length. */ 62 } bcm_collector_export_profile_t; 63 64 /* 65 * Defines used to define invalid/default values for export profile 66 * structure parameters. 67 */ 68 #define BCM_COLLECTOR_EXPORT_INTERVAL_INVALID 0xffffffff /* Invalid export 69 interval. Used to 70 initialize export 71 interval. */ 72 73 /* Initializes a export profile information structure. */ 74 extern void bcm_collector_export_profile_t_init( 75 bcm_collector_export_profile_t *export_profile_info); 76 77 /* 78 * Options that can be passed via options parameter during collector 79 * export profile creation. 80 */ 81 #define BCM_COLLECTOR_EXPORT_PROFILE_WITH_ID (1 << 0) /* Creates a collector 82 export profile with 83 ID. */ 84 #define BCM_COLLECTOR_EXPORT_PROFILE_REPLACE (1 << 1) /* Replaces a collector 85 export profile with 86 ID. */ 87 88 #ifndef BCM_HIDE_DISPATCHABLE 89 90 /* Createa a collector export profile with given export profile info. */ 91 extern int bcm_collector_export_profile_create( 92 int unit, 93 uint32 options, 94 int *export_profile_id, 95 bcm_collector_export_profile_t *export_profile_info); 96 97 /* Gets a collector export profile information with ID. */ 98 extern int bcm_collector_export_profile_get( 99 int unit, 100 int export_profile_id, 101 bcm_collector_export_profile_t *export_profile_info); 102 103 /* Gets the list of all configured collector export profile IDs. */ 104 extern int bcm_collector_export_profile_ids_get_all( 105 int unit, 106 int max_size, 107 int *export_profile_ids_list, 108 int *list_size); 109 110 /* Destroys a collector export profile with ID. */ 111 extern int bcm_collector_export_profile_destroy( 112 int unit, 113 int export_profile_id); 114 115 #endif /* BCM_HIDE_DISPATCHABLE */ 116 117 /* 118 * Macros for bcm_collector_eth_header_t.vlan_tag_structure to indicate 119 * the tag structure of vlans. 120 */ 121 #define BCM_COLLECTOR_ETH_HDR_UNTAGGED 0x1 122 #define BCM_COLLECTOR_ETH_HDR_SINGLE_TAGGED 0x2 123 #define BCM_COLLECTOR_ETH_HDR_DOUBLE_TAGGED 0x3 124 125 /* 126 * Ethernet header in the encap used to send the stats data packet to the 127 * collector. 128 */ 129 typedef struct bcm_collector_eth_header_s { 130 bcm_mac_t dst_mac; 131 bcm_mac_t src_mac; 132 uint8 vlan_tag_structure; 133 uint16 outer_tpid; 134 uint16 inner_tpid; 135 bcm_vlan_tag_t outer_vlan_tag; 136 bcm_vlan_tag_t inner_vlan_tag; 137 } bcm_collector_eth_header_t; 138 139 /* 140 * IPv4 header in the encap used to send the stats data packet to the 141 * collector. 142 */ 143 typedef struct bcm_collector_ipv4_header_s { 144 bcm_ip_t src_ip; 145 bcm_ip_t dst_ip; 146 uint8 dscp; 147 uint8 ttl; 148 } bcm_collector_ipv4_header_t; 149 150 /* 151 * IPv6 header in the encap used to send the stats data packet to the 152 * collector. 153 */ 154 typedef struct bcm_collector_ipv6_header_s { 155 bcm_ip6_t src_ip; 156 bcm_ip6_t dst_ip; 157 uint8 traffic_class; 158 uint32 flow_label; 159 uint8 hop_limit; 160 } bcm_collector_ipv6_header_t; 161 162 /* UDP header flags. */ 163 #define BCM_COLLECTOR_UDP_FLAGS_CHECKSUM_ENABLE (1 << 0) /* Add UDP checksum in 164 the export packet */ 165 166 /* 167 * UDP header in the encap used to send the stats data packet to the 168 * collector. 169 */ 170 typedef struct bcm_collector_udp_header_s { 171 uint32 flags; /* UDP header flags, see 172 BCM_COLLECTOR_UDP_FLAGS_XXX. */ 173 bcm_l4_port_t src_port; 174 bcm_l4_port_t dst_port; 175 } bcm_collector_udp_header_t; 176 177 /* 178 * IPFIX header in the encap used to send the data packet to the remote 179 * collector. 180 */ 181 typedef struct bcm_collector_ipfix_header_s { 182 int version; /* Ipfix Protocol Version. */ 183 int initial_sequence_num; /* Ipfix initial sequence number. */ 184 } bcm_collector_ipfix_header_t; 185 186 /* ProtoBuf config structure. */ 187 typedef struct bcm_collector_protobuf_header_s { 188 int system_id_length; /* system_id_length. */ 189 uint8 system_id[BCM_COLLECTOR_PROTOBUF_MAX_SYSTEM_ID_LENGTH]; /* System Id. */ 190 uint32 component_id; /* Component Id. */ 191 } bcm_collector_protobuf_header_t; 192 193 /* Software ID given for a Collector configuration. */ 194 typedef int bcm_collector_t; 195 196 /* 197 * Transport types that are supported for exporting stats data to the 198 * collector 199 */ 200 typedef enum bcm_collector_transport_type_e { 201 bcmCollectorTransportTypeIpv4Udp = 0, /* The encap will be of the format UDP 202 over IPv4. */ 203 bcmCollectorTransportTypeIpv6Udp = 1, /* The encap will be of the format UDP 204 over IPv6. */ 205 bcmCollectorTransportTypeRaw = 2, /* Indicates no encap. This will be 206 useful when the raw stats data PDUs 207 need to be transported to the local 208 CPU. */ 209 bcmCollectorTransportTypeCount = 3 /* Last Value. Not Usable. */ 210 } bcm_collector_transport_type_t; 211 212 /* Collector types. */ 213 typedef enum bcm_collector_type_e { 214 bcmCollectorRemote = 0, /* The collector is a remote machine expecting flow 215 information records using encap scheme defined 216 through TransportTypeXxx. */ 217 bcmCollectorLocal = 1, /* The collector is local CPU receiving flow 218 information records usually without any encap. 219 TransportTypeRaw. */ 220 bcmCollectorCount = 2 /* Last Value. Not Usable. */ 221 } bcm_collector_type_t; 222 223 /* Collector information. */ 224 typedef struct bcm_collector_info_s { 225 bcm_collector_type_t collector_type; /* Collector type. Remote vs Local */ 226 bcm_collector_transport_type_t transport_type; /* Transport type used for exporting 227 data to the collector. This 228 identifies the usable fields within 229 the encap structure member defined 230 below. */ 231 bcm_collector_eth_header_t eth; /* Ethernet encapsulation of the packet 232 sent to collector. */ 233 bcm_collector_ipv4_header_t ipv4; /* IPv4 encapsulation of the packet sent 234 to collector. */ 235 bcm_collector_ipv6_header_t ipv6; /* IPv6 encapsulation of the packet sent 236 to collector. */ 237 bcm_collector_udp_header_t udp; /* UDP encapsulation of the packet sent 238 to collector. */ 239 bcm_collector_ipfix_header_t ipfix; /* IPFIX encapsulation of the packet 240 sent to collector. */ 241 bcm_collector_protobuf_header_t protobuf; /* Protobuf header information. */ 242 } bcm_collector_info_t; 243 244 /* Initializes a collector information structure. */ 245 extern void bcm_collector_info_t_init( 246 bcm_collector_info_t *collector_info); 247 248 /* 249 * Options that can be passed via options parameter during collector 250 * creation. 251 */ 252 #define BCM_COLLECTOR_WITH_ID (1 << 0) /* Create a collector with ID. */ 253 #define BCM_COLLECTOR_REPLACE (1 << 1) /* Replace a collector with ID. */ 254 255 #ifndef BCM_HIDE_DISPATCHABLE 256 257 /* Create a collector with given collector info. */ 258 extern int bcm_collector_create( 259 int unit, 260 uint32 options, 261 bcm_collector_t *collector_id, 262 bcm_collector_info_t *collector_info); 263 264 /* Get collector information with ID. */ 265 extern int bcm_collector_get( 266 int unit, 267 bcm_collector_t id, 268 bcm_collector_info_t *collector_info); 269 270 /* Get the list of all collectors configured. */ 271 extern int bcm_collector_get_all( 272 int unit, 273 int max_size, 274 bcm_collector_t *collector_list, 275 int *list_size); 276 277 /* Destroy a collector with ID. */ 278 extern int bcm_collector_destroy( 279 int unit, 280 bcm_collector_t id); 281 282 #endif /* BCM_HIDE_DISPATCHABLE */ 283 284 /* 285 * Max size of the data record received at the CPU through the FIFO DMA 286 * reception. 287 */ 288 #define BCM_COLLECTOR_EXPORT_RECORD_LENGTH BITS2BYTES(1024) /* Maximum length of a 289 data record. 1024 290 bits. */ 291 292 /* 293 * Collector Export record structure. Data record info passed to 294 * application software by SDK Software. The unprocessed data record will 295 * be presented in network byte order. 296 */ 297 typedef struct bcm_collector_export_record_s { 298 int size; /* Number of valid octets in the 299 data_record array for the device. */ 300 uint8 data_record[BCM_COLLECTOR_EXPORT_RECORD_LENGTH]; /* Raw data record in network byte 301 order. */ 302 } bcm_collector_export_record_t; 303 304 /* bcm_collector_export_record_t_init */ 305 extern void bcm_collector_export_record_t_init( 306 bcm_collector_export_record_t *record); 307 308 /* 309 * Defines for priorities of registered handlers for Collector export 310 * records. Callback handlers are always called from highest priority to 311 * lowest priority until one of the handlers returns record_handled or 312 * record_handled_owned. 313 * 314 * 315 * When callback handling proecedure starts, a default callback handler 316 * is installed at BCM_COLLECTOR_EXPORT_CB_PRIO_MIN priority that simply 317 * discards the record. 318 */ 319 #define BCM_COLLECTOR_EXPORT_CB_PRIO_MIN ((uint8)0) 320 #define BCM_COLLECTOR_EXPORT_CB_PRIO_MAX ((uint8)255) 321 322 /* Export callback options */ 323 typedef struct bcm_collector_callback_options_s { 324 int callback_prio; /* Priority of the callback function in the list. */ 325 } bcm_collector_callback_options_t; 326 327 /* bcm_collector_callback_options_t_init */ 328 extern void bcm_collector_callback_options_t_init( 329 bcm_collector_callback_options_t *callback_options); 330 331 /* Return values from export record callout routines. */ 332 typedef enum bcm_collector_export_record_handle_e { 333 BCM_COLLECTOR_EXPORT_RECORD_INVALID = 0, /* Invalid return value. */ 334 BCM_COLLECTOR_EXPORT_RECORD_NOT_HANDLED = 1, /* Export record not processed. */ 335 BCM_COLLECTOR_EXPORT_RECORD_HANDLED = 2, /* Export record handled, not owned. */ 336 BCM_COLLECTOR_EXPORT_RECORD_HANDLED_OWNED = 3 /* Export record handled and owned. */ 337 } bcm_collector_export_record_handle_t; 338 339 /* Callback routine for collector record exported to local collector. */ 340 typedef bcm_collector_export_record_handle_t (*bcm_collector_export_record_cb_f)( 341 int unit, 342 bcm_collector_t collector_id, 343 bcm_collector_export_record_t *record, 344 void *userdata); 345 346 #ifndef BCM_HIDE_DISPATCHABLE 347 348 /* Register callback routine for Local collector record export. */ 349 extern int bcm_collector_export_record_register( 350 int unit, 351 bcm_collector_t collector_id, 352 bcm_collector_callback_options_t callback_options, 353 bcm_collector_export_record_cb_f callback_fn, 354 void *userdata); 355 356 /* Unregister callback routine for Local collector record export. */ 357 extern int bcm_collector_export_record_unregister( 358 int unit, 359 bcm_collector_t collector_id, 360 bcm_collector_callback_options_t callback_options, 361 bcm_collector_export_record_cb_f callback_fn); 362 363 #endif /* BCM_HIDE_DISPATCHABLE */ 364 365 #endif /* __BCM_COLLECTOR_H__ */