Skip to main content

Async P4Runtime/gNMI Framework

Project description

🐟 Finsy P4Runtime Library

pypi ci codecov

Finsy is a P4Runtime controller library written in Python using asyncio. Finsy includes support for gNMI.

import asyncio
import finsy as fy

async def main():
    async with fy.Switch("sw1", "127.0.0.1:50001") as sw1:
        print(sw1.p4info)

asyncio.run(main())

Multiple Switches

With Finsy, you can write a P4Runtime controller that manages multiple switches.

Each switch is managed by an async ready_handler function. Your ready_handler function can read or update various P4Runtime entities in the switch. It can also create tasks to listen for packets or digests.

async def ready_handler(sw: fy.Switch):
    await sw.delete_all()
    await sw.write(
        [
            # Insert multicast group with ports 1, 2, 3 and CONTROLLER.
            +fy.P4MulticastGroupEntry(1, replicas=[1, 2, 3, 255]),
            # Modify default table entry to flood all unmatched packets.
            ~fy.P4TableEntry(
                "ipv4",
                action=fy.P4TableAction("flood"),
                is_default_action=True,
            ),
        ]
    )

    async for packet in sw.read_packets():
        print(f"{sw.name}: {packet}")

Use the SwitchOptions class to specify each switch's settings, including the p4info/p4blob and ready_handler. Use the Controller class to drive multiple switch connections. Each switch will call back into your ready_handler function after the P4Runtime connection is established.

from pathlib import Path

options = fy.SwitchOptions(
    p4info=Path("hello.p4info.txt"),
    p4blob=Path("hello.json"),
    ready_handler=ready_handler,
)

controller = fy.Controller([
    fy.Switch("sw1", "127.0.0.1:50001", options),
    fy.Switch("sw2", "127.0.0.1:50002", options),
    fy.Switch("sw3", "127.0.0.1:50003", options),
])

asyncio.run(controller.run())

For more examples, see the examples directory.

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

finsy-0.5.0.tar.gz (161.6 kB view details)

Uploaded Source

Built Distribution

finsy-0.5.0-py3-none-any.whl (195.3 kB view details)

Uploaded Python 3

File details

Details for the file finsy-0.5.0.tar.gz.

File metadata

  • Download URL: finsy-0.5.0.tar.gz
  • Upload date:
  • Size: 161.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for finsy-0.5.0.tar.gz
Algorithm Hash digest
SHA256 89792d339a4b3a33c63a43a70f347585c4412390a442fcedcfeacac6db71063e
MD5 2398f445910f0db5633094d4ee5e4f6f
BLAKE2b-256 e31686117602a9c44d0ea20b2b6e382c149849f79753befb4b5825f94d60f657

See more details on using hashes here.

File details

Details for the file finsy-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: finsy-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 195.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for finsy-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14c5207870391eff0ca71453d63cbb7f103aff20172662816da19f8dff5fd819
MD5 9f644650f41da48fa043c91eeb33400c
BLAKE2b-256 b28faedd01e3155dfd84f455ba472eb1bc96bcdd6accf2a101906d46742e9042

See more details on using hashes here.

Supported by

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