sflow-parser 0.6.0

InMon sFlow v5 Parser
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
//! sFlow v5 data models
//!
//! This module contains the data structures representing sFlow v5 datagrams
//! as defined in <https://sflow.org/sflow_version_5.txt>

use std::net::{Ipv4Addr, Ipv6Addr};

/// MAC address (6 bytes)
///
/// Represents a 48-bit IEEE 802 MAC address.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MacAddress(pub [u8; 6]);

impl MacAddress {
    /// Create a new MAC address from 6 bytes
    pub const fn new(bytes: [u8; 6]) -> Self {
        Self(bytes)
    }

    /// Get the MAC address as a byte array
    pub const fn as_bytes(&self) -> &[u8; 6] {
        &self.0
    }

    /// Check if this is a broadcast address (FF:FF:FF:FF:FF:FF)
    pub fn is_broadcast(&self) -> bool {
        self.0 == [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
    }

    /// Check if this is a multicast address (first byte has LSB set)
    pub fn is_multicast(&self) -> bool {
        self.0[0] & 0x01 != 0
    }

    /// Check if this is a unicast address
    pub fn is_unicast(&self) -> bool {
        !self.is_multicast()
    }
}

impl std::fmt::Display for MacAddress {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
            self.0[0], self.0[1], self.0[2], self.0[3], self.0[4], self.0[5]
        )
    }
}

impl From<[u8; 6]> for MacAddress {
    fn from(bytes: [u8; 6]) -> Self {
        Self(bytes)
    }
}

impl From<MacAddress> for [u8; 6] {
    fn from(mac: MacAddress) -> Self {
        mac.0
    }
}

/// sFlow datagram version
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DatagramVersion {
    Version5 = 5,
}

/// Address types supported by sFlow
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// enum address_type {
///    UNKNOWN = 0,
///    IP_V4   = 1,
///    IP_V6   = 2
/// }
///
/// union address (address_type type) {
///    case UNKNOWN:
///       void;
///    case IP_V4:
///       ip_v4 ip;
///    case IP_V6:
///       ip_v6 ip;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Address {
    /// Unknown address type
    Unknown,
    /// IPv4 address
    IPv4(Ipv4Addr),
    /// IPv6 address
    IPv6(Ipv6Addr),
}

/// Data format identifier
///
/// Encodes enterprise ID and format number in a single 32-bit value.
/// Top 20 bits = enterprise ID, bottom 12 bits = format number.
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// typedef unsigned int data_format;
/// /* The data_format uniquely identifies the format of an opaque structure in
///    the sFlow specification. For example, the combination of enterprise = 0
///    and format = 1 identifies the "sampled_header" flow_data structure. */
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DataFormat(pub u32);

impl DataFormat {
    pub fn new(enterprise: u32, format: u32) -> Self {
        Self((enterprise << 12) | (format & 0xFFF))
    }

    pub fn enterprise(&self) -> u32 {
        self.0 >> 12
    }

    pub fn format(&self) -> u32 {
        self.0 & 0xFFF
    }
}

/// sFlow data source identifier
///
/// Identifies the source of the data. Top 8 bits = source type, bottom 24 bits = index.
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// typedef unsigned int sflow_data_source;
/// /* The sflow_data_source is encoded as follows:
///    The most significant byte of the sflow_data_source is used to indicate the type of
///    sFlowDataSource (e.g. ifIndex, smonVlanDataSource, entPhysicalEntry) and the lower
///    three bytes contain the relevant index value. */
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DataSource(pub u32);

impl DataSource {
    pub fn new(source_type: u8, index: u32) -> Self {
        Self(((source_type as u32) << 24) | (index & 0xFFFFFF))
    }

    pub fn source_type(&self) -> u8 {
        (self.0 >> 24) as u8
    }

    pub fn index(&self) -> u32 {
        self.0 & 0xFFFFFF
    }
}

/// Expanded data source (for ifIndex >= 2^24)
///
/// Used when the index value exceeds 24 bits (16,777,215).
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// struct sflow_data_source_expanded {
///    unsigned int source_id_type;  /* sFlowDataSource type */
///    unsigned int source_id_index; /* sFlowDataSource index */
/// }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DataSourceExpanded {
    /// Source type (e.g., 0 = ifIndex, 1 = smonVlanDataSource, 2 = entPhysicalEntry)
    pub source_id_type: u32,
    /// Source index value
    pub source_id_index: u32,
}

/// Interface identifier
///
/// Compact encoding for interface identification. Top 2 bits indicate format:
/// - 00 = Single interface (value is ifIndex)
/// - 01 = Packet discarded (value is reason code)
/// - 10 = Multiple destination interfaces (value is number of interfaces)
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// typedef unsigned int interface;
/// /* Encoding of the interface value:
///    Bits 31-30: Format
///       00 = ifIndex (0-0x3FFFFFFF)
///       01 = Packet discarded
///       10 = Multiple destinations
///    Bits 29-0: Value */
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Interface(pub u32);

impl Interface {
    pub fn format(&self) -> u8 {
        (self.0 >> 30) as u8
    }

    pub fn value(&self) -> u32 {
        self.0 & 0x3FFFFFFF
    }

    pub fn is_single(&self) -> bool {
        self.format() == 0
    }

    pub fn is_discarded(&self) -> bool {
        self.format() == 1
    }

    pub fn is_multiple(&self) -> bool {
        self.format() == 2
    }
}

