* Updated the utils/run_exercise.py to allow exercises to customize host configuration from the topology.json file. Now hosts and `ping` each other in the basic exercise. Other Linux utilities should work as well (e.g. iperf). ``` mininet> h1 ping h2 PING 10.0.2.2 (10.0.2.2) 56(84) bytes of data. 64 bytes from 10.0.2.2: icmp_seq=1 ttl=62 time=3.11 ms 64 bytes from 10.0.2.2: icmp_seq=2 ttl=62 time=2.34 ms 64 bytes from 10.0.2.2: icmp_seq=3 ttl=62 time=2.15 ms ^C --- 10.0.2.2 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 2.153/2.540/3.118/0.416 ms mininet> pingall *** Ping: testing ping reachability h1 -> h2 h3 h2 -> h1 h3 h3 -> h1 h2 *** Results: 0% dropped (6/6 received) ``` Only updated basic exercise, still need to update other exercises. Also, updated the root-bootstrap.sh because I was running into issues with latest version of vagrant. * Accidentially added the solution to the basic exercise in the previous commit. Undoing that here ... * Updated the topology.json file and table entries for the basic_tunnel exercise. * Updated P4Runtime exercise with new topology and table entries. * Fixed MAC addresses in P4Runtime exercise. It is working now. * Fixed MAC addresses in P4Runtime exercise starter code * Updated ECN exercise to use new topology.json file. Updated the table entries / MAC addresses as well. * Updated the topology.json file and table entries for the MRI exercise. * Updated source_routing exercise with new topology file and verified correct functionality. * Updated load_balance exercise with new topology. * Moved basic exercise triangle topology into a separate folder * Added new topology for the basic exercise: a single pod of a fat-tree. * Updated Makefiles and run_exercise.py to allow exercises to configure each switch with a different P4 program. This is mainly for the firewall exercise. * Updated Makefiles of project to work with new utils/Makefile * Updated load_balance and p4runtime exercise Makefiles * Initial commit of the firewall exercise, which is a simple stateful firewall that uses a bloom filter. Need to update README files * Initial commit of the path_monitor exercise. It is working but still need to update the README and figure out what we want the tutorial attendees to implement. * Updated README file in firewall exercise. Also removed the bits from the starter code that we want the tutorial attendees to implement * Renamed path_monitor exercise to link_monitor * Updated the README in the link_monitor exercise and removed the bits from the starter code that we want the tutorial attendees to implement. * Updated README for the firewall exercise * Adding pod-topo.png image to basic exercise * Added firewall-topo.png image to firewall exercise * Added link-monitor-topo.png to link_monitor exercise * Updated README files to point to topology images * Updated top-level README to point to new exercises. * Fixed link for VM dependencies script in README * Updated bmv2/pi/p4c commits * Updated README files for exercises to fix some typos and added a note about the V1Model architecture. * Added a note about food for thought in the link_monitor README * Updated the firewall.p4 program to use two register arrays rather than a single one. This is to make the design more portable to high line rate devices which can only support a single access to each register array. * Minor fix to firewall exercise to get rid of compiler warning. * Updated comment in firewall exercise. * Minor (typo) fixes in the firewall ReadMe * More info in firewall exercise ReadMe step 2 * Updated firewall.p4 to reuse direction variable * More testing steps, small fixes in firewall exercise Readme * Added food for thought to firewall Readme * Cosmetic fixes to firewall ReadMe * Made a few updates to the basic exercise README and added more details to the link_monitor exercise README. Also added a command to install grip when provisioning the VM. This could be useful for rendering the markdown README files offline. * Updated top level README so it can be merged into the master branch. * Moved cmd to install grip from root-bootstrap to user-bootstrap
Load Balancing
In this exercise, you will implement a form of load balancing based on a simple version of Equal-Cost Multipath Forwarding. The switch you will implement will use two tables to forward packets to one of two destination hosts at random. The first table will use a hash function (applied to a 5-tuple consisting of the source and destination IP addresses, IP protocol, and source and destination TCP ports) to select one of two hosts. The second table will use the computed hash value to forward the packet to the selected host.
Spoiler alert: There is a reference solution in the
solution
sub-directory. Feel free to compare your implementation to the reference.
Step 1: Run the (incomplete) starter code
The directory with this README also contains a skeleton P4 program,
load_balance.p4
, which initially drops all packets. Your job (in
the next step) will be to extend it to properly forward packets.
Before that, let's compile the incomplete load_balance.p4
and bring
up a switch in Mininet to test its behavior.
-
In your shell, run:
make
This will:
- compile
load_balance.p4
, and - start a Mininet instance with three switches (
s1
,s2
,s3
) configured in a triangle, each connected to one host (h1
,h2
,h3
). - The hosts are assigned IPs of
10.0.1.1
,10.0.2.2
, etc. - We use the IP address 10.0.0.1 to indicate traffic that should be
load balanced between
h2
andh3
.
- compile
-
You should now see a Mininet command prompt. Open three terminals for
h1
,h2
andh3
, respectively:mininet> xterm h1 h2 h3
-
Each host includes a small Python-based messaging client and server. In
h2
andh3
's XTerms, start the servers:./receive.py
-
In
h1
's XTerm, send a message from the client:./send.py 10.0.0.1 "P4 is cool"
The message will not be received.
-
Type
exit
to leave each XTerm and the Mininet command line.
The message was not received because each switch is programmed with
load_balance.p4
, which drops all packets on arrival. Your job is to
extend this file.
A note about the control plane
P4 programs define a packet-processing pipeline, but the rules governing packet processing are inserted into the pipeline by the control plane. When a rule matches a packet, its action is invoked with parameters supplied by the control plane as part of the rule.
In this exercise, the control plane logic has already been
implemented. As part of bringing up the Mininet instance, the make
script will install packet-processing rules in the tables of each
switch. These are defined in the sX-runtime.json
files.
Step 2: Implement Load Balancing
The load_balance.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.
A complete load_balance.p4
will contain the following components:
- Header type definitions for Ethernet (
ethernet_t
) and IPv4 (ipv4_t
). - Parsers for Ethernet and IPv4 that populate
ethernet_t
andipv4_t
fields. - An action to drop a packet, using
mark_to_drop()
. - TODO: An action (called
set_ecmp_select
), which will:- Hashes the 5-tuple specified above using the
hash
extern - Stores the result in the
meta.ecmp_select
field
- Hashes the 5-tuple specified above using the
- TODO: A control that:
- Applies the
ecmp_group
table. - Applies the
ecmp_nhop
table.
- Applies the
- A deparser that selects the order in which fields inserted into the outgoing packet.
- A
package
instantiation supplied with the parser, control, and deparser.In general, a package also requires instances of checksum verification and recomputation controls. These are not necessary for this tutorial and are replaced with instantiations of empty controls.
Step 3: Run your solution
Follow the instructions from Step 1. This time, your message from
h1
should be delivered to h2
or h3
. If you send several
messages, some should be received by each server.
Troubleshooting
There are several ways that problems might manifest:
-
load_balance.p4
fails to compile. In this case,make
will report the error emitted from the compiler and stop. -
load_balance.p4
compiles but does not support the control plane rules in thesX-runtime.json
files thatmake
tries to install using the Python controller. In this case,make
will log the controller output in thelogs
directory. Use the error messages to fix yourload_balance.p4
implementation. -
load_balance.p4
compiles, and the control plane rules are installed, but the switch does not process packets in the desired way. The/tmp/p4s.<switch-name>.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.
Cleaning up Mininet
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:
mn -c
Next Steps
Congratulations, your implementation works! Move on to Multi-Hop Route Inspection.