Introduction to P4 - Google Groups

56 downloads 221 Views 2MB Size Report
Open-source domain-specific language (DSL) for programmable ... E.g. PISA architecture, ingress/egress pipeline architec
Introduction to P4 ONOS-P4 Brigade Work Days, Seoul (Korea) September 18-29, 2017

What is P4? • Open-source domain-specific language (DSL) for programmable dataplanes • Protocol independent • Support for a variety of targets: ASICs, FPGAs, NICs, software • Field reconfigurable: add/remove capabilities to switches after they are deployed

• Based on the well known Match+Action forwarding model • 2 versions of the language: P4_14, P4_16 • We focus on P4_16

Outline • Programmable switch architecture • Workflow • P4 tools • p4c (compiler) • BMv2 (reference software switch) • P4Runtime (control plane framework)

Not covering the language, we will reverse engineer the example program during the hands-on

P4 Paradigm

OpenFlow or legacy

PISA: Protocol-Independent Switch Architecture Programmer declares the headers that should be recognized and their order in the packet

Slide courtesy: Vladimir Gurevich, P4_16 Tutorial. P4 Workshop 2017

Programmer defines the tables and the exact processing algorithm

Programmer declares how the output packet will look on the wire

Mapping a simple logical pipeline on PISA

Ethernet address table

Slide courtesy: Vladimir Gurevich, P4_16 Tutorial. P4 Workshop 2017

IPv4 address table

IPv6 address table

ACL filter table

P4 programs

my_program.p4 Defines the processing of each block

switch_arch.p4

Defines which blocks are available and the interface of each block

P416 terminology • P4 Target

• An embodiment of a specific hardware or software implementation • E.g. Barefoot’s Tofino chip, Netronome’s SmartNICs, BMv2 software switch, etc.

• P4 Architecture

• Set of P4-programmable components, externs, fixed components and their interfaces available to the P4 programmer • E.g. PISA architecture, ingress/egress pipeline architecture, etc. • Expressed as a P4 program Community-developed P416 Language

P416 Core Library

Vendor-supplied Architecture definition

Extern libraries

Portable Switch Architecture (PSA) • Community-developed architecture

• https://github.com/p4lang/p4-spec/tree/master/p4-16/psa

• Describes common capabilities of a network switch

• Which process and forward packets across multiple interface ports

• 6 programmable P4 blocks + 2 fixed-function blocks • P414 constructs removed from P416 now defined as PSA-specific externs • Counters, meters, stateful registers, hash functions, etc.

Workflow overview Control plane

p4c my_program.p4

P4 Compiler

arch.p4

Target-specific configuration/binary

Manufacturer supplied

P4Runtime

LOAD

Tables

Extern objects

BMv2

Data plane

p4c • https://github.com/p4lang/p4c • Open-source front-end compiler Compiler$data$flow • Support multiple back-ends (vendor-supplied)

• Generate code for ASICs, NICs, FPGAs, software switches and other targets • Some of them are open-source (BMv2, eBPF)

P414

P414 parser

v1 IR

ebpf back*end

C$code

mid* end

BMv2 back*end

JSON

mid* end

your own backend

target* specific code

convert IR

P416

mid* end

P416 parser

Slide courtesy: M. Budiu, C. Doss. The architecture of the P4_16 compiler. P4 Workshop 2017

frontend

IR

BMv2 • https://github.com/p4lang/behavioral-model • BMv2 = Behavioral-Model version 2 • User-space software switch to emulate a P4 data plane • Aimed at being 100% conformant to the P4 specification • Performance is non-goal, i.e. low throughput • Architecture-independent • Mostly generic code which can be used to implement any P4 target • Some targets provided as part of the repo, e.g. simple_router, simple_switch

BMv2’s simple_switch target

Parser

Packets Ingress pipeline

Multicast groups management

Packet Replication Engine (PRE)

configure

p4c-bm-ss my_program.p4

p4c compiler with simple_switch back-end

my_program.json

Table management Thrift-based RPC API

Egress pipeline

Deparser

Table management

P4Runtime • https://github.com/p4lang/PI • Framework for runtime control of P4-enabled devices • Developed by the p4.org API WG • Specification is still work-in-progress by API WG

Remote controller (e.g. ONOS) p4runtime.proto (interface)

• Specifically targeted for remote controllers • Protobuf + gRPC implementation

• P4 program-independent

• API doesn’t change with the P4 program

• Enables field-reconfigurability

• Ability to push a new P4 program to the device

Program-independent control server (gRPC) HW/SW target (e.g. BMv2 simple_switch, tofino chip, etc.)

Switch

p4runtime.proto • Allow interacting with entities defined in a P4 program • Tables, counters, meters, externs, etc.

• Bidirectional stream channel

• For packet-ins/outs, mastership updates, etc.

• P4 architecture-independent

• Easily extensible to support vendor-specific externs • Hardcoded support for PSA

Refers to P4 entities by integer IDs. How to get such IDs?

P4Runtime workflow P4Runtime PI Interface Workflow

switch.p4

• P4Info proto

• captures target-independent P4 program attributes • defines numeric IDs for P4 tables, actions, params, ● P4Info proto ○ captures target-independent P4 program attributes etc. ○

defines IDs for P4 tables, actions, params, etc.

• Target config ●

p4c front-end

IR

P4Info

IR = P4 compiler intermediate representation

• P4Info + device-specific configuration (e.g. BMv2’s ● Target Config JSON, Tofino binary, etc.) ○



p4c back-end

P4Info + P4-program mapping to silicon

target config

P4Runtime defines the PI interface ○

Refers to P4 entities by integer IDs coming from P4Info

rpc Controller Front-end p4runtime protos

Slide courtesy: S. Abdi, W. Mohsin, Y. Yetim, A. Ghaffarkhah. P4 Program-Dependent Controller Interface for SDN Applications. P4 Workshop 2017

PI

P4Runtime Interface

Switch 3

P4Info example P4Info Example action set_vrf(bit id) { meta.vrf_id = id; } table vrf_classifier_table { key = { hdr.ethernet.etherType : exact; hdr.ethernet.srcAddr : ternary; smeta.ingress_port: exact; } actions = { set_vrf; } default_action = set_vrf(0); }

action id: 16777233 param id: 50336000

p4c front-end

table id: 33554433 match_field id: 67108875 match_type: EXACT match_field id: 67108864 match_type: TERNARY match_field id: 67108870 match_type: EXACT action_ref id: 16777233

vrf.p4 vrf.p4 Slide courtesy: S. Abdi, W. Mohsin, Y. Yetim, A. Ghaffarkhah. P4 Program-Dependent Controller Interface for SDN Applications. P4 Workshop 2017

P4Info for vrf.p4 P4Info for vrf.p4

4

PIP4Runtime example Proto Example action set_vrf(bit id) { meta.vrf_id = id; } table vrf_classifier_table { key = { hdr.ethernet.etherType : exact; hdr.ethernet.srcAddr : ternary; smeta.ingress_port: exact; } actions = { set_vrf; } default_action = set_vrf(0); }

vrf.p4

table_entry { table_id: 33554433 match { field_id: 67108875 exact { value: \x08\x00 } } match { field_id: 67108870 exact { value: \x00\x00\x00\x00\x11\x01 } } ...

... table_action { action { action_id: 16777233 params { param_id: 50336000 value: \x00\x00\x00\x70 } } } }

PI message instance

Slide courtesy: S. Abdi, W. Mohsin, Y. Yetim, A. Ghaffarkhah. P4 Program-Dependent Controller Interface for SDN Applications. P4 Workshop 2017

5

Questions?