/// Expanded interface (for ifIndex >= 2^24)
///
/// Used when the interface index exceeds 30 bits (1,073,741,823).
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// struct interface_expanded {
///    unsigned int format;        /* interface format */
///    unsigned int value;         /* interface value,
///                                   Note: 0xFFFFFFFF is the maximum value and must be used
///                                   to indicate traffic originating or terminating in device
///                                   (do not use 0x3FFFFFFF value from compact encoding example) */
/// }
/// ```
///
/// **ERRATUM:** 0xFFFFFFFF is the maximum value and must be used to indicate traffic
/// originating or terminating in device (do not use 0x3FFFFFFF value from compact encoding example).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InterfaceExpanded {
    /// Interface format (0 = ifIndex, 1 = packet discarded, 2 = multiple destinations)
    pub format: u32,
    /// Interface value
    /// **ERRATUM:** 0xFFFFFFFF indicates traffic originating or terminating in device
    pub value: u32,
}

/// Flow data types
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FlowData {
    /// Sampled Header - Format (0,1)
    SampledHeader(crate::models::record_flows::SampledHeader),
    /// Sampled Ethernet - Format (0,2)
    SampledEthernet(crate::models::record_flows::SampledEthernet),
    /// Sampled IPv4 - Format (0,3)
    SampledIpv4(crate::models::record_flows::SampledIpv4),
    /// Sampled IPv6 - Format (0,4)
    SampledIpv6(crate::models::record_flows::SampledIpv6),
    /// Extended Switch - Format (0,1001)
    ExtendedSwitch(crate::models::record_flows::ExtendedSwitch),
    /// Extended Router - Format (0,1002)
    ExtendedRouter(crate::models::record_flows::ExtendedRouter),
    /// Extended Gateway - Format (0,1003)
    ExtendedGateway(crate::models::record_flows::ExtendedGateway),
    /// Extended User - Format (0,1004)
    ExtendedUser(crate::models::record_flows::ExtendedUser),
    /// Extended URL - Format (0,1005) - DEPRECATED
    ExtendedUrl(crate::models::record_flows::ExtendedUrl),
    /// Extended MPLS - Format (0,1006)
    ExtendedMpls(crate::models::record_flows::ExtendedMpls),
    /// Extended NAT - Format (0,1007)
    ExtendedNat(crate::models::record_flows::ExtendedNat),
    /// Extended MPLS Tunnel - Format (0,1008)
    ExtendedMplsTunnel(crate::models::record_flows::ExtendedMplsTunnel),
    /// Extended MPLS VC - Format (0,1009)
    ExtendedMplsVc(crate::models::record_flows::ExtendedMplsVc),
    /// Extended MPLS FEC - Format (0,1010)
    ExtendedMplsFec(crate::models::record_flows::ExtendedMplsFec),
    /// Extended MPLS LVP FEC - Format (0,1011)
    ExtendedMplsLvpFec(crate::models::record_flows::ExtendedMplsLvpFec),
    /// Extended VLAN Tunnel - Format (0,1012)
    ExtendedVlanTunnel(crate::models::record_flows::ExtendedVlanTunnel),
    /// Extended 802.11 Payload - Format (0,1013)
    Extended80211Payload(crate::models::record_flows::Extended80211Payload),
    /// Extended 802.11 RX - Format (0,1014)
    Extended80211Rx(crate::models::record_flows::Extended80211Rx),
    /// Extended 802.11 TX - Format (0,1015)
    Extended80211Tx(crate::models::record_flows::Extended80211Tx),
    /// Extended 802.11 Aggregation - Format (0,1016)
    Extended80211Aggregation(crate::models::record_flows::Extended80211Aggregation),
    /// Extended OpenFlow v1 - Format (0,1017) - DEPRECATED
    ExtendedOpenFlowV1(crate::models::record_flows::ExtendedOpenFlowV1),
    /// Extended Fiber Channel - Format (0,1018)
    ExtendedFc(crate::models::record_flows::ExtendedFc),
    /// Extended Queue Length - Format (0,1019)
    ExtendedQueueLength(crate::models::record_flows::ExtendedQueueLength),
    /// Extended NAT Port - Format (0,1020)
    ExtendedNatPort(crate::models::record_flows::ExtendedNatPort),
    /// Extended L2 Tunnel Egress - Format (0,1021)
    ExtendedL2TunnelEgress(crate::models::record_flows::ExtendedL2TunnelEgress),
    /// Extended L2 Tunnel Ingress - Format (0,1022)
    ExtendedL2TunnelIngress(crate::models::record_flows::ExtendedL2TunnelIngress),
    /// Extended IPv4 Tunnel Egress - Format (0,1023)
    ExtendedIpv4TunnelEgress(crate::models::record_flows::ExtendedIpv4TunnelEgress),
    /// Extended IPv4 Tunnel Ingress - Format (0,1024)
    ExtendedIpv4TunnelIngress(crate::models::record_flows::ExtendedIpv4TunnelIngress),
    /// Extended IPv6 Tunnel Egress - Format (0,1025)
    ExtendedIpv6TunnelEgress(crate::models::record_flows::ExtendedIpv6TunnelEgress),
    /// Extended IPv6 Tunnel Ingress - Format (0,1026)
    ExtendedIpv6TunnelIngress(crate::models::record_flows::ExtendedIpv6TunnelIngress),
    /// Extended Decapsulate Egress - Format (0,1027)
    ExtendedDecapsulateEgress(crate::models::record_flows::ExtendedDecapsulateEgress),
    /// Extended Decapsulate Ingress - Format (0,1028)
    ExtendedDecapsulateIngress(crate::models::record_flows::ExtendedDecapsulateIngress),
    /// Extended VNI Egress - Format (0,1029)
    ExtendedVniEgress(crate::models::record_flows::ExtendedVniEgress),
    /// Extended VNI Ingress - Format (0,1030)
    ExtendedVniIngress(crate::models::record_flows::ExtendedVniIngress),
    /// Extended InfiniBand LRH - Format (0,1031)
    ExtendedInfiniBandLrh(crate::models::record_flows::ExtendedInfiniBandLrh),
    /// Extended InfiniBand GRH - Format (0,1032)
    ExtendedInfiniBandGrh(crate::models::record_flows::ExtendedInfiniBandGrh),
    /// Extended InfiniBand BTH - Format (0,1033)
    ExtendedInfiniBandBth(crate::models::record_flows::ExtendedInfiniBandBth),
    /// Extended VLAN In - Format (0,1034)
    ExtendedVlanIn(crate::models::record_flows::ExtendedVlanIn),
    /// Extended VLAN Out - Format (0,1035)
    ExtendedVlanOut(crate::models::record_flows::ExtendedVlanOut),
    /// Extended Egress Queue - Format (0,1036)
    ExtendedEgressQueue(crate::models::record_flows::ExtendedEgressQueue),
    /// Extended ACL - Format (0,1037)
    ExtendedAcl(crate::models::record_flows::ExtendedAcl),
    /// Extended Function - Format (0,1038)
    ExtendedFunction(crate::models::record_flows::ExtendedFunction),
    /// Extended Transit - Format (0,1039)
    ExtendedTransit(crate::models::record_flows::ExtendedTransit),
    /// Extended Queue - Format (0,1040)
    ExtendedQueue(crate::models::record_flows::ExtendedQueue),
    /// Extended HW Trap - Format (0,1041)
    ExtendedHwTrap(crate::models::record_flows::ExtendedHwTrap),
    /// Extended Linux Drop Reason - Format (0,1042)
    ExtendedLinuxDropReason(crate::models::record_flows::ExtendedLinuxDropReason),
    /// Transaction - Format (0,2000)
    Transaction(crate::models::record_flows::Transaction),
    /// Extended NFS Storage Transaction - Format (0,2001)
    ExtendedNfsStorageTransaction(crate::models::record_flows::ExtendedNfsStorageTransaction),
    /// Extended SCSI Storage Transaction - Format (0,2002)
    ExtendedScsiStorageTransaction(crate::models::record_flows::ExtendedScsiStorageTransaction),
    /// Extended HTTP Transaction - Format (0,2003)
    ExtendedHttpTransaction(crate::models::record_flows::ExtendedHttpTransaction),
    /// Extended Socket IPv4 - Format (0,2100)
    ExtendedSocketIpv4(crate::models::record_flows::ExtendedSocketIpv4),
    /// Extended Socket IPv6 - Format (0,2101)
    ExtendedSocketIpv6(crate::models::record_flows::ExtendedSocketIpv6),
    /// Extended Proxy Socket IPv4 - Format (0,2102)
    ExtendedProxySocketIpv4(crate::models::record_flows::ExtendedProxySocketIpv4),
    /// Extended Proxy Socket IPv6 - Format (0,2103)
    ExtendedProxySocketIpv6(crate::models::record_flows::ExtendedProxySocketIpv6),
    /// Memcache Operation - Format (0,2200)
    MemcacheOperation(crate::models::record_flows::MemcacheOperation),
    /// HTTP Request - Format (0,2201) - DEPRECATED
    HttpRequestDeprecated(crate::models::record_flows::HttpRequestDeprecated),
    /// Application Operation - Format (0,2202)
    AppOperation(crate::models::record_flows::AppOperation),
    /// Application Parent Context - Format (0,2203)
    AppParentContext(crate::models::record_flows::AppParentContext),
    /// Application Initiator - Format (0,2204)
    AppInitiator(crate::models::record_flows::AppInitiator),
    /// Application Target - Format (0,2205)
    AppTarget(crate::models::record_flows::AppTarget),
    /// HTTP Request - Format (0,2206)
    HttpRequest(crate::models::record_flows::HttpRequest),
    /// Extended Proxy Request - Format (0,2207)
    ExtendedProxyRequest(crate::models::record_flows::ExtendedProxyRequest),
    /// Extended Nav Timing - Format (0,2208)
    ExtendedNavTiming(crate::models::record_flows::ExtendedNavTiming),
    /// Extended TCP Info - Format (0,2209)
    ExtendedTcpInfo(crate::models::record_flows::ExtendedTcpInfo),
    /// Extended Entities - Format (0,2210)
    ExtendedEntities(crate::models::record_flows::ExtendedEntities),
    /// Extended BST Egress Queue - Format (4413,1)
    ExtendedBstEgressQueue(crate::models::record_flows::ExtendedBstEgressQueue),
    /// Unknown or unparsed format
    Unknown { format: DataFormat, data: Vec<u8> },
}

