NCTU P4 Workshop
Tseng Yi
NCTU W2CNLab
https://takeshi.tw/tag/p4/
1
Outline
• Introduction
• Architecture
• Header and Parser
• Action and Table
• Control flow
• Register, Metadata, Counter and Meter
• Getting start
2
Introduction
• Programming Protocol-Independent Packet
Processors.
• Describe how to handle a packet for a target.
• White box in white box.
3
Introduction
• Protocol Independent
• P4 programs specify how a switch processes packets.
• Target Independent
• P4 is suitable for describing everything from high-
performance forwarding ASICs to software switches.
• Field Reconfigurable
• P4 allows network engineers to change the way their
switches process packets after they are deployed.
P4 is not
• SDN Software Switch
• OpenFlow or Protocol
• Network abstraction
• Won’t compile to OpenFlow or any southbound
message.
5
P4 can
But OpenFlow Switch can’t
• Parse or modify L5~ header (e.g. inner ethernet
header from VXLAN, DNS query data, DHCP
header…)
• Define new protocol parser
• Stateful switch (need newest version of OvS or
modified OF switch)
• Flexible match field and table size of any table.
• Define new actions for tables.
6
Architecture
Headers
Parsers
Control
Program
Table
Config
Packet
Input
Parser Tables Tables
Queues
and/or
Buffers
Ingress Egress
7
Deployment host
P4 Target
How to write P4?
1. Define headers and parsers (parser graph)
2. Define actions, match fields for table.
3. Design a control flow for your target.
8
P4 spec v1.0.2
http://p4.org/wp-content/uploads/2015/04/p4-latest.pdf
9
Header
• Like “struct” from C/C++, but more flexible.
header_type eth_t {
fields {
dst : 48;
src : 48;
ethType : 16;
}
}
header eth_t eth;
10
Parser
• Parse(extract) a packet step by step.
• Eth ————> IPv4 ———>TCP
parser parser_eth {
extract(eth);
return select(eth.type) {
0x800: parser_ipv4;
default: ingress;
}
}
parser parser_ipv4 {
extract(ipv4);
return select(latest.proto) {
6: parser_tcp;
default: ingress;
}
}
11
type 0x0800 proto 6
Actions
• Like a function(but no return value).
• In one function, you can use one or more P4 API
(e.g. modify_field, add_header…)
• Can be executed in parallel (depends on
implementation of target)
12
action set_dst_mac_and_output(new_mac, outport) {
modify_field(eth.dst, new_mac);
modify_field(standard_metadata.egress_spec, outport)
}
• For example, if we want to set destination mac
address and output port.
Actions
13
Table
• Every table might contains different match field and actions.
• Each table might have different features
• Not just P4, Some vendors slice tables for different purpose, for example:
OFDPA from Broadcom
Table definition
table first_table {
reads {
ipv4.dst : lpm; // exact, lpm, ternary, range, valid
}
actions {
drop;
set_dst_mac_and_output;
}
size 1024;
}
Add one Flow Entry
• Currently, ways to control a P4 target (bmv2):
• Use runtime command line interface
• ONOS test app for bmv2
p4cli> table_add first_table set_dst_mac_and_output
10.0.0.0/24 => 00:00:00:00:00:01 1
Control flow
• Also like a function, but no argument or return value
• Main control flow: ingress and egress
• In control flow, you can:
• apply packet to specific tables
• go to other control flows
• When ingress ends, data will be sent to queue or
buffer, then handle by egress control flow.
Control flow
• Ingress:
• Modify state (register)
• Modify packet
• Modify metadata
• Modify egress_spec (e.g. queue, output port)
• Egress:
• Modify packet
Control Flow
control ingress {
apply(in_port);
apply(vlan);
apply(termination_mac):
if(valid(ipv4)) {
apply(l3_flow);
}
apply(unicast);
apply(multicast);
apply(bridging);
apply(acl);
}
Register & Metadata
Counter & Meter
Register, Metadata
• Register
• Like global variable, store data
• Can be use for stateful dataplane design
• Metadata
• Like local variable, reset after one control flow ended.
• If we need to use register, we need to load register to
metadata.
Counter
• Counter
• Count bytes or packets
• Update when table match or action call
• Fixed size, will stop counting or reset to zero
(depends on program)
Meter
• Like counter, but it monitoring packet rate, not
packet/byte count.
Getting start
Getting start
• Basic knowledge:
• Linux shell (network & system commands)
• Linux basic tools (git, tmux…)
• GNU compiler toolchain (for bmv2)
• Python & C/C++
• FSM, data structure, network
Getting start
• Setup env:
• bmv2
• https://github.com/p4lang/behavioral-model
• p4c-bm
• https://github.com/p4lang/p4c-bm
• editor plugins (optional)
• https://github.com/TakeshiTseng/atom-language-p4
• https://github.com/TakeshiTseng/vim-language-p4
Workflow(bmv2)
• Write P4 program
• Generate json file by using p4c-bmv2
• Use json to start a bmv2 target (e.g.
simple_switch)
Use mininet
• from p4_mininet import P4Switch, P4Host
• Setup cls parameter for addSwitch and addHost.
Use mininet
• net.addSwitch('s1', cls=P4Switch,
sw_path=SW_PATH, json_path=JSON_PATH,
thrift_port=9091)
• sw_path: bmv2 target path
• json_path: json file generated by p4c-bm
• thrift_port: port number for runtime API
P4 thrift API
• Connect bmv2 target and runtime CLI or
Conroller (e.g. ONOS)
• You can use runtime_CLI.py from bmv2
repository.
Quick Demo
https://github.com/TakeshiTseng/2016-nctu-p4-workshop
Quick Demo
• Goal:
• Use new protocol instead of ethernet.
• Path routing.
• Setup by runtime CLI.
Normal packet With path header
src (16 bit)
dst (16 bit)
payload normal packet
path (16 bit)
preamble (24 bit)
start
Ingress control
pkt[0:24] != 0xc0ffee
pkt[0:24] == 0xc0ffee
my_path_header
my_header
Parser
apply “forward”
apply “path_look_up”
Egress
path is not valid
path header is valid
Demo topology
P4
Switch
1
Host 3 Host 4
P4
Switch
2
P4
Switch
3
P4
Switch
4
Host 1 Host 2
Number of path : P(4, 2) = 12
00 02 02
00 02 02
1
1
1
1
Quick Demo
Software Defined Networking Developer Society
• http://sdnds.tw
• https://www.facebook.com/groups/sdnds.tw
Thanks!
Question?

