Skip to content

Commit

Permalink
update zr_fec_test (openconfig#3056)
Browse files Browse the repository at this point in the history
* update zr_fec_test

* fix last line

* update
  • Loading branch information
prinikasn authored Jun 7, 2024
1 parent 30c0072 commit da7a533
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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{}
Expand All @@ -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)
})
}
}
51 changes: 51 additions & 0 deletions internal/cfgplugins/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
}

0 comments on commit da7a533

Please sign in to comment.