/// Flow record containing flow data
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FlowRecord {
    pub flow_format: DataFormat,
    pub flow_data: FlowData,
}

/// Counter data types
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CounterData {
    /// Generic Interface Counters - Format (0,1)
    GenericInterface(crate::models::record_counters::GenericInterfaceCounters),
    /// Ethernet Interface Counters - Format (0,2)
    EthernetInterface(crate::models::record_counters::EthernetInterfaceCounters),
    /// Token Ring Counters - Format (0,3)
    TokenRing(crate::models::record_counters::TokenRingCounters),
    /// 100BaseVG Counters - Format (0,4)
    Vg100Interface(crate::models::record_counters::Vg100InterfaceCounters),
    /// VLAN Counters - Format (0,5)
    Vlan(crate::models::record_counters::VlanCounters),
    /// IEEE 802.11 Counters - Format (0,6)
    Ieee80211(crate::models::record_counters::Ieee80211Counters),
    /// LAG Port Statistics - Format (0,7)
    LagPortStats(crate::models::record_counters::LagPortStats),
    /// Slow Path Counts - Format (0,8)
    SlowPathCounts(crate::models::record_counters::SlowPathCounts),
    /// InfiniBand Counters - Format (0,9)
    InfiniBandCounters(crate::models::record_counters::InfiniBandCounters),
    /// Optical SFP/QSFP Counters - Format (0,10)
    OpticalSfpQsfp(crate::models::record_counters::OpticalSfpQsfp),
    /// Processor Counters - Format (0,1001)
    Processor(crate::models::record_counters::ProcessorCounters),
    /// Radio Utilization - Format (0,1002)
    RadioUtilization(crate::models::record_counters::RadioUtilization),
    /// Queue Length - Format (0,1003)
    QueueLength(crate::models::record_counters::QueueLength),
    /// OpenFlow Port - Format (0,1004)
    OpenFlowPort(crate::models::record_counters::OpenFlowPort),
    /// OpenFlow Port Name - Format (0,1005)
    OpenFlowPortName(crate::models::record_counters::OpenFlowPortName),
    /// Host Description - Format (0,2000)
    HostDescription(crate::models::record_counters::HostDescription),
    /// Host Adapters - Format (0,2001)
    HostAdapters(crate::models::record_counters::HostAdapters),
    /// Host Parent - Format (0,2002)
    HostParent(crate::models::record_counters::HostParent),
    /// Host CPU - Format (0,2003)
    HostCpu(crate::models::record_counters::HostCpu),
    /// Host Memory - Format (0,2004)
    HostMemory(crate::models::record_counters::HostMemory),
    /// Host Disk I/O - Format (0,2005)
    HostDiskIo(crate::models::record_counters::HostDiskIo),
    /// Host Network I/O - Format (0,2006)
    HostNetIo(crate::models::record_counters::HostNetIo),
    /// MIB-2 IP Group - Format (0,2007)
    Mib2IpGroup(crate::models::record_counters::Mib2IpGroup),
    /// MIB-2 ICMP Group - Format (0,2008)
    Mib2IcmpGroup(crate::models::record_counters::Mib2IcmpGroup),
    /// MIB-2 TCP Group - Format (0,2009)
    Mib2TcpGroup(crate::models::record_counters::Mib2TcpGroup),
    /// MIB-2 UDP Group - Format (0,2010)
    Mib2UdpGroup(crate::models::record_counters::Mib2UdpGroup),
    /// Virtual Node - Format (0,2100)
    VirtualNode(crate::models::record_counters::VirtualNode),
    /// Virtual CPU - Format (0,2101)
    VirtualCpu(crate::models::record_counters::VirtualCpu),
    /// Virtual Memory - Format (0,2102)
    VirtualMemory(crate::models::record_counters::VirtualMemory),
    /// Virtual Disk I/O - Format (0,2103)
    VirtualDiskIo(crate::models::record_counters::VirtualDiskIo),
    /// Virtual Network I/O - Format (0,2104)
    VirtualNetIo(crate::models::record_counters::VirtualNetIo),
    /// JVM Runtime - Format (0,2105)
    JvmRuntime(crate::models::record_counters::JvmRuntime),
    /// JVM Statistics - Format (0,2106)
    JvmStatistics(crate::models::record_counters::JvmStatistics),
    /// Memcache Counters - Format (0,2200) - DEPRECATED
    MemcacheCountersDeprecated(crate::models::record_counters::MemcacheCountersDeprecated),
    /// HTTP Counters - Format (0,2201)
    HttpCounters(crate::models::record_counters::HttpCounters),
    /// App Operations - Format (0,2202)
    AppOperations(crate::models::record_counters::AppOperations),
    /// App Resources - Format (0,2203)
    AppResources(crate::models::record_counters::AppResources),
    /// Memcache Counters - Format (0,2204)
    MemcacheCounters(crate::models::record_counters::MemcacheCounters),
    /// App Workers - Format (0,2206)
    AppWorkers(crate::models::record_counters::AppWorkers),
    /// OVS DP Stats - Format (0,2207)
    OvsDpStats(crate::models::record_counters::OvsDpStats),
    /// Energy Consumption - Format (0,3000)
    Energy(crate::models::record_counters::Energy),
    /// Temperature - Format (0,3001)
    Temperature(crate::models::record_counters::Temperature),
    /// Humidity - Format (0,3002)
    Humidity(crate::models::record_counters::Humidity),
    /// Fans - Format (0,3003)
    Fans(crate::models::record_counters::Fans),
    /// Broadcom Device Buffer Utilization - Format (4413,1)
    BroadcomDeviceBuffers(crate::models::record_counters::BroadcomDeviceBuffers),
    /// Broadcom Port Buffer Utilization - Format (4413,2)
    BroadcomPortBuffers(crate::models::record_counters::BroadcomPortBuffers),
    /// Broadcom Switch ASIC Table Utilization - Format (4413,3)
    BroadcomTables(crate::models::record_counters::BroadcomTables),
    /// NVIDIA GPU Statistics - Format (5703,1)
    NvidiaGpu(crate::models::record_counters::NvidiaGpu),
    /// Unknown or unparsed format
    Unknown { format: DataFormat, data: Vec<u8> },
}

