Skip to content

Commit

Permalink
Add experimental p4rt replay test (openconfig#2537)
Browse files Browse the repository at this point in the history
* Add experimental p4rt replay test

* Change Clients to Config in existing replay tests
  • Loading branch information
nhawke authored Jan 11, 2024
1 parent 053ce99 commit f93d9d6
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestReplay(t *testing.T) {
}

t.Logf("Creating gRPC clients to dut")
clients := &replayer.Clients{
clients := &replayer.Config{
GNMI: dut.RawAPIs().GNMI(t),
GRIBI: dut.RawAPIs().GRIBI(t),
}
Expand Down
8 changes: 8 additions & 0 deletions feature/experimental/replay/tests/p4rt_replay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Replay-1.2: P4RT Replay Test

## Summary

This is an example record/replay test. It is meant to reproduce an error when
replaying P4RT messages.

At this time, no vendor is expected to run this test.
3 changes: 3 additions & 0 deletions feature/experimental/replay/tests/p4rt_replay/grpclog.pb
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# proto-file: github.com/openconfig/featureprofiles/proto/metadata.proto
# proto-message: Metadata

uuid: "65492a13-cccd-461a-9fc4-f47f1d45fa1b"
plan_id: "Replay-1.2"
description: "P4RT Replay Test"
testbed: TESTBED_DUT
118 changes: 118 additions & 0 deletions feature/experimental/replay/tests/p4rt_replay/p4rt_replay_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright 2024 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package p4rt_replay_test

import (
"context"
"flag"
"testing"

"github.com/cisco-open/go-p4/utils"
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/p4rtutils"
gpb "github.com/openconfig/gribi/v1/proto/service"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/replayer"
"github.com/openconfig/ygot/ygot"
)

// Flag variable definitions
var (
p4InfoFile = flag.String("p4info_file_location", "../../../p4rt/wbb.p4info.pb.txt", "Path to the p4info file.")
)

func TestMain(m *testing.M) {
fptest.RunTests(m)
}

// configureDeviceID configures p4rt device-id on the DUT.
func configureDeviceID(t *testing.T, dut *ondatra.DUTDevice) {
nodes := p4rtutils.P4RTNodesByPort(t, dut)
p4rtNode, ok := nodes["port1"]
if !ok {
t.Fatal("Couldn't find P4RT Node for port: port1")
}
c := oc.Component{}
c.Name = ygot.String(p4rtNode)
c.IntegratedCircuit = &oc.Component_IntegratedCircuit{}
c.IntegratedCircuit.NodeId = ygot.Uint64(1)
t.Logf("Configuring P4RT Node %s", p4rtNode)
gnmi.Replace(t, dut, gnmi.OC().Component(p4rtNode).Config(), &c)
}

func TestReplay(t *testing.T) {
const logFile = "grpclog.pb"
t.Logf("Parsing log file: %v", logFile)
rec := replayer.ParseFile(t, logFile)

dut := ondatra.DUT(t, "dut")
portMap := map[string]string{}
intfs, err := rec.Interfaces()
if err != nil {
t.Fatalf("Interfaces(): cannot get interfaces: %v", err)
}

// This test only needs Port-Channel4, so remap only those ports to the dut's reserved ports.
available := dut.Ports()
t.Logf("PortChannel4: %v", intfs["Port-Channel4"])
for _, member := range intfs["Port-Channel4"] {
if len(available) == 0 {
t.Fatalf("Ports(): not enough ports to satisfy Port-Channel4 remapping, members: %v", intfs["Port-Channel4"])
}
portMap[member.Name] = available[0].Name()
available = available[1:]
}

if err := rec.SetInterfaceMap(portMap); err != nil {
t.Fatalf("Transform(%v): cannot transform log: %v", portMap, err)
}

configureDeviceID(t, dut)

p4Info, err := utils.P4InfoLoad(p4InfoFile)
if err != nil {
t.Fatalf("wbbp4info.Get(): failed to get P4 Info file: %v", err)
}

t.Logf("Creating gRPC clients to dut")
cfg := &replayer.Config{
GNMI: dut.RawAPIs().GNMI(t),
GRIBI: dut.RawAPIs().GRIBI(t),
P4RT: dut.RawAPIs().P4RT(t),
P4Info: p4Info,
}

t.Logf("Replaying parsed log to device %v", dut.Name())
ctx := context.Background()
results := replayer.Replay(ctx, t, rec, cfg)

// Validate that all gRIBI requests were programmed successfully.
for _, result := range results.GRIBI() {
if result.OperationID > 0 && result.ProgrammingResult != gpb.AFTResult_FIB_PROGRAMMED && result.ProgrammingResult != gpb.AFTResult_RIB_PROGRAMMED {
t.Errorf("Replay(): gRIBI Result failed: %v", result)
}
}

// Validate that resulting gRIBI state matches the recorded one.
if diff := replayer.GRIBIDiff(rec, results); diff != "" {
t.Errorf("Replay(): unexpected diff in final gRIBI state (-want,+got): %v", diff)
}

for i, result := range results.GNMI() {
t.Logf("Result [%v]: %v", i, result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestReplay(t *testing.T) {
}

t.Logf("Creating gRPC clients to dut")
clients := &replayer.Clients{
clients := &replayer.Config{
GNMI: dut.RawAPIs().GNMI(t),
GRIBI: dut.RawAPIs().GRIBI(t),
}
Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ go 1.21
require (
cloud.google.com/go/pubsub v1.33.0
cloud.google.com/go/storage v1.35.1
github.com/cisco-open/go-p4 v0.1.1
github.com/cisco-open/go-p4 v0.1.2
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.11.0
github.com/golang/glog v1.2.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v50 v50.1.0
github.com/google/gopacket v1.1.19
github.com/google/uuid v1.4.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/google/uuid v1.5.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/open-traffic-generator/snappi/gosnappi v0.13.3
github.com/openconfig/entity-naming v0.0.0-20230912181021-7ac806551a31
github.com/openconfig/gnmi v0.10.0
Expand All @@ -23,19 +23,19 @@ require (
github.com/openconfig/gocloser v0.0.0-20220310182203-c6c950ed3b0b
github.com/openconfig/goyang v1.4.5
github.com/openconfig/gribi v1.0.0
github.com/openconfig/gribigo v0.0.0-20231211221638-48fe45d9284d
github.com/openconfig/gribigo v0.0.0-20231213034307-d0abeba7f432
github.com/openconfig/kne v0.1.14
github.com/openconfig/models-ci v1.0.2-0.20231113233730-f0986391428e
github.com/openconfig/ondatra v0.4.8
github.com/openconfig/replayer v0.0.0-20231031192218-5462382820d4
github.com/openconfig/replayer v0.0.0-20240110192655-4e9cf83d8d30
github.com/openconfig/testt v0.0.0-20220311054427-efbb1a32ec07
github.com/openconfig/ygnmi v0.11.0
github.com/openconfig/ygot v0.29.17
github.com/p4lang/p4runtime v1.4.0-rc.5.0.20220728214547-13f0d02a521e
github.com/protocolbuffers/txtpbfmt v0.0.0-20220608084003-fc78c767cd6a
golang.org/x/crypto v0.18.0
golang.org/x/exp v0.0.0-20240110193028-0dcbfd608b1e
github.com/yoheimuta/go-protoparser/v4 v4.9.0
golang.org/x/crypto v0.17.0
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/text v0.14.0
google.golang.org/api v0.153.0
google.golang.org/grpc v1.60.1
Expand Down Expand Up @@ -136,16 +136,16 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.16.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231211222908-989df2bf70f3 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
Loading

0 comments on commit f93d9d6

Please sign in to comment.