Skip to content

Commit

Permalink
[Thinkit] Add a util to verify queue limits are correctly set.Associa…
Browse files Browse the repository at this point in the history
…te test case Id. Add a queue counter log in sFlow test. fix thread issue. Use absl::CleanUp to join threads in case tests failed. Fix parameter name.Add util to check if sFlow is enabled in gNMI config. (#875)

Co-authored-by: kishanps <kishanps@google.com>
  • Loading branch information
VSuryaprasad-HCL and kishanps authored Dec 25, 2024
1 parent 7babec6 commit 400b8cd
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 343 deletions.
121 changes: 0 additions & 121 deletions tests/forwarding/smoke_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,127 +199,6 @@ TEST_P(SmokeTestFixture, FixedTableAddModifyDeleteOk) {
ASSERT_OK(pdpi::SetMetadataAndSendPiWriteRequest(&GetSutP4RuntimeSession(),
pi_request));

const sai::WriteRequest pd_delete = gutil::ParseProtoOrDie<sai::WriteRequest>(
R"pb(
updates {
type: DELETE
table_entry {
acl_ingress_table_entry {
match { is_ip { value: "0x1" } }
priority: 10
action { acl_forward {} }
}
}
}
)pb");
ASSERT_OK_AND_ASSIGN(p4::v1::WriteRequest pi_delete,
pdpi::PdWriteRequestToPi(
sai::GetIrP4Info(sai::Instantiation::kMiddleblock), pd_delete));

// Insert works.
ASSERT_OK(pdpi::SetMetadataAndSendPiWriteRequest(&GetSutP4RuntimeSession(),
pi_insert));

// ACL table entries are expected to contain counter data. However, it's
// updated periodically and may not be avaialable immediatly after writing so
// we poll the entry for a few seconds until we see the data.
absl::Time timeout = absl::Now() + absl::Seconds(11);
p4::v1::ReadResponse pi_read_response;
p4::v1::ReadRequest pi_read_request;
pi_read_request.add_entities()->mutable_table_entry();
do {
ASSERT_OK_AND_ASSIGN(pi_read_response,
pdpi::SetMetadataAndSendPiReadRequest(
&GetSutP4RuntimeSession(), pi_read_request));
ASSERT_EQ(pi_read_response.entities_size(), 1);

if (absl::Now() > timeout) {
FAIL() << "ACL table entry does not have counter data.";
}
} while (!pi_read_response.entities(0).table_entry().has_counter_data());

// Many ACL table attribues are NOT modifiable currently due to missing SAI
// implementation. Because there are no production use-cases, these are
// de-prioritized.
ASSERT_THAT(pdpi::SetMetadataAndSendPiWriteRequest(&GetSutP4RuntimeSession(),
pi_modify),
StatusIs(absl::StatusCode::kUnknown));

// Delete works.
ASSERT_OK(pdpi::SetMetadataAndSendPiWriteRequest(&GetSutP4RuntimeSession(),
pi_delete));
}

TEST_P(SmokeTestFixture, FixedTableAddModifyDeleteOk) {
p4::v1::WriteRequest pi_request;
ASSERT_OK_AND_ASSIGN(
*pi_request.add_updates(),
pins::VrfTableUpdate(
sai::GetIrP4Info(sai::Instantiation::kMiddleblock), p4::v1::Update::INSERT, "vrf-1"));
ASSERT_OK_AND_ASSIGN(
*pi_request.add_updates(),
pins::RouterInterfaceTableUpdate(sai::GetIrP4Info(sai::Instantiation::kMiddleblock),
p4::v1::Update::INSERT,
"router-intf-1", /*port=*/"1",
/*src_mac=*/"00:01:02:03:04:05"));
ASSERT_OK_AND_ASSIGN(
*pi_request.add_updates(),
pins::NeighborTableUpdate(sai::GetIrP4Info(sai::Instantiation::kMiddleblock),
p4::v1::Update::INSERT,
"router-intf-1",
/*neighbor_id=*/"fe80::0000:00ff:fe17:5f80",
/*dst_mac=*/"00:01:02:03:04:06"));
ASSERT_OK_AND_ASSIGN(
*pi_request.add_updates(),
pins::NexthopTableUpdate(sai::GetIrP4Info(sai::Instantiation::kMiddleblock),
p4::v1::Update::INSERT,
"nexthop-1", "router-intf-1",
/*neighbor_id=*/"fe80::0000:00ff:fe17:5f80"));
ASSERT_OK(pdpi::SetMetadataAndSendPiWriteRequest(&GetSutP4RuntimeSession(),
pi_request));

// Add and modify IPV4 table entry with different number of action params.
pi_request.Clear();
ASSERT_OK_AND_ASSIGN(
*pi_request.add_updates(),
pins::Ipv4TableUpdate(
sai::GetIrP4Info(sai::Instantiation::kMiddleblock),
p4::v1::Update::INSERT,
pins::IpTableOptions{
.vrf_id = "vrf-1",
.dst_addr_lpm = std::make_pair("20.0.0.1", 32),
.action = pins::IpTableOptions::Action::kSetNextHopId,
.nexthop_id = "nexthop-1",
}));
ASSERT_OK(pdpi::SetMetadataAndSendPiWriteRequest(&GetSutP4RuntimeSession(),
pi_request));
pi_request.Clear();
ASSERT_OK_AND_ASSIGN(
*pi_request.add_updates(),
pins::Ipv4TableUpdate(sai::GetIrP4Info(sai::Instantiation::kMiddleblock),
p4::v1::Update::MODIFY,
pins::IpTableOptions{
.vrf_id = "vrf-1",
.dst_addr_lpm = std::make_pair("20.0.0.1", 32),
.action = pins::IpTableOptions::Action::kDrop,
}));
ASSERT_OK(pdpi::SetMetadataAndSendPiWriteRequest(&GetSutP4RuntimeSession(),
pi_request));

pi_request.Clear();
ASSERT_OK_AND_ASSIGN(
*pi_request.add_updates(),
pins::Ipv4TableUpdate(sai::GetIrP4Info(sai::Instantiation::kMiddleblock),
p4::v1::Update::DELETE,
pins::IpTableOptions{
.vrf_id = "vrf-1",
.dst_addr_lpm = std::make_pair("20.0.0.1", 32),
.action = pins::IpTableOptions::Action::kDrop,
}));

ASSERT_OK(pdpi::SetMetadataAndSendPiWriteRequest(&GetSutP4RuntimeSession(),
pi_request));

// This used to fail with a read error.
ASSERT_OK(pdpi::ClearTableEntries(&GetSutP4RuntimeSession()));
}
Expand Down
98 changes: 25 additions & 73 deletions tests/integration/system/packet_forwarding_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "absl/flags/flag.h"
#include "absl/numeric/int128.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "absl/synchronization/mutex.h"
Expand All @@ -37,6 +42,7 @@
#include "gutil/status_matchers.h"
#include "gutil/testing.h"
#include "lib/basic_traffic/basic_p4rt_util.h"
#include "lib/basic_traffic/basic_traffic.h"
#include "lib/gnmi/gnmi_helper.h"
#include "lib/utils/generic_testbed_utils.h"
#include "p4/v1/p4runtime.pb.h"
Expand All @@ -50,14 +56,18 @@
#include "sai_p4/instantiations/google/instantiations.h"
#include "sai_p4/instantiations/google/sai_p4info.h"
#include "sai_p4/instantiations/google/sai_pd.pb.h"
#include "tests/lib/switch_test_setup_helpers.h"
#include "thinkit/control_device.h"
#include "thinkit/generic_testbed.h"
#include "thinkit/proto/generic_testbed.pb.h"
#include "thinkit/switch.h"

ABSL_FLAG(bool, push_p4_info, true, "Push P4 info to SUT.");

namespace pins_test {
namespace {

constexpr int kMtu[] = {1500, 5000, 9000};

// Test packet proto message sent from control switch to sut.
constexpr absl::string_view kTestPacket = R"pb(
Expand All @@ -74,72 +84,28 @@ constexpr absl::string_view kTestPacket = R"pb(
ihl: "0x5"
dscp: "0x03"
ecn: "0x0"
total_length: "0x00d4"
identification: "0x0000"
flags: "0x0"
fragment_offset: "0x0000"
ttl: "0x20"
protocol: "0x11"
checksum: "0x8c07"
ipv4_source: "1.2.3.4"
ipv4_destination: "10.0.0.1"
ipv4_destination: "$0"
}
}
headers { udp_header { source_port: "0x0000" destination_port: "0x0000" } }
payload: "Basic L3 test packet")pb";

