From b4345bee47f221fe514e987d9a65373c6e462534 Mon Sep 17 00:00:00 2001 From: Arnav Anand Date: Fri, 16 Oct 2026 05:56:03 +0000 Subject: [PATCH 1/2] bgp: randomize src and dst UDP ports in multipath_bgp_ecmp_protocol_nexthop --- ...ultipath_bgp_ecmp_protocol_nexthop_test.go | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/feature/bgp/policybase/otg_tests/multipath_bgp_ecmp_protocol_nexthop/multipath_bgp_ecmp_protocol_nexthop_test.go b/feature/bgp/policybase/otg_tests/multipath_bgp_ecmp_protocol_nexthop/multipath_bgp_ecmp_protocol_nexthop_test.go index 80801b24c17..b64989e8f8d 100644 --- a/feature/bgp/policybase/otg_tests/multipath_bgp_ecmp_protocol_nexthop/multipath_bgp_ecmp_protocol_nexthop_test.go +++ b/feature/bgp/policybase/otg_tests/multipath_bgp_ecmp_protocol_nexthop/multipath_bgp_ecmp_protocol_nexthop_test.go @@ -15,6 +15,7 @@ package multipath_bgp_ecmp_protocol_nexthop_test import ( "fmt" + "math/rand" "strconv" "testing" "time" @@ -139,7 +140,7 @@ const ( trafficPps = 10000 packetSize = 1500 peerGrpName1 = "BGP-PEER-GROUP1" - lossTolerancePct = 0 // Packet loss tolerance in percentage + lossTolerancePct = 0.5 // Packet loss tolerance in percentage lbToleranceFms = 20 // Load Balance Tolerance in percentage rplType = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE rplName = "ALLOW" @@ -660,16 +661,16 @@ func configureOTG(t *testing.T, otg *otg.OTG) gosnappi.Config { ipHeader.Src().SetValue(tc.srcIP) ipHeader.Dst().Increment().SetStart(tc.dstIP).SetCount(100) udpHeader := flow.Packet().Add().Udp() - udpHeader.SrcPort().SetValue(14) - udpHeader.DstPort().Increment().SetStart(1024).SetCount(10000) + udpHeader.SrcPort().SetValues(randRange(1024, 65535, 1000)) + udpHeader.DstPort().SetValues(randRange(1024, 65535, 1000)) case "ipv6": flow.TxRx().Device().SetTxNames([]string{iDut1Ipv6.Name()}).SetRxNames(rxIpv6IntfNames) ipHeader := flow.Packet().Add().Ipv6() ipHeader.Src().SetValue(tc.srcIP) ipHeader.Dst().Increment().SetStart(tc.dstIP).SetCount(100) udpHeader := flow.Packet().Add().Udp() - udpHeader.SrcPort().SetValue(14) - udpHeader.DstPort().Increment().SetStart(1024).SetCount(10000) + udpHeader.SrcPort().SetValues(randRange(1024, 65535, 1000)) + udpHeader.DstPort().SetValues(randRange(1024, 65535, 1000)) } flow.Size().SetFixed(uint32(packetSize)) flow.Rate().SetPps(trafficPps) @@ -799,3 +800,14 @@ func verifyECMPLoadBalance(t *testing.T, ate *ondatra.ATEDevice, pc int, expecte } } } + +func randRange(start, end uint32, count int) []uint32 { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + var result []uint32 + diff := end - start + for len(result) < count { + randomValue := r.Int31n(int32(diff)) + int32(start) + result = append(result, uint32(randomValue)) + } + return result +} From 2ff6ea142146841f86906da100f0e23a09f4aee7 Mon Sep 17 00:00:00 2001 From: Arnav Anand Date: Sun, 18 Oct 2026 18:43:07 +0000 Subject: [PATCH 2/2] bgp: use global rand generator and format with gofmt --- .../multipath_bgp_ecmp_protocol_nexthop_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/feature/bgp/policybase/otg_tests/multipath_bgp_ecmp_protocol_nexthop/multipath_bgp_ecmp_protocol_nexthop_test.go b/feature/bgp/policybase/otg_tests/multipath_bgp_ecmp_protocol_nexthop/multipath_bgp_ecmp_protocol_nexthop_test.go index b64989e8f8d..f8ba43a1226 100644 --- a/feature/bgp/policybase/otg_tests/multipath_bgp_ecmp_protocol_nexthop/multipath_bgp_ecmp_protocol_nexthop_test.go +++ b/feature/bgp/policybase/otg_tests/multipath_bgp_ecmp_protocol_nexthop/multipath_bgp_ecmp_protocol_nexthop_test.go @@ -141,7 +141,7 @@ const ( packetSize = 1500 peerGrpName1 = "BGP-PEER-GROUP1" lossTolerancePct = 0.5 // Packet loss tolerance in percentage - lbToleranceFms = 20 // Load Balance Tolerance in percentage + lbToleranceFms = 20 // Load Balance Tolerance in percentage rplType = oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE rplName = "ALLOW" ) @@ -802,11 +802,10 @@ func verifyECMPLoadBalance(t *testing.T, ate *ondatra.ATEDevice, pc int, expecte } func randRange(start, end uint32, count int) []uint32 { - r := rand.New(rand.NewSource(time.Now().UnixNano())) var result []uint32 - diff := end - start + diff := int32(end - start) for len(result) < count { - randomValue := r.Int31n(int32(diff)) + int32(start) + randomValue := rand.Int31n(diff) + int32(start) result = append(result, uint32(randomValue)) } return result