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
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
//! Flow record data structures
//!
//! These represent the actual packet data captured in flow samples.
//! Enterprise = 0 (sFlow.org standard formats)

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

/// Header protocol types for sampled headers
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum HeaderProtocol {
    EthernetIso88023 = 1,
    Iso88024TokenBus = 2,
    Iso88025TokenRing = 3,
    Fddi = 4,
    FrameRelay = 5,
    X25 = 6,
    Ppp = 7,
    Smds = 8,
    Aal5 = 9,
    Aal5Ip = 10,
    Ipv4 = 11,
    Ipv6 = 12,
    Mpls = 13,
    Pos = 14,
    Ieee80211Mac = 15,
    Ieee80211Ampdu = 16,
    Ieee80211Amsdu = 17,
}

impl HeaderProtocol {
    /// Convert from u32 value to HeaderProtocol enum
    pub fn from_u32(value: u32) -> Option<Self> {
        match value {
            1 => Some(HeaderProtocol::EthernetIso88023),
            2 => Some(HeaderProtocol::Iso88024TokenBus),
            3 => Some(HeaderProtocol::Iso88025TokenRing),
            4 => Some(HeaderProtocol::Fddi),
            5 => Some(HeaderProtocol::FrameRelay),
            6 => Some(HeaderProtocol::X25),
            7 => Some(HeaderProtocol::Ppp),
            8 => Some(HeaderProtocol::Smds),
            9 => Some(HeaderProtocol::Aal5),
            10 => Some(HeaderProtocol::Aal5Ip),
            11 => Some(HeaderProtocol::Ipv4),
            12 => Some(HeaderProtocol::Ipv6),
            13 => Some(HeaderProtocol::Mpls),
            14 => Some(HeaderProtocol::Pos),
            15 => Some(HeaderProtocol::Ieee80211Mac),
            16 => Some(HeaderProtocol::Ieee80211Ampdu),
            17 => Some(HeaderProtocol::Ieee80211Amsdu),
            _ => None,
        }
    }
}

impl std::fmt::Display for HeaderProtocol {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            HeaderProtocol::EthernetIso88023 => write!(f, "Ethernet (ISO 802.3)"),
            HeaderProtocol::Iso88024TokenBus => write!(f, "ISO 802.4 Token Bus"),
            HeaderProtocol::Iso88025TokenRing => write!(f, "ISO 802.5 Token Ring"),
            HeaderProtocol::Fddi => write!(f, "FDDI"),
            HeaderProtocol::FrameRelay => write!(f, "Frame Relay"),
            HeaderProtocol::X25 => write!(f, "X.25"),
            HeaderProtocol::Ppp => write!(f, "PPP"),
            HeaderProtocol::Smds => write!(f, "SMDS"),
            HeaderProtocol::Aal5 => write!(f, "AAL5"),
            HeaderProtocol::Aal5Ip => write!(f, "AAL5 IP"),
            HeaderProtocol::Ipv4 => write!(f, "IPv4"),
            HeaderProtocol::Ipv6 => write!(f, "IPv6"),
            HeaderProtocol::Mpls => write!(f, "MPLS"),
            HeaderProtocol::Pos => write!(f, "POS"),
            HeaderProtocol::Ieee80211Mac => write!(f, "IEEE 802.11 MAC"),
            HeaderProtocol::Ieee80211Ampdu => write!(f, "IEEE 802.11 A-MPDU"),
            HeaderProtocol::Ieee80211Amsdu => write!(f, "IEEE 802.11 A-MSDU"),
        }
    }
}

/// Sampled Header - Format (0,1)
///
/// Raw packet header captured from the wire
///
/// # XDR Definition (sFlow v5)
///
/// ```text
/// /* Raw Packet Header */
/// /* opaque = flow_data; enterprise = 0; format = 1 */
///
/// struct sampled_header {
///     header_protocol protocol;  /* Format of sampled header */
///     unsigned int frame_length; /* Original length of packet before sampling */
///     unsigned int stripped;     /* Number of octets removed from packet */
///     opaque header<>;           /* Header bytes */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SampledHeader {
    /// Protocol of the sampled packet
    pub protocol: HeaderProtocol,

    /// Original length of the packet (before sampling)
    pub frame_length: u32,

    /// Number of bytes stripped from the packet before sampling
    pub stripped: u32,

    /// Raw header bytes
    pub header: Vec<u8>,
}

/// Sampled Ethernet Frame - Format (0,2)
///
/// Ethernet frame header information
///
/// # XDR Definition (sFlow v5)
///
/// ```text
/// /* Ethernet Frame Data */
/// /* opaque = flow_data; enterprise = 0; format = 2 */
///
/// struct sampled_ethernet {
///     unsigned int length;   /* The length of the MAC packet received on the
///                               network, excluding lower layer encapsulations
///                               and framing bits but including FCS octets */
///     mac src_mac;           /* Source MAC address */
///     mac dst_mac;           /* Destination MAC address */
///     unsigned int type;     /* Ethernet packet type */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SampledEthernet {
    /// Length of MAC packet in bytes
    pub length: u32,

    /// Source MAC address
    pub src_mac: crate::models::MacAddress,

    /// Destination MAC address
    pub dst_mac: crate::models::MacAddress,

    /// Ethernet type (spec: type)
    pub eth_type: u32,
}

/// Sampled IPv4 - Format (0,3)
///
/// IPv4 packet header information
///
/// # XDR Definition (sFlow v5)
///
/// ```text
/// /* Packet IP version 4 data */
/// /* opaque = flow_data; enterprise = 0; format = 3 */
///
/// struct sampled_ipv4 {
///     unsigned int length;     /* Length of IP packet excluding lower layer encapsulations */
///     unsigned int protocol;   /* IP Protocol type (e.g., TCP = 6, UDP = 17) */
///     ip_v4 src_ip;            /* Source IP Address */
///     ip_v4 dst_ip;            /* Destination IP Address */
///     unsigned int src_port;   /* TCP/UDP source port number or equivalent */
///     unsigned int dst_port;   /* TCP/UDP destination port number or equivalent */
///     unsigned int tcp_flags;  /* TCP flags */
///     unsigned int tos;        /* IP type of service */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SampledIpv4 {
    /// Length of IP packet in bytes
    pub length: u32,

    /// IP Protocol (TCP=6, UDP=17, etc.)
    pub protocol: u32,

    /// Source IP address
    pub src_ip: Ipv4Addr,

    /// Destination IP address
    pub dst_ip: Ipv4Addr,

    /// Source port (for TCP/UDP)
    pub src_port: u32,

    /// Destination port (for TCP/UDP)
    pub dst_port: u32,

    /// TCP flags
    pub tcp_flags: u32,

    /// Type of Service
    pub tos: u32,
}

/// Sampled IPv6 - Format (0,4)
///
/// IPv6 packet header information
///
/// # XDR Definition (sFlow v5)
///
/// ```text
/// /* Packet IP Version 6 Data */
/// /* opaque = flow_data; enterprise = 0; format = 4 */
///
/// struct sampled_ipv6 {
///     unsigned int length;     /* Length of IP packet excluding lower layer encapsulations */
///     unsigned int protocol;   /* IP next header (e.g., TCP = 6, UDP = 17) */
///     ip_v6 src_ip;            /* Source IP Address */
///     ip_v6 dst_ip;            /* Destination IP Address */
///     unsigned int src_port;   /* TCP/UDP source port number or equivalent */
///     unsigned int dst_port;   /* TCP/UDP destination port number or equivalent */
///     unsigned int tcp_flags;  /* TCP flags */
///     unsigned int priority;   /* IP priority */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SampledIpv6 {
    /// Length of IP packet in bytes
    pub length: u32,

    /// IP Protocol (TCP=6, UDP=17, etc.)
    pub protocol: u32,

    /// Source IP address
    pub src_ip: Ipv6Addr,

    /// Destination IP address
    pub dst_ip: Ipv6Addr,

    /// Source port (for TCP/UDP)
    pub src_port: u32,

    /// Destination port (for TCP/UDP)
    pub dst_port: u32,

    /// TCP flags
    pub tcp_flags: u32,

    /// Priority (traffic class)
    pub priority: u32,
}

/// Extended Switch Data - Format (0,1001)
///
/// Layer 2 switching information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended Switch Data */
/// /* opaque = flow_data; enterprise = 0; format = 1001 */
///
/// struct extended_switch {
///     unsigned int src_vlan;     /* The 802.1Q VLAN id of incoming frame,
///                                   0xffffffff if unknown */
///     unsigned int src_priority; /* The 802.1p priority of incoming frame,
///                                   0xffffffff if unknown */
///     unsigned int dst_vlan;     /* The 802.1Q VLAN id of outgoing frame,
///                                   0xffffffff if unknown */
///     unsigned int dst_priority; /* The 802.1p priority of outgoing frame,
///                                   0xffffffff if unknown */
/// }
/// ```
///
/// **ERRATUM:** The specification was updated to clarify that 0xffffffff indicates unknown values.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedSwitch {
    /// Source VLAN ID
    /// **ERRATUM:** 0xffffffff if unknown
    pub src_vlan: u32,

    /// Source priority (802.1p)
    /// **ERRATUM:** 0xffffffff if unknown
    pub src_priority: u32,

    /// Destination VLAN ID
    /// **ERRATUM:** 0xffffffff if unknown
    pub dst_vlan: u32,

    /// Destination priority (802.1p)
    /// **ERRATUM:** 0xffffffff if unknown
    pub dst_priority: u32,
}

