Knowledge

P4 (programming language)

Source đź“ť

66: 128: 25: 539:
between the control and data planes. Instead, P4 uses the concept of tables to represent forwarding plane state. An interface between the control plane and the various P4 tables must be provided to allow the control plane to inject/modify state in the program. This interface is generally referred to as the
552:
device, and/or increment a counter. Tables and their associated actions are almost always chained together in sequence to realize the full packet forwarding logic, although in the abstract it is possible to build a single table that includes all the lookup key information and the full output action set.
504:
The P4 parser is a finite state machine that walks an incoming byte-stream and extracts headers based on the programmed parse graph. A simple example would be a parser that extracts the Ethernet source and destination and type fields, then performs a further extraction based on the value in the type
551:
P4 tables contain the state used to forward packets. Tables are composed of lookup keys and a corresponding set of actions and their parameters. A trivial example might be to store a set of destination MAC addresses as the lookup keys, and the corresponding action could set the output port on the
428:
that maps the P4 source code into a target switch model. The compiler may be embedded in the target device, an externally running software, or even a cloud service. As many of the initial targets for P4 programs were used for simple packet switching it is very common to hear the term "P4 switch"
538:
and generally consist of things such as copying byte fields from one location to another based on the lookup results on learned forwarding state. P4 addresses only the data plane of a packet forwarding device. It does not specify the control plane nor any exact protocol for communicating state
453:
Protocol independence and the abstract language model allow for reconfigurability–P4 targets should be able to change the way they process packets (perhaps multiple times) after they are deployed. This capability is traditionally associated with forwarding planes built on
490:
Header definitions describe packet formats and provide names for the fields within the packet. The language allows customized header names and fields of arbitrary length, although many header definitions use widely known protocol names and fields widths. For example, an
466:. Although within the language there is nothing to prevent a given target from optimizing around a certain set of protocols, these optimizations are invisible to the language author and may ultimately reduce the system's flexibility and reconfigurability goals. 572:
field by one" or "copy the MAC address from the output port table into the outgoing packet header." P4 defines both standard metadata that must be provided by all targets as well as target-specific metadata, which is provided by the author of specific targets.
495:
Ethernet header definition might be called “Ethernet” and consist of a 48-bit field named “dest” followed by a 48-bit “src” field, followed by a 16-bit “type” field. The names in a header definition are used later in the P4 program to reference these fields.
567:
manipulations. In P4 context, metadata is information about a packet that is not directly derived from the parser, such as the input interface that the frame arrived on. English descriptions of an example action might be "decrement the IPv4
403:
As the language is specifically targeted at packet forwarding applications, the list of requirements or design choices is somewhat specific to those use cases. The language is designed to meet several goals:
445:. Instead, the P4 programmer describes the header formats and field names of the required protocols in the program, which are in turn interpreted and processed by the compiled program and target device. 521:
The primary component of a P4 program is a set of user-defined match action tables. P4 treats all match action tables as generic, leaving the user to add their match-action rules via the control plane.
482:
P4 allows the specification of custom packet header parsing logic including but not limited to parsing typical headers used in the TCP/IP protocol suite and application specific headers.
534:. Conceptually, forwarding network packets or frames can be broken down into a series of table lookups and corresponding header manipulations. In P4 these manipulations are known as 161: 412:
P4 programs are designed to be implementation-independent: they can be compiled against many different types of execution machines such as general-purpose CPUs,
391:
paper titled “Programming Protocol-Independent Packet Processors”—the alliterative name shortens to "P4". The first P4 workshop took place in June 2015 at
38: 463: 758: 623:
P. Bosshart; D. Daly; G. Gibb; M. Izzard; N. McKeown; J. Rexford; C. Schlesinger; D. Talayco; A. Vahdat; G. Varghese; D. Walker (July 2014).
395:. An updated specification of P4, called P4-16, was released between 2016 and 2017, replacing P4-14, the original specification of P4. 582: 197: 179: 109: 87: 52: 437:
P4 is designed to be protocol-independent: the language has no native support for even common protocols such as IP, Ethernet, TCP,
369: 455: 147: 372:
code, and is maintained by the P4 Project (formerly the P4 Language Consortium), a not-for-profit organization hosted by the
44: 629: 442: 413: 385: 353: 753: 270: 373: 241: 357: 349: 225: 157: 80: 74: 143: 138: 438: 229: 91: 348:
in networking devices, such as routers and switches. In contrast to a general purpose language such as
365: 338: 216: 392: 309: 236: 459: 361: 221: 417: 345: 296: 513:
P4 allows the programmer to maintain state in the form of registers, counters and meters.
342: 301: 747: 569: 581:
The control flow in P4 determines the relative sequence of tables, and allows for
420:, network processors, and ASICs. These different types of machines are known as 651: 602: 127: 492: 564: 425: 624: 121: 59: 18: 684: 625:"P4: Programming Protocol-Independent Packet Processors" 429:
used, even though "P4 target" is more formally correct.
153: 709: 474:
P4 programs typically have the following components:
505:
field (common values might be ipv4, ipv6, or MPLS).
318: 308: 295: 269: 247: 235: 215: 323: 736: 424:, and each target must be provided along with a 142:, potentially preventing the article from being 16:Language for controlling network data forwarding 585:of tables based on if/then/else constructions. 8: 210: 53:Learn how and when to remove these messages 360:with a number of constructs optimized for 209: 162:reliable, independent, third-party sources 198:Learn how and when to remove this message 180:Learn how and when to remove this message 110:Learn how and when to remove this message 603:"P4 Language and Related Specifications" 156:by replacing them with more appropriate 73:This article includes a list of general 679: 677: 675: 673: 594: 139:too closely associated with the subject 384:P4 was originally described in a 2014 7: 530:Fundamental to P4 is the concept of 276:version 1.2.2 / May 2021 79:it lacks sufficient corresponding 14: 462:, rather than the fixed function 34:This article has multiple issues. 563:in P4 describe packet field and 137:may rely excessively on sources 126: 64: 23: 42:or discuss these issues on the 1: 759:C programming language family 630:Computer Communication Review 517:Generic match action tables 253:; 11 years ago 775: 374:Open Networking Foundation 278:; 3 years ago 242:Open Networking Foundation 291: 265: 364:. P4 is distributed as 358:domain-specific language 526:Match-action processing 362:network data forwarding 94:more precise citations. 532:match-action pipelines 583:conditional execution 433:Protocol independence 370:permissively licensed 456:general-purpose CPUs 339:programming language 754:Computer networking 689:P4 Official Website 656:P4 Official Website 509:Stateful processing 408:Target independence 393:Stanford University 310:Filename extensions 248:First appeared 212: 710:"P4 Mailing Lists" 460:network processors 652:"1st P4 Workshop" 449:Reconfigurability 418:system(s)-on-chip 346:forwarding planes 332: 331: 208: 207: 200: 190: 189: 182: 120: 119: 112: 57: 766: 740: 739: 737:Official website 722: 721: 719: 717: 706: 700: 699: 697: 695: 685:"Specifications" 681: 668: 667: 665: 663: 648: 642: 641: 639: 637: 620: 614: 613: 611: 609: 599: 341:for controlling 328: 325: 286: 284: 279: 261: 259: 254: 213: 203: 196: 185: 178: 174: 171: 165: 130: 122: 115: 108: 104: 101: 95: 90:this article by 81:inline citations 68: 67: 60: 49: 27: 26: 19: 774: 773: 769: 768: 767: 765: 764: 763: 744: 743: 735: 734: 731: 726: 725: 715: 713: 708: 707: 703: 693: 691: 683: 682: 671: 661: 659: 650: 649: 645: 635: 633: 622: 621: 617: 607: 605: 601: 600: 596: 591: 579: 558: 549: 528: 519: 511: 502: 488: 480: 472: 451: 435: 410: 401: 382: 322: 287: 282: 280: 277: 257: 255: 252: 226:domain-specific 204: 193: 192: 191: 186: 175: 169: 166: 151: 131: 116: 105: 99: 96: 86:Please help to 85: 69: 65: 28: 24: 17: 12: 11: 5: 772: 770: 762: 761: 756: 746: 745: 742: 741: 730: 729:External links 727: 724: 723: 701: 669: 643: 615: 593: 592: 590: 587: 578: 575: 557: 554: 548: 545: 527: 524: 518: 515: 510: 507: 501: 498: 487: 484: 479: 476: 471: 468: 450: 447: 434: 431: 409: 406: 400: 397: 381: 378: 330: 329: 320: 316: 315: 312: 306: 305: 299: 293: 292: 289: 288: 275: 273: 271:Stable release 267: 266: 263: 262: 249: 245: 244: 239: 233: 232: 219: 206: 205: 188: 187: 134: 132: 125: 118: 117: 72: 70: 63: 58: 32: 31: 29: 22: 15: 13: 10: 9: 6: 4: 3: 2: 771: 760: 757: 755: 752: 751: 749: 738: 733: 732: 728: 711: 705: 702: 690: 686: 680: 678: 676: 674: 670: 658:. 4 June 2015 657: 653: 647: 644: 632: 631: 626: 619: 616: 604: 598: 595: 588: 586: 584: 576: 574: 571: 566: 562: 555: 553: 546: 544: 542: 537: 533: 525: 523: 516: 514: 508: 506: 499: 497: 494: 485: 483: 478:Parsing logic 477: 475: 469: 467: 465: 461: 457: 448: 446: 444: 440: 432: 430: 427: 423: 419: 415: 407: 405: 398: 396: 394: 390: 389: 379: 377: 375: 371: 367: 363: 359: 355: 351: 347: 344: 340: 336: 327: 321: 317: 313: 311: 307: 303: 300: 298: 294: 290: 274: 272: 268: 264: 250: 246: 243: 240: 238: 234: 231: 227: 223: 220: 218: 214: 202: 199: 184: 181: 173: 163: 159: 155: 149: 145: 141: 140: 135:This article 133: 129: 124: 123: 114: 111: 103: 93: 89: 83: 82: 76: 71: 62: 61: 56: 54: 47: 46: 41: 40: 35: 30: 21: 20: 714:. Retrieved 704: 692:. Retrieved 688: 660:. Retrieved 655: 646: 634:. Retrieved 628: 618: 606:. Retrieved 597: 580: 577:Control flow 560: 559: 550: 540: 535: 531: 529: 520: 512: 503: 489: 481: 473: 452: 436: 421: 411: 402: 387: 383: 334: 333: 194: 176: 167: 152:Please help 136: 106: 97: 78: 50: 43: 37: 36:Please help 33: 712:. July 2015 541:program API 366:open-source 92:introducing 748:Categories 589:References 470:Components 422:P4 targets 356:, P4 is a 230:imperative 154:improve it 144:verifiable 75:references 39:improve it 237:Developer 170:July 2019 158:citations 45:talk page 662:1 August 565:metadata 426:compiler 386:SIGCOMM 222:compiled 217:Paradigm 100:May 2015 716:15 July 636:7 April 561:Actions 556:Actions 536:actions 500:Parsers 486:Headers 380:History 319:Website 297:License 283:2021-05 281: ( 256: ( 148:neutral 88:improve 694:7 June 608:7 June 547:Tables 399:Design 354:Python 343:packet 304:-style 302:Apache 77:, but 493:802.3 464:ASICs 441:, or 439:VxLAN 414:FPGAs 337:is a 718:2015 696:2022 664:2019 638:2015 610:2022 443:MPLS 326:.org 258:2013 251:2013 146:and 570:TTL 458:or 388:CCR 352:or 314:.p4 160:to 750:: 687:. 672:^ 654:. 627:. 543:. 416:, 376:. 368:, 335:P4 324:p4 228:, 224:, 211:P4 48:. 720:. 698:. 666:. 640:. 612:. 350:C 285:) 260:) 201:) 195:( 183:) 177:( 172:) 168:( 164:. 150:. 113:) 107:( 102:) 98:( 84:. 55:) 51:(

Index

improve it
talk page
Learn how and when to remove these messages
references
inline citations
improve
introducing
Learn how and when to remove this message

too closely associated with the subject
verifiable
neutral
improve it
citations
reliable, independent, third-party sources
Learn how and when to remove this message
Learn how and when to remove this message
Paradigm
compiled
domain-specific
imperative
Developer
Open Networking Foundation
Stable release
License
Apache
Filename extensions
p4.org
programming language
packet

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

↑