<s>
P4	B-Language
is	O
a	O
programming	O
language	O
for	O
controlling	O
packet	B-Protocol
forwarding	I-Protocol
planes	O
in	O
networking	O
devices	O
,	O
such	O
as	O
routers	O
and	O
switches	O
.	O
</s>
<s>
In	O
contrast	O
to	O
a	O
general	O
purpose	O
language	O
such	O
as	O
C	B-Language
or	O
Python	B-Language
,	O
P4	B-Language
is	O
a	O
domain-specific	B-Language
language	I-Language
with	O
a	O
number	O
of	O
constructs	O
optimized	O
for	O
network	B-Protocol
data	I-Protocol
forwarding	I-Protocol
.	O
</s>
<s>
P4	B-Language
is	O
distributed	O
as	O
open-source	B-Application
,	O
permissively	B-License
licensed	I-License
code	O
,	O
and	O
is	O
maintained	O
by	O
the	O
P4	B-Language
Project	O
(	O
formerly	O
the	O
P4	B-Language
Language	O
Consortium	O
)	O
,	O
a	O
not-for-profit	O
organization	O
hosted	O
by	O
the	O
Open	O
Networking	O
Foundation	O
.	O
</s>
<s>
P4	B-Language
was	O
originally	O
described	O
in	O
a	O
2014	O
SIGCOMM	O
CCR	O
paper	O
titled	O
“	O
Programming	O
Protocol-Independent	O
Packet	B-Protocol
Processors	O
”	O
—	O
the	O
alliterative	O
name	O
shortens	O
to	O
"	O
P4	B-Language
"	O
.	O
</s>
<s>
The	O
first	O
P4	B-Language
workshop	O
took	O
place	O
in	O
June	O
2015	O
at	O
Stanford	O
University	O
.	O
</s>
<s>
An	O
updated	O
specification	O
of	O
P4	B-Language
,	O
called	O
P4-16	O
,	O
was	O
released	O
between	O
2016	O
and	O
2017	O
,	O
replacing	O
P4-14	O
,	O
the	O
original	O
specification	O
of	O
P4	B-Language
.	O
</s>
<s>
As	O
the	O
language	O
is	O
specifically	O
targeted	O
at	O
packet	B-Protocol
forwarding	I-Protocol
applications	O
,	O
the	O
list	O
of	O
requirements	O
or	O
design	O
choices	O
is	O
somewhat	O
unusual	O
to	O
those	O
use	O
cases	O
.	O
</s>
<s>
P4	B-Language
programs	O
are	O
designed	O
to	O
be	O
implementation-independent	O
:	O
they	O
can	O
be	O
compiled	B-Language
against	O
many	O
different	O
types	O
of	O
execution	O
machines	O
such	O
as	O
general-purpose	O
CPUs	O
,	O
FPGAs	B-Architecture
,	O
system(s )	O
-on-chip	O
,	O
network	B-General_Concept
processors	I-General_Concept
,	O
and	O
ASICs	O
.	O
</s>
<s>
These	O
different	O
types	O
of	O
machines	O
are	O
known	O
as	O
P4	B-Language
targets	O
,	O
and	O
each	O
target	O
must	O
be	O
provided	O
along	O
with	O
a	O
compiler	B-Language
that	O
maps	O
the	O
P4	B-Language
source	O
code	O
into	O
a	O
target	O
switch	O
model	O
.	O
</s>
<s>
The	O
compiler	B-Language
may	O
be	O
embedded	O
in	O
the	O
target	O
device	O
,	O
an	O
externally	O
running	O
software	O
,	O
or	O
even	O
a	O
cloud	O
service	O
.	O
</s>
<s>
As	O
many	O
of	O
the	O
initial	O
targets	O
for	O
P4	B-Language
programs	O
were	O
used	O
for	O
simple	O
packet	B-Protocol
switching	O
it	O
is	O
very	O
common	O
to	O
hear	O
the	O
term	O
"	O
P4	B-Language
switch	O
"	O
used	O
,	O
even	O
though	O
"	O
P4	B-Language
target	O
"	O
is	O
more	O
formally	O
correct	O
.	O
</s>
<s>
P4	B-Language
is	O
designed	O
to	O
be	O
protocol-independent	O
:	O
the	O
language	O
has	O
no	O
native	O
support	O
for	O
even	O
common	O
protocols	O
such	O
as	O
IP	O
,	O
Ethernet	O
,	O
TCP	O
,	O
VxLAN	B-Protocol
,	O
or	O
MPLS	B-Protocol
.	O
</s>
<s>
Instead	O
,	O
the	O
P4	B-Language
programmer	O
describes	O
the	O
header	O
formats	O
and	O
field	O
names	O
of	O
the	O
required	O
protocols	O
in	O
the	O
program	O
,	O
which	O
are	O
in	O
turn	O
interpreted	O
and	O
processed	O
by	O
the	O
compiled	B-Language
program	O
and	O
target	O
device	O
.	O
</s>
<s>
Protocol	O
independence	O
and	O
the	O
abstract	O
language	O
model	O
allow	O
for	O
reconfigurability	O
–	O
P4	B-Language
targets	O
should	O
be	O
able	O
to	O
change	O
the	O
way	O
they	O
process	O
packets	B-Protocol
(	O
perhaps	O
multiple	O
times	O
)	O
after	O
they	O
are	O
deployed	O
.	O
</s>
<s>
This	O
capability	O
is	O
traditionally	O
associated	O
with	O
forwarding	B-Protocol
planes	I-Protocol
built	O
on	O
general-purpose	O
CPUs	O
or	O
network	B-General_Concept
processors	I-General_Concept
,	O
rather	O
than	O
the	O
fixed	O
function	O
ASICs	O
.	O
</s>
<s>
P4	B-Language
programs	O
typically	O
have	O
the	O
following	O
components	O
:	O
</s>
<s>
P4	B-Language
allows	O
the	O
specification	O
of	O
custom	O
packet	B-Protocol
header	O
parsing	O
logic	O
including	O
but	O
not	O
limited	O
to	O
parsing	O
typical	O
headers	O
used	O
in	O
the	O
TCP/IP	O
protocol	O
suite	O
and	O
application	O
specific	O
headers	O
.	O
</s>
<s>
Header	O
definitions	O
describe	O
packet	B-Protocol
formats	O
and	O
provide	O
names	O
for	O
the	O
fields	O
within	O
the	O
packet	B-Protocol
.	O
</s>
<s>
The	O
names	O
in	O
a	O
header	O
definition	O
are	O
used	O
later	O
in	O
the	O
P4	B-Language
program	O
to	O
reference	O
these	O
fields	O
.	O
</s>
<s>
The	O
P4	B-Language
parser	O
is	O
a	O
finite	O
state	O
machine	O
that	O
walks	O
an	O
incoming	O
byte-stream	O
and	O
extracts	O
headers	O
based	O
on	O
the	O
programmed	O
parse	O
graph	O
.	O
</s>
<s>
A	O
simple	O
example	O
would	O
be	O
a	O
parser	O
that	O
extracts	O
the	O
Ethernet	O
source	O
and	O
destination	O
and	O
type	O
fields	O
,	O
then	O
performs	O
a	O
further	O
extraction	O
based	O
on	O
the	O
value	O
in	O
the	O
type	O
field	O
(	O
common	O
values	O
might	O
be	O
ipv4	O
,	O
ipv6	O
,	O
or	O
MPLS	B-Protocol
)	O
.	O
</s>
<s>
P4	B-Language
allows	O
the	O
programmer	O
to	O
maintain	O
state	O
in	O
the	O
form	O
of	O
registers	O
,	O
counters	O
and	O
meters	O
.	O
</s>
<s>
The	O
primary	O
component	O
of	O
a	O
P4	B-Language
program	O
is	O
a	O
set	O
of	O
user-defined	O
match	O
action	O
tables	O
.	O
</s>
<s>
P4	B-Language
treats	O
all	O
match	O
action	O
tables	O
as	O
generic	O
,	O
leaving	O
the	O
user	O
to	O
add	O
their	O
match-action	O
rules	O
via	O
the	O
control	O
plane	O
.	O
</s>
<s>
Fundamental	O
to	O
P4	B-Language
is	O
the	O
concept	O
of	O
match-action	O
pipelines	O
.	O
</s>
<s>
Conceptually	O
,	O
forwarding	O
network	B-Protocol
packets	I-Protocol
or	O
frames	O
can	O
be	O
broken	O
down	O
into	O
a	O
series	O
of	O
table	O
lookups	O
and	O
corresponding	O
header	O
manipulations	O
.	O
</s>
<s>
In	O
P4	B-Language
these	O
manipulations	O
are	O
known	O
as	O
actions	O
and	O
generally	O
consist	O
of	O
things	O
such	O
as	O
copying	O
byte	O
fields	O
from	O
one	O
location	O
to	O
another	O
based	O
on	O
the	O
lookup	O
results	O
on	O
learned	O
forwarding	O
state	O
.	O
</s>
<s>
P4	B-Language
addresses	O
only	O
the	O
data	B-Protocol
plane	I-Protocol
of	O
a	O
packet	B-Protocol
forwarding	I-Protocol
device	O
.	O
</s>
<s>
It	O
does	O
not	O
specify	O
the	O
control	O
plane	O
nor	O
any	O
exact	O
protocol	O
for	O
communicating	O
state	O
between	O
the	O
control	O
and	O
data	B-Protocol
planes	I-Protocol
.	O
</s>
<s>
Instead	O
,	O
P4	B-Language
uses	O
the	O
concept	O
of	O
tables	O
to	O
represent	O
forwarding	B-Protocol
plane	I-Protocol
state	O
.	O
</s>
<s>
An	O
interface	O
between	O
the	O
control	O
plane	O
and	O
the	O
various	O
P4	B-Language
tables	O
must	O
be	O
provided	O
to	O
allow	O
the	O
control	O
plane	O
to	O
inject/modify	O
state	O
in	O
the	O
program	O
.	O
</s>
<s>
P4	B-Language
tables	O
contain	O
the	O
state	O
used	O
to	O
forward	O
packets	B-Protocol
.	O
</s>
<s>
Tables	O
and	O
their	O
associated	O
actions	O
are	O
almost	O
always	O
chained	O
together	O
in	O
sequence	O
to	O
realize	O
the	O
full	O
packet	B-Protocol
forwarding	I-Protocol
logic	O
,	O
although	O
in	O
the	O
abstract	O
it	O
is	O
possible	O
to	O
build	O
a	O
single	O
table	O
that	O
includes	O
all	O
the	O
lookup	O
key	O
information	O
and	O
the	O
full	O
output	O
action	O
set	O
.	O
</s>
<s>
Actions	O
in	O
P4	B-Language
describe	O
packet	B-Protocol
field	O
and	O
metadata	O
manipulations	O
.	O
</s>
<s>
In	O
P4	B-Language
context	O
,	O
metadata	O
is	O
information	O
about	O
a	O
packet	B-Protocol
that	O
is	O
not	O
directly	O
derived	O
from	O
the	O
parser	O
,	O
such	O
as	O
the	O
input	O
interface	O
that	O
the	O
frame	O
arrived	O
on	O
.	O
</s>
<s>
English	O
descriptions	O
of	O
an	O
example	O
action	O
might	O
be	O
"	O
decrement	O
the	O
IPv4	O
TTL	B-Protocol
field	O
by	O
one	O
"	O
or	O
"	O
copy	O
the	O
MAC	O
address	O
from	O
the	O
output	O
port	O
table	O
into	O
the	O
outgoing	O
packet	B-Protocol
header.	O
"	O
</s>
<s>
P4	B-Language
defines	O
both	O
standard	O
metadata	O
that	O
must	O
be	O
provided	O
by	O
all	O
targets	O
as	O
well	O
as	O
target-specific	O
metadata	O
,	O
which	O
is	O
provided	O
by	O
the	O
author	O
of	O
specific	O
targets	O
.	O
</s>
<s>
The	O
control	O
flow	O
in	O
P4	B-Language
determines	O
the	O
relative	O
sequence	O
of	O
tables	O
,	O
and	O
allows	O
for	O
conditional	B-Language
execution	I-Language
of	O
tables	O
based	O
on	O
if/then/else	O
constructions	O
.	O
</s>
