A P4Runtime-native SDN simulation framework for BMv2.
Project description
p4net
A P4Runtime-native SDN simulation framework for BMv2.
Status: 0.2.0 — second public release. APIs are stable for lab use; expect refinement before 1.0.
Features
- P4Runtime-native control plane.
- BMv2
simple_switch_grpcdata plane. - Linux network-namespace based hosts.
- veth-based links with
tc/netemimpairment. - Programmable Python topology DSL.
- Interactive CLI.
- Per-port packet capture.
- P4Runtime CPU-port packet I/O (
<switch> packet send/listen). - IPv4 and IPv6 host addressing with per-interface sysctl gating.
- Asymmetric link impairment (per-direction
bandwidth,delay,jitter,loss_pct). - Topology visualization (Graphviz DOT / PNG / SVG).
- No OpenFlow, no Open vSwitch, no Docker.
Requirements
- Linux kernel >= 5.4.
- Python 3.10+.
- BMv2 and p4c installed system-wide.
- Root or
CAP_NET_ADMINto manage namespaces and veth devices.
Installation
From a fresh checkout:
git clone https://github.com/zhh2001/p4net
cd p4net
python3 -m venv .venv
. .venv/bin/activate
pip install -e '.[dev]'
PyPI distribution may follow a future release.
Quick Start
from pathlib import Path
from p4net import Network
from p4net.topo import Topology
topo = Topology()
h1 = topo.add_host("h1", ip="10.0.0.1/24", mac="00:00:00:00:00:01")
h2 = topo.add_host("h2", ip="10.0.0.2/24", mac="00:00:00:00:00:02")
s1 = topo.add_switch("s1", p4_src=Path("quick_start.p4"))
topo.add_link(h1, s1, port_b=1)
topo.add_link(h2, s1, port_b=2)
with Network(topo) as net:
print(net.pingall())
A complete runnable version, including the matching quick_start.p4
(a port-2-port swap that needs no runtime table programming) and a tiny
static-ARP setup, lives in examples/quick_start/. Run it with:
sudo python examples/quick_start/quick_start.py
or, equivalently, with the p4net console script installed by
pip install -e .:
sudo p4net examples/quick_start/quick_start.py
The console script loads any .py file that defines a module-level
topology: Topology (and optionally setup(net)), brings up the
network, and drops you into an interactive shell. If sudo strips your
venv from PATH, run the binary explicitly: sudo env "PATH=$PATH" p4net ....
Examples
examples/quick_start/— minimal two-host network with a hardcoded port-swap pipeline.examples/l3_forwarding/— runtime-programmed IPv4 LPM with static ARP.examples/cpu_punt/— every dataplane packet punted to the controller; demonstrates<switch> packet send/<switch> packet listen.examples/dual_stack/— two hosts carrying both IPv4 and IPv6.examples/asymmetric_link/— per-directiondelayshaping.examples/ipv6_lpm/— runtime-programmed IPv6 LPM forwarding.
Documentation
docs/architecture.md— module layout and design decisions.docs/tutorial.md— walkthrough from a single host up to a programmed two-host network.docs/cli.md— CLI reference for thep4netshell.docs/releasing.md— release runbook.docs/roadmap.md— released milestones and what's next.
License
Apache-2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file p4net-0.2.0.tar.gz.
File metadata
- Download URL: p4net-0.2.0.tar.gz
- Upload date:
- Size: 149.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9dfeae85f4b8ad201fac775a1c4c9c4f4a7b25d38ef90ff92dc9bf18474b4f2
|
|
| MD5 |
b31f087b84888079c84a10fb97aded48
|
|
| BLAKE2b-256 |
c8865eedffb82d52ddc9ed1eb375b62753944d8a9f77f12d9a789fff284a2474
|
File details
Details for the file p4net-0.2.0-py3-none-any.whl.
File metadata
- Download URL: p4net-0.2.0-py3-none-any.whl
- Upload date:
- Size: 74.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
163ebd090b75c2ae9e44b28c02740f93957f72b1906186b4720a3a5f40494472
|
|
| MD5 |
8fb994da645716ad14bed51eac3e5cac
|
|
| BLAKE2b-256 |
f1425d22e0fde35c4a054e08831196c03d80200a7570918c1b80d08370ea558c
|