p4 spec v1.1 (1185620), страница 13
Текст из файла (страница 13)
A table with thematch type index can still lead to a miss if the table is not fully populated or theindex is out of range. For a table with the index match type, targets may or maynot support a default action even upon a miss.7213 PACKET PROCESSING AND CONTROL FLOW• The min_size attribute indicates the minimum number of entries required for thetable. If this cannot be supported, an error will be signaled when the declarationis processed.• The max_size attribute is an indication that the table is not expected to growlarger than this size. If, at run time, the table has this many entries and anotherinsert operation applied, it may be rejected.• The size attribute is equivalent to specifying min_size and max_size with thesame value.• Although size and min_size are optional, failing to specify at least one of themmay result in the table being eliminated as the compiler attempts to satisfy theother requirements of the program.• The support_timeout attribute is used to enable ageing on a table.
It is optionaland its default value is false.A no-op primitive action, no_op, is defined in P4 in Section 10.1. It may be used toindicate that a match should result in no change to the packet.13Packet Processing and Control FlowA packet is processed by a sequence of match+action tables. At configuration time,the control flow (in what order the tables are to be applied) may be expressed with animperative program. The imperative program may apply tables, call other control flowfunctions or test conditions.The execution of a table is indicated with the apply instruction. The apply instructionitself can affect the control flow to which the packet is subject by specifying a set ofcontrol blocks from which one is selected to be executed.
The choice of which block isselected may be determined by the action used on the packet or by whether a matchwas found at all.The apply instruction has three modes of operation.• Sequential: Control flow moves to the next statement unconditionally.• Action Selection: The action that was applied to the packet determines the blockof instructions to execute.• Hit/Miss Check: Whether or not a match was found determines the block of instructions to execute.Examples of each mode are given below, following the BNF. In conjunction with theif-else statement, this provides the mechanism for expressing control flow.7313 PACKET PROCESSING AND CONTROL FLOWcontrol_function_declaration ::=control control_fn_name control_blockcontrol_block ::= { control_statement * }control_statement ::=apply_call |apply_and_select_block |extern_method_call ; |if_else_statement |control_fn_name ( ) ; |return ;apply_call ::= apply ( table_name ) ;apply_and_select_block ::= apply ( table_name ) { [ case_list ] }case_list ::= action_case + | hit_miss_case +action_case ::= action_or_default control_blockaction_or_default ::= action_name | defaulthit_miss_case ::= hit_or_miss control_blockhit_or_miss ::= hit | missif_else_statement ::=if ( bool_expr ) control_block[ else_block ]else_block ::= else control_block | else if_else_statementTables are invoked on the packet with the apply operator as described at the beginningof this section.
If the same table is invoked in multiple places from the control flow,those invocations all refer to the same table instance; that is, there is only one set ofmatch+action entries for the table. Targets may impose limitations on these table invocations such as disallowing recursion, only allowing tables to be referenced once, oronly allowing control flow functions to be referenced once.Return statements are not mandated, but can be used to exit early from a control flowback to its caller.The simplest control flow is to execute a sequence of tables with the apply operator.// The ingress pipeline ’main’ control functioncontrol main {// Verify mTag state and port are consistentapply(check_mtag);apply(identify_port);7413 PACKET PROCESSING AND CONTROL FLOWapply(select_output_port);}The apply operator can be used to control the instruction flow based on whether amatch was found in the table.
This is done by specifying a block enclosed in bracesfollowing the apply operation with hit and/or miss as the case selection labels. ThemTag edge program includes the following example:// Apply egress_meter table; if hit, apply meter policyapply(egress_meter) {hit {apply(meter_policy);}}Alternatively, the apply operator can control the instruction flow based on the actionapplied by the table to the packet. Here is an example.apply(routing_table) {ipv4_route_action { // IPv4 action was usedapply(v4_rpf);apply(v4_acl);}ipv6_route_action { // IPv6 action was usedapply(v6_option_check);apply(v6_acl);}default { // Some other action was usedif (packet_metadata.ingress_port == 1) {apply(cpu_ingress_check);}}}Note that the two modes (match selection versus action selection) cannot be intermixed.
They are differentiated due to the fact that hit and miss are reserved wordsand cannot be used as action function names.7514 EGRESS PORT SELECTION, REPLICATION AND QUEUING14Egress Port Selection, Replication and QueuingIn P4, the egress_spec metadata field is used to specify the destination or destinationsof a packet. In addition, for devices supporting priority queuing, egress_spec may indicate the queue associated with each destination.
An egress_spec value may representa physical port, a logical port (e.g., a tunnel, a LAG, a route, or a VLAN flood group), ora multicast group.P4 assumes that the Buffering Mechanism implements a function that maps egress_spec to a collection of packet instances represented as triples:(packet, egress_port, egress_instance).The Buffering Mechanism is responsible for generating each packet instance along withthese metadata fields and sending it as necessary to reach its egress port through theegress match+action tables.This mapping of egress_spec values to sets of packet instances is currently outside thescope of P4; a forwarding element may statically map values to destinations or mayallow configuration of the map through a management interface.
The run time tableprograming interfaces must have access to this information to properly program thetables declared in the P4 program.The flow of packets through a forwarding element is as follows. Recall that, as depictedin Figure 1, processing is divided between ingress and egress with the packet possiblybeing buffered between the two. The parser normally terminates by indicating the control function used to begin processing. Upon completion of that control function, thepacket is submitted to the buffering system.The buffers are assumed to be organized into one or more queues per egress port. Thedetails of queue structure and dequeuing disciplines is considered to be target specific,though targets may use P4 to expose configuration (and even to define actions resultingfrom data plane events) related to queuing behavior.A single copy of each packet traverses the Ingress Pipeline.
At the completion of ingressprocessing, the switch determines the queue(s) to place the packet in based upon theegress_spec value. A packet that is sent to multiple destinations may be placed in multiple queues.When the packet is dequeued, it is processed in the Egress Pipeline by the control function egress. A separate copy of the packet is sent through the Egress Pipeline for eachdestination, requiring the Buffering Mechanism to replicate the packet.
The physicalegress port is known at the time the packet is dequeued; this value is passed through theEgress Pipeline as an immutable metadata field named egress_port. To support multiple copies of packets being sent to the same physical port (e.g., sending to multipleVLANs on one port), the immutable metadata field egress_instance contains a unique7615 RECIRCULATION AND CLONINGvalue for each copy. The semantics of egress_instance are target specific.15Recirculation and CloningMany standard networking functions, such as mirroring and recursive packet processing, require more complicated primitives than setting or testing fields. To support suchoperations, P4 provides primitive actions that allow a packet to be recirculated (sentback to the start of the processing pipeline) or cloned (a second instance of the packetis created).Note that cloning is not intended to be the mechanism by which multicast is normallyimplemented. That is expected to be done by the Buffering Mechanism in conjunctionwith the egress specification.
See Section 14.Here is a table that summarizes the different operations. The first four (clone) operations create an entirely new instance of the packet. The last two, resubmit andrecirculate, operate on the original packet and do not, by themselves, result in thegeneration of a new packet.Nameclone_ingress_pkt_to_ingressclone_egress_pkt_to_ingressclone_ingress_pkt_to_egressclone_egress_pkt_to_egressresubmitrecirculateSourceOriginal ingress pktPost deparsed pktOriginal ingress pktPost deparsed pktOriginal ingress pktPost deparsed pktInsertion PointIngress parserIngress parserBuffering MechanismBuffering MechanismIngress parserIngress parserTable 15: Clone and Recirculation Primitives15.1 CloneThe clone operations generate a new version of the packet.