netflow_parser 1.0.3

Parser for Netflow Cisco V5, V7, V9, IPFIX
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
//! See: <https://www.ibm.com/docs/en/npi/1.3.0?topic=versions-v9-field-type-definitions>

use crate::variable_versions::field_value::*;

use serde::Serialize;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Serialize)]
pub enum ScopeFieldType {
    System,
    Interface,
    LineCard,
    NetflowCache,
    Template,
    Unknown(u16),
}

impl Default for ScopeFieldType {
    fn default() -> Self {
        ScopeFieldType::Unknown(0)
    }
}

impl From<u16> for ScopeFieldType {
    fn from(item: u16) -> Self {
        match item {
            1 => ScopeFieldType::System,
            2 => ScopeFieldType::Interface,
            3 => ScopeFieldType::LineCard,
            4 => ScopeFieldType::NetflowCache,
            5 => ScopeFieldType::Template,
            _ => ScopeFieldType::Unknown(item),
        }
    }
}

impl From<ScopeFieldType> for u16 {
    fn from(item: ScopeFieldType) -> Self {
        match item {
            ScopeFieldType::System => 1,
            ScopeFieldType::Interface => 2,
            ScopeFieldType::LineCard => 3,
            ScopeFieldType::NetflowCache => 4,
            ScopeFieldType::Template => 5,
            ScopeFieldType::Unknown(n) => n,
        }
    }
}

#[derive(Debug, Hash, PartialEq, Eq, Clone, Ord, PartialOrd, Copy, Serialize)]
pub enum V9Field {
    InBytes,
    InPkts,
    Flows,
    Protocol,
    SrcTos,
    TcpFlags,
    L4SrcPort,
    Ipv4SrcAddr,
    SrcMask,
    InputSnmp,
    L4DstPort,
    Ipv4DstAddr,
    DstMask,
    OutputSnmp,
    Ipv4NextHop,
    SrcAs,
    DstAs,
    BgpIpv4NextHop,
    MulDstPkts,
    MulDstBytes,
    LastSwitched,
    FirstSwitched,
    OutBytes,
    OutPkts,
    MinPktLngth,
    MaxPktLngth,
    Ipv6SrcAddr,
    Ipv6DstAddr,
    Ipv6SrcMask,
    Ipv6DstMask,
    Ipv6FlowLabel,
    IcmpType,
    MulIgmpType,
    SamplingInterval,
    SamplingAlgorithm,
    FlowActiveTimeout,
    FlowInactiveTimeout,
    EngineType,
    EngineId,
    TotalBytesExp,
    TotalPktsExp,
    TotalFlowsExp,
    Ipv4SrcPrefix,
    Ipv4DstPrefix,
    MplsTopLabelType,
    MplsTopLabelIpAddr,
    FlowSamplerId,
    FlowSamplerMode,
    FlowSamplerRandomInterval,
    MinTtl,
    MaxTtl,
    Ipv4Ident,
    DstTos,
    InSrcMac,
    OutDstMac,
    SrcVlan,
    DstVlan,
    IpProtocolVersion,
    Direction,
    Ipv6NextHop,
    BgpIpv6NextHop,
    Ipv6OptionHeaders,
    MplsLabel1,
    MplsLabel2,
    MplsLabel3,
    MplsLabel4,
    MplsLabel5,
    MplsLabel6,
    MplsLabel7,
    MplsLabel8,
    MplsLabel9,
    MplsLabel10,
    InDstMac,
    OutSrcMac,
    IfName,
    IfDesc,
    SamplerName,
    InPermanentBytes,
    InPermanentPkts,
    FragmentOffset,
    ForwardingStatus,
    MplsPalRd,
    MplsPrefixLen,
    SrcTrafficIndex,
    DstTrafficIndex,
    ApplicationDescription,
    ApplicationTag,
    ApplicationName,
    PostipDiffServCodePoint,
    Replicationfactor,
    Deprecated,
    Layer2packetSectionOffset,
    Layer2packetSectionSize,
    Layer2packetSectionData,
    BgpNextAdjacentAsNumber,
    BgpPrevAdjacentAsNumber,
    ExporterIpv4Address,
    ExporterIpv6Address,
    DroppedOctetDeltaCount,
    DroppedPacketDeltaCount,
    DroppedOctetTotalCount,
    DroppedPacketTotalCount,
    FlowEndReason,
    CommonPropertiesId,
    ObservationPointId,
    IcmpTypeCodeIpv6,
    MplsTopLabelIpv6Address,
    LineCardId,
    PortId,
    MeteringProcessId,
    ExportingProcessId,
    TemplateId,
    WlanChannelId,
    WlanSsid,
    FlowId,
    ObservationDomainId,
    FlowStartSeconds,
    FlowEndSeconds,
    FlowStartMilliseconds,
    FlowEndMilliseconds,
    FlowStartMicroseconds,
    FlowEndMicroseconds,
    FlowStartNanoseconds,
    FlowEndNanoseconds,
    FlowStartDeltaMicroseconds,
    FlowEndDeltaMicroseconds,
    SystemInitTimeMilliseconds,
    FlowDurationMilliseconds,
    FlowDurationMicroseconds,
    ObservedFlowTotalCount,
    IgnoredPacketTotalCount,
    IgnoredOctetTotalCount,
    NotSentFlowTotalCount,
    NotSentPacketTotalCount,
    NotSentOctetTotalCount,
    DestinationIpv6Prefix,
    SourceIpv6Prefix,
    PostOctetTotalCount,
    PostPacketTotalCount,
    FlowKeyIndicator,
    PostMcastPacketTotalCount,
    PostMcastOctetTotalCount,
    IcmpTypeValue,
    IcmpCodeValue,
    IcmpIpv6TypeValue,
    IcmpIpv6CodeValue,
    PostNATSourceIPv4Address,
    PostNATDestinationIPv4Address,
    PostNATTSourceTransportPort,
    PostNATTDestinationTransportPort,
    NatOriginatingAddressRealm,
    NatEvent,
    PostNATSourceIpv6Address,
    PostNATDestinationIpv6Address,
    FirewallEvent,
    IngressVRFID,
    EgressVRFID,
    BiflowDirection,
    ObservationTimeMilliseconds,
    /// IANA-assigned fields that may appear in V9 but have no V9-specific name
    IanaAssigned(u16),
    Unknown(u16),
}

