16
16
17
17
#include < memory>
18
18
#include < optional>
19
+ #include < string>
20
+ #include < tuple>
21
+ #include < utility>
22
+ #include < vector>
19
23
20
24
#include " absl/strings/str_cat.h"
25
+ #include " absl/strings/string_view.h"
21
26
#include " absl/time/clock.h"
22
27
#include " absl/time/time.h"
23
28
#include " google/protobuf/util/message_differencer.h"
24
29
#include " gutil/proto_matchers.h"
25
30
#include " gutil/status_matchers.h"
26
31
#include " gutil/testing.h"
27
32
#include " lib/gnmi/gnmi_helper.h"
28
- #include " p4/config/v1/p4info.pb.h"
29
33
#include " p4/v1/p4runtime.pb.h"
30
34
#include " p4_pdpi/ir.h"
31
35
#include " p4_pdpi/ir.pb.h"
32
36
#include " p4_pdpi/p4_runtime_session.h"
33
37
#include " p4_pdpi/p4_runtime_session_extras.h"
34
38
#include " p4_pdpi/pd.h"
35
- #include " sai_p4/instantiations/google/sai_p4info.h"
36
39
#include " sai_p4/instantiations/google/sai_pd.pb.h"
40
+ #include " sai_p4/instantiations/google/test_tools/test_entries.h"
37
41
#include " tests/forwarding/test_data.h"
38
42
#include " tests/lib/p4rt_fixed_table_programming_helper.h"
39
43
#include " tests/lib/switch_test_setup_helpers.h"
40
44
#include " gmock/gmock.h"
41
45
#include " gtest/gtest.h"
46
+ #include " thinkit/mirror_testbed.h"
47
+ #include " thinkit/test_environment.h"
42
48
43
49
namespace pins_test {
44
50
namespace {
45
51
52
+ using ::gutil::EqualsProto;
46
53
using ::gutil::IsOk;
54
+ using ::testing::ElementsAre;
47
55
using ::testing::Not;
48
56
49
57
TEST_P (SmokeTestFixture, CanEstablishConnections) {
@@ -301,8 +309,7 @@ TEST_P(SmokeTestFixture, InsertTableEntryWithRandomCharacterId) {
301
309
ASSERT_OK (pdpi::InstallPiTableEntry (sut_p4rt_session.get (), pi_entry));
302
310
ASSERT_OK_AND_ASSIGN (auto entries,
303
311
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)));
306
313
307
314
// An auxiliary RedisDB tool that takes a snapshot of the database has issues
308
315
// with reading non-UTF-8 compliant characters. This is only used for
@@ -476,9 +483,8 @@ TEST_P(SmokeTestFixture, DISABLED_PushGnmiConfigWithFlows) {
476
483
ASSERT_OK (pins_test::PushGnmiConfig (testbed.Sut (), sut_gnmi_config));
477
484
}
478
485
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 =
482
488
GetParam ().mirror_testbed ->GetMirrorTestbed ();
483
489
ASSERT_OK_AND_ASSIGN (pdpi::IrP4Info ir_p4info,
484
490
pdpi::CreateIrP4Info (GetParam ().p4info ));
@@ -504,18 +510,29 @@ TEST_P(SmokeTestFixture, DISABLED_DeleteReferencedEntryNotOk) {
504
510
pins::RouterInterfaceTableUpdate (
505
511
ir_p4info, p4::v1::Update::INSERT, kRifId ,
506
512
/* 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 ));
512
513
514
+ // Install RIF then Neighbor entries.
513
515
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
+ }
516
533
517
534
// Cannot delete the neighbor table entry because it is used by the tunnel
518
- // entry.
535
+ // entry or the nexthop entry .
519
536
insert_and_delete_neighbor_update.set_type (p4::v1::Update::DELETE);
520
537
EXPECT_THAT (pdpi::SendPiUpdates (sut_p4rt_session.get (),
521
538
{insert_and_delete_neighbor_update}),
@@ -525,9 +542,94 @@ TEST_P(SmokeTestFixture, DISABLED_DeleteReferencedEntryNotOk) {
525
542
// Otherwise, the switch is in a corrupted state.
526
543
ASSERT_OK_AND_ASSIGN (const pdpi::IrTableEntries read_entries,
527
544
pdpi::ReadIrTableEntries (*sut_p4rt_session));
528
- ASSERT_OK (pdpi::ClearTableEntries ( sut_p4rt_session. get () ));
545
+ ASSERT_OK (pdpi::ClearEntities (* sut_p4rt_session));
529
546
EXPECT_OK (pdpi::InstallIrTableEntries (*sut_p4rt_session, read_entries));
530
547
}
531
548
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
+
532
634
} // namespace
533
635
} // namespace pins
0 commit comments