VPP-362 Implement dumping of LISP adjacencies
[vpp.git] / vppapigen / pyvppapigen.py
index e216169..75d6a14 100755 (executable)
@@ -36,6 +36,7 @@ format_struct = {'u8': 'B',
                  'f64' : 'd',
                  'vl_api_ip4_fib_counter_t' : 'IBQQ',
                  'vl_api_ip6_fib_counter_t' : 'QQBQQ',
+                 'vl_api_lisp_adjacency_t' : 'B' * 35
                  };
 #
 # NB: If new types are introduced in vpe.api, these must be updated.
@@ -48,6 +49,7 @@ type_size = {'u8':   1,
              'f64' : 8,
              'vl_api_ip4_fib_counter_t' : 21,
              'vl_api_ip6_fib_counter_t' : 33,
+             'vl_api_lisp_adjacency_t' : 35
 };
 
 def eprint(*args, **kwargs):
@@ -68,7 +70,7 @@ def get_pack(f):
     bytecount = 0
     pack = ''
     elements = 1
-    if len(f) is 3 or len(f) is 4:  # TODO: add support for variable length arrays (VPP-162)
+    if len(f) is 3 or len(f) is 4:
         size = type_size[f[0]]
         bytecount += size * int(f[2])
         # Check if we have a zero length array
@@ -118,14 +120,9 @@ def api_table_print(name, i):
     print('api_name_to_id["' + msg_id_in + '"] =', i)
     print('')
 
+
 def encode_print(name, id, t):
-    total = 0
     args = get_args(t)
-    pack = '>'
-    for i, f in enumerate(t):
-        p, elements, size = get_pack(f)
-        pack += p
-        total += size
 
     if name.find('_dump') > 0:
         multipart = True
@@ -146,14 +143,26 @@ def encode_print(name, id, t):
     if multipart == True:
         print(u"    results_more_set(context)")
 
-    ### TODO deal with zeroarray!!!
-    #if zeroarray == True:
-    #    print(u"    vpp_api.write(pack('" + pack + "', " + id + ", 0, context, " + ', '.join(args[3:-1]) + ") + " + args[-1] + ")")
-    #else:
-    print(u"    vpp_api.write(pack('" + pack + "', base + " + id + ", 0, context, " + ', '.join(args[3:]) + "))")
+    t = list(t)
+
+    # only the last field can be a variable-length-array
+    # it can either be 0, or a string
+    # first, deal with all the other fields
+    pack = '>' + ''.join([get_pack(f)[0] for f in t[:-1]])
+
+    # now see if the last field is a vla
+    if len(t[-1]) >= 3 and t[-1][2] == '0':
+        print(u"    vpp_api.write(pack('" + pack + "', base + " +
+              id + ", 0, context, " + ', '.join(args[3:-1]) + ") + "
+              + args[-1] + ")")
+    else:
+        pack += get_pack(t[-1])[0]
+        print(u"    vpp_api.write(pack('" + pack + "', base + " + id +
+              ", 0, context, " + ', '.join(args[3:]) + "))")
 
     if multipart == True:
-        print(u"    vpp_api.write(pack('>HII', VL_API_CONTROL_PING, 0, context))")
+        print(
+            u"    vpp_api.write(pack('>HII', VL_API_CONTROL_PING, 0, context))")
 
     print('''
     if not async:
@@ -260,7 +269,7 @@ api_func_table = []
 api_name_to_id = {}
     ''')
 
-    for i, a in enumerate(vppapidef):
+    for i, a in enumerate(messages):
         name = a[0]
         encode_print(name, str(i), a[1:])
         decode_print(name, a[1:])