@@ -104,6 +104,7 @@ func decodePacket6(t *testing.T, packetData []byte) uint8 {
104104// number of packets sent out.
105105func testTraffic (t * testing.T , top gosnappi.Config , ate * ondatra.ATEDevice , flows []gosnappi.Flow , srcEndPoint gosnappi.Port , duration int , cs gosnappi.ControlState ) int {
106106 t .Helper ()
107+ initialOutPkts := make (map [string ]uint64 , len (flows ))
107108 top .Flows ().Clear ()
108109 for _ , flow := range flows {
109110 flow .TxRx ().Port ().SetTxName (srcEndPoint .Name ()).SetRxName (srcEndPoint .Name ())
@@ -113,17 +114,20 @@ func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flow
113114 ate .OTG ().PushConfig (t , top )
114115 ate .OTG ().StartProtocols (t )
115116 time .Sleep (30 * time .Second )
117+ for _ , flow := range flows {
118+ initialOutPkts [flow .Name ()] = gnmi .Get (t , ate .OTG (), gnmi .OTG ().Flow (flow .Name ()).Counters ().OutPkts ().State ())
119+ }
116120 ate .OTG ().StartTraffic (t )
117121 time .Sleep (time .Duration (duration ) * time .Second )
118122 ate .OTG ().StopTraffic (t )
119123
120124 cs .Port ().Capture ().SetState (gosnappi .StatePortCaptureState .STOP )
121125 ate .OTG ().SetControlState (t , cs )
122126
123- outPkts := gnmi .GetAll (t , ate .OTG (), gnmi .OTG ().FlowAny ().Counters ().OutPkts ().State ())
124127 total := 0
125- for _ , count := range outPkts {
126- total += int (count )
128+ for _ , flow := range flows {
129+ current := gnmi .Get (t , ate .OTG (), gnmi .OTG ().Flow (flow .Name ()).Counters ().OutPkts ().State ())
130+ total += int (current - initialOutPkts [flow .Name ()])
127131 }
128132 return total
129133}
@@ -132,21 +136,15 @@ func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flow
132136// then validates packetin message metadata and payload.
133137func testPacketIn (ctx context.Context , t * testing.T , args * testArgs , isIPv4 bool , cs gosnappi.ControlState , flowValues []* flowArgs , EgressPortMap map [string ]bool ) []float64 {
134138 leader := args .leader
135- if isIPv4 {
136- // Insert p4rtutils acl entry on the DUT
137- if err := programmTableEntry (leader , args .packetIO , false , isIPv4 ); err != nil {
138- t .Fatalf ("There is error when programming entry" )
139- }
140- // Delete p4rtutils acl entry on the device
141- defer programmTableEntry (leader , args .packetIO , true , isIPv4 )
142- } else {
143- // Insert p4rtutils acl entry on the DUT
144- if err := programmTableEntry (leader , args .packetIO , false , false ); err != nil {
145- t .Fatalf ("There is error when programming entry" )
146- }
147- // Delete p4rtutils acl entry on the device
148- defer programmTableEntry (leader , args .packetIO , true , false )
139+ if err := programmTableEntry (leader , args .packetIO , false , true ); err != nil {
140+ t .Fatalf ("There is error when programming IPv4 entry" )
149141 }
142+ defer programmTableEntry (leader , args .packetIO , true , true )
143+ if err := programmTableEntry (leader , args .packetIO , false , false ); err != nil {
144+ t .Fatalf ("There is error when programming IPv6 entry" )
145+ }
146+ defer programmTableEntry (leader , args .packetIO , true , false )
147+
150148 streamChan := args .leader .StreamChannelGet (& streamName )
151149 qSize := 12000
152150 streamChan .SetArbQSize (qSize )
@@ -215,13 +213,13 @@ func testPacketIn(ctx context.Context, t *testing.T, args *testArgs, isIPv4 bool
215213 }
216214 if wantPacket .TTL != nil {
217215 // TTL/HopLimit comparison for IPV4 & IPV6
218- if isIPv4 {
216+ switch etherType {
217+ case layers .EthernetTypeIPv4 :
219218 captureTTL := decodePacket4 (t , packet .Pkt .GetPayload ())
220219 if captureTTL != TTL1 {
221220 t .Fatalf ("Packet in PacketIn message is not matching wanted packet=IPV4 TTL1" )
222221 }
223-
224- } else {
222+ case layers .EthernetTypeIPv6 :
225223 captureHopLimit := decodePacket6 (t , packet .Pkt .GetPayload ())
226224 if captureHopLimit != HopLimit1 {
227225 t .Fatalf ("Packet in PacketIn message is not matching wanted packet=IPV6 HopLimit1" )
0 commit comments