impl From<V9Field> for FieldDataType {
    fn from(d: V9Field) -> FieldDataType {
        match d {
            V9Field::InBytes => FieldDataType::UnsignedDataNumber,
            V9Field::InPkts => FieldDataType::UnsignedDataNumber,
            V9Field::Flows => FieldDataType::UnsignedDataNumber,
            V9Field::Protocol => FieldDataType::ProtocolType,
            V9Field::SrcTos => FieldDataType::UnsignedDataNumber,
            V9Field::TcpFlags => FieldDataType::TcpControlBits,
            V9Field::L4SrcPort => FieldDataType::UnsignedDataNumber,
            V9Field::Ipv4SrcAddr => FieldDataType::Ip4Addr,
            V9Field::SrcMask => FieldDataType::UnsignedDataNumber,
            V9Field::InputSnmp => FieldDataType::UnsignedDataNumber,
            V9Field::L4DstPort => FieldDataType::UnsignedDataNumber,
            V9Field::Ipv4DstAddr => FieldDataType::Ip4Addr,
            V9Field::DstMask => FieldDataType::UnsignedDataNumber,
            V9Field::OutputSnmp => FieldDataType::UnsignedDataNumber,
            V9Field::Ipv4NextHop => FieldDataType::Ip4Addr,
            V9Field::SrcAs => FieldDataType::UnsignedDataNumber,
            V9Field::DstAs => FieldDataType::UnsignedDataNumber,
            V9Field::BgpIpv4NextHop => FieldDataType::Ip4Addr,
            V9Field::MulDstPkts => FieldDataType::UnsignedDataNumber,
            V9Field::MulDstBytes => FieldDataType::UnsignedDataNumber,
            V9Field::LastSwitched => FieldDataType::DurationMillis,
            V9Field::FirstSwitched => FieldDataType::DurationMillis,
            V9Field::OutBytes => FieldDataType::UnsignedDataNumber,
            V9Field::OutPkts => FieldDataType::UnsignedDataNumber,
            V9Field::MinPktLngth => FieldDataType::UnsignedDataNumber,
            V9Field::MaxPktLngth => FieldDataType::UnsignedDataNumber,
            V9Field::Ipv6SrcAddr => FieldDataType::Ip6Addr,
            V9Field::Ipv6DstAddr => FieldDataType::Ip6Addr,
            V9Field::Ipv6SrcMask => FieldDataType::UnsignedDataNumber,
            V9Field::Ipv6DstMask => FieldDataType::UnsignedDataNumber,
            V9Field::Ipv6FlowLabel => FieldDataType::UnsignedDataNumber,
            V9Field::IcmpType => FieldDataType::UnsignedDataNumber,
            V9Field::MulIgmpType => FieldDataType::UnsignedDataNumber,
            V9Field::SamplingInterval => FieldDataType::UnsignedDataNumber,
            V9Field::SamplingAlgorithm => FieldDataType::UnsignedDataNumber,
            V9Field::FlowActiveTimeout => FieldDataType::UnsignedDataNumber,
            V9Field::FlowInactiveTimeout => FieldDataType::UnsignedDataNumber,
            V9Field::EngineType => FieldDataType::UnsignedDataNumber,
            V9Field::EngineId => FieldDataType::UnsignedDataNumber,
            V9Field::TotalBytesExp => FieldDataType::UnsignedDataNumber,
            V9Field::TotalPktsExp => FieldDataType::UnsignedDataNumber,
            V9Field::TotalFlowsExp => FieldDataType::UnsignedDataNumber,
            V9Field::Ipv4SrcPrefix => FieldDataType::Ip4Addr,
            V9Field::Ipv4DstPrefix => FieldDataType::Ip4Addr,
            V9Field::MplsTopLabelType => FieldDataType::MplsTopLabelType,
            V9Field::MplsTopLabelIpAddr => FieldDataType::Ip4Addr,
            V9Field::FlowSamplerId => FieldDataType::UnsignedDataNumber,
            V9Field::FlowSamplerMode => FieldDataType::UnsignedDataNumber,
            V9Field::FlowSamplerRandomInterval => FieldDataType::UnsignedDataNumber,
            V9Field::MinTtl => FieldDataType::UnsignedDataNumber,
            V9Field::MaxTtl => FieldDataType::UnsignedDataNumber,
            V9Field::Ipv4Ident => FieldDataType::UnsignedDataNumber,
            V9Field::DstTos => FieldDataType::UnsignedDataNumber,
            V9Field::InSrcMac => FieldDataType::MacAddr,
            V9Field::OutDstMac => FieldDataType::MacAddr,
            V9Field::SrcVlan => FieldDataType::UnsignedDataNumber,
            V9Field::DstVlan => FieldDataType::UnsignedDataNumber,
            V9Field::IpProtocolVersion => FieldDataType::UnsignedDataNumber,
            V9Field::Direction => FieldDataType::UnsignedDataNumber,
            V9Field::Ipv6NextHop => FieldDataType::Ip6Addr,
            V9Field::BgpIpv6NextHop => FieldDataType::Ip6Addr,
            V9Field::Ipv6OptionHeaders => FieldDataType::Ipv6ExtensionHeaders,
            V9Field::MplsLabel1
            | V9Field::MplsLabel2
            | V9Field::MplsLabel3
            | V9Field::MplsLabel4
            | V9Field::MplsLabel5
            | V9Field::MplsLabel6
            | V9Field::MplsLabel7
            | V9Field::MplsLabel8
            | V9Field::MplsLabel9
            | V9Field::MplsLabel10 => FieldDataType::UnsignedDataNumber,
            V9Field::InDstMac => FieldDataType::MacAddr,
            V9Field::OutSrcMac => FieldDataType::MacAddr,
            V9Field::IfName => FieldDataType::String,
            V9Field::IfDesc => FieldDataType::String,
            V9Field::SamplerName => FieldDataType::String,
            V9Field::InPermanentBytes => FieldDataType::UnsignedDataNumber,
            V9Field::InPermanentPkts => FieldDataType::UnsignedDataNumber,
            V9Field::FragmentOffset => FieldDataType::UnsignedDataNumber,
            V9Field::ForwardingStatus => FieldDataType::ForwardingStatus,
            V9Field::MplsPalRd => FieldDataType::Vec,
            V9Field::MplsPrefixLen => FieldDataType::UnsignedDataNumber,
            V9Field::SrcTrafficIndex => FieldDataType::UnsignedDataNumber,
            V9Field::DstTrafficIndex => FieldDataType::UnsignedDataNumber,
            V9Field::ApplicationDescription => FieldDataType::String,
            V9Field::ApplicationTag => FieldDataType::ApplicationId,
            V9Field::ApplicationName => FieldDataType::String,
            V9Field::PostipDiffServCodePoint => FieldDataType::UnsignedDataNumber,
            V9Field::Replicationfactor => FieldDataType::UnsignedDataNumber,
            V9Field::Deprecated => FieldDataType::UnsignedDataNumber,
            V9Field::Layer2packetSectionOffset => FieldDataType::UnsignedDataNumber,
            V9Field::Layer2packetSectionSize => FieldDataType::UnsignedDataNumber,
            V9Field::Layer2packetSectionData => FieldDataType::Vec,
            V9Field::BgpNextAdjacentAsNumber => FieldDataType::UnsignedDataNumber,
            V9Field::BgpPrevAdjacentAsNumber => FieldDataType::UnsignedDataNumber,
            V9Field::ExporterIpv4Address => FieldDataType::Ip4Addr,
            V9Field::ExporterIpv6Address => FieldDataType::Ip6Addr,
            V9Field::DroppedOctetDeltaCount => FieldDataType::UnsignedDataNumber,
            V9Field::DroppedPacketDeltaCount => FieldDataType::UnsignedDataNumber,
            V9Field::DroppedOctetTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::DroppedPacketTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::FlowEndReason => FieldDataType::FlowEndReason,
            V9Field::CommonPropertiesId => FieldDataType::UnsignedDataNumber,
            V9Field::ObservationPointId => FieldDataType::UnsignedDataNumber,
            V9Field::IcmpTypeCodeIpv6 => FieldDataType::UnsignedDataNumber,
            V9Field::MplsTopLabelIpv6Address => FieldDataType::Ip6Addr,
            V9Field::LineCardId => FieldDataType::UnsignedDataNumber,
            V9Field::PortId => FieldDataType::UnsignedDataNumber,
            V9Field::MeteringProcessId => FieldDataType::UnsignedDataNumber,
            V9Field::ExportingProcessId => FieldDataType::UnsignedDataNumber,
            V9Field::TemplateId => FieldDataType::UnsignedDataNumber,
            V9Field::WlanChannelId => FieldDataType::UnsignedDataNumber,
            V9Field::WlanSsid => FieldDataType::String,
            V9Field::FlowId => FieldDataType::UnsignedDataNumber,
            V9Field::ObservationDomainId => FieldDataType::UnsignedDataNumber,
            V9Field::FlowStartSeconds => FieldDataType::DurationSeconds,
            V9Field::FlowEndSeconds => FieldDataType::DurationSeconds,
            V9Field::FlowStartMilliseconds => FieldDataType::DurationMillis,
            V9Field::FlowEndMilliseconds => FieldDataType::DurationMillis,
            V9Field::FlowStartMicroseconds => FieldDataType::DurationMicrosNTP,
            V9Field::FlowEndMicroseconds => FieldDataType::DurationMicrosNTP,
            V9Field::FlowStartNanoseconds => FieldDataType::DurationNanosNTP,
            V9Field::FlowEndNanoseconds => FieldDataType::DurationNanosNTP,
            V9Field::FlowStartDeltaMicroseconds => FieldDataType::UnsignedDataNumber,
            V9Field::FlowEndDeltaMicroseconds => FieldDataType::UnsignedDataNumber,
            V9Field::SystemInitTimeMilliseconds => FieldDataType::DurationMillis,
            V9Field::FlowDurationMilliseconds => FieldDataType::DurationMillis,
            V9Field::FlowDurationMicroseconds => FieldDataType::UnsignedDataNumber,
            V9Field::ObservedFlowTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::IgnoredPacketTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::IgnoredOctetTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::NotSentFlowTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::NotSentPacketTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::NotSentOctetTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::DestinationIpv6Prefix => FieldDataType::Ip6Addr,
            V9Field::SourceIpv6Prefix => FieldDataType::Ip6Addr,
            V9Field::PostOctetTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::PostPacketTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::FlowKeyIndicator => FieldDataType::UnsignedDataNumber,
            V9Field::PostMcastPacketTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::PostMcastOctetTotalCount => FieldDataType::UnsignedDataNumber,
            V9Field::IcmpTypeValue => FieldDataType::UnsignedDataNumber,
            V9Field::IcmpCodeValue => FieldDataType::UnsignedDataNumber,
            V9Field::IcmpIpv6TypeValue => FieldDataType::UnsignedDataNumber,
            V9Field::IcmpIpv6CodeValue => FieldDataType::UnsignedDataNumber,
            V9Field::PostNATSourceIPv4Address => FieldDataType::Ip4Addr,
            V9Field::PostNATDestinationIPv4Address => FieldDataType::Ip4Addr,
            V9Field::PostNATTSourceTransportPort => FieldDataType::UnsignedDataNumber,
            V9Field::PostNATTDestinationTransportPort => FieldDataType::UnsignedDataNumber,
            V9Field::PostNATSourceIpv6Address => FieldDataType::Ip6Addr,
            V9Field::PostNATDestinationIpv6Address => FieldDataType::Ip6Addr,
            V9Field::ObservationTimeMilliseconds => FieldDataType::DurationMillis,
            V9Field::NatOriginatingAddressRealm => FieldDataType::NatOriginatingAddressRealm,
            V9Field::NatEvent => FieldDataType::NatEvent,
            V9Field::FirewallEvent => FieldDataType::FirewallEvent,
            V9Field::IngressVRFID | V9Field::EgressVRFID => FieldDataType::UnsignedDataNumber,
            V9Field::BiflowDirection => FieldDataType::UnsignedDataNumber,
            V9Field::IanaAssigned(_) | V9Field::Unknown(_) => FieldDataType::Unknown,
        }
    }
}

