Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rel1.8 - P4 switch notebook #323

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Programming a P4 Switches\n",
"Programming a P4 switch, whether targeting hardware or software, requires a dedicated software development environment equipped with a compiler. \n",
"\n",
"**Figure 1: Generic workflow design**\n",
"\n",
"![Workflow](./figs/p4-workflow.png)\n",
"\n",
"The workflow consists of the following components:\n",
"\n",
"1. **Vendor-Provided Components**:\n",
" - **Compiler**: Responsible for translating the target-independent P4 source code into platform-specific implementations.\n",
" - **Architecture Model**: Defines the capabilities and constraints of the target device.\n",
" - **Target Switch**: The hardware or software environment where the data plane logic is deployed.\n",
"\n",
"2. **User-Provided Component**:\n",
" - **P4 Source Code**: Customized by the user to specify the desired forwarding logic and behavior.\n",
"\n",
"### Compilation Process\n",
"\n",
"The compiler translates the user-defined P4 source code into two essential artifacts:\n",
"\n",
"1. **Data Plane Runtime Configuration**: \n",
" - Implements the forwarding logic defined in the P4 program.\n",
" - Contains instructions and resource mappings tailored to the specific target switch.\n",
"\n",
"2. **Runtime Application Programming Interfaces (APIs)**: \n",
" - Enable the control plane or user to interact with the data plane during runtime.\n",
" - Support operations such as adding/removing entries in match-action tables and reading/writing the state of external objects (e.g., counters, meters, registers).\n",
" - Provide the necessary information for the control plane to manipulate data plane components, including:\n",
" - Table identifiers\n",
" - Match fields\n",
" - Keys\n",
" - Action parameters"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -11,18 +50,44 @@
"tags": []
},
"source": [
"# Set Up a Network Slice with a P4 Tofino Switch and a Basic P4 Program\n",
"## Set Up a Network Slice with a P4 Tofino Switch and a Basic P4 Program\n",
"\n",
"In this notebook, we will configure a network slice that utilizes a P4 Tofino switch to run a basic P4 program. The setup will establish connectivity between two nodes via the P4 switch, allowing them to communicate and test connectivity using ping.\n",
"In this notebook, we will configure a network slice that utilizes a P4 Tofino switch to run a basic P4 program. The setup will establish connectivity between two nodes via the P4 switch, allowing them to communicate and test connectivity using `ping`.\n",
"\n",
"This example is inspired by the **University of South Carolina CyberTraining program** for P4 programmable devices, which provides hands-on training on using P4 to build and manage network slices effectively.\n",
"\n",
"## Prerequisites\n",
"\n",
"1. Access to a P4 Tofino switch.\n",
"2. Two nodes available for connection through the switch.\n",
"3. Fundamental knowledge of P4 programming.\n",
"4. Installed Tofino Software Development Environment (SDE).\n",
"1. **Access to a P4 Tofino switch**: A programmable hardware device equipped with an Intel Tofino ASIC.\n",
"2. **Two nodes for connectivity**: Ensure two nodes are physically or virtually connected to the P4 switch.\n",
"3. **Basic knowledge of P4 programming**: Familiarity with writing, compiling, and deploying P4 programs is necessary.\n",
"4. **Installed Tofino Software Development Environment (SDE)**: Required tools and libraries for P4 development and deployment.\n",
"\n",
"## Example Workflow Overview\n",
"\n",
"1. **Compile the P4 Program**:\n",
" - Use the **bf-p4c compiler** with the **Tofino Native Architecture (TNA)** to compile the program into a binary file.\n",
" - This binary will serve as the data plane runtime configuration for the P4 switch.\n",
"\n",
"2. **Load the Data Plane Program**:\n",
" - Load the compiled binary into the P4 switch daemon, ensuring the forwarding logic is active.\n",
"\n",
"3. **Configure the Control Plane**:\n",
" - Use the **bfrt-python API** to populate the match-action tables, specifying forwarding rules for the nodes.\n",
"\n",
"4. **Test Connectivity**:\n",
" - Use `ping` to test connectivity between the two nodes and validate that the network slice is functioning as intended.\n",
"\n",
"**Figure 2: P4 example workflow**\n",
"\n",
"![Topology](./figs/p4-slice.png)"
"![Lab Workflow](./figs/p4-lab-workflow.png)\n",
"\n",
"\n",
"**Figure 3: Slice Topology**\n",
"\n",
"![Topology](./figs/p4-slice.png)\n",
"\n",
"The topology depicts two nodes connected through the P4 switch. The P4 program running on the switch enables forwarding, allowing the nodes to communicate.\n"
]
},
{
Expand Down Expand Up @@ -94,6 +159,16 @@
"print(f\"Sites chosen for hosting VMs: {site1} P4: {site2}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"site2=\"RENC\"\n",
"site1=\"LBNL\""
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -166,40 +241,119 @@
},
{
"cell_type": "markdown",
"metadata": {
"id": "nwUUFd6nnk6j"
},
"metadata": {},
"source": [
"## Run the Experiment"
"## Compilling the basic P4 program\n",
"P4 program file is `basic.p4` is available inside a docker conatiner `p4_container` running on the switch and can be edited by the user via `vim`\n",
"\n",
"Login locally on P4 switch and run the below commands.\n",
"SDE is setup in the docker `p4_container` container, get into bash shell inside the container.\n",
"\n",
"```\n",
"docker exec -ti p4_container /bin/bash\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Configure the P4 Switch. \n",
"### Configure the environment variables\n",
"\n",
"- Login locally on P4 switch and run the below commands.\n",
"SDE is setup in the docker `p4_container` container, get into bash shell inside the container.\n",
"\n",
"```\n",
"docker exec -ti p4_container /bin/bash\n",
"```\n",
"- Go to Lab1 and source config environment\n",
"Go to Lab1 and source config environment\n",
"```\n",
"cd ~/P4_labs/lab1/\n",
"source config_env.sh\n",
"```\n",
"- Compile the code\n",
"```\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Compile the code\n",
"\n",
"In this example we will not modify the P4 code. Instead, we will just compile it and run it on the switch. \n",
"\n",
"The script `p4_build.s`h is provided by Intel’s support portal. It invokes the compiler to generate the output files. It automatically detects the P4 version (i.e., P416), and generates\n",
"the output files under `$SDE/build/p4-build/<program_name>`, where `<program_name>` is the file `basic.p4`. It also generates the log files under `$SDE/logs/p4-build/<program_name>` and other files (e.g., graphs).\n",
"After executing the command, if there are no error messages displayed in the terminal, then the P4 program was compiled successfully.\n",
"\n",
"\n",
"```\n",
"~/tools/p4_build.sh --with-p4c=bf-p4c p4src/basic.p4\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Verify the compilation output files\n",
"Verify the output files for the program basic.p4 are generated in the `$SDE/build/p4-build directory` by issuing the following command.\n",
"\n",
"```\n",
"ls $SDE/build/p4-build/basic\n",
"```\n",
"- Launch the switch daemon\n",
"\n",
"The binary file that corresponds to the compiled data plane is located under `$SDE/build/p4-build/<program_name>/tofino/<program_name>/pipe/`. Use the command below to display the contents of this directory.\n",
"\n",
"```\n",
"ls $SDE/build/p4-build/basic/tofino/basic/pipe/\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Start the switch daemon\n",
"Now that we have compiled our P4 program and generated the output files, we can start the switch daemon with the compiled output using the command below.\n",
"\n",
"```\n",
"cd ~/bf-sde-9.13.3\n",
"./run_switchd.sh -p basic\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configuring the switch ports\n",
"\n",
"Once the daemon is running, you can issue commands in the bfshell. \n",
"\n",
"1. Issue the following command in the switch CLI to manage the ports of the switch.\n",
"\n",
"```\n",
"ucli\n",
"```\n",
"\n",
"NOTE: The ucli is the bfshell instance used to manage the switch ports. With the ucli, you can enable or disable ports, set the port speed (e.g., 100 Gbps, 40 Gbps, and 10 Gbps), and\n",
"select the FEC type. Additionally, the user can monitor the status of the ports, the number of sent and received frames, and other variables.\n",
"\n",
"2. Now we will add the ports for the switch. Recall from the topology that Server1 is connected to port 1 on the switch, and Server2 is connected to port 2 on the switch. Issue the\n",
"commands below to add ports 1 and 2 in the Tofino switch.\n",
"\n",
"```\n",
"- Enable Ports on bfshell\n",
"pm port-add 1/- 100G NONE\n",
"pm port-add 2/- 100G NONE\n",
"```\n",
"\n",
"3. Enable the ports by issuing the following commands.\n",
"```\n",
"pm port-enb 1/-\n",
"pm port-enb 2/-\n",
"```\n",
"\n",
"4. Verify that the ports are up by issuing the following command.\n",
"```\n",
"pm show\n",
"```\n",
"\n",
"\n",
"**Expected output:**\n",
"```\n",
"bf-shell> ucli\n",
"bf-sde> pm port-add 1/- 100G NONE\n",
Expand All @@ -218,28 +372,40 @@
"-----+----+---+----+-------+----+--+--+---+---+---+--------+----------------+----------------+-\n",
"1/0 |23/0|128|2/ 0|100G |NONE|Au|Au|YES|ENB|UP | NONE | 16| 0|\n",
"2/0 |22/0|136|2/ 8|100G |NONE|Au|Au|YES|ENB|UP | NONE | 13| 0|\n",
"```"
"```\n",
"\n",
"The ouput above shows that ports 1 and 2 are up. The speed for the ports is 100G. The columns `FRAMES TX` indicate how many frames are received and `FRAMES RX` transmitted in each port respectively."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Set up the Routes\n",
"## Populating the switch’s forwarding table\n",
"\n",
"`bfrt_python/setup.py` is available inside a docker conatiner `p4_container` running on the switch and can be edited by the user via `vim`\n",
"\n",
"Login locally on P4 switch and run the below commands.\n",
"SDE is setup in the docker `p4_container` container, get into bash shell inside the container.\n",
"\n",
"- Open another SSH session, Login locally on P4 switch and run the below commands.\n",
"- SDE is setup in the docker `p4_container` container, get into bash shell inside the container.\n",
"```\n",
"docker exec -ti p4_container /bin/bash\n",
"```\n",
"\n",
"- Update the port numbers used in `~/P4_labs/lab1/bfrt_python/setup.py`. Port numbers should match the D_P column as observed in the output of `pm show` above.\n",
"**1. Update the port numbers highligted in red box in `~/P4_labs/lab1/bfrt_python/setup.py`. Port numbers should match the `D_P` column as observed in the output of `pm show` above.**\n",
"\n",
"<img src=\"./figs/p4-brft-setup.png\" alt=\"brft\" style=\"width:40%;\">\n",
"\n",
"\n",
"\n",
"**2. Populate the table entries to the switch by typing the following command in the embedded terminal.**\n",
"\n",
"- Set up the forwarding rules on another window:\n",
"```\n",
"cd ~/bf-sde-9.13.3; . ~/tools/set_sde.bash\n",
"$SDE/./run_bfshell.sh --no-status-srv -b ~/P4_labs/lab1/bfrt_python/setup.py\n",
"```"
"```\n",
"\n",
"The forwarding table contains the information that the P4 program will use to forward packets to the right destination. "
]
},
{
Expand All @@ -248,7 +414,7 @@
"id": "A8fEpDTqnk6k"
},
"source": [
"### Verifying Reachability through Ping Tests\n",
"## Verifying Reachability through Ping Tests\n",
"\n",
"Inititate ping between the VMs.\n",
"\n",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fabrictestbed-extensions>=1.7.3
fabrictestbed-extensions>=1.8.0
python-dotenv
ipython==8.12.0
fabrictestbed-mflib>=1.0.4
Loading