Sei sulla pagina 1di 55

P4 Language Tutorial

Copyright © 2017 – P4.org


What is Data Plane Programming?
• Why program the Data Plane?

Copyright © 2017 – P4.org 2


Status Quo: Bottom-up design

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

“This is how I want the


network to behave and how to
switch packets…”
(the user / controller
makes the rules)
P4 Programmable Device
Copyright © 2017 – P4.org 4
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.
• SW style development – rapid design cycle, fast innovation, fix data
plane bugs in the field
• You keep your own ideas

Think programming rather than protocols…

Copyright © 2017 – P4.org 5


Programmable Network Devices
• PISA: Flexible Match+Action ASICs
◦ Intel Flexpipe, Cisco Doppler, Cavium (Xpliant), Barefoot Tofino, …
• NPU
◦ EZchip, Netronome, …
• CPU
◦ Open Vswitch, eBPF, DPDK, VPP…
• FPGA
◦ Xilinx, Altera, …

These devices let us tell them how to process packets.

Copyright © 2017 – P4.org 6


What can you do with 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.

Copyright © 2017 – P4.org 7


Brief History and Trivia

• May 2013: Initial idea and the name “P4”


• July 2014: First paper (SIGCOMM ACR)
• Aug 2014: First P414 Draft Specification (v0.9.8)
• Sep 2014: P414 Specification released (v1.0.0)
• Jan 2015: P414 v1.0.1
• Mar 2015: P414 v1.0.2
• Nov 2016: P414 v1.0.3
• May 2017: P414 v1.0.4

• Apr 2016: P416 – first commits


• Dec 2016: First P416 Draft Specification
• May 2017: P416 Specification released

Copyright © 2017 – P4.org 8


P4_16 Data Plane Model

Copyright © 2017 – P4.org 9


PISA: Protocol-Independent Switch Architecture

Programmer defines the


tables and the exact Programmer declares
Programmer declares the processing algorithm how the output packet
headers that should be will look on the wire
recognized and their order in
the packet

Programmable Match-Action Pipeline


Programmable Programmable
Parser Deparser

Copyright © 2017 – P4.org 10


PISA in Action
• Packet is parsed into individual headers (parsed representation)
• Headers and intermediate results can be used for matching and
actions
• Headers can be modified, added or removed
• Packet is deparsed (serialized)
Programmable Match-Action Pipeline
Programmable Programmable
Parser Deparser

Copyright © 2017 – P4.org 11


P416 Language Elements

State machine,
Parsers bitfield extraction

Tables, Actions,
Controls control flow
statements

Basic operations
Expressions and operators

Bistrings, headers,
Data Types structures, arrays

Architecture Programmable blocks


and their interfaces
Description
Support for specialized
Extern Libraries components

Copyright © 2017 – P4.org 12


P4_16 Approach

Term Explanation

P4 Target An embodiment of a specific hardware implementation

Provides an interface to program a target via some set of P4-programmable components,


P4 Architecture externs, fixed components

Community-Developed Vendor-supplied

P416
Language
P416 Core
Library
Extern Architecture
Libraries Definition

Copyright © 2017 – P4.org 13


Programming a P4 Target
User supplied

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

Copyright © 2017 – P4.org 14


Lab 1: Basics

Copyright © 2017 – P4.org 15


Before we start...
•Install VM image (Look for instructor with USB sticks)
•Please make sure that your VM is up to date
◦$ cd ~/tutorials && git pull
•We’ll be using several software tools pre-installed on the VM
◦Bmv2: a P4 software switch
◦p4c: the reference P4 compiler
◦Mininet: a lightweight network emulation environment
•Each directory contains a few scripts
◦$ make : compiles P4 program, execute on Bmv2 in Mininet, populate tables
◦*.py: send and receive test packets in Mininet
•Exercises
◦Each example comes with an incomplete implementation; your job is to finish it!
◦Look for “TODOs” (or peek at the P4 code in solution/ if you must)
Copyright © 2017 – P4.org 16
V1Model Architecture
• Implemented on top of Bmv2’s simple_switch target

Parser Checksum Verification / Checksum Update / Deparser


Ingress Match-Action Egress Match-Action

Traffic
Manager

Copyright © 2017 – P4.org 17


V1Model Standard Metadata
struct standard_metadata_t { • ingress_port - the port on which
bit<9> ingress_port;
bit<9> egress_spec; the packet arrived
bit<9> egress_port;
bit<32> clone_spec; • egress_spec - the port to which
bit<32> instance_type;
bit<1> drop;
bit<16> recirculate_port;
the packet should be sent to
bit<32> packet_length;
bit<32> enq_timestamp;
• egress_port - the port on which
bit<19> enq_qdepth;
bit<32> deq_timedelta;
the packet is departing from (read
bit<19> deq_qdepth;
bit<48> ingress_global_timestamp; only in egress pipeline)
bit<32> lf_field_list;
bit<16> mcast_grp;
bit<1> resubmit_flag;
bit<16> egress_rid;
bit<1> checksum_error;
}

Copyright © 2017 – P4.org 18


P416 Program Template (V1Model)
#include <core.p4> /* EGRESS PROCESSING */
#include <v1model.p4> control MyEgress(inout headers hdr,
/* HEADERS */ inout metadata meta,
struct metadata { ... } inout standard_metadata_t std_meta) {
struct headers { ...
ethernet_t ethernet; }
ipv4_t ipv4; /* CHECKSUM UPDATE */
} control MyComputeChecksum(inout headers hdr,
/* PARSER */ inout metadata meta) {
parser MyParser(packet_in packet, ...
out headers hdr, }
inout metadata meta, /* DEPARSER */
inout standard_metadata_t smeta) { control MyDeparser(inout headers hdr,
... inout metadata meta) {
} ...
/* CHECKSUM VERIFICATION */ }
control MyVerifyChecksum(in headers hdr, /* SWITCH */
inout metadata meta) { V1Switch(
... MyParser(),
} MyVerifyChecksum(),
/* INGRESS PROCESSING */ MyIngress(),
control MyIngress(inout headers hdr, MyEgress(),
inout metadata meta, MyComputeChecksum(),
inout standard_metadata_t std_meta) { MyDeparser()
... ) main;
}

Copyright © 2017 – P4.org 19


P416 Hello World (V1Model)
#include <core.p4>
#include <v1model.p4> control MyEgress(inout headers hdr,
struct metadata {} inout metadata meta,
struct headers {} inout standard_metadata_t standard_metadata) {
apply { }
parser MyParser(packet_in packet, }
out headers hdr,
inout metadata meta, control MyComputeChecksum(inout headers hdr, inout metadata
inout standard_metadata_t standard_metadata) { meta) {
apply { }
state start { transition accept; } }
}
control MyDeparser(packet_out packet, in headers hdr) {
control MyVerifyChecksum(inout headers hdr, inout metadata apply { }
meta) { apply { } } }

control MyIngress(inout headers hdr, V1Switch(


inout metadata meta, MyParser(),
inout standard_metadata_t standard_metadata) { MyVerifyChecksum(),
apply { MyIngress(),
if (standard_metadata.ingress_port == 1) { MyEgress(),
standard_metadata.egress_spec = 2; MyComputeChecksum(),
} else if (standard_metadata.ingress_port == 2) { MyDeparser()
standard_metadata.egress_spec = 1; ) main;
}
}
}
Copyright © 2017 – P4.org 20
P416 Hello World (V1Model)
#include <core.p4>
#include <v1model.p4> control MyEgress(inout headers hdr,
struct metadata {} inout metadata meta,
struct headers {} inout standard_metadata_t standard_metadata) {
apply { }
parser MyParser(packet_in packet, out headers hdr, }
inout metadata meta,
inout standard_metadata_t standard_metadata) { control MyVerifyChecksum(inout headers hdr, inout metadata
state start { transition accept; } meta) { apply { } }
}
control MyComputeChecksum(inout headers hdr, inout metadata
control MyIngress(inout headers hdr, inout metadata meta, meta) { apply { } }
inout standard_metadata_t standard_metadata) {
action set_egress_spec(bit<9> port) { control MyDeparser(packet_out packet, in headers hdr) {
standard_metadata.egress_spec = port; apply { }
} }
table forward {
key = { standard_metadata.ingress_port: exact; } V1Switch( MyParser(), MyVerifyChecksum(), MyIngress(),
actions = { MyEgress(), MyComputeChecksum(), MyDeparser() ) main;
set_egress_spec;
NoAction; Key Action Name Action Data
}
size = 1024; 1 set_egress_spec 2
default_action = NoAction();
}
apply { forward.apply(); } 2 set_egress_spec 1
}
Copyright © 2017 – P4.org 21
Running Example: Basic Forwarding
•We’ll use a simple application as a running example—a basic
router—to illustrate the main features of P416