impl From<u16> for V9Field {
    fn from(item: u16) -> Self {
        match item {
            1 => V9Field::InBytes,
            2 => V9Field::InPkts,
            3 => V9Field::Flows,
            4 => V9Field::Protocol,
            5 => V9Field::SrcTos,
            6 => V9Field::TcpFlags,
            7 => V9Field::L4SrcPort,
            8 => V9Field::Ipv4SrcAddr,
            9 => V9Field::SrcMask,
            10 => V9Field::InputSnmp,
            11 => V9Field::L4DstPort,
            12 => V9Field::Ipv4DstAddr,
            13 => V9Field::DstMask,
            14 => V9Field::OutputSnmp,
            15 => V9Field::Ipv4NextHop,
            16 => V9Field::SrcAs,
            17 => V9Field::DstAs,
            18 => V9Field::BgpIpv4NextHop,
            19 => V9Field::MulDstPkts,
            20 => V9Field::MulDstBytes,
            21 => V9Field::LastSwitched,
            22 => V9Field::FirstSwitched,
            23 => V9Field::OutBytes,
            24 => V9Field::OutPkts,
            25 => V9Field::MinPktLngth,
            26 => V9Field::MaxPktLngth,
            27 => V9Field::Ipv6SrcAddr,
            28 => V9Field::Ipv6DstAddr,
            29 => V9Field::Ipv6SrcMask,
            30 => V9Field::Ipv6DstMask,
            31 => V9Field::Ipv6FlowLabel,
            32 => V9Field::IcmpType,
            33 => V9Field::MulIgmpType,
            34 => V9Field::SamplingInterval,
            35 => V9Field::SamplingAlgorithm,
            36 => V9Field::FlowActiveTimeout,
            37 => V9Field::FlowInactiveTimeout,
            38 => V9Field::EngineType,
            39 => V9Field::EngineId,
            40 => V9Field::TotalBytesExp,
            41 => V9Field::TotalPktsExp,
            42 => V9Field::TotalFlowsExp,
            43 => V9Field::IanaAssigned(43),
            44 => V9Field::Ipv4SrcPrefix,
            45 => V9Field::Ipv4DstPrefix,
            46 => V9Field::MplsTopLabelType,
            47 => V9Field::MplsTopLabelIpAddr,
            48 => V9Field::FlowSamplerId,
            49 => V9Field::FlowSamplerMode,
            50 => V9Field::FlowSamplerRandomInterval,
            51 => V9Field::IanaAssigned(51),
            52 => V9Field::MinTtl,
            53 => V9Field::MaxTtl,
            54 => V9Field::Ipv4Ident,
            55 => V9Field::DstTos,
            56 => V9Field::InSrcMac,
            57 => V9Field::OutDstMac,
            58 => V9Field::SrcVlan,
            59 => V9Field::DstVlan,
            60 => V9Field::IpProtocolVersion,
            61 => V9Field::Direction,
            62 => V9Field::Ipv6NextHop,
            63 => V9Field::BgpIpv6NextHop,
            64 => V9Field::Ipv6OptionHeaders,
            65 => V9Field::IanaAssigned(65),
            66 => V9Field::IanaAssigned(66),
            67 => V9Field::IanaAssigned(67),
            68 => V9Field::IanaAssigned(68),
            69 => V9Field::IanaAssigned(69),
            70 => V9Field::MplsLabel1,
            71 => V9Field::MplsLabel2,
            72 => V9Field::MplsLabel3,
            73 => V9Field::MplsLabel4,
            74 => V9Field::MplsLabel5,
            75 => V9Field::MplsLabel6,
            76 => V9Field::MplsLabel7,
            77 => V9Field::MplsLabel8,
            78 => V9Field::MplsLabel9,
            79 => V9Field::MplsLabel10,
            80 => V9Field::InDstMac,
            81 => V9Field::OutSrcMac,
            82 => V9Field::IfName,
            83 => V9Field::IfDesc,
            84 => V9Field::SamplerName,
            85 => V9Field::InPermanentBytes,
            86 => V9Field::InPermanentPkts,
            87 => V9Field::IanaAssigned(87),
            88 => V9Field::FragmentOffset,
            89 => V9Field::ForwardingStatus,
            90 => V9Field::MplsPalRd,
            91 => V9Field::MplsPrefixLen,
            92 => V9Field::SrcTrafficIndex,
            93 => V9Field::DstTrafficIndex,
            94 => V9Field::ApplicationDescription,
            95 => V9Field::ApplicationTag,
            96 => V9Field::ApplicationName,
            97 => V9Field::IanaAssigned(97),
            98 => V9Field::PostipDiffServCodePoint,
            99 => V9Field::Replicationfactor,
            100 => V9Field::Deprecated,
            101 => V9Field::IanaAssigned(101),
            102 => V9Field::Layer2packetSectionOffset,
            103 => V9Field::Layer2packetSectionSize,
            104 => V9Field::Layer2packetSectionData,
            105 => V9Field::IanaAssigned(105),
            106 => V9Field::IanaAssigned(106),
            107 => V9Field::IanaAssigned(107),
            108 => V9Field::IanaAssigned(108),
            109 => V9Field::IanaAssigned(109),
            110 => V9Field::IanaAssigned(110),
            111 => V9Field::IanaAssigned(111),
            112 => V9Field::IanaAssigned(112),
            113 => V9Field::IanaAssigned(113),
            114 => V9Field::IanaAssigned(114),
            115 => V9Field::IanaAssigned(115),
            116 => V9Field::IanaAssigned(116),
            117 => V9Field::IanaAssigned(117),
            118 => V9Field::IanaAssigned(118),
            119 => V9Field::IanaAssigned(119),
            120 => V9Field::IanaAssigned(120),
            121 => V9Field::IanaAssigned(121),
            122 => V9Field::IanaAssigned(122),
            123 => V9Field::IanaAssigned(123),
            124 => V9Field::IanaAssigned(124),
            125 => V9Field::IanaAssigned(125),
            126 => V9Field::IanaAssigned(126),
            127 => V9Field::IanaAssigned(127),
            128 => V9Field::BgpNextAdjacentAsNumber,
            129 => V9Field::BgpPrevAdjacentAsNumber,
            130 => V9Field::ExporterIpv4Address,
            131 => V9Field::ExporterIpv6Address,
            132 => V9Field::DroppedOctetDeltaCount,
            133 => V9Field::DroppedPacketDeltaCount,
            134 => V9Field::DroppedOctetTotalCount,
            135 => V9Field::DroppedPacketTotalCount,
            136 => V9Field::FlowEndReason,
            137 => V9Field::CommonPropertiesId,
            138 => V9Field::ObservationPointId,
            139 => V9Field::IcmpTypeCodeIpv6,
            140 => V9Field::MplsTopLabelIpv6Address,
            141 => V9Field::LineCardId,
            142 => V9Field::PortId,
            143 => V9Field::MeteringProcessId,
            144 => V9Field::ExportingProcessId,
            145 => V9Field::TemplateId,
            146 => V9Field::WlanChannelId,
            147 => V9Field::WlanSsid,
            148 => V9Field::FlowId,
            149 => V9Field::ObservationDomainId,
            150 => V9Field::FlowStartSeconds,
            151 => V9Field::FlowEndSeconds,
            152 => V9Field::FlowStartMilliseconds,
            153 => V9Field::FlowEndMilliseconds,
            154 => V9Field::FlowStartMicroseconds,
            155 => V9Field::FlowEndMicroseconds,
            156 => V9Field::FlowStartNanoseconds,
            157 => V9Field::FlowEndNanoseconds,
            158 => V9Field::FlowStartDeltaMicroseconds,
            159 => V9Field::FlowEndDeltaMicroseconds,
            160 => V9Field::SystemInitTimeMilliseconds,
            161 => V9Field::FlowDurationMilliseconds,
            162 => V9Field::FlowDurationMicroseconds,
            163 => V9Field::ObservedFlowTotalCount,
            164 => V9Field::IgnoredPacketTotalCount,
            165 => V9Field::IgnoredOctetTotalCount,
            166 => V9Field::NotSentFlowTotalCount,
            167 => V9Field::NotSentPacketTotalCount,
            168 => V9Field::NotSentOctetTotalCount,
            169 => V9Field::DestinationIpv6Prefix,
            170 => V9Field::SourceIpv6Prefix,
            171 => V9Field::PostOctetTotalCount,
            172 => V9Field::PostPacketTotalCount,
            173 => V9Field::FlowKeyIndicator,
            174 => V9Field::PostMcastPacketTotalCount,
            175 => V9Field::PostMcastOctetTotalCount,
            176 => V9Field::IcmpTypeValue,
            177 => V9Field::IcmpCodeValue,
            178 => V9Field::IcmpIpv6TypeValue,
            179 => V9Field::IcmpIpv6CodeValue,
            180..=224 => V9Field::IanaAssigned(item),
            225 => V9Field::PostNATSourceIPv4Address,
            226 => V9Field::PostNATDestinationIPv4Address,
            227 => V9Field::PostNATTSourceTransportPort,
            228 => V9Field::PostNATTDestinationTransportPort,
            229 => V9Field::NatOriginatingAddressRealm,
            230 => V9Field::NatEvent,
            231..=232 => V9Field::IanaAssigned(item),
            233 => V9Field::FirewallEvent,
            234 => V9Field::IngressVRFID,
            235 => V9Field::EgressVRFID,
            236..=238 => V9Field::IanaAssigned(item),
            239 => V9Field::BiflowDirection,
            240..=280 => V9Field::IanaAssigned(item),
            281 => V9Field::PostNATSourceIpv6Address,
            282 => V9Field::PostNATDestinationIpv6Address,
            283..=322 => V9Field::IanaAssigned(item),
            323 => V9Field::ObservationTimeMilliseconds,
            _ => V9Field::Unknown(item),
        }
    }
}