/// Extended Router Data - Format (0,1002)
///
/// Layer 3 routing information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended Router Data */
/// /* opaque = flow_data; enterprise = 0; format = 1002 */
///
/// struct extended_router {
///     next_hop nexthop;          /* IP address of immediate next hop router */
///     unsigned int src_mask_len; /* Source address prefix mask (number of bits) */
///     unsigned int dst_mask_len; /* Destination address prefix mask (number of bits) */
/// }
/// ```
///
/// **ERRATUM:** The specification was clarified to specify "immediate" next hop router.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedRouter {
    /// IP address of immediate next hop router (spec: nexthop)
    /// **ERRATUM:** Clarified as "immediate" next hop router
    pub next_hop: crate::models::core::Address,

    /// Source subnet mask bits
    pub src_mask_len: u32,

    /// Destination subnet mask bits
    pub dst_mask_len: u32,
}

/// AS Path Type
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum AsPathType {
    AsSet = 1,
    AsSequence = 2,
}

impl From<u32> for AsPathType {
    fn from(value: u32) -> Self {
        match value {
            1 => AsPathType::AsSet,
            2 => AsPathType::AsSequence,
            _ => AsPathType::AsSet,
        }
    }
}

/// AS Path Segment
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AsPathSegment {
    pub path_type: AsPathType,
    pub path_length: u32,
    pub path: Vec<u32>,
}

/// Extended Gateway Data - Format (0,1003)
///
/// BGP routing information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended Gateway Data */
/// /* opaque = flow_data; enterprise = 0; format = 1003 */
///
/// struct extended_gateway {
///     next_hop nexthop;           /* Address of the border router */
///     unsigned int as;            /* Autonomous system number of router */
///     unsigned int src_as;        /* Autonomous system number of source */
///     unsigned int src_peer_as;   /* Autonomous system number of source peer */
///     as_path_type dst_as_path<>; /* AS path to the destination */
///     unsigned int communities<>; /* Communities associated with this route */
///     unsigned int localpref;     /* LocalPref associated with this route */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedGateway {
    /// IP address of the border router (spec: nexthop)
    pub next_hop: crate::models::core::Address,

    /// Autonomous system number (spec: as)
    pub as_number: u32,

    /// Source AS
    pub src_as: u32,

    /// Source peer AS
    pub src_peer_as: u32,

    /// Autonomous system path to the destination
    pub dst_as_path: Vec<AsPathSegment>,

    /// Communities associated with this route
    pub communities: Vec<u32>,

    /// Local preference (spec: localpref)
    pub local_pref: u32,
}

/// Extended User Data - Format (0,1004)
///
/// Application-level user information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended User Data */
/// /* opaque = flow_data; enterprise = 0; format = 1004 */
///
/// struct extended_user {
///     charset src_charset;   /* Character set for src_user */
///     opaque src_user<>;     /* User ID associated with packet source */
///     charset dst_charset;   /* Character set for dst_user */
///     opaque dst_user<>;     /* User ID associated with packet destination */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedUser {
    /// Source character set (MIBEnum)
    pub src_charset: u32,

    /// Source user ID
    pub src_user: String,

    /// Destination character set (MIBEnum)
    pub dst_charset: u32,

    /// Destination user ID
    pub dst_user: String,
}

/// URL Direction
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum UrlDirection {
    Source = 1,
    Destination = 2,
}

impl From<u32> for UrlDirection {
    fn from(value: u32) -> Self {
        match value {
            1 => UrlDirection::Source,
            2 => UrlDirection::Destination,
            _ => UrlDirection::Source,
        }
    }
}

/// Extended URL Data - Format (0,1005) - **DEPRECATED**
///
/// HTTP request information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended URL Data */
/// /* opaque = flow_data; enterprise = 0; format = 1005 */
///
/// struct extended_url {
///     url_direction direction; /* Direction of connection */
///     string url<>;            /* The HTTP request-line (see RFC 2616) */
///     string host<>;           /* The host field from the HTTP header */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedUrl {
    /// Direction (source or destination)
    pub direction: UrlDirection,

    /// URL string (HTTP request-line)
    pub url: String,

    /// Host header from HTTP request
    pub host: String,
}

/// Extended MPLS Data - Format (0,1006)
///
/// MPLS label stack information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended MPLS Data */
/// /* opaque = flow_data; enterprise = 0; format = 1006 */
///
/// struct extended_mpls {
///     next_hop nexthop;     /* Address of the next hop */
///     label_stack in_stack; /* Label stack of received packet */
///     label_stack out_stack;/* Label stack for transmitted packet */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedMpls {
    /// Next hop address (spec: nexthop)
    pub next_hop: crate::models::core::Address,

    /// Input label stack
    pub in_stack: Vec<u32>,

    /// Output label stack
    pub out_stack: Vec<u32>,
}

/// Extended NAT Data - Format (0,1007)
///
/// Network Address Translation information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended NAT Data */
/// /* opaque = flow_data; enterprise = 0; format = 1007 */
///
/// struct extended_nat {
///     address src_address; /* Source address */
///     address dst_address; /* Destination address */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedNat {
    /// Source address type
    pub src_address: crate::models::core::Address,

    /// Destination address type
    pub dst_address: crate::models::core::Address,
}

/// Extended MPLS Tunnel - Format (0,1008)
///
/// MPLS tunnel information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended MPLS Tunnel */
/// /* opaque = flow_data; enterprise = 0; format = 1008 */
///
/// struct extended_mpls_tunnel {
///     string tunnel_lsp_name<>; /* Tunnel name */
///     unsigned int tunnel_id;   /* Tunnel ID */
///     unsigned int tunnel_cos;  /* Tunnel COS value */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedMplsTunnel {
    /// Tunnel LSP name
    pub tunnel_lsp_name: String,

    /// Tunnel ID
    pub tunnel_id: u32,

    /// Tunnel COS value
    pub tunnel_cos: u32,
}

/// Extended MPLS VC - Format (0,1009)
///
/// MPLS Virtual Circuit information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended MPLS VC */
/// /* opaque = flow_data; enterprise = 0; format = 1009 */
///
/// struct extended_mpls_vc {
///     string vc_instance_name<>; /* VC instance name */
///     unsigned int vll_vc_id;    /* VLL/VC instance ID */
///     unsigned int vc_label_cos; /* VC Label COS value */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedMplsVc {
    /// VC instance name
    pub vc_instance_name: String,

    /// VC ID
    pub vll_vc_id: u32,

    /// VC label
    pub vc_label: u32,

    /// VC COS
    pub vc_cos: u32,
}

/// Extended MPLS FEC - Format (0,1010)
///
/// MPLS Forwarding Equivalence Class information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended MPLS FEC */
/// /* opaque = flow_data; enterprise = 0; format = 1010 */
///
/// struct extended_mpls_FTN {
///     string mplsFTNDescr<>;  /* FEC description */
///     unsigned int mplsFTNMask; /* FEC mask */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedMplsFec {
    /// FEC address prefix
    pub fec_addr_prefix: crate::models::core::Address,

    /// FEC prefix length
    pub fec_prefix_len: u32,
}

/// Extended MPLS LVP FEC - Format (0,1011)
///
/// MPLS LDP FEC information
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended MPLS LVP FEC */
/// /* opaque = flow_data; enterprise = 0; format = 1011 */
///
/// struct extended_mpls_LDP_FEC {
///     unsigned int mplsFecAddrPrefixLength; /* FEC address prefix length */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedMplsLvpFec {
    /// FEC address prefix length
    pub mpls_fec_addr_prefix_length: u32,
}

/// Extended VLAN Tunnel - Format (0,1012)
///
/// VLAN tunnel information for nested VLAN tags
///
/// # XDR Definition ([sFlow v5](https://sflow.org/sflow_version_5.txt))
///
/// ```text
/// /* Extended VLAN tunnel information */
/// /* opaque = flow_data; enterprise = 0; format = 1012 */
///
/// struct extended_vlantunnel {
///     unsigned int stack<>; /* List of stripped 802.1Q TPID/TCI layers */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedVlanTunnel {
    /// List of stripped 802.1Q TPID/TCI layers
    pub stack: Vec<u32>,
}

/// Extended 802.11 Payload - Format (0,1013)
///
/// Unencrypted 802.11 payload data
///
/// # XDR Definition ([sFlow 802.11](https://sflow.org/sflow_80211.txt))
///
/// ```text
/// /* Extended 80211 Payload */
/// /* opaque = flow_data; enterprise = 0; format = 1013 */
///
/// struct extended_80211_payload {
///     cipher_suite ciphersuite; /* encryption scheme used for this packet */
///     opaque data<>;            /* unencrypted bytes from the payload */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Extended80211Payload {
    /// Cipher suite (OUI + Suite Type) (spec: ciphersuite)
    pub cipher_suite: u32,

    /// Unencrypted payload data
    pub data: Vec<u8>,
}

/// Extended 802.11 RX - Format (0,1014)
///
/// 802.11 receive information
///
/// # XDR Definition ([sFlow 802.11](https://sflow.org/sflow_80211.txt))
///
/// ```text
/// /* Extended 802.11 RX */
/// /* opaque = flow_data; enterprise = 0; format = 1014 */
///
/// struct extended_80211_rx {
///     string ssid<32>;             /* SSID string */
///     mac bssid;                   /* BSSID */
///     ieee80211_version version;   /* version */
///     unsigned int channel;        /* channel number */
///     unsigned hyper speed;        /* speed */
///     unsigned int rsni;           /* received signal to noise ratio */
///     unsigned int rcpi;           /* received channel power */
///     duration_us packet_duration; /* time packet occupied RF medium */
/// }
/// ```
///
/// **ERRATUM:** The specification is missing a semicolon after `packet_duration`,
/// violating RFC 4506 XDR syntax requirements. The corrected version is shown above.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Extended80211Rx {
    /// SSID string (max 32 bytes)
    pub ssid: String,

    /// BSSID (MAC address)
    pub bssid: crate::models::MacAddress,

    /// IEEE 802.11 version (a=1, b=2, g=3, n=4)
    pub version: u32,

    /// Channel number
    pub channel: u32,

    /// Speed in bits per second
    pub speed: u64,

    /// Received signal to noise ratio (RSNI)
    pub rsni: u32,

    /// Received channel power indicator (RCPI)
    pub rcpi: u32,

    /// Packet duration in microseconds
    pub packet_duration: u32,
}

/// Extended 802.11 TX - Format (0,1015)
///
/// 802.11 transmit information
///
/// # XDR Definition ([sFlow 802.11](https://sflow.org/sflow_80211.txt))
///
/// ```text
/// /* Extended 802.11 TX */
/// /* opaque = flow_data; enterprise = 0; format = 1015 */
///
/// struct extended_80211_tx {
///     string ssid<32>;             /* SSID string */
///     mac bssid;                   /* BSSID */
///     ieee80211_version version;   /* version */
///     unsigned int transmissions;  /* number of transmissions */
///     duration_us packet_duration; /* time packet occupied RF medium */
///     duration_us retrans_duration;/* time failed attempts occupied RF */
///     unsigned int channel;        /* channel number */
///     unsigned hyper speed;        /* speed */
///     unsigned int power;          /* transmit power in mW */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Extended80211Tx {
    /// SSID string (max 32 bytes)
    pub ssid: String,

    /// BSSID (MAC address)
    pub bssid: crate::models::MacAddress,

    /// IEEE 802.11 version (a=1, b=2, g=3, n=4)
    pub version: u32,

    /// Number of transmissions (0=unknown, 1=success on first attempt, n>1 = n-1 retransmissions)
    pub transmissions: u32,

    /// Packet duration in microseconds (successful transmission)
    pub packet_duration: u32,

    /// Retransmission duration in microseconds (failed attempts)
    pub retrans_duration: u32,

    /// Channel number
    pub channel: u32,

    /// Speed in bits per second
    pub speed: u64,

    /// Transmit power in milliwatts
    pub power: u32,
}

/// PDU (Protocol Data Unit) in 802.11 aggregation
///
/// # XDR Definition ([sFlow 802.11](https://sflow.org/sflow_80211.txt))
///
/// ```text
/// struct pdu {
///     flow_record flow_records<>;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Pdu {
    /// Flow records for this PDU
    pub flow_records: Vec<crate::models::FlowRecord>,
}

/// Extended 802.11 Aggregation - Format (0,1016)
///
/// 802.11 frame aggregation information
///
/// # XDR Definition ([sFlow 802.11](https://sflow.org/sflow_80211.txt))
///
/// ```text
/// /* Extended 802.11 Aggregation Data */
/// /* opaque = flow_data; enterprise = 0; format = 1016 */
///
/// struct extended_80211_aggregation {
///     pdu pdus<>; /* Array of PDUs in the aggregation */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Extended80211Aggregation {
    /// Array of PDUs in the aggregation
    pub pdus: Vec<Pdu>,
}

/// Extended OpenFlow v1 - Format (0,1017) - **DEPRECATED**
///
/// OpenFlow 1.0 forwarding information
///
/// **Note:** This format was defined in an early draft of the sFlow OpenFlow specification
/// but was deprecated and removed from the final specification. It is included here for
/// backward compatibility with legacy implementations.
///
/// # XDR Definition ([sFlow OpenFlow Draft](https://sflow.org/draft-sflow-openflow.txt))
///
/// ```text
/// /* Extended OpenFlow 1.0 Data */
/// /* opaque = flow_data; enterprise = 0; format = 1017 */
///
/// struct extended_openflow_v1 {
///     unsigned hyper flow_cookie;  /* Flow cookie set by controller */
///     wildcards flow_match;        /* Bit array of wildcarded fields */
///     actions flow_actions;        /* Bit array of actions applied */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedOpenFlowV1 {
    /// Flow cookie set by the OpenFlow controller
    pub flow_cookie: u64,

    /// Bit array describing the fields in the packet header that are used to form the flow key
    /// See OpenFlow 1.0 ofp_match for the definition of wildcards
    pub flow_match: u32,

    /// Bit array describing fields that may have been altered by the flow action
    /// The ofp_action_type enum is used to determine the bit positions
    pub flow_actions: u32,
}

/// Extended Fiber Channel Routing Entry - Format (0,1018)
///
/// Fiber Channel routing information
///
/// # XDR Definition (RFC 4625)
///
/// ```text
/// /* Extended Fiber Channel Routing Entry */
/// /* opaque = flow_data; enterprise = 0; format = 1018 */
/// /* See RFC 4625 */
/// typedef unsigned int fc_address; /* 24 bit fiber channel address,
///                                     most significant byte = 0 */
/// struct extended_fc {
///  unsigned int src_mask_len; /* Source FC address mask,
///                                 see t11FcRouteSrcMask
///                                (expressed in number of bits) */
///  unsigned int dst_mask_len; /* Destination FC address mask,
///                                 see t11FcRouteDestMask
///                                (expressed in number of bits) */
///   fc_address next_hop; /* Next hop FC switch
///                                 see t11FcRouteDomainId */
///   unsigned int metric; /* most significant byte,
///                                 most significant bit = t11FcRouteType
///                                 least significant 7 bits = t11FcRouteProto,
///                                 least significant 3 bytes = t11FcRouteMetric
///                              */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedFc {
    /// Source FC address mask (number of bits)
    pub src_mask_len: u32,

    /// Destination FC address mask (number of bits)
    pub dst_mask_len: u32,

    /// Next hop FC switch (24-bit fiber channel address)
    pub next_hop: u32,

    /// Metric containing route type, protocol, and metric value
    /// - Most significant byte, most significant bit: t11FcRouteType
    /// - Most significant byte, least significant 7 bits: t11FcRouteProto
    /// - Least significant 3 bytes: t11FcRouteMetric
    pub metric: u32,
}

/// Extended Queue Length - Format (0,1019)
///
/// Queue length experienced by the sampled packet
///
/// # XDR Definition ([sFlow Discussion](http://groups.google.com/group/sflow/browse_thread/thread/773d27b17a81600c))
///
/// ```text
/// /* Extended queue length data
///    Used to indicate the queue length experienced by the sampled packet.
///    If the extended_queue_length record is exported, queue_length counter
///    records must also be exported with the if_counter record.*/
///
/// /* opaque = flow_data; enterprise = 0; format = 1019 */
///
/// struct extended_queue_length
/// {
///     unsigned int queueIndex; /* persistent index within port of queue
///                                 used to enqueue sampled packet.
///                                 The ifIndex of the port can be inferred
///                                 from the data source. */
///     unsigned int queueLength; /* length of queue, in segments,
///                                  experienced by the packet (ie queue length
///                                  immediately before the sampled packet is
///                                  enqueued). */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedQueueLength {
    /// Persistent index within port of queue used to enqueue sampled packet
    pub queue_index: u32,

    /// Length of queue, in segments, experienced by the packet
    /// (queue length immediately before the sampled packet is enqueued)
    pub queue_length: u32,
}

/// Extended NAT Port Data - Format (0,1020)
///
/// Layer 4 port translation information for NAT
///
/// # XDR Definition ([sFlow Port NAT](https://sflow.org/sflow_pnat.txt))
///
/// ```text
/// /* Extended NAT L4 Port Data
///    Packet header reports ports as seen at the sFlowDataSource.
///    The extended_nat_port structure reports on translated source and/or
///    destination layer 4 (TCP/UDP) ports for this packet. If port was not
///    translated it should be equal to that reported for the header. */
/// /* opaque = flow_data; enterprise = 0; format = 1020 */
///
/// struct extended_nat_port {
///      unsigned int src_port;            /* Source port */
///      unsigned int dst_port;            /* Destination port */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedNatPort {
    /// Translated source port
    pub src_port: u32,

    /// Translated destination port
    pub dst_port: u32,
}

/// Extended L2 Tunnel Egress - Format (0,1021)
///
/// Layer 2 tunnel egress information - reports outer Ethernet headers
/// that will be added on egress when encapsulating packets
///
/// # XDR Definition ([sFlow Tunnels](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1021 */
/// struct extended_L2_tunnel_egress {
///     sampled_ethernet header;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedL2TunnelEgress {
    /// Outer Ethernet header that will be added on egress
    pub header: SampledEthernet,
}

/// Extended L2 Tunnel Ingress - Format (0,1022)
///
/// Layer 2 tunnel ingress information - reports outer Ethernet headers
/// that were present on ingress and removed during decapsulation
///
/// # XDR Definition ([sFlow Tunnels](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1022 */
/// struct extended_L2_tunnel_ingress {
///     sampled_ethernet header;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedL2TunnelIngress {
    /// Outer Ethernet header that was present on ingress
    pub header: SampledEthernet,
}

