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

p4 tofino config added #299

Merged
merged 5 commits into from
Aug 8, 2024
Merged
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
@@ -0,0 +1,299 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"editable": true,
"id": "-tjEL9EBnk6e",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Create a Slice with P4 tofino switch running a simple P4 program\n",
"\n",
"In this notebook, we will create a network slice using a P4 Tofino switch and run a simple P4 program. We will connect two nodes through the P4 switch on the same network, enabling them to ping each other.\n",
"\n",
"## Prerequisites\n",
"1. Access to a P4 Tofino switch.\n",
"\n",
"2. Two nodes to connect through the switch.\n",
"\n",
"3. Basic understanding of P4 programming.\n",
"\n",
"4. Tofino Software Development Environment (SDE) installed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Image\n",
"\n",
"# Display the image\n",
"Image(filename='figs/Simple_P4_Lab.drawio.png')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "CPhslE-unk6g"
},
"source": [
"## Import the FABlib Library\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "LmiM5Husnk6h"
},
"outputs": [],
"source": [
"from ipaddress import ip_address, IPv4Address, IPv6Address, IPv4Network, IPv6Network\n",
"import ipaddress\n",
"\n",
"from fabrictestbed_extensions.fablib.fablib import FablibManager as fablib_manager\n",
"\n",
"fablib = fablib_manager()\n",
"\n",
"fablib.show_config();"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "c0oBE6mYnk6i"
},
"source": [
"## Create the Experiment Slice\n",
"\n",
"The following script sets up two nodes, each with Shared NICs connected to two ports on a P4 tofino switch.\n",
"\n",
"NIC component model options include:\n",
"- NIC_Basic: 100 Gbps Mellanox ConnectX-6 SR-IOV VF (1 Port)\n",
"- NIC_ConnectX_5: 25 Gbps Dedicated Mellanox ConnectX-5 PCI Device (2 Ports)\n",
"- NIC_ConnectX_6: 100 Gbps Dedicated Mellanox ConnectX-6 PCI Device (2 Ports)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "imUjQXMXnk6i"
},
"outputs": [],
"source": [
"slice_name = 'P4-Lab-Slice'\n",
"p4_column_name = \"p4-switch_available\"\n",
"\n",
"site1 = \"LBNL\"\n",
"site2 = \"LBNL\"\n",
"site3 = \"RENC\"\n",
"\n",
"node1_name = 'Node1'\n",
"node2_name = 'Node2'\n",
"p4_name = 'P4'\n",
"network1_name = 'Network1'\n",
"network2_name = 'Network2'\n",
"\n",
"print(f\"Sites: {site1}, {site2}\")\n",
"print(f\"P4 Site: {site3}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "SXC2W_gfnk6i",
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"#Create Slice\n",
"slice = fablib.new_slice(name=slice_name)\n",
"\n",
"# Create Network\n",
"Network1 = slice.add_l2network(name=network1_name, subnet=IPv4Network(\"192.168.0.0/24\"))\n",
"Network2 = slice.add_l2network(name=network2_name, subnet=IPv4Network(\"192.168.0.0/24\"))\n",
"\n",
"# Create Node 1 and its links\n",
"node1 = slice.add_node(name=node1_name, site=site1)\n",
"iface1 = node1.add_component(model='NIC_ConnectX_6', name='nic1').get_interfaces()[0]\n",
"iface1.set_mode('config')\n",
"Network1.add_interface(iface1)\n",
"iface1.set_ip_addr(IPv4Address(\"192.168.0.1\"))\n",
"\n",
"# Create P4 switch and its links \n",
"p4 = slice.add_switch(name=p4_name, site=site3)\n",
"iface2 = p4.get_interfaces()[0]\n",
"Network1.add_interface(iface2)\n",
"\n",
"iface3 = p4.get_interfaces()[1]\n",
"Network2.add_interface(iface3)\n",
"\n",
"# Create Node 2 and its links\n",
"node2 = slice.add_node(name=node2_name, site=site2)\n",
"iface4 = node2.add_component(model='NIC_ConnectX_6', name='nic1').get_interfaces()[0]\n",
"iface4.set_mode('config')\n",
"Network2.add_interface(iface4)\n",
"iface4.set_ip_addr(IPv4Address(\"192.168.0.2\"))\n",
"\n",
"# Submit Slice Request\n",
"slice.submit()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nwUUFd6nnk6j"
},
"source": [
"## Run the Experiment"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Configure the P4 Switch. Login locally on P4 switch and perform below commands.\n",
"\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",
"~/tools/p4_build.sh --with-p4c=bf-p4c p4src/basic.p4\n",
"```\n",
"- Run the code\n",
"```\n",
"cd ~/bf-sde-9.13.3\n",
"./run_switchd.sh -p basic\n",
"```\n",
"- Enable Ports on bfshell\n",
"```\n",
"bf-shell> ucli\n",
"bf-sde> pm port-add 1/- 100G NONE\n",
"bf-sde> pm port-add 2/- 100G NONE\n",
"bf-sde> pm show\n",
"-----+----+---+----+-------+----+--+--+---+---+---+--------+----------------+----------------+-\n",
"PORT |MAC |D_P|P/PT|SPEED |FEC |AN|KR|RDY|ADM|OPR|LPBK |FRAMES RX |FRAMES TX |E\n",
"-----+----+---+----+-------+----+--+--+---+---+---+--------+----------------+----------------+-\n",
"1/0 |23/0|128|2/ 0|100G | RS |Au|Au|YES|DIS|DWN| NONE | 0| 0|\n",
"2/0 |22/0|136|2/ 8|100G | RS |Au|Au|YES|DIS|DWN| NONE | 0| 0|\n",
"bf-sde> pm port-enb 1/-\n",
"bf-sde> pm port-enb 2/-\n",
"bf-sde> pm show\n",
"-----+----+---+----+-------+----+--+--+---+---+---+--------+----------------+----------------+-\n",
"PORT |MAC |D_P|P/PT|SPEED |FEC |AN|KR|RDY|ADM|OPR|LPBK |FRAMES RX |FRAMES TX |E\n",
"-----+----+---+----+-------+----+--+--+---+---+---+--------+----------------+----------------+-\n",
"1/0 |23/0|128|2/ 0|100G | RS |Au|Au|YES|ENB|DWN| NONE | 0| 0|\n",
"2/0 |22/0|136|2/ 8|100G | RS |Au|Au|YES|ENB|DWN| NONE | 0| 0|\n",
"bf-sde>\n",
"```\n",
"\n",
"- Set up the forwarding rules on another window:\n",
" - Update the port numbers used in `~/P4_labs/lab1/bfrt_python/setup.py` are same as indicated by D_P column above \n",
" - Run the commands below\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",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Image\n",
"\n",
"# Display the image\n",
"Image(filename='figs/P4-Lab-Slice.png')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "A8fEpDTqnk6k"
},
"source": [
"### Verifying Reachability through Ping Tests"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "rldR_eV1nk6k"
},
"outputs": [],
"source": [
"slice=fablib.get_slice(slice_name)\n",
"node1=slice.get_node(node1_name)\n",
"node2=slice.get_node(node2_name)\n",
"\n",
"node1_addr = node1.get_interface(network_name=network1_name).get_ip_addr()\n",
"node2_addr = node2.get_interface(network_name=network2_name).get_ip_addr()\n",
"\n",
"stdout, stderr = node1.execute(f'ping -c 5 {node2_addr}')\n",
"stdout, stderr = node2.execute(f'ping -c 5 {node1_addr}')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "jr40raKGnk6k"
},
"source": [
"## Delete the Slice\n",
"\n",
"Please delete your slice when you are done with your experiment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Z5v7ECIjnk6k"
},
"outputs": [],
"source": [
"slice=fablib.get_slice(slice_name)\n",
"slice.delete()"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading