From a35d0040d499db896ff91843546e1b6a1a44132b Mon Sep 17 00:00:00 2001 From: smolkaj Date: Tue, 10 Dec 2024 14:58:07 +0000 Subject: [PATCH] Make l3_admit_test use mirror_blackbox_test_fixture. --- tests/forwarding/BUILD.bazel | 1 + tests/forwarding/l3_admit_test.cc | 66 +++++++++++++++---------------- tests/forwarding/l3_admit_test.h | 17 ++++---- 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/tests/forwarding/BUILD.bazel b/tests/forwarding/BUILD.bazel index 5c72296e..25e06638 100644 --- a/tests/forwarding/BUILD.bazel +++ b/tests/forwarding/BUILD.bazel @@ -158,6 +158,7 @@ cc_library( srcs = ["l3_admit_test.cc"], hdrs = ["l3_admit_test.h"], deps = [ + ":mirror_blackbox_test_fixture", ":util", "//gutil:proto", "//gutil:status_matchers", diff --git a/tests/forwarding/l3_admit_test.cc b/tests/forwarding/l3_admit_test.cc index ec7c3bf6..c756e4e0 100644 --- a/tests/forwarding/l3_admit_test.cc +++ b/tests/forwarding/l3_admit_test.cc @@ -267,10 +267,10 @@ TEST_P(L3AdmitTestFixture, // Punt all traffic arriving at the control switch, and collect them to verify // forwarding. std::unique_ptr packetio_control = - std::make_unique(p4rt_control_switch_session_.get(), + std::make_unique(&GetControlP4RuntimeSession(), PacketInHelper::NoFilter); ASSERT_OK( - PuntAllPacketsToController(*p4rt_control_switch_session_, sai::GetIrP4Info(sai::Instantiation::kMiddleblock))); + PuntAllPacketsToController(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock))); // Add an L3 route to enable forwarding. L3Route l3_route{ @@ -283,13 +283,13 @@ TEST_P(L3AdmitTestFixture, .router_interface_id = "rif-1", .nexthop_id = "nexthop-1", }; - ASSERT_OK(AddAndSetDefaultVrf(*p4rt_sut_switch_session_, sai::GetIrP4Info(sai::Instantiation::kMiddleblock), + ASSERT_OK(AddAndSetDefaultVrf(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route.vrf_id)); - ASSERT_OK(AddL3Route(*p4rt_sut_switch_session_, sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route)); + ASSERT_OK(AddL3Route(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route)); // Admit only 1 MAC address to the forwaring pipeline. ASSERT_OK(AdmitL3Route( - *p4rt_sut_switch_session_, sai::GetIrP4Info(sai::Instantiation::kMiddleblock), + GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), L3AdmitOptions{ .priority = 2070, .dst_mac = std ::make_pair("00:01:02:03:04:05", "FF:FF:FF:FF:FF:FF"), @@ -303,7 +303,7 @@ TEST_P(L3AdmitTestFixture, // Send the "bad" packets first to give them the most time. const std::string kBadPayload = "Testing L3 forwarding. This packet should be dropped."; - ASSERT_OK(SendUdpPacket(*p4rt_control_switch_session_, + ASSERT_OK(SendUdpPacket(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), /*port_id=*/"1", kNumberOfTestPacket, /*dst_mac=*/"00:aa:bb:cc:cc:dd", @@ -312,7 +312,7 @@ TEST_P(L3AdmitTestFixture, // Then send the "good" packets. const std::string kGoodPayload = "Testing L3 forwarding. This packet should arrive to packet in."; - ASSERT_OK(SendUdpPacket(*p4rt_control_switch_session_, + ASSERT_OK(SendUdpPacket(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), /*port_id=*/"1", kNumberOfTestPacket, /*dst_mac=*/"00:01:02:03:04:05", @@ -355,10 +355,10 @@ TEST_P(L3AdmitTestFixture, L3AdmitCanUseMaskToAllowMultipleMacAddresses) { // Punt all traffic arriving at the control switch, and collect them to verify // forwarding. std::unique_ptr packetio_control = - std::make_unique(p4rt_control_switch_session_.get(), + std::make_unique(&GetControlP4RuntimeSession(), PacketInHelper::NoFilter); ASSERT_OK( - PuntAllPacketsToController(*p4rt_control_switch_session_, + PuntAllPacketsToController(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock))); // Add an L3 route to enable forwarding. @@ -373,16 +373,16 @@ TEST_P(L3AdmitTestFixture, L3AdmitCanUseMaskToAllowMultipleMacAddresses) { .nexthop_id = "nexthop-1", }; - ASSERT_OK(AddAndSetDefaultVrf(*p4rt_sut_switch_session_, + ASSERT_OK(AddAndSetDefaultVrf(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route.vrf_id)); - ASSERT_OK(AddL3Route(*p4rt_sut_switch_session_, + ASSERT_OK(AddL3Route(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route)); // Admit multiple MAC addresses into L3 routing with a single L3 admit rule. ASSERT_OK(AdmitL3Route( - *p4rt_sut_switch_session_, sai::GetIrP4Info(sai::Instantiation::kMiddleblock), + GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), L3AdmitOptions{ .priority = 2070, .dst_mac = std ::make_pair("00:01:02:03:00:05", "FF:FF:FF:FF:F0:FF"), @@ -395,7 +395,7 @@ TEST_P(L3AdmitTestFixture, L3AdmitCanUseMaskToAllowMultipleMacAddresses) { "Testing L3 forwarding. This packet should arrive to packet in."; for (int i = 0; i < 5; ++i) { std::string dst_mac = absl::StrFormat("00:01:02:03:%02d:05", i); - ASSERT_OK(SendUdpPacket(*p4rt_control_switch_session_, + ASSERT_OK(SendUdpPacket(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), /*port_id=*/"1", kNumberOfTestPacket, dst_mac, /*dst_ip=*/"10.0.0.1", kGoodPayload)); @@ -434,10 +434,10 @@ TEST_P(L3AdmitTestFixture, DISABLED_L3AdmitCanUseInPortToRestrictMacAddresses) { // Punt all traffic arriving at the control switch, and collect them to verify // forwarding. std::unique_ptr packetio_control = - std::make_unique(p4rt_control_switch_session_.get(), + std::make_unique(&GetControlP4RuntimeSession(), PacketInHelper::NoFilter); ASSERT_OK( - PuntAllPacketsToController(*p4rt_control_switch_session_, + PuntAllPacketsToController(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock))); // Add an L3 route to enable forwarding. @@ -451,16 +451,16 @@ TEST_P(L3AdmitTestFixture, DISABLED_L3AdmitCanUseInPortToRestrictMacAddresses) { .router_interface_id = "rif-1", .nexthop_id = "nexthop-1", }; - ASSERT_OK(AddAndSetDefaultVrf(*p4rt_sut_switch_session_, + ASSERT_OK(AddAndSetDefaultVrf(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route.vrf_id)); - ASSERT_OK(AddL3Route(*p4rt_sut_switch_session_, + ASSERT_OK(AddL3Route(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route)); // Admit the MAC addresses only on port XYZ ASSERT_OK(AdmitL3Route( - *p4rt_sut_switch_session_, + GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), L3AdmitOptions{ .priority = 2070, @@ -476,7 +476,7 @@ TEST_P(L3AdmitTestFixture, DISABLED_L3AdmitCanUseInPortToRestrictMacAddresses) { // Send the "bad" packets first to give them the most time. const std::string kBadPayload = "Testing L3 forwarding. This packet should be dropped."; - ASSERT_OK(SendUdpPacket(*p4rt_control_switch_session_, + ASSERT_OK(SendUdpPacket(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), /*port_id=*/"1", kNumberOfTestPacket, /*dst_mac=*/"00:01:02:03:04:05", @@ -485,7 +485,7 @@ TEST_P(L3AdmitTestFixture, DISABLED_L3AdmitCanUseInPortToRestrictMacAddresses) { // Then send the "good" packets. const std::string kGoodPayload = "Testing L3 forwarding. This packet should arrive to packet in."; - ASSERT_OK(SendUdpPacket(*p4rt_control_switch_session_, + ASSERT_OK(SendUdpPacket(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), /*port_id=*/"2", kNumberOfTestPacket, /*dst_mac=*/"00:01:02:03:04:05", @@ -529,10 +529,10 @@ TEST_P(L3AdmitTestFixture, L3PacketsCanBeRoutedWithOnlyARouterInterface) { // Punt all traffic arriving at the control switch, and collect them to verify // forwarding. std::unique_ptr packetio_control = - std::make_unique(p4rt_control_switch_session_.get(), + std::make_unique(&GetControlP4RuntimeSession(), PacketInHelper::NoFilter); ASSERT_OK( - PuntAllPacketsToController(*p4rt_control_switch_session_, + PuntAllPacketsToController(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock))); // Add an L3 route to enable forwarding, but do not add an explicit L3Admit @@ -547,10 +547,10 @@ ASSERT_OK( .router_interface_id = "rif-1", .nexthop_id = "nexthop-1", }; - ASSERT_OK(AddAndSetDefaultVrf(*p4rt_sut_switch_session_, + ASSERT_OK(AddAndSetDefaultVrf(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route.vrf_id)); - ASSERT_OK(AddL3Route(*p4rt_sut_switch_session_, + ASSERT_OK(AddL3Route(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route)); @@ -559,7 +559,7 @@ ASSERT_OK( const int kNumberOfTestPacket = 100; const std::string kGoodPayload = "Testing L3 forwarding. This packet should arrive to packet in."; - ASSERT_OK(SendUdpPacket(*p4rt_control_switch_session_, + ASSERT_OK(SendUdpPacket(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), /*port_id=*/"1", kNumberOfTestPacket, /*dst_mac=*/"00:00:00:00:00:01", @@ -605,10 +605,10 @@ TEST_P(L3AdmitTestFixture, L3PacketsCanBeClassifiedByDestinationMac) { // Punt all traffic arriving at the control switch, and collect them to verify // forwarding. std::unique_ptr packetio_control = - std::make_unique(p4rt_control_switch_session_.get(), + std::make_unique(&GetControlP4RuntimeSession(), PacketInHelper::NoFilter); ASSERT_OK( - PuntAllPacketsToController(*p4rt_control_switch_session_, + PuntAllPacketsToController(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock))); // This test uses 2 MAC addresses. Both will be admitted to L3 routing, but @@ -618,18 +618,18 @@ TEST_P(L3AdmitTestFixture, L3PacketsCanBeClassifiedByDestinationMac) { std::string vrf_id = "vrf-1"; std::string good_dst_mac = "00:00:00:00:00:03"; std::string drop_dst_mac = "00:00:00:00:00:04"; - ASSERT_OK(AllowVrfTrafficToDstMac(*p4rt_sut_switch_session_, + ASSERT_OK(AllowVrfTrafficToDstMac(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), good_dst_mac, vrf_id)); ASSERT_OK(AdmitL3Route( - *p4rt_sut_switch_session_, + GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), L3AdmitOptions{ .priority = 2070, .dst_mac = std ::make_pair(good_dst_mac, "FF:FF:FF:FF:FF:FF"), })); ASSERT_OK(AdmitL3Route( - *p4rt_sut_switch_session_, + GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), L3AdmitOptions{ .priority = 2070, @@ -647,7 +647,7 @@ TEST_P(L3AdmitTestFixture, L3PacketsCanBeClassifiedByDestinationMac) { .router_interface_id = "rif-1", .nexthop_id = "nexthop-1", }; - ASSERT_OK(AddL3Route(*p4rt_sut_switch_session_, + ASSERT_OK(AddL3Route(GetSutP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), l3_route)); // Send 2 set of packets to the switch. One using the expected destination @@ -660,11 +660,11 @@ TEST_P(L3AdmitTestFixture, L3PacketsCanBeClassifiedByDestinationMac) { "Testing L3 forwarding. This packet should be dropped."; // Send the "bad" packets first to give them the most time. - ASSERT_OK(SendUdpPacket(*p4rt_control_switch_session_, + ASSERT_OK(SendUdpPacket(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), /*port_id=*/"1", kNumberOfTestPacket, drop_dst_mac, /*dst_ip=*/"10.0.0.1", kBadPayload)); - ASSERT_OK(SendUdpPacket(*p4rt_control_switch_session_, + ASSERT_OK(SendUdpPacket(GetControlP4RuntimeSession(), sai::GetIrP4Info(sai::Instantiation::kMiddleblock), /*port_id=*/"1", kNumberOfTestPacket, good_dst_mac, /*dst_ip=*/"10.0.0.1", kGoodPayload)); diff --git a/tests/forwarding/l3_admit_test.h b/tests/forwarding/l3_admit_test.h index 690bf489..17e4db11 100644 --- a/tests/forwarding/l3_admit_test.h +++ b/tests/forwarding/l3_admit_test.h @@ -21,19 +21,22 @@ #include "p4_pdpi/p4_runtime_session.h" #include "sai_p4/instantiations/google/instantiations.h" #include "sai_p4/instantiations/google/sai_p4info.h" +#include "tests/forwarding/mirror_blackbox_test_fixture.h" #include "tests/lib/packet_in_helper.h" #include "thinkit/mirror_testbed_fixture.h" namespace pins { -class L3AdmitTestFixture : public thinkit::MirrorTestbedFixture { +class L3AdmitTestFixture : public pins_test::MirrorBlackboxTestFixture { protected: - void SetUp() override; - - // This test runs on a mirror testbed setup so we open a P4RT connection to - // both switches. - std::unique_ptr p4rt_sut_switch_session_; - std::unique_ptr p4rt_control_switch_session_; + void TearDown() override { + // MirrorBlackboxTestFixture unnecessarily clears tables at TearDown. This + // is not harmful for other tests but is problematic for l3_admit_tests + // since the P4RT session to the controller is closed during the tests (see + // lib/packet_in_helper.h). Therefore, We bypass table clearance in + // TearDown. + MirrorTestbedFixture::TearDown(); + } }; } // namespace pins