Upgrade to Pro — share decks privately, control downloads, hide ads and more …

P4 Introduction

P4 Introduction

Samina (Shan Jung Fu)

April 18, 2018
Tweet

More Decks by Samina (Shan Jung Fu)

Other Decks in Technology

Transcript

  1. P4 Introduction Define your network packet forwarding on switch using

    P4 2018/04/18, Hsinchu, PyHUG Presenter: Shan-Jung Fu (Samina)
  2. • Shan-Jung Fu (Samina) ◦ National Chiao Tung University, Taiwan

    ◦ Wireless Internet Laboratory • Department of Computer Science • ITRI Intern • Was a Information Technology Service Center Network & System Engineer @ NCTU before • GitHub: @sufuf3 • Twitter: @sufuf3149 About Me 2
  3. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 3
  4. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 4
  5. What is P4 • Programming Protocol-Independent Packet Processors ◦ processors:

    eg. switches, smart NIC, etc • Web site: https://p4.org • GitHub: https://github.com/p4lang • White Paper(July 2014) 5
  6. • A high-level language • Can program the network data

    plane What is P4 (Cont’d) Ref: https://www.slideshare.net/Docker/docker-networking-control-plane-and-data-plane 6
  7. • What is P4 • Why P4 ◦ Motivation ◦

    Benefits • P4.org Membership • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 7
  8. • Network changes Motivation • Why P4 ◦ Motivation ◦

    Benefits 2014 P4: Programming Protocol-Independent Packet Processors 2008 Software Defined Networking (SDN) with OpenFlow Before 2008 Traditional Network 8
  9. • Using SDN to solve the problems of traditional network

    • The problems of traditional network are ◦ Closed equipment ▪ Software bundled with hardware ▪ Vendor-specific CLI interfaces ◦ Networks are hard to evolve ▪ Networks are stuck in the past • Routing algorithms change very slowly • Network management extremely primitive ◦ Networks design not based on formal principles ▪ Networks used to be simple • Basic Ethernet/IP straightforward ▪ New control requirements have led to complexity • ACLs, VLANs, TE, Middleboxes, DPI,… ◦ … etc. Traditional network problem • Why P4 ◦ Motivation ◦ Benefits 9
  10. • What is Software-Defined Networking(SDN) ◦ Physical separation of the

    network control plane from the forwarding plane (data plane) ◦ Control plane controls several devices ◦ The network control to become directly programmable SDN • Why P4 ◦ Motivation ◦ Benefits Ref: https://www.sdxcentral.com/sdn/definitions/inside-sdn-architecture/ 10
  11. SDN with OpenFlow • Why P4 ◦ Motivation ◦ Benefits

    Ref: http://flowgrammable.org/sdn/openflow/ https://www.opennetworking.org/images/stories/downloads/sdn-resources/onf-specifications/ope nflow/openflow-spec-v1.4.0.pdf#page=9 11
  12. • OpenFlow explicitly specifies protocol headers on which it operates.

    This set has grown from 12 to 41 fields in a few years, increasing the complexity of the specification while still not providing the flexibility to add new headers. Using P4 to solve Openflow problems • Why P4 ◦ Motivation ◦ Benefits Versio n Date Header Fields OF 1.0 Dec 2009 12 fields (Ethernet, TCP/IPv4) OF 1.1 Feb 2011 15 fields (MPLS, inter-table metadata) OF 1.2 Dec 2011 36 fields (ARP, ICMP, IPv6, etc.) OF 1.3 Jun 2012 40 fields OF 1.4 Oct 2013 41 fields Ref: https://www.sigcomm.org/sites/default/files/ccr/papers/2014/July/0000000-0000004.pdf 12
  13. • Reconfigurability in the field ◦ Controller can redefine the

    packet parsing & processing in the field • Protocol independence ◦ Switches should not be tied to any specific network protocols. ◦ Controller should be able to specify ▪ A packet parser for extracting header fields with particular names and types ▪ A collection of typed match + action tables that process these headers • Target independence ◦ Programmers should be able to describe packet-processing functionality independently of the specifics of the underlying hardware. The goals of P4 • Why P4 ◦ Motivation ◦ Benefits Ref: https://www.sigcomm.org/sites/default/files/ccr/papers/2014/July/0000000-0000004.pdf 13
  14. Compared to state-of-the-art packet-processing systems • Flexibility • Expressiveness •

    Resource mapping and management • Software engineering • Component libraries • Decoupling hardware and software evolution • Debugging Benefits of P4 • Why P4 ◦ Motivation ◦ Benefits Ref: https://p4.org/p4-spec/docs/P4-16-v1.0.0-spec.html#sec-benefits-of-p4 14
  15. Benefits of Data Plane Programmability • New Features - Add

    new protocols • Reduce complexity - Remove unused protocols • Efficient use of resources - flexible use of tables • Greater visibility - New diagnostic techniques, telemetry, etc. • Software style development - rapid design cycle, fast innovation, fix data plane bugs in the field • You keep your own ideas Think programming rather than protocols... Benefits of P4 (Cont’d) • Why P4 ◦ Motivation ◦ Benefits Ref: https://p4.org/assets/P4_tutorial_01_basics.gslide.pdf 15
  16. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 16
  17. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 18
  18. • Headers ◦ Describes the sequence & structure of a

    series of fields • Parsers ◦ Specifies how to identify headers & valid header sequences within packets • Tables (match + action tables) ◦ The mechanism for performing packet processing • Actions ◦ P4 supports construction of complex actions from simpler protocol-independent primitives. These complex actions are available within match + action tables. • Control Program ◦ Determines the order of tables that are applied to a packet. A simple imperative program describe the flow of control between match + action tables Key Components of P4 19
  19. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language ◦ Program Template ◦ Approach ▪ Target ▪ Architecture • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 20
  20. P4 16 Program Template • P4 16 Language ◦ Program

    Template ◦ Approach ▪ Target ▪ Architecture Ref: https://p4.org/assets/P4_tutorial_01_basics.gslide.pdf 21
  21. P4 16 Approach • • P4 16 Language ◦ Program

    Template ◦ Approach ▪ Target ▪ Architecture Ref: https://p4.org/assets/P4_tutorial_01_basics.gslide.pdf Term Explanation P4 Target An embodiment of a specific hardware implementation P4 Architecture Provides an interface to program a target via some set of P4-programmable components, externs, fixed components 22
  22. Programming a P4 Target • • P4 16 Language ◦

    Program Template ◦ Approach ▪ Target ▪ Architecture Ref: https://p4.org/assets/P4_tutorial_01_basics.gslide.pdf 23
  23. P4 16 Architecature • P4 16 Language ◦ Program Template

    ◦ Approach ▪ Target ▪ Architecture • Ingress Pipeline • Egress Pipeline • Traffic Manager ◦ N:1 Relationships: Package Queueing, Congestion Control ◦ 1:N Relationships: Replication ◦ Scheduling Ref: https://p4.org/assets/P4_tutorial_01_basics.gslide.pdf https://github.com/NetFPGA/P4-NetFPGA-public/blob/master/slides/FPGA-2018/FPGA%202018%20P4%20tut orial.pdf 24
  24. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code ◦ Topology ◦ Source code ◦ Explain • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 25
  25. Basic Forwarding: Topology • For every packet, the L3 switch

    must perform: ◦ Update the source and destination MAC addresses ◦ Decrement the time-to-live (TTL) in the IP header ◦ Forward the packet out the appropriate port • Topology • Source code • Explain 26 • Have a single table: the control plane will populate with static rules • Each rule will map an IP address to the MAC address and output port for the next hop • Already defined the control plane rules
  26. Basic Forwarding: Source code • Code: https://github.com/p4lang/tutorials/blob/master/P4D2_2018 _East/exercises/basic/solution/basic.p4 • Ref:

    https://p4.org/assets/P4_tutorial_01_basics.gslide.pdf • Topology • Source code • Explain 27
  27. Explain • Some Elements • Headers • Parser • Controls

    ◦ Checksum Verification ◦ Ingress Processing ◦ Egress Processing ◦ Checksum Computation ◦ Deparser • Switch • Topology • Source code • Explain 28
  28. • Some Elements • Headers • Parser • Controls ◦

    Checksum Verification ◦ Ingress Processing ◦ Egress Processing ◦ Checksum Computation ◦ Deparser • Switch Explain • Topology • Source code • Explain 29
  29. • Include P4 core library ◦ Defines some standard data-types

    and error codes ◦ https://p4.org/p4-spec/docs/P4-16-v1.0.0-spec.html#sec-p4-core-lib • https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/ basic/solution/basic.p4#L2-L5 Ref: https://en.wikipedia.org/wiki/EtherType Some Elements #include <core.p4> #include <v1model.p4> const bit<16> TYPE_IPV4 = 0x800; 30
  30. • Some Elements • Headers • Parser • Controls ◦

    Checksum Verification ◦ Ingress Processing ◦ Egress Processing ◦ Checksum Computation ◦ Deparser • Switch Explain • Topology • Source code • Explain 31
  31. Headers typedef bit<9> egressSpec_t; typedef bit<48> macAddr_t; typedef bit<32> ip4Addr_t;

    header ethernet_t { macAddr_t dstAddr; macAddr_t srcAddr; bit<16> etherType; } • Typedef ◦ Alternative name for a type • Basic Types ◦ bit<n> ◦ bit == bit<1> ◦ int<n> ◦ varbit<n> • Header Types ◦ Ordered collection of members https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/basic/s olution/basic.p4#L11-L19 32
  32. Headers (Cont’d) header ipv4_t { bit<4> version; bit<4> ihl; bit<8>

    diffserv; bit<16> totalLen; bit<16> identification; bit<3> flags; bit<13> fragOffset; bit<8> ttl; bit<8> protocol; bit<16> hdrChecksum; ip4Addr_t srcAddr; ip4Addr_t dstAddr; } https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/basic/s olution/basic.p4#L21-L34 33
  33. • Other useful types • Struct ◦ Unordered collection of

    members (with no alignment restrictions) • Header Stack ◦ array of headers • Header Union ◦ one of several headers Headers (Cont’d) struct metadata { /* empty */ } struct headers { ethernet_t ethernet; ipv4_t ipv4; } https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/basic/s olution/basic.p4#L36-L43 34
  34. • Some Elements • Headers • Parser • Controls ◦

    Checksum Verification ◦ Ingress Processing ◦ Egress Processing ◦ Checksum Computation ◦ Deparser • Switch Explain • Topology • Source code • Explain 35
  35. Parser parser MyParser(packet_in packet, out headers hdr, inout metadata meta,

    inout standard_metadata_t standard_metadata) { state start { transition parse_ethernet; } state parse_ethernet { packet.extract(hdr.ethernet); transition select(hdr.ethernet.etherType) { TYPE_IPV4: parse_ipv4; default: accept; } } state parse_ipv4 { packet.extract(hdr.ipv4); transition accept; } } https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/basic/s olution/basic.p4#L49-L71 36
  36. parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout

    standard_metadata_t standard_metadata) { state start { transition parse_ethernet; } state parse_ethernet { packet.extract(hdr.ethernet); transition select(hdr.ethernet.etherType) { TYPE_IPV4: parse_ipv4; default: accept; } } state parse_ipv4 { packet.extract(hdr.ipv4); transition accept; } } Parser (Cont’d) Parsers are functions that map packets into headers and metadata, written in a state machine style • packet_in: reads its input from a packet_in • in: read-only • out: are treated as a storage • inout: both in & out 37
  37. parser MyParser(packet_in packet, out headers hdr, inout metadata meta, inout

    standard_metadata_t standard_metadata) { state start { transition parse_ethernet; } state parse_ethernet { packet.extract(hdr.ethernet); transition select(hdr.ethernet.etherType) { TYPE_IPV4: parse_ipv4; default: accept; } } state parse_ipv4 { packet.extract(hdr.ipv4); transition accept; } } Every parser has three predefined states • start • accept • reject Parser (Cont’d) select statement that can be used to branch in a parser 38
  38. • Some Elements • Headers • Parser • Controls ◦

    Checksum Verification (CV) ◦ Ingress Processing ◦ Egress Processing ◦ Checksum Computation (CC) ◦ Deparser • Switch Explain • Topology • Source code • Explain 39
  39. • Similar to C functions (without loops) • Can declare

    variables, create tables, instantiate externs, etc. • Functionality specified by code in apply statement • Represent all kinds of processing that are expressible as DAG(Directed Acyclic Graph): ◦ Additional forms of packet processing (updating checksums) ◦ Match-Action Pipelines ◦ Deparsers Controls control MyVerifyChecksum(inout headers hdr, inout metadata meta) { apply { } } Evaluating a program that has several instantiations of the same component. parameters of control • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 40
  40. Controls (Cont’d) • The control instances enclose controllable entities: ◦

    actions ◦ tables ◦ keys ◦ extern instances • Control flow control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { action drop() { ... } action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) { standard_metadata.egress_spec = port; hdr.ethernet.srcAddr = hdr.ethernet.dstAddr; hdr.ethernet.dstAddr = dstAddr; hdr.ipv4.ttl = hdr.ipv4.ttl - 1; } table ipv4_lpm { ... } apply { //bosy of the pipeline if (hdr.ipv4.isValid()) { ipv4_lpm.apply(); } } } • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 41
  41. • After the switch parse headers’ value, the switch needs

    to do something to update some of the headers’ value. • How does the switch update the headers’ value? 1. Write some logical program to deal with them ▪ Action function 2. Does the actions according to the rules which are sent from the SDN controller ▪ Table function Controls (Cont’d) • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 42
  42. Controls (Cont’d) • Actions ◦ Very similar to C functions

    ◦ Reside in tables; invoked automatically on table match. ◦ Can be declared inside a control or globally ◦ Parameters have type and direction ◦ Variables can be instantiated inside ◦ Many standard arithmetic and logical operations are supported • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 43
  43. • Tables ◦ The fundamental unit of a Match-Action Pipeline

    ◦ Specifies what data to match on and match kind ◦ Specifies a list of possible actions ◦ Optionally specifies a number of table properties ▪ Size ▪ Default action ▪ Static entries ▪ etc. ◦ Each table contains one or more entries (rules) ◦ An entry contains: ▪ A specific key to match on ▪ A single action that is executed when a packet matches the entry ▪ Action data (possibly empty) Controls (Cont’d) • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 44
  44. table ipv4_lpm { key = { hdr.ipv4.dstAddr: lpm; } action

    = { ipv4_forward; drop; NoAction; } size = 1024; default_action = NoAction(); } Controls (Cont’d) Data Plane (P4) Program • Defines the format of table ◦ Key Fields ◦ Actions ◦ Action Data • Performs the lookup • Executes the chosen action Control Plane (IP stack, Routing protocols) • Populates table entries with specific information ◦ Based on the configuration, automatic discovery, protocol calculations Tables(Cont’d) • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 45 table_add ipv4_lpm ipv4_forward 10.0.1.1/32 => 00:00:00:00:01:01 1 Longest prefix match
  45. Checksum Verification • No built-in constructs in P4 16 for

    manipulating packet checksums • You can write your checksum verification • Ref: https://p4.org/p4-spec/docs/P4-16-v1.0.0-spec.html#sec-checksums control MyVerifyChecksum(inout headers hdr, inout metadata meta) { apply { } } https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/basic/s olution/basic.p4#L77-L79 • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 47
  46. Ingress Processing control MyIngress(inout headers hdr, inout metadata meta, inout

    standard_metadata_t standard_metadata) { action drop() { mark_to_drop(); } action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) { standard_metadata.egress_spec = port; hdr.ethernet.srcAddr = hdr.ethernet.dstAddr; hdr.ethernet.dstAddr = dstAddr; hdr.ipv4.ttl = hdr.ipv4.ttl - 1; } table ipv4_lpm { key = { hdr.ipv4.dstAddr: lpm; } action = { ipv4_forward; drop; NoAction; } size = 1024; default_action = NoAction(); } apply { if (hdr.ipv4.isValid()) { ipv4_lpm.apply(); } } } https://github.com/p4lang/tutorials/blob/master/P4D2_2 018_East/exercises/basic/solution/basic.p4#L86-L118 • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 48
  47. control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata)

    { apply { } } Egress Processing • Egress processing https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/basic/solution/basic.p4# L124-L128 • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 49
  48. Checksum Computation control MyComputeChecksum(inout headers hdr, inout metadata meta) {

    apply { update_checksum( hdr.ipv4.isValid(), { hdr.ipv4.version, hdr.ipv4.ihl, hdr.ipv4.diffserv, hdr.ipv4.totalLen, hdr.ipv4.identification, hdr.ipv4.flags, hdr.ipv4.fragOffset, hdr.ipv4.ttl, hdr.ipv4.protocol, hdr.ipv4.srcAddr, hdr.ipv4.dstAddr }, hdr.ipv4.hdrChecksum, HashAlgorithm.csum16); } } Computes the checksum of the supplied data https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/basic/solutio n/basic.p4#L134-L152 • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 50
  49. Deparser • Assembles the headers back into a well-formed packet

    • P4 16 does not provide a separate language for packet deparsing • Deparsing is done in a control block that has at least one parameter of type packet_out • packet_out extern is defined in core.p4: emit(hdr): serializes header if it is valid • Advantages: ◦ Makes deparsing explicit...but decouples from parsing control MyDeparser(packet_out packet, in headers hdr){ apply { packet.emit(hdr.ethernet); packet.emit(hdr.ipv4); } } https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/basic/solution/basic.p4#L1 58-L163 • Controls ◦ CV ◦ Ingress ◦ Egress ◦ CC ◦ Deparser 51
  50. Explain • Topology • Source code • Explain • Some

    Elements • Headers • Parser • Controls ◦ Checksum Verification ◦ Ingress Processing ◦ Egress Processing ◦ Checksum Computation ◦ Deparser • Switch 52
  51. • Instantiate the top-level V1Switch package • All the arguments

    of the V1Switch package constructor have been evaluated (instances of MyParser, MyVerifyChecksum ...). • Their signatures are matched w/ the V1Switch declaration • The result of the program evaluation is the value of the main variable Switch V1Switch( MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser() ) main; https://github.com/p4lang/tutorials/blob/master/P4D2_2018_East/exercises/basic/solution/basic.p4#L1 69-L176 53
  52. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 54
  53. P4 Tools & Environments • Tools ◦ P4 Compiler ◦

    P4 Runtime ◦ Packet Test Framework (PTF) ◦ P4 Container • Environments ◦ Behavioral Model (BMv2) ◦ Programmable Network Devices Ref: https://p4.org/code/ 55
  54. P4 Compiler • p4c • A new, alpha-quality reference compiler

    • Supports both P4 14 and P4 16 • Provides a standard frontend and midend which can be combined with a target-specific backend to create a complete P4 compiler • The compiler supports several backends: ◦ p4c-bmv2 – targets the behavioral model ◦ p4c-ebpf, p4c-graphs, p4test … etc. • Repository: https://github.com/p4lang/p4c Eg. $ p4c -b bmv2-ss-p4org program.p4 -o program.bmv2.json • Tools ◦ P4 Compiler ◦ P4 Runtime ◦ PTF ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices 56
  55. • Tools ◦ P4 Compiler ◦ P4 Runtime ◦ PTF

    ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices P4 Runtime • Runtime control of P4 data planes Ref: https://p4.org/api/announcing-p4runtime-a-contribution-by-the-p4-api-working-group.html 57
  56. P4 Runtime (Cont’d) Ref: https://p4.org/p4-runtime/ https://p4.org/api/p4-runtime-putting-the-control-plane-in-charge-of-the-forwarding-plane.html • Tools ◦ P4

    Compiler ◦ P4 Runtime ◦ PTF ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices • Framework for control plane software to control forwarding plane ◦ https://github.com/p4lang/PI ◦ Initial contribution by Google and Barefoot • Work-in-progress by the p4.org API WG • Protobuf-based API definition ◦ p4runtime.proto ◦ gRPC as a possible RPC transport • P4 program-independent ◦ API doesn’t change with the P4 program • Enables field-reconfigurability ◦ Ability to push new P4 program without recompiling deployed switches • A runtime API & protocol for controlling data-plane programs • Can be used for local or remote control plane 58
  57. Ref: https://github.com/p4lang/tutorials/blob/master/P4D2_2017_Fall/P4_tutorial_labs.pdf P4 Runtime (Cont’d) • P4Runtime workflow • Captures

    P4 program attributes needed at runtime ◦ IDs for tables, actions, params, etc. ◦ Table structure, action parameters, etc. • Protobuf-based format • Target-independent compiler output ◦ Same P4Info for BMv2, ASIC, etc. • Tools ◦ P4 Compiler ◦ P4 Runtime ◦ PTF ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices 59
  58. Ref: https://github.com/p4lang/tutorials/blob/master/P4D2_2017_Fall/P4_tutorial_labs.pdf P4 Runtime (Cont’d) • Can be used for

    ◦ Local control plane ◦ Remote control plane ◦ Local control plane • Tools ◦ P4 Compiler ◦ P4 Runtime ◦ PTF ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices 60
  59. Ref: https://github.com/p4lang/tutorials/blob/master/P4D2_2017_Fall/P4_tutorial_labs.pdf P4 Runtime (Cont’d) • Can be used for

    ◦ Local control plane ◦ Remote control plane ◦ • Tools ◦ P4 Compiler ◦ P4 Runtime ◦ PTF ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices 61
  60. Packet Test Framework • PTF • A Python based dataplane

    test framework • Based on unittest • Enables configuring a switch and creating tests that send, receive, and verify packets of different formats. • PTF interfaces with P4 Runtime. • Repository: https://github.com/p4lang/ptf • Tools ◦ P4 Compiler ◦ P4 Runtime ◦ PTF ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices 62
  61. P4 Container • A Docker container • pre-packaged with a

    development environment • Can compile & deploy P4 programs using simple configuration rules • Repository: https://github.com/p4lang/p4app • Tools ◦ P4 Compiler ◦ P4 Runtime ◦ PTF ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices 63
  62. Behavioral Model • aka behavioral model • nicknamed BMv2 •

    The second version of the P4 software switch • A simulation environment to run the P4 software switch, standalone or in Mininet • Allows you to easily simulate new architectures by implementing new externs • Enabling you to organize the forwarding elements as needed • Repository: https://github.com/p4lang/behavioral-model • Tools ◦ P4 Compiler ◦ P4 Runtime ◦ PTF ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices 64
  63. Programmable Network Devices • Tools ◦ P4 Compiler ◦ P4

    Runtime ◦ PTF ◦ P4 Container • Environments ◦ BMv2 ◦ Network Devices • Protocol-Independent Switch Architecture (PISA): Flexible Match+Action ASICs ◦ Intel Flexpipe, Cisco Doppler, Cavium (Xpliant), Barefoot Tofino, ... • Network Processor Unit (NPU) ◦ EZchip, Netronome, ... • CPU ◦ Open Vswitch, eBPF, DPDK, VPP... • Field-Programmable Gate Array (FPGA) ◦ Xilinx, Altera, ... Ref: https://p4.org/assets/P4_tutorial_01_basics.gslide.pdf 65
  64. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On ◦ Implementing ECN • What can you do with P4? • Conclusion • Additional Outline 66
  65. Hands-On • Let’s implement Explicit Congestion Notification (ECN) • You

    could refer to all P4 tutorials: https://github.com/p4lang/tutorials • This hands-on is ref to https://github.com/p4lang/tutorials/tree/master/P4D2_2018_ East/exercises/ecn 67
  66. Implementing ECN • What is ECN • Before Hands-on ◦

    Obtaining required software ◦ Get exercises code • Steps ◦ Run the (incomplete) starter code ◦ Implement ECN ◦ Run the solution 68
  67. What is ECN • Explicit Congestion Notification • Extend basic

    L3 forwarding • Allows end-to-end notification of network congestion without dropping packets • What is ECN • Before Hands-on ◦ Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution Ref: https://github.com/p4lang/tutorials/tree/master/P4D2_2017_Fall 69
  68. What is ECN (Cont’d) • Puts 1 or 2 value

    in the ipv4.ecn field • Each switch may change the value to 3 if the queue size is larger than a threshold • The receiver copies the value to sender, and the sender can lower the rate • What is ECN • Before Hands-on ◦ Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution • Type of Service field • DSCP(DiffServ Code Points RFC 2474) + ECN (RFC 3168) Ref: https://en.wikipedia.org/wiki/Type_of_service 70
  69. What is ECN (Cont’d) • Explicit Congestion Notification ◦ 00:

    Non ECN-Capable Transport, Non-ECT ◦ 10: ECN Capable Transport, ECT(0) ◦ 01: ECN Capable Transport, ECT(1) ◦ 11: Congestion Encountered, CE • For packets originating from ECT, ECN-capable switches set the CE bit upon congestion ◦ E.g., observed queue depth > threshold • What is ECN • Before Hands-on ◦ Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution Ref: https://github.com/p4lang/tutorials/tree/master/P4D2_2017_Fall 71
  70. • These are two ways to setup P4 Env ◦

    OS & HW requirement ▪ OS: Ubuntu 16.04 64-bits ▪ CPU: at least 2 cores ▪ RAM: at least 2G ▪ Disk: at least 25G ◦ Build your env by yourself (not root), after finish OS installation ◦ Download VM (ovf file) https://goo.gl/VQRFPt $ wget -O setup.sh https://goo.gl/EHgk4v && sudo bash setup.sh && wget -O - https://goo.gl/NKaau7 | bash Before Hands-on • What is ECN • Before Hands-on ◦ Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution Ref: https://github.com/sufuf3/p4-install-environment https://github.com/p4lang/tutorials/tree/master/P4D2_2018_East 72
  71. Run the (incomplete) starter code • Please just follow this

    README: https://github.com/p4lang/tutorials/tree/master/P4D2_2018_East/ exercises/ecn • What is ECN • Before Hands-on ◦ Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution 73
  72. Implement ECN • What is ECN • Before Hands-on ◦

    Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution header ipv4_t { bit<4>version; bit<4>ihl; bit<8>tos; bit<16> totalLen; bit<16> identification; bit<3>flags; bit<13> fragOffset; bit<8>ttl; bit<8>protocol; bit<16> hdrChecksum; ip4Addr_t srcAddr; ip4Addr_t dstAddr; } • Before bit<6> diffserv; bit<2> ecn; • After 74
  73. Implement ECN (Cont’d) • What is ECN • Before Hands-on

    ◦ Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { apply { /* * TODO: * - if ecn is 1 or 2 * - compare standard_metadata.enq_qdepth * with threshold and set hdr.ipv4.ecn to 3 if larger */ } } • Before https://github.com/p4lang/p4c/blob/master/p4include/v1model.p4#L 51 75
  74. Implement ECN (Cont’d) • What is ECN • Before Hands-on

    ◦ Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { action mark_ecn() { hdr.ipv4.ecn = 3; } apply { if (hdr.ipv4.ecn == 1 || hdr.ipv4.ecn == 2){ if (standard_metadata.enq_qdepth >= ECN_THRESHOLD){ mark_ecn(); } } } } • After 76
  75. Implement ECN (Cont’d) • What is ECN • Before Hands-on

    ◦ Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution control MyComputeChecksum(inout headers hdr, inout metadata meta) { apply { /* TODO: replace tos with diffserve and ecn */ update_checksum( hdr.ipv4.isValid(), { hdr.ipv4.version, hdr.ipv4.ihl, hdr.ipv4.tos, hdr.ipv4.totalLen, hdr.ipv4.identification, hdr.ipv4.flags, hdr.ipv4.fragOffset, hdr.ipv4.ttl, hdr.ipv4.protocol, hdr.ipv4.srcAddr, hdr.ipv4.dstAddr }, hdr.ipv4.hdrChecksum, HashAlgorithm.csum16); } } • Before hdr.ipv4.diffserv, hdr.ipv4.ecn, • After 77
  76. Run the solution • Follow the instructions from Step 1.

    • On h2 run $ ./receive.py > h2.log • $ grep tos h2.log • What is ECN • Before Hands-on ◦ Obtaining software ◦ Get code • Steps ◦ Run starter code ◦ Implement ◦ Run solution tos = 0x1 tos = 0x1 tos = 0x1 tos = 0x1 tos = 0x3 tos = 0x3 tos = 0x3 tos = 0x3 tos = 0x3 tos = 0x3 tos = 0x1 tos = 0x1 tos = 0x1 tos = 0x1 78
  77. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 79
  78. • Applications of P4 ◦ Layer 4 Load Balancer –

    SilkRoad[1] ◦ Low Latency Congestion Control – NDP[2] ◦ Fast In-Network cache for key-value stores – NetCache[3] ◦ In-band Network Telemetry – INT[4] ◦ Consensus at network speed – NetPaxos[5] ◦ ... and much more [1] Miao, Rui, et al. "SilkRoad: Making Stateful Layer-4 Load Balancing Fast and Cheap Using Switching ASICs." SIGCOMM, 2017. [2] Handley, Mark, et al. "Re-architecting datacenter networks and stacks for low latency and high performance.” SIGCOMM, 2017. [3] Xin Jin et al. “NetCache: Balancing Key-Value Stores with Fast In-Network Caching.” To appear at SOSP 2017 [4] Kim, Changhoon, et al. "In-band network telemetry via programmable dataplanes.” SIGCOMM. 2015. [5] Dang, Huynh Tu, et al. "NetPaxos: Consensus at network speed.” SIGCOMM, 2015 What can you do with P4? 80
  79. What can you do with P4? (Cont’d) • In-band Network

    Telemetry (INT) ◦ A framework ◦ Designed to allow the collection and reporting of network state, by the data plane ◦ Without requiring intervention or work by the control plane ◦ Spec: https://p4.org/assets/INT-current-spec.pdf 81
  80. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 82
  81. Conclusion • Introduce P4, its concepts, languages & some applications

    • With P4, SDN programmers can design these goals ◦ Can keep the new ideas secret ▪ Don’t have to let switch chip vendor know ◦ Unique features in every network 83
  82. • What is P4 • Why P4 • P4.org Membership

    • Key Components of P4 • P4 16 Language • Explain Basic Forwarding P4 code • P4 Tools & Environments • Hands-On • What can you do with P4? • Conclusion • Additional Outline 84
  83. Additional • Clarifying the differences between P4 and OpenFlow: https://p4.org/p4/clarifying-the-differences-between-p4-and-openflow.ht

    ml • P416 Portable Switch Architecture (PSA) Draft: https://p4.org/p4-spec/docs/PSA.html • Protocol Independent Switch Architecture (PISA): https://p4.org/assets/p4-ws-2017-p4-architectures.pdf && http://conferences.sigcomm.org/sigcomm/2013/papers/sigcomm/p99.pd f && https://www.barefootnetworks.com/resources/worlds-fastest-most-progr ammable-networks/ • Programming the Forwarding Plane: https://platformlab.stanford.edu/Presentations/Platform%20Lab%20Rev iew%202016.pdf 85
  84. Thanks for your attention! Q & A If it any

    unreasonable point, please let me know and accept my sincere apology. Thank you. • GitHub: @sufuf3 • Twitter: @sufuf3149 Facebook: SDNDS.TW