aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_papi_async.py
AgeCommit message (Collapse)AuthorFilesLines
2025-03-04papi: fix socket api max message id calculationVladislav Grishenko1-1/+2
In case of sparse message ids due fixed offsets, length of the message table is less than max message id, causing "IndexError: list assignment index out of range" exception in _register_function() due "self.id_msgdef[i] = msg". Unlike shmem api, socket api needs to use max id. Type: fix Signed-off-by: Vladislav Grishenko <themiron@yandex-team.ru> Change-Id: Ib777db9dabc3a5a3ff83f07ec211cf2fb3c15cf0 Signed-off-by: Ole Troan <otroan@employees.org>
2024-12-16papi: vpp_papi asyncio supportOle Troan1-0/+768
An asyncio version of the VPP Python API. A API call returns a awaitable future. In comparision to the legacy API, the extra message receive thread is no needed. from vpp_papi.vpp_papi_async import VPPApiClient async def process_events(event_queue): while True: event = await event_queue.get() print(f"*** Processing event: {event}") if event is None: return async def test(): vpp = VPPApiClient() event_queue = asyncio.Queue() event_processor_task = asyncio.create_task(process_events(event_queue)) rv = await vpp.connect("foobar", event_queue) assert rv == 0 rv = await vpp.api.show_version() rv = await vpp.api.sw_interface_dump() await event_queue.put(None) # Send sentinel to stop the event processor await asyncio.gather(event_processor_task) # Wait for them to finish await vpp.disconnect() Example of sending multiple requests and gather replies asynchronously async def test_bulk(): futures = [] for i in range(n): futures.append(vpp.api.show_version()) rv = await asyncio.gather(*futures) def main(): asyncio.run(test()) Type: feature Change-Id: Ie6bcb483930216c21a45658b72e87ba4c46f43ad Signed-off-by: Ole Troan <otroan@employees.org>