aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_stats.py
AgeCommit message (Collapse)AuthorFilesLines
2024-03-26tests: Add a socket timeoutTom Jones1-0/+6
On FreeBSD a races seems to occur between the states socket connecting and VPP accepting the connection and calling getpeername. The recv_fd call here will fail with no fds before the VPP process has time to handle the connection. Introducing a socket timeout removes this failure on FreeBSD and allows the test suite to run. Add a timeout on all platforms to try to avoid this race everywhere. Type: improvement Change-Id: I96f77f924a9491222bc213b534cb17001d081f3f Signed-off-by: Tom Jones <thj@freebsd.org>
2024-03-26papi: Use CMSG_SPACE for sizing ancillary buffer spaceTom Jones1-1/+1
CMSG_LEN provides the length required to store an ancillary item, but it does not consider padding. RFC 3542 requires portable applications to use CMSG_SPACE(), this is documented in the python API: https://docs.python.org/3/library/socket.html#socket.CMSG_LEN Type: improvement Change-Id: I0eab470585f2f39bea38639db95d6b0e047d2cff Signed-off-by: Tom Jones <thj@freebsd.org>
2022-05-10tests: replace pycodestyle with blackKlement Sekera1-135/+173
Drop pycodestyle for code style checking in favor of black. Black is much faster, stable PEP8 compliant code style checker offering also automatic formatting. It aims to be very stable and produce smallest diffs. It's used by many small and big projects. Running checkstyle with black takes a few seconds with a terse output. Thus, test-checkstyle-diff is no longer necessary. Expand scope of checkstyle to all python files in the repo, replacing test-checkstyle with checkstyle-python. Also, fixstyle-python is now available for automatic style formatting. Note: python virtualenv has been consolidated in test/Makefile, test/requirements*.txt which will eventually be moved to a central location. This is required to simply the automated generation of docker executor images in the CI. Type: improvement Change-Id: I022a326603485f58585e879ac0f697fceefbc9c8 Signed-off-by: Klement Sekera <klement.sekera@gmail.com> Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
2022-03-31stats: convert error counters to normal countersDamjan Marion1-61/+15
Change-Id: I9794da718805b40cc922e4f3cf316255398029a9 Type: improvement Signed-off-by: Damjan Marion <damarion@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com>
2021-08-31stats: check epoch in python vpp_stats lsOle Troan1-0/+3
The VPP Stats Python binding was missing checking epoch. Resulting it would not pick up changes in the directory. Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I3226d71c77be2e80e24b5cd48fc9820833f7d30e Signed-off-by: Ole Troan <ot@cisco.com>
2021-06-25stats: reverts part of a fix on Python clientArthur de Kerhor1-12/+4
Puts return statements back inside code blocks under the lock Type: fix Change-Id: I76d426f336200035026b92bcb0ffe2b472a3142d Signed-off-by: Arthur de Kerhor <arthurdekerhor@gmail.com>
2021-06-25stats: fix race conditions in vpp-api stats clientArthur de Kerhor1-4/+12
Type: fix Signed-off-by: Arthur de Kerhor <arthurdekerhor@gmail.com> Signed-off-by: Dave Wallace <dwallacelf@gmail.com> Change-Id: Ie5c197f6ec0d41d5e405b22662701d83ad94d29e
2021-05-21stats: catch stat segment overrun in retry loopOle Troan1-3/+3
Raise IOError so that the blocking code retries not only on optimistic locking failures but also on data segment illegal reads. Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I6bb250e239486b60192004271c1690e790513318
2021-05-04stats: adding symlinks for nodes and interfaces in the stat segmentArthur de Kerhor1-40/+88
A given interface counter (e.g rx) can be accessed via /interfaces/<interface_name>/<counter_name>. Same goes with nodes: /nodes/<node_name>/<counter_name> As interfaces may contain '/' in their names, these are replaced by '_' in symlinks Also added 2 tests for the stat segment Type: feature Signed-off-by: Arthur de Kerhor <arthurdekerhor@gmail.com> Change-Id: I27da252e7b3dc177815616ca46b5c200a456bf0f Signed-off-by: Ole Troan <ot@cisco.com>
2021-04-15papi: fix ubuntu 1804 make test socket.close errorTianyu Li1-1/+1
make test failed on ubuntu 18.04 File "/vpp/src/vpp-api/python/vpp_papi/vpp_stats.py", line 135, in connect socket.close(mfd) AttributeError: module 'socket' has no attribute 'close' Due to ubuntu 18.04 using python3.6 and socket.close() is introduced since python3.7 Using os.close to replace socket.close as mfd is a memory fd Type: fix Signed-off-by: Tianyu Li <tianyu.li@arm.com> Change-Id: I6d980fc87ae6c77bbed416879f9b2fcd0a0abe6a
2021-03-30stats: python: handle when pattern is not list in lsOle Troan1-0/+9
The reimplementation of python stats module mishandled the case where pattern to ls was not a list. Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I9ba189423a76f2fd4298c4c4b19a0875f705d719
2021-03-25stats: python vpp_stats rewrite to access stat segment directlyOle Troan1-296/+482
This module implement Python access to the VPP statistics segment. It accesses the data structures directly in shared memory. VPP uses optimistic locking, so data structures may change underneath us while we are reading. Data is copied out and it's important to spend as little time as possible "holding the lock". Counters are stored in VPP as a two dimensional array. Index by thread and index (typically sw_if_index). Simple counters count only packets, Combined counters count packets and octets. Counters can be accessed in either dimension. stat['/if/rx'] - returns 2D lists stat['/if/rx'][0] - returns counters for all interfaces for thread 0 stat['/if/rx'][0][1] - returns counter for interface 1 on thread 0 stat['/if/rx'][0][1]['packets'] - returns the packet counter for interface 1 on thread 0 stat['/if/rx'][:, 1] - returns the counters for interface 1 on all threads stat['/if/rx'][:, 1].packets() - returns the packet counters for interface 1 on all threads stat['/if/rx'][:, 1].sum_packets() - returns the sum of packet counters for interface 1 on all threads stat['/if/rx-miss'][:, 1].sum() - returns the sum of packet counters for interface 1 on all threads for simple counters Type: refactor Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I1fe7f7c7d11378d06be8276db5e1900ecdb8f515 Signed-off-by: Ole Troan <ot@cisco.com>
2020-12-03papi: remove python2 patternsPaul Vinciguerra1-1/+1
Type: refactor Change-Id: I541759b4b788acf08599661eb9e7abc58e9283d2 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2020-10-07api: add heap alloc to vpp statsOle Troan1-0/+2
The Python VPP Stats module also used the VPP heap. Fix so it now explicitly allocates a heap. Fixes: f68fccfe7e188fec2c9f91da38ca9acf6f67d811 Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I0bd4ae64d6c89cdf634d8d9a91c23ab38017c5cc Signed-off-by: Ole Troan <ot@cisco.com>
2020-08-13stats: remove offsets on vpp sideOle Troan1-5/+4
Represent pointers directly in shared memory and require clients to adjust for shared memory segment being mapped at different base address. Deprecated: stat_segment_pointer() / stat_segment_offset() Added: stat_segment_adjust() Bumped the stat segment version to 2. Type: refactor Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I33e756187b8903b45dcd353e6c1a101b7a4acb79
2019-12-19papi: lazily initialize stats clientPaul Vinciguerra1-5/+25
remove wait-loop on stats socket from test framework. Type: refactor Change-Id: I5bb95a7c597707a87f9d9a471215c4b4af1a2280 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-11-05misc: Fix python scripts shebang lineRenato Botelho do Couto1-1/+1
Type: fix Since CentOS 8, RPM build script doesn't accept '#!/usr/bin/env python' as a valid shebang line. It requires scripts to explicitly chose between python2 or python3. Change all to use python3 as suggested by Paul Vinciguerra. Depends-On: https://gerrit.fd.io/r/23170 Signed-off-by: Renato Botelho do Couto <renato@netgate.com> Change-Id: Ie72af9f60fd0609e07f05b70f8d96e738b2754d1
2019-08-09stats: create /run/vpp before stat socket bind()YohanPipereau1-1/+1
When VPP tries to bind to stats.sock it will complain about non-existing /run/vpp directory. /run/vpp is created before cli socket operations are performed. The same should be done for stat socket. Ticket: VPP-1708 Type: fix Change-Id: I53d70939c8125d04a365ac51a6cbf8926dc52adf Signed-off-by: YohanPipereau <ypiperea@cisco.com> Signed-off-by: Ole Troan <ot@cisco.com>
2019-07-01papi: refactor set_errors_strPaul Vinciguerra1-3/+3
Assuming 2500 50 char lines: string_concat elapsed: 5.919933e-04 string_join elapsed: 2.830029e-04 string_concat size: 156,312,500 string_join size: 125,000 Type: refactor Change-Id: I0a400265426bde492e9a651d24996ddcfe954aa1 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-06-18misc: vpp_papi- add tests, clean up pep8Paul Vinciguerra1-4/+6
Type: test Change-Id: Ic81bd4a9eba3c89a746e7a9b9e471b59cd87fa40 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-06-14stats: add version field to stat segment base headerOle Troan1-0/+3
Add a version in the base header of the stat segment To make support for multiple reader implementations safer. Change-Id: I6816e2a51a98c2df1e621e80d4ef0b4ba4e9f47b Type: feature Signed-off-by: Ole Troan <ot@cisco.com>
2019-06-07API: Add support for "defaults"Ole Troan1-3/+7
Add support in the API language for specifying a field default. Add default support in Python binding. define foo { u16 mtu [default = 1500]; }; This is client side only. I.e. if the mtu argument is not passed to the foo function, the client language binding will set it default to 1500. Change-Id: I5df43f3cd87cb300b40ca38e15dcab25b40e424a Signed-off-by: Ole Troan <ot@cisco.com>
2019-06-04stats: removing empty object in stats vectorOle Troan1-1/+3
Type: fix Change-Id: I9b6bdacdb9a0750834de9a93d8c3f7ed827ce3c8 Signed-off-by: Ole Troan <ot@cisco.com>
2019-05-22stats: support multiple works for error countersOle Troan1-4/+15
The current code only allowed access to the main thread error counters. That is not so useful for a multi worker instance. No return a vector indexed by thread of counter_t values. Type: fix Change-Id: Ie322c8889c0c8175e1116e71de04a2cf453b9ed7 Signed-off-by: Ole Troan <ot@cisco.com>
2019-04-16stats: Add name vectors to Python clientOle Troan1-3/+21
Change-Id: Ic62dfa0bf3e082a0b999026830c64a9c543da586 Signed-off-by: Ole Troan <ot@cisco.com>
2019-03-19vpp_papi: specify encoding for .encode()/.decode()Paul Vinciguerra1-3/+3
py2 defaults to 'ascii', py3 defaults to 'utf-8'. Change-Id: Ib76d0ec56f24535e4bafd397cc6fb5e85967d508 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2019-01-06vpp-api: Add context to VPPStatsIOError.Paul Vinciguerra1-3/+25
* Provide context information and return meaningful information. VPPStatsIOError: Stat segment client connection returned: -2 Stat client socket open but couldn't connect. Change-Id: I14ea35c58452a2cb7598a7efd136f0c7e1f5743a Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2018-12-10Test framework: StringIO fixes for Python3Ole Troan1-2/+7
Add 2/3 support to binarytomac and mactobinary and move to vpp_mac.py Change-Id: I3dc7e4a24486aee22140c781aae7e44e58935877 Signed-off-by: Ole Troan <ot@cisco.com>
2018-11-29vpp_papi: Add custom exceptions.Paul Vinciguerra1-7/+21
This patchset adds and raises the following custom exception classes: * class VPPApiError(Exception): * class VPPNotImplementedError(NotImplementedError): * class VPPIOError(IOError): * class VPPRuntimeError(RuntimeError): * class VPPValueError(ValueError): * class VPPSerializerValueError(ValueError): * class VPPStatsIOError(IOError): * class VPPStatsClientLoadError(RuntimeError): * class VppTransportShmemIOError(IOError): * class VppTransportSocketIOError(IOError) Change-Id: Ia40900fd2dcef148d01125d6c691329fc666901e Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2018-11-28vpp_papi: Use new style classes.Paul Vinciguerra1-1/+1
Python2 defaults to old style classes to maintain compatability with python 2.1. Moving to new style classes will ensure consistent behavior across interpreters. Change-Id: I89493d608d1edb63989000c17a9566a97785a4aa Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2018-11-22stat_client issues while running parallel tests.Paul Vinciguerra1-9/+48
This patch addresses intermittent problems we saw in our CI while running parallel tests. Change-Id: Icb5fdb34cc134e3eb341225d56ab67fbbef80b0d Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2018-10-22PAPI: Add support for format/unformat functions.Ole Troan1-4/+5
With the introduction of new types, like vl_api_address_t it is now possible to call a message using one of those functions with a string representation. E.g. for an IP address ip_add_address(address="1.1.1.1/24") The language wrapper will automatically convert the string into the vl_api_address_t representation. Currently the caller must do the reverse conversion from the returned named tuple with the unformat function. rv = get_address_on_interface(sw_if_index=1) print(VPPFormat.unformat(rv.address)) Change-Id: Ic872b4560b2f4836255bd5260289bfa38c75bc5d Signed-off-by: Ole Troan <ot@cisco.com>
2018-09-27IPIP and IPv6 fragmentationOle Troan1-1/+2
- Error where ICMPv6 error code doesn't reset VLIB_TX = -1 Leading to crash for ICMP generated on tunnelled packets - Missed setting VNET_BUFFER_F_LOCALLY_ORIGINATED, so IP in IPv6 packets never got fragmented. - Add support for fragmentation of buffer chains. - Remove support for inner fragmentation in frag code itself. Change-Id: If9a97301b7e35ca97ffa5c0fada2b9e7e7dbfb27 Signed-off-by: Ole Troan <ot@cisco.com>
2018-09-18STATS: Optimistic concurrency handling in Python library.Ole Troan1-4/+24
Change-Id: I2135f3e77206fd171636a1e0b07c373c0bf093e4 Signed-off-by: Ole Troan <ot@cisco.com>
2018-09-18STATS: Add Python 3 support to vpp_stats.py.Ole Troan1-3/+3
Change-Id: Iad0b0315fbd493b67e6ca490206ec8e8422790ea Signed-off-by: Ole Troan <ot@cisco.com>
2018-09-17STATS: Dynamically mapped shared memory segmentOle Troan1-31/+27
Move from using a hash to a vector with offsets into shared memory. Limit exposure of VPP data structures and include files to external stats library and applications. Change-Id: Ic06129f12d10cf4c4946a86d9bc734eacff2c7da Signed-off-by: Ole Troan <ot@cisco.com>
2018-09-02STATS: Python binding to access VPP statistics and counters.Ole Troan1-0/+161
from vpp_papi.vpp_stats import VPPStats s = VPPStats(socketname='/var/run/stats.sock') c = s.ls('/if/rx') counters = s.dump(c) print(s.set_error_str()) Change-Id: I203ebe60b0c9ee5742aadc737c0f29051757959d Signed-off-by: Ole Troan <ot@cisco.com>