Neha,

I tried this [1] and it works with output like this [2] in the latest VPP 
branch. You should follow the instructions in 
https://wiki.fd.io/view/VPP/Python_API for setting up python VPP module and 
running the script.
I will update the wiki with this.

Thanks,
Shwetha

1]
from vpp_papi import VPP                                                        
                                                                                
                                          import os
import sys
import fnmatch                                                                  
                                                                                
                                          import time

def papi_event_handler(msgname, result):                                        
                                                                                
                                            print(msgname)
  print(result)
                                                                                
                                                                                
                                          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.
vpp = VPP(jsonfiles)                                                            
                                                                                
                                          r = vpp.connect("test_papi")
print(r)
                                                                                
                                                                                
                                          async=True
r=vpp.register_event_callback(papi_event_handler)
pid=os.getpid()                                                                 
                                                                                
                                          sw_ifs = [1,2,3,4,5,6,7]
r = vpp.api.want_per_interface_simple_stats(enable_disable=True, sw_ifs=sw_ifs, 
num=len(sw_ifs), pid=pid)
print(r)                                                                        
                                                                                
                                          # Wait for some stats
time.sleep(60)
r = vpp.api.want_per_interface_simple_stats(enable_disable=False)               
                                                                                
                                          r = vpp.disconnect()


2]
>sudo -E LD_LIBRARY_PATH=$LD_LIBRARY_PATH $VPP/virtualenv/bin/python 
>test_simple_stats.py
0
want_per_interface_simple_stats_reply(_0=818, context=1, retval=0)
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158137, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=7, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158137, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=5, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158137, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=6, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158137, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=3, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158137, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=1, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158137, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=4, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158137, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=2, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158147, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=7, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158147, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=5, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158147, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=6, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158147, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=3, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158147, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=1, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158147, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=4, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])
vnet_per_interface_simple_counters
vnet_per_interface_simple_counters(_0=843, count=1, timestamp=158147, 
data=[vl_api_vnet_simple_counter_t(sw_if_index=2, drop=0, punt=0, rx_ip4=0, 
rx_ip6=0, rx_no_buffer=0, rx_miss=0, rx_error=0, tx_error=0, rx_mpls=0)])


From: <vpp-dev@lists.fd.io> on behalf of Neha <neha.r.vadn...@intel.com>
Date: Thursday, July 12, 2018 at 9:46 AM
To: Shwetha bhandari <shwet...@cisco.com>, 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,

I verified that values for ‘show api client’  and ‘os.getpid’ are same. But 
this issue is seen in all the want_* functions.
The example provided in  https://wiki.fd.io/view/VPP/Python_API does not work.
Also, examples provided in ‘src/vpp-api/python/tests/test_papi.py’ is also 
failing. There is no such class ‘vpe’ in vpp_papi.py (result.vl_msg_id == 
vpp_papi.vpe.VL_API_SW_INTERFACE_SET_FLAGS).

Can you please share working example for getting statistics from interface 
using want_stats functions?

Regards,
Neha

From: Shwetha Bhandari (shwethab) [mailto:shwet...@cisco.com]
Sent: Tuesday, July 10, 2018 2:37 PM
To: Vadnere, Neha R <neha.r.vadn...@intel.com>; Ole Troan <otr...@employees.org>
Cc: vpp-dev@lists.fd.io
Subject: Re: [vpp-dev] VPP python binding for getting interface stats in VPP 
18.07

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<mailto:vpp-dev@lists.fd.io>> on behalf of Neha 
<neha.r.vadn...@intel.com<mailto:neha.r.vadn...@intel.com>>
Date: Tuesday, July 10, 2018 at 11:46 AM
To: Ole Troan <otr...@employees.org<mailto:otr...@employees.org>>
Cc: "vpp-dev@lists.fd.io<mailto:vpp-dev@lists.fd.io>" 
<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

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<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

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 (#9826): https://lists.fd.io/g/vpp-dev/message/9826
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