Skip to content

Commit

Permalink
improved ValidateInterfaceConfig function in interface.go file by rem…
Browse files Browse the repository at this point in the history
…oving the constances
  • Loading branch information
jianchen-g committed Jan 27, 2025
1 parent 52981b3 commit 4301b3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import (
)

const (
intUpdateTime = 2 * time.Minute
intUpdateTime = 2 * time.Minute
targetOutputPowerdBm = -10
targetOutputPowerTolerancedBm = 1
targetFrequencyMHz = 193100000
targetFrequencyToleranceMHz = 100000
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -175,7 +179,7 @@ func TestLowPowerMode(t *testing.T) {
"max": opMax,
}
validateOutputPower(t, powerStreamMap)
cfgplugins.ValidateInterfaceConfig(t, dut, dp)
cfgplugins.ValidateInterfaceConfig(t, dut, dp, targetOutputPowerdBm, targetFrequencyMHz, targetOutputPowerTolerancedBm, targetFrequencyToleranceMHz)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
const (
intUpdateTime = 5 * time.Minute
samplingInterval = 10 * time.Second
targetOutputPower = -3
frequency = 193100000
targetOutputPowerdBm = -3
targetOutputPowerTolerancedBm = 1
targetFrequencyMHz = 193100000
targetFrequencyToleranceMHz = 100000
)

Expand Down Expand Up @@ -101,8 +101,8 @@ func TestLowPowerMode(t *testing.T) {
t.Logf("dut1 dp1 name: %v", dp1.Name())
och1 := components.OpticalChannelComponentFromPort(t, dut, dp1)
och2 := components.OpticalChannelComponentFromPort(t, dut, dp2)
cfgplugins.ConfigOpticalChannel(t, dut, och1, frequency, targetOutputPower, operationalMode)
cfgplugins.ConfigOpticalChannel(t, dut, och2, frequency, targetOutputPower, operationalMode)
cfgplugins.ConfigOpticalChannel(t, dut, och1, targetFrequencyMHz, targetOutputPowerdBm, operationalMode)
cfgplugins.ConfigOpticalChannel(t, dut, och2, targetFrequencyMHz, targetOutputPowerdBm, operationalMode)
for _, port := range []string{"port1", "port2"} {
t.Run(fmt.Sprintf("Port:%s", port), func(t *testing.T) {
dp := dut.Port(t, port)
Expand Down Expand Up @@ -196,31 +196,8 @@ func TestLowPowerMode(t *testing.T) {
"max": opMax,
}
validateOutputPower(t, powerStreamMap)
// Validate the output power and frequency for the given port.
// NOTE: Default values should be removed in ValidateInterfaceConfig in cfgplugins.
// cfgplugins.ValidateInterfaceConfig(t, dut, dp)
targetOutputPowerStream := samplestream.New(t, dut, gnmi.OC().Component(opticalChannelName).OpticalChannel().TargetOutputPower().State(), samplingInterval)
defer targetOutputPowerStream.Close()
if targetOutputPowerStreamN := targetOutputPowerStream.Next(); targetOutputPowerStreamN != nil {
if val, ok := targetOutputPowerStreamN.Val(); ok {
if reflect.TypeOf(val).Kind() != reflect.Float64 {
t.Fatalf("Return value is not type float64 for key :%f", val)
}
}
}
// // TODO: jchenjian - Uncomment the output power and frequency checks from the test once the bug b/382296833 is fixed.
// outputPower := gnmi.Get(t, dut, gnmi.OC().Component(opticalChannelName).OpticalChannel().TargetOutputPower().State())
// t.Logf("Type and value of outputPower: %T, %v", outputPower, outputPower)
// t.Logf("port: %s, Power delta: %v", dp.Name(), math.Abs(float64(outputPower)-float64(targetOutputPower)))
// if math.Abs(float64(outputPower)-float64(targetOutputPower)) > targetOutputPowerTolerancedBm {
// t.Fatalf("Output power is not within expected tolerance, got: %v want: %v tolerance: %v", outputPower, targetOutputPower, targetOutputPowerTolerancedBm)
// }

// freq := gnmi.Get(t, dut, gnmi.OC().Component(opticalChannelName).OpticalChannel().Frequency().State())
// t.Logf("port: %s, Frequency delta: %v", dp.Name(), math.Abs(float64(freq)-float64(frequency)))
// if math.Abs(float64(freq)-float64(frequency)) > targetFrequencyToleranceMHz {
// t.Fatalf("Frequency is not within expected tolerance, got: %v want: %v tolerance: %v", freq, frequency, targetFrequencyToleranceMHz)
// }
// TODO: jchenjian - Uncomment the output power and frequency checks from the test once the bug b/382296833 is fixed.
// cfgplugins.ValidateInterfaceConfig(t, dut, dp, targetOutputPowerdBm, targetFrequencyMHz, targetOutputPowerTolerancedBm, targetFrequencyToleranceMHz)
})
}
}
2 changes: 1 addition & 1 deletion internal/cfgplugins/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func InterfaceConfig(t *testing.T, dut *ondatra.DUTDevice, dp *ondatra.Port) {
}

// ValidateInterfaceConfig validates the output power and frequency for the given port.
func ValidateInterfaceConfig(t *testing.T, dut *ondatra.DUTDevice, dp *ondatra.Port) {
func ValidateInterfaceConfig(t *testing.T, dut *ondatra.DUTDevice, dp *ondatra.Port, targetOutputPowerdBm float64, targetFrequencyMHz uint64, targetOutputPowerTolerancedBm float64, targetFrequencyToleranceMHz float64) {
t.Helper()
ocComponent := components.OpticalChannelComponentFromPort(t, dut, dp)
t.Logf("Got opticalChannelComponent from port: %s", ocComponent)
Expand Down

0 comments on commit 4301b3d

Please sign in to comment.