From da7a53334c1901e5d52df2afce02f63c1cce3493 Mon Sep 17 00:00:00 2001 From: prinikasn <117314826+prinikasn@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:46:58 -0700 Subject: [PATCH] update zr_fec_test (#3056) * update zr_fec_test * fix last line * update --- .../zr_fec_uncorrectable_frames_test.go | 41 +++++++++++---- internal/cfgplugins/interface.go | 51 +++++++++++++++++++ 2 files changed, 82 insertions(+), 10 deletions(-) diff --git a/feature/platform/transceiver/tests/zr_fec_uncorrectable_frames_test/zr_fec_uncorrectable_frames_test.go b/feature/platform/transceiver/tests/zr_fec_uncorrectable_frames_test/zr_fec_uncorrectable_frames_test.go index 590fa814e86..9cb628c6189 100644 --- a/feature/platform/transceiver/tests/zr_fec_uncorrectable_frames_test/zr_fec_uncorrectable_frames_test.go +++ b/feature/platform/transceiver/tests/zr_fec_uncorrectable_frames_test/zr_fec_uncorrectable_frames_test.go @@ -32,6 +32,8 @@ import ( const ( sampleInterval = 10 * time.Second intUpdateTime = 2 * time.Minute + otnIndexBase = uint32(4000) + ethIndexBase = uint32(40000) ) func TestMain(m *testing.M) { @@ -47,8 +49,8 @@ func validateFecUncorrectableBlocks(t *testing.T, stream *samplestream.SampleStr if !ok { t.Fatalf("Error capturing streaming Fec value") } - if reflect.TypeOf(fec).Kind() != reflect.Int64 { - t.Fatalf("fec value is not type int64") + if reflect.TypeOf(fec).Kind() != reflect.Uint64 { + t.Fatalf("fec value is not type uint64") } if fec != 0 { t.Fatalf("Got FecUncorrectableBlocks got %d, want 0", fec) @@ -57,17 +59,36 @@ func validateFecUncorrectableBlocks(t *testing.T, stream *samplestream.SampleStr func TestZrUncorrectableFrames(t *testing.T) { dut := ondatra.DUT(t, "dut") - cfgplugins.InterfaceConfig(t, dut, dut.Port(t, "port1")) - cfgplugins.InterfaceConfig(t, dut, dut.Port(t, "port2")) - for _, port := range []string{"port1", "port2"} { + var ( + trs = make(map[string]string) + ochs = make(map[string]string) + otnIndexes = make(map[string]uint32) + ethIndexes = make(map[string]uint32) + ) + + ports := []string{"port1", "port2"} + + for i, port := range ports { + dp := dut.Port(t, port) + cfgplugins.InterfaceConfig(t, dut, dp) + trs[dp.Name()] = gnmi.Get(t, dut, gnmi.OC().Interface(dp.Name()).Transceiver().State()) + ochs[dp.Name()] = gnmi.Get(t, dut, gnmi.OC().Component(trs[dp.Name()]).Transceiver().Channel(0).AssociatedOpticalChannel().State()) + otnIndexes[dp.Name()] = otnIndexBase + uint32(i) + ethIndexes[dp.Name()] = ethIndexBase + uint32(i) + cfgplugins.ConfigOTNChannel(t, dut, ochs[dp.Name()], otnIndexes[dp.Name()], ethIndexes[dp.Name()]) + cfgplugins.ConfigETHChannel(t, dut, dp.Name(), trs[dp.Name()], otnIndexes[dp.Name()], ethIndexes[dp.Name()]) + } + + for _, port := range ports { t.Run(fmt.Sprintf("Port:%s", port), func(t *testing.T) { - dp := dut.Port(t, "port1") + dp := dut.Port(t, port) + gnmi.Await(t, dut, gnmi.OC().Interface(dp.Name()).OperStatus().State(), intUpdateTime, oc.Interface_OperStatus_UP) - streamFec := samplestream.New(t, dut, gnmi.OC().TerminalDevice().Channel(0).Otn().FecUncorrectableBlocks().State(), sampleInterval) - defer streamFec.Close() - validateFecUncorrectableBlocks(t, streamFec) + streamFecOtn := samplestream.New(t, dut, gnmi.OC().TerminalDevice().Channel(otnIndexes[dp.Name()]).Otn().FecUncorrectableBlocks().State(), sampleInterval) + defer streamFecOtn.Close() + validateFecUncorrectableBlocks(t, streamFecOtn) // Toggle interface enabled d := &oc.Root{} @@ -86,7 +107,7 @@ func TestZrUncorrectableFrames(t *testing.T) { // Wait for the cooling off period gnmi.Await(t, dut, gnmi.OC().Interface(dp.Name()).OperStatus().State(), intUpdateTime, oc.Interface_OperStatus_UP) - validateFecUncorrectableBlocks(t, streamFec) + validateFecUncorrectableBlocks(t, streamFecOtn) }) } } diff --git a/internal/cfgplugins/interface.go b/internal/cfgplugins/interface.go index 7567518c89e..8eac70f3360 100644 --- a/internal/cfgplugins/interface.go +++ b/internal/cfgplugins/interface.go @@ -89,3 +89,54 @@ func ValidateInterfaceConfig(t *testing.T, dut *ondatra.DUTDevice, dp *ondatra.P t.Fatalf("Frequency is not within expected tolerance, got: %v want: %v tolerance: %v", frequency, targetFrequencyMHz, targetFrequencyToleranceMHz) } } + +// ConfigOTNChannel configures the OTN channel. +func ConfigOTNChannel(t *testing.T, dut *ondatra.DUTDevice, och string, otnIndex, ethIndex uint32) { + t.Helper() + gnmi.Replace(t, dut, gnmi.OC().TerminalDevice().Channel(otnIndex).Config(), &oc.TerminalDevice_Channel{ + Description: ygot.String("OTN Logical Channel"), + Index: ygot.Uint32(otnIndex), + LogicalChannelType: oc.TransportTypes_LOGICAL_ELEMENT_PROTOCOL_TYPE_PROT_OTN, + TribProtocol: oc.TransportTypes_TRIBUTARY_PROTOCOL_TYPE_PROT_400GE, + Assignment: map[uint32]*oc.TerminalDevice_Channel_Assignment{ + 0: { + Index: ygot.Uint32(0), + OpticalChannel: ygot.String(och), + Description: ygot.String("OTN to Optical Channel"), + Allocation: ygot.Float64(400), + AssignmentType: oc.Assignment_AssignmentType_OPTICAL_CHANNEL, + }, + 1: { + Index: ygot.Uint32(1), + LogicalChannel: ygot.Uint32(ethIndex), + Description: ygot.String("OTN to ETH"), + Allocation: ygot.Float64(400), + AssignmentType: oc.Assignment_AssignmentType_LOGICAL_CHANNEL, + }, + }, + }) +} + +// ConfigETHChannel configures the ETH channel. +func ConfigETHChannel(t *testing.T, dut *ondatra.DUTDevice, interfaceName, transceiverName string, otnIndex, ethIndex uint32) { + t.Helper() + gnmi.Replace(t, dut, gnmi.OC().TerminalDevice().Channel(ethIndex).Config(), &oc.TerminalDevice_Channel{ + Description: ygot.String("ETH Logical Channel"), + Index: ygot.Uint32(ethIndex), + LogicalChannelType: oc.TransportTypes_LOGICAL_ELEMENT_PROTOCOL_TYPE_PROT_ETHERNET, + TribProtocol: oc.TransportTypes_TRIBUTARY_PROTOCOL_TYPE_PROT_400GE, + Ingress: &oc.TerminalDevice_Channel_Ingress{ + Interface: ygot.String(interfaceName), + Transceiver: ygot.String(transceiverName), + }, + Assignment: map[uint32]*oc.TerminalDevice_Channel_Assignment{ + 0: { + Index: ygot.Uint32(0), + LogicalChannel: ygot.Uint32(otnIndex), + Description: ygot.String("ETH to OTN"), + Allocation: ygot.Float64(400), + AssignmentType: oc.Assignment_AssignmentType_LOGICAL_CHANNEL, + }, + }, + }) +}