/// Counter record containing counter data
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CounterRecord {
    pub counter_format: DataFormat,
    pub counter_data: CounterData,
}

/// Compact flow sample - Format (0,1)
///
/// Contains sampled packet information with compact encoding for interfaces.
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Format of a single flow sample */
/// /* opaque = sample_data; enterprise = 0; format = 1 */
///
/// struct flow_sample {
///    unsigned int sequence_number;  /* Incremented with each flow sample
///                                      generated by this sFlow Instance. */
///    sflow_data_source source_id;   /* sFlowDataSource */
///    unsigned int sampling_rate;    /* sFlowPacketSamplingRate */
///    unsigned int sample_pool;      /* Total number of packets that could have been
///                                      sampled (i.e. packets skipped by sampling process
///                                      + total number of samples) */
///    unsigned int drops;            /* Number of times that the sFlow agent detected
///                                      that a packet marked to be sampled was dropped
///                                      due to lack of resources. */
///    interface input;               /* Input interface */
///    interface output;              /* Output interface */
///    flow_record flow_records<>;    /* Information about sampled packet */
/// }
/// ```
///
/// **ERRATUM:** Sequence number clarified as incremented per "sFlow Instance" instead of "source_id".
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FlowSample {
    /// Sequence number incremented with each flow sample generated by this sFlow Instance
    /// **ERRATUM:** Clarified as "sFlow Instance" instead of "source_id"
    pub sequence_number: u32,
    /// sFlow data source identifier
    pub source_id: DataSource,
    /// Sampling rate (1 in N packets)
    pub sampling_rate: u32,
    /// Total packets that could have been sampled
    pub sample_pool: u32,
    /// Number of dropped samples due to lack of resources
    pub drops: u32,
    /// Input interface
    pub input: Interface,
    /// Output interface
    pub output: Interface,
    /// Flow records describing the sampled packet
    pub flow_records: Vec<FlowRecord>,
}