/// Extended IPv4 Tunnel Egress - Format (0,1023)
///
/// IPv4 tunnel egress information - reports outer IPv4 headers
/// that will be added on egress when encapsulating packets
///
/// # XDR Definition ([sFlow Tunnels](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1023 */
/// struct extended_ipv4_tunnel_egress {
///     sampled_ipv4 header;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedIpv4TunnelEgress {
    /// Outer IPv4 header that will be added on egress
    pub header: SampledIpv4,
}

/// Extended IPv4 Tunnel Ingress - Format (0,1024)
///
/// IPv4 tunnel ingress information - reports outer IPv4 headers
/// that were present on ingress and removed during decapsulation
///
/// # XDR Definition ([sFlow Tunnels](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1024 */
/// struct extended_ipv4_tunnel_ingress {
///     sampled_ipv4 header;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedIpv4TunnelIngress {
    /// Outer IPv4 header that was present on ingress
    pub header: SampledIpv4,
}

/// Extended IPv6 Tunnel Egress - Format (0,1025)
///
/// IPv6 tunnel egress information - reports outer IPv6 headers
/// that will be added on egress when encapsulating packets
///
/// # XDR Definition ([sFlow Tunnels](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1025 */
/// struct extended_ipv6_tunnel_egress {
///     sampled_ipv6 header;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedIpv6TunnelEgress {
    /// Outer IPv6 header that will be added on egress
    pub header: SampledIpv6,
}

/// Extended IPv6 Tunnel Ingress - Format (0,1026)
///
/// IPv6 tunnel ingress information - reports outer IPv6 headers
/// that were present on ingress and removed during decapsulation
///
/// # XDR Definition ([sFlow Tunnels](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1026 */
/// struct extended_ipv6_tunnel_ingress {
///     sampled_ipv6 header;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedIpv6TunnelIngress {
    /// Outer IPv6 header that was present on ingress
    pub header: SampledIpv6,
}

/// Extended Decapsulate Egress - Format (0,1027)
///
/// Indicates the end of a tunnel and points to the start of the inner header
/// Used when a packet is sampled before decapsulation on ingress
///
/// # XDR Definition ([sFlow Tunnels](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1027 */
/// struct extended_decapsulate_egress {
///     unsigned int inner_header_offset;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedDecapsulateEgress {
    /// Offset in bytes to the inner header within the sampled packet header
    pub inner_header_offset: u32,
}

/// Extended Decapsulate Ingress - Format (0,1028)
///
/// Indicates the start of a tunnel
/// Used when a packet is sampled after encapsulation on egress
///
/// # XDR Definition ([sFlow Tunnels](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1028 */
/// struct extended_decapsulate_ingress {
///     unsigned int inner_header_offset;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedDecapsulateIngress {
    /// Offset in bytes to the inner header within the sampled packet header
    pub inner_header_offset: u32,
}

/// Extended VNI Egress - Format (0,1029)
///
/// Virtual Network Identifier for egress traffic
/// The VNI may be explicitly included in the tunneling protocol or implicit
///
/// # XDR Definition ([sFlow Tunnels](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* opaque_flow_data; enterprise = 0; format = 1029 */
/// struct extended_vni_egress {
///     unsigned int vni;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedVniEgress {
    /// Virtual Network Identifier
    pub vni: u32,
}

/// Extended VNI Ingress - Format (0,1030)
///
/// Virtual Network Identifier for ingress traffic
/// The VNI may be explicitly included in the tunneling protocol or implicit
/// in the encapsulation (e.g., VXLAN uses UDP port 4789).
///
/// # XDR Definition ([sFlow Tunnel](https://sflow.org/sflow_tunnels.txt))
///
/// ```text
/// /* VNI ingress */
/// /* opaque = flow_data; enterprise = 0; format = 1030 */
///
/// struct extended_vni_ingress {
///     unsigned int vni;  /* VNI associated with ingress packet */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedVniIngress {
    /// Virtual Network Identifier
    pub vni: u32,
}

/// Extended InfiniBand LRH - Format (0,1031)
///
/// InfiniBand Local Routing Header information
///
/// # XDR Definition ([sFlow InfiniBand](https://sflow.org/draft_sflow_infiniband_2.txt))
///
/// ```text
/// /* Extended IB LRH Data
///    - Local Routing Header definition from InfiniBand Architecture
///      Specification */
///
/// /* opaque = flow_data; enterprise = 0; format = 1031 */
///
/// struct extended_ib_lrh {
///    unsigned int src_vl;       /* source virtual lane               */
///    unsigned int src_sl;       /* source service level              */
///    unsigned int src_dlid;     /* source destination-local-ID       */
///    unsigned int src_slid;     /* source source-local-ID            */
///    unsigned int src_lnh;      /* source link next header           */
///    unsigned int dst_vl;       /* Destination virtual lane          */
///    unsigned int dst_sl;       /* Destination service level         */
///    unsigned int dst_dlid;     /* Destination destination-local-ID  */
///    unsigned int dst_slid;     /* Destination source-local-ID       */
///    unsigned int dst_lnh;      /* Destination link next header      */
/// }
/// ```
///
/// **ERRATUM:** The specification uses non-standard data type `ib_lrh_data` instead of `flow_data`.
/// The corrected version is shown above.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedInfiniBandLrh {
    /// Source virtual lane
    pub src_vl: u32,
    /// Source service level
    pub src_sl: u32,
    /// Source destination-local-ID
    pub src_dlid: u32,
    /// Source source-local-ID
    pub src_slid: u32,
    /// Source link next header
    pub src_lnh: u32,
    /// Destination virtual lane
    pub dst_vl: u32,
    /// Destination service level
    pub dst_sl: u32,
    /// Destination destination-local-ID
    pub dst_dlid: u32,
    /// Destination source-local-ID
    pub dst_slid: u32,
    /// Destination link next header
    pub dst_lnh: u32,
}

/// Extended InfiniBand GRH - Format (0,1032)
///
/// InfiniBand Global Routing Header information
///
/// # XDR Definition ([sFlow InfiniBand](https://sflow.org/draft_sflow_infiniband_2.txt))
///
/// ```text
/// /* GID type  16 bytes long */
/// typedef opaque gid[16];
///
/// /* Extended IB GRH Data
///    - Global Routing Header definition from InfiniBand Architecture
///      Specification */
///
/// /* opaque = flow_data; enterprise = 0; format = 1032 */
///
/// struct extended_ib_grh {
///    unsigned int flow_label; /* flow label          */
///    unsigned int tc;         /* Traffic Class       */
///    gid s_gid;               /* source GID          */
///    gid d_gid;               /* destination GID     */
///    unsigned int next_header; /* next header type    */
///    unsigned int length;      /* payload length      */
/// }
/// ```
///
/// **ERRATUM:** The specification is missing semicolons after `next_header` and `length`,
/// violating RFC 4506 XDR syntax requirements. Additionally, the specification uses
/// non-standard data type `ib_grh_data` instead of `flow_data`. The corrected version is shown above.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedInfiniBandGrh {
    /// Flow label
    pub flow_label: u32,
    /// Traffic class
    pub tc: u32,
    /// Source GID (16 bytes)
    pub s_gid: [u8; 16],
    /// Destination GID (16 bytes)
    pub d_gid: [u8; 16],
    /// Next header type
    pub next_header: u32,
    /// Payload length
    pub length: u32,
}

/// Extended InfiniBand BTH - Format (0,1033)
///
/// InfiniBand Base Transport Header information
///
/// # XDR Definition ([sFlow InfiniBand](https://sflow.org/draft_sflow_infiniband_2.txt))
///
/// ```text
/// /* Extended IB BTH Data
///    - Base Transport Header definition from InfiniBand Architecture
///      Specification */
///
/// /* opaque = flow_data; enterprise = 0; format = 1033 */
///
/// struct extended_ib_bth {
///    unsigned int pkey;   /* Partition key                */
///    unsigned int dst_qp; /* Destination Queue Pair       */
///    unsigned int opcode; /* IBA packet type              */
/// }
/// ```
///
/// **ERRATUM:** The specification uses non-standard data type `ib_bth_data` instead of `flow_data`.
/// The corrected version is shown above.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedInfiniBandBth {
    /// Partition key
    pub pkey: u32,
    /// Destination Queue Pair
    pub dst_qp: u32,
    /// IBA packet type (opcode)
    pub opcode: u32,
}

/// Extended VLAN In - Format (0,1034)
///
/// Ingress 802.1Q VLAN tag information
///
/// # XDR Definition ([sFlow Discussion](https://sflow.org/discussion/sflow-discussion/0199.html))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1034 */
/// extended_vlanin {
///   unsigned int stack<>;  /* List of ingress 802.1Q TPID/TCI layers. Each
///                             TPID,TCI pair is represented as a single 32 bit
///                             integer. Layers listed from outermost to
///                             innermost. */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedVlanIn {
    /// List of ingress 802.1Q TPID/TCI layers
    /// Each TPID,TCI pair is represented as a single 32-bit integer
    /// Layers listed from outermost to innermost
    pub stack: Vec<u32>,
}