More Related Content

PDF
20170925 onos and p4
PDF
Programming Protocol-Independent Packet Processors
PDF
[Webinar Slides] Programming the Network Dataplane in P4
PDF
JS introduction
PDF
Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...
PDF
P4 for Custom Identification, Flow Tagging, Monitoring and Control
PDF
P4, EPBF, and Linux TC Offload
PDF
Programming the Network Data Plane
20170925 onos and p4
Programming Protocol-Independent Packet Processors
[Webinar Slides] Programming the Network Dataplane in P4
JS introduction
Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...
P4 for Custom Identification, Flow Tagging, Monitoring and Control
P4, EPBF, and Linux TC Offload
Programming the Network Data Plane

What's hot (20)

PPTX
Compiling P4 to XDP, IOVISOR Summit 2017
PDF
Stacks and Layers: Integrating P4, C, OVS and OpenStack
PDF
Network Measurement with P4 and C on Netronome Agilio
PDF
P4-based VNF and Micro-VNF Chaining for Servers With Intelligent Server Adapters
PDF
Transparent eBPF Offload: Playing Nice with the Linux Kernel
PDF
Protocol Independence
PDF
Networking and Go: An Epic Journey
PDF
Measuring a 25 and 40Gb/s Data Plane
PDF
Ebpf ovsconf-2016
PDF
Cilium - Fast IPv6 Container Networking with BPF and XDP
PDF
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
PDF
CETH for XDP [Linux Meetup Santa Clara | July 2016]
PDF
Consensus as a Network Service
PDF
Programmable data plane at terabit speeds
PDF
LinuxCon 2015 Stateful NAT with OVS
PDF
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
PDF
BKK16-409 VOSY Switch Port to ARMv8 Platforms and ODP Integration
PDF
P4 Introduction
PDF
Network Programming: Data Plane Development Kit (DPDK)
PDF
DevConf 2014 Kernel Networking Walkthrough
Compiling P4 to XDP, IOVISOR Summit 2017
Stacks and Layers: Integrating P4, C, OVS and OpenStack
Network Measurement with P4 and C on Netronome Agilio
P4-based VNF and Micro-VNF Chaining for Servers With Intelligent Server Adapters
Transparent eBPF Offload: Playing Nice with the Linux Kernel
Protocol Independence
Networking and Go: An Epic Journey
Measuring a 25 and 40Gb/s Data Plane
Ebpf ovsconf-2016
Cilium - Fast IPv6 Container Networking with BPF and XDP
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
CETH for XDP [Linux Meetup Santa Clara | July 2016]
Consensus as a Network Service
Programmable data plane at terabit speeds
LinuxCon 2015 Stateful NAT with OVS
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
BKK16-409 VOSY Switch Port to ARMv8 Platforms and ODP Integration
P4 Introduction
Network Programming: Data Plane Development Kit (DPDK)
DevConf 2014 Kernel Networking Walkthrough
Ad

Viewers also liked (20)

