Hi,

I am trying to use VPP python APIs and seeing the tracebacks (see below)
for Python APIs with parameters, while Python APIs without parameters are
fine. Will anyone help?  The APIs I tried is vpp.sw_interface_add_del_
address.

below is the traceback and code snippets. Whole codes are attached as well.


<snip>
Traceback (most recent call last):
  File "set_addr_test.py", line 53, in <module>
    main()
  File "set_addr_test.py", line 45, in main
    loop = vpp.sw_interface_add_del_address(ifindex, 1, 1, 0, 16, addr)
TypeError: <lambda>() takes exactly 0 arguments (6 given)
Cleaning up VPP on exit
<snip>


<snip>
  ....
  loop = vpp.create_loopback()
  print(loop)
  ifindex = loop.sw_if_index
  print('{}'.format(ifindex))

  addr = str(IPv6Address(u'1::1').packed)
  loop = vpp.sw_interface_add_del_address(ifindex, 1, 1, 0, 16, addr)
  ...
<snip>


The syntax from help  for this API:

sw_interface_add_del_address(**kwargs)
    u16 _vl_msg_id, u32 client_index, u32 context, u32 sw_if_index, u8
is_add, u8 is_ipv6, u8 del_all, u8 address_length, u8 address



regards,
Hang
#!/usr/bin/env python

from __future__ import print_function

import time
import struct
import os
import fnmatch
from ipaddress import *

import vpp_papi 
from vpp_papi import VPP

# first, construct a vpp instance from vpp json api files
# this will be a header for all python vpp scripts

# directory containing all the json api files.
# if vpp is installed on the system, these will be in /usr/share/vpp/api/

def main(*args):

# Note that there will be no vpp method available before vpp.connect()
  vpp = VPP()
  vpp.connect('test_papi')

# You're all set.
# You can check the list of available methods by calling dir(vpp)

  print('Interface Name   Index   State ')
  for intf in vpp.sw_interface_dump():
    if intf.link_up_down == 1:
      updown = 'up'
    else:
      updown = 'down'
    print('{:20s}         {:3d}   {:4s}'.format(intf.interface_name.decode(), intf.sw_if_index, updown))

  loop = vpp.create_loopback()
  print(loop)
  ifindex = loop.sw_if_index
  print('{}'.format(ifindex))
  
  addr = str(IPv6Address(u'1::1').packed)
  loop = vpp.sw_interface_add_del_address(ifindex, 1, 1, 0, 16, addr)
#  loop = vpp.sw_interface_add_del_address("loop1", "192.168.3.1/24")
# loop = vpp.sw_interface_add_del_address()
  print(loop)  
  exit(vpp.disconnect())


if __name__ == "__main__":
  main()

_______________________________________________
vpp-dev mailing list
vpp-dev@lists.fd.io
https://lists.fd.io/mailman/listinfo/vpp-dev

Reply via email to