linux/tools/net/ynl/lib
Donald Hunter 8aefcfa04b tools/net/ynl: add async notification handling
The notification handling in ynl is currently very simple, using sleep()
to wait a period of time and then handling all the buffered messages in
a single batch.

This patch adds async notification handling so that messages can be
processed as they are received. This makes it possible to use ynl as a
library that supplies notifications in a timely manner.

- Add poll_ntf() to be a generator that yields 1 notification at a
  time and blocks until a notification is available.
- Add a --duration parameter to the CLI, with --sleep as an alias.

./tools/net/ynl/cli.py \
    --spec <SPEC> --subscribe <TOPIC> [ --duration <SECS> ]

The cli will report any notifications for duration seconds and then
exit. If duration is not specified, then it will poll forever, until
interrupted.

Here is an example python snippet that shows how to use ynl as a library
for receiving notifications:

    ynl = YnlFamily(f"{dir}/rt_route.yaml")
    ynl.ntf_subscribe('rtnlgrp-ipv4-route')

    for event in ynl.poll_ntf():
        handle(event)

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/20241113090843.72917-3-donald.hunter@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2024-11-14 18:09:06 -08:00
..
.gitignore selftests: add ncdevmem, netcat for devmem TCP 2024-09-11 20:44:32 -07:00
Makefile tools: ynl: extend CFLAGS to keep options from environment 2024-11-13 18:43:46 -08:00
__init__.py tools/net/ynl: Report netlink errors without stacktrace 2024-03-07 20:28:26 -08:00
nlspec.py tools: ynl-gen: de-kdocify enums with no doc for entries 2024-11-04 18:11:47 -08:00
ynl-priv.h tools: ynl: make user space policies const 2024-06-09 15:51:40 +01:00
ynl.c tools: ynl: remove extraneous ; after statements 2024-08-05 16:28:39 -07:00
ynl.h tools: ynl: make user space policies const 2024-06-09 15:51:40 +01:00
ynl.py tools/net/ynl: add async notification handling 2024-11-14 18:09:06 -08:00