620 likes | 658 Vues
P4: specifying data planes http://P4.org. Intel – Hillsboro, OR July 10, 2018. Mihai Budiu VMware Research Group. My Background. Ph.D. from CMU (computer architecture, compilers) Microsoft Research (security, big data, machine learning) Barefoot Networks (P4 design and implementation)
E N D
P4: specifying data planeshttp://P4.org Intel – Hillsboro, ORJuly 10, 2018 Mihai Budiu VMware Research Group
My Background Ph.D. from CMU (computer architecture, compilers) Microsoft Research(security, big data, machine learning) Barefoot Networks(P4 design and implementation) VMware Research(P4, SDNs, big data) Note: I am not a networking person
My involvement with P4 Hired at to work on the design and implementation of P4 In Barefoot led the group that created the first P416 draft document Started (with Chris Dodd) the C++ reference compiler implementation Main contributor to the open-source P4 compiler front-end, mid-end and several back-ends Pushed P416 through standardization process Currently co-chair of the P4 language design working group
What I can talk about today • P416 programming language • Language design • Language/architecture separation • Portability vs. extensibility • P416 reference compiler architecture • How to extend the compiler for a new target • Compiling P4->eBPF • Compiling to eBPF (packet filters) • Compiling to XDP (packet switching) • Comparing P4 and eBPF • These are organized as 3 separate PPTX presentations
What I don’t plan to cover P414(the old version of P4) Run the P4 tutorials (given at P4 developer days) Demonstrate P4-related tools (compilers, simulators, IDEs) The P4 control-plane API (P4Runtime) The P4 Portable Switch Architecture Various applications written in P4
Presentation outline • P4 & Programmable networks • Why should you care? • An introduction to P416 • P4 limitations • Conclusions
Networking 101 Data packets switches/routers
Switch Control and Data Planes Switch architecture Control plane packets Data plane Interfaces
Traditional switch architecture Control-plane CPU Control plane Table management Data plane Switch ASIC Look-up tables (policies)
Software-Defined Networking Policies/signaling Controller Dumb control plane Data plane
The P4 world Upload program Policies/signaling Dumb control plane Programmable data plane SW: P4
Not just for switches! Programmable switches FPGA switches Programmable network cards Software switches Hypervisor switches You name it… Control plane Programmable data plane SW: P4
How is this possible? Datacenter Hello Most useful if you haveyour own network playground ?
Data-planes Control plane Data plane From now on in this presentation we only talk about the data-plane We expect that SDN will continue to evolve the control-plane
P4.org Consortium Carriers, cloud operators, chip cos, networking, systems, universities, start-ups
Isn’t Open-Flow Enough? Open-Flow version • Open-flow has never been enough: it keeps changing to describe new protocols • Very fragmented
Protocols = programs • VxLAN: 175 lines of P4 • Took 4 years from proposal to wide availability • NVGRE: 183 lines of P4 M. Shahbaz, S. Choi, B. Pfaff, C. Kim, N. Feamster, N. McKeown, J. Rexford, PISCES: A Programmable, Protocol-Independent Software SwitchSIGCOMM 2016 • 40 times reduction in the size of the OvS parser • Much easier to add new protocols • Same performance
Use only what you need IETF has issued thousands of RFCs Switch RAM and CPU is very expensive Network operators can remove protocols Simplertroubleshooting
Network monitoring measurements (custom headers) Monitoring agent In-Band Network Telemetry (INT) Improving Network Monitoring and Managementwith Programmable Data Planes By Mukesh Hira & LJ Wobker
Optimize your network Paxos Made Switch-y Huynh Tu Dang, Marco Canini, Fernando Pedone, Robert Soulé CCR April 2016 Push application functionality in the network High speed
Network = software Use software engineering principles and tools Upgrade your network at any time Protocols = intellectual property
Language evolution P4: Programming Protocol-Independent Packet Processors Pat Bosshart, Dan Daly, Glen Gibb, Martin Izzard, Nick McKeown, Jennifer Rexford, Cole Schlesinger, Dan Talayco, Amin Vahdat, George Varghese, David Walker ACM SIGCOMM Computer Communications Review (CCR). Volume 44, Issue #3 (July 2014) P4 v1.0 spec, reference implementation and tools released in Spring 2015 (mostly by Barefoot Networks), Apache 2 license, http://github.com/p4lang. P416 spec, draft reference implementation and tools released in December 2016; spec finalized May 2017; v1.1 in June 2018 http://github.com/p4lang/p4-spec
P4 Community http://github.com/p4lang http://p4.org Free membership! Mailing lists Workshops P4 developer days Academic papers (SIGCOMM, SOSR)
P4 working groups Language design: evolves P4 Control-plane API: defines API between control-plane and P4 program (P4Runtime) Applications: defines interoperable applications (e.g. In-band Network Telemetry) Architecture (Portable Switch Architecture):standardizes portable architecture models Education
Available Software Tools • Compilers for various back-ends • Netronome chip, Barefoot chip, eBPF, Xilinx FPGA (open-source and proprietary) • Multiple control-plane implementations • SAI, OpenFlow, P4Runtime • Simulators • Testing tools • Sample P4 programs • IntelliJ plugin IDE, editor modes • Tutorials
P4 software workflow User-supplied Control-plane API P4 program P4 compiler LOAD API control signals Data plane P4architecture model Dataplaneruntime Tables externobjects LOAD target Manufacturer supplied
P416 • Most recent revision of P4 • C-like syntax; strongly typed • No loops, pointers, recursion, dynamic allocation • Spec: http://github.com/p4lang/p4-spec • Reference compiler implementation(Apache 2 license): http://github.com/p4lang/p4c
P416 Language Overview • Suitable for L2 & 3 • High-level, type, memory-safe (no pointers) • Bounded execution (no loops) • Statically allocated (no malloc, no recursion) • Sub-languages: • Parsing headers • Packet header rewriting • Target architecture description
P416 data plane model Programmableblocks P4 P4 P4 Data plane Fixed function Interfaces
Example packet processing pipeline Programmable parser Headers eth vlan ipv4 Payload Packet (byte[]) Queueing/ switching Programmable match-action units eth ipv4 port mtag err bcast Metadata Not programmable Headers Programmable reassembly eth mtag ipv4 Packet
Language elements Programmable parser State-machine; bitfield extraction Programmable match-action units Table lookup; bitfield manipulation; control flow Programmable reassembly Bitfield packing Bitstrings, headers,structures, arrays Data-types user target Target description Interfaces of programmable blocks External libraries Support for custom accelerators
Basic data types • bit<N>, int<N> • e.g., bit<128>, int<1024> • intis two’s complement • varbit<13> • Container up to specified size; dynamic size is shorter • Only operation is copying • bool • enum, error, match_kind • error { PacketTooShort, ParseError } • error.PacketTooShort • Only string constants supported • typedef
Structures, headers • typedefbit<32> IPv4Address; • header IPv4_h {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; IPv4Address srcAddr; IPv4Address dstAddr;} • // List of all recognized headersstructParsed_packet {Ethernet_hethernet; IPv4_h ip;} header = struct + valid bit
Other derived types • Array of headers • H[6] arr; • Fixed size • Unions of headers • header_unionIP { ipv4 v4header; ipv6 v6header;} • Tuples • tuple<bit<32>, bit<16>> • set<tuple<bit<32>, bit<16>> - implicit only • No recursive types
Expression language • Standard arithmetic/logic on arbitrary bitstrings • But no funky undefined cases like in C • 2s complement for signed values • No division/modulo • Bit-slicing, bit concatenation • Integers are not Booleans • No implicit casts
Extern objects Generic type constructor instantiation • Model hardware accelerators or… • …behaviors not expressible in P4 extern Register<T> { Register(bit<32> size); T read(inbit<32> index);void write(inbit<32> index, in T value);} Register<bit<32>>(1024) reg; • Method calls using copy-in, copy-out • Like Java interfaces
Packets = byte streams • externpacket_in { • void extract<T>(out T headerLvalue);void extract<T>(out T varSizeHdr, inbit<32> varFieldSizeBits); T lookahead<T>();bit<32> length();void advance(inbit<32> bits); } • externpacket_out {void emit<T>(in T hdr);void emit<T>(inbool condition, in T data); }
Parsing = State machines dst src type IP header IP payload ethernet header • parser Parser(packet_in b, outParsed_packet p) {state start {b.extract(p.ethernet);transitionselect(p.ethernet.type) {0x0800: parse_ipv4;default: reject; } } • state parse_ipv4 {b.extract(p.ip);transition accept; }} start parse_ipv4 accept reject Parser states can contain cycles => loops bounded by packet size
Value Sets A set of 32-bit values changed dynamically by the control plane. parser p(packet_in pk, out Headers h) {value_set<bit<32>>(4) vs; state start { pk.extract(h); transition select(h.f) { vs: next; default: reject; } … } }
Actions • ~ Objects with a single method. • Straight-line code. • Reside in tables; invoked automatically on table match. Action data; from control plane • actionSet_nhop(IPv4Address ipv4_dest, PortId port) {nextHop = ipv4_dest;outCtrl.outputPort = port;} classSet_nhop { IPv4Address ipv4_dest; PortId port; void run() { nextHop = ipv4_dest;outCtrl.outputPort = port } } Java/C++ equivalent code.
Tables Map<K, Action> table ipv4_match { key = { headers.ip.dstAddr: exact; } actions = { drop; Set_nhop; }default_action = drop;} Populated bythe control plane
Table = Match-Action Processing Control plane Data action code hit actiondata Execute Lookup Action headers & metadata headers & metadata Lookup key Lookup table Default action
Control-Flow Ipv4_match • control Pipe(inoutParsed_packet headers,inInControlinCtrl,// input portoutOutControloutCtrl) { // output port IPv4Address nextHop; // local variable • actionDrop_action() { … } • actionSet_nhop(…) { … } • table ipv4_match() { … } • … • apply { // body of the pipeline ipv4_match.apply();if (outCtrl.outputPort == DROP_PORT) return; • dmac.apply(nextHop);if (outCtrl.outputPort == DROP_PORT) return; • smac.apply(); }} dmac smac
Packet Construction Convert headers back into a byte stream. Only valid headers are emitted. • control Deparser(inParsed_packet p, packet_out b) {apply {b.emit(p.ethernet); b.emit(p.ip); }}
P4 Program structure #include <core.p4> // core library#include <target.p4> // target description #include "library.p4" // library functions #include "user.p4" // user program
Architecture declaration Provided by the target manufacturer • structinput_metadata{ bit<12> inputPort; } • structoutput_metadata{ bit<12> outputPort; } • parser Parser<H>(packet_in b, out H headers); • control Pipeline<H>(inout H headers, in input_metadata input,out output_metadata output); • control Deparser<H>(in H headers, packet_out p); • package Switch<H>(Parser<H> p, Pipeline<H> p, Deparser<H> d); H = user-specified header type Switch Parser Pipeline Deparser
Support for custom “accelerators” External function External object with methods. Methods can be invoked like functions. Some external objects can be accessed from the control-plane. externbit<32> random(); extern Checksum16 {void clear(); // prepare unit for computationvoid update<T>(in T data); // add data to checksumvoid remove<T>(in T data); // remove data from checksumbit<16> get(); // get the checksum for data added}
Execution model • When a block is invoked (parser, control) it executes to completion on a separate thread • All local variables are thread-local • Only inter-thread communication possible through extern objects and functions • Execution triggered by outside event(e.g., packet arrival) • Actions execute atomically • @atomic annotation