PPTX
ONOS intent introduction
PPTX
NSCTF
PPTX
Ryu dynamic loader
PDF
P4: Programming Protocol-Independent Packet Processor
PPTX
Ryu SDN-IP
PPTX
音樂劇 羅密歐與茱麗葉 Musical - Roméo et Juliette
PPTX
20161119 SDNDS-TW Meetup
PDF
Extending Network Virtualization into the Optical Domain
PPTX
2015 COSCUP SDN Workshop -- SDN Quick Start
PDF
Blackholing from a_providers_perspektive_theo_voss
PDF
Jon Nield FastNetMon
PDF
Detecting and mitigating DDoS ZenDesk by Vicente De Luca
PDF
2016 COSCUP SDN Introduction
PDF
Janog 39: speech about FastNetMon by Yutaka Ishizaki
PDF
2016 COSCUP ONOS
PDF
GoBGP : yet another OSS BGPd
PPTX
SDN-IP Peering using BGP
PPT
PDF
03 estrategia-ddos
PDF
Ultra fast DDoS Detection with FastNetMon at Coloclue (AS 8283)
ONOS intent introduction
NSCTF
Ryu dynamic loader
P4: Programming Protocol-Independent Packet Processor
Ryu SDN-IP
音樂劇 羅密歐與茱麗葉 Musical - Roméo et Juliette
20161119 SDNDS-TW Meetup
Extending Network Virtualization into the Optical Domain
2015 COSCUP SDN Workshop -- SDN Quick Start
Blackholing from a_providers_perspektive_theo_voss
Jon Nield FastNetMon
Detecting and mitigating DDoS ZenDesk by Vicente De Luca
2016 COSCUP SDN Introduction
Janog 39: speech about FastNetMon by Yutaka Ishizaki
2016 COSCUP ONOS
GoBGP : yet another OSS BGPd
SDN-IP Peering using BGP
03 estrategia-ddos
Ultra fast DDoS Detection with FastNetMon at Coloclue (AS 8283)
Ad

Similar to 2016 NCTU P4 Workshop (20)

PDF
P4_tutorial.pdf
PDF
Linkmeup v076(2019-06).2
PDF
Rina p4 rina workshop
PDF
P4 foundation
PDF
P4 foundation
PDF
Openlab.2014 02-13.major.vi sion
PDF
Linkmeup v076 (2019-06)
PPTX
lect13_programmable_dp.pptx
PDF
M 14ofl
PDF
Introduction to OpenFlow
PPTX
P4+ONOS SRv6 tutorial.pptx
PDF
An FPGA for high end Open Networking
PDF
Recent advance in netmap/VALE(mSwitch)
PPTX
Designing HPC, Deep Learning, and Cloud Middleware for Exascale Systems
PDF
Introduction to Programmable Networks by Clarence Anslem, Intel
PPTX
Software-Defined Networking (SDN) is a transformative networking paradigm
PDF
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
PPT
Naveen nimmu sdn future of networking
PPT
Naveen nimmu sdn future of networking
PDF
FreeBSD VPC Introduction
P4_tutorial.pdf
Linkmeup v076(2019-06).2
Rina p4 rina workshop
P4 foundation
P4 foundation
Openlab.2014 02-13.major.vi sion
Linkmeup v076 (2019-06)
lect13_programmable_dp.pptx
M 14ofl
Introduction to OpenFlow
P4+ONOS SRv6 tutorial.pptx
An FPGA for high end Open Networking
Recent advance in netmap/VALE(mSwitch)
Designing HPC, Deep Learning, and Cloud Middleware for Exascale Systems
Introduction to Programmable Networks by Clarence Anslem, Intel
Software-Defined Networking (SDN) is a transformative networking paradigm
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
Naveen nimmu sdn future of networking
Naveen nimmu sdn future of networking
FreeBSD VPC Introduction

Recently uploaded (20)

PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
IGGE1 Understanding the Self1234567891011
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
advance database management system book.pdf
PDF
Complications of Minimal Access-Surgery.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PPTX
20th Century Theater, Methods, History.pptx
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
My India Quiz Book_20210205121199924.pdf
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
IGGE1 Understanding the Self1234567891011
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
advance database management system book.pdf
Complications of Minimal Access-Surgery.pdf
Weekly quiz Compilation Jan -July 25.pdf
TNA_Presentation-1-Final(SAVE)) (1).pptx
Cambridge-Practice-Tests-for-IELTS-12.docx
20th Century Theater, Methods, History.pptx
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
FORM 1 BIOLOGY MIND MAPS and their schemes
Uderstanding digital marketing and marketing stratergie for engaging the digi...
My India Quiz Book_20210205121199924.pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Hazard Identification & Risk Assessment .pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Practical Manual AGRO-233 Principles and Practices of Natural Farming

2016 NCTU P4 Workshop

Editor's Notes