From 7a6794cdddede6122f477def7f39d7f5a98fb871 Mon Sep 17 00:00:00 2001 From: MANSI AGARWAL Date: Thu, 30 Jul 2026 09:21:41 +0000 Subject: [PATCH 1/5] traceroute_packetin_with_vrf_selection_test: Replace fixed sleep with telemetry watch to reduce test execution time Refactor traffic waiting logic in to use on OTG telemetry counters instead of a fixed . This allows test cases to finish dynamically as soon as the target packet count (500 packets) is transmitted, significantly reducing total test execution time. In addition, cleaned up redundant , , and calls in and , ensuring OTG configuration and capture state are pushed once in after all flows are attached. - Replaced fixed sleep with on with an loop. - Cleaned up redundant OTG config push and protocol start calls. --- .../packetin_test.go | 20 ++++++++++++++++--- .../traceroute_packetin_test.go | 4 ---- ...eroute_packetin_with_vrf_selection_test.go | 5 ----- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go index 31a1fffbae1..b09acc005ac 100644 --- a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go +++ b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go @@ -102,7 +102,7 @@ func decodePacket6(t *testing.T, packetData []byte) uint8 { // testTraffic sends traffic flow for duration seconds and returns the // number of packets sent out. -func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flows []gosnappi.Flow, srcEndPoint gosnappi.Port, duration int, cs gosnappi.ControlState) int { +func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flows []gosnappi.Flow, srcEndPoint gosnappi.Port, targetPkts uint64, cs gosnappi.ControlState) int { t.Helper() initialOutPkts := make(map[string]uint64, len(flows)) top.Flows().Clear() @@ -114,11 +114,25 @@ func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flow ate.OTG().PushConfig(t, top) ate.OTG().StartProtocols(t) time.Sleep(30 * time.Second) + + // START THE PACKET CAPTURE AFTER CONFIG IS PUSHED + ate.OTG().SetControlState(t, cs) + for _, flow := range flows { initialOutPkts[flow.Name()] = gnmi.Get(t, ate.OTG(), gnmi.OTG().Flow(flow.Name()).Counters().OutPkts().State()) } ate.OTG().StartTraffic(t) - time.Sleep(time.Duration(duration) * time.Second) + // AWAIT LOGIC INSTEAD OF SLEEP + for _, flow := range flows { + _, ok := gnmi.Watch(t, ate.OTG(), gnmi.OTG().Flow(flow.Name()).Counters().OutPkts().State(), time.Minute, func(val *ygnmi.Value[uint64]) bool { + pkts, present := val.Val() + return present && (pkts >= initialOutPkts[flow.Name()]+targetPkts) + }).Await(t) + + if !ok { + t.Errorf("Traffic flow %s did not reach the target of %d packets within the timeout", flow.Name(), targetPkts) + } + } ate.OTG().StopTraffic(t) cs.Port().Capture().SetState(gosnappi.StatePortCaptureState.STOP) @@ -174,7 +188,7 @@ func testPacketIn(ctx context.Context, t *testing.T, args *testArgs, isIPv4 bool for _, flowValue := range flowValues { flow = append(flow, args.packetIO.GetTrafficFlow(args.ate, dstMac, isIPv4, 1, 300, 50, ipv4InnerDst, flowValue)) } - pktOut := testTraffic(t, args.top, args.ate, flow, srcEndPoint, 60, cs) + pktOut := testTraffic(t, args.top, args.ate, flow, srcEndPoint, 500, cs) var countPkts = map[string]int{"11": 0, "12": 0, "13": 0, "14": 0, "15": 0, "16": 0, "17": 0} packetInTests := []struct { diff --git a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_test.go b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_test.go index 5e9de62b889..819e4eb720e 100644 --- a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_test.go +++ b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_test.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "testing" - "time" "github.com/cisco-open/go-p4/p4rt_client" "github.com/cisco-open/go-p4/utils" @@ -133,9 +132,6 @@ func testPacket(t *testing.T, args *testArgs, cs gosnappi.ControlState, flowValu configureDeviceID(ctx, t, dut) - ate.OTG().PushConfig(t, top) - ate.OTG().StartProtocols(t) - time.Sleep(30 * time.Second) args = &testArgs{ ctx: ctx, diff --git a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_with_vrf_selection_test.go b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_with_vrf_selection_test.go index 295dc4558c7..9ea473c55b6 100644 --- a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_with_vrf_selection_test.go +++ b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_with_vrf_selection_test.go @@ -955,13 +955,8 @@ func startCapture(t *testing.T, args *testArgs, capturePortList []string) gosnap args.otgConfig.Captures().Add().SetName("packetCapture"). SetPortNames(capturePortList). SetFormat(gosnappi.CaptureFormat.PCAP) - args.otg.PushConfig(t, args.otgConfig) - time.Sleep(30 * time.Second) - args.otg.StartProtocols(t) - time.Sleep(30 * time.Second) cs := gosnappi.NewControlState() cs.Port().Capture().SetState(gosnappi.StatePortCaptureState.START) - args.otg.SetControlState(t, cs) return cs } From ea9d4bfdf3edb2694d5f1d5fefb80649f27cbacc Mon Sep 17 00:00:00 2001 From: MANSI AGARWAL Date: Thu, 30 Jul 2026 16:22:25 +0000 Subject: [PATCH 2/5] Replace hardcoded sleeps with otgutils.WaitForARP and gNMI packet await logic --- .../packetin_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go index b09acc005ac..1fddbf39b62 100644 --- a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go +++ b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go @@ -28,6 +28,7 @@ import ( "github.com/google/gopacket/layers" "github.com/open-traffic-generator/snappi/gosnappi" "github.com/openconfig/featureprofiles/internal/p4rtutils" + "github.com/openconfig/featureprofiles/internal/otgutils" "github.com/openconfig/ondatra" "github.com/openconfig/ondatra/gnmi" "github.com/openconfig/ygnmi/ygnmi" @@ -113,7 +114,8 @@ func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flow } ate.OTG().PushConfig(t, top) ate.OTG().StartProtocols(t) - time.Sleep(30 * time.Second) + otgutils.WaitForARP(t, ate.OTG(), top, "IPv4") + otgutils.WaitForARP(t, ate.OTG(), top, "IPv6") // START THE PACKET CAPTURE AFTER CONFIG IS PUSHED ate.OTG().SetControlState(t, cs) From 92206413d6b66c8a6fd2586d93d708fc992948cb Mon Sep 17 00:00:00 2001 From: MANSI AGARWAL Date: Fri, 31 Jul 2026 10:34:56 +0000 Subject: [PATCH 3/5] style: fix gofmt formatting issues in traceroute_packetin_with_vrf_selection_test --- .../packetin_test.go | 2 +- .../traceroute_packetin_test.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go index 1fddbf39b62..422abadc253 100644 --- a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go +++ b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go @@ -27,8 +27,8 @@ import ( "github.com/google/gopacket" "github.com/google/gopacket/layers" "github.com/open-traffic-generator/snappi/gosnappi" - "github.com/openconfig/featureprofiles/internal/p4rtutils" "github.com/openconfig/featureprofiles/internal/otgutils" + "github.com/openconfig/featureprofiles/internal/p4rtutils" "github.com/openconfig/ondatra" "github.com/openconfig/ondatra/gnmi" "github.com/openconfig/ygnmi/ygnmi" diff --git a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_test.go b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_test.go index 819e4eb720e..1cef1b73af5 100644 --- a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_test.go +++ b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/traceroute_packetin_test.go @@ -132,7 +132,6 @@ func testPacket(t *testing.T, args *testArgs, cs gosnappi.ControlState, flowValu configureDeviceID(ctx, t, dut) - args = &testArgs{ ctx: ctx, leader: args.leader, From ddde38dc6e29464faa2e2d08205d17c9bd4354cf Mon Sep 17 00:00:00 2001 From: MANSI AGARWAL Date: Tue, 4 Aug 2026 10:06:18 +0000 Subject: [PATCH 4/5] refactor: use defer for traffic/capture cleanup and const for targetPkts --- .../packetin_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go index 422abadc253..ba54b1f9c7c 100644 --- a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go +++ b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go @@ -119,11 +119,17 @@ func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flow // START THE PACKET CAPTURE AFTER CONFIG IS PUSHED ate.OTG().SetControlState(t, cs) + defer func() { + cs.Port().Capture().SetState(gosnappi.StatePortCaptureState.STOP) + ate.OTG().SetControlState(t, cs) + }() for _, flow := range flows { initialOutPkts[flow.Name()] = gnmi.Get(t, ate.OTG(), gnmi.OTG().Flow(flow.Name()).Counters().OutPkts().State()) } ate.OTG().StartTraffic(t) + defer ate.OTG().StopTraffic(t) + // AWAIT LOGIC INSTEAD OF SLEEP for _, flow := range flows { _, ok := gnmi.Watch(t, ate.OTG(), gnmi.OTG().Flow(flow.Name()).Counters().OutPkts().State(), time.Minute, func(val *ygnmi.Value[uint64]) bool { @@ -132,13 +138,9 @@ func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flow }).Await(t) if !ok { - t.Errorf("Traffic flow %s did not reach the target of %d packets within the timeout", flow.Name(), targetPkts) + t.Fatalf("Traffic flow %s did not reach the target of %d packets within the timeout", flow.Name(), targetPkts) } } - ate.OTG().StopTraffic(t) - - cs.Port().Capture().SetState(gosnappi.StatePortCaptureState.STOP) - ate.OTG().SetControlState(t, cs) total := 0 for _, flow := range flows { @@ -151,6 +153,7 @@ func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flow // testPacketIn programs p4rt table entry and sends traffic related to Traceroute, // then validates packetin message metadata and payload. func testPacketIn(ctx context.Context, t *testing.T, args *testArgs, isIPv4 bool, cs gosnappi.ControlState, flowValues []*flowArgs, EgressPortMap map[string]bool) []float64 { + const targetPkts = 500 leader := args.leader if err := programmTableEntry(leader, args.packetIO, false, true); err != nil { t.Fatalf("There is error when programming IPv4 entry") @@ -190,7 +193,7 @@ func testPacketIn(ctx context.Context, t *testing.T, args *testArgs, isIPv4 bool for _, flowValue := range flowValues { flow = append(flow, args.packetIO.GetTrafficFlow(args.ate, dstMac, isIPv4, 1, 300, 50, ipv4InnerDst, flowValue)) } - pktOut := testTraffic(t, args.top, args.ate, flow, srcEndPoint, 500, cs) + pktOut := testTraffic(t, args.top, args.ate, flow, srcEndPoint, targetPkts, cs) var countPkts = map[string]int{"11": 0, "12": 0, "13": 0, "14": 0, "15": 0, "16": 0, "17": 0} packetInTests := []struct { From 2511050da8481006a4ab9c2df029a124dd0d916c Mon Sep 17 00:00:00 2001 From: MANSI AGARWAL Date: Wed, 5 Aug 2026 06:35:27 +0000 Subject: [PATCH 5/5] updated the targetPkts size from 500 to 1000 --- .../packetin_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go index ba54b1f9c7c..7768c664092 100644 --- a/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go +++ b/feature/p4rt/otg_tests/traceroute_packetin_with_vrf_selection_test/packetin_test.go @@ -153,7 +153,7 @@ func testTraffic(t *testing.T, top gosnappi.Config, ate *ondatra.ATEDevice, flow // testPacketIn programs p4rt table entry and sends traffic related to Traceroute, // then validates packetin message metadata and payload. func testPacketIn(ctx context.Context, t *testing.T, args *testArgs, isIPv4 bool, cs gosnappi.ControlState, flowValues []*flowArgs, EgressPortMap map[string]bool) []float64 { - const targetPkts = 500 + const targetPkts = 1000 leader := args.leader if err := programmTableEntry(leader, args.packetIO, false, true); err != nil { t.Fatalf("There is error when programming IPv4 entry")