From ab80020eeed27e56c6cbde3a1a3716c6a7815a48 Mon Sep 17 00:00:00 2001 From: smolkaj Date: Tue, 26 Nov 2024 06:24:47 +0000 Subject: [PATCH 1/4] Use generic testbed interface in BERT test. --- tests/gnoi/BUILD.bazel | 4 +- tests/gnoi/bert_tests.cc | 808 ++++++++++++++++++++++++--------------- tests/gnoi/bert_tests.h | 79 +++- 3 files changed, 579 insertions(+), 312 deletions(-) diff --git a/tests/gnoi/BUILD.bazel b/tests/gnoi/BUILD.bazel index fa89d2b2..80ffa3d6 100644 --- a/tests/gnoi/BUILD.bazel +++ b/tests/gnoi/BUILD.bazel @@ -31,7 +31,9 @@ cc_library( "//gutil:testing", "//lib/gnmi:gnmi_helper", "//lib/validator:validator_lib", - "//thinkit:mirror_testbed_fixture", + "//thinkit:control_device", + "//thinkit:generic_testbed", + "//thinkit:generic_testbed_fixture", "//thinkit:test_environment", "@com_github_gnoi//diag:diag_cc_proto", "@com_github_google_glog//:glog", diff --git a/tests/gnoi/bert_tests.cc b/tests/gnoi/bert_tests.cc index b12fed12..81704c6d 100644 --- a/tests/gnoi/bert_tests.cc +++ b/tests/gnoi/bert_tests.cc @@ -15,6 +15,7 @@ #include "tests/gnoi/bert_tests.h" #include + #include "absl/container/flat_hash_set.h" #include "absl/flags/flag.h" #include "absl/random/random.h" @@ -28,11 +29,14 @@ #include "gmock/gmock.h" #include "google/protobuf/text_format.h" #include "google/protobuf/util/message_differencer.h" +#include "grpcpp/impl/codegen/client_context.h" #include "gtest/gtest.h" #include "gutil/status_matchers.h" #include "gutil/testing.h" #include "lib/gnmi/gnmi_helper.h" #include "lib/validator/validator_lib.h" +#include "thinkit/control_device.h" +#include "thinkit/generic_testbed.h" #include "thinkit/test_environment.h" ABSL_FLAG(uint32_t, idx_seed, static_cast(std::time(nullptr)), @@ -67,6 +71,8 @@ constexpr absl::Duration kPollInterval = absl::Seconds(30); constexpr absl::Duration kWaitTime = absl::Seconds(30); // Wait time for ports to be up after re-enabling admin down ports. constexpr absl::Duration kPortsUpWaitTime = absl::Seconds(30); +// Wait time for BERT recovery phase. +constexpr absl::Duration kWaitForRecoveryComplete = absl::Seconds(90); constexpr uint8_t kMaxAllowedInterfacesToRunBert = 96; @@ -102,12 +108,12 @@ const std::string BuildOpenConfigInterface(absl::string_view interface_name) { interface_name); } -void SendStartBertRequestSuccessfully( - gnoi::diag::StartBERTRequest& request, +void SendStartBertRequestSuccessfullyOnSut( + const gnoi::diag::StartBERTRequest& request, gnoi::diag::Diag::StubInterface& gnoi_diag_stub) { gnoi::diag::StartBERTResponse response; grpc::ClientContext context; - LOG(INFO) << "StartBERT request: " << request.ShortDebugString(); + LOG(INFO) << "StartBERT request on SUT: " << request.ShortDebugString(); ASSERT_OK(gnoi_diag_stub.StartBERT(&context, request, &response)); // Verify response. @@ -117,7 +123,7 @@ void SendStartBertRequestSuccessfully( for (int idx = 0; idx < response.per_port_responses_size(); ++idx) { auto per_port_response = response.per_port_responses(idx); - SCOPED_TRACE(absl::StrCat("Verifying StartBERT port response: ", + SCOPED_TRACE(absl::StrCat("Verifying StartBERT port response on SUT: ", per_port_response.ShortDebugString())); EXPECT_EQ(per_port_response.status(), gnoi::diag::BERT_STATUS_OK); EXPECT_TRUE( @@ -126,6 +132,32 @@ void SendStartBertRequestSuccessfully( } } +void SendStartBertRequestSuccessfullyOnControlSwitch( + const gnoi::diag::StartBERTRequest& request, + thinkit::ControlDevice& control_device) { + LOG(INFO) << "StartBERT request on control switch: " + << request.ShortDebugString(); + + ASSERT_OK_AND_ASSIGN(gnoi::diag::StartBERTResponse response, + control_device.StartBERT(request)); + + // Verify response. + ASSERT_THAT(response.per_port_responses(), + SizeIs(request.per_port_requests_size())); + EXPECT_EQ(response.bert_operation_id(), request.bert_operation_id()); + + for (int idx = 0; idx < response.per_port_responses_size(); ++idx) { + auto per_port_response = response.per_port_responses(idx); + SCOPED_TRACE( + absl::StrCat("Verifying StartBERT port response on control switch: ", + per_port_response.ShortDebugString())); + EXPECT_EQ(per_port_response.status(), gnoi::diag::BERT_STATUS_OK); + EXPECT_TRUE( + MessageDifferencer::Equals(per_port_response.interface(), + request.per_port_requests(idx).interface())); + } +} + absl::StatusOr GetInterfaceNameFromOcInterfacePath( const gnoi::types::Path& interface) { // Validate if interface is in valid format(either in OpenConfig format or @@ -180,38 +212,75 @@ void SetAdminStateOnInterfaceList(gnmi::gNMI::StubInterface& gnmi_stub, } bool IsInterfaceInList(absl::string_view interface, - std::vector& interfaces) { + const std::vector& interfaces) { return std::find(interfaces.begin(), interfaces.end(), interface) != interfaces.end(); } void WaitForBertToCompleteOnInterfaces( gnmi::gNMI::StubInterface& sut_gnmi_stub, - gnmi::gNMI::StubInterface& control_switch_gnmi_stub, - std::vector& interfaces, int max_poll_count) { + std::vector sut_interfaces, + thinkit::ControlDevice& control_device, + gnoi::diag::GetBERTResultRequest control_switch_result_request, + int max_poll_count) { for (int count = 0; count < max_poll_count; ++count) { absl::SleepFor(kPollInterval); // If port is no longer in "TESTING" oper state on both sides of the link, // linkqual has completed on the link and full result is ready. - for (auto it = interfaces.begin(); it != interfaces.end();) { + for (auto it = sut_interfaces.begin(); it != sut_interfaces.end();) { ASSERT_OK_AND_ASSIGN( pins_test::OperStatus oper_status, pins_test::GetInterfaceOperStatusOverGnmi(sut_gnmi_stub, *it)); if (oper_status != pins_test::OperStatus::kTesting) { - ASSERT_OK_AND_ASSIGN(oper_status, - pins_test::GetInterfaceOperStatusOverGnmi( - control_switch_gnmi_stub, *it)); - if (oper_status != pins_test::OperStatus::kTesting) { - it = interfaces.erase(it); - continue; - } + it = sut_interfaces.erase(it); + continue; } ++it; } - if (interfaces.empty()) break; + + // Check if BERT is completed on control switch - we cannot check + // "TESTING" mode on control device so read BERT result and verify that + // BERT either failed, or succeeded and the error count per minute field + // is completely populated (size is equal to number of minutes). If status + // is OK and error count per minute field isn't completely populated, BERT + // is still in progress. + if (control_switch_result_request.per_port_requests_size() != 0) { + gnoi::diag::GetBERTResultRequest tmp_result_request; + tmp_result_request.set_bert_operation_id( + control_switch_result_request.bert_operation_id()); + ASSERT_OK_AND_ASSIGN( + gnoi::diag::GetBERTResultResponse result_response, + control_device.GetBERTResult(control_switch_result_request)); + ASSERT_THAT( + result_response.per_port_responses(), + SizeIs(control_switch_result_request.per_port_requests_size())); + int testDurationMinutes = absl::ToInt64Minutes(kTestDuration); + for (const auto& result : result_response.per_port_responses()) { + if (result.status() == gnoi::diag::BERT_STATUS_OK && + result.error_count_per_minute_size() < testDurationMinutes) { + *(tmp_result_request.add_per_port_requests()->mutable_interface()) = + result.interface(); + } + } + control_switch_result_request = tmp_result_request; + } + if (sut_interfaces.empty() && + (control_switch_result_request.per_port_requests_size() == 0)) + break; } - EXPECT_THAT(interfaces, testing::IsEmpty()); + EXPECT_THAT(sut_interfaces, testing::IsEmpty()); + EXPECT_THAT(control_switch_result_request.per_port_requests(), + testing::IsEmpty()); + // For SUT ports, verification of non-TESTING mode is enough to indicate the + // completion of BERT. However for the control switch, there is a possibility + // that when the result was read, results were fully populated but recovery + // steps were not completed yet, if control switch BERT steps were running + // behind the SUT BERT steps - we cannot differentiate if BERT is completed or + // post BERT recovery steps are still in progress based on BERT results on + // control switch. Sleeping for some extra time ensures that control switch + // BERT is completed. + absl::SleepFor(kWaitForRecoveryComplete); } void VerifyBertResultForSuccess( @@ -245,7 +314,7 @@ void VerifyBertResultForSuccess( // Helps in getting the BERT result on a set of ports and if BERT is running on // the port, forces admin status down by disabling it. It also modifies the // list of ports in request by removing the port that was running BERT. -void CheckRunningBertAndForceAdminDownHelper( +void CheckRunningBertAndForceAdminDownHelperSut( gnoi::diag::Diag::StubInterface& gnoi_diag_stub, gnmi::gNMI::StubInterface& gnmi_stub, gnoi::diag::GetBERTResultRequest* request) { @@ -253,7 +322,7 @@ void CheckRunningBertAndForceAdminDownHelper( grpc::ClientContext context; ASSERT_OK(gnoi_diag_stub.GetBERTResult(&context, *request, &response)); - ASSERT_THAT(response.per_port_responses(), + ASSERT_THAT(response.per_port_responses(), SizeIs(request->per_port_requests_size())); request->clear_per_port_requests(); for (const auto& result : response.per_port_responses()) { @@ -277,15 +346,42 @@ void CheckRunningBertAndForceAdminDownHelper( } } +void CheckRunningBertAndForceAdminDownHelperControlSwitch( + thinkit::ControlDevice& control_device, + gnoi::diag::GetBERTResultRequest* request) { + gnoi::diag::GetBERTResultResponse response; + + ASSERT_OK_AND_ASSIGN(response, control_device.GetBERTResult(*request)); + + ASSERT_THAT(response.per_port_responses(), + SizeIs(request->per_port_requests_size())); + request->clear_per_port_requests(); + for (const auto& result : response.per_port_responses()) { + // Check if BERT is running. + if ((result.status() == gnoi::diag::BERT_STATUS_OK) && + (result.peer_lock_established())) { + ASSERT_OK_AND_ASSIGN( + const std::string interface, + GetInterfaceNameFromOcInterfacePath(result.interface())); + // Disable the admin status. + EXPECT_OK(control_device.SetAdminLinkState({interface}, + thinkit::LinkState::kDown)); + } else { + // Get result for interfaces again that didn't start BERT in last poll. + *(request->add_per_port_requests()->mutable_interface()) = + result.interface(); + } + } +} + // Checks if BERT is running on the ports where we are supposed to force admin // status DOWN. If BERT is running, force admin status to DOWN on port. void CheckRunningBertAndForceAdminDown( gnoi::diag::Diag::StubInterface& sut_gnoi_diag_stub, - gnoi::diag::Diag::StubInterface& control_switch_gnoi_diag_stub, - gnmi::gNMI::StubInterface& sut_gnmi_stub, - gnmi::gNMI::StubInterface& control_switch_gnmi_stub, - absl::string_view op_id, std::vector& sut_interfaces, - std::vector& control_switch_interfaces) { + thinkit::ControlDevice& control_device, + gnmi::gNMI::StubInterface& sut_gnmi_stub, absl::string_view op_id, + const std::vector& sut_interfaces, + const std::vector& control_switch_interfaces) { gnoi::diag::GetBERTResultRequest sut_request; sut_request.set_bert_operation_id(std::string(op_id)); for (const std::string& interface : sut_interfaces) { @@ -310,15 +406,15 @@ void CheckRunningBertAndForceAdminDown( absl::SleepFor(kPollInterval); if (sut_request.per_port_requests_size() > 0) { // Check BERT status on SUT and force admin status down. - ASSERT_NO_FATAL_FAILURE(CheckRunningBertAndForceAdminDownHelper( + ASSERT_NO_FATAL_FAILURE(CheckRunningBertAndForceAdminDownHelperSut( sut_gnoi_diag_stub, sut_gnmi_stub, &sut_request)); } if (control_switch_request.per_port_requests_size() > 0) { // Check BERT status on control switch and force admin status down. - ASSERT_NO_FATAL_FAILURE(CheckRunningBertAndForceAdminDownHelper( - control_switch_gnoi_diag_stub, control_switch_gnmi_stub, - &control_switch_request)); + ASSERT_NO_FATAL_FAILURE( + CheckRunningBertAndForceAdminDownHelperControlSwitch( + control_device, &control_switch_request)); } if (sut_request.per_port_requests().empty() && control_switch_request.per_port_requests().empty()) { @@ -327,7 +423,7 @@ void CheckRunningBertAndForceAdminDown( --max_poll_count; } - EXPECT_THAT(sut_request.per_port_requests(), testing::IsEmpty()); + EXPECT_THAT(sut_request.per_port_requests(), testing::IsEmpty()); EXPECT_THAT(control_switch_request.per_port_requests(), testing::IsEmpty()); } @@ -335,20 +431,10 @@ void CheckRunningBertAndForceAdminDown( // failure result on ports where admin status was forced to DOWN. Other ports // are expected to have successful BERT results. void GetAndVerifyBertResultsWithAdminDownInterfaces( - gnoi::diag::Diag::StubInterface& gnoi_diag_stub, - gnoi::diag::StartBERTRequest& bert_request, - std::vector& sut_admin_down_interfaces, - std::vector& control_switch_admin_down_interfaces) { - gnoi::diag::GetBERTResultRequest result_request; - result_request.set_bert_operation_id(bert_request.bert_operation_id()); - for (unsigned idx = 0; idx < bert_request.per_port_requests_size(); ++idx) { - *(result_request.add_per_port_requests()->mutable_interface()) = - bert_request.per_port_requests(idx).interface(); - } - gnoi::diag::GetBERTResultResponse result_response; - grpc::ClientContext result_context; - ASSERT_OK(gnoi_diag_stub.GetBERTResult(&result_context, result_request, - &result_response)); + const gnoi::diag::StartBERTRequest& bert_request, + const gnoi::diag::GetBERTResultResponse& result_response, + const std::vector& sut_admin_down_interfaces, + const std::vector& control_switch_admin_down_interfaces) { ASSERT_THAT(result_response.per_port_responses(), SizeIs(bert_request.per_port_requests_size())); for (unsigned idx = 0; idx < result_response.per_port_responses_size(); @@ -380,36 +466,93 @@ void GetAndVerifyBertResultsWithAdminDownInterfaces( } } -void SelectNUpInterfaces(int port_count_to_select, - gnmi::gNMI::StubInterface& gnmi_stub, - std::vector* interfaces) { - // Get all the interfaces that are operational status "UP". - ASSERT_OK_AND_ASSIGN(*interfaces, - pins_test::GetUpInterfacesOverGnmi(gnmi_stub)); - // Choose random ports. - ASSERT_GE(interfaces->size(), port_count_to_select); - std::shuffle(interfaces->begin(), interfaces->end(), absl::BitGen()); - interfaces->resize(port_count_to_select); +gnoi::diag::GetBERTResultRequest GetBertResultRequestFromStartRequest( + const gnoi::diag::StartBERTRequest& start_request) { + gnoi::diag::GetBERTResultRequest result_request; + result_request.set_bert_operation_id(start_request.bert_operation_id()); + for (const auto& per_port_request : start_request.per_port_requests()) { + *(result_request.add_per_port_requests()->mutable_interface()) = + per_port_request.interface(); + } + return result_request; +} + +void VerifyOperStatusOnSetOfSutInterfaces(gnmi::gNMI::StubInterface& gnmi_stub, + std::vector& interfaces, + absl::string_view oper_status) { + LOG(INFO) << "Verifying operational state " << oper_status + << " on interfaces."; + ASSERT_OK_AND_ASSIGN(auto interface_to_oper_status_map, + pins_test::GetInterfaceToOperStatusMapOverGnmi( + gnmi_stub, /*timeout=*/absl::Seconds(60))); + for (const std::string& interface : interfaces) { + SCOPED_TRACE(absl::StrCat("Interface: ", interface)); + EXPECT_NE(interface_to_oper_status_map.count(interface), 0); + EXPECT_EQ(interface_to_oper_status_map[interface], oper_status); + } +} + +absl::Status ValidateControlSwitchPortsUp( + thinkit::ControlDevice& control_device, + const std::vector& interfaces) { + ASSIGN_OR_RETURN( + const auto up_interfaces, + control_device.GetUpLinks(absl::Span(interfaces))); + + std::vector down_interfaces; + for (const std::string& interface : interfaces) { + if (!up_interfaces.contains(interface)) { + down_interfaces.push_back(interface); + } + } + + if (!down_interfaces.empty()) { + return absl::InternalError( + absl::StrCat("Some interfaces are not up on control switch: ", + absl::StrJoin(down_interfaces, "\n"))); + } + return absl::OkStatus(); +} + +std::vector SelectNInterfacesFromList( + int port_count_to_select, std::vector interfaces) { + if (interfaces.size() < port_count_to_select) { + return std::vector(); + } + std::shuffle(interfaces.begin(), interfaces.end(), absl::BitGen()); + interfaces.resize(port_count_to_select); + return interfaces; +} + +bool IsListPartOfInterfaceList(const std::vector& list, + const std::vector& interface_list) { + for (const std::string& interface : list) { + if (IsInterfaceInList(interface, interface_list) == false) { + return false; + } + } + return true; } // Test StartBERT with invalid request parameters. TEST_P(BertTest, StartBertFailsIfRequestParametersInvalid) { - GetMirrorTestbed().Environment().SetTestCaseID( - "c1dcb1cc-4806-45cc-8f8a-676beafde103"); - thinkit::Switch& sut = GetMirrorTestbed().Sut(); - ASSERT_OK(pins_test::PortsUp(sut)); - ASSERT_OK_AND_ASSIGN(auto sut_gnoi_diag_stub, sut.CreateGnoiDiagStub()); + ASSERT_NO_FATAL_FAILURE( + InitializeTestEnvironment("c1dcb1cc-4806-45cc-8f8a-676beafde103")); + thinkit::Switch& sut = generic_testbed_->Sut(); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); // Select one operational state "up" port. std::string interface = absl::GetFlag(FLAGS_interface); - if (interface.empty()) { - std::vector interfaces; - ASSERT_OK_AND_ASSIGN( - std::unique_ptr sut_gnmi_stub, - sut.CreateGnmiStub()); - ASSERT_NO_FATAL_FAILURE( - SelectNUpInterfaces(1, *sut_gnmi_stub, &interfaces)); - interface = interfaces[0]; + if (!interface.empty()) { + // Verify that provided interfaces are part of SUT's UP interfaces. + ASSERT_TRUE(IsInterfaceInList(interface, sut_interfaces_)) + << "SUT test interface selected for test: " + << interface << "./n UP interfaces on SUT: " + << absl::StrJoin(sut_interfaces_, ","); + } else { + sut_test_interfaces_ = SelectNInterfacesFromList(1, sut_interfaces_); + interface = sut_test_interfaces_[0]; } LOG(INFO) << "Selected interface: " << interface << ". To repeat the test with same interface, use " @@ -421,7 +564,7 @@ TEST_P(BertTest, StartBertFailsIfRequestParametersInvalid) { absl::StrCat("OpId-", absl::ToUnixMillis(absl::Now()))); *(valid_request.add_per_port_requests()) = gutil::ParseProtoOrDie( - BuildPerPortStartBertRequest("interface")); + BuildPerPortStartBertRequest(interface)); gnoi::diag::StartBERTResponse response; // Case 1: BERT test duration is 0 secs. @@ -432,7 +575,7 @@ TEST_P(BertTest, StartBertFailsIfRequestParametersInvalid) { grpc::ClientContext context; LOG(INFO) << "Sending StartBERT request: " << too_short_time_request.ShortDebugString(); - EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_gnoi_diag_stub->StartBERT( + EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_diag_stub_->StartBERT( &context, too_short_time_request, &response)), gutil::StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("is too short"))); @@ -448,7 +591,7 @@ TEST_P(BertTest, StartBertFailsIfRequestParametersInvalid) { grpc::ClientContext context; LOG(INFO) << "Sending StartBERT request: " << too_long_time_request.ShortDebugString(); - EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_gnoi_diag_stub->StartBERT( + EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_diag_stub_->StartBERT( &context, too_long_time_request, &response)), gutil::StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("is too long"))); @@ -463,7 +606,7 @@ TEST_P(BertTest, StartBertFailsIfRequestParametersInvalid) { grpc::ClientContext context; LOG(INFO) << "Sending StartBERT request: " << unset_prbs_polynomial_request.ShortDebugString(); - EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_gnoi_diag_stub->StartBERT( + EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_diag_stub_->StartBERT( &context, unset_prbs_polynomial_request, &response)), gutil::StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("PRBS polynomial is not set"))); @@ -480,13 +623,13 @@ TEST_P(BertTest, StartBertFailsIfRequestParametersInvalid) { grpc::ClientContext context; LOG(INFO) << "Sending StartBERT request: " << invalid_interface_request.ShortDebugString(); - EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_gnoi_diag_stub->StartBERT( + EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_diag_stub_->StartBERT( &context, invalid_interface_request, &response)), gutil::StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("Interface is invalid"))); } - // TODO (b/176913347): Enable the all ports UP check. - // ASSERT_OK(pins_test::PortsUp(sut)); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); } // Test StopBERT RPC with invalid argument in the request. @@ -494,12 +637,11 @@ TEST_P(BertTest, StartBertFailsIfRequestParametersInvalid) { // 2) If StopBERT RPC is requested on a port that is not running BERT, RPC // should fail. TEST_P(BertTest, StopBertfailsIfRequestParametersInvalid) { - GetMirrorTestbed().Environment().SetTestCaseID( - "224db9cf-c709-486d-a0d3-6ab64c1a1e1f"); - thinkit::Switch& sut = GetMirrorTestbed().Sut(); - - ASSERT_OK(pins_test::PortsUp(sut)); - ASSERT_OK_AND_ASSIGN(auto sut_gnoi_diag_stub, sut.CreateGnoiDiagStub()); + ASSERT_NO_FATAL_FAILURE( + InitializeTestEnvironment("224db9cf-c709-486d-a0d3-6ab64c1a1e1f")); + thinkit::Switch& sut = generic_testbed_->Sut(); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); // Request StopBERT RPC on an invalid port, RPC should fail. { @@ -515,7 +657,7 @@ TEST_P(BertTest, StopBertfailsIfRequestParametersInvalid) { LOG(INFO) << "Sending StopBERT request: " << request.ShortDebugString(); EXPECT_THAT( gutil::GrpcStatusToAbslStatus( - sut_gnoi_diag_stub->StopBERT(&context, request, &response)), + sut_diag_stub_->StopBERT(&context, request, &response)), gutil::StatusIs( absl::StatusCode::kInvalidArgument, AllOf(HasSubstr("Interface is invalid"), @@ -526,12 +668,15 @@ TEST_P(BertTest, StopBertfailsIfRequestParametersInvalid) { { // Select one operational state "up" port. std::string interface = absl::GetFlag(FLAGS_interface); - if (interface.empty()) { - std::vector interfaces; - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - ASSERT_NO_FATAL_FAILURE( - SelectNUpInterfaces(1, *sut_gnmi_stub, &interfaces)); - interface = interfaces[0]; + if (!interface.empty()) { + // Verify that provided interfaces are part of SUT's UP interfaces. + ASSERT_TRUE(IsInterfaceInList(interface, sut_interfaces_)) + << "SUT test interface selected for test: " + << interface << "./n UP interfaces on SUT: " + << absl::StrJoin(sut_interfaces_, ","); + } else { + sut_test_interfaces_ = SelectNInterfacesFromList(1, sut_interfaces_); + interface = sut_test_interfaces_[0]; } LOG(INFO) << "Selected interface: " << interface << ". To repeat the test with same interface, use " @@ -549,13 +694,12 @@ TEST_P(BertTest, StopBertfailsIfRequestParametersInvalid) { LOG(INFO) << "Sending StopBERT request: " << request.ShortDebugString(); EXPECT_THAT( gutil::GrpcStatusToAbslStatus( - sut_gnoi_diag_stub->StopBERT(&context, request, &response)), + sut_diag_stub_->StopBERT(&context, request, &response)), gutil::StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("Operation ID is not found on interface"))); } - - // TODO (b/176913347): Enable the all ports UP check. - // ASSERT_OK(pins_test::PortsUp(sut)); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); } // Test GetBERTResult RPC with invalid argument in the request. @@ -563,11 +707,11 @@ TEST_P(BertTest, StopBertfailsIfRequestParametersInvalid) { // 2) If GetBERTResult RPC is requested on a port that never ran BERT before, // RPC should fail. TEST_P(BertTest, GetBertResultFailsIfRequestParametersInvalid) { - GetMirrorTestbed().Environment().SetTestCaseID( - "4f837d7a-ab44-4694-9ca9-399d576757f4"); - thinkit::Switch& sut = GetMirrorTestbed().Sut(); - ASSERT_OK(pins_test::PortsUp(sut)); - ASSERT_OK_AND_ASSIGN(auto sut_gnoi_diag_stub, sut.CreateGnoiDiagStub()); + ASSERT_NO_FATAL_FAILURE( + InitializeTestEnvironment("4f837d7a-ab44-4694-9ca9-399d576757f4")); + thinkit::Switch& sut = generic_testbed_->Sut(); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); // Request GetBERTResult RPC on an invalid port, RPC should fail. { @@ -582,7 +726,7 @@ TEST_P(BertTest, GetBertResultFailsIfRequestParametersInvalid) { grpc::ClientContext context; LOG(INFO) << "Sending GetBERTResult request: " << result_request.ShortDebugString(); - EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_gnoi_diag_stub->GetBERTResult( + EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_diag_stub_->GetBERTResult( &context, result_request, &result_response)), gutil::StatusIs( absl::StatusCode::kInvalidArgument, @@ -593,12 +737,15 @@ TEST_P(BertTest, GetBertResultFailsIfRequestParametersInvalid) { { // Select one operational state "up" port. std::string interface = absl::GetFlag(FLAGS_interface); - if (interface.empty()) { - std::vector interfaces; - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - ASSERT_NO_FATAL_FAILURE( - SelectNUpInterfaces(1, *sut_gnmi_stub, &interfaces)); - interface = interfaces[0]; + if (!interface.empty()) { + // Verify that provided interfaces are part of SUT's UP interfaces. + ASSERT_TRUE(IsInterfaceInList(interface, sut_interfaces_)) + << "SUT test interface selected for test: " + << interface << "./n UP interfaces on SUT: " + << absl::StrJoin(sut_interfaces_, ","); + } else { + sut_test_interfaces_ = SelectNInterfacesFromList(1, sut_interfaces_); + interface = sut_test_interfaces_[0]; } LOG(INFO) << "Selected interface: " << interface << ". To repeat the test with same interface, use " @@ -616,33 +763,35 @@ TEST_P(BertTest, GetBertResultFailsIfRequestParametersInvalid) { grpc::ClientContext context; LOG(INFO) << "Sending GetBERTResult request: " << result_request.ShortDebugString(); - EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_gnoi_diag_stub->GetBERTResult( + EXPECT_THAT(gutil::GrpcStatusToAbslStatus(sut_diag_stub_->GetBERTResult( &context, result_request, &result_response)), gutil::StatusIs(absl::StatusCode::kInvalidArgument, AllOf(HasSubstr("Result is not found for intf"), HasSubstr(interface)))); } - - ASSERT_OK(pins_test::PortsUp(sut)); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); } - // Test StartBERT fails if peer port is not running BERT. TEST_P(BertTest, StartBertfailsIfPeerPortNotRunningBert) { - GetMirrorTestbed().Environment().SetTestCaseID( - "37e48922-0616-4d16-8fd3-975897491956"); - thinkit::Switch& sut = GetMirrorTestbed().Sut(); - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - ASSERT_OK(pins_test::PortsUp(sut)); - ASSERT_OK_AND_ASSIGN(auto sut_gnoi_diag_stub, sut.CreateGnoiDiagStub()); + ASSERT_NO_FATAL_FAILURE( + InitializeTestEnvironment("37e48922-0616-4d16-8fd3-975897491956")); + thinkit::Switch& sut = generic_testbed_->Sut(); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); // Select one operational state "up" port. std::string interface = absl::GetFlag(FLAGS_interface); - if (interface.empty()) { - std::vector interfaces; - ASSERT_NO_FATAL_FAILURE( - SelectNUpInterfaces(1, *sut_gnmi_stub, &interfaces)); - interface = interfaces[0]; + if (!interface.empty()) { + // Verify that provided interfaces are part of SUT's UP interfaces. + ASSERT_TRUE(IsInterfaceInList(interface, sut_interfaces_)) + << "SUT test interface selected for test: " + << interface << "./n UP interfaces on SUT: " + << absl::StrJoin(sut_interfaces_, ","); + } else { + sut_test_interfaces_ = SelectNInterfacesFromList(1, sut_interfaces_); + interface = sut_test_interfaces_[0]; } LOG(INFO) << "Selected interface: " << interface << ". To repeat the test with same interface, use " @@ -655,19 +804,20 @@ TEST_P(BertTest, StartBertfailsIfPeerPortNotRunningBert) { *(bert_request.add_per_port_requests()) = gutil::ParseProtoOrDie( BuildPerPortStartBertRequest(interface)); - gnoi::diag::StartBERTResponse bert_response; - grpc::ClientContext context; - LOG(INFO) << "Sending StartBERT request: " << bert_request.ShortDebugString(); + + LOG(INFO) << "Sending StartBERT request on SUT:"; + ASSERT_NO_FATAL_FAILURE( + SendStartBertRequestSuccessfullyOnSut(bert_request, *sut_diag_stub_)); // Poll for allowed BERT delay duration. int max_poll_count = ceil(ToInt64Seconds(kDelayDuration) / ToInt64Seconds(kPollInterval)); bool poll_timeout = true; - for (int count = 0; count < max_poll_count; ++count) { + for (int count = 0; count < max_poll_count; ++count) { absl::SleepFor(kPollInterval); ASSERT_OK_AND_ASSIGN( pins_test::OperStatus oper_status, - pins_test::GetInterfaceOperStatusOverGnmi(*sut_gnmi_stub, interface)); + pins_test::GetInterfaceOperStatusOverGnmi(*sut_gnmi_stub_, interface)); // If port is "UP" and no longer in "TESTING" oper state, BERT has completed // on the port and full BERT result is ready for read. if (oper_status == pins_test::OperStatus::kUp) { @@ -675,6 +825,7 @@ TEST_P(BertTest, StartBertfailsIfPeerPortNotRunningBert) { break; } } + if (poll_timeout == true) { LOG(WARNING) << "BERT is not completed on the port in maximum allowed time."; @@ -684,14 +835,13 @@ TEST_P(BertTest, StartBertfailsIfPeerPortNotRunningBert) { result_request.set_bert_operation_id(bert_request.bert_operation_id()); *(result_request.add_per_port_requests()->mutable_interface()) = bert_request.per_port_requests(0).interface(); - gnoi::diag::GetBERTResultResponse result_response; grpc::ClientContext result_context; - EXPECT_OK(sut_gnoi_diag_stub->GetBERTResult(&result_context, result_request, - &result_response)); + EXPECT_OK(sut_diag_stub_->GetBERTResult(&result_context, result_request, + &result_response)); LOG(INFO) << "Result: " << result_response.ShortDebugString(); - // TODO (b/176913347): Enable the all ports UP check. - // ASSERT_OK(pins_test::PortsUp(sut)); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); // Verify the response. ASSERT_THAT(result_response.per_port_responses(), SizeIs(1)); EXPECT_EQ(result_response.per_port_responses(0).status(), @@ -707,40 +857,59 @@ TEST_P(BertTest, StartBertfailsIfPeerPortNotRunningBert) { // 3) Operation id that was used earlier to start the BERT test will fail to // start BERT if used again. TEST_P(BertTest, StartBertSucceeds) { - GetMirrorTestbed().Environment().SetTestCaseID( - "b31a796a-d078-4d45-b785-f09ec598e05a"); - thinkit::Switch& sut = GetMirrorTestbed().Sut(); - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - ASSERT_OK(pins_test::PortsUp(sut)); - ASSERT_OK_AND_ASSIGN(auto sut_gnoi_diag_stub, sut.CreateGnoiDiagStub()); + ASSERT_NO_FATAL_FAILURE( + InitializeTestEnvironment("b31a796a-d078-4d45-b785-f09ec598e05a")); + thinkit::Switch& sut = generic_testbed_->Sut(); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); - thinkit::Switch& control_switch = GetMirrorTestbed().ControlSwitch(); - ASSERT_OK_AND_ASSIGN(auto control_switch_gnmi_stub, - control_switch.CreateGnmiStub()); - ASSERT_OK(pins_test::PortsUp(control_switch)); - ASSERT_OK_AND_ASSIGN(auto control_switch_gnoi_diag_stub, - control_switch.CreateGnoiDiagStub()); + thinkit::ControlDevice& control_device = generic_testbed_->ControlDevice(); + ASSERT_OK(ValidateControlSwitchPortsUp(control_device, peer_interfaces_)); // Select 2 operational state "up" ports. - std::vector interfaces = absl::GetFlag(FLAGS_interfaces); - if (interfaces.empty()) { - ASSERT_OK_AND_ASSIGN(std::unique_ptr sut_gnmi_stub, - sut.CreateGnmiStub()); - ASSERT_NO_FATAL_FAILURE( - SelectNUpInterfaces(2, *sut_gnmi_stub, &interfaces)); + sut_test_interfaces_ = absl::GetFlag(FLAGS_interfaces); + constexpr int kNumInterfaces = 2; + if (!sut_test_interfaces_.empty()) { + // Verify that provided interfaces are part of SUT's UP interfaces. + ASSERT_TRUE( + IsListPartOfInterfaceList(sut_test_interfaces_, sut_interfaces_)) + << "SUT test infaces selected for test: " + << absl::StrJoin(sut_test_interfaces_, ",") + << "./n UP interfaces on SUT: " << absl::StrJoin(sut_interfaces_, ","); + } else { + sut_test_interfaces_ = + SelectNInterfacesFromList(kNumInterfaces, sut_interfaces_); + } + ASSERT_THAT(sut_test_interfaces_, SizeIs(kNumInterfaces)); + // Get peer test interfaces corresponding to SUT test interfaces. + ASSERT_OK_AND_ASSIGN(peer_test_interfaces_, + GetPeerInterfacesForSutInterfaces(sut_test_interfaces_)); + LOG(INFO) << "Selected {SUT, control_device} interfaces: "; + for (size_t idx = 0; idx < sut_test_interfaces_.size(); ++idx) { + LOG(INFO) << "{" << sut_test_interfaces_[idx] << ", " + << peer_test_interfaces_[idx] << "}, "; } - ASSERT_THAT(interfaces, SizeIs(2)); - LOG(INFO) << "Selected interfaces: " << absl::StrJoin(interfaces, ",") - << ". To repeat the test with same interfaces, " - << "use --test_arg=--interfaces=" << absl::StrJoin(interfaces, ",") + + LOG(INFO) << "To repeat the test with same SUT interfaces, " + << "use --test_arg=--interfaces=" + << absl::StrJoin(sut_test_interfaces_, ",") << " in test arguments."; - gnoi::diag::StartBERTRequest bert_request; - // Create the BERT request. - bert_request.set_bert_operation_id( - absl::StrCat("OpId-", absl::ToUnixMillis(absl::Now()))); - for (const std::string& interface : interfaces) { - *(bert_request.add_per_port_requests()) = + gnoi::diag::StartBERTRequest bert_request_sut; + gnoi::diag::StartBERTRequest bert_request_control_switch; + std::string op_id = absl::StrCat("OpId-", absl::ToUnixMillis(absl::Now())); + // Create the BERT request for SUT. + bert_request_sut.set_bert_operation_id(op_id); + for (const std::string& interface : sut_test_interfaces_) { + *(bert_request_sut.add_per_port_requests()) = + gutil::ParseProtoOrDie( + BuildPerPortStartBertRequest(interface)); + } + + // Create the BERT request for control switch. + bert_request_control_switch.set_bert_operation_id(op_id); + for (const std::string& interface : peer_test_interfaces_) { + *(bert_request_control_switch.add_per_port_requests()) = gutil::ParseProtoOrDie( BuildPerPortStartBertRequest(interface)); } @@ -748,59 +917,43 @@ TEST_P(BertTest, StartBertSucceeds) { // Request StartBert on the SUT switch. LOG(INFO) << "Sending StartBERT request on SUT:"; ASSERT_NO_FATAL_FAILURE( - SendStartBertRequestSuccessfully(bert_request, *sut_gnoi_diag_stub)); + SendStartBertRequestSuccessfullyOnSut(bert_request_sut, *sut_diag_stub_)); // Request StartBert on the control switch. LOG(INFO) << "Sending StartBERT request on control switch:"; - ASSERT_NO_FATAL_FAILURE(SendStartBertRequestSuccessfully( - bert_request, *control_switch_gnoi_diag_stub)); + ASSERT_NO_FATAL_FAILURE(SendStartBertRequestSuccessfullyOnControlSwitch( + bert_request_control_switch, control_device)); // Get start timestamp. absl::Time start_time = absl::Now(); // Wait before reading the oper status. absl::SleepFor(kWaitToReadOperStatus); - // Verify that ports should be in TESTING mode now. - for (const std::string& interface : interfaces) { - SCOPED_TRACE( - absl::StrCat("Getting operational status for interface: ", interface)); - ASSERT_OK_AND_ASSIGN( - pins_test::OperStatus oper_status, - pins_test::GetInterfaceOperStatusOverGnmi(*sut_gnmi_stub, interface)); - ASSERT_EQ(oper_status, pins_test::OperStatus::kTesting); - ASSERT_OK_AND_ASSIGN(oper_status, - pins_test::GetInterfaceOperStatusOverGnmi( - *control_switch_gnmi_stub, interface)); - ASSERT_EQ(oper_status, pins_test::OperStatus::kTesting); - } + // Verify TESTING operational state on SUT ports running linkqual. + ASSERT_NO_FATAL_FAILURE(VerifyOperStatusOnSetOfSutInterfaces( + *sut_gnmi_stub_, sut_test_interfaces_, /*oper_status=*/"TESTING")); // Request another StartBert on the same ports on SUT and it should fail. { - gnoi::diag::StartBERTRequest second_bert_request = bert_request; + gnoi::diag::StartBERTRequest second_bert_request = bert_request_sut; second_bert_request.set_bert_operation_id( absl::StrCat("OpId-", absl::ToUnixMillis(absl::Now()))); // Request StartBert on the SUT switch. LOG(INFO) << "Sending second StartBERT request on SUT:"; - ASSERT_NO_FATAL_FAILURE(SendStartBertRequestSuccessfully( - second_bert_request, *sut_gnoi_diag_stub)); + ASSERT_NO_FATAL_FAILURE(SendStartBertRequestSuccessfullyOnSut( + second_bert_request, *sut_diag_stub_)); // Wait some time before querying the result. absl::SleepFor(kWaitTime); - gnoi::diag::GetBERTResultRequest result_request; - result_request.set_bert_operation_id( - second_bert_request.bert_operation_id()); - for (int idx = 0; idx < interfaces.size(); ++idx) { - *(result_request.add_per_port_requests()->mutable_interface()) = - second_bert_request.per_port_requests(idx).interface(); - } - + gnoi::diag::GetBERTResultRequest result_request = + GetBertResultRequestFromStartRequest(second_bert_request); gnoi::diag::GetBERTResultResponse result_response; grpc::ClientContext result_context; - EXPECT_OK(sut_gnoi_diag_stub->GetBERTResult(&result_context, result_request, - &result_response)); + EXPECT_OK(sut_diag_stub_->GetBERTResult(&result_context, result_request, + &result_response)); LOG(INFO) << "Result: " << result_response.ShortDebugString(); EXPECT_THAT(result_response.per_port_responses(), - SizeIs(interfaces.size())); + SizeIs(sut_test_interfaces_.size())); for (const auto& per_port_result : result_response.per_port_responses()) { EXPECT_EQ(per_port_result.status(), gnoi::diag::BERT_STATUS_PORT_ALREADY_IN_BERT) @@ -813,51 +966,47 @@ TEST_P(BertTest, StartBertSucceeds) { (absl::Now() - start_time) - absl::Seconds(1)) / kPollInterval; - std::vector interfaces_running_bert = interfaces; ASSERT_NO_FATAL_FAILURE(WaitForBertToCompleteOnInterfaces( - *sut_gnmi_stub, *control_switch_gnmi_stub, interfaces_running_bert, + *sut_gnmi_stub_, sut_test_interfaces_, control_device, + GetBertResultRequestFromStartRequest(bert_request_control_switch), max_poll_count)); - gnoi::diag::GetBERTResultRequest result_request; - result_request.set_bert_operation_id(bert_request.bert_operation_id()); - for (int idx = 0; idx < interfaces.size(); ++idx) { - *(result_request.add_per_port_requests()->mutable_interface()) = - bert_request.per_port_requests(idx).interface(); - } // Get the BERT result from the SUT. - { + gnoi::diag::GetBERTResultRequest result_request_sut = + GetBertResultRequestFromStartRequest(bert_request_sut); gnoi::diag::GetBERTResultResponse result_response; grpc::ClientContext result_context; - EXPECT_OK(sut_gnoi_diag_stub->GetBERTResult(&result_context, result_request, - &result_response)); + EXPECT_OK(sut_diag_stub_->GetBERTResult(&result_context, result_request_sut, + &result_response)); LOG(INFO) << "Result: " << result_response.ShortDebugString(); ASSERT_THAT(result_response.per_port_responses(), - SizeIs(bert_request.per_port_requests_size())); + SizeIs(bert_request_sut.per_port_requests_size())); for (int idx = 0; idx < result_response.per_port_responses_size(); ++idx) { VerifyBertResultForSuccess( result_response.per_port_responses(idx), - bert_request.bert_operation_id(), - bert_request.per_port_requests(idx).interface(), - bert_request.per_port_requests(idx).prbs_polynomial()); + bert_request_sut.bert_operation_id(), + bert_request_sut.per_port_requests(idx).interface(), + bert_request_sut.per_port_requests(idx).prbs_polynomial()); } } - + // Get the BERT result from the control switch. { - gnoi::diag::GetBERTResultResponse result_response; - grpc::ClientContext result_context; - EXPECT_OK(control_switch_gnoi_diag_stub->GetBERTResult( - &result_context, result_request, &result_response)); + gnoi::diag::GetBERTResultRequest result_request_control_switch = + GetBertResultRequestFromStartRequest(bert_request_control_switch); + ASSERT_OK_AND_ASSIGN( + gnoi::diag::GetBERTResultResponse result_response, + control_device.GetBERTResult(result_request_control_switch)); LOG(INFO) << "Result: " << result_response.ShortDebugString(); ASSERT_THAT(result_response.per_port_responses(), - SizeIs(bert_request.per_port_requests_size())); + SizeIs(bert_request_control_switch.per_port_requests_size())); for (int idx = 0; idx < result_response.per_port_responses_size(); ++idx) { VerifyBertResultForSuccess( result_response.per_port_responses(idx), - bert_request.bert_operation_id(), - bert_request.per_port_requests(idx).interface(), - bert_request.per_port_requests(idx).prbs_polynomial()); + bert_request_control_switch.bert_operation_id(), + bert_request_control_switch.per_port_requests(idx).interface(), + bert_request_control_switch.per_port_requests(idx).prbs_polynomial()); } } @@ -867,19 +1016,19 @@ TEST_P(BertTest, StartBertSucceeds) { gnoi::diag::StartBERTResponse bert_response; grpc::ClientContext context; LOG(INFO) << "Sending StartBERT request: " - << bert_request.ShortDebugString(); + << bert_request_sut.ShortDebugString(); EXPECT_THAT( - gutil::GrpcStatusToAbslStatus(sut_gnoi_diag_stub->StartBERT( - &context, bert_request, &bert_response)), + gutil::GrpcStatusToAbslStatus(sut_diag_stub_->StartBERT( + &context, bert_request_sut, &bert_response)), gutil::StatusIs(absl::StatusCode::kInvalidArgument, AllOf(HasSubstr("Invalid request"), - HasSubstr(bert_request.bert_operation_id()), + HasSubstr(bert_request_sut.bert_operation_id()), HasSubstr("exists")))) << "Response: " << bert_response.ShortDebugString(); } - // TODO (b/176913347): Enable the all ports UP check. - // ASSERT_OK(pins_test::PortsUp(sut)); - // ASSERT_OK(pins_test::PortsUp(control_switch)); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); + ASSERT_OK(ValidateControlSwitchPortsUp(control_device, peer_interfaces_)); } // Runs the BERT test on current maximum allowed number of interfaces. During @@ -889,80 +1038,95 @@ TEST_P(BertTest, StartBertSucceeds) { // This helps us verify a mix of operation during BERT - unexpected software or // hardware errors. TEST_P(BertTest, RunBertOnMaximumAllowedPorts) { - GetMirrorTestbed().Environment().SetTestCaseID( - "ce526e97-2a62-4044-9dce-8fc74b232e4b"); - thinkit::Switch& sut = GetMirrorTestbed().Sut(); - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - ASSERT_OK(pins_test::PortsUp(sut)); - ASSERT_OK_AND_ASSIGN(auto sut_gnoi_diag_stub, sut.CreateGnoiDiagStub()); + ASSERT_NO_FATAL_FAILURE( + InitializeTestEnvironment("ce526e97-2a62-4044-9dce-8fc74b232e4b")); + thinkit::Switch& sut = generic_testbed_->Sut(); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); - thinkit::Switch& control_switch = GetMirrorTestbed().ControlSwitch(); - ASSERT_OK_AND_ASSIGN(auto control_switch_gnmi_stub, - control_switch.CreateGnmiStub()); - ASSERT_OK(pins_test::PortsUp(control_switch)); - ASSERT_OK_AND_ASSIGN(auto control_switch_gnoi_diag_stub, - control_switch.CreateGnoiDiagStub()); + thinkit::ControlDevice& control_device = generic_testbed_->ControlDevice(); + ASSERT_OK(ValidateControlSwitchPortsUp(control_device, peer_interfaces_)); // Get all the interfaces that are operational status "UP". - ASSERT_OK_AND_ASSIGN(std::vector interfaces, - pins_test::GetUpInterfacesOverGnmi(*sut_gnmi_stub)); + sut_test_interfaces_ = sut_interfaces_; // For this test, we need at least 5 UP interfaces. - ASSERT_GE(interfaces.size(), 5); + ASSERT_GE(sut_test_interfaces_.size(), 5); // Resize the interface list if UP ports are more than max number of allowed // ports. - if (interfaces.size() > kMaxAllowedInterfacesToRunBert) { - interfaces.resize(kMaxAllowedInterfacesToRunBert); + if (sut_test_interfaces_.size() > kMaxAllowedInterfacesToRunBert) { + sut_test_interfaces_.resize(kMaxAllowedInterfacesToRunBert); } // Select 'N' ports on control switch and 'N' ports on SUT for admin down. - int num_interfaces_to_disable = 1 + (interfaces.size() / 16); + int num_interfaces_to_disable = 1 + (sut_test_interfaces_.size() / 16); // Seed the std::rand(). LOG(INFO) << "Seeding pseudo-random number generator with seed: " << absl::GetFlag(FLAGS_idx_seed); // Select SUT interfaces in the range [0..interfaces/2). std::vector sut_interfaces_for_admin_down; - std::sample(interfaces.begin(), interfaces.begin() + interfaces.size() / 2, + std::sample(sut_test_interfaces_.begin(), + sut_test_interfaces_.begin() + sut_test_interfaces_.size() / 2, std::back_inserter(sut_interfaces_for_admin_down), num_interfaces_to_disable, std::mt19937(absl::GetFlag(FLAGS_idx_seed))); - // Select control switch interfaces in the range [interfaces/2..interfaces]. - std::vector control_switch_interfaces_for_admin_down; - std::sample(interfaces.begin() + interfaces.size() / 2, interfaces.end(), - std::back_inserter(control_switch_interfaces_for_admin_down), + // Select SUT interfaces whose peer interfaces on control switch will be admin + // disabled in the range + // [sut_test_interfaces_/2..sut_test_interfaces_.size()). + std::vector sut_interfaces_for_peer_select; + std::sample(sut_test_interfaces_.begin() + sut_test_interfaces_.size() / 2, + sut_test_interfaces_.end(), + std::back_inserter(sut_interfaces_for_peer_select), num_interfaces_to_disable, std::mt19937(absl::GetFlag(FLAGS_idx_seed))); - - LOG(INFO) << "Starting BERT on " << interfaces.size() - << " interfaces: " << absl::StrJoin(interfaces, ","); + // Get control switch interfaces for admin disable. + ASSERT_OK_AND_ASSIGN( + std::vector control_switch_interfaces_for_admin_down, + GetPeerInterfacesForSutInterfaces(sut_interfaces_for_peer_select)); + + LOG(INFO) << "Starting BERT on " << sut_test_interfaces_.size() + << " {SUT, control_device} links: "; + for (const std::string& interface : sut_test_interfaces_) { + LOG(INFO) << "{" << interface << ", " + << sut_to_peer_interface_mapping_[interface] << "}, "; + } LOG(INFO) << "Interfaces selected on SUT for admin down: " << absl::StrJoin(sut_interfaces_for_admin_down, ","); LOG(INFO) << "Interfaces selected on control switch for admin down: " << absl::StrJoin(control_switch_interfaces_for_admin_down, ","); - gnoi::diag::StartBERTRequest bert_request; - // Create the BERT request. - bert_request.set_bert_operation_id( - absl::StrCat("OpId-", absl::ToUnixMillis(absl::Now()))); - for (const std::string& interface : interfaces) { - *(bert_request.add_per_port_requests()) = + gnoi::diag::StartBERTRequest bert_request_sut; + gnoi::diag::StartBERTRequest bert_request_control_switch; + // Create the BERT request for SUT and control switch. + std::string op_id = absl::StrCat("OpId-", absl::ToUnixMillis(absl::Now())); + bert_request_sut.set_bert_operation_id(op_id); + bert_request_control_switch.set_bert_operation_id(op_id); + for (const std::string& interface : sut_test_interfaces_) { + *(bert_request_sut.add_per_port_requests()) = gutil::ParseProtoOrDie( BuildPerPortStartBertRequest(interface)); + const std::string peer_interface = + sut_to_peer_interface_mapping_[interface]; + *(bert_request_control_switch.add_per_port_requests()) = + gutil::ParseProtoOrDie( + BuildPerPortStartBertRequest(peer_interface)); } // Request StartBert on the SUT switch. LOG(INFO) << "Sending StartBERT request on SUT:"; ASSERT_NO_FATAL_FAILURE( - SendStartBertRequestSuccessfully(bert_request, *sut_gnoi_diag_stub)); + SendStartBertRequestSuccessfullyOnSut(bert_request_sut, *sut_diag_stub_)); // Request StartBert on the control switch. LOG(INFO) << "Sending StartBERT request on control switch:"; - ASSERT_NO_FATAL_FAILURE(SendStartBertRequestSuccessfully( - bert_request, *control_switch_gnoi_diag_stub)); + ASSERT_NO_FATAL_FAILURE(SendStartBertRequestSuccessfullyOnControlSwitch( + bert_request_control_switch, control_device)); absl::Time start_time = absl::Now(); // Give some time to BERT to move in SYNC state. absl::SleepFor(absl::Seconds(90)); - + ASSERT_NO_FATAL_FAILURE(CheckRunningBertAndForceAdminDown( + *sut_diag_stub_, control_device, *sut_gnmi_stub_, op_id, + sut_interfaces_for_admin_down, control_switch_interfaces_for_admin_down)); absl::Time end_time = absl::Now(); // Wait for BERT to finish on test interfaces. @@ -970,86 +1134,117 @@ TEST_P(BertTest, RunBertOnMaximumAllowedPorts) { (end_time - start_time) - absl::Seconds(1)) / kPollInterval; - std::vector interfaces_running_bert = interfaces; ASSERT_NO_FATAL_FAILURE(WaitForBertToCompleteOnInterfaces( - *sut_gnmi_stub, *control_switch_gnmi_stub, interfaces_running_bert, + *sut_gnmi_stub_, sut_test_interfaces_, control_device, + GetBertResultRequestFromStartRequest(bert_request_control_switch), max_poll_count)); + // Get the BERT result from SUT and verify it. + LOG(INFO) << "Verify BERT results on SUT interfaces."; + grpc::ClientContext context; + gnoi::diag::GetBERTResultResponse bert_response_sut; + ASSERT_OK(sut_diag_stub_->GetBERTResult( + &context, GetBertResultRequestFromStartRequest(bert_request_sut), + &bert_response_sut)); + ASSERT_NO_FATAL_FAILURE(GetAndVerifyBertResultsWithAdminDownInterfaces( + bert_request_sut, bert_response_sut, sut_interfaces_for_admin_down, + control_switch_interfaces_for_admin_down)); + // Get the BERT result from control switch and verify it. + LOG(INFO) << "Verify BERT results on control switch interfaces."; + ASSERT_OK_AND_ASSIGN( + gnoi::diag::GetBERTResultResponse bert_response_control_switch, + control_device.GetBERTResult( + GetBertResultRequestFromStartRequest(bert_request_control_switch))); + ASSERT_NO_FATAL_FAILURE(GetAndVerifyBertResultsWithAdminDownInterfaces( + bert_request_control_switch, bert_response_control_switch, + sut_interfaces_for_admin_down, control_switch_interfaces_for_admin_down)); + + // Enable admin state on SUT and control switch interfaces. + ASSERT_NO_FATAL_FAILURE(SetAdminStateOnInterfaceList( + *sut_gnmi_stub_, sut_interfaces_for_admin_down, kEnabledTrue)); + ASSERT_OK(control_device.SetAdminLinkState( + control_switch_interfaces_for_admin_down, thinkit::LinkState::kUp)); + // Wait for some time before checking the port status. absl::SleepFor(kPortsUpWaitTime); ASSERT_OK(pins_test::PortsUp(sut)); - ASSERT_OK(pins_test::PortsUp(control_switch)); + ASSERT_OK(ValidateControlSwitchPortsUp(control_device, peer_interfaces_)); } // Run BERT on a port. Issue StopBERT on the SUT port, this causes BERT to // stop on SUT and this will cause BERT failure on control switch as control // switch side port will lose lock with its peer port on SUT side. TEST_P(BertTest, StopBertSucceeds) { - GetMirrorTestbed().Environment().SetTestCaseID( - "be7b6653-51b9-4231-a438-d9589bbcb677"); - thinkit::Switch& sut = GetMirrorTestbed().Sut(); - ASSERT_OK_AND_ASSIGN(auto sut_gnmi_stub, sut.CreateGnmiStub()); - ASSERT_OK(pins_test::PortsUp(sut)); - ASSERT_OK_AND_ASSIGN(auto sut_gnoi_diag_stub, sut.CreateGnoiDiagStub()); + ASSERT_NO_FATAL_FAILURE( + InitializeTestEnvironment("be7b6653-51b9-4231-a438-d9589bbcb677")); + thinkit::Switch& sut = generic_testbed_->Sut(); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); - thinkit::Switch& control_switch = GetMirrorTestbed().ControlSwitch(); - ASSERT_OK_AND_ASSIGN(auto control_switch_gnmi_stub, - control_switch.CreateGnmiStub()); - ASSERT_OK(pins_test::PortsUp(control_switch)); - ASSERT_OK_AND_ASSIGN(auto control_switch_gnoi_diag_stub, - control_switch.CreateGnoiDiagStub()); + thinkit::ControlDevice& control_device = generic_testbed_->ControlDevice(); + ASSERT_OK(ValidateControlSwitchPortsUp(control_device, peer_interfaces_)); // Select one operational state "up" port. std::string interface = absl::GetFlag(FLAGS_interface); - if (interface.empty()) { - std::vector interfaces; - ASSERT_NO_FATAL_FAILURE(SelectNUpInterfaces(/*port_count_to_select=*/1, - *sut_gnmi_stub, &interfaces)); - interface = interfaces[0]; + if (!interface.empty()) { + // Verify that provided interfaces are part of SUT's UP interfaces. + ASSERT_TRUE(IsInterfaceInList(interface, sut_interfaces_)) + << "SUT test interface selected for test: " + << interface << "./n UP interfaces on SUT: " + << absl::StrJoin(sut_interfaces_, ","); + } else { + sut_test_interfaces_ = SelectNInterfacesFromList(1, sut_interfaces_); + interface = sut_test_interfaces_[0]; } - LOG(INFO) << "Selected interface: " - << interface << ". To repeat the test with same interface, use " + ASSERT_OK_AND_ASSIGN(peer_test_interfaces_, + GetPeerInterfacesForSutInterfaces(sut_test_interfaces_)); + std::string peer_interface = peer_test_interfaces_[0]; + LOG(INFO) << "Selected {SUT, control interface}: {" << interface << ", " + << peer_interface + << "}. To repeat the test with same SUT interface, use " << "--test_arg=--interface=" << interface << " in test arguments."; - gnoi::diag::StartBERTRequest bert_request; + gnoi::diag::StartBERTRequest bert_request_sut; + gnoi::diag::StartBERTRequest bert_request_control_switch; + std::string op_id = absl::StrCat("OpId-", absl::ToUnixMillis(absl::Now())); // Create the BERT request. - bert_request.set_bert_operation_id( - absl::StrCat("OpId-", absl::ToUnixMillis(absl::Now()))); - *(bert_request.add_per_port_requests()) = + bert_request_sut.set_bert_operation_id(op_id); + *(bert_request_sut.add_per_port_requests()) = gutil::ParseProtoOrDie( BuildPerPortStartBertRequest(interface)); + bert_request_control_switch.set_bert_operation_id(op_id); + *(bert_request_control_switch.add_per_port_requests()) = + gutil::ParseProtoOrDie( + BuildPerPortStartBertRequest(peer_interface)); // Request StartBert on the SUT switch. LOG(INFO) << "Sending StartBERT request on SUT:"; ASSERT_NO_FATAL_FAILURE( - SendStartBertRequestSuccessfully(bert_request, *sut_gnoi_diag_stub)); + SendStartBertRequestSuccessfullyOnSut(bert_request_sut, *sut_diag_stub_)); // Request StartBert on the control switch. LOG(INFO) << "Sending StartBERT request on control switch:"; - ASSERT_NO_FATAL_FAILURE(SendStartBertRequestSuccessfully( - bert_request, *control_switch_gnoi_diag_stub)); + ASSERT_NO_FATAL_FAILURE(SendStartBertRequestSuccessfullyOnControlSwitch( + bert_request_control_switch, control_device)); absl::Time start_time = absl::Now(); // Wait before reading the oper status. absl::SleepFor(kWaitToReadOperStatus); - // Verify that port should be in TESTING mode now. + // Verify that SUT port should be in TESTING mode now. { ASSERT_OK_AND_ASSIGN( pins_test::OperStatus oper_status, - pins_test::GetInterfaceOperStatusOverGnmi(*sut_gnmi_stub, interface)); - ASSERT_EQ(oper_status, pins_test::OperStatus::kTesting); - ASSERT_OK_AND_ASSIGN(oper_status, - pins_test::GetInterfaceOperStatusOverGnmi( - *control_switch_gnmi_stub, interface)); + pins_test::GetInterfaceOperStatusOverGnmi(*sut_gnmi_stub_, interface)); ASSERT_EQ(oper_status, pins_test::OperStatus::kTesting); } - gnoi::diag::GetBERTResultRequest result_request; - result_request.set_bert_operation_id(bert_request.bert_operation_id()); - *(result_request.add_per_port_requests()->mutable_interface()) = - bert_request.per_port_requests(0).interface(); + gnoi::diag::GetBERTResultRequest result_request_control_switch; + result_request_control_switch.set_bert_operation_id(op_id); + *(result_request_control_switch.add_per_port_requests() + ->mutable_interface()) = + bert_request_control_switch.per_port_requests(0).interface(); // Verify control switch side BERT has acquired the lock and is running now. { @@ -1059,11 +1254,10 @@ TEST_P(BertTest, StopBertSucceeds) { while (remaining_poll_count > 0) { absl::SleepFor(kPollInterval); gnoi::diag::GetBERTResultResponse response; - grpc::ClientContext context; - EXPECT_OK(control_switch_gnoi_diag_stub->GetBERTResult( - &context, result_request, &response)); + ASSERT_OK_AND_ASSIGN(response, control_device.GetBERTResult( + result_request_control_switch)); ASSERT_THAT(response.per_port_responses(), - SizeIs(bert_request.per_port_requests_size())); + SizeIs(bert_request_control_switch.per_port_requests_size())); ASSERT_EQ(response.per_port_responses(0).status(), gnoi::diag::BERT_STATUS_OK); if (response.per_port_responses(0).peer_lock_established()) { @@ -1078,14 +1272,14 @@ TEST_P(BertTest, StopBertSucceeds) { // Request StopBERT on SUT. { gnoi::diag::StopBERTRequest stop_request; - stop_request.set_bert_operation_id(bert_request.bert_operation_id()); + stop_request.set_bert_operation_id(op_id); *(stop_request.add_per_port_requests()->mutable_interface()) = - bert_request.per_port_requests(0).interface(); + bert_request_sut.per_port_requests(0).interface(); gnoi::diag::StopBERTResponse response; grpc::ClientContext context; LOG(INFO) << "Sending StopBERT request on SUT: " << stop_request.ShortDebugString(); - EXPECT_OK(sut_gnoi_diag_stub->StopBERT(&context, stop_request, &response)); + EXPECT_OK(sut_diag_stub_->StopBERT(&context, stop_request, &response)); // Verify response. ASSERT_THAT(response.per_port_responses(), @@ -1110,18 +1304,21 @@ TEST_P(BertTest, StopBertSucceeds) { std::vector interfaces_running_bert = {interface}; ASSERT_NO_FATAL_FAILURE(WaitForBertToCompleteOnInterfaces( - *sut_gnmi_stub, *control_switch_gnmi_stub, interfaces_running_bert, + *sut_gnmi_stub_, sut_test_interfaces_, control_device, + GetBertResultRequestFromStartRequest(bert_request_control_switch), max_poll_count)); // Get the BERT result from the SUT. BERT status should be OK. { + gnoi::diag::GetBERTResultRequest result_request_sut = + GetBertResultRequestFromStartRequest(bert_request_sut); gnoi::diag::GetBERTResultResponse response; grpc::ClientContext context; EXPECT_OK( - sut_gnoi_diag_stub->GetBERTResult(&context, result_request, &response)); + sut_diag_stub_->GetBERTResult(&context, result_request_sut, &response)); LOG(INFO) << "SUT BERT Result: " << response.ShortDebugString(); ASSERT_THAT(response.per_port_responses(), - SizeIs(bert_request.per_port_requests_size())); + SizeIs(bert_request_sut.per_port_requests_size())); EXPECT_EQ(response.per_port_responses(0).status(), gnoi::diag::BERT_STATUS_OK); } @@ -1130,12 +1327,11 @@ TEST_P(BertTest, StopBertSucceeds) { // peer lock loss. { gnoi::diag::GetBERTResultResponse response; - grpc::ClientContext context; - EXPECT_OK(control_switch_gnoi_diag_stub->GetBERTResult( - &context, result_request, &response)); + ASSERT_OK_AND_ASSIGN( + response, control_device.GetBERTResult(result_request_control_switch)); LOG(INFO) << "Control switch BERT Result: " << response.ShortDebugString(); ASSERT_THAT(response.per_port_responses(), - SizeIs(bert_request.per_port_requests_size())); + SizeIs(bert_request_control_switch.per_port_requests_size())); EXPECT_EQ(response.per_port_responses(0).status(), gnoi::diag::BERT_STATUS_PEER_LOCK_LOST); EXPECT_TRUE(response.per_port_responses(0).peer_lock_established()); @@ -1143,7 +1339,7 @@ TEST_P(BertTest, StopBertSucceeds) { } ASSERT_OK(pins_test::PortsUp(sut)); - ASSERT_OK(pins_test::PortsUp(control_switch)); + ASSERT_OK(ValidateControlSwitchPortsUp(control_device, peer_interfaces_)); } } // namespace bert diff --git a/tests/gnoi/bert_tests.h b/tests/gnoi/bert_tests.h index aef0c8c9..9ad3157a 100644 --- a/tests/gnoi/bert_tests.h +++ b/tests/gnoi/bert_tests.h @@ -12,15 +12,84 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef GOOGLE_TESTS_GNOI_BERT_TESTS_H_ -#define GOOGLE_TESTS_GNOI_BERT_TESTS_H_ +#ifndef PINS_TESTS_GNOI_BERT_TESTS_H_ +#define PINS_TESTS_GNOI_BERT_TESTS_H_ -#include "thinkit/mirror_testbed_fixture.h" +#include "absl/strings/substitute.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "gutil/status_matchers.h" +#include "gutil/testing.h" +#include "thinkit/generic_testbed_fixture.h" namespace bert { -class BertTest : public thinkit::MirrorTestbedFixture {}; +class BertTest : public thinkit::GenericTestbedFixture<> { + public: + BertTest() + : generic_testbed_(nullptr), + sut_gnmi_stub_(nullptr), + sut_diag_stub_(nullptr) {} + + void InitializeTestEnvironment(absl::string_view test_id) { + thinkit::TestRequirements requirements = + gutil::ParseProtoOrDie( + R"pb(interface_requirements { + count: 1 + interface_mode: CONTROL_INTERFACE + })pb"); + + ASSERT_OK_AND_ASSIGN(generic_testbed_, + GetTestbedWithRequirements(requirements)); + generic_testbed_->Environment().SetTestCaseID(test_id); + + absl::flat_hash_map interface_info = + generic_testbed_->GetSutInterfaceInfo(); + + for (const auto &[interface, info] : interface_info) { + if ((info.interface_modes.contains(thinkit::CONTROL_INTERFACE)) == thinkit::CONTROL_INTERFACE) { + sut_interfaces_.push_back(interface); + peer_interfaces_.push_back(info.peer_interface_name); + sut_to_peer_interface_mapping_[interface] = info.peer_interface_name; + } + } + + ASSERT_OK_AND_ASSIGN(sut_gnmi_stub_, + generic_testbed_->Sut().CreateGnmiStub()); + ASSERT_OK_AND_ASSIGN(sut_diag_stub_, + generic_testbed_->Sut().CreateGnoiDiagStub()); + } + + absl::StatusOr> GetPeerInterfacesForSutInterfaces( + const std::vector &sut_interfaces) { + std::vector peer_interfaces; + peer_interfaces.reserve(sut_interfaces.size()); + for (const std::string &sut_interface : sut_interfaces) { + if (sut_to_peer_interface_mapping_.count(sut_interface) == 0) { + return absl::NotFoundError(absl::Substitute( + "Failed to find peer for SUT interface $0", sut_interface)); + } + peer_interfaces.push_back(sut_to_peer_interface_mapping_[sut_interface]); + } + return peer_interfaces; + } + + protected: + std::unique_ptr generic_testbed_; + std::unique_ptr sut_gnmi_stub_; + std::unique_ptr sut_diag_stub_; + // List of SUT interfaces. + std::vector sut_interfaces_; + // List of control switch interfaces. + std::vector peer_interfaces_; + // List of SUT interfaces that are under test. + std::vector sut_test_interfaces_; + // List of control switch interfaces that are under test. + std::vector peer_test_interfaces_; + // A mapping of SUT interface and its peer interface on control switch. + absl::flat_hash_map sut_to_peer_interface_mapping_; +}; } // namespace bert -#endif // GOOGLE_TESTS_GNOI_BERT_TESTS_H_ +#endif // PINS_TESTS_GNOI_BERT_TESTS_H_ From 3790f434128277abcab9627ef09db9f82ecb4a85 Mon Sep 17 00:00:00 2001 From: smolkaj Date: Tue, 26 Nov 2024 07:47:27 +0000 Subject: [PATCH 2/4] Check PortsUp only on test interfaces.Increase gNOI factory reset test time limit. --- tests/gnoi/bert_tests.cc | 6 ++++-- tests/gnoi/factory_reset_test.cc | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/gnoi/bert_tests.cc b/tests/gnoi/bert_tests.cc index 81704c6d..33c860c6 100644 --- a/tests/gnoi/bert_tests.cc +++ b/tests/gnoi/bert_tests.cc @@ -1168,7 +1168,8 @@ TEST_P(BertTest, RunBertOnMaximumAllowedPorts) { // Wait for some time before checking the port status. absl::SleepFor(kPortsUpWaitTime); - ASSERT_OK(pins_test::PortsUp(sut)); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); ASSERT_OK(ValidateControlSwitchPortsUp(control_device, peer_interfaces_)); } @@ -1338,7 +1339,8 @@ TEST_P(BertTest, StopBertSucceeds) { EXPECT_TRUE(response.per_port_responses(0).peer_lock_lost()); } - ASSERT_OK(pins_test::PortsUp(sut)); + ASSERT_OK( + pins_test::PortsUp(sut, absl::Span(sut_interfaces_))); ASSERT_OK(ValidateControlSwitchPortsUp(control_device, peer_interfaces_)); } diff --git a/tests/gnoi/factory_reset_test.cc b/tests/gnoi/factory_reset_test.cc index 1f42349a..34da0a61 100644 --- a/tests/gnoi/factory_reset_test.cc +++ b/tests/gnoi/factory_reset_test.cc @@ -38,7 +38,7 @@ namespace factory_reset { constexpr absl::Duration kFactoryResetWaitForDownTime = absl::Seconds(60); -constexpr absl::Duration kFactoryResetWaitForUpTime = absl::Minutes(18); +constexpr absl::Duration kFactoryResetWaitForUpTime = absl::Minutes(25); constexpr absl::Duration kSshSessionTimeout = absl::Seconds(5); void IssueGnoiFactoryResetAndValidateStatus( From e62b873b44c7c59ab16659e45af71c6250a907e2 Mon Sep 17 00:00:00 2001 From: smolkaj Date: Tue, 26 Nov 2024 12:00:36 +0000 Subject: [PATCH 3/4] BERT test.Add instantiation param for watch port tests --- tests/forwarding/watch_port_test.cc | 129 +++++++++++++++------------- tests/forwarding/watch_port_test.h | 6 +- tests/gnoi/bert_tests.cc | 7 +- 3 files changed, 73 insertions(+), 69 deletions(-) diff --git a/tests/forwarding/watch_port_test.cc b/tests/forwarding/watch_port_test.cc index 743e812e..ac292010 100644 --- a/tests/forwarding/watch_port_test.cc +++ b/tests/forwarding/watch_port_test.cc @@ -441,19 +441,21 @@ void WatchPortTestFixture::SetUp() { testbed.ControlSwitch(), gnmi_config, /*timeout=*/absl::Minutes(3))); - ASSERT_OK(testbed.Environment().StoreTestArtifact("p4info.pb.txt", - GetP4Info().DebugString())); + ASSERT_OK(testbed.Environment().StoreTestArtifact( + "p4info.pb.txt", GetParam().p4_info.DebugString())); // Setup SUT & control switch. ASSERT_OK_AND_ASSIGN(sut_p4_session_, pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables( - testbed.Sut(), GetP4Info())); + testbed.Sut(), GetParam().p4_info)); ASSERT_OK_AND_ASSIGN(control_p4_session_, pdpi::P4RuntimeSession::CreateWithP4InfoAndClearTables( - testbed.ControlSwitch(), GetP4Info())); - ASSERT_OK(SetUpSut(*sut_p4_session_, GetIrP4Info(), kVrfId)); - ASSERT_OK(SetUpControlSwitch(*control_p4_session_, GetIrP4Info())); + testbed.ControlSwitch(), GetParam().p4_info)); + ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, + pdpi::CreateIrP4Info(GetParam().p4_info)); + ASSERT_OK(SetUpSut(*sut_p4_session_, ir_p4info, kVrfId)); + ASSERT_OK(SetUpControlSwitch(*control_p4_session_, ir_p4info)); // Create GNMI stub for admin operations. ASSERT_OK_AND_ASSIGN(sut_gnmi_stub_, testbed.Sut().CreateGnmiStub()); @@ -462,12 +464,12 @@ void WatchPortTestFixture::SetUp() { // Start the receiver thread for control switch to listen for packets from // SUT, this thread is terminated in the TearDown. - receive_packet_thread_ = std::thread([&]() { + receive_packet_thread_ = std::thread([&, ir_p4info]() { p4::v1::StreamMessageResponse pi_response; while (control_p4_session_->StreamChannelRead(pi_response)) { absl::MutexLock lock(&test_data_.mutex); sai::StreamMessageResponse pd_response; - ASSERT_OK(pdpi::PiStreamMessageResponseToPd(GetIrP4Info(), pi_response, + ASSERT_OK(pdpi::PiStreamMessageResponseToPd(ir_p4info, pi_response, &pd_response)) << " PacketIn PI to PD failed: "; ASSERT_TRUE(pd_response.has_packet()) @@ -536,15 +538,6 @@ void WatchPortTestFixture::TearDown() { testbed.TearDown(); } -// TODO: Parameterize over the different instantiations like -// MiddleBlock, FBR400. -const p4::config::v1::P4Info& WatchPortTestFixture::GetP4Info() { - return sai::GetP4Info(sai::Instantiation::kMiddleblock); -} -const pdpi::IrP4Info& WatchPortTestFixture::GetIrP4Info() { - return sai::GetIrP4Info(sai::Instantiation::kMiddleblock); -} - namespace { // Verifies basic WCMP behavior by programming a group with multiple members @@ -561,19 +554,21 @@ TEST_P(WatchPortTestFixture, VerifyBasicWcmpPacketDistribution) { CreateGroupMembers(group_size, controller_port_ids)); const int input_port = controller_port_ids[kDefaultInputPortIndex]; - ASSERT_OK(SetUpInputPortForPacketReceive(*sut_p4_session_, GetIrP4Info(), - input_port)); + ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, + pdpi::CreateIrP4Info(GetParam().p4_info)); + ASSERT_OK( + SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Programs the required router interfaces, nexthops for wcmp group. - ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, GetIrP4Info(), + ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, members)); ASSERT_OK(pins::ProgramGroupWithMembers(environment, *sut_p4_session_, - GetIrP4Info(), kGroupId, members, + ir_p4info, kGroupId, members, p4::v1::Update::INSERT)) << "Failed to program WCMP group: "; // Program default routing for all packets on SUT. - ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, GetIrP4Info(), kVrfId, + ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, ir_p4info, kVrfId, p4::v1::Update::INSERT)); // Generate test configuration, pick any field (IP_SRC) used by hashing to @@ -598,7 +593,7 @@ TEST_P(WatchPortTestFixture, VerifyBasicWcmpPacketDistribution) { // Send 5000 packets and check for packet distribution. ASSERT_OK(SendNPacketsToSut(kNumTestPackets, test_config, members, - controller_port_ids, GetIrP4Info(), + controller_port_ids, ir_p4info, *control_p4_session_, environment)); test_data_.total_packets_sent = kNumTestPackets; @@ -620,7 +615,7 @@ TEST_P(WatchPortTestFixture, VerifyBasicWcmpPacketDistribution) { absl::flat_hash_set expected_member_ports = CreateExpectedMemberPorts(members); - ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, GetIrP4Info(), + ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, ir_p4info, kGroupId, members)); // Verifies the actual members inferred from receive traffic matches the @@ -645,17 +640,19 @@ TEST_P(WatchPortTestFixture, VerifyBasicWatchPortAction) { CreateGroupMembers(group_size, controller_port_ids)); const int input_port = controller_port_ids[kDefaultInputPortIndex]; - ASSERT_OK(SetUpInputPortForPacketReceive(*sut_p4_session_, GetIrP4Info(), - input_port)); + ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, + pdpi::CreateIrP4Info(GetParam().p4_info)); + ASSERT_OK( + SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Programs the required router interfaces, nexthops for wcmp group. - ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, GetIrP4Info(), + ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, members)); ASSERT_OK(pins::ProgramGroupWithMembers(environment, *sut_p4_session_, - GetIrP4Info(), kGroupId, members, + ir_p4info, kGroupId, members, p4::v1::Update::INSERT)); // Program default routing for all packets on SUT. - ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, GetIrP4Info(), kVrfId, + ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, ir_p4info, kVrfId, p4::v1::Update::INSERT)); // Generate test configuration, pick any field used by hashing to vary for @@ -704,7 +701,7 @@ TEST_P(WatchPortTestFixture, VerifyBasicWatchPortAction) { // Send 5000 packets and check for packet distribution. ASSERT_OK(SendNPacketsToSut(kNumTestPackets, test_config, members, - controller_port_ids, GetIrP4Info(), + controller_port_ids, ir_p4info, *control_p4_session_, environment)); test_data_.total_packets_sent = kNumTestPackets; @@ -732,7 +729,7 @@ TEST_P(WatchPortTestFixture, VerifyBasicWatchPortAction) { expected_member_ports.insert(selected_port_id); } - ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, GetIrP4Info(), + ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, ir_p4info, kGroupId, members)); // Verifies the actual members inferred from receive traffic matches the // expected members. @@ -762,17 +759,19 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionInCriticalState) { CreateGroupMembers(group_size, controller_port_ids)); const int input_port = controller_port_ids[kDefaultInputPortIndex]; - ASSERT_OK(SetUpInputPortForPacketReceive(*sut_p4_session_, GetIrP4Info(), - input_port)); + ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, + pdpi::CreateIrP4Info(GetParam().p4_info)); + ASSERT_OK( + SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Program the required router interfaces, nexthops for wcmp group. - ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, GetIrP4Info(), + ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, members)); ASSERT_OK(pins::ProgramGroupWithMembers(environment, *sut_p4_session_, - GetIrP4Info(), kGroupId, members, + ir_p4info, kGroupId, members, p4::v1::Update::INSERT)); // Program default routing for all packets on SUT. - ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, GetIrP4Info(), kVrfId, + ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, ir_p4info, kVrfId, p4::v1::Update::INSERT)); // Generate test configuration, pick any field used by hashing to vary for @@ -824,7 +823,7 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionInCriticalState) { // Send 5000 packets and check for packet distribution. ASSERT_OK(SendNPacketsToSut(kNumTestPackets, test_config, members, - controller_port_ids, GetIrP4Info(), + controller_port_ids, ir_p4info, *control_p4_session_, environment)); test_data_.total_packets_sent = kNumTestPackets; @@ -840,7 +839,7 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionInCriticalState) { << " and actual: " << test.output.size() << "packets received for " << DescribeTestConfig(test_config); - ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, GetIrP4Info(), + ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, ir_p4info, kGroupId, members)); // Count the received packets and create the expected_member_ports for admin @@ -873,17 +872,19 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForSingleMember) { CreateGroupMembers(group_size, controller_port_ids)); const int input_port = controller_port_ids[kDefaultInputPortIndex]; - ASSERT_OK(SetUpInputPortForPacketReceive(*sut_p4_session_, GetIrP4Info(), - input_port)); + ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, + pdpi::CreateIrP4Info(GetParam().p4_info)); + ASSERT_OK( + SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Programs the required router interfaces, nexthops for wcmp group. - ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, GetIrP4Info(), + ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, members)); ASSERT_OK(pins::ProgramGroupWithMembers(environment, *sut_p4_session_, - GetIrP4Info(), kGroupId, members, + ir_p4info, kGroupId, members, p4::v1::Update::INSERT)); // Program default routing for all packets on SUT. - ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, GetIrP4Info(), kVrfId, + ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, ir_p4info, kVrfId, p4::v1::Update::INSERT)); // Generate test configuration, pick any field used by hashing to vary for @@ -933,7 +934,7 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForSingleMember) { // Send 5000 packets and check for packet distribution. ASSERT_OK(SendNPacketsToSut(kNumTestPackets, test_config, members, - controller_port_ids, GetIrP4Info(), + controller_port_ids, ir_p4info, *control_p4_session_, environment)); test_data_.total_packets_sent = kNumTestPackets; @@ -963,7 +964,7 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForSingleMember) { ASSERT_OK_AND_ASSIGN(auto num_packets_per_port, CountNumPacketsPerPort(test.output)); - ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, GetIrP4Info(), + ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, ir_p4info, kGroupId, members)); // Verifies the actual members inferred from receive traffic matches the @@ -989,17 +990,19 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForMemberModify) { CreateGroupMembers(group_size, controller_port_ids)); const int input_port = controller_port_ids[kDefaultInputPortIndex]; - ASSERT_OK(SetUpInputPortForPacketReceive(*sut_p4_session_, GetIrP4Info(), - input_port)); + ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, + pdpi::CreateIrP4Info(GetParam().p4_info)); + ASSERT_OK( + SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Programs the required router interfaces, nexthops for wcmp group. - ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, GetIrP4Info(), + ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, members)); ASSERT_OK(pins::ProgramGroupWithMembers(environment, *sut_p4_session_, - GetIrP4Info(), kGroupId, members, + ir_p4info, kGroupId, members, p4::v1::Update::INSERT)); // Program default routing for all packets on SUT. - ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, GetIrP4Info(), kVrfId, + ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, ir_p4info, kVrfId, p4::v1::Update::INSERT)); // Generate test configuration, pick any field used by hashing to vary for @@ -1038,7 +1041,7 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForMemberModify) { // Send Modify request to remove the down member from the group. members.erase(members.begin() + random_member_index); ASSERT_OK(pins::ProgramGroupWithMembers(environment, *sut_p4_session_, - GetIrP4Info(), kGroupId, members, + ir_p4info, kGroupId, members, p4::v1::Update::MODIFY)); // Bring the down member watch port up. ASSERT_OK(SetInterfaceAdminState(*control_gnmi_stub_, selected_port_name, @@ -1050,7 +1053,7 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForMemberModify) { // Send 5000 packets and check for packet distribution. ASSERT_OK(SendNPacketsToSut(kNumTestPackets, test_config, members, - controller_port_ids, GetIrP4Info(), + controller_port_ids, ir_p4info, *control_p4_session_, environment)); test_data_.total_packets_sent = kNumTestPackets; @@ -1072,7 +1075,7 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForMemberModify) { absl::flat_hash_set expected_member_ports = CreateExpectedMemberPorts(members); - ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, GetIrP4Info(), + ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, ir_p4info, kGroupId, members)); // Verifies the actual members inferred from receive traffic matches the @@ -1084,11 +1087,11 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForMemberModify) { } // Delete default routes to prepare for delete group. - ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, GetIrP4Info(), kVrfId, + ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, ir_p4info, kVrfId, p4::v1::Update::DELETE)); // Delete group and verify no errors. - ASSERT_OK(DeleteGroup(*sut_p4_session_, GetIrP4Info(), kGroupId)); + ASSERT_OK(DeleteGroup(*sut_p4_session_, ir_p4info, kGroupId)); }; // Add ActionProfileGroup member whose watch port is down (during create) and @@ -1099,8 +1102,10 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForDownPortMemberInsert) { environment.SetTestCaseID("e54da480-d2cc-42c6-bced-0354b5ab3329"); absl::Span controller_port_ids = GetParam().port_ids; const int input_port = controller_port_ids[kDefaultInputPortIndex]; - ASSERT_OK(SetUpInputPortForPacketReceive(*sut_p4_session_, GetIrP4Info(), - input_port)); + ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, + pdpi::CreateIrP4Info(GetParam().p4_info)); + ASSERT_OK( + SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); const int group_size = kNumWcmpMembersForTest; ASSERT_OK_AND_ASSIGN(std::vector members, @@ -1120,13 +1125,13 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForDownPortMemberInsert) { AdminState::kDown)); // Programs the required router interfaces, nexthops for wcmp group. - ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, GetIrP4Info(), + ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, members)); ASSERT_OK(pins::ProgramGroupWithMembers(environment, *sut_p4_session_, - GetIrP4Info(), kGroupId, members, + ir_p4info, kGroupId, members, p4::v1::Update::INSERT)); // Program default routing for all packets on SUT. - ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, GetIrP4Info(), kVrfId, + ASSERT_OK(ProgramDefaultRoutes(*sut_p4_session_, ir_p4info, kVrfId, p4::v1::Update::INSERT)); // Generate test configuration, pick any field used by hashing to vary for @@ -1163,7 +1168,7 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForDownPortMemberInsert) { // Send 5000 packets and check for packet distribution. ASSERT_OK(SendNPacketsToSut(kNumTestPackets, test_config, members, - controller_port_ids, GetIrP4Info(), + controller_port_ids, ir_p4info, *control_p4_session_, environment)); test_data_.total_packets_sent = kNumTestPackets; @@ -1190,7 +1195,7 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForDownPortMemberInsert) { ASSERT_OK_AND_ASSIGN(auto num_packets_per_port, CountNumPacketsPerPort(test.output)); - ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, GetIrP4Info(), + ASSERT_OK(VerifyGroupMembersFromP4Read(*sut_p4_session_, ir_p4info, kGroupId, members)); // Verifies the actual members inferred from receive traffic matches the // expected members. diff --git a/tests/forwarding/watch_port_test.h b/tests/forwarding/watch_port_test.h index 08570edd..d00d14f9 100644 --- a/tests/forwarding/watch_port_test.h +++ b/tests/forwarding/watch_port_test.h @@ -39,6 +39,8 @@ namespace pins { struct WatchPortTestParams { thinkit::MirrorTestbedInterface* testbed; std::string gnmi_config; + // P4Info to be used based on a specific instantiation. + p4::config::v1::P4Info p4_info; // TODO: Remove port ids from here and derive from gNMI config. std::vector port_ids; // Optional function that raises critical alarm in the system. @@ -57,10 +59,6 @@ class WatchPortTestFixture void TearDown() override; - // Returns the P4Info used by the test, for now just Middleblock. - const p4::config::v1::P4Info& GetP4Info(); - const pdpi::IrP4Info& GetIrP4Info(); - TestData test_data_; std::unique_ptr sut_p4_session_; std::unique_ptr control_p4_session_; diff --git a/tests/gnoi/bert_tests.cc b/tests/gnoi/bert_tests.cc index 33c860c6..5014534c 100644 --- a/tests/gnoi/bert_tests.cc +++ b/tests/gnoi/bert_tests.cc @@ -90,7 +90,7 @@ const std::string BuildPerPortStartBertRequest( key { key: "name" value: '$0' } } } - prbs_polynomial: PRBS_POLYNOMIAL_PRBS23 + prbs_polynomial: PRBS_POLYNOMIAL_PRBS31 test_duration_in_secs: $1 )pb", interface_name, ToInt64Seconds(kTestDuration)); @@ -979,7 +979,7 @@ TEST_P(BertTest, StartBertSucceeds) { grpc::ClientContext result_context; EXPECT_OK(sut_diag_stub_->GetBERTResult(&result_context, result_request_sut, &result_response)); - LOG(INFO) << "Result: " << result_response.ShortDebugString(); + LOG(INFO) << "SUT BERT result: " << result_response.ShortDebugString(); ASSERT_THAT(result_response.per_port_responses(), SizeIs(bert_request_sut.per_port_requests_size())); for (int idx = 0; idx < result_response.per_port_responses_size(); ++idx) { @@ -998,7 +998,8 @@ TEST_P(BertTest, StartBertSucceeds) { ASSERT_OK_AND_ASSIGN( gnoi::diag::GetBERTResultResponse result_response, control_device.GetBERTResult(result_request_control_switch)); - LOG(INFO) << "Result: " << result_response.ShortDebugString(); + LOG(INFO) << "Control switch BERT result: " + << result_response.ShortDebugString(); ASSERT_THAT(result_response.per_port_responses(), SizeIs(bert_request_control_switch.per_port_requests_size())); for (int idx = 0; idx < result_response.per_port_responses_size(); ++idx) { From f6b5693632146baf097271d0ba354c17b12c3017 Mon Sep 17 00:00:00 2001 From: smolkaj Date: Tue, 26 Nov 2024 12:42:55 +0000 Subject: [PATCH 4/4] Remove ingress RIF requirement on input traffic port. --- tests/forwarding/watch_port_test.cc | 59 +---------------------------- 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/tests/forwarding/watch_port_test.cc b/tests/forwarding/watch_port_test.cc index ac292010..ff970274 100644 --- a/tests/forwarding/watch_port_test.cc +++ b/tests/forwarding/watch_port_test.cc @@ -104,37 +104,6 @@ constexpr int kNumTestPackets = 5000; // arrive. constexpr int kDefaultInputPortIndex = 0; -// Helper function that sets up the input port for packet recieve. -// Creates the router interface for the input port. Without this input packets -// get dropped (b/190736007). -absl::Status SetUpInputPortForPacketReceive(pdpi::P4RuntimeSession& p4_session, - const pdpi::IrP4Info& ir_p4info, - int input_port) { - ASSIGN_OR_RETURN( - p4::v1::WriteRequest write_request, - pdpi::PdWriteRequestToPi( - ir_p4info, gutil::ParseProtoOrDie(absl::Substitute( - R"pb( - updates { - type: INSERT - table_entry { - router_interface_table_entry { - match { router_interface_id: "$0" } - action { - set_port_and_src_mac { - port: "$1" - src_mac: "00:02:03:04:05:06" - } - } - } - } - } - )pb", - input_port, input_port)))); - - return pdpi::SetMetadataAndSendPiWriteRequest(&p4_session, write_request); -} - // Helper function that creates/deletes V4, V6 default route entries. absl::Status ProgramDefaultRoutes(pdpi::P4RuntimeSession& p4_session, const pdpi::IrP4Info& ir_p4info, @@ -552,12 +521,8 @@ TEST_P(WatchPortTestFixture, VerifyBasicWcmpPacketDistribution) { const int group_size = kNumWcmpMembersForTest; ASSERT_OK_AND_ASSIGN(std::vector members, CreateGroupMembers(group_size, controller_port_ids)); - - const int input_port = controller_port_ids[kDefaultInputPortIndex]; ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, pdpi::CreateIrP4Info(GetParam().p4_info)); - ASSERT_OK( - SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Programs the required router interfaces, nexthops for wcmp group. ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, @@ -638,12 +603,8 @@ TEST_P(WatchPortTestFixture, VerifyBasicWatchPortAction) { const int group_size = kNumWcmpMembersForTest; ASSERT_OK_AND_ASSIGN(std::vector members, CreateGroupMembers(group_size, controller_port_ids)); - - const int input_port = controller_port_ids[kDefaultInputPortIndex]; ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, pdpi::CreateIrP4Info(GetParam().p4_info)); - ASSERT_OK( - SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Programs the required router interfaces, nexthops for wcmp group. ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, @@ -757,12 +718,8 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionInCriticalState) { const int group_size = kNumWcmpMembersForTest; ASSERT_OK_AND_ASSIGN(std::vector members, CreateGroupMembers(group_size, controller_port_ids)); - - const int input_port = controller_port_ids[kDefaultInputPortIndex]; ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, pdpi::CreateIrP4Info(GetParam().p4_info)); - ASSERT_OK( - SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Program the required router interfaces, nexthops for wcmp group. ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, @@ -870,12 +827,8 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForSingleMember) { const int group_size = 1; ASSERT_OK_AND_ASSIGN(std::vector members, CreateGroupMembers(group_size, controller_port_ids)); - - const int input_port = controller_port_ids[kDefaultInputPortIndex]; ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, pdpi::CreateIrP4Info(GetParam().p4_info)); - ASSERT_OK( - SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Programs the required router interfaces, nexthops for wcmp group. ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, @@ -988,12 +941,8 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForMemberModify) { const int group_size = kNumWcmpMembersForTest; ASSERT_OK_AND_ASSIGN(std::vector members, CreateGroupMembers(group_size, controller_port_ids)); - - const int input_port = controller_port_ids[kDefaultInputPortIndex]; ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, pdpi::CreateIrP4Info(GetParam().p4_info)); - ASSERT_OK( - SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); // Programs the required router interfaces, nexthops for wcmp group. ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, @@ -1101,12 +1050,6 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForDownPortMemberInsert) { GetParam().testbed->GetMirrorTestbed().Environment(); environment.SetTestCaseID("e54da480-d2cc-42c6-bced-0354b5ab3329"); absl::Span controller_port_ids = GetParam().port_ids; - const int input_port = controller_port_ids[kDefaultInputPortIndex]; - ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, - pdpi::CreateIrP4Info(GetParam().p4_info)); - ASSERT_OK( - SetUpInputPortForPacketReceive(*sut_p4_session_, ir_p4info, input_port)); - const int group_size = kNumWcmpMembersForTest; ASSERT_OK_AND_ASSIGN(std::vector members, CreateGroupMembers(group_size, controller_port_ids)); @@ -1125,6 +1068,8 @@ TEST_P(WatchPortTestFixture, VerifyWatchPortActionForDownPortMemberInsert) { AdminState::kDown)); // Programs the required router interfaces, nexthops for wcmp group. + ASSERT_OK_AND_ASSIGN(const pdpi::IrP4Info ir_p4info, + pdpi::CreateIrP4Info(GetParam().p4_info)); ASSERT_OK(pins::ProgramNextHops(environment, *sut_p4_session_, ir_p4info, members)); ASSERT_OK(pins::ProgramGroupWithMembers(environment, *sut_p4_session_,