/// Extended VLAN Out - Format (0,1035)
///
/// Egress 802.1Q VLAN tag information
///
/// # XDR Definition ([sFlow Discussion](https://sflow.org/discussion/sflow-discussion/0199.html))
///
/// ```text
/// /* opaque = flow_data; enterprise = 0; format = 1035 */
/// extended_vlanout {
///   unsigned int stack<>;  /* List of egress 802.1Q TPID/TCI layers. Each
///                             TPID,TCI pair is represented as a single 32 bit
///                             integer. Layers listed from outermost to
///                             innermost. */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedVlanOut {
    /// List of egress 802.1Q TPID/TCI layers
    /// Each TPID,TCI pair is represented as a single 32-bit integer
    /// Layers listed from outermost to innermost
    pub stack: Vec<u32>,
}

/// Extended Egress Queue - Format (0,1036)
///
/// Selected egress queue for the sampled packet
///
/// # XDR Definition ([sFlow Drops](https://sflow.org/sflow_drops.txt))
///
/// ```text
/// /* Selected egress queue */
/// /* Output port number must be provided in enclosing structure */
/// /* opaque = flow_data; enterprise = 0; format = 1036 */
/// struct extended_egress_queue {
///   unsigned int queue;  /* eqress queue number selected for sampled packet */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedEgressQueue {
    /// Egress queue number selected for sampled packet
    pub queue: u32,
}

/// Extended ACL - Format (0,1037)
///
/// ACL information about the rule that matched this packet
///
/// # XDR Definition ([sFlow Drops](https://sflow.org/sflow_drops.txt))
///
/// ```text
/// /* ACL information */
/// /* Information about ACL rule that matched this packet
/// /* opaque = flow_data; enterprise = 0; format = 1037 */
/// struct extended_acl {
///   unsigned int number; /* access list number */
///   string name<>; /* access list name */
///   unsigned int direction; /* unknown = 0, ingress = 1, egress = 2 */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedAcl {
    /// Access list number
    pub number: u32,

    /// Access list name
    pub name: String,

    /// Direction: unknown = 0, ingress = 1, egress = 2
    pub direction: u32,
}

/// Extended Function - Format (0,1038)
///
/// Name of the function in software network stack that discarded the packet
///
/// # XDR Definition ([sFlow Drops](https://sflow.org/sflow_drops.txt))
///
/// ```text
/// /* Software function */
/// /* Name of the function in software network stack that discarded the packet */
/// /* opaque = flow_data; enterprise = 0; format = 1038 */
/// struct extended_function {
///   string symbol<>;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedFunction {
    /// Function symbol name
    pub symbol: String,
}

/// Extended Transit - Format (0,1039)
///
/// Delay for sampled packet traversing switch
///
/// # XDR Definition ([sFlow Transit](https://sflow.org/sflow_transit.txt))
///
/// ```text
/// /* Delay for sampled packet traversing switch */
/// /* opaque = flow_data; enterprise = 0; format = 1039 */
/// struct extended_transit {
///   unsigned int delay; /* transit delay in nanoseconds
///                          0xffffffff indicates value >= 0xffffffff */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedTransit {
    /// Transit delay in nanoseconds (0xffffffff indicates value >= 0xffffffff)
    pub delay: u32,
}

/// Extended Queue - Format (0,1040)
///
/// Queue depth for sampled packet traversing switch
///
/// # XDR Definition ([sFlow Transit](https://sflow.org/sflow_transit.txt))
///
/// ```text
/// /* Queue depth for sampled packet traversing switch */
/// /* extended_egress_queue structure must be included */
/// /* opaque = flow_data; enterprise = 0; format = 1040 */
/// struct extended_queue {
///   unsigned int depth;   /* queue depth in bytes */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedQueue {
    /// Queue depth in bytes
    pub depth: u32,
}

/// Extended HW Trap - Format (0,1041)
///
/// Devlink Trap Name information from Linux kernel
///
/// # XDR Definition ([host-sflow](https://github.com/sflow/host-sflow/blob/v2.0.50-3/src/sflow/sflow.h))
///
/// ```text
/// /* Devlink Trap Name */
/// /* opaque = flow_data; enterprise = 0; format = 1041 */
/// /* https://www.kernel.org/doc/html/latest/networking/devlink/devlink-trap.html */
/// /* XDR spec: */
/// /*  struct extended_hw_trap { */
/// /*    string group<>; */ /* NET_DM_ATTR_HW_TRAP_GROUP_NAME */
/// /*    string trap<>; */ /* NET_DM_ATTR_HW_TRAP_NAME */
/// /*  } */
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedHwTrap {
    /// Hardware trap group name (NET_DM_ATTR_HW_TRAP_GROUP_NAME)
    pub group: String,

    /// Hardware trap name (NET_DM_ATTR_HW_TRAP_NAME)
    pub trap: String,
}

/// Extended Linux Drop Reason - Format (0,1042)
///
/// Linux drop_monitor reason information
///
/// # XDR Definition ([host-sflow](https://github.com/sflow/host-sflow/blob/v2.0.50-3/src/sflow/sflow.h))
///
/// ```text
/// /* Linux drop_monitor reason */
/// /* opaque = flow_data; enterprise = 0; format = 1042 */
/// /* https://github.com/torvalds/linux/blob/master/include/net/dropreason.h */
/// /* XDR spec: */
/// /*  struct extended_linux_drop_reason { */
/// /*    string reason<>; */ /* NET_DM_ATTR_REASON */
/// /*  } */
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedLinuxDropReason {
    /// Drop reason string (NET_DM_ATTR_REASON)
    pub reason: String,
}

/// Transaction status values
///
/// # XDR Definition ([sFlow Discussion](https://sflow.org/discussion/sflow-discussion/0282.html))
///
/// ```text
/// enum status_value {
///     succeeded = 0,
///     generic_failure = 1,
///     outofmemory = 2,
///     timeout = 3,
///     notpermitted = 4
/// }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum TransactionStatus {
    Succeeded = 0,
    GenericFailure = 1,
    OutOfMemory = 2,
    Timeout = 3,
    NotPermitted = 4,
}

impl From<u32> for TransactionStatus {
    fn from(value: u32) -> Self {
        match value {
            0 => TransactionStatus::Succeeded,
            1 => TransactionStatus::GenericFailure,
            2 => TransactionStatus::OutOfMemory,
            3 => TransactionStatus::Timeout,
            4 => TransactionStatus::NotPermitted,
            _ => TransactionStatus::GenericFailure,
        }
    }
}

/// Service direction for transactions
///
/// # XDR Definition ([sFlow Discussion](https://sflow.org/discussion/sflow-discussion/0282.html))
///
/// ```text
/// enum service_direction {
///     client = 1,
///     server = 2
/// }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum ServiceDirection {
    Client = 1,
    Server = 2,
}

impl From<u32> for ServiceDirection {
    fn from(value: u32) -> Self {
        match value {
            1 => ServiceDirection::Client,
            2 => ServiceDirection::Server,
            _ => ServiceDirection::Client,
        }
    }
}

/// Transaction - Format (0,2000)
///
/// Generic application transaction record sampled upon completion
///
/// # XDR Definition ([sFlow Discussion](https://sflow.org/discussion/sflow-discussion/0282.html))
///
/// ```text
/// /* Generic Application Transaction record */
/// /* Every Application Transaction sample must start with a generic transaction record */
/// /* opaque = flow_data; enterprise = 0; format = 2000 */
/// struct transaction {
///     service_direction direction; /* was this transaction observed by the server or the client */
///     unsigned int wait;           /* time in microseconds that transaction was queued
///                                     before processing started */
///     unsigned int duration;       /* time in microseconds from start of processing to completion */
///     status_value status;         /* status of transaction */
///     unsigned hyper bytes_received; /* bytes received */
///     unsigned hyper bytes_send;   /* bytes sent */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Transaction {
    /// Was this transaction observed by the server or the client
    pub direction: ServiceDirection,

    /// Time in microseconds that transaction was queued before processing started
    pub wait: u32,

    /// Time in microseconds from start of processing to completion
    pub duration: u32,

    /// Status of transaction
    pub status: TransactionStatus,

    /// Bytes received
    pub bytes_received: u64,

    /// Bytes sent (spec: bytes_send)
    pub bytes_sent: u64,
}

/// Extended NFS Storage Transaction - Format (0,2001)
///
/// NFS operation transaction details
///
/// # XDR Definition ([sFlow Discussion](https://sflow.org/discussion/sflow-discussion/0282.html))
///
/// ```text
/// /* Extended NFS transaction */
/// /* see RFC 3530 */
/// /* opaque = flow_data; enterprise = 0; format = 2001 */
/// struct extended_nfs_storage_transaction {
///     opaque<> path;        /* canonical path to file or directory
///                              associated with operation file handle
///                              UTF8 encoded string */
///     unsigned int operation; /* NFS operation */
///     unsigned int status;    /* NFS operation status - nfsstat4 */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedNfsStorageTransaction {
    /// Canonical path to file or directory (UTF8 encoded)
    pub path: Vec<u8>,

    /// NFS operation
    pub operation: u32,

    /// NFS operation status (nfsstat4)
    pub status: u32,
}

/// Extended SCSI Storage Transaction - Format (0,2002)
///
/// SCSI operation transaction details
///
/// # XDR Definition ([sFlow Discussion](https://sflow.org/discussion/sflow-discussion/0282.html))
///
/// ```text
/// /* Extended SCSI transaction */
/// /* opaque = flow_data; enterprise = 0; format = 2002 */
/// struct extended_scsi_storage_transaction {
///     unsigned int lun;       /* LUN */
///     unsigned int operation; /* use maxint to encode unknown operation */
///     unsigned int status;    /* SCSI status code reporting result of operation */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedScsiStorageTransaction {
    /// Logical Unit Number
    pub lun: u32,

    /// SCSI operation (use maxint to encode unknown operation)
    pub operation: u32,

    /// SCSI status code reporting result of operation
    pub status: u32,
}

