Skip to content

Commit

Permalink
CPU QoS test (sonic-net#685)
Browse files Browse the repository at this point in the history
Co-authored-by: kishanps <[email protected]>
  • Loading branch information
divyagayathri-hcl and kishanps authored Nov 4, 2024
1 parent f048448 commit 30c9eed
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/qos/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2024 Google LLC
#
# 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
#
# https://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(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
)

cc_library(
name = "cpu_qos_test",
testonly = True,
srcs = ["cpu_qos_test.cc"],
hdrs = ["cpu_qos_test.h"],
deps = [
"//gutil:status",
"//gutil:status_matchers",
"//gutil:testing",
"//lib/gnmi:gnmi_helper",
"//lib/p4rt:packet_listener",
"//lib/validator:validator_lib",
"//p4_pdpi:ir",
"//p4_pdpi:pd",
"//p4_pdpi/packetlib",
"//p4_pdpi:p4_runtime_session",
"//p4_pdpi/packetlib:packetlib_cc_proto",
"//sai_p4/instantiations/google:sai_p4info_cc",
"//sai_p4/instantiations/google:sai_pd_cc_proto",
"//thinkit:generic_testbed",
"//thinkit:generic_testbed_fixture",
"//thinkit:switch",
"//thinkit/proto:generic_testbed_cc_proto",
"@com_github_google_glog//:glog",
"@com_github_nlohmann_json//:nlohmann_json",
"@com_google_absl//absl/cleanup",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
],
alwayslink = True,
)
95 changes: 95 additions & 0 deletions tests/qos/cpu_qos_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2024 Google LLC
//
// 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.

#include "tests/qos/cpu_qos_test.h"

#include <cstdint>
#include <string>
#include <vector>

#include "absl/cleanup/cleanup.h"
#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "absl/strings/escaping.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "glog/logging.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "gutil/status.h"
#include "gutil/status_matchers.h"
#include "gutil/testing.h"
#include "include/nlohmann/json.hpp"
#include "lib/gnmi/gnmi_helper.h"
#include "lib/p4rt/packet_listener.h"
#include "lib/validator/validator_lib.h"
#include "p4_pdpi/ir.h"
#include "p4_pdpi/p4_runtime_session.h"
#include "p4_pdpi/packetlib/packetlib.h"
#include "p4_pdpi/packetlib/packetlib.pb.h"
#include "p4_pdpi/pd.h"
#include "sai_p4/instantiations/google/sai_p4info.h"
#include "sai_p4/instantiations/google/sai_pd.pb.h"
#include "thinkit/generic_testbed.h"
#include "thinkit/proto/generic_testbed.pb.h"
#include "thinkit/switch.h"

namespace pins_test {

TEST_P(CpuQosIxiaTestFixture, TestCPUQueueRateLimit) {
// Pick a testbed with an Ixia Traffic Generator. A SUT is assumed.
auto requirements =
gutil::ParseProtoOrDie<thinkit::TestRequirements>(
R"pb(interface_requirements {
count: 1
interface_mode: TRAFFIC_GENERATOR
})pb");

ASSERT_OK_AND_ASSIGN(
std::unique_ptr<thinkit::GenericTestbed> generic_testbed,
GetParam().testbed_interface->GetTestbedWithRequirements(requirements));

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

// Connect to TestTracker for test status.
if (auto& id = GetParam().test_case_id; id.has_value()) {
generic_testbed->Environment().SetTestCaseID(*id);
}

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

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

// Set up P4Runtime session..
// TODO: Use `CreateWithP4InfoAndClearTables` cl/397193959 when
// its available.
ASSERT_OK_AND_ASSIGN(std::unique_ptr<pdpi::P4RuntimeSession> sut_p4_session,
pdpi::P4RuntimeSession::Create(generic_testbed->Sut()));
auto clear_table_entries = absl::Cleanup(
[&]() { ASSERT_OK(pdpi::ClearTableEntries(sut_p4_session.get())); });

// TODO: Set Up single P4RT punt flow.

// TODO:
// Setup Ixia traffic.
// Send Ixia traffic.
// Stop Ixia traffic.

}

} // namespace pins_test
41 changes: 41 additions & 0 deletions tests/qos/cpu_qos_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2024 Google LLC
//
// 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.

#ifndef PINS_TESTS_CPU_QOS_TEST_H_
#define PINS_TESTS_CPU_QOS_TEST_H_
#include "sai_p4/instantiations/google/sai_pd.pb.h"
#include "thinkit/generic_testbed.h"
#include "thinkit/generic_testbed_fixture.h"

namespace pins_test {

struct QosTestArguments {
// Description of the test instantation given by this set of arguments.
std::string description;
thinkit::GenericTestbedInterface* testbed_interface;
std::vector<sai::TableEntry> table_entries;
std::string gnmi_config;
absl::optional<std::string> test_case_id;
};

class CpuQosIxiaTestFixture : public testing::TestWithParam<QosTestArguments> {
protected:
void SetUp() override { GetParam().testbed_interface->SetUp(); }

void TearDown() override { GetParam().testbed_interface->TearDown(); }

~CpuQosIxiaTestFixture() override { delete GetParam().testbed_interface; }
};
} // namespace pins_test
#endif // PINS_TESTS_CPU_QOS_TEST_H_

0 comments on commit 30c9eed

Please sign in to comment.