Skip to content

Commit

Permalink
[Thinkit] Use switch setup helpers throughout to support P4Info recon…
Browse files Browse the repository at this point in the history
…figuration gracefully.
  • Loading branch information
smolkaj authored and divyagayathri-hcl committed Dec 11, 2024
1 parent b9d8f8d commit 0e85363
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 92 deletions.
1 change: 1 addition & 0 deletions tests/qos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ cc_library(
"//sai_p4/instantiations/google:sai_p4info_cc",
"//sai_p4/instantiations/google:sai_pd_cc_proto",
"//tests/forwarding:util",
"//tests/lib:switch_test_setup_helpers",
"//thinkit:control_device",
"//thinkit:generic_testbed",
"//thinkit:generic_testbed_fixture",
Expand Down
138 changes: 46 additions & 92 deletions tests/qos/cpu_qos_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include "sai_p4/instantiations/google/sai_p4info.h"
#include "sai_p4/instantiations/google/sai_pd.pb.h"
#include "tests/forwarding/util.h"
#include "tests/lib/switch_test_setup_helpers.h"
#include "tests/qos/gnmi_parsers.h"
#include "tests/qos/qos_test_util.h"
#include "thinkit/control_device.h"
Expand Down Expand Up @@ -373,34 +374,17 @@ TEST_P(CpuQosTestWithoutIxia, PerEntryAclCounterIncrementsWhenEntryIsHit) {
ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info,
pdpi::CreateIrP4Info(p4info));

// Set up P4Runtime.
// Configure mirror testbed.
EXPECT_OK(Testbed().Environment().StoreTestArtifact("gnmi_config.json",
GetParam().gnmi_config));
EXPECT_OK(
Testbed().Environment().StoreTestArtifact("p4info.textproto", p4info));
std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
control_p4rt_session;
ASSERT_OK_AND_ASSIGN(
std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables(sut, p4info));
ASSERT_OK_AND_ASSIGN(
std::unique_ptr<pdpi::P4RuntimeSession> control_p4rt_session,
pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables(control_device,
p4info));

// Set up gNMI.
EXPECT_OK(Testbed().Environment().StoreTestArtifact("gnmi_config.json",
GetParam().gnmi_config));
ASSERT_OK(pins_test::PushGnmiConfig(sut, GetParam().gnmi_config));
ASSERT_OK(pins_test::PushGnmiConfig(control_device, GetParam().gnmi_config));
ASSERT_OK_AND_ASSIGN(auto gnmi_stub, sut.CreateGnmiStub());

// TODO: Poll for config to be applied, links to come up instead.
LOG(INFO) << "Sleeping " << kTimeToWaitForGnmiConfigToApply
<< " to wait for config to be applied/links to come up.";
absl::SleepFor(kTimeToWaitForGnmiConfigToApply);
ASSERT_OK(
pins_test::WaitForGnmiPortIdConvergence(sut, GetParam().gnmi_config,
/*timeout=*/absl::Minutes(3)));
ASSERT_OK(pins_test::WaitForGnmiPortIdConvergence(
control_device, GetParam().gnmi_config,
/*timeout=*/absl::Minutes(3)));
std::tie(sut_p4rt_session, control_p4rt_session),
pins_test::ConfigureSwitchPairAndReturnP4RuntimeSessionPair(
sut, control_device, GetParam().gnmi_config, p4info));

