Skip to content

Commit 8d1c7b8

Browse files
kishanpsVSuryaprasad-HCL
authored andcommitted
Remove a potential crash in smoke_test. Enable DeleteReferencedEntryNotOk test due to fixed bug.Support platforms that do not support GRE tunnels. Add test checking that the switch will tolerate unicast routes with multicast dst IPs.Fix update ordering to allow proper fail-on-first.
1 parent 33f3408 commit 8d1c7b8

File tree

3 files changed

+125
-18
lines changed

3 files changed

+125
-18
lines changed

tests/forwarding/BUILD.bazel

+4-2
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ cc_library(
115115
"//p4_pdpi:pd",
116116
"//sai_p4/instantiations/google:sai_p4info_cc",
117117
"//sai_p4/instantiations/google:sai_pd_cc_proto",
118-
"//tests/lib:p4rt_fixed_table_programming_helper",
118+
"//sai_p4/instantiations/google/test_tools:test_entries",
119+
"//tests/lib:p4rt_fixed_table_programming_helper",
119120
"//tests/lib:switch_test_setup_helpers",
121+
"//thinkit:mirror_testbed",
120122
"//thinkit:mirror_testbed_fixture",
121-
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
123+
"//thinkit:test_environment",
122124
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
123125
"@com_google_absl//absl/strings",
124126
"@com_google_absl//absl/time",

tests/forwarding/smoke_test.cc

+118-16
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,42 @@
1616

1717
#include <memory>
1818
#include <optional>
19+
#include <string>
20+
#include <tuple>
21+
#include <utility>
22+
#include <vector>
1923

2024
#include "absl/strings/str_cat.h"
25+
#include "absl/strings/string_view.h"
2126
#include "absl/time/clock.h"
2227
#include "absl/time/time.h"
2328
#include "google/protobuf/util/message_differencer.h"
2429
#include "gutil/proto_matchers.h"
2530
#include "gutil/status_matchers.h"
2631
#include "gutil/testing.h"
2732
#include "lib/gnmi/gnmi_helper.h"
28-
#include "p4/config/v1/p4info.pb.h"
2933
#include "p4/v1/p4runtime.pb.h"
3034
#include "p4_pdpi/ir.h"
3135
#include "p4_pdpi/ir.pb.h"
3236
#include "p4_pdpi/p4_runtime_session.h"
3337
#include "p4_pdpi/p4_runtime_session_extras.h"
3438
#include "p4_pdpi/pd.h"
35-
#include "sai_p4/instantiations/google/sai_p4info.h"
3639
#include "sai_p4/instantiations/google/sai_pd.pb.h"
40+
#include "sai_p4/instantiations/google/test_tools/test_entries.h"
3741
#include "tests/forwarding/test_data.h"
3842
#include "tests/lib/p4rt_fixed_table_programming_helper.h"
3943
#include "tests/lib/switch_test_setup_helpers.h"
4044
#include "gmock/gmock.h"
4145
#include "gtest/gtest.h"
46+
#include "thinkit/mirror_testbed.h"
47+
#include "thinkit/test_environment.h"
4248

4349
namespace pins_test {
4450
namespace {
4551

52+
using ::gutil::EqualsProto;
4653
using ::gutil::IsOk;
54+
using ::testing::ElementsAre;
4755
using ::testing::Not;
4856

4957
TEST_P(SmokeTestFixture, CanEstablishConnections) {
@@ -301,8 +309,7 @@ TEST_P(SmokeTestFixture, InsertTableEntryWithRandomCharacterId) {
301309
ASSERT_OK(pdpi::InstallPiTableEntry(sut_p4rt_session.get(), pi_entry));
302310
ASSERT_OK_AND_ASSIGN(auto entries,
303311
pdpi::ReadPiTableEntries(sut_p4rt_session.get()));
304-
EXPECT_EQ(entries.size(), 1);
305-
EXPECT_THAT(entries[0], gutil::EqualsProto(pi_entry));
312+
EXPECT_THAT(entries, ElementsAre(EqualsProto(pi_entry)));
306313

307314
// An auxiliary RedisDB tool that takes a snapshot of the database has issues
308315
// with reading non-UTF-8 compliant characters. This is only used for
@@ -476,9 +483,8 @@ TEST_P(SmokeTestFixture, DISABLED_PushGnmiConfigWithFlows) {
476483
ASSERT_OK(pins_test::PushGnmiConfig(testbed.Sut(), sut_gnmi_config));
477484
}
478485

479-
// TODO: Enable when this test passes due to the bug being fixed.
480-
TEST_P(SmokeTestFixture, DISABLED_DeleteReferencedEntryNotOk) {
481-
thinkit::MirrorTestbed &testbed =
486+
TEST_P(SmokeTestFixture, DeleteReferencedEntryNotOk) {
487+
thinkit::MirrorTestbed& testbed =
482488
GetParam().mirror_testbed->GetMirrorTestbed();
483489
ASSERT_OK_AND_ASSIGN(pdpi::IrP4Info ir_p4info,
484490
pdpi::CreateIrP4Info(GetParam().p4info));
@@ -504,18 +510,29 @@ TEST_P(SmokeTestFixture, DISABLED_DeleteReferencedEntryNotOk) {
504510
pins::RouterInterfaceTableUpdate(
505511
ir_p4info, p4::v1::Update::INSERT, kRifId,
506512
/*port=*/"1", /*src_mac=*/"00:02:03:04:05:06"));
507-
ASSERT_OK_AND_ASSIGN(
508-
const p4::v1::Update tunnel_update,
509-
pins::TunnelTableUpdate(
510-
ir_p4info, p4::v1::Update::INSERT, /*tunnel_id=*/"tid",
511-
/*encap_dst_ip=*/kNeighborId, /*encap_src_ip=*/"::2", kRifId));
512513

514+
// Install RIF then Neighbor entries.
513515
ASSERT_OK(pdpi::SendPiUpdates(
514-
sut_p4rt_session.get(),
515-
{insert_and_delete_neighbor_update, rif_update, tunnel_update}));
516+
sut_p4rt_session.get(), {rif_update, insert_and_delete_neighbor_update}));
517+
518+
// Install either a tunnel or a nexthop depending on if tunnels are supported.
519+
if (GetParam().does_not_support_gre_tunnels) {
520+
ASSERT_OK_AND_ASSIGN(
521+
const p4::v1::Update nexthop_update,
522+
pins::NexthopTableUpdate(ir_p4info, p4::v1::Update::INSERT,
523+
/*nexthop_id=*/"nid", kRifId, kNeighborId));
524+
ASSERT_OK(pdpi::SendPiUpdates(sut_p4rt_session.get(), {nexthop_update}));
525+
} else {
526+
ASSERT_OK_AND_ASSIGN(
527+
const p4::v1::Update tunnel_update,
528+
pins::TunnelTableUpdate(
529+
ir_p4info, p4::v1::Update::INSERT, /*tunnel_id=*/"tid",
530+
/*encap_dst_ip=*/kNeighborId, /*encap_src_ip=*/"::2", kRifId));
531+
ASSERT_OK(pdpi::SendPiUpdates(sut_p4rt_session.get(), {tunnel_update}));
532+
}
516533

517534
// Cannot delete the neighbor table entry because it is used by the tunnel
518-
// entry.
535+
// entry or the nexthop entry.
519536
insert_and_delete_neighbor_update.set_type(p4::v1::Update::DELETE);
520537
EXPECT_THAT(pdpi::SendPiUpdates(sut_p4rt_session.get(),
521538
{insert_and_delete_neighbor_update}),
@@ -525,9 +542,94 @@ TEST_P(SmokeTestFixture, DISABLED_DeleteReferencedEntryNotOk) {
525542
// Otherwise, the switch is in a corrupted state.
526543
ASSERT_OK_AND_ASSIGN(const pdpi::IrTableEntries read_entries,
527544
pdpi::ReadIrTableEntries(*sut_p4rt_session));
528-
ASSERT_OK(pdpi::ClearTableEntries(sut_p4rt_session.get()));
545+
ASSERT_OK(pdpi::ClearEntities(*sut_p4rt_session));
529546
EXPECT_OK(pdpi::InstallIrTableEntries(*sut_p4rt_session, read_entries));
530547
}
531548

549+
// Check that unicast routes with a multicast destination range are accepted by
550+
// the switch. We may disallow this via a p4-constraint in the future, but need
551+
// the capability as a temporary workaround as of 2023-12-08.
552+
TEST_P(SmokeTestFixture, CanInstallIpv4TableEntriesWithMulticastDstIp) {
553+
thinkit::MirrorTestbed& testbed =
554+
GetParam().mirror_testbed->GetMirrorTestbed();
555+
ASSERT_OK_AND_ASSIGN(
556+
std::unique_ptr<pdpi::P4RuntimeSession> sut,
557+
pins_test::ConfigureSwitchAndReturnP4RuntimeSession(
558+
testbed.Sut(), GetParam().gnmi_config, GetParam().p4info));
559+
ASSERT_OK_AND_ASSIGN(pdpi::IrP4Info p4info, pdpi::GetIrP4Info(*sut));
560+
ASSERT_OK_AND_ASSIGN(
561+
std::vector<p4::v1::Entity> pi_entities,
562+
sai::EntryBuilder().AddVrfEntry("vrf").GetDedupedPiEntities(p4info));
563+
ASSERT_OK(pdpi::InstallPiEntities(sut.get(), p4info, pi_entities));
564+
ASSERT_OK(pdpi::InstallPdTableEntries<sai::TableEntries>(*sut, R"pb(
565+
entries {
566+
ipv4_table_entry {
567+
match {
568+
vrf_id: "vrf"
569+
ipv4_dst { value: "224.0.0.0" prefix_length: 8 }
570+
}
571+
action { drop {} }
572+
}
573+
}
574+
entries {
575+
ipv4_table_entry {
576+
match {
577+
vrf_id: "vrf"
578+
ipv4_dst { value: "224.2.3.4" prefix_length: 32 }
579+
}
580+
action { drop {} }
581+
}
582+
}
583+
)pb"));
584+
}
585+
586+
// Check that unicast routes with a multicast destination range are accepted by
587+
// the switch. We may disallow this via a p4-constraint in the future, but need
588+
// the capability as a temporary workaround as of 2023-12-08.
589+
TEST_P(SmokeTestFixture, CanInstallIpv6TableEntriesWithMulticastDstIp) {
590+
thinkit::MirrorTestbed& testbed =
591+
GetParam().mirror_testbed->GetMirrorTestbed();
592+
ASSERT_OK_AND_ASSIGN(
593+
std::unique_ptr<pdpi::P4RuntimeSession> sut,
594+
pins_test::ConfigureSwitchAndReturnP4RuntimeSession(
595+
testbed.Sut(), GetParam().gnmi_config, GetParam().p4info));
596+
ASSERT_OK_AND_ASSIGN(pdpi::IrP4Info p4info, pdpi::GetIrP4Info(*sut));
597+
ASSERT_OK_AND_ASSIGN(
598+
std::vector<p4::v1::Entity> pi_entities,
599+
sai::EntryBuilder().AddVrfEntry("vrf").GetDedupedPiEntities(p4info));
600+
ASSERT_OK(pdpi::InstallPiEntities(sut.get(), p4info, pi_entities));
601+
// TODO: Use `sai::EntryBuilder` instead of hard-coding the entries
602+
// here.
603+
ASSERT_OK(pdpi::InstallPdTableEntries<sai::TableEntries>(*sut, R"pb(
604+
entries {
605+
ipv6_table_entry {
606+
match {
607+
vrf_id: "vrf"
608+
ipv6_dst { value: "ff00::" prefix_length: 8 }
609+
}
610+
action { drop {} }
611+
}
612+
}
613+
entries {
614+
ipv6_table_entry {
615+
match {
616+
vrf_id: "vrf"
617+
ipv6_dst { value: "ff00:1234:5678:9012::" prefix_length: 64 }
618+
}
619+
action { drop {} }
620+
}
621+
}
622+
entries {
623+
ipv6_table_entry {
624+
match {
625+
vrf_id: "vrf"
626+
ipv6_dst { value: "ff00::1234" prefix_length: 128 }
627+
}
628+
action { drop {} }
629+
}
630+
}
631+
)pb"));
632+
}
633+
532634
} // namespace
533635
} // namespace pins

tests/forwarding/smoke_test.h

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct SmokeTestParams {
2828
// given (default), or otherwise pushes the given config before starting.
2929
std::optional<std::string> gnmi_config;
3030
p4::config::v1::P4Info p4info;
31+
// Use on platforms that don't support GRE tunnels to avoid using them in
32+
// tests.
33+
bool does_not_support_gre_tunnels;
3134
};
3235

3336
class SmokeTestFixture : public testing::TestWithParam<SmokeTestParams> {

0 commit comments

Comments
 (0)