papi: fix socket api max message id calculation 26/35726/5
authorVladislav Grishenko <[email protected]>
Fri, 29 Oct 2021 15:40:52 +0000 (20:40 +0500)
committerDamjan Marion <[email protected]>
Tue, 4 Mar 2025 10:04:14 +0000 (10:04 +0000)
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 <[email protected]>
Change-Id: Ib777db9dabc3a5a3ff83f07ec211cf2fb3c15cf0
Signed-off-by: Ole Troan <[email protected]>
src/vpp-api/python/vpp_papi/vpp_papi_async.py
src/vpp-api/python/vpp_papi/vpp_transport_socket.py

index d9a4fab..44e2a78 100644 (file)
@@ -451,7 +451,8 @@ class VPPApiClient:
         for m in r.message_table:
             n = m.name
             self.message_table[n] = m.index
-        self.vpp_dictionary_maxid = len(self.message_table)
+        # Find the maximum index of the message table
+        self.vpp_dictionary_maxid = max(self.message_table.values() or [0])
 
         # self.worker_task = asyncio.create_task(self.message_handler(event_queue))
         requests = {}
index 174ab74..1ba365a 100644 (file)
@@ -177,7 +177,8 @@ class VppTransport:
             return 0
 
     def msg_table_max_index(self):
-        return len(self.message_table)
+        """Return the maximum index of the message table."""
+        return max(self.message_table.values() or [0])
 
     def write(self, buf):
         """Send a binary-packed message to VPP."""