@@ -385,3 +385,345 @@ func TestStatisticsTCPUnmarshaling(t *testing.T) {
385385 })
386386 }
387387}
388+
389+ func TestStatisticsARPUnmarshaling (t * testing.T ) {
390+ type testCase struct {
391+ name string
392+ xmlFile string
393+ expect SystemStatistics
394+ }
395+
396+ tests := []testCase {
397+ {
398+ name : "complete_arp_statistics" ,
399+ xmlFile : "testsFiles/ARP/ARPTestDataCase1.xml" ,
400+ expect : SystemStatistics {
401+ Statistics : Statistics {
402+ Arp : ARP {
403+ DatagramsReceived : 5000 ,
404+ ArpRequestsReceived : 5001 ,
405+ ArpRepliesReceived : 5002 ,
406+ ResolutionRequestReceived : 5003 ,
407+ ResolutionRequestDropped : 5004 ,
408+ UnrestrictedProxyRequests : 5005 ,
409+ RestrictedProxyRequests : 5006 ,
410+ ReceivedProxyRequests : 5007 ,
411+ ProxyRequestsNotProxied : 5008 ,
412+ RestrictedProxyRequestsNotProxied : 5009 ,
413+ DatagramsWithBogusInterface : 5010 ,
414+ DatagramsWithIncorrectLength : 5011 ,
415+ DatagramsForNonIpProtocol : 5012 ,
416+ DatagramsWithUnsupportedOpcode : 5013 ,
417+ DatagramsWithBadProtocolAddressLength : 5014 ,
418+ DatagramsWithBadHardwareAddressLength : 5015 ,
419+ DatagramsWithMulticastSourceAddress : 5016 ,
420+ DatagramsWithMulticastTargetAddress : 5017 ,
421+ DatagramsWithMyOwnHardwareAddress : 5018 ,
422+ DatagramsForAnAddressNotOnTheInterface : 5019 ,
423+ DatagramsWithABroadcastSourceAddress : 5020 ,
424+ DatagramsWithSourceAddressDuplicateToMine : 5021 ,
425+ DatagramsWhichWereNotForMe : 5022 ,
426+ PacketsDiscardedWaitingForResolution : 5023 ,
427+ PacketsSentAfterWaitingForResolution : 5024 ,
428+ ArpRequestsSent : 5025 ,
429+ ArpRepliesSent : 5026 ,
430+ RequestsForMemoryDenied : 5027 ,
431+ RequestsDroppedOnEntry : 5028 ,
432+ RequestsDroppedDuringRetry : 5029 ,
433+ RequestsDroppedDueToInterfaceDeletion : 5030 ,
434+ RequestsOnUnnumberedInterfaces : 5031 ,
435+ NewRequestsOnUnnumberedInterfaces : 5032 ,
436+ RepliesFromUnnumberedInterfaces : 5033 ,
437+ RequestsOnUnnumberedInterfaceWithNonSubnettedDonor : 5034 ,
438+ RepliesFromUnnumberedInterfaceWithNonSubnettedDonor : 5035 ,
439+ ArpPacketsRejectedAsFamilyIsConfiguredWithDenyArp : 5036 ,
440+ ArpResponsePacketsAreRejectedOnMcAeIclInterface : 5037 ,
441+ ArpRepliesAreRejectedAsSourceAndDestinationIsSame : 5038 ,
442+ ArpProbeForProxyAddressReachableFromTheIncomingInterface : 5039 ,
443+ ArpRequestDiscardedForVrrpSourceAddress : 5040 ,
444+ SelfArpRequestPacketReceivedOnIrbInterface : 5041 ,
445+ ProxyArpRequestDiscardedAsSourceIpIsAProxyTarget : 5042 ,
446+ ArpPacketsAreDroppedAsNexthopAllocationFailed : 5043 ,
447+ ArpPacketsReceivedFromPeerVrrpRouterAndDiscarded : 5044 ,
448+ ArpPacketsAreRejectedAsTargetIpArpResolveIsInProgress : 5045 ,
449+ GratArpPacketsAreIgnoredAsMacAddressIsNotChanged : 5046 ,
450+ ArpPacketsAreDroppedFromPeerVrrp : 5047 ,
451+ ArpPacketsAreDroppedAsDriverCallFailed : 5048 ,
452+ ArpPacketsAreDroppedAsSourceIsNotValidated : 5049 ,
453+ ArpSystemMax : 5050 ,
454+ ArpPublicMax : 5051 ,
455+ ArpIriMax : 5052 ,
456+ ArpMgtMax : 5053 ,
457+ ArpPublicCnt : 5054 ,
458+ ArpIriCnt : 5055 ,
459+ ArpMgtCnt : 5056 ,
460+ ArpSystemDrop : 5057 ,
461+ ArpPublicDrop : 5058 ,
462+ ArpIriDrop : 5059 ,
463+ ArpMgtDrop : 5060 ,
464+ },
465+ },
466+ },
467+ },
468+ }
469+
470+ for _ , tc := range tests {
471+ t .Run (tc .name , func (t * testing.T ) {
472+ fc , err := os .ReadFile (tc .xmlFile )
473+ if err != nil {
474+ log .Fatal ("failed to read xml file in ARP testing due to: " , err )
475+ }
476+ var result SystemStatistics
477+ err = xml .Unmarshal (fc , & result )
478+ if err != nil {
479+ log .Fatal ("failed to unmarshal xml file in ARP testing due to: " , err )
480+ }
481+
482+ result .Statistics .Arp .Text = ""
483+ assert .Equal (t , tc .expect .Statistics .Arp , result .Statistics .Arp , tc .name )
484+ assert .NoError (t , err , "unmarshal should not return error" )
485+ })
486+ }
487+ }
488+
489+ func TestStatisticsICMPUnmarshaling (t * testing.T ) {
490+ type testCase struct {
491+ name string
492+ xmlFile string
493+ expect SystemStatistics
494+ }
495+ tests := []testCase {
496+ {
497+ name : "complete_icmp_statistics" ,
498+ xmlFile : "testsFiles/ICMP/ICMPTestDataCase1.xml" ,
499+ expect : SystemStatistics {
500+ Statistics : Statistics {
501+ Icmp : ICMP {
502+ DropsDueToRateLimit : 6000 ,
503+ CallsToIcmpError : 6001 ,
504+ ErrorsNotGeneratedBecauseOldMessageWasIcmp : 6002 ,
505+ Histogram : []ICMPHistogram {
506+ {
507+ IcmpEchoReply : 6003 ,
508+ DestinationUnreachable : 6004 ,
509+ IcmpEcho : 6005 ,
510+ TimeStampReply : 6006 ,
511+ TimeExceeded : 6007 ,
512+ TimeStamp : 6008 ,
513+ AddressMaskRequest : 6009 ,
514+ AnEndpointChangedItsCookieSecret : 6010 ,
515+ },
516+ {
517+ IcmpEchoReply : 6011 ,
518+ DestinationUnreachable : 6012 ,
519+ IcmpEcho : 6013 ,
520+ TimeStampReply : 6014 ,
521+ TimeExceeded : 6015 ,
522+ TimeStamp : 6016 ,
523+ AddressMaskRequest : 6017 ,
524+ AnEndpointChangedItsCookieSecret : 6018 ,
525+ },
526+ },
527+ MessagesWithBadCodeFields : 6019 ,
528+ MessagesLessThanTheMinimumLength : 6020 ,
529+ MessagesWithBadChecksum : 6021 ,
530+ MessagesWithBadSourceAddress : 6022 ,
531+ MessagesWithBadLength : 6023 ,
532+ EchoDropsWithBroadcastOrMulticastDestinatonAddress : 6024 ,
533+ TimestampDropsWithBroadcastOrMulticastDestinationAddress : 6025 ,
534+ MessageResponsesGenerated : 6026 ,
535+ },
536+ },
537+ },
538+ },
539+ }
540+
541+ for _ , tc := range tests {
542+ t .Run (tc .name , func (t * testing.T ) {
543+ fc , err := os .ReadFile (tc .xmlFile )
544+ if err != nil {
545+ log .Fatal ("failed to read xml file in ICMP testing due to: " , err )
546+ }
547+ var result SystemStatistics
548+ err = xml .Unmarshal (fc , & result )
549+ if err != nil {
550+ log .Fatal ("failed to unmarshal xml file in ICMP testing due to: " , err )
551+ }
552+ for i , _ := range result .Statistics .Icmp .Histogram {
553+ result .Statistics .Icmp .Histogram [i ].Text = ""
554+ result .Statistics .Icmp .Histogram [i ].TypeOfHistogram = ""
555+ }
556+ result .Statistics .Icmp .Text = ""
557+ assert .Equal (t , tc .expect .Statistics .Icmp , result .Statistics .Icmp , tc .name )
558+ assert .NoError (t , err , "unmarshal should not return error" )
559+ })
560+ }
561+ }
562+
563+ func TestStatisticsICMP6Unmarshaling (t * testing.T ) {
564+ type testCase struct {
565+ name string
566+ xmlFile string
567+ expect SystemStatistics
568+ }
569+ tests := []testCase {
570+ {
571+ name : "complete_icmp6_statistics" ,
572+ xmlFile : "testsFiles/ICMP6/ICMP6TestDataCase1.xml" ,
573+ expect : SystemStatistics {
574+ Statistics : Statistics {
575+ Icmp6 : ICMP6 {
576+ CallsToIcmp6Error : 7000 ,
577+ ErrorsNotGeneratedBecauseOldMessageWasIcmpError : 7001 ,
578+ ErrorsNotGeneratedBecauseRateLimitation : 7002 ,
579+ OutputHistogram : ICMP6OutputHistogram {
580+ UnreachableIcmp6Packets : 7003 ,
581+ Icmp6Echo : 7004 ,
582+ Icmp6EchoReply : 7005 ,
583+ NeighborSolicitation : 7006 ,
584+ NeighborAdvertisement : 7007 ,
585+ },
586+ Icmp6MessagesWithBadCodeFields : 7008 ,
587+ MessagesLessThanMinimumLength : 7009 ,
588+ BadChecksums : 7010 ,
589+ Icmp6MessagesWithBadLength : 7011 ,
590+ InputHistogram : ICMP6InputHistogram {
591+ UnreachableIcmp6Packets : 7012 ,
592+ PacketTooBig : 7013 ,
593+ TimeExceededIcmp6Packets : 7014 ,
594+ Icmp6Echo : 7015 ,
595+ Icmp6EchoReply : 7016 ,
596+ RouterSolicitationIcmp6Packets : 7017 ,
597+ NeighborSolicitation : 7018 ,
598+ NeighborAdvertisement : 7019 ,
599+ },
600+ NoRoute : 7020 ,
601+ AdministrativelyProhibited : 7021 ,
602+ BeyondScope : 7022 ,
603+ AddressUnreachable : 7023 ,
604+ PortUnreachable : 7024 ,
605+ PacketTooBig : 7025 ,
606+ TimeExceedTransit : 7026 ,
607+ TimeExceedReassembly : 7027 ,
608+ ErroneousHeaderField : 7028 ,
609+ UnrecognizedNextHeader : 7029 ,
610+ UnrecognizedOption : 7030 ,
611+ Redirect : 7031 ,
612+ Unknown : 7032 ,
613+ Icmp6MessageResponsesGenerated : 7033 ,
614+ MessagesWithTooManyNdOptions : 7034 ,
615+ NdSystemMax : 7035 ,
616+ NdPublicMax : 7036 ,
617+ NdIriMax : 7037 ,
618+ NdMgtMax : 7038 ,
619+ NdPublicCnt : 7039 ,
620+ NdIriCnt : 7040 ,
621+ NdMgtCnt : 7041 ,
622+ NdSystemDrop : 7042 ,
623+ NdPublicDrop : 7043 ,
624+ NdIriDrop : 7044 ,
625+ NdMgtDrop : 7045 ,
626+ Nd6NdpProxyRequests : 7046 ,
627+ Nd6DadProxyRequests : 7047 ,
628+ Nd6NdpProxyResponses : 7048 ,
629+ Nd6DadProxyConflicts : 7049 ,
630+ Nd6DupProxyResponses : 7050 ,
631+ Nd6NdpProxyResolveCnt : 7051 ,
632+ Nd6DadProxyResolveCnt : 7052 ,
633+ Nd6DadProxyEqmacDrop : 7053 ,
634+ Nd6DadProxyNomacDrop : 7054 ,
635+ Nd6NdpProxyUnrRequests : 7055 ,
636+ Nd6DadProxyUnrRequests : 7056 ,
637+ Nd6NdpProxyUnrResponses : 7057 ,
638+ Nd6DadProxyUnrConflicts : 7058 ,
639+ Nd6DadProxyUnrResponses : 7059 ,
640+ Nd6NdpProxyUnrResolveCnt : 7060 ,
641+ Nd6DadProxyUnrResolveCnt : 7061 ,
642+ Nd6DadProxyUnrEqportDrop : 7062 ,
643+ Nd6DadProxyUnrNomacDrop : 7063 ,
644+ Nd6RequestsDroppedOnEntry : 7064 ,
645+ Nd6RequestsDroppedDuringRetry : 7065 ,
646+ },
647+ },
648+ },
649+ },
650+ }
651+
652+ for _ , tc := range tests {
653+ t .Run (tc .name , func (t * testing.T ) {
654+ fc , err := os .ReadFile (tc .xmlFile )
655+ if err != nil {
656+ log .Fatal ("failed to read xml file in ICMP6 testing due to: " , err )
657+ }
658+ var result SystemStatistics
659+ err = xml .Unmarshal (fc , & result )
660+ if err != nil {
661+ log .Fatal ("failed to unmarshal xml file in ICMP6 testing due to: " , err )
662+ }
663+ result .Statistics .Icmp6 .Text = ""
664+ result .Statistics .Icmp6 .HistogramOfErrorMessagesToBeGenerated = ""
665+ result .Statistics .Icmp6 .InputHistogram .Text = ""
666+ result .Statistics .Icmp6 .OutputHistogram .Text = ""
667+ result .Statistics .Icmp6 .InputHistogram .HistogramType = ""
668+ result .Statistics .Icmp6 .OutputHistogram .HistogramType = ""
669+ result .Statistics .Icmp6 .InputHistogram .Style = ""
670+ result .Statistics .Icmp6 .OutputHistogram .Style = ""
671+ assert .Equal (t , tc .expect .Statistics .Icmp6 , result .Statistics .Icmp6 , tc .name )
672+ assert .NoError (t , err , "unmarshal should not return error" )
673+ })
674+ }
675+ }
676+
677+ func TestStatisticsMPLSUnmarshaling (t * testing.T ) {
678+ type testCase struct {
679+ name string
680+ xmlFile string
681+ expect SystemStatistics
682+ }
683+ tests := []testCase {
684+ {
685+ name : "complete_mpls_statistics" ,
686+ xmlFile : "testsFiles/MPLS/MPLSTestDataCase1.xml" ,
687+ expect : SystemStatistics {
688+ Statistics : Statistics {
689+ Mpls : MPLS {
690+ TotalMplsPacketsReceived : 8000 ,
691+ PacketsForwarded : 8001 ,
692+ PacketsDropped : 8002 ,
693+ PacketsWithHeaderTooSmall : 8003 ,
694+ AfterTaggingPacketsCanNotFitLinkMtu : 8004 ,
695+ PacketsWithIpv4ExplicitNullTag : 8005 ,
696+ PacketsWithIpv4ExplicitNullChecksumErrors : 8006 ,
697+ PacketsWithRouterAlertTag : 8007 ,
698+ LspPingPackets : 8008 ,
699+ PacketsWithTtlExpired : 8009 ,
700+ PacketsWithTagEncodingError : 8010 ,
701+ PacketsDiscardedDueToNoRoute : 8011 ,
702+ PacketsUsedFirstNexthopInEcmpUnilist : 8012 ,
703+ PacketsDroppedDueToIflDown : 8013 ,
704+ PacketsDroppedAtMplsSocketSend : 8014 ,
705+ PacketsForwardedAtMplsSocketSend : 8015 ,
706+ PacketsDroppedAtP2mpCnhOutput : 8016 ,
707+ },
708+ },
709+ },
710+ },
711+ }
712+
713+ for _ , tc := range tests {
714+ t .Run (tc .name , func (t * testing.T ) {
715+ fc , err := os .ReadFile (tc .xmlFile )
716+ if err != nil {
717+ log .Fatal ("failed to read xml file in MPLS testing due to: " , err )
718+ }
719+ var result SystemStatistics
720+ err = xml .Unmarshal (fc , & result )
721+ if err != nil {
722+ log .Fatal ("failed to unmarshal xml file in MPLS testing due to: " , err )
723+ }
724+ result .Statistics .Mpls .Text = ""
725+ assert .Equal (t , tc .expect .Statistics .Mpls , result .Statistics .Mpls , tc .name )
726+ assert .NoError (t , err , "unmarshal should not return error" )
727+ })
728+ }
729+ }
0 commit comments