// Sets up route from source port to destination port on sut.
absl::Status SetupRoute(pdpi::P4RuntimeSession& p4_session, int src_port_id,
int dst_port_id) {
RETURN_IF_ERROR(pins_test::basic_traffic::ProgramTrafficVrf(&p4_session,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock)));

RETURN_IF_ERROR(
basic_traffic::ProgramRouterInterface(&p4_session, src_port_id,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock)));

RETURN_IF_ERROR(
basic_traffic::ProgramRouterInterface(&p4_session, dst_port_id,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock)));

return basic_traffic::ProgramIPv4Route(&p4_session, dst_port_id,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock));
}

// Sets up route from source port to destination port on sut.
absl::Status SetupRoute(pdpi::P4RuntimeSession& p4_session, int src_port_id,
int dst_port_id) {
RETURN_IF_ERROR(pins_test::basic_traffic::ProgramTrafficVrf(&p4_session,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock)));

RETURN_IF_ERROR(
basic_traffic::ProgramRouterInterface(&p4_session, src_port_id,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock)));

RETURN_IF_ERROR(
basic_traffic::ProgramRouterInterface(&p4_session, dst_port_id,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock)));

return basic_traffic::ProgramIPv4Route(&p4_session, dst_port_id,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock));
}

