Skip to content

Commit

Permalink
[SAIP4] Break routing.p4 into routing_lookup and routing_resolution. …
Browse files Browse the repository at this point in the history
…Move routing_resolution to after ACL ingress stage. (sonic-net#611)



Co-authored-by: smolkaj <[email protected]>
Co-authored-by: kheradmandG <[email protected]>
Co-authored-by: kishanps <[email protected]>
  • Loading branch information
4 people authored Oct 11, 2024
1 parent 879cf64 commit e03cbe1
Show file tree
Hide file tree
Showing 13 changed files with 1,985 additions and 1,985 deletions.
9 changes: 9 additions & 0 deletions sai_p4/fixed/metadata.p4
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ struct local_metadata_t {
bool nexthop_id_valid;
// Nexthop id, only valid if `nexthop_id_valid` is true.
nexthop_id_t nexthop_id_value;

// Determines if packet was dropped in ACL ingress/egress stage. If true, the
// actual call to mark_to_drop (that affects standard_metadata) takes place at
// the end of the respective pipeline.
// This is done this way because we want to call mark_to_drop after
// determining the target_egress_port through the value assigned to
// standard_metadata.egress_spec (which happens in routing_resolution *after*
// ACL ingress) for punted packets.
bool acl_drop;
}

#endif // SAI_METADATA_P4_
5 changes: 5 additions & 0 deletions sai_p4/fixed/parser.p4
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ parser packet_parser(packet_in packet, out headers_t headers,
local_metadata.ingress_port = (port_id_t)standard_metadata.ingress_port;
local_metadata.route_metadata = 0;
local_metadata.bypass_ingress = false;
local_metadata.wcmp_group_id_valid = false;
local_metadata.wcmp_group_id_value = 0;
local_metadata.nexthop_id_valid = false;
local_metadata.nexthop_id_value = 0;
local_metadata.acl_drop = false;

transition select(standard_metadata.ingress_port) {
SAI_P4_CPU_PORT: parse_packet_out_header;
Expand Down
528 changes: 251 additions & 277 deletions sai_p4/fixed/routing.p4

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions sai_p4/instantiations/google/acl_common_actions.p4
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
// more information.
@id(ACL_DROP_ACTION_ID)
@sai_action(SAI_PACKET_ACTION_DROP)
action acl_drop(inout standard_metadata_t standard_metadata) {
mark_to_drop(standard_metadata);
action acl_drop(inout local_metadata_t local_metadata) {
// It is necessary (and enough) to set acl_drop metadata at this point. The
// actual call to mark_to_drop (that affects standard_metadata) happens at the
// end of the current pipeline.
// This is done this way because we want to call mark_to_drop after
// determining the target_egress_port through the value assigned to
// standard_metadata.egress_spec (which happens in routing_resolution *after*
// ACL ingress) for punted packets.
local_metadata.acl_drop = true;
}

#endif // SAI_ACL_COMMON_ACTIONS_P4_
8 changes: 6 additions & 2 deletions sai_p4/instantiations/google/acl_egress.p4
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ control acl_egress(in headers_t headers,
#endif
}
actions = {
@proto_id(1) acl_drop(standard_metadata);
@proto_id(1) acl_drop(local_metadata);
#if defined(SAI_INSTANTIATION_TOR)
@proto_id(2) acl_egress_forward();
#endif
Expand Down Expand Up @@ -139,7 +139,7 @@ control acl_egress(in headers_t headers,
@sai_field(SAI_ACL_TABLE_ATTR_FIELD_OUT_PORT);
}
actions = {
@proto_id(1) acl_drop(standard_metadata);
@proto_id(1) acl_drop(local_metadata);
@defaultonly NoAction;
}
const default_action = NoAction;
Expand Down Expand Up @@ -167,6 +167,10 @@ control acl_egress(in headers_t headers,
acl_egress_table.apply();
acl_egress_dhcp_to_host_table.apply();
#endif
// Act on ACL drop metadata.
if (local_metadata.acl_drop) {
mark_to_drop(standard_metadata);
}
}
}
} // control ACL_EGRESS
Expand Down
20 changes: 9 additions & 11 deletions sai_p4/instantiations/google/acl_ingress.p4
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ control acl_ingress(in headers_t headers,
#endif
action acl_trap(@sai_action_param(QOS_QUEUE) @id(1) qos_queue_t qos_queue) {
acl_copy(qos_queue);
mark_to_drop(standard_metadata);
// TODO: Use `acl_drop(local_metadata)` instead when supported
// in P4-Symbolic.
local_metadata.acl_drop = true;
}

// Forward the packet normally (i.e., perform no action). This is useful as
Expand Down Expand Up @@ -184,7 +186,9 @@ control acl_ingress(in headers_t headers,
@sai_action(SAI_PACKET_ACTION_DENY)
action acl_deny() {
cancel_copy = true;
mark_to_drop(standard_metadata);
// TODO: Use `acl_drop(local_metadata)` instead when supported
// in P4-Symbolic.
local_metadata.acl_drop = true;
}

@p4runtime_role(P4RUNTIME_ROLE_SDN_CONTROLLER)
Expand Down Expand Up @@ -295,7 +299,7 @@ control acl_ingress(in headers_t headers,
@proto_id(2) acl_trap();
@proto_id(3) acl_forward();
@proto_id(4) acl_mirror();
@proto_id(5) acl_drop(standard_metadata);
@proto_id(5) acl_drop(local_metadata);
@defaultonly NoAction;
}
const default_action = NoAction;
Expand Down Expand Up @@ -378,7 +382,7 @@ control acl_ingress(in headers_t headers,
@proto_id(1) set_qos_queue_and_cancel_copy_above_rate_limit();
@proto_id(2) set_cpu_queue_and_deny_above_rate_limit();
@proto_id(3) acl_forward();
@proto_id(4) acl_drop(standard_metadata);
@proto_id(4) acl_drop(local_metadata);
@proto_id(5) set_cpu_queue();
@proto_id(6)
set_cpu_and_multicast_queues_and_deny_above_rate_limit();
Expand Down Expand Up @@ -585,7 +589,7 @@ control acl_ingress(in headers_t headers,
}
actions = {
@proto_id(1) acl_forward();
@proto_id(2) acl_drop(standard_metadata);
@proto_id(2) acl_drop(local_metadata);
@proto_id(3) acl_deny();
@defaultonly NoAction;
}
Expand All @@ -607,12 +611,6 @@ control acl_ingress(in headers_t headers,
ip_protocol = headers.ipv6.next_header;
}

// If a packet gets punted, this adds relevant metadata to it. Must happen
// here, rather than below, since `standard_metadata` can change based on
// actions taken in the various tables.
local_metadata.packet_in_target_egress_port = standard_metadata.egress_spec;
local_metadata.packet_in_ingress_port = standard_metadata.ingress_port;

#if defined(SAI_INSTANTIATION_MIDDLEBLOCK)
acl_ingress_table.apply();
acl_ingress_security_table.apply();
Expand Down
5 changes: 3 additions & 2 deletions sai_p4/instantiations/google/fabric_border_router.p4
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ control ingress(inout headers_t headers,
tunnel_termination_decap.apply(headers, local_metadata);
admit_google_system_mac.apply(headers, local_metadata);
l3_admit.apply(headers, local_metadata, standard_metadata);
routing.apply(headers, local_metadata, standard_metadata);
drop_martians.apply(headers, local_metadata, standard_metadata);
routing_lookup.apply(headers, local_metadata, standard_metadata);
acl_ingress.apply(headers, local_metadata, standard_metadata);
routing_resolution.apply(headers, local_metadata, standard_metadata);
mirror_session_lookup.apply(headers, local_metadata, standard_metadata);
ingress_cloning.apply(headers, local_metadata, standard_metadata);
drop_martians.apply(headers, local_metadata, standard_metadata);
}
}
} // control ingress
Expand Down
Loading

0 comments on commit e03cbe1

Please sign in to comment.