Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SAIP4] Model multicast. #547

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sai_p4/fixed/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ filegroup(
name = "fixed",
srcs = [
"bitwidths.p4",
"drop_martians.p4",
"bmv2_intrinsics.h",
"drop_martians.p4",
"headers.p4",
"ids.h",
"ipv4_checksum.p4",
Expand Down
6 changes: 6 additions & 0 deletions sai_p4/fixed/bitwidths.p4
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@
#define TUNNEL_ID_BITWIDTH 16
#endif

// Inherited from v1model, see `standard_metadata_t.mcast_grp`.
#define MULTICAST_GROUP_ID_BITWIDTH 16

// Inherited from v1model, see `standard_metadata_t.egress_rid`.
#define REPLICA_INSTANCE_BITWIDTH 16

#endif // SAI_BITWIDTHS_P4_
15 changes: 15 additions & 0 deletions sai_p4/fixed/bmv2_intrinsics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef PINS_INFRA_SAI_P4_FIXED_BMV2_INTRINSICS_H_
#define PINS_INFRA_SAI_P4_FIXED_BMV2_INTRINSICS_H_

// Possible values of the v1model `standard_metadata_t` field `instance_type` in
// BMv2. The semantics of these values is explained here:
// https://github.com/p4lang/behavioral-model/blob/main/docs/simple_switch.md
#define PKT_INSTANCE_TYPE_NORMAL 0
#define PKT_INSTANCE_TYPE_INGRESS_CLONE 1
#define PKT_INSTANCE_TYPE_EGRESS_CLONE 2
#define PKT_INSTANCE_TYPE_COALESCED 3
#define PKT_INSTANCE_TYPE_INGRESS_RECIRC 4
#define PKT_INSTANCE_TYPE_REPLICATION 5
#define PKT_INSTANCE_TYPE_RESUBMIT 6

#endif // PINS_INFRA_SAI_P4_FIXED_BMV2_INTRINSICS_H_
10 changes: 7 additions & 3 deletions sai_p4/fixed/ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
#define ROUTING_IPV4_TABLE_ID 0x02000044 // 33554500
#define ROUTING_IPV6_TABLE_ID 0x02000045 // 33554501
#define ROUTING_VRF_TABLE_ID 0x0200004A // 33554506
#define ROUTING_MULTICAST_SRC_MAC_TABLE_ID 0x0200004C // 33554508
#define MIRROR_SESSION_TABLE_ID 0x02000046 // 33554502
#define L3_ADMIT_TABLE_ID 0x02000047 // 33554503
#define MIRROR_PORT_TO_PRE_SESSION_TABLE_ID 0x02000048 // 33554504
#define ECMP_HASHING_TABLE_ID 0x02000049 // 33554505
#define ROUTING_TUNNEL_TABLE_ID 0x02000050 // 33554512
#define IPV6_TUNNEL_TERMINATION_TABLE_ID 0x0200004B // 33554507
// Next available table id: 0x0200004C (33554508)
// Next available table id: 0x0200004D (33554509)

// --- Actions -----------------------------------------------------------------

Expand All @@ -37,12 +38,15 @@
#define ROUTING_SET_WCMP_GROUP_ID_ACTION_ID 0x01000004 // 16777220
#define ROUTING_SET_WCMP_GROUP_ID_AND_METADATA_ACTION_ID 0x01000011 // 16777233
#define ROUTING_SET_NEXTHOP_ID_ACTION_ID 0x01000005 // 16777221
#define ROUTING_SET_IP_NEXTHOP_AND_DISABLE_REWRITES_ACTION_ID \
0x01000017
// 16777239
#define ROUTING_SET_IP_NEXTHOP_AND_DISABLE_REWRITES_ACTION_ID 0x01000017
#define ROUTING_SET_NEXTHOP_ID_AND_METADATA_ACTION_ID 0x01000010 // 16777232
#define ROUTING_DROP_ACTION_ID 0x01000006 // 16777222
#define ROUTING_SET_P2P_TUNNEL_ENCAP_NEXTHOP_ACTION_ID 0x01000012 // 16777234
#define ROUTING_MARK_FOR_P2P_TUNNEL_ENCAP_ACTION_ID 0x01000013 // 16777235
#define ROUTING_SET_MULTICAST_GROUP_ID_ACTION_ID 0x01000018 // 16777240
#define ROUTING_SET_MULTICAST_SRC_MAC_ACTION_ID 0x01000019 // 16777241
#define MIRRORING_MIRROR_AS_IPV4_ERSPAN_ACTION_ID 0x01000007 // 16777223
#define L3_ADMIT_ACTION_ID 0x01000008 // 16777224
#define MIRRORING_SET_PRE_SESSION_ACTION_ID 0x01000009 // 16777225
Expand All @@ -54,7 +58,7 @@
#define TRAP_ACTION_ID 0x0100000F // 16777231
#define ROUTING_SET_METADATA_AND_DROP_ACTION_ID 0x01000015 // 16777237
#define MARK_FOR_TUNNEL_DECAP_AND_SET_VRF_ACTION_ID 0x01000016 // 16777238
// Next available action id: 0x01000018 (16777240)
// Next available action id: 0x0100001A (16777242)

// --- Action Profiles and Selectors (8 most significant bits = 0x11) ----------
// This value should ideally be 0x11000001, but we currently have this value for
Expand Down
2 changes: 2 additions & 0 deletions sai_p4/fixed/metadata.p4
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ type bit<QOS_QUEUE_BITWIDTH> qos_queue_t;

typedef bit<ROUTE_METADATA_BITWIDTH> route_metadata_t;
typedef bit<ACL_METADATA_BITWIDTH> acl_metadata_t;
typedef bit<MULTICAST_GROUP_ID_BITWIDTH> multicast_group_id_t;
typedef bit<REPLICA_INSTANCE_BITWIDTH> replica_instance_t;

// -- Meters -------------------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions sai_p4/fixed/minimum_guaranteed_sizes.p4
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
#define ROUTING_TUNNEL_TABLE_MINIMUM_GUARANTEED_SIZE 0
#endif

#ifndef ROUTING_MULTICAST_SOURCE_MAC_TABLE_MINIMUM_GUARANTEED_SIZE
#define ROUTING_MULTICAST_SOURCE_MAC_TABLE_MINIMUM_GUARANTEED_SIZE 0
#endif

#ifndef L3_ADMIT_TABLE_MINIMUM_GUARANTEED_SIZE
#define L3_ADMIT_TABLE_MINIMUM_GUARANTEED_SIZE 0
#endif
Expand Down
97 changes: 87 additions & 10 deletions sai_p4/fixed/packet_rewrites.p4
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,96 @@
#include "headers.p4"
#include "metadata.p4"
#include "minimum_guaranteed_sizes.p4"
#include "bmv2_intrinsics.h"

// This control block applies the rewrites computed during the the ingress
// To be applied only for multicast-replicated packets, i.e. packets with
// `standard_metadata.instance_type == PKT_INSTANCE_TYPE_REPLICATION`.
// In P4Runtime, these are packets created by a `Replica` of a
// `MulticastGroupEntry`.
control multicast_rewrites(inout local_metadata_t local_metadata,
in standard_metadata_t standard_metadata) {
// The egress port of the multicast-replicated packet.
// In P4Runtime, equal to the `port` value of the `Replica` of the
// `MulticastGroupEntry` that created this packet.
port_id_t multicast_replica_port = (port_id_t) standard_metadata.egress_port;

// The instance number of the multicast-replicated packet.
// In P4Runtime, equal to the `instance` value of the `Replica` of the
// `MulticastGroupEntry` that created this packet.
replica_instance_t multicast_replica_instance =
standard_metadata.egress_rid;

@id(ROUTING_SET_MULTICAST_SRC_MAC_ACTION_ID)
action set_multicast_src_mac(@id(1) @format(MAC_ADDRESS)
ethernet_addr_t src_mac) {
local_metadata.enable_src_mac_rewrite = true;
local_metadata.packet_rewrites.src_mac = src_mac;
}

// Rewrites the source MAC of the multicast-replicated packet.
//
// This is a logical table that does not exist in SAI and that is managed by
// Orchagent. There is a many-to-one correspondence between entries in this
// table and SAI Router Interfaces (RIFs). Each entry corresponds to a RIF
// with the following attributes:
// * `SAI_ROUTER_INTERFACE_ATTR_PORT_ID` is equal to `multicast_replica_port`.
// * `SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS` is equal to the `src_mac`
// parameter of the `set_multicast_src_mac` action.
//
// Orchagent maintains a mapping from entries to RIFs, creating and destroying
// (possibly shared) RIFs as entries are inserted and deleted.
//
// When creating a multicast group member (`SAI_IPMC_GROUP_MEMBER`) from a
// P4Runtime `Replica`, Orchagent will use this table to set the value of the
// `SAI_IPMC_GROUP_MEMBER_ATTR_IPMC_OUTPUT_ID` attribute: it will expect to
// find an entry for the replica's port and instance in this table, and will
// use the ID of the RIF associated with that entry.
// This will cause the source MAC of packets generated by the group member to
// be rewritten to the `src_mac` of the `set_multicast_src_mac` action of the
// entry.
//
// TODO: Remove `@unsupported` annotation once the switch stack
// supports this table.
@unsupported
@p4runtime_role(P4RUNTIME_ROLE_ROUTING)
@id(ROUTING_MULTICAST_SRC_MAC_TABLE_ID)
table multicast_source_mac_table {
key = {
multicast_replica_port : exact
// TODO: Add this once supported by PDPI and its customers.
// @referenced_by(multicast_group_table, replica.port)
@id(1);
multicast_replica_instance : exact
// TODO: Add this once supported by PDPI and its customers.
// @referenced_by(multicast_group_table, replica.instance)
@id(2);
}
actions = {
@proto_id(1) set_multicast_src_mac;
}
size = ROUTING_MULTICAST_SOURCE_MAC_TABLE_MINIMUM_GUARANTEED_SIZE;
}

apply {
multicast_source_mac_table.apply();
}
} // control multicast_rewrites

// This control block applies the rewrites computed during the ingress
// stage to the actual packet.
control packet_rewrites(inout headers_t headers,
in local_metadata_t local_metadata,
inout local_metadata_t local_metadata,
inout standard_metadata_t standard_metadata) {
apply {
// TODO: Use a more robust check to determine whether to rewrite
// packets.
if (standard_metadata.instance_type == PKT_INSTANCE_TYPE_REPLICATION) {
// TODO: Remove guard once p4-symbolic suports assertions.
#ifndef PLATFORM_P4SYMBOLIC
assert(local_metadata.admit_to_l3);
#endif
local_metadata.enable_ttl_rewrite = true;
multicast_rewrites.apply(local_metadata, standard_metadata);
}

if (local_metadata.admit_to_l3){
if (local_metadata.enable_src_mac_rewrite) {
headers.ethernet.src_addr = local_metadata.packet_rewrites.src_mac;
Expand All @@ -27,19 +108,15 @@ control packet_rewrites(inout headers_t headers,
}
// TODO: Verify this is accurate when TTL rewrite is
// disabled and update this code if not.
if (headers.ipv4.ttl == 0) {
mark_to_drop(standard_metadata);
}
if (headers.ipv4.ttl == 0) mark_to_drop(standard_metadata);
}
if (headers.ipv6.isValid()) {
if (headers.ipv6.hop_limit > 0 && local_metadata.enable_ttl_rewrite) {
headers.ipv6.hop_limit = headers.ipv6.hop_limit - 1;
}
// TODO: Verify this is accurate when TTL rewrite is
// disabled and update this code if not.
if (headers.ipv6.hop_limit == 0) {
mark_to_drop(standard_metadata);
}
if (headers.ipv6.hop_limit == 0) mark_to_drop(standard_metadata);
}
}
}
Expand Down
27 changes: 26 additions & 1 deletion sai_p4/fixed/routing.p4
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,30 @@ control routing(in headers_t headers,
}
#endif

@p4runtime_role(P4RUNTIME_ROLE_ROUTING)
// Sets the multicast group ID (SAI_IPMC_ENTRY_ATTR_OUTPUT_GROUP_ID).
// The ID will be looked up in the multicast group table after ingress
// processing. The group table will then make 0 or more copies of the packet
// and pass them to the egress pipeline.
//
// Calling this action will override unicast, and can itself be overriden by
// `mark_to_drop`.
//
// Using a `multicast_group_id` of 0 is not allowed.
// TODO: Enforce this requirement using p4-constraints.
//
// TODO: Remove `@unsupported` annotation once the switch stack
// supports multicast.
@unsupported
@id(ROUTING_SET_MULTICAST_GROUP_ID_ACTION_ID)
action set_multicast_group_id(
@id(1)
// TODO: Add this once supported by PDPI and its customers.
// @refers_to(multicast_group_table, multicast_group_id)
multicast_group_id_t multicast_group_id) {
standard_metadata.mcast_grp = multicast_group_id;
}

@p4runtime_role(P4RUNTIME_ROLE_ROUTING)
@id(ROUTING_IPV4_TABLE_ID)
table ipv4_table {
key = {
Expand All @@ -427,6 +450,7 @@ control routing(in headers_t headers,
#ifdef SAI_INSTANTIATION_FABRIC_BORDER_ROUTER
@proto_id(7) set_metadata_and_drop;
#endif
@proto_id(8) set_multicast_group_id;
}
const default_action = drop;
size = ROUTING_IPV4_TABLE_MINIMUM_GUARANTEED_SIZE;
Expand All @@ -453,6 +477,7 @@ control routing(in headers_t headers,
#ifdef SAI_INSTANTIATION_FABRIC_BORDER_ROUTER
@proto_id(7) set_metadata_and_drop;
#endif
@proto_id(8) set_multicast_group_id;
}
const default_action = drop;
size = ROUTING_IPV6_TABLE_MINIMUM_GUARANTEED_SIZE;
Expand Down
69 changes: 68 additions & 1 deletion sai_p4/instantiations/google/fabric_border_router.p4info.pb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ tables {
scope: DEFAULT_ONLY
}
const_default_action_id: 21257015
size: 128
size: 64
}
tables {
preamble {
Expand Down Expand Up @@ -389,6 +389,10 @@ tables {
id: 16777237
annotations: "@proto_id(7)"
}
action_refs {
id: 16777240
annotations: "@proto_id(8)"
}
const_default_action_id: 16777222
size: 32768
}
Expand Down Expand Up @@ -443,6 +447,10 @@ tables {
id: 16777237
annotations: "@proto_id(7)"
}
action_refs {
id: 16777240
annotations: "@proto_id(8)"
}
const_default_action_id: 16777222
size: 4096
}
Expand Down Expand Up @@ -737,6 +745,39 @@ tables {
const_default_action_id: 21257015
size: 1024
}
tables {
preamble {
id: 33554508
name: "egress.packet_rewrites.multicast_rewrites.multicast_source_mac_table"
alias: "multicast_source_mac_table"
annotations: "@unsupported"
annotations: "@p4runtime_role(\"sdn_controller\")"
}
match_fields {
id: 1
name: "multicast_replica_port"
match_type: EXACT
type_name {
name: "port_id_t"
}
}
match_fields {
id: 2
name: "multicast_replica_instance"
bitwidth: 16
match_type: EXACT
}
action_refs {
id: 16777241
annotations: "@proto_id(1)"
}
action_refs {
id: 21257015
annotations: "@defaultonly"
scope: DEFAULT_ONLY
}
size: 128
}
tables {
preamble {
id: 33554692
Expand Down Expand Up @@ -1118,6 +1159,19 @@ actions {
bitwidth: 6
}
}
actions {
preamble {
id: 16777240
name: "ingress.routing.set_multicast_group_id"
alias: "set_multicast_group_id"
annotations: "@unsupported"
}
params {
id: 1
name: "multicast_group_id"
bitwidth: 16
}
}
actions {
preamble {
id: 16777473
Expand Down Expand Up @@ -1249,6 +1303,19 @@ actions {
bitwidth: 32
}
}
actions {
preamble {
id: 16777241
name: "egress.packet_rewrites.multicast_rewrites.set_multicast_src_mac"
alias: "set_multicast_src_mac"
}
params {
id: 1
name: "src_mac"
annotations: "@format(MAC_ADDRESS)"
bitwidth: 48
}
}
action_profiles {
preamble {
id: 299650760
Expand Down
2 changes: 1 addition & 1 deletion sai_p4/instantiations/google/instantiations.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ inline std::ostream& operator<<(std::ostream& os, Instantiation instantiation) {
}

template <typename Sink>
inline void AbslStringify(Sink& sink, Instantiation instantiation) {
void AbslStringify(Sink& sink, Instantiation instantiation) {
absl::Format(&sink, "%s", InstantiationToString(instantiation));
}

Expand Down
Loading
Loading