// Sets up route from source port to destination port on sut.
absl::Status SetupRoute(pdpi::P4RuntimeSession& p4_session, int src_port_id,
int dst_port_id) {
RETURN_IF_ERROR(pins_test::basic_traffic::ProgramTrafficVrf(&p4_session,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock)));

RETURN_IF_ERROR(
basic_traffic::ProgramRouterInterface(&p4_session, src_port_id,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock)));

RETURN_IF_ERROR(
basic_traffic::ProgramRouterInterface(&p4_session, dst_port_id,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock)));

return basic_traffic::ProgramIPv4Route(&p4_session, dst_port_id,
sai::GetIrP4Info(sai::Instantiation::kMiddleblock));
// Pushes the P4 Info to SUT if the flag push_p4_info is set to true and returns
// the P4 Runtime Session
absl::StatusOr<std::unique_ptr<pdpi::P4RuntimeSession>> P4InfoPush(
const p4::config::v1::P4Info& p4_info, thinkit::GenericTestbed& testbed) {
std::optional<p4::config::v1::P4Info> p4info = std::nullopt;
if (absl::GetFlag(FLAGS_push_p4_info)) {
p4info = p4_info;
}
return ConfigureSwitchAndReturnP4RuntimeSession(
testbed.Sut(), /*gnmi_config=*/std::nullopt, p4info);
}