impl From<V9Field> for u16 {
    fn from(field: V9Field) -> Self {
        match field {
            V9Field::InBytes => 1,
            V9Field::InPkts => 2,
            V9Field::Flows => 3,
            V9Field::Protocol => 4,
            V9Field::SrcTos => 5,
            V9Field::TcpFlags => 6,
            V9Field::L4SrcPort => 7,
            V9Field::Ipv4SrcAddr => 8,
            V9Field::SrcMask => 9,
            V9Field::InputSnmp => 10,
            V9Field::L4DstPort => 11,
            V9Field::Ipv4DstAddr => 12,
            V9Field::DstMask => 13,
            V9Field::OutputSnmp => 14,
            V9Field::Ipv4NextHop => 15,
            V9Field::SrcAs => 16,
            V9Field::DstAs => 17,
            V9Field::BgpIpv4NextHop => 18,
            V9Field::MulDstPkts => 19,
            V9Field::MulDstBytes => 20,
            V9Field::LastSwitched => 21,
            V9Field::FirstSwitched => 22,
            V9Field::OutBytes => 23,
            V9Field::OutPkts => 24,
            V9Field::MinPktLngth => 25,
            V9Field::MaxPktLngth => 26,
            V9Field::Ipv6SrcAddr => 27,
            V9Field::Ipv6DstAddr => 28,
            V9Field::Ipv6SrcMask => 29,
            V9Field::Ipv6DstMask => 30,
            V9Field::Ipv6FlowLabel => 31,
            V9Field::IcmpType => 32,
            V9Field::MulIgmpType => 33,
            V9Field::SamplingInterval => 34,
            V9Field::SamplingAlgorithm => 35,
            V9Field::FlowActiveTimeout => 36,
            V9Field::FlowInactiveTimeout => 37,
            V9Field::EngineType => 38,
            V9Field::EngineId => 39,
            V9Field::TotalBytesExp => 40,
            V9Field::TotalPktsExp => 41,
            V9Field::TotalFlowsExp => 42,
            V9Field::Ipv4SrcPrefix => 44,
            V9Field::Ipv4DstPrefix => 45,
            V9Field::MplsTopLabelType => 46,
            V9Field::MplsTopLabelIpAddr => 47,
            V9Field::FlowSamplerId => 48,
            V9Field::FlowSamplerMode => 49,
            V9Field::FlowSamplerRandomInterval => 50,
            V9Field::MinTtl => 52,
            V9Field::MaxTtl => 53,
            V9Field::Ipv4Ident => 54,
            V9Field::DstTos => 55,
            V9Field::InSrcMac => 56,
            V9Field::OutDstMac => 57,
            V9Field::SrcVlan => 58,
            V9Field::DstVlan => 59,
            V9Field::IpProtocolVersion => 60,
            V9Field::Direction => 61,
            V9Field::Ipv6NextHop => 62,
            V9Field::BgpIpv6NextHop => 63,
            V9Field::Ipv6OptionHeaders => 64,
            V9Field::MplsLabel1 => 70,
            V9Field::MplsLabel2 => 71,
            V9Field::MplsLabel3 => 72,
            V9Field::MplsLabel4 => 73,
            V9Field::MplsLabel5 => 74,
            V9Field::MplsLabel6 => 75,
            V9Field::MplsLabel7 => 76,
            V9Field::MplsLabel8 => 77,
            V9Field::MplsLabel9 => 78,
            V9Field::MplsLabel10 => 79,
            V9Field::InDstMac => 80,
            V9Field::OutSrcMac => 81,
            V9Field::IfName => 82,
            V9Field::IfDesc => 83,
            V9Field::SamplerName => 84,
            V9Field::InPermanentBytes => 85,
            V9Field::InPermanentPkts => 86,
            V9Field::FragmentOffset => 88,
            V9Field::ForwardingStatus => 89,
            V9Field::MplsPalRd => 90,
            V9Field::MplsPrefixLen => 91,
            V9Field::SrcTrafficIndex => 92,
            V9Field::DstTrafficIndex => 93,
            V9Field::ApplicationDescription => 94,
            V9Field::ApplicationTag => 95,
            V9Field::ApplicationName => 96,
            V9Field::PostipDiffServCodePoint => 98,
            V9Field::Replicationfactor => 99,
            V9Field::Deprecated => 100,
            V9Field::Layer2packetSectionOffset => 102,
            V9Field::Layer2packetSectionSize => 103,
            V9Field::Layer2packetSectionData => 104,
            V9Field::BgpNextAdjacentAsNumber => 128,
            V9Field::BgpPrevAdjacentAsNumber => 129,
            V9Field::ExporterIpv4Address => 130,
            V9Field::ExporterIpv6Address => 131,
            V9Field::DroppedOctetDeltaCount => 132,
            V9Field::DroppedPacketDeltaCount => 133,
            V9Field::DroppedOctetTotalCount => 134,
            V9Field::DroppedPacketTotalCount => 135,
            V9Field::FlowEndReason => 136,
            V9Field::CommonPropertiesId => 137,
            V9Field::ObservationPointId => 138,
            V9Field::IcmpTypeCodeIpv6 => 139,
            V9Field::MplsTopLabelIpv6Address => 140,
            V9Field::LineCardId => 141,
            V9Field::PortId => 142,
            V9Field::MeteringProcessId => 143,
            V9Field::ExportingProcessId => 144,
            V9Field::TemplateId => 145,
            V9Field::WlanChannelId => 146,
            V9Field::WlanSsid => 147,
            V9Field::FlowId => 148,
            V9Field::ObservationDomainId => 149,
            V9Field::FlowStartSeconds => 150,
            V9Field::FlowEndSeconds => 151,
            V9Field::FlowStartMilliseconds => 152,
            V9Field::FlowEndMilliseconds => 153,
            V9Field::FlowStartMicroseconds => 154,
            V9Field::FlowEndMicroseconds => 155,
            V9Field::FlowStartNanoseconds => 156,
            V9Field::FlowEndNanoseconds => 157,
            V9Field::FlowStartDeltaMicroseconds => 158,
            V9Field::FlowEndDeltaMicroseconds => 159,
            V9Field::SystemInitTimeMilliseconds => 160,
            V9Field::FlowDurationMilliseconds => 161,
            V9Field::FlowDurationMicroseconds => 162,
            V9Field::ObservedFlowTotalCount => 163,
            V9Field::IgnoredPacketTotalCount => 164,
            V9Field::IgnoredOctetTotalCount => 165,
            V9Field::NotSentFlowTotalCount => 166,
            V9Field::NotSentPacketTotalCount => 167,
            V9Field::NotSentOctetTotalCount => 168,
            V9Field::DestinationIpv6Prefix => 169,
            V9Field::SourceIpv6Prefix => 170,
            V9Field::PostOctetTotalCount => 171,
            V9Field::PostPacketTotalCount => 172,
            V9Field::FlowKeyIndicator => 173,
            V9Field::PostMcastPacketTotalCount => 174,
            V9Field::PostMcastOctetTotalCount => 175,
            V9Field::IcmpTypeValue => 176,
            V9Field::IcmpCodeValue => 177,
            V9Field::IcmpIpv6TypeValue => 178,
            V9Field::IcmpIpv6CodeValue => 179,
            V9Field::PostNATSourceIPv4Address => 225,
            V9Field::PostNATDestinationIPv4Address => 226,
            V9Field::PostNATTSourceTransportPort => 227,
            V9Field::PostNATTDestinationTransportPort => 228,
            V9Field::NatOriginatingAddressRealm => 229,
            V9Field::NatEvent => 230,
            V9Field::FirewallEvent => 233,
            V9Field::IngressVRFID => 234,
            V9Field::EgressVRFID => 235,
            V9Field::BiflowDirection => 239,
            V9Field::PostNATSourceIpv6Address => 281,
            V9Field::PostNATDestinationIpv6Address => 282,
            V9Field::ObservationTimeMilliseconds => 323,
            V9Field::IanaAssigned(n) | V9Field::Unknown(n) => n,
        }
    }
}

#[cfg(test)]
mod v9_lookup_tests {

    use crate::variable_versions::field_value::FieldDataType;

    use super::V9Field;

    use insta::assert_yaml_snapshot;

    #[test]
    fn it_tests_field_lookup() {
        let mut fields = vec![];
        for i in 1..=323 {
            let field: V9Field = i.into();
            fields.push(field);
        }
        assert_yaml_snapshot!(fields);
    }

    #[test]
    fn it_tests_field_data_type_lookup() {
        let mut fields: Vec<FieldDataType> = vec![];
        for i in 1..=323 {
            let field: V9Field = i.into();
            fields.push(field.into());
        }
        assert_yaml_snapshot!(fields);
    }
}