Skip to content

Commit

Permalink
kne link flap fix (openconfig#2573)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijit-dhar authored and frasieroh committed Jan 24, 2024
1 parent 1e4afd2 commit 3dde4b1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
36 changes: 25 additions & 11 deletions feature/gribi/otg_tests/ipv4_entry_test/ipv4_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func TestIPv4Entry(t *testing.T) {
t.Run(fmt.Sprintf("Persistence=%s", persist), func(t *testing.T) {

for _, tc := range cases {
newGoodFlows, newBadFlows := createTrafficFlows(t, ate, tc.wantGoodFlows, tc.wantBadFlows)
t.Run(tc.desc, func(t *testing.T) {
if tc.gribiMACOverrideWithStaticARPStaticRoute {
staticARPWithMagicUniversalIP(t, dut)
Expand Down Expand Up @@ -444,8 +445,7 @@ func TestIPv4Entry(t *testing.T) {
for _, wantResult := range tc.wantOperationResults {
chk.HasResult(t, c.Results(t), wantResult, chk.IgnoreOperationID())
}

validateTrafficFlows(t, ate, tc.wantGoodFlows, tc.wantBadFlows)
validateTrafficFlows(t, ate, newGoodFlows, newBadFlows)
})
}
})
Expand Down Expand Up @@ -505,7 +505,6 @@ func createFlow(t *testing.T, name string, ate *ondatra.ATEDevice, ateTop gosnap
for _, dst := range dsts {
rxEndpoints = append(rxEndpoints, dst.Name+".IPv4")
}
otg := ate.OTG()
flowipv4 := ateTop.Flows().Add().SetName(name)
flowipv4.Metrics().SetEnable(true)
e1 := flowipv4.Packet().Add().Ethernet()
Expand All @@ -514,19 +513,19 @@ func createFlow(t *testing.T, name string, ate *ondatra.ATEDevice, ateTop gosnap
v4 := flowipv4.Packet().Add().Ipv4()
v4.Src().SetValue(atePort1.IPv4)
v4.Dst().Increment().SetStart(dstPfxMin).SetCount(dstPfxCount)
otg.PushConfig(t, ateTop)
otg.StartProtocols(t)
return name
}

func validateTrafficFlows(t *testing.T, ate *ondatra.ATEDevice, good, bad []string) {
ateTop := ate.OTG().FetchConfig(t)
if len(good) == 0 && len(bad) == 0 {
return
}

func createTrafficFlows(t *testing.T, ate *ondatra.ATEDevice, good, bad []string) (newGood, newBad []string) {
var newGoodFlows, newBadFlows []string
allFlows := append(good, bad...)
otg := ate.OTG()
ateTop := otg.FetchConfig(t)
if len(good) == 0 && len(bad) == 0 {
otg.PushConfig(t, ateTop)
otg.StartProtocols(t)
return newGoodFlows, newBadFlows
}
ateTop.Flows().Clear().Items()
for _, flow := range allFlows {
if flow == "port2Flow" {
Expand Down Expand Up @@ -556,6 +555,21 @@ func validateTrafficFlows(t *testing.T, ate *ondatra.ATEDevice, good, bad []stri

}
}
otg.PushConfig(t, ateTop)
otg.StartProtocols(t)
return newGoodFlows, newBadFlows
}

func validateTrafficFlows(t *testing.T, ate *ondatra.ATEDevice, good, bad []string) {
if len(good) == 0 && len(bad) == 0 {
return
}

newGoodFlows := good
newBadFlows := bad

ateTop := ate.OTG().FetchConfig(t)

ate.OTG().StartTraffic(t)
time.Sleep(15 * time.Second)
ate.OTG().StopTraffic(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func testNextHopRemaining(
top gosnappi.Config,
) {
// Generate and analyze traffic.
atePorts, inPkts, outPkts := generateTraffic(t, ate, top)
atePorts, inPkts, outPkts := runTraffic(t, ate, top)
t.Logf("atePorts = %v", atePorts)
t.Logf("inPkts = %v", inPkts)
t.Logf("outPkts = %v", outPkts)
Expand Down Expand Up @@ -151,10 +151,12 @@ func TestPortFlap(t *testing.T) {
// Turn down ports one by one.
dt := gnmi.OC()

createTraffic(t, ate, top)
for i := len(atePorts); i >= 2; i-- {
numUps := i - 1
numDowns := len(atePorts) - i
testName := fmt.Sprintf("%d Up, %d Down", numUps, numDowns)

if i < len(atePorts) {
dp := dut.Port(t, atePorts[i].ID())
if deviations.ATEPortLinkStateOperationsUnsupported(ate) {
Expand Down
16 changes: 11 additions & 5 deletions feature/gribi/otg_tests/weighted_balancing_test/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ func sortPorts(ports []*ondatra.Port) []*ondatra.Port {
return ports
}

// generateTraffic generates traffic from ateSrcNetCIDR to
// ateDstNetCIDR, then returns the atePorts as well as the number of
// packets received (inPkts) and sent (outPkts) across the atePorts.
func generateTraffic(t *testing.T, ate *ondatra.ATEDevice, config gosnappi.Config) (atePorts []*ondatra.Port, inPkts []uint64, outPkts []uint64) {
func createTraffic(t *testing.T, ate *ondatra.ATEDevice, config gosnappi.Config) {
re, _ := regexp.Compile(".+:([a-zA-Z0-9]+)")
dutString := "dut:" + re.FindStringSubmatch(ateSrcPort)[1]
gwIp := portsIPv4[dutString]
Expand Down Expand Up @@ -334,7 +331,9 @@ func generateTraffic(t *testing.T, ate *ondatra.ATEDevice, config gosnappi.Confi
flow.Size().SetFixed(200)
ate.OTG().PushConfig(t, config)
ate.OTG().StartProtocols(t)
}

func runTraffic(t *testing.T, ate *ondatra.ATEDevice, config gosnappi.Config) (atePorts []*ondatra.Port, inPkts []uint64, outPkts []uint64) {
if *trafficPause != 0 {
t.Logf("Pausing before traffic at %v for %v", time.Now(), *trafficPause)
time.Sleep(*trafficPause)
Expand Down Expand Up @@ -362,10 +361,17 @@ func generateTraffic(t *testing.T, ate *ondatra.ATEDevice, config gosnappi.Confi
}
}
}

return atePorts, inPkts, outPkts
}

// generateTraffic generates traffic from ateSrcNetCIDR to
// ateDstNetCIDR, then returns the atePorts as well as the number of
// packets received (inPkts) and sent (outPkts) across the atePorts.
func generateTraffic(t *testing.T, ate *ondatra.ATEDevice, config gosnappi.Config) (atePorts []*ondatra.Port, inPkts []uint64, outPkts []uint64) {
createTraffic(t, ate, config)
return runTraffic(t, ate, config)
}

// normalize normalizes the input values so that the output values sum
// to 1.0 but reflect the proportions of the input. For example,
// input [1, 2, 3, 4] is normalized to [0.1, 0.2, 0.3, 0.4].
Expand Down

0 comments on commit 3dde4b1

Please sign in to comment.