// Pick a link to be used for packet injection.
ASSERT_OK_AND_ASSIGN(SutToControlLink link_used_for_test_packets,
Expand Down Expand Up @@ -676,34 +660,17 @@ TEST_P(CpuQosTestWithoutIxia,
ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info,
pdpi::CreateIrP4Info(p4info));

// Set up P4Runtime.
// Configure mirror testbed.
EXPECT_OK(Testbed().Environment().StoreTestArtifact("gnmi_config.json",
GetParam().gnmi_config));
EXPECT_OK(
Testbed().Environment().StoreTestArtifact("p4info.textproto", p4info));
std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
control_p4rt_session;
ASSERT_OK_AND_ASSIGN(
std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables(sut, p4info));
ASSERT_OK_AND_ASSIGN(
std::unique_ptr<pdpi::P4RuntimeSession> control_p4rt_session,
pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables(control_device,
p4info));

// Set up gNMI.
EXPECT_OK(Testbed().Environment().StoreTestArtifact("gnmi_config.json",
GetParam().gnmi_config));
ASSERT_OK(pins_test::PushGnmiConfig(sut, GetParam().gnmi_config));
ASSERT_OK(pins_test::PushGnmiConfig(control_device, GetParam().gnmi_config));
ASSERT_OK_AND_ASSIGN(auto gnmi_stub, sut.CreateGnmiStub());

// TODO: Poll for config to be applied, links to come up instead.
LOG(INFO) << "Sleeping " << kTimeToWaitForGnmiConfigToApply
<< " to wait for config to be applied/links to come up.";
absl::SleepFor(kTimeToWaitForGnmiConfigToApply);
ASSERT_OK(
pins_test::WaitForGnmiPortIdConvergence(sut, GetParam().gnmi_config,
/*timeout=*/absl::Minutes(3)));
ASSERT_OK(pins_test::WaitForGnmiPortIdConvergence(
control_device, GetParam().gnmi_config,
/*timeout=*/absl::Minutes(3)));
std::tie(sut_p4rt_session, control_p4rt_session),
pins_test::ConfigureSwitchPairAndReturnP4RuntimeSessionPair(
sut, control_device, GetParam().gnmi_config, p4info));

// Pick a link to be used for packet injection.
ASSERT_OK_AND_ASSIGN(SutToControlLink link_used_for_test_packets,
Expand Down Expand Up @@ -732,6 +699,7 @@ TEST_P(CpuQosTestWithoutIxia,

// Read CPU queue state prior to injecting test packets. The state should
// remain unchanged when we inject test packets.
ASSERT_OK_AND_ASSIGN(auto gnmi_stub, sut.CreateGnmiStub());
ASSERT_OK_AND_ASSIGN(openconfig::QueuesByName initial_cpu_queue_state,
GetCpuQueueStateViaGnmi(*gnmi_stub));

Expand Down Expand Up @@ -794,33 +762,17 @@ TEST_P(CpuQosTestWithoutIxia, TrafficToLoopackIpGetsMappedToCorrectQueues) {
ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info,
pdpi::CreateIrP4Info(p4info));

// Set up P4Runtime.
// Configure mirror testbed.
EXPECT_OK(Testbed().Environment().StoreTestArtifact("gnmi_config.json",
GetParam().gnmi_config));
EXPECT_OK(
Testbed().Environment().StoreTestArtifact("p4info.textproto", p4info));
std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
control_p4rt_session;
ASSERT_OK_AND_ASSIGN(
std::unique_ptr<pdpi::P4RuntimeSession> p4rt_session,
pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables(sut, p4info));
ASSERT_OK_AND_ASSIGN(
std::unique_ptr<pdpi::P4RuntimeSession> control_p4rt_session,
pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables(control_device,
p4info));

// Set up gNMI.
EXPECT_OK(Testbed().Environment().StoreTestArtifact("gnmi_config.json",
GetParam().gnmi_config));
ASSERT_OK(pins_test::PushGnmiConfig(sut, GetParam().gnmi_config));
ASSERT_OK(pins_test::PushGnmiConfig(control_device, GetParam().gnmi_config));
ASSERT_OK_AND_ASSIGN(auto gnmi_stub, sut.CreateGnmiStub());
// TODO: Poll for config to be applied, links to come up instead.
LOG(INFO) << "Sleeping " << kTimeToWaitForGnmiConfigToApply
<< " to wait for config to be applied/links to come up.";
absl::SleepFor(kTimeToWaitForGnmiConfigToApply);
ASSERT_OK(
pins_test::WaitForGnmiPortIdConvergence(sut, GetParam().gnmi_config,
/*timeout=*/absl::Minutes(3)));
ASSERT_OK(pins_test::WaitForGnmiPortIdConvergence(
control_device, GetParam().gnmi_config,
/*timeout=*/absl::Minutes(3)));
std::tie(sut_p4rt_session, control_p4rt_session),
pins_test::ConfigureSwitchPairAndReturnP4RuntimeSessionPair(
sut, control_device, GetParam().gnmi_config, p4info));

// Pick a link to be used for packet injection.
ASSERT_OK_AND_ASSIGN(SutToControlLink link_used_for_test_packets,
Expand All @@ -840,8 +792,8 @@ TEST_P(CpuQosTestWithoutIxia, TrafficToLoopackIpGetsMappedToCorrectQueues) {
link_used_for_test_packets.sut_port_p4rt_name,
/*mac=*/kSutMacAddress,
/*ir_p4info=*/ir_p4info));
ASSERT_OK(
pdpi::InstallPiTableEntry(p4rt_session.get(), router_interface_entry));
ASSERT_OK(pdpi::InstallPiTableEntry(sut_p4rt_session.get(),
router_interface_entry));
}

// Extract DSCP-to-queue mapping from gNMI config.
Expand Down Expand Up @@ -889,10 +841,11 @@ TEST_P(CpuQosTestWithoutIxia, TrafficToLoopackIpGetsMappedToCorrectQueues) {
LOG(INFO) << "Target queue: " << target_queue;

// Read counters of the target queue.
ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub());
ASSERT_OK_AND_ASSIGN(
const QueueCounters queue_counters_before_test_packet,
GetGnmiQueueCounters(/*port=*/"CPU", /*queue=*/target_queue,
*gnmi_stub));
*sut_gnmi_stub));

// Inject test packet.
ASSERT_OK_AND_ASSIGN(
Expand All @@ -917,7 +870,7 @@ TEST_P(CpuQosTestWithoutIxia, TrafficToLoopackIpGetsMappedToCorrectQueues) {
ASSERT_OK_AND_ASSIGN(
queue_counters_after_test_packet,
GetGnmiQueueCounters(/*port=*/"CPU", /*queue=*/target_queue,
*gnmi_stub));
*sut_gnmi_stub));
} while (
// It may take several seconds for the queue counters to update.
CumulativeNumPacketsEnqueued(queue_counters_after_test_packet) ==
Expand Down Expand Up @@ -1022,15 +975,16 @@ TEST_P(CpuQosTestWithIxia, TestCPUQueueAssignmentAndQueueRateLimit) {

thinkit::Switch &sut = generic_testbed->Sut();

// Set up P4Runtime session.
ASSERT_OK_AND_ASSIGN(std::unique_ptr<pdpi::P4RuntimeSession> sut_p4_session,
pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables(
generic_testbed->Sut(), GetParam().p4info));
// Configure SUT.
EXPECT_OK(generic_testbed->Environment().StoreTestArtifact(
"gnmi_config.json", GetParam().gnmi_config));
EXPECT_OK(generic_testbed->Environment().StoreTestArtifact(
"p4info.textproto", GetParam().p4info));

// Push GNMI config.
ASSERT_OK(pins_test::PushGnmiConfig(sut, GetParam().gnmi_config));
ASSERT_OK_AND_ASSIGN(std::unique_ptr<pdpi::P4RuntimeSession> sut_p4_session,
pins_test::ConfigureSwitchAndReturnP4RuntimeSession(
sut, GetParam().gnmi_config, GetParam().p4info));

// Hook up to GNMI.
ASSERT_OK_AND_ASSIGN(auto gnmi_stub, sut.CreateGnmiStub());

// Flow details.
Expand Down Expand Up @@ -1076,15 +1030,15 @@ TEST_P(CpuQosTestWithIxia, TestPuntFlowRateLimitAndCounters) {

thinkit::Switch &sut = generic_testbed->Sut();

// Set up P4Runtime session.
// Configure SUT.
EXPECT_OK(generic_testbed->Environment().StoreTestArtifact(
"gnmi_config.json", GetParam().gnmi_config));
EXPECT_OK(generic_testbed->Environment().StoreTestArtifact(
"p4info.textproto", GetParam().p4info));
ASSERT_OK_AND_ASSIGN(std::unique_ptr<pdpi::P4RuntimeSession> sut_p4_session,
pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables(
generic_testbed->Sut(), GetParam().p4info));

// Push GNMI config.
ASSERT_OK(pins_test::PushGnmiConfig(sut, GetParam().gnmi_config));
pins_test::ConfigureSwitchAndReturnP4RuntimeSession(
sut, GetParam().gnmi_config, GetParam().p4info));

// Hook up to GNMI.
ASSERT_OK_AND_ASSIGN(auto gnmi_stub, sut.CreateGnmiStub());

// Flow details.
Expand Down

0 comments on commit 0e85363

Please sign in to comment.