Hi Neha,

You should provide the PID of the process that wants to receive the callbacks 
for the want apis not the PID of the vpp.
Look at the API documentation <VPP>/src/vpp /stats/stats.api. Something like 
pid=os.getpid() instead of the VPP PID in the code snippet below will fix it.

Also the callback (papi_event_handler) accepts msgname, result, change it in 
the below code snippet.

On the VPP side you can check “show api client” to check if the python client 
is connected.

Thanks,
Shwetha

From: <vpp-dev@lists.fd.io> on behalf of Neha <neha.r.vadn...@intel.com>
Date: Tuesday, July 10, 2018 at 11:46 AM
To: Ole Troan <otr...@employees.org>
Cc: "vpp-dev@lists.fd.io" <vpp-dev@lists.fd.io>
Subject: Re: [vpp-dev] VPP python binding for getting interface stats in VPP 
18.07

Hi,

This is the code snippet: (As explained in 
https://wiki.fd.io/view/VPP/Python_API).

from vpp_papi import VPP
def papi_event_handler(result):
        if result.vl_msg_id == vpp_papi.VL_API_VNET_INTERFACE_SIMPLE_COUNTERS:
        format = '>' + str(int(len(result.data) / 8)) + 'Q'
        counters = struct.unpack(format, result.data)
        print('Counters:', counters)
        return

    print('Unknown message id:', result.vl_msg_id)

vpp_json_dir = os.environ['VPP'] + 
'/build-root/install-vpp_debug-native/vpp/share/vpp/api/core'

# construct a list of all the json api files
jsonfiles = []
for root, dirnames, filenames in os.walk(vpp_json_dir):
    for filename in fnmatch.filter(filenames, '*.api.json'):
        jsonfiles.append(os.path.join(vpp_json_dir, filename))

if not jsonfiles:
    print('Error: no json api files found')
    exit(-1)

# use all those files to create vpp.
# Note that there will be no vpp method available before vpp.connect()
vpp = VPP(jsonfiles)
r = vpp.connect("test_papi")
print(r)

async=True
r=vpp.register_event_callback(papi_event_handler)
enable_disable = True
pid=85821      #This is pid of vpp process
r = vpp.api.want_stats()
r=vpp.register_event_callback(papi_event_handler)
sw_ifs=0
num=1
r = vpp.api.want_per_interface_simple_stats()
print(r)
sw_if_index=1
enable_disable=True
r = vpp.api.collect_detailed_interface_stats()
print(r)
#vpp.api.stats_enable_disable()
r=vpp.api.vnet_get_summary_stats()
print(r)
#
# Wait for some stats
#
time.sleep(60)
enale_disable = False
pid=85821
r = vpp.api.want_stats()
r = vpp.disconnect()


Regards,
Neha

From: Ole Troan [mailto:otr...@employees.org]
Sent: Monday, July 9, 2018 12:45 PM
To: Vadnere, Neha R <neha.r.vadn...@intel.com>
Cc: vpp-dev@lists.fd.io
Subject: Re: [vpp-dev] VPP python binding for getting interface stats in VPP 
18.07

Hi Neha,

Can you share your code?
Alternatively look around in the test/ directory for examples.

Cheers
Ole


On 9 Jul 2018, at 08:37, Neha 
<neha.r.vadn...@intel.com<mailto:neha.r.vadn...@intel.com>> wrote:
Hi Ole,

If that is correct, why I am not able to see the stats? ( I am waiting for 60 
sec for getting the stats)


Regards,
Neha

From: Ole Troan [mailto:otr...@employees.org]
Sent: Monday, July 9, 2018 12:03 PM
To: Vadnere, Neha R <neha.r.vadn...@intel.com<mailto:neha.r.vadn...@intel.com>>
Cc: vpp-dev@lists.fd.io<mailto:vpp-dev@lists.fd.io>
Subject: Re: [vpp-dev] VPP python binding for getting interface stats in VPP 
18.07

Neha,

On 9 Jul 2018, at 07:26, Neha 
<neha.r.vadn...@intel.com<mailto:neha.r.vadn...@intel.com>> wrote:
Hi,

I want to get stats from vpp python api. I am following instructions as 
specified in https://wiki.fd.io/view/VPP/Python_API. I am able to get other 
info as interface details etc. which uses dump and req/rep messages.

vpp_papi.register_event_callback(papi_event_handler) does not call the callback 
function specified, when want_stats is called.


In https://www.mail-archive.com/vpp-dev@lists.fd.io/msg03819.html it is 
mentioned
1.) client -> want_stats -> vpp
2.) vpp -> want_stats_reply -> client (confirms subscription)
3.) vpp -> <various stats messages> -> client (when timer fires)

in step 3.), client needs to read the shared memory queue in the
vpp->client direction (or use the appropriate XXX_read() function). Note
that stats take a few seconds to arrive (the test programs require
10-15 seconds of runtime to get some stats).

But not sure where these read_from_shared_mem functions are. I assumed that 
want_stats will send the stats when enabled.
Please guide on this.

That’s correct, the Python language binding takes care of reading from shared 
memory.
Sounds like you have done everything right.

Cheers
Ole




Regards,
Neha

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#9801): https://lists.fd.io/g/vpp-dev/message/9801
Mute This Topic: https://lists.fd.io/mt/23196484/675193
Group Owner: vpp-dev+ow...@lists.fd.io<mailto:vpp-dev+ow...@lists.fd.io>
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  
[otr...@employees.org<mailto:otr...@employees.org>]
-=-=-=-=-=-=-=-=-=-=-=-
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#9803): https://lists.fd.io/g/vpp-dev/message/9803
Mute This Topic: https://lists.fd.io/mt/23196484/675193
Group Owner: vpp-dev+ow...@lists.fd.io<mailto:vpp-dev+ow...@lists.fd.io>
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  
[otr...@employees.org<mailto:otr...@employees.org>]
-=-=-=-=-=-=-=-=-=-=-=-
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#9817): https://lists.fd.io/g/vpp-dev/message/9817
Mute This Topic: https://lists.fd.io/mt/23196484/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to