ipfix.h (13633B)
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 */ 9 10 #ifndef __BCM_IPFIX_H__ 11 #define __BCM_IPFIX_H__ 12 13 #include <bcm/types.h> 14 15 #define BCM_IPFIX_DSCP_MASK_COUNT 64 16 17 typedef enum bcm_ipfix_stage_e { 18 BCM_IPFIX_STAGE_INGRESS = 0, 19 BCM_IPFIX_STAGE_EGRESS = 1 20 } bcm_ipfix_stage_t; 21 22 /* Flags for bcm_ipfix_data_t.flags. */ 23 #define BCM_IPFIX_DATA_VLAN_TAGGED 0x0001 24 #define BCM_IPFIX_DATA_TYPE_L2 0x0002 25 #define BCM_IPFIX_DATA_TYPE_IP4 0x0004 26 #define BCM_IPFIX_DATA_TYPE_IP6 0x0008 27 #define BCM_IPFIX_DATA_REASON_FLOW_TIMEOUT 0x0010 28 #define BCM_IPFIX_DATA_REASON_FLOW_END 0x0020 29 #define BCM_IPFIX_DATA_REASON_FLOW 0x0040 30 #define BCM_IPFIX_DATA_REASON_COUNT 0x0080 31 #define BCM_IPFIX_DATA_REASON_TIMESTAMP 0x0100 32 #define BCM_IPFIX_DATA_RATE_VIOLATION 0x0200 33 #define BCM_IPFIX_DATA_NON_FRAGMENT_PKT_DETECTED 0x0400 34 #define BCM_IPFIX_DATA_FRAGMENT_PKT_DETECTED 0x0800 35 #define BCM_IPFIX_DATA_TTL_CHANGED_DETECTED 0x1000 36 #define BCM_IPFIX_DATA_DROP_DETECTED 0x2000 37 #define BCM_IPFIX_DATA_TYPE_MASK 0x000e 38 #define BCM_IPFIX_DATA_REASON_MASK 0x01f0 39 40 /* Export data structure */ 41 typedef struct bcm_ipfix_data_s { 42 bcm_ipfix_stage_t stage; /* Ingress or egress. */ 43 uint32 flags; /* Type and reason. */ 44 bcm_port_t port; /* port. */ 45 bcm_vlan_t vlan; /* L2: VLAN identifier. */ 46 uint16 vlan_prio; /* L2: VLAN priority. */ 47 uint16 ether_type; /* L2: type in Ethernet II frame or 802.1Q 48 tag. */ 49 bcm_mac_t src_mac_addr; /* L2: source MAC address. */ 50 bcm_mac_t dst_mac_addr; /* L2: destination MAC address. */ 51 bcm_ip_t src_ip4_addr; /* IPv4: source IP address. */ 52 bcm_ip_t dst_ip4_addr; /* IPv4: destination IP address. */ 53 bcm_ip6_t src_ip6_addr; /* IPv6: source IP address. */ 54 bcm_ip6_t dst_ip6_addr; /* IPv6: destination IP address. */ 55 uint16 ip_protocol; /* IPv4: protocol; IPv6: next header. */ 56 uint16 tos; /* IPv4: type of service; IPv6: traffic 57 class. */ 58 uint32 ip6_flow_label; /* IPv6: flow label. */ 59 uint16 l4_src_port; /* First 16 bits of L4 header such as TCP 60 source port or ICMP type and code. */ 61 uint16 l4_dst_port; /* Second 16 bits of L4 header such as TCP 62 destination port. */ 63 bcm_gport_t source_port; /* Source port. */ 64 uint32 start_timestamp; /* Session information. */ 65 uint32 last_timestamp; /* Session information. */ 66 uint32 byte_count; /* Session information. */ 67 uint32 pkt_count; /* Session information. */ 68 uint32 ttl; /* TTL value of the first packet. */ 69 uint32 tcp_flags; /* TCP flags. */ 70 bcm_gport_t dest_port; /* Destination. */ 71 bcm_vlan_t egress_vlan; /* Egress VLAN. */ 72 bcm_multicast_t dest_multicast; /* Destination multicast group. */ 73 } bcm_ipfix_data_t; 74 75 /* Flags for bcm_ipfix_config_t.flags. */ 76 #define BCM_IPFIX_CONFIG_ENABLE_NON_IP 0x00000001 77 #define BCM_IPFIX_CONFIG_ENABLE_IP4 0x00000002 78 #define BCM_IPFIX_CONFIG_ENABLE_IP6 0x00000004 79 #define BCM_IPFIX_CONFIG_TCP_END_DETECT 0x00000008 80 #define BCM_IPFIX_CONFIG_RECORD_NON_DISCARD_PKT 0x00000010 81 #define BCM_IPFIX_CONFIG_RECORD_DISCARD_PKT 0x00000020 82 #define BCM_IPFIX_CONFIG_KEY_IP4_USE_L2 0x00000040 83 #define BCM_IPFIX_CONFIG_KEY_IP6_USE_L2 0x00000080 84 #define BCM_IPFIX_CONFIG_KEY_SRC_IP 0x00000100 85 #define BCM_IPFIX_CONFIG_KEY_DST_IP 0x00000200 86 #define BCM_IPFIX_CONFIG_KEY_IP_PROT 0x00000400 87 #define BCM_IPFIX_CONFIG_KEY_IP_DSCP 0x00000800 88 #define BCM_IPFIX_CONFIG_KEY_IP_ECN 0x00001000 89 #define BCM_IPFIX_CONFIG_KEY_L4_SRC_PORT 0x00002000 90 #define BCM_IPFIX_CONFIG_KEY_L4_DST_PORT 0x00004000 91 #define BCM_IPFIX_CONFIG_KEY_IP6_FLOW 0x00008000 92 #define BCM_IPFIX_CONFIG_KEY_ICMP_TYPE 0x00010000 93 #define BCM_IPFIX_CONFIG_KEY_ICMP_CODE 0x00020000 94 #define BCM_IPFIX_CONFIG_KEY_MACDA 0x00040000 95 #define BCM_IPFIX_CONFIG_KEY_MACSA 0x00080000 96 #define BCM_IPFIX_CONFIG_KEY_VLAN_ID 0x00100000 97 #define BCM_IPFIX_CONFIG_KEY_VLAN_PRI 0x00200000 98 #define BCM_IPFIX_CONFIG_KEY_ETHER_TYPE 0x00400000 99 #define BCM_IPFIX_CONFIG_KEY_VLAN_TAGGED 0x00800000 100 #define BCM_IPFIX_CONFIG_TCP_FLAGS_LAST 0x01000000 101 #define BCM_IPFIX_CONFIG_KEY_SOURCE_PORT_OR_INTERFACE 0x02000000 102 #define BCM_IPFIX_CONFIG_ENABLE_MASK 0x00000007 103 #define BCM_IPFIX_CONFIG_KEY_MASK 0x02ffffc0 104 105 /* IPFIX port configuration structure */ 106 typedef struct bcm_ipfix_config_s { 107 uint32 flags; /* Fields select and other flags. */ 108 uint8 dscp_mask[BCM_IPFIX_DSCP_MASK_COUNT]; /* DSCP value translation mapping. */ 109 bcm_ip_t src_ip4_mask; /* Mask to map IPv4 address to key 110 value. */ 111 bcm_ip_t dst_ip4_mask; /* Mask to map IPv4 address to key 112 value. */ 113 bcm_ip_t tunnel_src_ip4_mask; /* Mask to map IPv4 address to key 114 value. */ 115 bcm_ip_t tunnel_dst_ip4_mask; /* Mask to map IPv4 address to key 116 value. */ 117 bcm_ip6_t src_ip6_mask; /* Mask to map IPv6 address to key 118 value. */ 119 bcm_ip6_t dst_ip6_mask; /* Mask to map IPv6 address to key 120 value. */ 121 bcm_ip6_t tunnel_src_ip6_mask; /* Mask to map IPv6 address to key 122 value. */ 123 bcm_ip6_t tunnel_dst_ip6_mask; /* Mask to map IPv6 address to key 124 value. */ 125 uint32 entry_limit; /* Maximum number of flow entry 126 collected for the port. */ 127 uint32 min_time; /* The flow will not be exported unless 128 the flow has been established for 129 more than min_time (unit is 10 ms). */ 130 uint32 max_time; /* The flow will not be exported unless 131 the flow has been established for 132 less than max_time (unit is 10 ms). */ 133 uint32 max_idle_time; /* The flow will be exported and 134 terminated if idle for more than 135 max_idle_time (unit is 10 ms). */ 136 uint32 sample_rate; /* Collect one packet info for every 137 sample_rate packets. */ 138 } bcm_ipfix_config_t; 139 140 /* bcm_ipfix_callback_t */ 141 typedef void (*bcm_ipfix_callback_t)( 142 int unit, 143 bcm_ipfix_data_t *info, 144 void *userdata); 145 146 /* Flags for bcm_ipfix_rate_t.flags */ 147 #define BCM_IPFIX_RATE_VIOLATION_WITH_ID 0x00000001 148 #define BCM_IPFIX_RATE_VIOLATION_REPLACE 0x00000002 149 #define BCM_IPFIX_RATE_VIOLATION_DROP 0x00000004 150 #define BCM_IPFIX_RATE_VIOLATION_COPY_TO_CPU 0x00000008 151 #define BCM_IPFIX_RATE_VIOLATION_DSCP_SET 0x00000010 152 #define BCM_IPFIX_RATE_VIOLATION_COLOR_SET 0x00000020 153 #define BCM_IPFIX_RATE_VIOLATION_PKT_PRI_SET 0x00000040 154 #define BCM_IPFIX_RATE_VIOLATION_INT_PRI_SET 0x00000080 155 156 /* Flow rate meter entry */ 157 typedef struct bcm_ipfix_rate_s { 158 bcm_ipfix_rate_id_t rate_id; /* Flow rate meter id. */ 159 uint32 flags; /* Configuration flags. */ 160 uint32 count; /* Flow count (for get only). */ 161 uint32 limit; /* Max number of good flows to allow. */ 162 uint32 rate; /* Number of good flows per second. */ 163 uint8 dscp; /* New DSCP value. */ 164 bcm_color_t color; /* New color value. */ 165 int pkt_pri; /* New packet priority. */ 166 int int_pri; /* New internal priority. */ 167 } bcm_ipfix_rate_t; 168 169 /* Flags for bcm_ipfix_mirror_config_t.flags. */ 170 #define BCM_IPFIX_MIRROR_CONFIG_TTL_OFFSET_MAX 0x0001 171 #define BCM_IPFIX_MIRROR_CONFIG_FRAGMENT 0x0002 172 #define BCM_IPFIX_MIRROR_CONFIG_NON_FRAGMENT 0x0004 173 174 /* IPFIX port mirror configuration */ 175 typedef struct bcm_ipfix_mirror_config_s { 176 uint32 flags; /* Configuration flags. */ 177 uint32 pkt_count; /* Number of packets to be mirrored. */ 178 uint8 tcp_flags_mask; /* TCP flags mask to determine if the packet will be 179 mirrored. */ 180 uint8 ttl_offset_max; /* Max TTL offset allowance to be mirrored. */ 181 } bcm_ipfix_mirror_config_t; 182 183 /* Initialize an IPFIX configuration structure. */ 184 extern void bcm_ipfix_config_t_init( 185 bcm_ipfix_config_t *config); 186 187 /* Initialize an IPFIX rate configuration structure. */ 188 extern void bcm_ipfix_rate_t_init( 189 bcm_ipfix_rate_t *rate); 190 191 /* Initialize an IPFIX mirror configuration structure. */ 192 extern void bcm_ipfix_mirror_config_t_init( 193 bcm_ipfix_mirror_config_t *config); 194 195 #ifndef BCM_HIDE_DISPATCHABLE 196 197 /* 198 * Register/Unregister a callback routine for BCM IPFIX export 199 * information. 200 */ 201 extern int bcm_ipfix_register( 202 int unit, 203 bcm_ipfix_callback_t callback, 204 void *userdata); 205 206 /* 207 * Register/Unregister a callback routine for BCM IPFIX export 208 * information. 209 */ 210 extern int bcm_ipfix_unregister( 211 int unit, 212 bcm_ipfix_callback_t callback, 213 void *userdata); 214 215 /* Set/Get the IPFIX configuration of the specified port. */ 216 extern int bcm_ipfix_config_set( 217 int unit, 218 bcm_ipfix_stage_t stage, 219 bcm_port_t port, 220 bcm_ipfix_config_t *config); 221 222 /* Set/Get the IPFIX configuration of the specified port. */ 223 extern int bcm_ipfix_config_get( 224 int unit, 225 bcm_ipfix_stage_t stage, 226 bcm_port_t port, 227 bcm_ipfix_config_t *config); 228 229 /* Create an IPFIX flow rate meter entry. */ 230 extern int bcm_ipfix_rate_create( 231 int unit, 232 bcm_ipfix_rate_t *rate_info); 233 234 /* Destroy an IPFIX flow rate meter entry. */ 235 extern int bcm_ipfix_rate_destroy( 236 int unit, 237 bcm_ipfix_rate_id_t rate_id); 238 239 /* Get IPFIX flow rate meter entry for the specified ID. */ 240 extern int bcm_ipfix_rate_get( 241 int unit, 242 bcm_ipfix_rate_t *rate_info); 243 244 #endif /* BCM_HIDE_DISPATCHABLE */ 245 246 /* IPFIX flow rate meter entry traverse callback function */ 247 typedef int (*bcm_ipfix_rate_traverse_cb)( 248 int unit, 249 bcm_ipfix_rate_t *rate_info, 250 void *userdata); 251 252 #ifndef BCM_HIDE_DISPATCHABLE 253 254 /* Traverse through IPFIX flow rate meter entries. */ 255 extern int bcm_ipfix_rate_traverse( 256 int unit, 257 bcm_ipfix_rate_traverse_cb cb, 258 void *userdata); 259 260 /* Destroy all IPFIX flow rate meter entries. */ 261 extern int bcm_ipfix_rate_destroy_all( 262 int unit); 263 264 /* Add a mirror destination to the IPFIX flow rate meter entry. */ 265 extern int bcm_ipfix_rate_mirror_add( 266 int unit, 267 bcm_ipfix_rate_id_t rate_id, 268 bcm_gport_t mirror_dest_id); 269 270 /* Delete a mirror destination from the IPFIX flow rate meter entry. */ 271 extern int bcm_ipfix_rate_mirror_delete( 272 int unit, 273 bcm_ipfix_rate_id_t rate_id, 274 bcm_gport_t mirror_dest_id); 275 276 /* 277 * Delete all mirror destination associated with the IPFIX flow rate 278 * meter entry. 279 */ 280 extern int bcm_ipfix_rate_mirror_delete_all( 281 int unit, 282 bcm_ipfix_rate_id_t rate_id); 283 284 /* Get all mirror destination from the IPFIX flow rate meter entry. */ 285 extern int bcm_ipfix_rate_mirror_get( 286 int unit, 287 bcm_ipfix_rate_id_t rate_id, 288 int mirror_dest_size, 289 bcm_gport_t *mirror_dest_id, 290 int *mirror_dest_count); 291 292 /* Set IPFIX mirror control configuration of the specified port. */ 293 extern int bcm_ipfix_mirror_config_set( 294 int unit, 295 bcm_ipfix_stage_t stage, 296 bcm_gport_t port, 297 bcm_ipfix_mirror_config_t *config); 298 299 /* Get IPFIX mirror control configuration of the specified port. */ 300 extern int bcm_ipfix_mirror_config_get( 301 int unit, 302 bcm_ipfix_stage_t stage, 303 bcm_gport_t port, 304 bcm_ipfix_mirror_config_t *config); 305 306 /* Add an IPFIX mirror destination to the specified port. */ 307 extern int bcm_ipfix_mirror_port_dest_add( 308 int unit, 309 bcm_ipfix_stage_t stage, 310 bcm_gport_t port, 311 bcm_gport_t mirror_dest_id); 312 313 /* Delete an IPFIX mirror destination from the specified port. */ 314 extern int bcm_ipfix_mirror_port_dest_delete( 315 int unit, 316 bcm_ipfix_stage_t stage, 317 bcm_gport_t port, 318 bcm_gport_t mirror_dest_id); 319 320 /* Delete all IPFIX mirror destination from the specified port. */ 321 extern int bcm_ipfix_mirror_port_dest_delete_all( 322 int unit, 323 bcm_ipfix_stage_t stage, 324 bcm_gport_t port); 325 326 /* Get all IPFIX mirror destination of the specified port */ 327 extern int bcm_ipfix_mirror_port_dest_get( 328 int unit, 329 bcm_ipfix_stage_t stage, 330 bcm_gport_t port, 331 int mirror_dest_size, 332 bcm_gport_t *mirror_dest_id, 333 int *mirror_dest_count); 334 335 #endif /* BCM_HIDE_DISPATCHABLE */ 336 337 #endif /* __BCM_IPFIX_H__ */