Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tx only test added #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions feature/tx_only/otg_tests/tx_only_test/tx_only_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package tx_only_test

import (
"testing"
"time"

"github.com/open-traffic-generator/snappi/gosnappi"
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/ondatra"
otg "github.com/openconfig/ondatra/otg"
otgtelemetry "github.com/openconfig/ondatra/telemetry/otg"
)

func TestMain(m *testing.M) {
fptest.RunTests(m)
}
func configureOTGTxOnly(t *testing.T, otg *otg.OTG) gosnappi.Config {
config := otg.NewConfig(t)
port1 := config.Ports().Add().SetName("port1")
flow := config.Flows().Add().SetName("f1")
flow.Metrics().SetEnable(true)
flow.TxRx().SetChoice("port").Port().SetTxName(port1.Name())
flow.Duration().FixedPackets().SetPackets(100)
flow.Rate().SetPps(50)
eth := flow.Packet().Add().Ethernet()
eth.Dst().SetValue("00:AB:BC:AB:BC:AB")
eth.Src().SetValue("00:CD:DC:CD:DC:CD")

otg.PushConfig(t, config)
return config
}

func verifyTraffic(t *testing.T, ate *ondatra.ATEDevice, c gosnappi.Config, expectedPacket uint64) {
otg := ate.OTG()
for _, p := range c.Ports().Items() {
_, ok := otg.Telemetry().Port(p.Name()).Counters().OutFrames().Watch(t, time.Minute, func(val *otgtelemetry.QualifiedUint64) bool {
return val.IsPresent() && val.Val(t) == expectedPacket
}).Await(t)
if !ok {
t.Logf("Expected Tx Packets :%v, Actual: %v", expectedPacket, otg.Telemetry().Port(p.Name()).Counters().OutFrames().Get(t))
t.Fatal("Expected Packet Mismatch!!!")
}
}
for _, f := range c.Flows().Items() {
_, ok := otg.Telemetry().Flow(f.Name()).Counters().OutPkts().Watch(t, time.Minute, func(val *otgtelemetry.QualifiedUint64) bool {
return val.IsPresent() && val.Val(t) == expectedPacket
}).Await(t)
if !ok {
t.Logf("Expected Tx Packets :%v, Actual: %v", expectedPacket, otg.Telemetry().Flow(f.Name()).Counters().OutPkts().Get(t))
t.Fatal("Expected Packet Mismatch!!!")
}
}
t.Logf("Port and Flow Metrics is Ok!!!")
}

func TestOTGTxOnly(t *testing.T) {
ate := ondatra.ATE(t, "ate")
otg := ate.OTG()
otgConfig := configureOTGTxOnly(t, otg)

t.Logf("Setting config")
otg.PushConfig(t, otgConfig)

t.Logf("Starting traffic")
otg.StartTraffic(t)

t.Logf("Verify traffic")
verifyTraffic(t, ate, otgConfig, 100)

t.Logf("Stop traffic")
otg.StopTraffic(t)
}