•Basic router functionality:


◦Parse Ethernet and IPv4 headers from packet
◦Find destination in IPv4 routing table
◦Update source / destination MAC addresses
◦Decrement time-to-live (TTL) field
◦Set the egress port
◦Deparse headers back into a packet

•We’ve written some starter code for you (basic.p4) and


implemented a static control plane
Copyright © 2017 – P4.org 22
Basic Forwarding: Topology

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;
}

Copyright © 2017 – P4.org 24


P416 Types (Other Types)
/* Architecture */
struct standard_metadata_t {
Other useful types
bit<9> ingress_port;
bit<9> egress_spec; • Struct: Unordered collection of members (with no
bit<9> egress_port;
bit<32> clone_spec; alignment restrictions)
bit<32> instance_type;
bit<1> drop; • Header Stack: array of headers
bit<16> recirculate_port;
bit<32> packet_length; • Header Union: one of several headers
...
}

/* User program */
struct metadata {
...
}
struct headers {
ethernet_t ethernet;
ipv4_t ipv4;
}

Copyright © 2017 – P4.org 25


P416 Parsers
• Parsers are functions that map packets
into headers and metadata, written in a start
state machine style
• Every parser has three predefined states
◦ start
◦ accept
◦ reject
• Other states may be defined by the
programmer
• In each state, execute zero or more
statements, and then transition to
accept reject
another state (loops are OK)

Copyright © 2017 – P4.org 26


Parsers (V1Model)
/* From core.p4 */
extern packet_in {
void extract<T>(out T hdr); MyParser
void extract<T>(out T variableSizeHeader,
in bit<32> variableFieldSizeInBits); packet_in hdr
T lookahead<T>();
void advance(in bit<32> sizeInBits);
bit<32> length();
} meta meta
/* User Program */
parser MyParser(packet_in packet,
The platform Initializes
out headers hdr, User Metadata to 0
inout metadata meta,
inout standard_metadata_t std_meta) {

state start { standard_meta


packet.extract(hdr.ethernet);
transition accept;
}

Copyright © 2017 – P4.org 27


Select Statement
state start { P416 has a select statement that can be
transition parse_ethernet; used to branch in a parser
}
Similar to case statements in C or Java,
state parse_ethernet { but without “fall-through behavior”—i.e.,
packet.extract(hdr.ethernet);
break statements are not needed
transition select(hdr.ethernet.etherType) {
0x800: parse_ipv4;
default: accept; In parsers it is often necessary to branch
} based on some of the bits just parsed
}
For example, etherType determines the
format of the rest of the packet

Match patterns can either be literals or


simple computations such as masks

Copyright © 2017 – P4.org 28


Coding Break

Copyright © 2017 – P4.org 29


P416 Controls
• 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:


◦ Match-Action Pipelines
◦ Deparsers
◦ Additional forms of packet processing (updating checksums)

• Interfaces with other blocks are governed by user- and


architecture-specified types (typically headers and metadata)
Copyright © 2017 – P4.org 30
Example: Reflector (V1Model)
control MyIngress(inout headers hdr, Desired Behavior:
inout metadata meta,
inout standard_metadata_t std_meta) {
bit<48> tmp; • Swap source and
apply { destination MAC
tmp = hdr.ethernet.dstAddr;
hdr.ethernet.dstAddr = hdr.ethernet.srcAddr;
addresses
hdr.ethernet.srcAddr = tmp;
std_meta.egress_spec = std_meta.ingress_port; • Bounce the packet back
}
}
out on the physical port
that it came into the
switch on

Copyright © 2017 – P4.org


Example: Simple Actions
control MyIngress(inout headers hdr, • Very similar to C functions
inout metadata meta, • Can be declared inside a control or
inout standard_metadata_t std_meta) { globally
• Parameters have type and direction
action swap_mac(inout bit<48> src,
inout bit<48> dst) {
• Variables can be instantiated inside
bit<48> tmp = src; • Many standard arithmetic and
src = dst; logical operations are supported
dst = tmp; ◦ +, -, *
} ◦ ~, &, |, ^, >>, <<
◦ ==, !=, >, >=, <, <=
apply { ◦ No division/modulo
swap_mac(hdr.ethernet.srcAddr, • Non-standard operations:
hdr.ethernet.dstAddr); ◦ Bit-slicing: [m:l] (works as l-value too)
std_meta.egress_spec = std_meta.ingress_port; ◦ Bit Concatenation: ++
}
}

Copyright © 2017 – P4.org


P416 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)

Copyright © 2017 – P4.org 33


Tables: Match-Action Processing
Control Plane

(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

Headers and Headers and


Metadata
Default Default
Action Metadata
(Input) Action ID Action Data
Execution (Output)

Copyright © 2017 – P4.org


Example: IPv4_LPM Table
• Data Plane (P4) Program
◦ Defines the format of the table
10.0.1.1 10.0.1.2 ■ Key Fields
■ Actions
■ Action Data
◦ Performs the lookup
◦ Executes the chosen action
• Control Plane (IP stack,
Key Action Action Data Routing protocols)
10.0.1.1/32 ipv4_forward dstAddr=00:00:00:00:01:01 ◦ Populates table entries with
port=1 specific information
10.0.1.2/32 drop ■ Based on the configuration
*` NoAction ■ Based on automatic discovery
■ Based on protocol calculations

Copyright © 2017 – P4.org 35


IPv4_LPM Table
table ipv4_lpm {
key = {
hdr.ipv4.dstAddr: lpm;
}
actions = {
ipv4_forward;
drop;
NoAction;
}
size = 1024;
default_action = NoAction();
}

Copyright © 2017 – P4.org 36


Match Kinds
/* core.p4 */ • The type match_kind is special in P4
match_kind {
exact, • The standard library (core.p4) defines
ternary, three standard match kinds
lpm ◦ Exact match
} ◦ Ternary match
◦ LPM match
/* v1model.p4 */
match_kind { • The architecture (v1model.p4) defines
range, two additional match kinds:
selector ◦ range
} ◦ selector

/* Some other architecture */ • Other architectures may define (and


match_kind { provide implementation for) additional
regexp, match kinds
fuzzy
}
Copyright © 2017 – P4.org 37
Defining Actions for L3 forwarding
/* core.p4 */ • Actions can have two different

(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

◦ Typically use directionless


/* basic.p4 */ parameters

(Action Data)
Directionless

Parameters
action ipv4_forward(macAddr_t dstAddr, ◦ May sometimes use directional
bit<9> port) { parameters too
...
}
Action
Execution

Copyright © 2017 – P4.org 38


Applying Tables in Controls

control MyIngress(inout headers hdr,


inout metadata meta,
inout standard_metadata_t standard_metadata) {
table ipv4_lpm {
...
}
apply {
...
ipv4_lpm.apply();
...
}
}

Copyright © 2017 – P4.org 39


P416 Deparsing
/* From core.p4 */ • Assembles the headers back
extern packet_out {
void emit<T>(in T hdr); into a well-formed packet
}
• Expressed as a control function
/* User Program */
control DeparserImpl(packet_out packet, ◦ No need for another construct!
in headers hdr) {
apply {
... • packet_out extern is defined in
packet.emit(hdr.ethernet); core.p4: emit(hdr): serializes
... header if it is valid
}
}
• Advantages:
• Makes deparsing explicit...
...but decouples from parsing
Copyright © 2017 – P4.org 40
Coding Break

Copyright © 2017 – P4.org 41


Makefile: under the hood
simple_switch_CLI
Program-independent
test.p4 CLI and Client

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

test.p4 $ p4c-bm2-ss -o test.json test.p4

p4c-bm2-ss

test.json

Copyright © 2017 – P4.org 43


Step 2: Preparing veth Interfaces

test.p4 $ sudo ~/p4lang/tutorials/examples/veth_setup.sh

# ip link add name veth0 type veth peer name veth1


# for iface in “veth0 veth1”; do
ip link set dev ${iface} up
sysctl net.ipv6.conf.${iface}.disable_ipv6=1
TOE_OPTIONS="rx tx sg tso ufo gso gro lro rxvlan txvlan rxhash”
for TOE_OPTION in $TOE_OPTIONS; do
/sbin/ethtool --offload $intf "$TOE_OPTION”
done
done

test.jso
test.json veth
n 0 2 4 2n

Linux
Kernel
2n
veth 1 3 5 +1

Copyright © 2017 – P4.org 44


Step 3: Starting the model
$ sudo simple_switch --log-console --dump-packet-data 64 \
–i 0@veth0 -i 1@veth2 … [--pcap] \
test.json
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.pcap

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)]

RuntimeCmd: table_info m_table


m_table [ethernet.srcAddr(ternary, 48)]
********************************************************************************
_nop
[]m_action [meter_idx(32)]

RuntimeCmd: table_dump m_table


Value and mask for ternary
m_table: matching. No spaces around Entry priority
0: aaaaaaaaaaaa &&& ffffffffffff => m_action - 0, “&&&”
SUCCESS

RuntimeCmd: table_add m_table m_action 01:00:00:00:00:00&&&01:00:00:00:00:00 => 1 0


Adding entry to ternary match table m_table
match key: TERNARY-01:00:00:00:00:00 &&& 01:00:00:00:00:00
action: m_action
runtime data: 00:00:00:05 “=>” separates the key
SUCCESS from the action data
entry has been added with handle 1
All subsequent
RuntimeCmd: table_delete 1 operations use the
entry handle

Copyright © 2017 – P4.org 47


Step 5: Sending and Receiving Packets

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

Copyright © 2017 – P4.org 48


Basic Tunneling
•Add support for basic tunneling to the basic IP router

•Define a new header type (myTunnel) to encapsulate the IP


packet

•myTunnel header includes:


○ proto_id : type of packet being encapsulated
○ dst_id : ID of destination host

•Modify the switch to perform routing using the myTunnel header

Copyright © 2017 – P4.org 49


Basic Tunneling TODO List
• Define myTunnel_t header type and add to headers struct
• Update parser
• Define myTunnel_forward action
• Define myTunnel_exact table
• Update table application logic in MyIngress apply statement
• Update deparser
• Adding forwarding rules

Copyright © 2017 – P4.org 50


Basic Forwarding: Topology

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

Copyright © 2017 – P4.org 52


P4→NetFPGA
• Prototype and evaluate P4 programs in real hardware!
• 4x10G network interfaces
• Special price for academic users :)
• https://github.com/NetFPGA/P4-NetFPGA-public/wiki

Copyright © 2017 – P4.org 53


Fin!

Copyright © 2017 – P4.org 54


Debugging
• Bmv2 maintains logs that keep track of
control MyIngress(...) { how packets are processed in detail
table debug { • /tmp/p4s.s1.log
key = { • /tmp/p4s.s2.log
std_meta.egress_spec : exact; • /tmp/p4s.s3.log
}
actions = { } • Can manually add information to the
}
logs by using a dummy debug table that
apply {
reads headers and metadata of interest
...
debug.apply();
} •[15:16:48.145] [bmv2] [D]
} [thread 4090] [96.0] [cxt 0]
Looking up key:
* std_meta.egress_spec : 2

Copyright © 2017 – P4.org 55

Potrebbero piacerti anche