p4 spec v1.1 (1185620), страница 2
Текст из файла (страница 2)
Once configured, tables maybe populated and packet processing takes place. These post-configuration operationsare referred to as "run time" in this document. This does not preclude updating a forwarding element’s configuration while it is running.1.1 The P4 Abstract ModelThe following diagram shows a high level representation of the P4 abstract model.The P4 machine operates with only a few simple rules.• For each packet, the parser produces a Parsed Representation on which match+action tables operate.• The match+action tables in the Ingress Pipeline generate an Egress Specificationwhich determines the set of ports (and number of packet instances for each port)to which the packet will be sent.• The Queuing Mechanism processes this Egress Specification, generates the necessary instances of the packet and submits each to the Egress Pipeline. Egress51.1 The P4 Abstract Model1 INTRODUCTIONFigure 1: Abstract Forwarding Modelqueuing may buffer packets when there is over-subscription for an output port,although this is not mandated by P4.• A packet instance’s physical destination is determined before entering the EgressPipeline.
Once it is in the Egress Pipeline, this destination is assumed not tochange (though the packet may be dropped or its headers further modified).• After all processing by the Egress Pipeline is complete, the packet instance’s headeris formed from the Parsed Representation (as modified by match+action processing) and the resulting packet is transmitted.Although not shown in this diagram, P4 supports recirculation and cloning of packets.This is described in detail in Section 15.P4 focuses on the specification of the parser, match+action tables, and the control flowthrough the pipelines. Programmers control this by writing a P4 program which specifies the switch configuration as shown at the top of Figure 1.A packet-processing machine that can be programmed in P4 is called a target. Althougha target may directly execute a P4 program, it is assumed in this document that theprogram is compiled into a suitable configuration for the target.In the current version, P4 does not expose, for example, the functionality of the Queu61.2 The mTag Example1 INTRODUCTIONing Mechanism and does not specify the semantics of the Egress Specification beyondwhat is mentioned above.
Currently they are defined in target specific input to thecompiler and exposed in conjunction with other interfaces that provide run time system management and configuration. Future versions of P4 may expose configurationof these mechanisms allowing consistent management of such resources from the P4program.1.2 The mTag ExampleThe original P4 paper [1] includes an example called mTag. We use this example throughout this specification as a means of explaining the basic language features as they arepresented.
Complete source for this example, including sample run time APIs, is available at the P4 web site [2].We give an overview of the mTag example here. Quoting from the original paper:Consider an example L2 network deployment with top-of-rack (ToR) switchesat the edge connected by a two-tier core. We will assume the number ofend-hosts is growing and the core L2 tables are overflowing. . . . P4 lets usexpress a custom solution with minimal changes to the network architecture. . . . The routes through the core are encoded by a 32-bit tag composedof four single-byte fields. The 32-bit tag can carry a "source route".... Eachcore switch need only examine one byte of the tag and switch on that information.
[1]Two P4 programs are defined for this example: One for edge switches (called "ToR"above) and one for aggregation switches (called "core switches" above). These two programs share definitions for packet headers, the parser and actions.1.3 Specification ConventionsThis document represents P4 grammatical constructs using BNF with the followingconventions:• The BNF is presented in green boxes.• Non-terminal nodes are indicated with bold.• A node with a name ending in _name is implicitly a string whose first character isa letter (not a digit).• Nodes followed by + indicate one or more instances.• Nodes followed by * indicate zero or more instances.• A vertical bar, |, separates options from which exactly one must be selected.72 STRUCTURE OF THE P4 LANGUAGE• Square brackets, [], are used to group nodes.
A group is optional unless it is followed by +. A group may be followed by * indicating zero or more instances of thegroup.• Symbols with special significance (e.g., [ ] * + |) may be used as terminal nodesby enclosing them in quotes: for example "*".• Symbols other than those listed above are literals. Examples include curly braces,colon, semi-colon, parentheses, and comma.• If a rule does not fit on one line, a new line immediately follows ::= and the description ends with a blank line.• Example P4 code appears in blue boxes• Example code in a language other than P4 appears in beige boxesHeader types and table definitions are specified declaratively. These typically consist ofa set of attribute/value pairs separated by a colon.Parsers, actions and control flow are specified imperatively with typed parameters (ifany) and a limited set of operations.2Structure of the P4 Language2.1 AbstractionsP4 provides the following top-level abstractions:• Base types: Integers and bitstrings with arbitrary widths.• Headers:– Header types: A specification of fields within a header.– Header instances: A specific instance of a packet header or metadata.• Parser state function: Defines how headers are identified within a packet.• Action function: A composition of primitive actions that are to be applied together.• Table instance: Specified by the fields to match and the permitted actions.• Control flow function: Imperative description of the table application order.• Stateful memories: Counters, meters and registers which persist across packets.• Extern:82.2 Value Specifications2 STRUCTURE OF THE P4 LANGUAGE– Extern types: An object type provided by a standard library or target providerwhich can perform functionality not otherwise expressible in P4.– Extern instances: A specific instance of an extern type.In addition to these high level abstractions, the following are used• For a header instance:– Metadata: Per-packet state which may not be derived from packet data.Otherwise treated the same as a packet header.– Header stack: a contiguous array of header instances.– Dependent fields: Fields whose values depend on a calculation applied toother fields or constants.• For a parser:– Value set: run-time updatable values used to determine parse state transitions.– Checksum calculations: The ability to apply a function to a set of bytes fromthe packet and test that a field matches the calculation.2.2 Value SpecificationsP4 supports generic and bit-width specific values.
These are unified through the following representation.const_value ::=bool_value |[ "+" | - ] [ width_spec ] unsigned_valueunsigned_value ::=binary_value |decimal_value |hexadecimal_valuebool_value ::= true | falsebinary_value ::=binary_base binary_digit+decimal_value ::= decimal_digit+hexadecimal_value ::= hexadecimal_base hexadecimal_digit+binary_base ::= 0b | 0Bhexadecimal_base ::= 0x | 0X92.2 Value Specifications2 STRUCTURE OF THE P4 LANGUAGEbinary_digit ::= _ | 0 | 1decimal_digit ::= binary_digit | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9hexadecimal_digit ::=decimal_digit | a | A | b | B | c | C | d | D | e | E | f | Fwidth_spec ::=decimal_digit+ w |decimal_digit+ sfield_value ::= const_valueThe width specification is followed by a letter w or s depending on the sign of the value.The width must be specified in decimal.Note that constants always start with a digit to distinguish them from other identifiers.The node const_value may be read as ’constant value’.
The node field_value is usedin this specification to emphasize that the width of the representation may be relevant;otherwise it is a synonym for const_value.Whitespace terminates a constant specification.Underscores are permitted in values to add clarity by grouping digits; they are ignoredotherwise. Examples include: 78_256_803 (replacing commas in decimal representation) or 0b1101_1110_0101 (grouping bits into nibbles or bytes in binary representation).Negative numbers are represented in two’s complement. See Section 2.4 for the P4 typing rules.Here are some example values.Notation4216w420b10101012w0x1007w0b1-0B101Decimal Value4242Bit Width616422566121-574NotesDefault base is decimalThe same value, but explicitly given a widthof 16 bits.Binary representation of 42Example of bit width and hexadecimal baseindication.Binary value specified with explicit widthTable 1: Value Representation Examples102.3 Types and declarations2 STRUCTURE OF THE P4 LANGUAGE2.3 Types and declarationsA P4 program consists of concrete declarations of the abstractions listed in Section 2.1.Object declarations occur at the top-level of the program; declarations cannot happenconditionally, such as inside a specific parse state or branch of a control flow.