/// Compact counters sample - Format (0,2)
///
/// Contains interface and system counter statistics.
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Format of a single counter sample */
/// /* opaque = sample_data; enterprise = 0; format = 2 */
///
/// struct counters_sample {
///    unsigned int sequence_number;   /* Incremented with each counter sample
///                                       generated by this sFlow Instance. */
///    sflow_data_source source_id;    /* sFlowDataSource */
///    counter_record counters<>;      /* Counters polled for this source */
/// }
/// ```
///
/// **ERRATUM:** Sequence number clarified as incremented per "sFlow Instance" instead of "source_id".
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CountersSample {
    /// Sequence number incremented with each counter sample generated by this sFlow Instance
    /// **ERRATUM:** Clarified as "sFlow Instance" instead of "source_id"
    pub sequence_number: u32,
    /// sFlow data source identifier
    pub source_id: DataSource,
    /// Counter records for this source
    pub counters: Vec<CounterRecord>,
}

/// Expanded flow sample - Format (0,3)
///
/// Flow sample with expanded encoding for large interface indices (>= 2^24).
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Format of a single expanded flow sample */
/// /* opaque = sample_data; enterprise = 0; format = 3 */
///
/// struct flow_sample_expanded {
///    unsigned int sequence_number;  /* Incremented with each flow sample
///                                      generated by this sFlow Instance. */
///    sflow_data_source_expanded source_id; /* sFlowDataSource */
///    unsigned int sampling_rate;    /* sFlowPacketSamplingRate */
///    unsigned int sample_pool;      /* Total number of packets that could have been
///                                      sampled (i.e. packets skipped by sampling process
///                                      + total number of samples) */
///    unsigned int drops;            /* Number of times that the sFlow agent detected
///                                      that a packet marked to be sampled was dropped
///                                      due to lack of resources. */
///    interface_expanded input;      /* Input interface */
///    interface_expanded output;     /* Output interface */
///    flow_record flow_records<>;    /* Information about sampled packet */
/// }
/// ```
///
/// **ERRATUM:** Sequence number clarified as incremented per "sFlow Instance" instead of "source_id".
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FlowSampleExpanded {
    /// Sequence number incremented with each flow sample generated by this sFlow Instance
    /// **ERRATUM:** Clarified as "sFlow Instance" instead of "source_id"
    pub sequence_number: u32,
    /// Expanded sFlow data source identifier
    pub source_id: DataSourceExpanded,
    /// Sampling rate (1 in N packets)
    pub sampling_rate: u32,
    /// Total packets that could have been sampled
    pub sample_pool: u32,
    /// Number of dropped samples due to lack of resources
    pub drops: u32,
    /// Input interface (expanded)
    pub input: InterfaceExpanded,
    /// Output interface (expanded)
    pub output: InterfaceExpanded,
    /// Flow records describing the sampled packet
    pub flow_records: Vec<FlowRecord>,
}

