Skip to content

Commit 3a0c82e

Browse files
kishanpsVSuryaprasad-HCL
authored andcommitted
[SAI-P4] Add semantic modeling tests for multicast and enable vlan rewrites for multicast actions.
1 parent 31445df commit 3a0c82e

File tree

4 files changed

+168
-3
lines changed

4 files changed

+168
-3
lines changed

sai_p4/fixed/packet_rewrites.p4

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ control multicast_rewrites(inout local_metadata_t local_metadata,
3030
ethernet_addr_t src_mac) {
3131
local_metadata.enable_src_mac_rewrite = true;
3232
local_metadata.packet_rewrites.src_mac = src_mac;
33-
// Hard-coded for now. We may make the VLAN ID programmable when needed.
33+
34+
// By default VLAN is removed (if present). This is modeled by rewriting
35+
// vlan_id to the INTERNAL_VLAN_ID.
36+
local_metadata.enable_vlan_rewrite = true;
3437
local_metadata.packet_rewrites.vlan_id = INTERNAL_VLAN_ID;
3538
}
3639

@@ -120,7 +123,7 @@ control multicast_rewrites(inout local_metadata_t local_metadata,
120123
@id(2);
121124
}
122125
actions = {
123-
// such an image is rolled out.
126+
// TODO: Remove once no longer in use.
124127
// Deprecated: use `set_src_mac` instead.
125128
@proto_id(1) set_multicast_src_mac;
126129
@proto_id(2) l2_multicast_passthrough;

sai_p4/instantiations/google/test_tools/test_entries.cc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,71 @@ EntryBuilder& EntryBuilder::AddMulticastRouterInterfaceEntry(
368368
return *this;
369369
}
370370

371+
EntryBuilder& EntryBuilder::AddMrifEntryRewritingSrcMac(
372+
absl::string_view egress_port, int replica_instance,
373+
const netaddr::MacAddress& src_mac) {
374+
sai::MulticastRouterInterfaceTableEntry& pd_entry =
375+
*entries_.add_entries()->mutable_multicast_router_interface_table_entry();
376+
auto& match = *pd_entry.mutable_match();
377+
match.set_multicast_replica_port(egress_port);
378+
match.set_multicast_replica_instance(
379+
pdpi::BitsetToHexString<16>(replica_instance));
380+
auto& action = *pd_entry.mutable_action()->mutable_multicast_set_src_mac();
381+
action.set_src_mac(src_mac.ToString());
382+
return *this;
383+
}
384+
385+
EntryBuilder& EntryBuilder::AddMrifEntryRewritingSrcMacAndVlanId(
386+
absl::string_view egress_port, int replica_instance,
387+
const netaddr::MacAddress& src_mac, int vlan_id) {
388+
sai::MulticastRouterInterfaceTableEntry& pd_entry =
389+
*entries_.add_entries()->mutable_multicast_router_interface_table_entry();
390+
auto& match = *pd_entry.mutable_match();
391+
match.set_multicast_replica_port(egress_port);
392+
match.set_multicast_replica_instance(
393+
pdpi::BitsetToHexString<16>(replica_instance));
394+
auto& action =
395+
*pd_entry.mutable_action()->mutable_multicast_set_src_mac_and_vlan_id();
396+
action.set_src_mac(src_mac.ToString());
397+
action.set_vlan_id(pdpi::BitsetToHexString<12>(vlan_id));
398+
return *this;
399+
}
400+
401+
EntryBuilder& EntryBuilder::AddMrifEntryRewritingSrcMacDstMacAndVlanId(
402+
absl::string_view egress_port, int replica_instance,
403+
const netaddr::MacAddress& src_mac, const netaddr::MacAddress& dst_mac,
404+
int vlan_id) {
405+
sai::MulticastRouterInterfaceTableEntry& pd_entry =
406+
*entries_.add_entries()->mutable_multicast_router_interface_table_entry();
407+
auto& match = *pd_entry.mutable_match();
408+
match.set_multicast_replica_port(egress_port);
409+
match.set_multicast_replica_instance(
410+
pdpi::BitsetToHexString<16>(replica_instance));
411+
auto& action = *pd_entry.mutable_action()
412+
->mutable_multicast_set_src_mac_and_dst_mac_and_vlan_id();
413+
action.set_src_mac(src_mac.ToString());
414+
action.set_dst_mac(dst_mac.ToString());
415+
action.set_vlan_id(pdpi::BitsetToHexString<12>(vlan_id));
416+
return *this;
417+
}
418+
419+
EntryBuilder&
420+
EntryBuilder::AddMrifEntryRewritingSrcMacAndPreservingIngressVlanId(
421+
absl::string_view egress_port, int replica_instance,
422+
const netaddr::MacAddress& src_mac) {
423+
sai::MulticastRouterInterfaceTableEntry& pd_entry =
424+
*entries_.add_entries()->mutable_multicast_router_interface_table_entry();
425+
auto& match = *pd_entry.mutable_match();
426+
match.set_multicast_replica_port(egress_port);
427+
match.set_multicast_replica_instance(
428+
pdpi::BitsetToHexString<16>(replica_instance));
429+
auto& action =
430+
*pd_entry.mutable_action()
431+
->mutable_multicast_set_src_mac_and_preserve_ingress_vlan_id();
432+
action.set_src_mac(src_mac.ToString());
433+
return *this;
434+
}
435+
371436
EntryBuilder& EntryBuilder::AddMulticastRoute(
372437
absl::string_view vrf, const netaddr::Ipv4Address& dst_ip,
373438
int multicast_group_id) {

sai_p4/instantiations/google/test_tools/test_entries.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,24 @@ class EntryBuilder {
295295
absl::Span<const Replica> replicas);
296296
EntryBuilder& AddMulticastGroupEntry(
297297
int multicast_group_id, absl::Span<const std::string> egress_ports);
298+
// TODO: b/345579972 - Remove once `mulitcast_set_src_mac` is exclusively used
299+
// and such an image is rolled out. Replace all calls with
300+
// `AddMrifEntryRewritingSrcMac`.
298301
EntryBuilder& AddMulticastRouterInterfaceEntry(
299302
const MulticastRouterInterfaceTableEntry& entry);
303+
EntryBuilder& AddMrifEntryRewritingSrcMac(absl::string_view egress_port,
304+
int replica_instance,
305+
const netaddr::MacAddress& src_mac);
306+
EntryBuilder& AddMrifEntryRewritingSrcMacAndVlanId(
307+
absl::string_view egress_port, int replica_instance,
308+
const netaddr::MacAddress& src_mac, int vlan_id);
309+
EntryBuilder& AddMrifEntryRewritingSrcMacDstMacAndVlanId(
310+
absl::string_view egress_port, int replica_instance,
311+
const netaddr::MacAddress& src_mac, const netaddr::MacAddress& dst_mac,
312+
int vlan_id);
313+
EntryBuilder& AddMrifEntryRewritingSrcMacAndPreservingIngressVlanId(
314+
absl::string_view egress_port, int replica_instance,
315+
const netaddr::MacAddress& src_mac);
300316
EntryBuilder& AddIngressAclDroppingAllPackets();
301317
EntryBuilder& AddEgressAclDroppingIpPackets(
302318
IpVersion ip_version = IpVersion::kIpv4And6);

sai_p4/instantiations/google/test_tools/test_entries_test.cc

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,91 @@ TEST(EntryBuilder, AddMulticastRouterInterfaceEntryAddsEntry) {
464464
.LogPdEntries()
465465
.GetDedupedIrEntities(kIrP4Info, /*allow_unsupported=*/true));
466466
EXPECT_THAT(entities.entities(), ElementsAre(Partially(EqualsProto(R"pb(
467-
table_entry { table_name: "multicast_router_interface_table" }
467+
table_entry {
468+
table_name: "multicast_router_interface_table"
469+
action { name: "set_multicast_src_mac" }
470+
}
471+
)pb"))));
472+
}
473+
474+
TEST(EntryBuilder, AddMrifEntryRewritingSrcMacAddsEntry) {
475+
pdpi::IrP4Info kIrP4Info = GetIrP4Info(Instantiation::kFabricBorderRouter);
476+
ASSERT_OK_AND_ASSIGN(
477+
pdpi::IrEntities entities,
478+
EntryBuilder()
479+
.AddMrifEntryRewritingSrcMac(
480+
/*egress_port=*/"\1", /*replica_instance=*/15,
481+
/*src_mac=*/netaddr::MacAddress(1, 2, 3, 4, 5, 6))
482+
.LogPdEntries()
483+
.GetDedupedIrEntities(kIrP4Info, /*allow_unsupported=*/true));
484+
EXPECT_THAT(entities.entities(), ElementsAre(Partially(EqualsProto(R"pb(
485+
table_entry {
486+
table_name: "multicast_router_interface_table"
487+
action { name: "multicast_set_src_mac" }
488+
}
489+
)pb"))));
490+
}
491+
492+
TEST(EntryBuilder, AddMrifEntryRewritingSrcMacAndVlanIdAddsEntry) {
493+
pdpi::IrP4Info kIrP4Info = GetIrP4Info(Instantiation::kFabricBorderRouter);
494+
ASSERT_OK_AND_ASSIGN(
495+
pdpi::IrEntities entities,
496+
EntryBuilder()
497+
.AddMrifEntryRewritingSrcMacAndVlanId(
498+
/*egress_port=*/"\1", /*replica_instance=*/15,
499+
/*src_mac=*/netaddr::MacAddress(1, 2, 3, 4, 5, 6),
500+
/*vlan_id=*/123)
501+
.LogPdEntries()
502+
.GetDedupedIrEntities(kIrP4Info, /*allow_unsupported=*/true));
503+
EXPECT_THAT(entities.entities(), ElementsAre(Partially(EqualsProto(R"pb(
504+
table_entry {
505+
table_name: "multicast_router_interface_table"
506+
action { name: "multicast_set_src_mac_and_vlan_id" }
507+
}
468508
)pb"))));
469509
}
470510

511+
TEST(EntryBuilder, AddMrifEntryRewritingSrcMacDstMacAndVlanIdAddsEntry) {
512+
pdpi::IrP4Info kIrP4Info = GetIrP4Info(Instantiation::kFabricBorderRouter);
513+
ASSERT_OK_AND_ASSIGN(
514+
pdpi::IrEntities entities,
515+
EntryBuilder()
516+
.AddMrifEntryRewritingSrcMacDstMacAndVlanId(
517+
/*egress_port=*/"\1", /*replica_instance=*/15,
518+
/*src_mac=*/netaddr::MacAddress(1, 2, 3, 4, 5, 6),
519+
/*dst_mac=*/netaddr::MacAddress(7, 8, 9, 10, 11, 12),
520+
/*vlan_id=*/123)
521+
.LogPdEntries()
522+
.GetDedupedIrEntities(kIrP4Info, /*allow_unsupported=*/true));
523+
EXPECT_THAT(
524+
entities.entities(), ElementsAre(Partially(EqualsProto(R"pb(
525+
table_entry {
526+
table_name: "multicast_router_interface_table"
527+
action { name: "multicast_set_src_mac_and_dst_mac_and_vlan_id" }
528+
}
529+
)pb"))));
530+
}
531+
532+
TEST(EntryBuilder,
533+
AddMrifEntryRewritingSrcMacAndPreservingIngressVlanIdAddsEntry) {
534+
pdpi::IrP4Info kIrP4Info = GetIrP4Info(Instantiation::kFabricBorderRouter);
535+
ASSERT_OK_AND_ASSIGN(
536+
pdpi::IrEntities entities,
537+
EntryBuilder()
538+
.AddMrifEntryRewritingSrcMacAndPreservingIngressVlanId(
539+
/*egress_port=*/"\1", /*replica_instance=*/15,
540+
/*src_mac=*/netaddr::MacAddress(1, 2, 3, 4, 5, 6))
541+
.LogPdEntries()
542+
.GetDedupedIrEntities(kIrP4Info, /*allow_unsupported=*/true));
543+
EXPECT_THAT(
544+
entities.entities(), ElementsAre(Partially(EqualsProto(R"pb(
545+
table_entry {
546+
table_name: "multicast_router_interface_table"
547+
action { name: "multicast_set_src_mac_and_preserve_ingress_vlan_id" }
548+
}
549+
)pb"))));
550+
}
551+
471552
TEST(EntryBuilder, AddMulticastRouteAddsIpv4Entry) {
472553
pdpi::IrP4Info kIrP4Info = GetIrP4Info(Instantiation::kFabricBorderRouter);
473554
ASSERT_OK_AND_ASSIGN(auto dst_ip,

0 commit comments

Comments
 (0)