Skip to content

Commit

Permalink
testpmd, console: Add vmiName field
Browse files Browse the repository at this point in the history
Currently, the exported methods of `testpmd.Console`
are receiving a vmiName parameter.

Because this object is supposed to work against a single VMI,
a better approach would be to pass the vmiName parameter during
the object's construction.

Add a vmiName field to `testpmd.Console`.
Remove the vmiName parameter from all its exported methods.

Signed-off-by: Orel Misan <[email protected]>
  • Loading branch information
orelmisan committed Jul 25, 2023
1 parent 9726a81 commit fdb4527
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
24 changes: 15 additions & 9 deletions pkg/internal/checkup/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,24 @@ func (e Executor) Execute(ctx context.Context, vmiUnderTestName, trafficGenVMINa
return status.Results{}, fmt.Errorf("failed to Start to Trex Service on VMI \"%s/%s\": %w", e.namespace, trafficGenVMIName, err)
}

testpmdConsole := testpmd.NewTestpmdConsole(e.vmiSerialClient, e.namespace, e.vmiUnderTestEastNICPCIAddress, e.trafficGenEastMACAddress,
e.vmiUnderTestWestNICPCIAddress, e.trafficGenWestMACAddress, e.verbosePrintsEnabled)
testpmdConsole := testpmd.NewTestpmdConsole(
e.vmiSerialClient,
e.namespace,
vmiUnderTestName,
e.vmiUnderTestEastNICPCIAddress,
e.trafficGenEastMACAddress,
e.vmiUnderTestWestNICPCIAddress,
e.trafficGenWestMACAddress,
e.verbosePrintsEnabled,
)

log.Printf("Starting testpmd in VMI...")
if err := testpmdConsole.Run(vmiUnderTestName); err != nil {
if err := testpmdConsole.Run(); err != nil {
return status.Results{}, err
}

log.Printf("Clearing testpmd stats in VMI...")
if err := testpmdConsole.ClearStats(vmiUnderTestName); err != nil {
if err := testpmdConsole.ClearStats(); err != nil {
return status.Results{}, err
}

Expand All @@ -132,12 +140,10 @@ func (e Executor) Execute(ctx context.Context, vmiUnderTestName, trafficGenVMINa
}
log.Printf("traffic Generator Max Drop Rate: %fBps", trafficGeneratorMaxDropRate)

return calculateStats(trexClient, testpmdConsole, vmiUnderTestName)
return calculateStats(trexClient, testpmdConsole)
}

func calculateStats(trexClient trex.Client,
testpmdConsole *testpmd.TestpmdConsole,
vmiUnderTestName string) (status.Results, error) {
func calculateStats(trexClient trex.Client, testpmdConsole *testpmd.TestpmdConsole) (status.Results, error) {
var err error
results := status.Results{}
var trafficGeneratorSrcPortStats trex.PortStats
Expand All @@ -161,7 +167,7 @@ func calculateStats(trexClient trex.Client,

log.Printf("get testpmd stats in DPDK VMI...")
var testPmdStats [testpmd.StatsArraySize]testpmd.PortStats
if testPmdStats, err = testpmdConsole.GetStats(vmiUnderTestName); err != nil {
if testPmdStats, err = testpmdConsole.GetStats(); err != nil {
return status.Results{}, err
}
results.DPDKPacketsRxDropped = testPmdStats[testpmd.StatsSummary].RXDropped
Expand Down
24 changes: 16 additions & 8 deletions pkg/internal/checkup/executor/testpmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type vmiSerialConsoleClient interface {
type TestpmdConsole struct {
vmiSerialClient vmiSerialConsoleClient
namespace string
vmiName string
vmiEastNICPCIAddress string
vmiEastEthPeerMACAddress string
vmiWestNICPCIAddress string
Expand Down Expand Up @@ -67,11 +68,18 @@ const (

const testpmdPrompt = "testpmd> "

func NewTestpmdConsole(vmiSerialClient vmiSerialConsoleClient, namespace, vmiUnderTestEastNICPCIAddress,
trafficGenEastMACAddress, vmiUnderTestWestNICPCIAddress, trafficGenWestMACAddress string, verbosePrintsEnabled bool) *TestpmdConsole {
func NewTestpmdConsole(vmiSerialClient vmiSerialConsoleClient,
namespace,
vmiName,
vmiUnderTestEastNICPCIAddress,
trafficGenEastMACAddress,
vmiUnderTestWestNICPCIAddress,
trafficGenWestMACAddress string,
verbosePrintsEnabled bool) *TestpmdConsole {
return &TestpmdConsole{
vmiSerialClient: vmiSerialClient,
namespace: namespace,
vmiName: vmiName,
vmiEastEthPeerMACAddress: trafficGenEastMACAddress,
vmiWestEthPeerMACAddress: trafficGenWestMACAddress,
vmiEastNICPCIAddress: vmiUnderTestEastNICPCIAddress,
Expand All @@ -80,12 +88,12 @@ func NewTestpmdConsole(vmiSerialClient vmiSerialConsoleClient, namespace, vmiUnd
}
}

func (t TestpmdConsole) Run(vmiName string) error {
func (t TestpmdConsole) Run() error {
const batchTimeout = 30 * time.Second

testpmdCmd := buildTestpmdCmd(t.vmiEastNICPCIAddress, t.vmiWestNICPCIAddress, t.vmiEastEthPeerMACAddress, t.vmiWestEthPeerMACAddress)

resp, err := console.SafeExpectBatchWithResponse(t.vmiSerialClient, t.namespace, vmiName,
resp, err := console.SafeExpectBatchWithResponse(t.vmiSerialClient, t.namespace, t.vmiName,
[]expect.Batcher{
&expect.BSnd{S: testpmdCmd + "\n"},
&expect.BExp{R: testpmdPrompt},
Expand All @@ -104,12 +112,12 @@ func (t TestpmdConsole) Run(vmiName string) error {
return nil
}

func (t TestpmdConsole) ClearStats(vmiName string) error {
func (t TestpmdConsole) ClearStats() error {
const batchTimeout = 30 * time.Second

const testpmdCmd = "clear fwd stats all"

_, err := console.SafeExpectBatchWithResponse(t.vmiSerialClient, t.namespace, vmiName,
_, err := console.SafeExpectBatchWithResponse(t.vmiSerialClient, t.namespace, t.vmiName,
[]expect.Batcher{
&expect.BSnd{S: testpmdCmd + "\n"},
&expect.BExp{R: testpmdPrompt},
Expand All @@ -124,14 +132,14 @@ func (t TestpmdConsole) ClearStats(vmiName string) error {
return nil
}

func (t TestpmdConsole) GetStats(vmiName string) ([StatsArraySize]PortStats, error) {
func (t TestpmdConsole) GetStats() ([StatsArraySize]PortStats, error) {
const batchTimeout = 30 * time.Second

const testpmdPromt = "testpmd> "

testpmdCmd := "show fwd stats all"

resp, err := console.SafeExpectBatchWithResponse(t.vmiSerialClient, t.namespace, vmiName,
resp, err := console.SafeExpectBatchWithResponse(t.vmiSerialClient, t.namespace, t.vmiName,
[]expect.Batcher{
&expect.BSnd{S: testpmdCmd + "\n"},
&expect.BExp{R: testpmdPromt},
Expand Down

0 comments on commit fdb4527

Please sign in to comment.