In this lab, you will write P4 code to program the dataplane and utilize the P4 Runtime Shell package in Python to perform the controller's tasks.
Import the .ova file into VirtualBox and start the VM.
p4/p4
for normal usagevagrant/vagrant
for root permissionDownload the sample code archive.
Unzip the sample code into the VM and place it in ~/tutorials
. Overwrite if prompted. The folder should contain the following files:
exercises/
learning_switch/
disable_ipv6.sh
learning_switch.p4
Makefile
mycontroller.py
README.md
utils/
vm/
vm-ubuntu-20.04/
LICENSE
P4_tutorial.pdf
p4-cheat-sheet.pdf
README.md
run_controller.py
Open a console and execute the following command:
In this lab, you will construct a hierarchical tree topology as illustrated below:
The IP and MAC addresses of each host are listed as follows:
Note: Since all topology setups have been completed for you, you don't need to perform any actions in this step. If you are interested in knowing how to set MAC, IP, ARP, and port configurations, please refer to ~/tutorials/learning_switch/sig-topo
.
After setting up your VM, open two consoles and navigate to ~/tutorials/learning_switch/
. Run the following commands:
Once you see
You can run
This command tests ping reachability between all hosts, equivalent to individual pings between hosts (e.g., h1 ping h2, h1 ping h3, …).
You will see the result:
You can use Ctrl+C
to terminate the ping, and use exit
to stop the Mininet.
The other console should display some messages like below:
The socket address 127.0.0.1:50051
corresponds to s1, 127.0.0.1:50052
is for s2, and 127.0.0.1:50053
is for s3.
Because the unmatched packet will be sent to the controller, and the controller currently only displays packet source, destination, and incoming port without any further functionality, the ping requests will not reach the destination side now. Additionally, the incoming port is reported as 0 because the switch is not providing this information to the controller. Your task is to modify the P4 code and the controller logic to enable the learning switch functionality.
The overall logic for the learning switch implementation involves the following steps:
When receiving a packet:
If the destination MAC address is in the mapping:
If the destination MAC address is not in the mapping:
Forward the packet:
In learning_switch.p4
send_to_cpu
action, some information should be placed into the packet_in header to inform the controller. Please fill in these details.In mycontroller.py
{student_id}_lab2.zip
learning_switch.p4
mycontroller.py
self.log
method for debugging purposes. Its usage is the same as print()
in Python, but it will add the switch address in front of the print message.make clean
.v1model
. If you are looking for reference data, don't get it wrong!