// Sets up route from source port to destination port on sut.
Expand Down Expand Up @@ -177,20 +143,6 @@ TEST_P(PacketForwardingTestFixture, PacketForwardingTest) {
ASSERT_OK_AND_ASSIGN(auto stub, testbed->Sut().CreateGnmiStub());
ASSERT_OK_AND_ASSIGN(auto port_id_by_interface,
GetAllInterfaceNameToPortId(*stub));
for (const auto& [interface, info] : testbed->GetSutInterfaceInfo()) {
if (info.interface_modes.contains(thinkit::CONTROL_INTERFACE)) {
int port_id;
EXPECT_TRUE(absl::SimpleAtoi(port_id_by_interface[interface], &port_id));
LOG(INFO) << "@ " << interface << ":" << info.peer_interface_name << ":"
<< port_id;
sut_interfaces.push_back(interface);
peer_interfaces.push_back(info.peer_interface_name);
sut_interface_ports.push_back(port_id);
}
if (sut_interfaces.size() == 2) {
break;
}
}

// Set the `source_interface` to the first SUT control interface.
const InterfaceLink& source_interface = control_interfaces[0];
Expand Down Expand Up @@ -225,22 +177,22 @@ TEST_P(PacketForwardingTestFixture, PacketForwardingTest) {

// Make test packet based on destination port ID.
const auto test_packet =
gutil::ParseProtoOrDie<packetlib::Packet>(kTestPacket);
gutil::ParseProtoOrDie<packetlib::Packet>(absl::Substitute(
kTestPacket, basic_traffic::PortIdToIP(destination_port_id)));
ASSERT_OK_AND_ASSIGN(std::string test_packet_data,
packetlib::SerializePacket(test_packet));

absl::Mutex mutex;
std::vector<std::string> received_packets;

static constexpr int kPacketsToSend = 10;
{
ASSERT_OK_AND_ASSIGN(auto finalizer,
testbed.get()->ControlDevice().CollectPackets());

LOG(INFO) << "Sending Packet to " << source_interface.peer_interface;

LOG(INFO) << "Test packet data: " << test_packet.DebugString();

for (int i = 0; i < 10; i++) {
for (int i = 0; i < kPacketsToSend; i++) {
// Send packet to SUT.
ASSERT_OK(testbed->ControlDevice().SendPacket(
source_interface.peer_interface, test_packet_data))
Expand Down
9 changes: 9 additions & 0 deletions tests/qos/qos_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
#include "lib/gnmi/gnmi_helper.h"

namespace pins_test {

QueueCounters operator-(const QueueCounters &x, const QueueCounters &y) {
return QueueCounters{
.num_packets_transmitted =
x.num_packets_transmitted - y.num_packets_transmitted,
.num_packet_dropped = x.num_packet_dropped - y.num_packet_dropped,
};
}

absl::StatusOr<QueueCounters> GetGnmiQueueCounters(
absl::string_view port, absl::string_view queue,
gnmi::gNMI::StubInterface &gnmi_stub) {
Expand Down
2 changes: 2 additions & 0 deletions tests/qos/qos_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ inline std::ostream &operator<<(std::ostream &os,
counters.num_packets_transmitted, counters.num_packet_dropped);
}

QueueCounters operator-(const QueueCounters &x, const QueueCounters &y);

// Get queue counters for a port queue.
absl::StatusOr<QueueCounters> GetGnmiQueueCounters(
absl::string_view port, absl::string_view queue,
Expand Down
2 changes: 2 additions & 0 deletions tests/sflow/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ cc_library(
"//tests/lib:p4rt_fixed_table_programming_helper",
"//tests/lib:switch_test_setup_helpers",
"//tests/qos:gnmi_parsers",
"//tests/qos:qos_test_util",
"//thinkit:generic_testbed",
"//thinkit:generic_testbed_fixture",
"//thinkit:mirror_testbed",
Expand All @@ -49,6 +50,7 @@ cc_library(
"@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
"@com_github_google_glog//:glog",
"@com_github_grpc_grpc//:grpc++",
"@com_google_absl//absl/cleanup",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/status",
Expand Down
Loading

0 comments on commit 400b8cd

Please sign in to comment.