{"id":13510606,"url":"https://github.com/p4lang/tutorials","last_synced_at":"2025-10-06T02:41:45.031Z","repository":{"id":1763189,"uuid":"43453620","full_name":"p4lang/tutorials","owner":"p4lang","description":"P4 language tutorials","archived":false,"fork":false,"pushed_at":"2025-10-01T04:27:13.000Z","size":49068,"stargazers_count":1501,"open_issues_count":17,"forks_count":906,"subscribers_count":90,"default_branch":"master","last_synced_at":"2025-10-01T06:24:43.120Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/p4lang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2015-09-30T19:17:28.000Z","updated_at":"2025-10-01T04:27:17.000Z","dependencies_parsed_at":"2023-07-06T20:01:38.246Z","dependency_job_id":"0c33742f-df6b-4331-8aa4-fdd9c6aeed27","html_url":"https://github.com/p4lang/tutorials","commit_stats":{"total_commits":136,"total_committers":45,"mean_commits":3.022222222222222,"dds":0.7867647058823529,"last_synced_commit":"e855fa7dfd7c05d8c8f4ec0cd25930dfa304389a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/p4lang/tutorials","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p4lang%2Ftutorials","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p4lang%2Ftutorials/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p4lang%2Ftutorials/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p4lang%2Ftutorials/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p4lang","download_url":"https://codeload.github.com/p4lang/tutorials/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p4lang%2Ftutorials/sbom","scorecard":{"id":716895,"data":{"date":"2025-08-11","repo":{"name":"github.com/p4lang/tutorials","commit":"247c5e7b84f0ebcd4409bd456c0deb27aef3ed27"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":6,"reason":"6 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 6","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":2,"reason":"Found 7/30 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: pipCommand not pinned by hash: vm-ubuntu-20.04/root-dev-bootstrap.sh:108","Warn: pipCommand not pinned by hash: vm-ubuntu-20.04/root-dev-bootstrap.sh:113","Warn: pipCommand not pinned by hash: vm-ubuntu-20.04/root-dev-bootstrap.sh:116","Warn: pipCommand not pinned by hash: vm-ubuntu-20.04/root-dev-bootstrap.sh:119","Warn: pipCommand not pinned by hash: vm-ubuntu-20.04/root-release-bootstrap.sh:43","Warn: pipCommand not pinned by hash: vm-ubuntu-20.04/user-dev-bootstrap.sh:149","Warn: pipCommand not pinned by hash: vm-ubuntu-20.04/user-dev-bootstrap.sh:150","Warn: pipCommand not pinned by hash: vm-ubuntu-20.04/user-dev-bootstrap.sh:151","Warn: pipCommand not pinned by hash: vm-ubuntu-20.04/user-dev-bootstrap.sh:224","Warn: pipCommand not pinned by hash: vm/user-bootstrap.sh:51","Warn: pipCommand not pinned by hash: vm/user-bootstrap.sh:117","Info:   0 out of  11 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 29 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-22T09:58:46.460Z","repository_id":1763189,"created_at":"2025-08-22T09:58:46.460Z","updated_at":"2025-08-22T09:58:46.460Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278551498,"owners_count":26005386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:01:46.538Z","updated_at":"2025-10-06T02:41:45.015Z","avatar_url":"https://github.com/p4lang.png","language":"Python","readme":"\n[comment]: # (SPDX-License-Identifier:  Apache-2.0)\n\n# P4 Tutorial\n\n* [Introduction](#introduction)\n* [Presentation](#presentation)\n* [P4 Documentation](#p4-documentation)\n* [Obtaining required software](#obtaining-required-software)\n     * [To build the virtual machine](#to-build-the-virtual-machine)\n     * [Accessing the VM](#accessing-the-vm)\n     * [To install P4 development tools on an existing system](#to-install-p4-development-tools-on-an-existing-system)\n* [How to Contribute](#how-to-contribute)\n* [Older tutorials](#older-tutorials)\n\nIf you are reading this while not attending a live P4 tutorial class,\nsee [below](#older-tutorials) for links to information about recently\ngiven live classes.\n\n\n## Introduction\n\nWelcome to the P4 Tutorial! We've prepared a set of exercises to help\nyou get started with P4 programming, organized into several modules:\n\n1. Introduction and Language Basics\n   - [Basic Forwarding](./exercises/basic)\u003cbr\u003e\n     \u003csmall\u003eIn this exercise, you'll learn to implement basic IPv4 packet forwarding using P4. By extending the provided `basic.p4` skeleton, you'll develop logic for updating MAC addresses, decrementing TTL values, and forwarding packets based on predefined rules. Through practical implementation and testing on a fat-tree topology in Mininet, you'll gain insights into designing and deploying data plane logic for network switches.\u003c/small\u003e\n   \n   - [Basic Tunneling](./exercises/basic_tunnel)\u003cbr\u003e\n     \u003csmall\u003eIn this exercise, you enhance an IP router implemented in P4 by adding basic tunneling support, enabling encapsulation of IP packets for customized forwarding. By introducing a new tunnel header type, you modify the switch code to handle encapsulated packets and define forwarding rules based on destination IDs. Through static control plane entries, the switch routes encapsulated packets, showcasing P4's versatility in customizing packet processing and network functionality.\u003c/small\u003e\n\n2. P4Runtime and the Control Plane\n   - [P4Runtime](./exercises/p4runtime)\u003cbr\u003e\n     \u003csmall\u003eThis exercise involves implementing a control plane using P4Runtime to send flow entries to switches for tunneling traffic between hosts. Students modify the provided P4 program and controller script to establish connections, push P4 programs, install tunnel ingress rules, and read tunnel counters, enhancing their understanding of P4Runtime and network forwarding logic.\u003c/small\u003e\n\n   - [Flowcache](./exercises/flowcache)\u003cbr\u003e\n     \u003csmall\u003e This exercise implements a program named flowcache.p4, which handles the PacketIn and PacketOut mechanisms, along with an idle timeout mechanism for table entries. In the data plane, packets are sent to the P4Runtime controller using the PacketIn. Upon receiving these packets, the controller adds an entry to the flow table. While the controller computes and installs the flow rule, PacketOut are sent to forward the packets to its destination. Once a flow entry is installed and no packets match it, the idle timeout start. Once a flow entry is installed and no packets match it, the idle timeout starts. When the timer expires, an IdleTimeoutNotification message is sent to the controller, which is responsible for reinstalling the expired flow entry.\u003c/small\u003e\n\n3. Monitoring and Debugging\n   - [Explicit Congestion Notification](./exercises/ecn)\u003cbr\u003e\n     \u003csmall\u003eIn this tutorial, you'll enhance a basic L3 forwarding P4 program with Explicit Congestion Notification (ECN) support, enabling end-to-end notification of network congestion without packet drops. By modifying the `ecn.p4` file, you'll implement ECN logic such as updating the ECN flag based on queue length thresholds and configuring static rules for proper ECN handling, followed by testing the solution in Mininet to verify packet forwarding and ECN flag manipulation.\u003c/small\u003e\n\n   - [Multi-Hop Route Inspection](./exercises/mri)\u003cbr\u003e\n     \u003csmall\u003eThis tutorial aims to augment basic L3 forwarding with a simplified version of In-Band Network Telemetry (INT) called Multi-Hop Route Inspection (MRI). It guides users through extending a skeleton P4 program, `mri.p4`, to append an ID and queue length to the header stack of every packet, enabling tracking of the packet's path and queue lengths.\u003c/small\u003e\n\n4. Advanced Behavior\n   - [Source Routing](./exercises/source_routing)\u003cbr\u003e\n     \u003csmall\u003eThis exercise aims to implement source routing, where the source host specifies the route for each packet through a stack of output ports. After configuring the P4 program, `source_routing.p4`, packets should be routed according to the specified port numbers in the stack, enabling end-to-end delivery based on the predetermined path.\u003c/small\u003e\n\n   - [Calculator](./exercises/calc)\u003cbr\u003e\n     \u003csmall\u003eThis tutorial guides you through implementing a basic calculator using a custom protocol header in P4. The P4 program, `calc.p4`, parses incoming calculator packets, performs the specified operation on the operands, and returns the result to the sender, enabling basic arithmetic calculations in a network switch.\u003c/small\u003e\n\n   - [Load Balancing](./exercises/load_balance)\u003cbr\u003e\n     \u003csmall\u003eThis exercise guides you in implementing load balancing using Equal-Cost Multipath Forwarding in a P4 program named `load_balance.p4`. It utilizes a hash function to distribute packets between two destination hosts based on a 5-tuple hash, enabling efficient traffic distribution across the network.\u003c/small\u003e\n\n   - [Quality of Service](./exercises/qos)\u003cbr\u003e\n     \u003csmall\u003eThis tutorial focuses on implementing Quality of Service (QoS) using Differentiated Services (Diffserv) in a P4 program named `qos.p4`. It extends basic L3 forwarding to classify and manage network traffic, providing QoS on modern IP networks by setting DiffServ flags based on traffic classes and priority.\u003c/small\u003e\n\n   - [Multicasting](./exercises/multicast)\u003cbr\u003e \n     \u003csmall\u003eThis exercise involves writing a P4 program to enable a network switch to multicast packets to multiple output ports based on the destination MAC address. It requires the implementation of logic to handle multicast packets, including defining actions for packet forwarding and configuring the control plane to manage packet processing rules. Through practical implementation and testing in a Mininet environment, participants learn to enhance network traffic management and efficiency through multicast communication.\u003c/small\u003e\n\n5. Stateful Packet Processing\n   - [Firewall](./exercises/firewall)\u003cbr\u003e\n     \u003csmall\u003eThis exercise focuses on implementing a basic stateful firewall using a P4 program named `firewall.p4`. The firewall is designed to allow communication between internal and external hosts based on predefined rules, utilizing a bloom filter for stateful packet inspection and filtering.\u003c/small\u003e\n\n   - [Link Monitoring](./exercises/link_monitor)\u003cbr\u003e\n     \u003csmall\u003eThis exercise focuses on implementing link monitoring within a network using P4 programming. By extending the basic IPv4 forwarding exercise, the program enables the measurement of link utilization by processing source-routed probe packets. Through the manipulation of probe packet headers and the maintenance of register arrays, the solution facilitates accurate monitoring of link utilization, which can be invaluable for network management and optimization.\u003c/small\u003e\n\n## Presentation\n\nThe slides are available [online](https://bit.ly/p4d2-2018-spring) and\nin the [P4_tutorial.pdf](./P4_tutorial.pdf) in the tutorial directory.\n\nA P4 Cheat Sheet is also available [online](https://drive.google.com/file/d/1Z8woKyElFAOP6bMd8tRa_Q4SA1cd_Uva/view?usp=sharing)\nwhich contains various examples that you can refer to.\n\n## P4 Documentation\n\nThe documentation for P4_16 and P4Runtime is available [here](https://p4.org/specs/)\n\nAll exercises in this repository use the v1model architecture, the documentation for which is available at:\n1. The BMv2 Simple Switch target document accessible [here](https://github.com/p4lang/behavioral-model/blob/master/docs/simple_switch.md) talks mainly about the v1model architecture.\n2. The include file `v1model.p4` has extensive comments and can be accessed [here](https://github.com/p4lang/p4c/blob/master/p4include/v1model.p4).\n\n## Obtaining required software\n\nIf you are starting this tutorial at one of the proctored tutorial events,\nthen we've already provided you with a virtual machine that has all of\nthe required software installed. Ask an instructor for a USB stick with\nthe VM image.\n\nOtherwise, to complete the\n[exercises](https://github.com/p4lang/tutorials/tree/master/exercises),\nyou will need to do one of the following:\n\n+ Download and run a virtual machine with the P4 development tools\n  already installed.\n+ Build a virtual machine, compiling and installing the P4 development\n  tools within it.\n+ Install the P4 development tools on an existing system with a\n  supported version of Ubuntu Linux.\n\n### Download a virtual machine with the P4 development tools already installed\n\nYou will need a system with a 64-bit Intel/AMD processor architecture,\nwith [VirtualBox](https://virtualbox.org) installed on it.  See the\ntable\n[here](https://github.com/jafingerhut/p4-guide/blob/master/bin/README-install-troubleshooting.md)\nfor a list of virtual machine images that you can download, then use\nVirtualBox's File-\u003eImport Appliance menu item to add the virtual\nmachine to those on your system.\n\nThere is one user account:\n+ Username: p4 | Password: p4\n\n### To build a virtual machine with the P4 development tools.\n\nSee the instructions [here](vm-ubuntu-24.04/README.md).\n\n### To install P4 development tools on an existing system\n\nThere are instructions and scripts in another Github repository that can, starting from a freshly installed Ubuntu 20.04, 22.04, or 24.04 Linux system with enough RAM and free disk space, install all of the necessary P4 development tools to run the exercises in this repository.  You can find those instructions and scripts [here](https://github.com/jafingerhut/p4-guide/blob/master/bin/README-install-troubleshooting.md) (note that you must clone a copy of that entire repository in order for its install scripts to work).\n\n# How to Contribute\n\nWe value and welcome new contributions. To get started, kindly look at our [Contribution Guidelines](CONTRIBUTING.md).\n\n# Older tutorials\n\nMultiple live tutorial classes have been given using the example code\nin this repository for hands-on exercises.  For example, there is one\neach April or May at the P4 workshop at Stanford University in\nCalifornia, and there have been several at networking conferences such\nas ACM SIGCOMM.\n\nPlease [create an issue](https://github.com/p4lang/tutorials/issues)\nfor this tutorials repository if you know a public link for classroom\nvideo recordings and/or pre-built VM images that currently do not have\nsuch a link.\n\n\n## ACM SIGCOMM August 2019 Tutorial on Programming the Network Data Plane\n\nYou can find more information about the ACM SIGCOMM August 2019 Tutorial on Programming the Network Data Plane [here](https://p4.org/events/2019-08-23-p4-tutorial/)\n\nThe page linked above has a link to download a pre-built VM image used\nfor this class, as well as instructions to build one yourself from a\nparticular branch of this repository.\n\n\n## P4 Developer Day, April 2019\n\nYou can find more information about the P4 Developer Day held in April 2019 [here](https://p4.org/p4-developer-day-2019/)\n\nBoth a beginner and advanced class were taught at this event.  The\npage linked above contains instructions to download and install a\npre-built Linux VM that was used during the classes.\n\n\n## P4 Developer Day, November 2017\n\nThis [link](https://www.youtube.com/watch?v=3DJeqS_dl_o\u0026list=PLf7HGRMAlJBzGC58GcYpimyIs7D0nuSoo) plays the first welcome video of a \nseries of 6 videos of tutorials given at this event.\n\nMore information about this event can be found\n[here](https://p4.org/p4-developer-day-fall-2017/).\n","funding_links":[],"categories":["P4","Python","others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp4lang%2Ftutorials","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp4lang%2Ftutorials","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp4lang%2Ftutorials/lists"}