P4 Examples (text)

by Sasha Shkrebets last modified Mar 20, 2023 08:02 AM
In this brief lecture, I'll present a brief example of the P4 software switch in action. A P4 switch has three main parts, a file that defines the header format, a file that defines the parser, and a file that defines behavior model with a control flow over the switch.
Welcome back.
In this brief lecture,
I'll present a brief example of the P4 software switch in action.
A P4 switch has three main parts, a file that defines the header format,
a file that defines the parser, and
a file that defines behavior model with a control flow over the switch.
I'll give a brief overview of these three components.
And then we'll take a quick look at a P4 switch in action.
The parser specifies the header fields and provides a field list that defines
the list of fields that will be in the packet header.
The parser may also include the calculations that define
various operations on the header, such as performing checksum,
as well as specifying to the parser what should be extracted from packet headers.
The header file defines all the header fields that are used in the parser,
such as all field definitions, including the bit widths for each header field.
The behavioral model defines tables and control flow.
The tables include both specification of what's read and matched from each packet,
as well as enumeration of possible actions to take on the packet.
In a brief demonstration,
I'll compile a P4 program into a switch data-plane program.
And then we'll use the built-in P4 tester application to generate test traffic that
we send at virtual ethernet interfaces that we create with the P4 setup scripts.
It's also possible to integrate a P4 software switch in Mininet,
documentation for doing so is described on the P4 website.
To run a P4 program, we first go into the P4 Factory Tools directory and
set up the virtual ethernet interfaces for our test harness.
We then go into the directory of one of the targets, such as the basic router, and
make the behavioral model.
Once we've compiled the behavioral model, we can then run it.
And then we can run the P4 test harness,
which will send test traffic at our P4 software switch.
Here we see the header file,
which defines the width of each of the headers that will be used in the parser.
The parser contains a directive to extract the IPv4 headers, as seen here.
The parser also performs additional operations,
such has performing a checksum on the header fields.
Finally, we can see the basic routing behavior model which defines,
among other things, a control flow.
Here's the ingress control flow which does a number of operations, including
matching on the IPV4 fib table, which is defined elsewhere in the basic router.
Note that the basic router only defines the sets of tables,
including including the possible reads and actions for
each table, and the control flow of how these tables interact with one another.
But a control program such as this that we've been writing in the rest of this
course is necessary for actually populating this table.
In summary, P4 is real.
There are many P4 reference programs available in the P4 source code
repository that implement various popular protocols.
We've demonstrated the P4 compiler and the simulation model,
and all these tools are available on the P4 website and open source.
Navigation