/// Expanded counter sample - Format (0,4)
///
/// Counter sample with expanded encoding for large interface indices (>= 2^24).
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Format of a single expanded counters sample */
/// /* opaque = sample_data; enterprise = 0; format = 4 */
///
/// struct counters_sample_expanded {
///    unsigned int sequence_number;   /* Incremented with each counter sample
///                                       generated by this sFlow Instance. */
///    sflow_data_source_expanded source_id; /* sFlowDataSource */
///    counter_record counters<>;      /* Counters polled for this source */
/// }
/// ```
///
/// **ERRATUM:** Sequence number clarified as incremented per "sFlow Instance" instead of "source_id".
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CountersSampleExpanded {
    /// Sequence number incremented with each counter sample generated by this sFlow Instance
    /// **ERRATUM:** Clarified as "sFlow Instance" instead of "source_id"
    pub sequence_number: u32,
    /// Expanded sFlow data source identifier
    pub source_id: DataSourceExpanded,
    /// Counter records for this source
    pub counters: Vec<CounterRecord>,
}

/// Drop reason codes for discarded packets
///
/// # XDR Definition ([sFlow Drops](https://sflow.org/sflow_drops.txt))
///
/// ```text
/// /* The drop_reason enumeration may be expanded over time.
///    sFlow collectors must be prepared to receive discard_packet
///    structures with unrecognized drop_reason values.
///
///    This document expands on the discard reason codes 0-262 defined
///    in the sFlow Version 5 [1] interface typedef and this expanded list
///    should be regarded as an expansion of the reason codes in the
///    interface typdef and are valid anywhere the typedef is referenced.
///
///    Codes 263-288 are defined in Devlink Trap [2]. Drop reason / group
///    names from the Devlink Trap document are preserved where they define
///    new reason codes, or referenced as comments where they map to existing
///    codes.
///
///    Codes 289-303 are reasons that have yet to be upstreamed to Devlink Trap,
///    but the intent is that they will eventually be upstreamed and documented as
///    part of the Linux API [2], and so they have been reserved.
///
///    The authoritative list of drop reasons will be maintained
///    at sflow.org */
///
/// enum drop_reason {
///    net_unreachable      = 0,
///    host_unreachable     = 1,
///    protocol_unreachable = 2,
///    port_unreachable     = 3,
///    frag_needed          = 4,
///    src_route_failed     = 5,
///    dst_net_unknown      = 6, /* ipv4_lpm_miss, ipv6_lpm_miss */
///    dst_host_unknown     = 7,
///    src_host_isolated    = 8,
///    dst_net_prohibited   = 9, /* reject_route */
///    dst_host_prohibited  = 10,
///    dst_net_tos_unreachable  = 11,
///    dst_host_tos_unreacheable = 12,
///    comm_admin_prohibited = 13,
///    host_precedence_violation = 14,
///    precedence_cutoff    = 15,
///    unknown              = 256,
///    ttl_exceeded         = 257, /* ttl_value_is_too_small */
///    acl                  = 258, /* ingress_flow_action_drop,
///                                   egress_flow_action_drop
///                                   group acl_drops */
///    no_buffer_space      = 259, /* tail_drop */
///    red                  = 260, /* early_drop */
///    traffic_shaping      = 261,
///    pkt_too_big          = 262, /* mtu_value_is_too_small */
///    src_mac_is_multicast = 263,
///    vlan_tag_mismatch    = 264,
///    ingress_vlan_filter  = 265,
///    ingress_spanning_tree_filter = 266,
///    port_list_is_empty   = 267,
///    port_loopback_filter = 268,
///    blackhole_route      = 269,
///    non_ip               = 270,
///    uc_dip_over_mc_dmac  = 271,
///    dip_is_loopback_address = 272,
///    sip_is_mc            = 273,
///    sip_is_loopback_address = 274,
///    ip_header_corrupted  = 275,
///    ipv4_sip_is_limited_bc = 276,
///    ipv6_mc_dip_reserved_scope = 277,
///    ipv6_mc_dip_interface_local_scope = 278,
///    unresolved_neigh     = 279,
///    mc_reverse_path_forwarding = 280,
///    non_routable_packet  = 281,
///    decap_error          = 282,
///    overlay_smac_is_mc   = 283,
///    unknown_l2           = 284, /* group l2_drops */
///    unknown_l3           = 285, /* group l3_drops */
///    unknown_l3_exception = 286, /* group l3_exceptions */
///    unknown_buffer       = 287, /* group buffer_drops */
///    unknown_tunnel       = 288, /* group tunnel_drops */
///    unknown_l4           = 289,
///    sip_is_unspecified   = 290,
///    mlag_port_isolation  = 291,
///    blackhole_arp_neigh  = 292,
///    src_mac_is_dmac      = 293,
///    dmac_is_reserved     = 294,
///    sip_is_class_e       = 295,
///    mc_dmac_mismatch     = 296,
///    sip_is_dip           = 297,
///    dip_is_local_network = 298,
///    dip_is_link_local    = 299,
///    overlay_smac_is_dmac = 300,
///    egress_vlan_filter   = 301,
///    uc_reverse_path_forwarding = 302,
///    split_horizon        = 303
/// }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum DropReason {
    NetUnreachable = 0,
    HostUnreachable = 1,
    ProtocolUnreachable = 2,
    PortUnreachable = 3,
    FragNeeded = 4,
    SrcRouteFailed = 5,
    DstNetUnknown = 6,
    DstHostUnknown = 7,
    SrcHostIsolated = 8,
    DstNetProhibited = 9,
    DstHostProhibited = 10,
    DstNetTosUnreachable = 11,
    DstHostTosUnreachable = 12,
    CommAdminProhibited = 13,
    HostPrecedenceViolation = 14,
    PrecedenceCutoff = 15,
    Unknown = 256,
    TtlExceeded = 257,
    Acl = 258,
    NoBufferSpace = 259,
    Red = 260,
    TrafficShaping = 261,
    PktTooBig = 262,
    SrcMacIsMulticast = 263,
    VlanTagMismatch = 264,
    IngressVlanFilter = 265,
    IngressSpanningTreeFilter = 266,
    PortListIsEmpty = 267,
    PortLoopbackFilter = 268,
    BlackholeRoute = 269,
    NonIp = 270,
    UcDipOverMcDmac = 271,
    DipIsLoopbackAddress = 272,
    SipIsMc = 273,
    SipIsLoopbackAddress = 274,
    IpHeaderCorrupted = 275,
    Ipv4SipIsLimitedBc = 276,
    Ipv6McDipReservedScope = 277,
    Ipv6McDipInterfaceLocalScope = 278,
    UnresolvedNeigh = 279,
    McReversePathForwarding = 280,
    NonRoutablePacket = 281,
    DecapError = 282,
    OverlaySmacIsMc = 283,
    UnknownL2 = 284,
    UnknownL3 = 285,
    UnknownL3Exception = 286,
    UnknownBuffer = 287,
    UnknownTunnel = 288,
    UnknownL4 = 289,
    SipIsUnspecified = 290,
    MlagPortIsolation = 291,
    BlackholeArpNeigh = 292,
    SrcMacIsDmac = 293,
    DmacIsReserved = 294,
    SipIsClassE = 295,
    McDmacMismatch = 296,
    SipIsDip = 297,
    DipIsLocalNetwork = 298,
    DipIsLinkLocal = 299,
    OverlaySmacIsDmac = 300,
    EgressVlanFilter = 301,
    UcReversePathForwarding = 302,
    SplitHorizon = 303,
}

