Skip to content

Commit

Permalink
OTG Test Update - TE-6.1 Stats check for continuous traffic (openconf…
Browse files Browse the repository at this point in the history
…ig#2169)

* Initial changes to TE-6.1

* removed sleep from LogFlowMetrics

* re-added the sleep

* GetFlowStats added in the otgutils
  • Loading branch information
octpetre authored Nov 16, 2023
1 parent b673016 commit bf1d71b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func testFlushWithDefaultNetworkInstance(ctx context.Context, t *testing.T, args
if got := lossPct; got > 0 {
t.Errorf("LossPct for flow got %v, want 0", got)
} else {
t.Log("Traffic can be forwarded between ATE port-1 and ATE port-2")
t.Log("Traffic is forwarded between ATE port-1 and ATE port-2")
}

// Flush should delete the entries
Expand All @@ -181,7 +181,7 @@ func testFlushWithDefaultNetworkInstance(ctx context.Context, t *testing.T, args
if got := lossPct; got == 0 {
t.Error("Traffic can still be forwarded between ATE port-1 and ATE port-2")
} else {
t.Log("Traffic can not be forwarded between ATE port-1 and ATE port-2")
t.Log("Traffic is not forwarded between ATE port-1 and ATE port-2")
}
if got, want := checkNIHasNEntries(ctx, args.clientA, deviations.DefaultNetworkInstance(args.dut), t), 0; got != want {
t.Errorf("Network instance has %d entry/entries, wanted: %d", got, want)
Expand Down Expand Up @@ -240,21 +240,11 @@ func configureATE(t *testing.T, ate *ondatra.ATEDevice) gosnappi.Config {
t.Helper()
top := gosnappi.NewConfig()

top.Ports().Add().SetName(ate.Port(t, "port1").ID())
i1 := top.Devices().Add().SetName(ate.Port(t, "port1").ID())
eth1 := i1.Ethernets().Add().SetName(atePort1.Name + ".Eth").SetMac(atePort1.MAC)
eth1.Connection().SetChoice(gosnappi.EthernetConnectionChoice.PORT_NAME).SetPortName(i1.Name())
eth1.Ipv4Addresses().Add().SetName(atePort1.Name + ".IPv4").
SetAddress(atePort1.IPv4).SetGateway(dutPort1.IPv4).
SetPrefix(uint32(atePort1.IPv4Len))

top.Ports().Add().SetName(ate.Port(t, "port2").ID())
i2 := top.Devices().Add().SetName(ate.Port(t, "port2").ID())
eth2 := i2.Ethernets().Add().SetName(atePort2.Name + ".Eth").SetMac(atePort2.MAC)
eth2.Connection().SetChoice(gosnappi.EthernetConnectionChoice.PORT_NAME).SetPortName(i2.Name())
eth2.Ipv4Addresses().Add().SetName(atePort2.Name + ".IPv4").
SetAddress(atePort2.IPv4).SetGateway(dutPort2.IPv4).
SetPrefix(uint32(atePort2.IPv4Len))
p1 := ate.Port(t, "port1")
p2 := ate.Port(t, "port2")

atePort1.AddToOTG(top, p1, &dutPort1)
atePort2.AddToOTG(top, p2, &dutPort2)

return top
}
Expand Down Expand Up @@ -318,17 +308,16 @@ func testTraffic(t *testing.T, ate *ondatra.ATEDevice, top gosnappi.Config) floa
// Ensure that traffic can be forwarded between ATE port-1 and ATE port-2.
t.Helper()
otg := ate.OTG()
dstMac := gnmi.Get(t, otg, gnmi.OTG().Interface(atePort1.Name+".Eth").Ipv4Neighbor(dutPort1.IPv4).LinkLayerAddress().State())
top.Flows().Clear().Items()
flowipv4 := top.Flows().Add().SetName("Flow")
flowipv4.Metrics().SetEnable(true)
flowipv4.TxRx().Port().
SetTxName(ate.Port(t, "port1").ID()).
SetRxName(ate.Port(t, "port2").ID())
flowipv4.TxRx().Device().
SetTxNames([]string{atePort1.Name + ".IPv4"}).
SetRxNames([]string{atePort2.Name + ".IPv4"})

flowipv4.Duration().SetChoice("continuous")
e1 := flowipv4.Packet().Add().Ethernet()
e1.Src().SetValue(atePort1.MAC)
e1.Dst().SetChoice("value").SetValue(dstMac)
v4 := flowipv4.Packet().Add().Ipv4()
v4.Src().SetValue(atePort1.IPv4)
v4.Dst().Increment().SetStart("198.51.100.1").SetCount(250)
Expand All @@ -340,14 +329,9 @@ func testTraffic(t *testing.T, ate *ondatra.ATEDevice, top gosnappi.Config) floa
t.Logf("Stop traffic")
otg.StopTraffic(t)

txPkts, rxPkts := otgutils.GetFlowStats(t, otg, "Flow", 5*time.Second)
otgutils.LogFlowMetrics(t, otg, top)
time.Sleep(time.Minute)
txPkts := float32(gnmi.Get(t, otg, gnmi.OTG().Flow("Flow").Counters().OutPkts().State()))
rxPkts := float32(gnmi.Get(t, otg, gnmi.OTG().Flow("Flow").Counters().InPkts().State()))
if txPkts == 0 {
t.Fatalf("TxPkts == 0, want > 0")
}
lossPct := (txPkts - rxPkts) * 100 / txPkts
lossPct := float32(txPkts-rxPkts) * 100 / float32(txPkts)
return lossPct
}

Expand Down
47 changes: 47 additions & 0 deletions internal/otgutils/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package otgutils

import (
"testing"
"time"

"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/otg"
"github.com/openconfig/ygnmi/ygnmi"
)

// GetFlowStats checks to see if all the flows are completely stopped and returns tx and rx packets for the given flow
func GetFlowStats(t testing.TB, otg *otg.OTG, flowName string, timeout time.Duration) (txPackets, rxPackets uint64) {
flow := gnmi.OTG().Flow(flowName)

_, watcher := gnmi.Watch(t, otg, flow.Transmit().State(), timeout, func(val *ygnmi.Value[bool]) bool {
transmitState, ok := val.Val()
return ok && !transmitState
}).Await(t)
if !watcher {
t.Logf("Flow still not stopped after %v. Stats may be inconsistent", timeout)
}
txPkts := gnmi.Get(t, otg, gnmi.OTG().Flow(flowName).Counters().OutPkts().State())

rxPkts, _ := gnmi.Watch(t, otg, gnmi.OTG().Flow(flowName).Counters().InPkts().State(), timeout, func(val *ygnmi.Value[uint64]) bool {
rxPackets, ok := val.Val()
return ok && rxPackets == txPkts
}).Await(t)
rx, _ := rxPkts.Val()

return txPkts, rx

}

0 comments on commit bf1d71b

Please sign in to comment.