{"id":23164760,"url":"https://github.com/another-s347/rusty-p4","last_synced_at":"2025-08-18T04:32:42.300Z","repository":{"id":57665938,"uuid":"195022823","full_name":"another-s347/rusty-p4","owner":"another-s347","description":"p4 controller in Rust","archived":false,"fork":false,"pushed_at":"2021-02-22T15:11:37.000Z","size":603,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-17T13:50:12.445Z","etag":null,"topics":["p4language","p4runtime","rust","rust-lang","sdn","sdn-controller"],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/another-s347.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-03T09:32:17.000Z","updated_at":"2024-11-14T05:08:36.000Z","dependencies_parsed_at":"2022-09-14T13:01:35.020Z","dependency_job_id":null,"html_url":"https://github.com/another-s347/rusty-p4","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/another-s347%2Frusty-p4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/another-s347%2Frusty-p4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/another-s347%2Frusty-p4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/another-s347%2Frusty-p4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/another-s347","download_url":"https://codeload.github.com/another-s347/rusty-p4/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230164324,"owners_count":18183373,"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","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":["p4language","p4runtime","rust","rust-lang","sdn","sdn-controller"],"created_at":"2024-12-18T01:12:48.328Z","updated_at":"2024-12-18T01:12:48.815Z","avatar_url":"https://github.com/another-s347.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Work in Progress\n\n\nI hope I can finish this.\n\n# Rusty P4 [![Build (Linux)](https://github.com/another-s347/rusty-p4/actions/workflows/build_linux.yml/badge.svg?branch=new_app\u0026event=push)](https://github.com/another-s347/rusty-p4/actions/workflows/build_linux.yml) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![dev doc](https://img.shields.io/badge/-dev%20doc-ff69b4)](https://another-s347.github.io/docs/rusty_p4/rusty_p4/)\nA Work-in-progress composable and lightweight library for writing [P4Runtime](https://p4.org/specs/) controller in Rust. The goal is to bring powerful \u0026 expressive tools into the world of P4 and SDN so that developers can test their ideas faster.\n\nIt's trying to provide multi-level APIs for writing controllers with different complexity (see Examples below). Some design come from the tutorials of P4 and [ONOS](https://onosproject.org/).\n\n## Repo structure\n\n- rusty-p4-core. The core of rusty-p4, providing the basic building blocks like App trait, Service trait, P4 runtime, Pipeconf, flow and some other things.\n- rusty-p4-packet. Provides methods to parse packets.\n- rusty-p4-northbound. Provides impls for northbound server.\n- rusty-p4-app. Provides some simple application implementation.\n\n## Getting Started\n\nCurrent version hasn't been published, so to use it, add\n```\nrusty-p4 = { git=\"https://github.com/another-s347/rusty-p4\" }\n```\nto your Cargo.toml.\n\n\u003c!-- 1. [tutorials from P4](https://github.com/p4lang/tutorials/blob/master/exercises/p4runtime/mycontroller.py) (low-level API) (See src/p4rt/mycontroller.rs)\n```rust\npub fn run() {\n    let p4info_helper = P4InfoHelper::new(\u0026Path::new(\"path_to/advanced_tunnel.p4.p4info.bin\"));\n    let bmv2_file = \"path_to/advanced_tunnel.json\";\n    let mut s1 = Bmv2SwitchConnection::new(\"s1\",\"127.0.0.1:50051\",0);\n    let mut s2 = Bmv2SwitchConnection::new(\"s2\",\"127.0.0.1:50052\",1);\n\n    s1.master_arbitration_update_async();\n    s2.master_arbitration_update_async();\n\n    s1.set_forwarding_pipeline_config(\u0026p4info_helper.p4info,\u0026Path::new(bmv2_file));\n    s2.set_forwarding_pipeline_config(\u0026p4info_helper.p4info,\u0026Path::new(bmv2_file));\n\n    write_tunnel_rules(\u0026p4info_helper, \u0026s1, \u0026s2, 100, MACString(\"00:00:00:00:02:02\".to_owned()), Ipv4Addr::from_str(\"10.0.2.2\").unwrap());\n    write_tunnel_rules(\u0026p4info_helper, \u0026s2, \u0026s1, 200, MACString(\"00:00:00:00:01:01\".to_owned()), Ipv4Addr::from_str(\"10.0.1.1\").unwrap());\n}\n\nfn write_tunnel_rules(p4info_helper:\u0026P4InfoHelper, ingress_sw:\u0026Bmv2SwitchConnection, egress_sw:\u0026Bmv2SwitchConnection,\n                      tunnel_id:u32, dst_eth_addr:MACString, dst_ip_addr:Ipv4Addr)\n{\n    let table_entry = p4info_helper.build_table_entry(\n        \"MyIngress.ipv4_lpm\",\n        \u0026[\n            (\"hdr.ipv4.dstAddr\", Value::LPM(dst_ip_addr, 32))\n        ],\n        false,\n        \"MyIngress.myTunnel_ingress\",\n        \u0026[\n            (\"dst_id\", ParamValue::of(tunnel_id))\n        ],\n        0\n    );\n\n    ingress_sw.write_table_entry(dbg!(table_entry));\n}\n```\n2. Packet Counter (mid-level API)\n```rust\npub struct Example {\n    pub counter:u32\n}\n\nimpl P4app for Example {\n    fn on_packet(self:\u0026mut Self, packet:PacketReceived, ctx: \u0026ContextHandle) {\n        let packet = Bytes::from(packet.packet.payload);\n        let parsed:Option\u003cEthernet\u003cData\u003e\u003e = Ethernet::from_bytes(packet);\n        if let Some(ethernet) = parsed {\n            self.counter+=1;\n            println!(\"Counter == {}, ethernet type == {:x}\", self.counter, ethernet.ether_type);\n        }\n        else {\n            println!(\"packet parse fail\");\n        }\n    }\n}\n```\n3. ... (high-level API)\n```rust\npub struct AdhocApp {\n    flowMap: HashMap\u003cString, FlowOwned\u003e\n}\n\nimpl P4appExtended\u003cCommonEvents\u003e for AdhocApp {\n    fn on_packet(self: \u0026mut Self, packet: PacketReceived, ctx: \u0026ContextHandle\u003cCommonEvents\u003e, state: \u0026CommonState) {\n        if let Some(eth) = Ethernet::from_bytes(BytesMut::from(packet.packet.payload)) {\n            if eth.ether_type == 0x865 {\n                let path = state.graph.get_path(...);\n            }\n        }\n    }\n\n    fn on_host_added(self: \u0026mut Self, host: \u0026Host, state: \u0026CommonState, ctx: \u0026ContextHandle\u003cCommonEvents\u003e) {\n\n    }\n\n    fn on_device_added(self: \u0026mut Self, device: \u0026Device, state: \u0026CommonState, ctx: \u0026ContextHandle\u003cCommonEvents\u003e) {\n\n    }\n\n    fn on_link_added(self: \u0026mut Self, link: \u0026Link, state: \u0026CommonState, ctx: \u0026ContextHandle\u003cCommonEvents\u003e) {\n\n    }\n}\n``` --\u003e\n\u003c!-- ## TODO\n0. Migrate to tokio 0.2/ hyper 0.13/ tower-grpc.\n1. Complete P4Runtime API (read/write table, counter...).\n2. More packet parser.\n3. ~~Composable App~~.\n4. ~~Extended-App and app collection for high-level API~~.\n5. Logging and error handling and config.\n6. ~~Network-object configuration~~(Simple net config supported).\n7. ~~State restore~~.\n8. ~~Multiple p4 pipeline~~(need test and app update).\n9. Rest API for external control (CLI and ONOS restconf driver..etc).\n10. More API.\n11. Maybe more. --\u003e\n\n## Built With\n\n* [tonic](https://github.com/hyperium/tonic) - gRPC for Rust.\n* [PI](https://github.com/p4lang/PI) - P4Runtime\n* [tokio](https://tokio.rs) - The asynchronous run-time for the Rust programming language.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanother-s347%2Frusty-p4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanother-s347%2Frusty-p4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanother-s347%2Frusty-p4/lists"}