/// Extended HTTP Transaction - Format (0,2003)
///
/// HTTP transaction details
///
/// # XDR Definition ([sFlow Discussion](https://sflow.org/discussion/sflow-discussion/0282.html))
///
/// ```text
/// /* Extended Web transaction */
/// /* opaque = flow_data; enterprise = 0; format = 2003 */
/// struct extended_http_transaction {
///     string<> url;       /* The HTTP request-line (see RFC 2616) */
///     string<> host;      /* The host field from the HTTP header */
///     string<> referer;   /* The referer field from the HTTP header */
///     string<> useragent; /* The user agent from the HTTP header */
///     string<> user;      /* The authenticated user */
///     unigned int status; /* Status code returned with response */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedHttpTransaction {
    /// The HTTP request-line (see RFC 2616)
    pub url: String,

    /// The host field from the HTTP header
    pub host: String,

    /// The referer field from the HTTP header
    pub referer: String,

    /// The user agent from the HTTP header (spec: useragent)
    pub user_agent: String,

    /// The authenticated user
    pub user: String,

    /// Status code returned with response
    pub status: u32,
}

/// Extended Socket IPv4 - Format (0,2100)
///
/// IPv4 socket information for application transactions
///
/// # XDR Definition ([sFlow Host](https://sflow.org/sflow_host.txt))
///
/// ```text
/// /* IPv4 Socket */
/// /* opaque = flow_data; enterprise = 0; format = 2100 */
///
/// struct extended_socket_ipv4 {
///     unsigned int protocol;     /* IP Protocol type (e.g., TCP = 6, UDP = 17) */
///     ip_v4 local_ip;            /* local IP address */
///     ip_v4 remote_ip;           /* remote IP address */
///     unsigned int local_port;   /* TCP/UDP local port number or equivalent */
///     unsigned int remote_port;  /* TCP/UDP remote port number or equivalent */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedSocketIpv4 {
    /// IP Protocol type (e.g., TCP = 6, UDP = 17)
    pub protocol: u32,

    /// Local IP address
    pub local_ip: std::net::Ipv4Addr,

    /// Remote IP address
    pub remote_ip: std::net::Ipv4Addr,

    /// TCP/UDP local port number
    pub local_port: u32,

    /// TCP/UDP remote port number
    pub remote_port: u32,
}

/// Extended Socket IPv6 - Format (0,2101)
///
/// IPv6 socket information for application transactions
///
/// # XDR Definition ([sFlow Host](https://sflow.org/sflow_host.txt))
///
/// ```text
/// /* IPv6 Socket */
/// /* opaque = flow_data; enterprise = 0; format = 2101 */
///
/// struct extended_socket_ipv6 {
///     unsigned int protocol;     /* IP Protocol type (e.g., TCP = 6, UDP = 17) */
///     ip_v6 local_ip;            /* local IP address */
///     ip_v6 remote_ip;           /* remote IP address */
///     unsigned int local_port;   /* TCP/UDP local port number or equivalent */
///     unsigned int remote_port;  /* TCP/UDP remote port number or equivalent */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedSocketIpv6 {
    /// IP Protocol type (e.g., TCP = 6, UDP = 17)
    pub protocol: u32,

    /// Local IP address
    pub local_ip: std::net::Ipv6Addr,

    /// Remote IP address
    pub remote_ip: std::net::Ipv6Addr,

    /// TCP/UDP local port number
    pub local_port: u32,

    /// TCP/UDP remote port number
    pub remote_port: u32,
}

/// Extended Proxy Socket IPv4 - Format (0,2102)
///
/// IPv4 socket information for proxy connections
///
/// # XDR Definition ([sFlow HTTP](https://sflow.org/sflow_http.txt))
///
/// ```text
/// /* Proxy socket IPv4 */
/// /* opaque = flow_data; enterprise=0; format=2102 */
/// struct extended_proxy_socket_ipv4 {
///   extended_socket_ipv4 socket;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedProxySocketIpv4 {
    /// Socket information
    pub socket: ExtendedSocketIpv4,
}

/// Extended Proxy Socket IPv6 - Format (0,2103)
///
/// IPv6 socket information for proxy connections
///
/// # XDR Definition ([sFlow HTTP](https://sflow.org/sflow_http.txt))
///
/// ```text
/// /* Proxy socket IPv6 */
/// /* opaque = flow_data; enterprise=0; format=2103 */
/// struct extended_proxy_socket_ipv6 {
///   extended_socket_ipv6 socket;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedProxySocketIpv6 {
    /// Socket information
    pub socket: ExtendedSocketIpv6,
}

/// Application operation context
///
/// # XDR Definition ([sFlow Application](https://sflow.org/sflow_application.txt))
///
/// ```text
/// struct context {
///     application application;
///     operation operation;
///     attributes attributes;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AppContext {
    /// Application name (e.g., "payment", "mail.smtp", "db.oracle")
    pub application: String,

    /// Operation name (e.g., "get.customer.name", "upload.photo")
    pub operation: String,

    /// Operation attributes as name=value pairs (e.g., "cc=visa&loc=mobile")
    pub attributes: String,
}

/// Application operation status
///
/// # XDR Definition ([sFlow Application](https://sflow.org/sflow_application.txt))
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum AppStatus {
    Success = 0,
    Other = 1,
    Timeout = 2,
    InternalError = 3,
    BadRequest = 4,
    Forbidden = 5,
    TooLarge = 6,
    NotImplemented = 7,
    NotFound = 8,
    Unavailable = 9,
    Unauthorized = 10,
}

impl From<u32> for AppStatus {
    fn from(value: u32) -> Self {
        match value {
            0 => AppStatus::Success,
            1 => AppStatus::Other,
            2 => AppStatus::Timeout,
            3 => AppStatus::InternalError,
            4 => AppStatus::BadRequest,
            5 => AppStatus::Forbidden,
            6 => AppStatus::TooLarge,
            7 => AppStatus::NotImplemented,
            8 => AppStatus::NotFound,
            9 => AppStatus::Unavailable,
            10 => AppStatus::Unauthorized,
            _ => AppStatus::Other,
        }
    }
}

/// Memcache Protocol
///
/// # XDR Definition ([sFlow Memcache](https://sflow.org/sflow_memcache.txt))
///
/// ```text
/// enum memcache_protocol {
///   OTHER  = 0;
///   ASCII  = 1;
///   BINARY = 2;
/// }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum MemcacheProtocol {
    Other = 0,
    Ascii = 1,
    Binary = 2,
}

impl MemcacheProtocol {
    /// Convert from u32 value to MemcacheProtocol enum
    pub fn from_u32(value: u32) -> Self {
        match value {
            1 => MemcacheProtocol::Ascii,
            2 => MemcacheProtocol::Binary,
            _ => MemcacheProtocol::Other,
        }
    }
}

/// Memcache Command
///
/// # XDR Definition ([sFlow Memcache](https://sflow.org/sflow_memcache.txt))
///
/// ```text
/// enum memcache_cmd {
///   OTHER    = 0;
///   SET      = 1;
///   ADD      = 2;
///   REPLACE  = 3;
///   APPEND   = 4;
///   PREPEND  = 5;
///   CAS      = 6;
///   GET      = 7;
///   GETS     = 8;
///   INCR     = 9;
///   DECR     = 10;
///   DELETE   = 11;
///   STATS    = 12;
///   FLUSH    = 13;
///   VERSION  = 14;
///   QUIT     = 15;
///   TOUCH    = 16;
/// }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum MemcacheCommand {
    Other = 0,
    Set = 1,
    Add = 2,
    Replace = 3,
    Append = 4,
    Prepend = 5,
    Cas = 6,
    Get = 7,
    Gets = 8,
    Incr = 9,
    Decr = 10,
    Delete = 11,
    Stats = 12,
    Flush = 13,
    Version = 14,
    Quit = 15,
    Touch = 16,
}

impl MemcacheCommand {
    /// Convert from u32 value to MemcacheCommand enum
    pub fn from_u32(value: u32) -> Self {
        match value {
            1 => MemcacheCommand::Set,
            2 => MemcacheCommand::Add,
            3 => MemcacheCommand::Replace,
            4 => MemcacheCommand::Append,
            5 => MemcacheCommand::Prepend,
            6 => MemcacheCommand::Cas,
            7 => MemcacheCommand::Get,
            8 => MemcacheCommand::Gets,
            9 => MemcacheCommand::Incr,
            10 => MemcacheCommand::Decr,
            11 => MemcacheCommand::Delete,
            12 => MemcacheCommand::Stats,
            13 => MemcacheCommand::Flush,
            14 => MemcacheCommand::Version,
            15 => MemcacheCommand::Quit,
            16 => MemcacheCommand::Touch,
            _ => MemcacheCommand::Other,
        }
    }
}

/// Memcache Status
///
/// # XDR Definition ([sFlow Memcache](https://sflow.org/sflow_memcache.txt))
///
/// ```text
/// enum memcache_status {
///   UNKNOWN      = 0;
///   OK           = 1;
///   ERROR        = 2;
///   CLIENT_ERROR = 3;
///   SERVER_ERROR = 4;
///   STORED       = 5;
///   NOT_STORED   = 6;
///   EXISTS       = 7;
///   NOT_FOUND    = 8;
///   DELETED      = 9;
/// }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum MemcacheStatus {
    Unknown = 0,
    Ok = 1,
    Error = 2,
    ClientError = 3,
    ServerError = 4,
    Stored = 5,
    NotStored = 6,
    Exists = 7,
    NotFound = 8,
    Deleted = 9,
}

impl MemcacheStatus {
    /// Convert from u32 value to MemcacheStatus enum
    pub fn from_u32(value: u32) -> Self {
        match value {
            1 => MemcacheStatus::Ok,
            2 => MemcacheStatus::Error,
            3 => MemcacheStatus::ClientError,
            4 => MemcacheStatus::ServerError,
            5 => MemcacheStatus::Stored,
            6 => MemcacheStatus::NotStored,
            7 => MemcacheStatus::Exists,
            8 => MemcacheStatus::NotFound,
            9 => MemcacheStatus::Deleted,
            _ => MemcacheStatus::Unknown,
        }
    }
}

/// Memcache Operation - Format (0,2200)
///
/// Sampled memcache operation
///
/// # XDR Definition ([sFlow Memcache](https://sflow.org/sflow_memcache.txt))
///
/// ```text
/// /* Memcache operation */
/// /* opaque = flow_data; enterprise = 0; format = 2200 */
///
/// struct memcache_operation {
///   memcache_protocol protocol;  /* protocol */
///   memcache_cmd cmd;            /* command */
///   string<255> key;             /* key used to store/retrieve data */
///   unsigned int nkeys;          /* number of keys
///                                   (including sampled key) */
///   unsigned int value_bytes;    /* size of the value (in bytes) */
///   unsigned int uS;             /* duration of the operation
///                                   (in microseconds) */
///   memcache_status status;      /* status of command */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MemcacheOperation {
    /// Protocol (ASCII or Binary)
    pub protocol: MemcacheProtocol,

    /// Command type
    pub cmd: MemcacheCommand,

    /// Key used to store/retrieve data
    pub key: String,

    /// Number of keys (including sampled key)
    pub nkeys: u32,

    /// Size of the value in bytes
    pub value_bytes: u32,

    /// Duration of the operation in microseconds
    pub duration_us: u32,

    /// Status of the command
    pub status: MemcacheStatus,
}

/// HTTP method enumeration
///
/// # XDR Definition ([sFlow HTTP](https://sflow.org/sflow_http.txt))
///
/// ```text
/// /* The http_method enumeration may be expanded over time.
///    Applications receiving sFlow must be prepared to receive
///    http_request structures with unknown http_method values */
///
/// enum http_method {
///   OTHER    = 0;
///   OPTIONS  = 1;
///   GET      = 2;
///   HEAD     = 3;
///   POST     = 4;
///   PUT      = 5;
///   DELETE   = 6;
///   TRACE    = 7;
///   CONNECT  = 8;
/// }
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u32)]
pub enum HttpMethod {
    Other = 0,
    Options = 1,
    Get = 2,
    Head = 3,
    Post = 4,
    Put = 5,
    Delete = 6,
    Trace = 7,
    Connect = 8,
}

impl From<u32> for HttpMethod {
    fn from(value: u32) -> Self {
        match value {
            1 => HttpMethod::Options,
            2 => HttpMethod::Get,
            3 => HttpMethod::Head,
            4 => HttpMethod::Post,
            5 => HttpMethod::Put,
            6 => HttpMethod::Delete,
            7 => HttpMethod::Trace,
            8 => HttpMethod::Connect,
            _ => HttpMethod::Other,
        }
    }
}

impl std::fmt::Display for HttpMethod {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            HttpMethod::Other => write!(f, "OTHER"),
            HttpMethod::Options => write!(f, "OPTIONS"),
            HttpMethod::Get => write!(f, "GET"),
            HttpMethod::Head => write!(f, "HEAD"),
            HttpMethod::Post => write!(f, "POST"),
            HttpMethod::Put => write!(f, "PUT"),
            HttpMethod::Delete => write!(f, "DELETE"),
            HttpMethod::Trace => write!(f, "TRACE"),
            HttpMethod::Connect => write!(f, "CONNECT"),
        }
    }
}

/// HTTP Request - Format (0,2201) - **DEPRECATED**
///
/// Legacy HTTP request information
///
/// **Note:** This format was defined in an early sFlow HTTP discussion
/// but was deprecated and replaced by format 2206. It is included here for
/// backward compatibility with legacy implementations.
///
/// # XDR Definition ([sFlow Discussion](https://groups.google.com/g/sflow/c/iKzLK61ZTR0))
///
/// ```text
/// /* HTTP request */
/// /* opaque = flow_data; enterprise = 0; format = 2201 */
/// struct http_request {
///   http_method method;        /* method */
///   string<255> uri;           /* URI exactly as it came from the client */
///   string<32> host;           /* Host value from request header */
///   string<255> referer;       /* Referer value from request header */
///   string<64> useragent;      /* User-Agent value from request header */
///   string<64> xff;            /* X-Forwarded-For value from request header */
///   string<32> authuser;       /* RFC 1413 identity of user*/
///   string<32> mime_type;      /* Mime-Type */
///   unsigned hyper req_bytes;  /* Content-Length of request */
///   unsigned hyper resp_bytes; /* Content-Length of response */
///   unsigned int uS;           /* duration of the operation (microseconds) */
///   int status;                /* HTTP status code */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct HttpRequestDeprecated {
    /// HTTP method
    pub method: HttpMethod,

    /// URI exactly as it came from the client
    pub uri: String,

    /// Host value from request header
    pub host: String,

    /// Referer value from request header
    pub referer: String,

    /// User-Agent value from request header
    pub useragent: String,

    /// X-Forwarded-For value from request header
    pub xff: String,

    /// RFC 1413 identity of user
    pub authuser: String,

    /// Mime-Type
    pub mime_type: String,

    /// Content-Length of request
    pub req_bytes: u64,

    /// Content-Length of response
    pub resp_bytes: u64,

    /// Duration of the operation in microseconds
    pub duration_us: u32,

    /// HTTP status code
    pub status: i32,
}

/// Application Operation - Format (0,2202)
///
/// Sampled application operation information
///
/// # XDR Definition ([sFlow Application](https://sflow.org/sflow_application.txt))
///
/// ```text
/// /* Sampled Application Operation */
/// /* opaque = flow_data; enterprise = 0; format = 2202 */
///
/// struct app_operation {
///     context context;             /* attributes describing the operation */
///     utf8string<64> status_descr; /* additional text describing status */
///     unsigned hyper req_bytes;    /* size of request body (exclude headers) */
///     unsigned hyper resp_bytes;   /* size of response body (exclude headers) */
///     unsigned int uS;             /* duration of the operation (microseconds) */
///     status status;               /* status code */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AppOperation {
    /// Operation context
    pub context: AppContext,

    /// Additional status description
    pub status_descr: String,

    /// Size of request body in bytes (excluding headers)
    pub req_bytes: u64,

    /// Size of response body in bytes (excluding headers)
    pub resp_bytes: u64,

    /// Duration of the operation in microseconds
    pub duration_us: u32,

    /// Operation status code
    pub status: AppStatus,
}

/// Application Parent Context - Format (0,2203)
///
/// Parent context for sampled client operations
///
/// # XDR Definition ([sFlow Application](https://sflow.org/sflow_application.txt))
///
/// ```text
/// /* Optional parent context information for sampled client operation */
/// /* opaque = flow_data; enterprise = 0; format = 2203 */
///
/// struct app_parent_context {
///     context context;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AppParentContext {
    /// Parent operation context
    pub context: AppContext,
}

/// Application Initiator - Format (0,2204)
///
/// Actor initiating the request (e.g., customer sending a payment)
///
/// # XDR Definition ([sFlow Application](https://sflow.org/sflow_application.txt))
///
/// ```text
/// /* Actor initiating the request */
/// /* e.g. customer sending a payment */
/// /* opaque = flow_data; enterprise = 0; format = 2204 */
///
/// struct app_initiator {
///    actor actor;
/// }
/// ```
///
/// **ERRATUM:** The specification is missing the `struct` keyword before the structure name,
/// which is inconsistent with XDR syntax conventions. The corrected version is shown above.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AppInitiator {
    /// Business level identifier (e.g., customer id, vendor id)
    pub actor: String,
}

/// Application Target - Format (0,2205)
///
/// Actor targeted by the request (e.g., recipient of payment)
///
/// # XDR Definition ([sFlow Application](https://sflow.org/sflow_application.txt))
///
/// ```text
/// /* Actor targetted by the request */
/// /* e.g. recipient of payment */
/// /* opaque = flow_data; enterprise = 0; format = 2205 */
///
/// struct app_target {
///    actor actor;
/// }
/// ```
///
/// **ERRATUM:** The specification is missing the `struct` keyword before the structure name,
/// which is inconsistent with XDR syntax conventions. The corrected version is shown above.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AppTarget {
    /// Business level identifier (e.g., customer id, vendor id)
    pub actor: String,
}

/// HTTP Request - Format (0,2206)
///
/// HTTP request information
///
/// # XDR Definition ([sFlow HTTP](https://sflow.org/sflow_http.txt))
///
/// ```text
/// /* HTTP protocol version number */
/// /* Encoded as major_number * 1000 + minor_number */
/// /* e.g. HTTP1.1 is encoded as 1001 */
/// typedef unsigned int version;
///
/// /* HTTP request */
/// /* opaque = flow_data; enterprise = 0; format = 2206 */
/// struct http_request {
///   http_method method;        /* method */
///   version protocol;          /* HTTP protocol version */
///   string<255> uri;           /* URI exactly as it came from the client */
///   string<64> host;           /* Host value from request header */
///   string<255> referer;       /* Referer value from request header */
///   string<128> useragent;     /* User-Agent value from request header */
///   string<64> xff;            /* X-Forwarded-For value
///                                 from request header */
///   string<32> authuser;       /* RFC 1413 identity of user*/
///   string<64> mime-type;      /* Mime-Type of response */
///   unsigned hyper req_bytes;  /* Content-Length of request */
///   unsigned hyper resp_bytes; /* Content-Length of response */
///   unsigned int uS;           /* duration of the operation
///                                 (in microseconds) */
///   int status;                /* HTTP status code */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct HttpRequest {
    /// HTTP method
    pub method: HttpMethod,

    /// HTTP protocol version (major * 1000 + minor, e.g., HTTP/1.1 = 1001)
    pub protocol: u32,

    /// URI exactly as it came from the client
    pub uri: String,

    /// Host value from request header
    pub host: String,

    /// Referer value from request header
    pub referer: String,

    /// User-Agent value from request header
    pub useragent: String,

    /// X-Forwarded-For value from request header
    pub xff: String,

    /// RFC 1413 identity of user
    pub authuser: String,

    /// MIME type of response
    pub mime_type: String,

    /// Content-Length of request
    pub req_bytes: u64,

    /// Content-Length of response
    pub resp_bytes: u64,

    /// Duration of the operation in microseconds
    pub duration_us: u32,

    /// HTTP status code
    pub status: i32,
}

/// Extended Proxy Request - Format (0,2207)
///
/// Rewritten URI for proxy requests
///
/// # XDR Definition ([sFlow HTTP](https://sflow.org/sflow_http.txt))
///
/// ```text
/// /* Rewritten URI */
/// /* Only include if host or uri are modified */
/// /* opaque = flow_data; enterprise = 0; format = 2207 */
/// struct extended_proxy_request {
///   string<255> uri;           /* URI in request to downstream server */
///   string<64>  host;          /* Host in request to downstream server */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedProxyRequest {
    /// URI in request to downstream server
    pub uri: String,

    /// Host in request to downstream server
    pub host: String,
}

/// Extended Nav Timing - Format (0,2208)
///
/// Navigation timing information from web browsers
///
/// # XDR Definition ([sFlow Discussion](https://groups.google.com/g/sflow/c/FKzkvig32Tk))
///
/// ```text
/// /* Navigation Timing */
/// /* reference http://www.w3.org/TR/navigation-timing/ */
/// /* To allow times to fit into 32 bits, normalize so that smallest time
/// value is 1, times are expressed in milliseconds and 0 is used to indicate
/// that event is not fired, or not complete */
/// /* opaque = flow_data; enterprise = 0; format = 2208 */
///
/// struct extended_nav_timing {
///     unsigned int type; /* PerformanceNavigation */
///     unsigned int redirectCount;
///     unsigned int navigationStart; /* PerformanceTiming */
///     unsigned int unloadEventStart;
///     unsigned int unloadEventEnd;
///     unsigned int redirectStart;
///     unsigned int redirectEnd;
///     unsigned int fetchStart;
///     unsigned int domainLookupStart;
///     unsigned int domainLookupEnd;
///     unsigned int connectStart;
///     unsigned int connectEnd;
///     unsigned int secureConnectionStart;
///     unsigned int requestStart;
///     unsigned int responseStart;
///     unsigned int responseEnd;
///     unsigned int domLoading;
///     unsigned int domInteractive;
///     unsigned int domContentLoadedEventStart;
///     unsigned int domContentLoadedEventEnd;
///     unsigned int domComplete;
///     unsigned int loadEventStart;
///     unsigned int loadEventEnd;
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedNavTiming {
    /// Navigation type (PerformanceNavigation)
    pub nav_type: u32,
    /// Redirect count
    pub redirect_count: u32,
    /// Navigation start time (PerformanceTiming)
    pub navigation_start: u32,
    /// Unload event start time
    pub unload_event_start: u32,
    /// Unload event end time
    pub unload_event_end: u32,
    /// Redirect start time
    pub redirect_start: u32,
    /// Redirect end time
    pub redirect_end: u32,
    /// Fetch start time
    pub fetch_start: u32,
    /// Domain lookup start time
    pub domain_lookup_start: u32,
    /// Domain lookup end time
    pub domain_lookup_end: u32,
    /// Connect start time
    pub connect_start: u32,
    /// Connect end time
    pub connect_end: u32,
    /// Secure connection start time
    pub secure_connection_start: u32,
    /// Request start time
    pub request_start: u32,
    /// Response start time
    pub response_start: u32,
    /// Response end time
    pub response_end: u32,
    /// DOM loading time
    pub dom_loading: u32,
    /// DOM interactive time
    pub dom_interactive: u32,
    /// DOM content loaded event start time
    pub dom_content_loaded_event_start: u32,
    /// DOM content loaded event end time
    pub dom_content_loaded_event_end: u32,
    /// DOM complete time
    pub dom_complete: u32,
    /// Load event start time
    pub load_event_start: u32,
    /// Load event end time
    pub load_event_end: u32,
}

/// Packet direction for TCP info
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PacketDirection {
    Unknown = 0,
    Received = 1,
    Sent = 2,
}

impl PacketDirection {
    /// Convert from u32 value to PacketDirection enum
    pub fn from_u32(value: u32) -> Self {
        match value {
            1 => PacketDirection::Received,
            2 => PacketDirection::Sent,
            _ => PacketDirection::Unknown,
        }
    }
}

/// Extended TCP Info - Format (0,2209)
///
/// TCP connection state information based on Linux struct tcp_info
///
/// # XDR Definition ([sFlow Discussion](https://groups.google.com/g/sflow/c/JCG9iwacLZA))
///
/// ```text
/// /* TCP connection state */
/// /* Based on Linux struct tcp_info */
/// /* opaque = flow_data; enterprise=0; format=2209 */
/// struct extended_tcp_info {
///   packet_direction dir;     /* Sampled packet direction */
///   unsigned int snd_mss;     /* Cached effective mss, not including SACKS */
///   unsigned int rcv_mss;     /* Max. recv. segment size */
///   unsigned int unacked;     /* Packets which are "in flight" */
///   unsigned int lost;        /* Lost packets */
///   unsigned int retrans;     /* Retransmitted packets */
///   unsigned int pmtu;        /* Last pmtu seen by socket */
///   unsigned int rtt;         /* smoothed RTT (microseconds) */
///   unsigned int rttvar;      /* RTT variance (microseconds) */
///   unsigned int snd_cwnd;    /* Sending congestion window */
///   unsigned int reordering;  /* Reordering */
///   unsigned int min_rtt;     /* Minimum RTT (microseconds) */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedTcpInfo {
    /// Sampled packet direction
    pub dir: PacketDirection,
    /// Cached effective MSS, not including SACKS
    pub snd_mss: u32,
    /// Maximum receive segment size
    pub rcv_mss: u32,
    /// Packets which are "in flight"
    pub unacked: u32,
    /// Lost packets
    pub lost: u32,
    /// Retransmitted packets
    pub retrans: u32,
    /// Last PMTU seen by socket
    pub pmtu: u32,
    /// Smoothed RTT (microseconds)
    pub rtt: u32,
    /// RTT variance (microseconds)
    pub rttvar: u32,
    /// Sending congestion window
    pub snd_cwnd: u32,
    /// Reordering
    pub reordering: u32,
    /// Minimum RTT (microseconds)
    pub min_rtt: u32,
}

/// Extended Entities - Format (0,2210)
///
/// Traffic source/sink entity reference
///
/// # XDR Definition ([sFlow Discussion](https://blog.sflow.com/2018/10/systemd-traffic-marking.html))
///
/// ```text
/// /* Traffic source/sink entity reference */
/// /* opaque = flow_data; enterprise = 0; format = 2210 */
/// /* Set Data source to all zeroes if unknown */
/// struct extended_entities {
///  sflow_data_source_expanded src_ds;    /* Data Source associated with
///                                           packet source */
///  sflow_data_source_expanded dst_ds;    /* Data Source associated with
///                                           packet destination */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedEntities {
    /// Data source associated with packet source
    pub src_ds: crate::models::core::DataSourceExpanded,
    /// Data source associated with packet destination
    pub dst_ds: crate::models::core::DataSourceExpanded,
}

/// Extended BST Egress Queue - Format (4413,1)
///
/// Selected egress queue for sampled packet from Broadcom switch ASIC
///
/// # XDR Definition ([sFlow Broadcom Buffers](https://sflow.org/bv-sflow.txt))
///
/// ```text
/// /* Selected egress queue */
/// /* opaque = flow_data; enterprise = 4413; format = 1 */
/// struct extended_bst_egress_queue {
///   unsigned int queue;  /* eqress queue number selected for sampled packet */
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtendedBstEgressQueue {
    /// Egress queue number selected for sampled packet
    pub queue: u32,
}