Skip to main content

A P4Runtime-native SDN simulation framework for BMv2.

Project description

p4net

CI PyPI Python Versions License Documentation Status

A P4Runtime-native SDN simulation framework for BMv2.

Status: 1.1.0 — stable. Public API committed per API Stability. Patch releases for fixes; minor releases for new functionality with deprecation cycles where needed.

Features

  • P4Runtime-native control plane.
  • BMv2 simple_switch_grpc data plane.
  • Linux network-namespace based hosts.
  • veth-based links with tc/netem impairment.
  • 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).
  • In-band network telemetry (INT) example.
  • Unified p4net.* logger hierarchy with CLI verbosity control.
  • 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_ADMIN to 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

Documentation

Full documentation: https://zhh2001.github.io/p4net/

The English site is the authoritative reference; a Chinese translation layer is being added incrementally. Pages on the site cover installation, a tutorial, an architecture overview, the CLI reference, the auto-generated API reference, troubleshooting, a glossary, and per-example walk-throughs.

The source for these pages lives under docs/ and is built with MkDocs Material.

License

Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

p4net-1.1.0.tar.gz (242.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

p4net-1.1.0-py3-none-any.whl (80.2 kB view details)

Uploaded Python 3

File details

Details for the file p4net-1.1.0.tar.gz.

File metadata

  • Download URL: p4net-1.1.0.tar.gz
  • Upload date:
  • Size: 242.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for p4net-1.1.0.tar.gz
Algorithm Hash digest
SHA256 fbdfc8d46bfdeaf71d57c1c0bf24a0882d10d0214fa440ce0c63fe26e72f6dcc
MD5 d07c4b4937d9746249998a86b813bea5
BLAKE2b-256 57c201021771a1189632ff5fa3eb10990cdab68f1907182fb6785fb679c3f9fe

See more details on using hashes here.

File details

Details for the file p4net-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: p4net-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 80.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for p4net-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ad3556c1a3fe2a03ea64521da0333c7a7478940dff801416d5d1bb8ab77a5ba
MD5 f34c28e76c6c2f5b12fe8e6037635283
BLAKE2b-256 996ddba7b1f4546f41a7a1e595455309ed6e8b0365254e8eb96b67f511fa8a1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page