impl DropReason {
    /// Convert from u32 value to DropReason enum
    ///
    /// This is a mechanical mapping of u32 values to enum variants
    /// defined in the sFlow specification. The function is tested
    /// with representative samples rather than exhaustively.
    pub fn from_u32(value: u32) -> Option<Self> {
        match value {
            0 => Some(DropReason::NetUnreachable),
            1 => Some(DropReason::HostUnreachable),
            2 => Some(DropReason::ProtocolUnreachable),
            3 => Some(DropReason::PortUnreachable),
            4 => Some(DropReason::FragNeeded),
            5 => Some(DropReason::SrcRouteFailed),
            6 => Some(DropReason::DstNetUnknown),
            7 => Some(DropReason::DstHostUnknown),
            8 => Some(DropReason::SrcHostIsolated),
            9 => Some(DropReason::DstNetProhibited),
            10 => Some(DropReason::DstHostProhibited),
            11 => Some(DropReason::DstNetTosUnreachable),
            12 => Some(DropReason::DstHostTosUnreachable),
            13 => Some(DropReason::CommAdminProhibited),
            14 => Some(DropReason::HostPrecedenceViolation),
            15 => Some(DropReason::PrecedenceCutoff),
            256 => Some(DropReason::Unknown),
            257 => Some(DropReason::TtlExceeded),
            258 => Some(DropReason::Acl),
            259 => Some(DropReason::NoBufferSpace),
            260 => Some(DropReason::Red),
            261 => Some(DropReason::TrafficShaping),
            262 => Some(DropReason::PktTooBig),
            263 => Some(DropReason::SrcMacIsMulticast),
            264 => Some(DropReason::VlanTagMismatch),
            265 => Some(DropReason::IngressVlanFilter),
            266 => Some(DropReason::IngressSpanningTreeFilter),
            267 => Some(DropReason::PortListIsEmpty),
            268 => Some(DropReason::PortLoopbackFilter),
            269 => Some(DropReason::BlackholeRoute),
            270 => Some(DropReason::NonIp),
            271 => Some(DropReason::UcDipOverMcDmac),
            272 => Some(DropReason::DipIsLoopbackAddress),
            273 => Some(DropReason::SipIsMc),
            274 => Some(DropReason::SipIsLoopbackAddress),
            275 => Some(DropReason::IpHeaderCorrupted),
            276 => Some(DropReason::Ipv4SipIsLimitedBc),
            277 => Some(DropReason::Ipv6McDipReservedScope),
            278 => Some(DropReason::Ipv6McDipInterfaceLocalScope),
            279 => Some(DropReason::UnresolvedNeigh),
            280 => Some(DropReason::McReversePathForwarding),
            281 => Some(DropReason::NonRoutablePacket),
            282 => Some(DropReason::DecapError),
            283 => Some(DropReason::OverlaySmacIsMc),
            284 => Some(DropReason::UnknownL2),
            285 => Some(DropReason::UnknownL3),
            286 => Some(DropReason::UnknownL3Exception),
            287 => Some(DropReason::UnknownBuffer),
            288 => Some(DropReason::UnknownTunnel),
            289 => Some(DropReason::UnknownL4),
            290 => Some(DropReason::SipIsUnspecified),
            291 => Some(DropReason::MlagPortIsolation),
            292 => Some(DropReason::BlackholeArpNeigh),
            293 => Some(DropReason::SrcMacIsDmac),
            294 => Some(DropReason::DmacIsReserved),
            295 => Some(DropReason::SipIsClassE),
            296 => Some(DropReason::McDmacMismatch),
            297 => Some(DropReason::SipIsDip),
            298 => Some(DropReason::DipIsLocalNetwork),
            299 => Some(DropReason::DipIsLinkLocal),
            300 => Some(DropReason::OverlaySmacIsDmac),
            301 => Some(DropReason::EgressVlanFilter),
            302 => Some(DropReason::UcReversePathForwarding),
            303 => Some(DropReason::SplitHorizon),
            _ => None,
        }
    }
}

/// Discarded packet sample - Format (0,5)
///
/// # XDR Definition ([sFlow Drops](https://sflow.org/sflow_drops.txt))
///
/// ```text
/// /* Format of a single discarded packet event */
/// /* opaque = sample_data; enterprise = 0; format = 5 */
/// struct discarded_packet {
///    unsigned int sequence_number;  /* Incremented with each discarded packet
///                                      record generated by this source_id. */
///    sflow_data_source_expanded source_id; /* sFlowDataSource */
///    unsigned int drops;            /* Number of times that the sFlow agent
///                                      detected that a discarded packet record
///                                      was dropped by the rate limit, or because
///                                      of a lack of resources. The drops counter
///                                      reports the total number of drops detected
///                                      since the agent was last reset. Note: An
///                                      agent that cannot detect drops will always
///                                      report zero. */
///    unsigned int inputifindex;     /* If set, ifIndex of interface packet was
///                                      received on. Zero if unknown. Must identify
///                                      physical port consistent with flow_sample
///                                      input interface. */
///    unsigned int outputifindex;    /* If set, ifIndex for egress drops. Zero
///                                      otherwise. Must identify physical port
///                                      consistent with flow_sample output
///                                      interface. */
///    drop_reason reason;            /* Reason for dropping packet. */
///    flow_record discard_records<>; /* Information about the discarded packet. */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DiscardedPacket {
    /// Sequence number incremented with each discarded packet record
    pub sequence_number: u32,

    /// sFlow data source
    pub source_id: DataSourceExpanded,

    /// Number of discarded packet records dropped by rate limit or lack of resources
    pub drops: u32,

    /// Input interface index (0 if unknown)
    pub input_ifindex: u32,

    /// Output interface index (0 if not egress drop)
    pub output_ifindex: u32,

    /// Reason for dropping the packet
    pub reason: DropReason,

    /// Flow records describing the discarded packet
    pub flow_records: Vec<FlowRecord>,
}

/// Sample data types
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum SampleData {
    FlowSample(FlowSample),
    CountersSample(CountersSample),
    FlowSampleExpanded(FlowSampleExpanded),
    CountersSampleExpanded(CountersSampleExpanded),
    DiscardedPacket(DiscardedPacket),
    /// sFlow-RT Custom Metrics - Format (4300,1002)
    /// Opaque data - structure defined at runtime via sFlow-RT API
    RtMetric {
        format: DataFormat,
        data: Vec<u8>,
    },
    /// sFlow-RT Custom Flow Metrics - Format (4300,1003)
    /// Opaque data - structure defined at runtime via sFlow-RT API
    RtFlow {
        format: DataFormat,
        data: Vec<u8>,
    },
    Unknown {
        format: DataFormat,
        data: Vec<u8>,
    },
}

/// Sample record
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SampleRecord {
    pub sample_type: DataFormat,
    pub sample_data: SampleData,
}

/// sFlow v5 datagram
///
/// Top-level structure containing one or more samples.
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* sFlow version 5 datagram */
///
/// struct sflow_datagram {
///    unsigned int version;        /* sFlow version (5) */
///    address agent_address;       /* IP address of sampling agent */
///    unsigned int sub_agent_id;   /* Used to distinguish multiple sFlow instances
///                                    on the same agent */
///    unsigned int sequence_number;/* Incremented with each sample datagram generated
///                                    by a sub-agent within an agent */
///    unsigned int uptime;         /* Current time (in milliseconds since device
///                                    last booted). Should be set as close to
///                                    datagram transmission time as possible. */
///    sample_record samples<>;     /* An array of sample records */
/// }
/// ```
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SFlowDatagram {
    /// sFlow protocol version (always 5)
    pub version: DatagramVersion,
    /// IP address of the sFlow agent
    pub agent_address: Address,
    /// Sub-agent identifier (distinguishes multiple sFlow instances on same agent)
    pub sub_agent_id: u32,
    /// Datagram sequence number (incremented with each datagram from this sub-agent)
    pub sequence_number: u32,
    /// Device uptime in milliseconds since last boot
    pub uptime: u32,
    /// Array of sample records
    pub samples: Vec<SampleRecord>,
}

impl SFlowDatagram {
    /// Create a new sFlow v5 datagram
    pub fn new(
        agent_address: Address,
        sub_agent_id: u32,
        sequence_number: u32,
        uptime: u32,
    ) -> Self {
        Self {
            version: DatagramVersion::Version5,
            agent_address,
            sub_agent_id,
            sequence_number,
            uptime,
            samples: Vec::new(),
        }
    }
}