Professional Documents
Culture Documents
Switch OS
Network Demands
?
“This is how I know to
Run-time API
Driver
process packets”
(i.e. the ASIC datasheet
makes the rules)
Fixed-function ASIC
Copyright © 2017 – P4.org 3
A Better Approach: Top-down design
Switch OS
Network Demands
Feedback
Run-time API
Driver
P4
[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.
State machine,
Parsers bitfield extraction
Tables, Actions,
Controls control flow
statements
Basic operations
Expressions and operators
Bistrings, headers,
Data Types structures, arrays
Term Explanation
Community-Developed Vendor-supplied
P416
Language
P416 Core
Library
Extern Architecture
Libraries Definition
Control Plane
RUNTIME
P4 Program P4 Compiler Add/remove Extern Packet-in/out
table entries control
CPU port
P4 Architecture Target-specific Extern
configuration Load Tables Data Plane
Model objects
binary
Target
Vendor supplied
Traffic
Manager
h1 h2
(10.0.1.1) (10.0.2.2)
s1 s2
s3
h3
(10.0.3.3)
Copyright © 2017 – P4.org 23
P416 Types (Basic and Header Types)
typedef bit<48> macAddr_t; Basic Types
typedef bit<32> ip4Addr_t;
header ethernet_t { • bit<n>: Unsigned integer (bitstring) of size n
macAddr_t dstAddr; • bit is the same as bit<1>
macAddr_t srcAddr;
• int<n>: Signed integer of size n (>=2)
bit<16> etherType;
} • varbit<n>: Variable-length bitstring
header ipv4_t {
bit<4> version;
Header Types: Ordered collection of members
bit<4> ihl;
bit<8> diffserv; • Can contain bit<n>, int<n>, and varbit<n>
bit<16> totalLen; • Byte-aligned
bit<16> identification;
bit<3> flags;
• Can be valid or invalid
bit<13> fragOffset; • Provides several operations to test and set validity bit:
bit<8> ttl; isValid(), setValid(), and setInvalid()
bit<8> protocol;
bit<16> hdrChecksum;
ip4Addr_t srcAddr; Typedef: Alternative name for a type
ip4Addr_t dstAddr;
}
/* User program */
struct metadata {
...
}
struct headers {
ethernet_t ethernet;
ipv4_t ipv4;
}
(DataPlane)
Parameters
Directional
Headers and Metadata
Lookup Key
Hit
Key Action ID Action Data
Action
ID
Action ID
Code
Selector
Hit/Miss
(Action Data)
Directionless
Parameters
Data
(DataPlane)
Parameters
Directional
action NoAction() { types of parameters
} ◦ Directional (from the Data Plane)
◦ Directionless (from the Control
/* basic.p4 */ Plane)
action drop() { • Actions that are called directly:
mark_to_drop(); ◦ Only use directional parameters Action
} • Actions used in tables: Code
(Action Data)
Directionless
Parameters
action ipv4_forward(macAddr_t dstAddr, ◦ May sometimes use directional
bit<9> port) { parameters too
...
}
Action
Execution
Program-independent
Control Server
p4c-bm2-ss test.json
L
o
TM g
simple_switch (BMv2)
Egress
Ingress
P4
D Debugger
test.json e
b
u
g
Parser Deparser
Packet Packet
generator Port Interface sniffer
veth0..n
Linux Kernel
Copyright © 2017 – P4.org 42
Step 1: P4 Program Compilation
p4c-bm2-ss
test.json
test.jso
test.json veth
n 0 2 4 2n
Linux
Kernel
2n
veth 1 3 5 +1
Program-independent
Control Server
L
test.json
TM o
g
g
i
n
Egress
BMv2
Ingress
g
test.jso
test.json
n
Parser Deparser
veth0..n
Linux Kernel
Copyright © 2017 – P4.org 45
Step 4: Starting the CLI
$ simple_switch_CLI BMv2 CLI
Program-independent
CLI and Client
test.p4 Program-independent
Control Server
L
test.json
TM o
g
g
i
n
Egress
BMv2
Ingress
g
test.jso
test.json
n Parser Deparser
Port Interface
veth0..n
Linux Kernel
Copyright © 2017 – P4.org 46
Working with Tables in simple_switch_CLI
RuntimeCmd: show_tables
m_filter [meta.meter_tag(exact, 32)]
m_table [ethernet.srcAddr(ternary, 48)]
Program-independent
Control Server
L
test.json
TM o
g
g
•scapy i
p = Ethernet()/IP()/UDP()/”Payload” n
•scapy
Egress
BMv2
Ingress
g
sendp(p, iface=“veth0”) sniff(iface=“veth9”, prn=lambda x: x.show())
•Ethereal, etc.. •Wirehark, tshark, tcpdump
Packet Packet
Generator Sniffer
Parser Deparser
Port Interface
veth 0 2 4 2n
Linux
Kernel 2n
veth 1 3 5 +1
h1 h2
1 1
(10.0.1.1) 2 2 (10.0.2.2)
(dst_id: 1) s1 3 3 s2 (dst_id: 2)
2 3
1
s3
h3
(10.0.3.3) (dst_id: 3)
Copyright © 2017 – P4.org 51
Coding Break