1 /* Copyright (c) 2002-2009 InMon Corp. Licensed under the terms of either the
2 * Sun Industry Standards Source License 1.1, that is available at:
3 * http://host-sflow.sourceforge.net/sissl.html
4 * or the InMon sFlow License, that is available at:
5 * http://www.inmon.com/technology/sflowlicense.txt
16 SFL_DSCLASS_IFINDEX = 0,
18 SFL_DSCLASS_PHYSICAL_ENTITY = 2,
19 SFL_DSCLASS_LOGICAL_ENTITY = 3
22 enum SFLAddress_type {
23 SFLADDRESSTYPE_IP_V4 = 1,
24 SFLADDRESSTYPE_IP_V6 = 2
35 typedef union _SFLAddress_value {
40 typedef struct _SFLAddress {
41 u_int32_t type; /* enum SFLAddress_type */
42 SFLAddress_value address;
45 /* Packet header data */
47 #define SFL_DEFAULT_HEADER_SIZE 128
48 #define SFL_DEFAULT_COLLECTOR_PORT 6343
49 #define SFL_DEFAULT_SAMPLING_RATE 400
50 #define SFL_DEFAULT_POLLING_INTERVAL 30
52 /* The header protocol describes the format of the sampled header */
53 enum SFLHeader_protocol {
54 SFLHEADER_ETHERNET_ISO8023 = 1,
55 SFLHEADER_ISO88024_TOKENBUS = 2,
56 SFLHEADER_ISO88025_TOKENRING = 3,
58 SFLHEADER_FRAME_RELAY = 5,
63 SFLHEADER_AAL5_IP = 10, /* e.g. Cisco AAL5 mux */
69 /* raw sampled header */
71 typedef struct _SFLSampled_header {
72 u_int32_t header_protocol; /* (enum SFLHeader_protocol) */
73 u_int32_t frame_length; /* Original length of packet before sampling */
74 u_int32_t stripped; /* header/trailer bytes stripped by sender */
75 u_int32_t header_length; /* length of sampled header bytes to follow */
76 u_int8_t *header_bytes; /* Header bytes */
79 /* decoded ethernet header */
81 typedef struct _SFLSampled_ethernet {
82 u_int32_t eth_len; /* The length of the MAC packet excluding
83 lower layer encapsulations */
84 u_int8_t src_mac[8]; /* 6 bytes + 2 pad */
87 } SFLSampled_ethernet;
89 /* decoded IP version 4 header */
91 typedef struct _SFLSampled_ipv4 {
92 u_int32_t length; /* The length of the IP packet
93 excluding lower layer encapsulations */
94 u_int32_t protocol; /* IP Protocol type (for example, TCP = 6, UDP = 17) */
95 SFLIPv4 src_ip; /* Source IP Address */
96 SFLIPv4 dst_ip; /* Destination IP Address */
97 u_int32_t src_port; /* TCP/UDP source port number or equivalent */
98 u_int32_t dst_port; /* TCP/UDP destination port number or equivalent */
99 u_int32_t tcp_flags; /* TCP flags */
100 u_int32_t tos; /* IP type of service */
103 /* decoded IP version 6 data */
105 typedef struct _SFLSampled_ipv6 {
106 u_int32_t length; /* The length of the IP packet
107 excluding lower layer encapsulations */
108 u_int32_t protocol; /* IP Protocol type (for example, TCP = 6, UDP = 17) */
109 SFLIPv6 src_ip; /* Source IP Address */
110 SFLIPv6 dst_ip; /* Destination IP Address */
111 u_int32_t src_port; /* TCP/UDP source port number or equivalent */
112 u_int32_t dst_port; /* TCP/UDP destination port number or equivalent */
113 u_int32_t tcp_flags; /* TCP flags */
114 u_int32_t priority; /* IP priority */
117 /* Extended data types */
119 /* Extended switch data */
121 typedef struct _SFLExtended_switch {
122 u_int32_t src_vlan; /* The 802.1Q VLAN id of incomming frame */
123 u_int32_t src_priority; /* The 802.1p priority */
124 u_int32_t dst_vlan; /* The 802.1Q VLAN id of outgoing frame */
125 u_int32_t dst_priority; /* The 802.1p priority */
126 } SFLExtended_switch;
128 /* Extended router data */
130 typedef struct _SFLExtended_router {
131 SFLAddress nexthop; /* IP address of next hop router */
132 u_int32_t src_mask; /* Source address prefix mask bits */
133 u_int32_t dst_mask; /* Destination address prefix mask bits */
134 } SFLExtended_router;
136 /* Extended gateway data */
137 enum SFLExtended_as_path_segment_type {
138 SFLEXTENDED_AS_SET = 1, /* Unordered set of ASs */
139 SFLEXTENDED_AS_SEQUENCE = 2 /* Ordered sequence of ASs */
142 typedef struct _SFLExtended_as_path_segment {
143 u_int32_t type; /* enum SFLExtended_as_path_segment_type */
144 u_int32_t length; /* number of AS numbers in set/sequence */
149 } SFLExtended_as_path_segment;
151 typedef struct _SFLExtended_gateway {
152 SFLAddress nexthop; /* Address of the border router that should
153 be used for the destination network */
154 u_int32_t as; /* AS number for this gateway */
155 u_int32_t src_as; /* AS number of source (origin) */
156 u_int32_t src_peer_as; /* AS number of source peer */
157 u_int32_t dst_as_path_segments; /* number of segments in path */
158 SFLExtended_as_path_segment *dst_as_path; /* list of seqs or sets */
159 u_int32_t communities_length; /* number of communities */
160 u_int32_t *communities; /* set of communities */
161 u_int32_t localpref; /* LocalPref associated with this route */
162 } SFLExtended_gateway;
164 typedef struct _SFLString {
169 /* Extended user data */
171 typedef struct _SFLExtended_user {
172 u_int32_t src_charset; /* MIBEnum value of character set used to encode a string - See RFC 2978
173 Where possible UTF-8 encoding (MIBEnum=106) should be used. A value
174 of zero indicates an unknown encoding. */
176 u_int32_t dst_charset;
180 /* Extended URL data */
182 enum SFLExtended_url_direction {
183 SFLEXTENDED_URL_SRC = 1, /* URL is associated with source address */
184 SFLEXTENDED_URL_DST = 2 /* URL is associated with destination address */
187 typedef struct _SFLExtended_url {
188 u_int32_t direction; /* enum SFLExtended_url_direction */
189 SFLString url; /* URL associated with the packet flow.
190 Must be URL encoded */
191 SFLString host; /* The host field from the HTTP header */
194 /* Extended MPLS data */
196 typedef struct _SFLLabelStack {
198 u_int32_t *stack; /* first entry is top of stack - see RFC 3032 for encoding */
201 typedef struct _SFLExtended_mpls {
202 SFLAddress nextHop; /* Address of the next hop */
203 SFLLabelStack in_stack;
204 SFLLabelStack out_stack;
208 Packet header records report addresses as seen at the sFlowDataSource.
209 The extended_nat structure reports on translated source and/or destination
210 addesses for this packet. If an address was not translated it should
211 be equal to that reported for the header. */
213 typedef struct _SFLExtended_nat {
214 SFLAddress src; /* Source address */
215 SFLAddress dst; /* Destination address */
218 /* additional Extended MPLS stucts */
220 typedef struct _SFLExtended_mpls_tunnel {
221 SFLString tunnel_lsp_name; /* Tunnel name */
222 u_int32_t tunnel_id; /* Tunnel ID */
223 u_int32_t tunnel_cos; /* Tunnel COS value */
224 } SFLExtended_mpls_tunnel;
226 typedef struct _SFLExtended_mpls_vc {
227 SFLString vc_instance_name; /* VC instance name */
228 u_int32_t vll_vc_id; /* VLL/VC instance ID */
229 u_int32_t vc_label_cos; /* VC Label COS value */
230 } SFLExtended_mpls_vc;
233 - Definitions from MPLS-FTN-STD-MIB mplsFTNTable */
235 typedef struct _SFLExtended_mpls_FTN {
236 SFLString mplsFTNDescr;
237 u_int32_t mplsFTNMask;
238 } SFLExtended_mpls_FTN;
240 /* Extended MPLS LVP FEC
241 - Definition from MPLS-LDP-STD-MIB mplsFecTable
242 Note: mplsFecAddrType, mplsFecAddr information available
243 from packet header */
245 typedef struct _SFLExtended_mpls_LDP_FEC {
246 u_int32_t mplsFecAddrPrefixLength;
247 } SFLExtended_mpls_LDP_FEC;
249 /* Extended VLAN tunnel information
250 Record outer VLAN encapsulations that have
251 been stripped. extended_vlantunnel information
252 should only be reported if all the following conditions are satisfied:
253 1. The packet has nested vlan tags, AND
254 2. The reporting device is VLAN aware, AND
255 3. One or more VLAN tags have been stripped, either
256 because they represent proprietary encapsulations, or
257 because switch hardware automatically strips the outer VLAN
259 Reporting extended_vlantunnel information is not a substitute for
260 reporting extended_switch information. extended_switch data must
261 always be reported to describe the ingress/egress VLAN information
262 for the packet. The extended_vlantunnel information only applies to
263 nested VLAN tags, and then only when one or more tags has been
266 typedef SFLLabelStack SFLVlanStack;
267 typedef struct _SFLExtended_vlan_tunnel {
268 SFLVlanStack stack; /* List of stripped 802.1Q TPID/TCI layers. Each
269 TPID,TCI pair is represented as a single 32 bit
270 integer. Layers listed from outermost to
272 } SFLExtended_vlan_tunnel;
274 enum SFLFlow_type_tag {
275 /* enterprise = 0, format = ... */
276 SFLFLOW_HEADER = 1, /* Packet headers are sampled */
277 SFLFLOW_ETHERNET = 2, /* MAC layer information */
278 SFLFLOW_IPV4 = 3, /* IP version 4 data */
279 SFLFLOW_IPV6 = 4, /* IP version 6 data */
280 SFLFLOW_EX_SWITCH = 1001, /* Extended switch information */
281 SFLFLOW_EX_ROUTER = 1002, /* Extended router information */
282 SFLFLOW_EX_GATEWAY = 1003, /* Extended gateway router information */
283 SFLFLOW_EX_USER = 1004, /* Extended TACAS/RADIUS user information */
284 SFLFLOW_EX_URL = 1005, /* Extended URL information */
285 SFLFLOW_EX_MPLS = 1006, /* Extended MPLS information */
286 SFLFLOW_EX_NAT = 1007, /* Extended NAT information */
287 SFLFLOW_EX_MPLS_TUNNEL = 1008, /* additional MPLS information */
288 SFLFLOW_EX_MPLS_VC = 1009,
289 SFLFLOW_EX_MPLS_FTN = 1010,
290 SFLFLOW_EX_MPLS_LDP_FEC = 1011,
291 SFLFLOW_EX_VLAN_TUNNEL = 1012, /* VLAN stack */
294 typedef union _SFLFlow_type {
295 SFLSampled_header header;
296 SFLSampled_ethernet ethernet;
297 SFLSampled_ipv4 ipv4;
298 SFLSampled_ipv6 ipv6;
299 SFLExtended_switch sw;
300 SFLExtended_router router;
301 SFLExtended_gateway gateway;
302 SFLExtended_user user;
304 SFLExtended_mpls mpls;
306 SFLExtended_mpls_tunnel mpls_tunnel;
307 SFLExtended_mpls_vc mpls_vc;
308 SFLExtended_mpls_FTN mpls_ftn;
309 SFLExtended_mpls_LDP_FEC mpls_ldp_fec;
310 SFLExtended_vlan_tunnel vlan_tunnel;
313 typedef struct _SFLFlow_sample_element {
314 struct _SFLFlow_sample_element *nxt;
315 u_int32_t tag; /* SFLFlow_type_tag */
317 SFLFlow_type flowType;
318 } SFLFlow_sample_element;
320 enum SFL_sample_tag {
321 SFLFLOW_SAMPLE = 1, /* enterprise = 0 : format = 1 */
322 SFLCOUNTERS_SAMPLE = 2, /* enterprise = 0 : format = 2 */
323 SFLFLOW_SAMPLE_EXPANDED = 3, /* enterprise = 0 : format = 3 */
324 SFLCOUNTERS_SAMPLE_EXPANDED = 4 /* enterprise = 0 : format = 4 */
327 /* Format of a single flow sample */
329 typedef struct _SFLFlow_sample {
330 /* u_int32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 1 */
331 /* u_int32_t length; */
332 u_int32_t sequence_number; /* Incremented with each flow sample
334 u_int32_t source_id; /* fsSourceId */
335 u_int32_t sampling_rate; /* fsPacketSamplingRate */
336 u_int32_t sample_pool; /* Total number of packets that could have been
337 sampled (i.e. packets skipped by sampling
338 process + total number of samples) */
339 u_int32_t drops; /* Number of times a packet was dropped due to
341 u_int32_t input; /* SNMP ifIndex of input interface.
342 0 if interface is not known. */
343 u_int32_t output; /* SNMP ifIndex of output interface,
344 0 if interface is not known.
345 Set most significant bit to indicate
346 multiple destination interfaces
347 (i.e. in case of broadcast or multicast)
348 and set lower order bits to indicate
349 number of destination interfaces.
351 0x00000002 indicates ifIndex = 2
352 0x00000000 ifIndex unknown.
353 0x80000007 indicates a packet sent
355 0x80000000 indicates a packet sent to
357 interfaces greater than 1.*/
358 u_int32_t num_elements;
359 SFLFlow_sample_element *elements;
362 /* same thing, but the expanded version (for full 32-bit ifIndex numbers) */
364 typedef struct _SFLFlow_sample_expanded {
365 /* u_int32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 1 */
366 /* u_int32_t length; */
367 u_int32_t sequence_number; /* Incremented with each flow sample
369 u_int32_t ds_class; /* EXPANDED */
370 u_int32_t ds_index; /* EXPANDED */
371 u_int32_t sampling_rate; /* fsPacketSamplingRate */
372 u_int32_t sample_pool; /* Total number of packets that could have been
373 sampled (i.e. packets skipped by sampling
374 process + total number of samples) */
375 u_int32_t drops; /* Number of times a packet was dropped due to
377 u_int32_t inputFormat; /* EXPANDED */
378 u_int32_t input; /* SNMP ifIndex of input interface.
379 0 if interface is not known. */
380 u_int32_t outputFormat; /* EXPANDED */
381 u_int32_t output; /* SNMP ifIndex of output interface,
382 0 if interface is not known. */
383 u_int32_t num_elements;
384 SFLFlow_sample_element *elements;
385 } SFLFlow_sample_expanded;
389 /* Generic interface counters - see RFC 1573, 2233 */
391 typedef struct _SFLIf_counters {
395 u_int32_t ifDirection; /* Derived from MAU MIB (RFC 2668)
396 0 = unknown, 1 = full-duplex,
397 2 = half-duplex, 3 = in, 4 = out */
398 u_int32_t ifStatus; /* bit field with the following bits assigned:
399 bit 0 = ifAdminStatus (0 = down, 1 = up)
400 bit 1 = ifOperStatus (0 = down, 1 = up) */
401 u_int64_t ifInOctets;
402 u_int32_t ifInUcastPkts;
403 u_int32_t ifInMulticastPkts;
404 u_int32_t ifInBroadcastPkts;
405 u_int32_t ifInDiscards;
406 u_int32_t ifInErrors;
407 u_int32_t ifInUnknownProtos;
408 u_int64_t ifOutOctets;
409 u_int32_t ifOutUcastPkts;
410 u_int32_t ifOutMulticastPkts;
411 u_int32_t ifOutBroadcastPkts;
412 u_int32_t ifOutDiscards;
413 u_int32_t ifOutErrors;
414 u_int32_t ifPromiscuousMode;
417 /* Ethernet interface counters - see RFC 2358 */
418 typedef struct _SFLEthernet_counters {
419 u_int32_t dot3StatsAlignmentErrors;
420 u_int32_t dot3StatsFCSErrors;
421 u_int32_t dot3StatsSingleCollisionFrames;
422 u_int32_t dot3StatsMultipleCollisionFrames;
423 u_int32_t dot3StatsSQETestErrors;
424 u_int32_t dot3StatsDeferredTransmissions;
425 u_int32_t dot3StatsLateCollisions;
426 u_int32_t dot3StatsExcessiveCollisions;
427 u_int32_t dot3StatsInternalMacTransmitErrors;
428 u_int32_t dot3StatsCarrierSenseErrors;
429 u_int32_t dot3StatsFrameTooLongs;
430 u_int32_t dot3StatsInternalMacReceiveErrors;
431 u_int32_t dot3StatsSymbolErrors;
432 } SFLEthernet_counters;
434 /* Token ring counters - see RFC 1748 */
436 typedef struct _SFLTokenring_counters {
437 u_int32_t dot5StatsLineErrors;
438 u_int32_t dot5StatsBurstErrors;
439 u_int32_t dot5StatsACErrors;
440 u_int32_t dot5StatsAbortTransErrors;
441 u_int32_t dot5StatsInternalErrors;
442 u_int32_t dot5StatsLostFrameErrors;
443 u_int32_t dot5StatsReceiveCongestions;
444 u_int32_t dot5StatsFrameCopiedErrors;
445 u_int32_t dot5StatsTokenErrors;
446 u_int32_t dot5StatsSoftErrors;
447 u_int32_t dot5StatsHardErrors;
448 u_int32_t dot5StatsSignalLoss;
449 u_int32_t dot5StatsTransmitBeacons;
450 u_int32_t dot5StatsRecoverys;
451 u_int32_t dot5StatsLobeWires;
452 u_int32_t dot5StatsRemoves;
453 u_int32_t dot5StatsSingles;
454 u_int32_t dot5StatsFreqErrors;
455 } SFLTokenring_counters;
457 /* 100 BaseVG interface counters - see RFC 2020 */
459 typedef struct _SFLVg_counters {
460 u_int32_t dot12InHighPriorityFrames;
461 u_int64_t dot12InHighPriorityOctets;
462 u_int32_t dot12InNormPriorityFrames;
463 u_int64_t dot12InNormPriorityOctets;
464 u_int32_t dot12InIPMErrors;
465 u_int32_t dot12InOversizeFrameErrors;
466 u_int32_t dot12InDataErrors;
467 u_int32_t dot12InNullAddressedFrames;
468 u_int32_t dot12OutHighPriorityFrames;
469 u_int64_t dot12OutHighPriorityOctets;
470 u_int32_t dot12TransitionIntoTrainings;
471 u_int64_t dot12HCInHighPriorityOctets;
472 u_int64_t dot12HCInNormPriorityOctets;
473 u_int64_t dot12HCOutHighPriorityOctets;
476 typedef struct _SFLVlan_counters {
480 u_int32_t multicastPkts;
481 u_int32_t broadcastPkts;
487 enum SFLCounters_type_tag {
488 /* enterprise = 0, format = ... */
489 SFLCOUNTERS_GENERIC = 1,
490 SFLCOUNTERS_ETHERNET = 2,
491 SFLCOUNTERS_TOKENRING = 3,
496 typedef union _SFLCounters_type {
497 SFLIf_counters generic;
498 SFLEthernet_counters ethernet;
499 SFLTokenring_counters tokenring;
501 SFLVlan_counters vlan;
504 typedef struct _SFLCounters_sample_element {
505 struct _SFLCounters_sample_element *nxt; /* linked list */
506 u_int32_t tag; /* SFLCounters_type_tag */
508 SFLCounters_type counterBlock;
509 } SFLCounters_sample_element;
511 typedef struct _SFLCounters_sample {
512 /* u_int32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 2 */
513 /* u_int32_t length; */
514 u_int32_t sequence_number; /* Incremented with each counters sample
515 generated by this source_id */
516 u_int32_t source_id; /* fsSourceId */
517 u_int32_t num_elements;
518 SFLCounters_sample_element *elements;
519 } SFLCounters_sample;
521 /* same thing, but the expanded version, so ds_index can be a full 32 bits */
522 typedef struct _SFLCounters_sample_expanded {
523 /* u_int32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 2 */
524 /* u_int32_t length; */
525 u_int32_t sequence_number; /* Incremented with each counters sample
526 generated by this source_id */
527 u_int32_t ds_class; /* EXPANDED */
528 u_int32_t ds_index; /* EXPANDED */
529 u_int32_t num_elements;
530 SFLCounters_sample_element *elements;
531 } SFLCounters_sample_expanded;
533 #define SFLADD_ELEMENT(_sm, _el) do { (_el)->nxt = (_sm)->elements; (_sm)->elements = (_el); } while(0)
535 /* Format of a sample datagram */
537 enum SFLDatagram_version {
538 SFLDATAGRAM_VERSION2 = 2,
539 SFLDATAGRAM_VERSION4 = 4,
540 SFLDATAGRAM_VERSION5 = 5
543 typedef struct _SFLSample_datagram_hdr {
544 u_int32_t datagram_version; /* (enum SFLDatagram_version) = VERSION5 = 5 */
545 SFLAddress agent_address; /* IP address of sampling agent */
546 u_int32_t sub_agent_id; /* Used to distinguishing between datagram
547 streams from separate agent sub entities
549 u_int32_t sequence_number; /* Incremented with each sample datagram
551 u_int32_t uptime; /* Current time (in milliseconds since device
552 last booted). Should be set as close to
553 datagram transmission time as possible.*/
554 u_int32_t num_records; /* Number of tag-len-val flow/counter records to follow */
555 } SFLSample_datagram_hdr;
557 #define SFL_MAX_DATAGRAM_SIZE 1500
558 #define SFL_MIN_DATAGRAM_SIZE 200
559 #define SFL_DEFAULT_DATAGRAM_SIZE 1400
561 #define SFL_DATA_PAD 400