The objective of this tutorial is to extend basic L3 forwarding with an implementation of Quality of Service (QOS) using Differentiated Services.
Diffserv is simple and scalable. It classifies and manages network traffic and provides QOS on modern IP networks.
As before, we have already defined the control plane rules for routing, so you only need to implement the data plane logic of your P4 program.
Spoiler alert: There is a reference solution in the
solution
sub-directory. Feel free to compare your implementation to the reference.
The directory with this README also contains a skeleton P4 program,
qos.p4
, which initially implements L3 forwarding. Your job (in the
next step) will be to extend it to properly set the diffserv
bits.
Before that, let's compile the incomplete qos.p4
and bring up a
network in Mininet to test its behavior.
-
In your shell, run:
make
This will:
- compile
qos.p4
, and - start a Mininet instance with three switches (
s1
,s2
,s3
) configured in a triangle. There are 5 hosts.h1
andh11
are connected tos1
.h2
andh22
are connected tos2
andh3
is connected tos3
. - The hosts are assigned IPs of
10.0.1.1
,10.0.2.2
, etc (10.0.<Switchid>.<hostID>
). - The control plane programs the P4 tables in each switch based on
sx-runtime.json
- compile
-
We want to send traffic from
h1
toh2
. If we capture packets ath2
, we should see the right diffserv value.
- You should now see a Mininet command prompt. Open two terminals
for
h1
andh2
, respectively:mininet> xterm h1 h2
- In
h2
's XTerm, start the server that captures packets:./receive.py
- In
h1
's XTerm, send one packet per second toh2
using send.py say for 30 seconds. To send UDP:To send TCP:./send.py --p=UDP --des=10.0.2.2 --m="P4 is cool" --dur=30
The message "P4 is cool" should be received in./send.py --p=TCP --des=10.0.2.2 --m="P4 is cool" --dur=30
h2
's xterm, - At
h2
, theipv4.tos
field (DiffServ+ECN) is always 1 - type
exit
to close each XTerm window
Your job is to extend the code in qos.p4
to implement the diffserv logic
for setting the diffserv flag.
The qos.p4
file contains a skeleton P4 program with key pieces of
logic replaced by TODO
comments. These should guide your
implementation---replace each TODO
with logic implementing the
missing piece.
First we have to change the ipv4_t header by splitting the TOS field
into DiffServ and ECN fields. Remember to update the checksum block
accordingly. Then, in the ingress control block we must compare the
protocol in IP header with IP protocols. Based on the traffic classes
and priority, the diffserv
flag will be set.
A complete qos.p4
will contain the following components:
- Header type definitions for Ethernet (
ethernet_t
) and IPv4 (ipv4_t
). - Parsers for Ethernet, IPv4,
- An action to drop a packet, using
mark_to_drop()
. - An action (called
ipv4_forward
), which will:- Set the egress port for the next hop.
- Update the ethernet destination address with the address of the next hop.
- Update the ethernet source address with the address of the switch.
- Decrement the TTL.
- An ingress control block that checks the protocols and sets the ipv4.diffserv.
- A deparser that selects the order in which headers are inserted into the outgoing packet.
- A
package
instantiation supplied with the parser, control, checksum verification and recomputation and deparser.
Follow the instructions from Step 1. This time, when your message from
h1
is delivered to h2
, you should see tos
values change from 0x1
to 0xb9 for UDP and 0xb1 for TCP. It depends upon the action you choose
in Ingress processing.
To easily track the tos
values you may want to redirect the output
of h2
to a file by running the following for h2
./receive.py > h2.log
and just print the tos
values grep tos h2.log
in a separate window
tos = 0xb9
tos = 0xb9
tos = 0xb9
tos = 0xb9
tos = 0xb9
tos = 0xb9
tos = 0xb9
tos = 0xb9
tos = 0xb1
tos = 0xb1
tos = 0xb1
tos = 0xb1
tos = 0xb1
tos = 0xb1
tos = 0xb1
tos = 0xb1
How can we let the user use other protocols?
There are several ways that problems might manifest:
qos.p4
fails to compile. In this case,make
will report the error emitted from the compiler and stop.qos.p4
compiles but does not support the control plane rules in thesX-runtime.json
files thatmake
tries to install using a Python controller. In this case,make
will log the controller output in thelogs
directory. Use these error messages to fix yourqos.p4
implementation.qos.p4
compiles, and the control plane rules are installed, but the switch does not process packets in the desired way. Thelogs/sX.log
files contain trace messages describing how each switch processes each packet. The output is detailed and can help pinpoint logic errors in your implementation. Thebuild/<switch-name>-<interface-name>.pcap
also contains the pcap of packets on each interface. Usetcpdump -r <filename> -xxx
to print the hexdump of the packets.
In the latter two cases above, make
may leave a Mininet instance
running in the background. Use the following command to clean up
these instances:
make stop
Congratulations, your implementation works! Move on to Multicasting.
Documentation on the Usage of Gateway (gw) and ARP Commands in topology.json is here
The documentation for P4_16 and P4Runtime is available here
All excercises in this repository use the v1model architecture, the documentation for which is available at: