Thanks, my mistake, it worked...

On Fri, 1 Oct 2021 at 13:34, Stanislav Zaikin <zsta...@gmail.com> wrote:

> You need to uncomment clib_mem_init
>
> On Fri, 1 Oct 2021 at 10:01, Venumadhav Josyula <vjosy...@gmail.com>
> wrote:
>
>> Hi Ole,
>>
>> So instead of the code below, I tried the code from
>> "src/vpp-api/client/test.c". I directly copied this into my .c file. And
>> following commands i used
>>
>> compilation + linking : - gcc vpp_api_client_vac_layer.c -o
>> vpp_api_client_vac_layer.o -lpthread -lvlibmemoryclient -lvppinfra
>> -lvppapiclient -I/usr/include/
>> code is below
>> #include<stdio.h>
>> #include<stdlib.h>
>> #include <vnet/vnet.h>
>> #include <vlib/vlib.h>
>> #include <vlib/unix/unix.h>
>> #include <vlibapi/api.h>
>> #include <vppinfra/time.h>
>> #include <vpp/api/vpe_msg_enum.h>
>> #include <signal.h>
>>
>> #include<vpp-api/client/vppapiclient.h>
>> #include<vpp-api/client/stat_client.h>
>>
>> #define vl_typedefs             /* define message structures */
>> #include <vpp/api/vpe_all_api_h.h>
>> #undef vl_typedefs
>>
>>
>> volatile int sigterm_received = 0;
>> volatile u32 result_ready;
>> volatile u16 result_msg_id;
>>
>> /* M_NOALLOC: construct, but don't yet send a message */
>>
>> #define M_NOALLOC(T,t)                          \
>>         do {                                          \
>>                 result_ready = 0;                           \
>>                 clib_memset (mp, 0, sizeof (*mp));          \
>>                 mp->_vl_msg_id = ntohs (VL_API_##T);        \
>>                 mp->client_index = am->my_client_index;     \
>>         } while(0);
>>
>> void
>> wrap_vac_callback (unsigned char *data, int len)
>> {
>>         result_ready = 1;
>>         result_msg_id = ntohs(*((u16 *)data));
>> }
>>
>>         static void
>> test_connect ()
>> {
>>         static int i;
>>         int rv = vac_connect("vac_client", NULL, wrap_vac_callback, 32 /*
>> rx queue-length*/);
>>         if (rv != 0) {
>>                 printf("Connect failed: %d\n", rv);
>>                 exit(rv);
>>         }
>>         printf(".");
>>         vac_disconnect();
>>         i++;
>> }
>>
>> static void test_messages (void)
>> {
>>         api_main_t * am = vlibapi_get_main();
>>         vl_api_show_version_t message;
>>         vl_api_show_version_t *mp;
>>         int async = 1;
>>
>>         int rv = vac_connect("vac_client", NULL, wrap_vac_callback, 32 /*
>> rx queue-length*/);
>>         if (rv != 0) {
>>                 printf("Connect failed: %d\n", rv);
>>                 exit(rv);
>>         }
>>
>>         double timestamp_start = unix_time_now_nsec() * 1e-6;
>>
>>         /*
>>          * Test vpe_api_write and vpe_api_read to send and recv message
>> for an
>>          * API
>>          */
>>         int i;
>>         long int no_msgs = 10000;
>>         mp = &message;
>>
>>         for (i = 0; i < no_msgs; i++) {
>>                 /* Construct the API message */
>>                 M_NOALLOC(SHOW_VERSION, show_version);
>>                 vac_write((char *)mp, sizeof(*mp));
>> #ifndef __COVERITY__
>>                 /* As given, async is always 1. Shut up Coverity about it
>> */
>>                 if (!async)
>>                         while (result_ready == 0);
>> #endif
>>         }
>>         if (async) {
>>                 vl_api_control_ping_t control;
>>                 vl_api_control_ping_t *mp;
>>                 mp = &control;
>>                 M_NOALLOC(CONTROL_PING, control_ping);
>>                 vac_write((char *)mp, sizeof(*mp));
>>
>>                 while (result_msg_id != VL_API_CONTROL_PING_REPLY);
>>         }
>>
>>         double timestamp_end = unix_time_now_nsec() * 1e-6;
>>         printf("\nTook %.2f msec, %.0f msgs/msec \n", (timestamp_end -
>> timestamp_start),
>>                         no_msgs/(timestamp_end - timestamp_start));
>>         printf("Exiting...\n");
>>         vac_disconnect();
>> }
>>
>>
>> int main (int argc, char ** argv)
>> {
>> #if 0
>>         clib_mem_init (0, 3ULL << 30);
>>         test_stats();
>> #endif
>>
>>         int i;
>>
>>         for (i = 0; i < 1000; i++) {
>>                 test_connect();
>>         }
>>
>>         test_messages();
>>         exit (0);
>> }
>>
>> It compiled successfully, i got following assert for heap
>> [root@8f57181df3a1 vpp_c_api_examples]# gdb ./vpp_api_client_vac_layer.o
>> GNU gdb (GDB) Red Hat Enterprise Linux 8.3-3.el7
>> Copyright (C) 2019 Free Software Foundation, Inc.
>> License GPLv3+: GNU GPL version 3 or later <
>> http://gnu.org/licenses/gpl.html>
>> This is free software: you are free to change and redistribute it.
>> There is NO WARRANTY, to the extent permitted by law.
>> Type "show copying" and "show warranty" for details.
>> This GDB was configured as "x86_64-redhat-linux-gnu".
>> Type "show configuration" for configuration details.
>> For bug reporting instructions, please see:
>> <http://www.gnu.org/software/gdb/bugs/>.
>> Find the GDB manual and other documentation resources online at:
>>     <http://www.gnu.org/software/gdb/documentation/>.
>>
>> For help, type "help".
>> Type "apropos word" to search for commands related to "word"...
>> Reading symbols from ./vpp_api_client_vac_layer.o...
>> (No debugging symbols found in ./vpp_api_client_vac_layer.o)
>> (gdb) r
>> Starting program: /root/vpp_c_api_examples/vpp_api_client_vac_layer.o
>> Missing separate debuginfos, use: debuginfo-install
>> glibc-2.17-324.el7_9.x86_64
>> [Thread debugging using libthread_db enabled]
>> Using host libthread_db library "/lib64/libthread_db.so.1".
>> vpp_api_client_vac_layer.o:
>> /vpp/build-root/rpmbuild/vpp-21.06.0/src/vpp-api/client/client.c:295:
>> vac_connect: Assertion `clib_mem_get_heap ()' failed.
>>
>> Program received signal SIGABRT, Aborted.
>> 0x00007ffff7827387 in raise () from /lib64/libc.so.6
>> (gdb) bt
>> #0  0x00007ffff7827387 in raise () from /lib64/libc.so.6
>> #1  0x00007ffff7828a78 in abort () from /lib64/libc.so.6
>> #2  0x00007ffff78201a6 in __assert_fail_base () from /lib64/libc.so.6
>> #3  0x00007ffff7820252 in __assert_fail () from /lib64/libc.so.6
>> #4  0x00007ffff7f57bcd in vac_connect (name=0x402010 "vac_client",
>> chroot_prefix=0x0, cb=0x4011d2 <wrap_vac_callback>, rx_qlen=32)
>>     at /usr/src/debug/vpp-21.06.0/src/vpp-api/client/client.c:314
>> #5  0x0000000000401227 in test_connect ()
>> #6  0x0000000000401687 in main ()
>> (gdb)
>>
>> Startup.conf
>> [root@8f57181df3a1 vpp_c_api_examples]# cat /etc/vpp/startup.conf
>> unix {
>>   #nodaemon
>>   #interactive
>>   log /var/log/vpp/vpp.log
>>   cli-listen /run/vpp/cli.sock
>>   gid vpp
>>   #exec /etc/ipsec-setup.txt
>> }
>>
>> cpu {
>>   main-core 2
>> }
>>
>> dpdk {
>>   dev default {
>>      num-rx-desc 512
>>      num-tx-desc 512
>>   }
>>   socket-mem 1024
>>   dev 0000:00:04.0
>>   uio-driver uio_pci_generic
>> }
>>
>> logging {
>>   default-log-level debug
>>   default-syslog-log-level info
>> }
>> [root@8f57181df3a1 vpp_c_api_examples]#
>> I
>> Is there some setting  i need to do in the startup.conf ?
>>
>> Please suggest a way to fix this assert.
>>
>> Thanks,
>> Regards
>> Venu
>>
>> On Thu, 30 Sept 2021 at 21:08, Benoit Ganne (bganne) <bga...@cisco.com>
>> wrote:
>>
>>> You should remove -lvlib it is not needed here.
>>> If you really want to link with vlib, you must fix the link ordering:
>>> vlib depends upon vppinfra (where os_exit is defined) so you'd need link as
>>> -lvlib -lvppinfra instead of the opposite (the C linker scan libraries
>>> symbols in reverse order, so symbols declared in a library are available to
>>> libraries listed *before*).
>>>
>>> Best
>>> ben
>>>
>>> > -----Original Message-----
>>> > From: vpp-dev@lists.fd.io <vpp-dev@lists.fd.io> On Behalf Of
>>> Venumadhav
>>> > Josyula
>>> > Sent: jeudi 30 septembre 2021 16:09
>>> > To: Akash S R <akashsr.akas...@gmail.com>
>>> > Cc: Benoit Ganne (bganne) <bga...@cisco.com>; Ole Troan
>>> > <otr...@employees.org>; RaviKiran Veldanda <ravi.jup...@gmail.com>;
>>> vpp-
>>> > dev <vpp-dev@lists.fd.io>
>>> > Subject: Re: [vpp-dev] VPP Socket API how to use from the application
>>> > #socket-api #vpp #sock-api
>>> >
>>> > Hi Akash,
>>> >
>>> > Thansks, now after devtoolset,
>>> >
>>> >
>>> > @Benoit Ganne (bganne) <mailto:bga...@cisco.com>  , @Ole Troan
>>> > <mailto:otr...@employees.org>
>>> >
>>> > i am getting following error
>>> >
>>> > [root@8f57181df3a1 vpp_c_api_examples]# gcc vpp_api_client_test3.c -o
>>> > vpp_api_client_test3.o -lvlibmemoryclient -lsvm -lvppinfra -lvlib
>>> > /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld:
>>> > /lib/../lib64/libvlib.so: undefined reference to
>>> > `classify_get_trace_chain'
>>> > /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld:
>>> > /lib/../lib64/libvlib.so: undefined reference to
>>> > `stat_segment_register_gauge'
>>> > /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld:
>>> > /lib/../lib64/libvlib.so: undefined reference to `os_exit'
>>> > collect2: error: ld returned 1 exit status
>>> > [root@8f57181df3a1 vpp_c_api_examples]#
>>> >
>>> > Let me paste the code again,
>>> > #include<stdio.h>
>>> > #include<stdlib.h>
>>> > #include <vlibapi/api.h>
>>> > #include <vlibmemory/api.h>
>>> > #include <vpp/api/vpe_msg_enum.h>
>>> >
>>> > #define vl_typedefs
>>> > #define vl_endianfun
>>> > #include <vpp/api/vpe_all_api_h.h>
>>> > #undef vl_typedefs
>>> > #undef vl_endianfun
>>> >
>>> > int main()
>>> > {
>>> >    char *name = "vpp-test-app";
>>> >
>>> >    clib_mem_init_thread_safe (0, 64ULL << 20);
>>> >
>>> >    if (vl_client_api_map("/vpe-api"))
>>> >    {
>>> >         printf("unable to map....\n");
>>> >         goto quit;
>>> >    }
>>> >    if (vl_client_connect("vpp-test-app", 0, 32) < 0)
>>> >    {
>>> >         printf("unable to connect \n");
>>> >         vl_client_api_unmap();
>>> >         goto quit;
>>> >    }
>>> >    printf("successfully connected... \n");
>>> >  quit:
>>> >         return 0;
>>> > }
>>> >
>>> > Is this wrong way, i am trying to use APIs ?
>>> >
>>> > Thanks,
>>> > Regards
>>> > Venu
>>> >
>>> >
>>> > On Thu, 30 Sept 2021 at 19:00, Akash S R <akashsr.akas...@gmail.com
>>> > <mailto:akashsr.akas...@gmail.com> > wrote:
>>> >
>>> >
>>> >       Hey Venu,
>>> >
>>> >       Try "scl enable devtoolset-9 bash" inside your docker or update
>>> your
>>> > gcc version.
>>> >
>>> >
>>> >       /Akash S R
>>> >
>>> >       On Thu, Sep 30, 2021, 18:54 Venumadhav Josyula <
>>> vjosy...@gmail.com
>>> > <mailto:vjosy...@gmail.com> > wrote:
>>> >
>>> >
>>> >               Hi Benoit,
>>> >
>>> >               Thanks for quick reply.
>>> >
>>> >               I have docker with following
>>> >               [root@8f57181df3a1 vpp_c_api_examples]# rpm -qa | grep
>>> vpp
>>> >               vpp-lib-21.06.0-4~g0d9d3a0.x86_64
>>> >               vpp-api-lua-21.06.0-4~g0d9d3a0.x86_64
>>> >               vpp-api-python3-21.06.0-4~g0d9d3a0.x86_64
>>> >               vpp-debuginfo-21.06.0-4~g0d9d3a0.x86_64
>>> >               vpp-selinux-policy-21.06.0-4~g0d9d3a0.x86_64
>>> >               vpp-21.06.0-4~g0d9d3a0.x86_64
>>> >               vpp-plugins-21.06.0-4~g0d9d3a0.x86_64
>>> >               vpp-devel-21.06.0-4~g0d9d3a0.x86_64
>>> >
>>> >               This will vpp running in it.
>>> >
>>> >               [root@8f57181df3a1 /]# cat /etc/redhat-release
>>> >               CentOS Linux release 7.3.1611 (Core)
>>> >               [root@8f57181df3a1 /]#
>>> >
>>> >               > Eg. use devtoolset-9 (gcc-9).
>>> >
>>> >
>>> >               How do I use it ?
>>> >
>>> >               Thanks,
>>> >               Regards,
>>> >               Venu
>>> >
>>> >
>>> >               On Thu, 30 Sept 2021 at 18:47, Benoit Ganne (bganne)
>>> > <bga...@cisco.com <mailto:bga...@cisco.com> > wrote:
>>> >
>>> >
>>> >                       You should upgrade your compiler... GCC-4 is way
>>> too
>>> > old.
>>> >                       Eg. use devtoolset-9 (gcc-9).
>>> >
>>> >                       Best
>>> >                       ben
>>> >
>>> >                       > -----Original Message-----
>>> >                       > From: vpp-dev@lists.fd.io <mailto:
>>> vpp-dev@lists.fd.io>
>>> > <vpp-dev@lists.fd.io <mailto:vpp-dev@lists.fd.io> > On Behalf Of
>>> > Venumadhav
>>> >                       > Josyula
>>> >                       > Sent: jeudi 30 septembre 2021 14:49
>>> >                       > To: otr...@employees.org <mailto:
>>> otr...@employees.org>
>>> >                       > Cc: RaviKiran Veldanda <ravi.jup...@gmail.com
>>> > <mailto:ravi.jup...@gmail.com> >; vpp-dev <vpp-
>>> >                       > d...@lists.fd.io <mailto:d...@lists.fd.io> >
>>> >                       > Subject: Re: [vpp-dev] VPP Socket API how to
>>> use from
>>> > the application
>>> >                       > #socket-api #vpp #sock-api
>>> >                       >
>>> >                       > Hi Ole / Others,
>>> >                       >
>>> >                       >
>>> >                       >
>>> >                       > Thanks for your email, i getting following
>>> compilation
>>> > error
>>> >                       > [root@8f57181df3a1 vpp_c_api_examples]# gcc
>>> > vpp_api_client_test3.c -o
>>> >                       > vpp_api_client_test3.o -lvlibmemoryclient
>>> -lsvm -
>>> > lvppinfra -lvlib
>>> >                       > In file included from
>>> > /usr/include/vppinfra/error.h:41:0,
>>> >                       >                  from
>>> /usr/include/vlibapi/api.h:24,
>>> >                       >                  from vpp_api_client_test3.c:3:
>>> >                       > /usr/include/vppinfra/clib.h:43:18: error:
>>> missing
>>> > binary operator before
>>> >                       > token "("
>>> >                       >  #if __has_include(<vppinfra/config.h>)
>>> >                       >                   ^
>>> >                       > In file included from
>>> > /usr/include/vppinfra/mem.h:49:0,
>>> >                       >                  from
>>> /usr/include/vppinfra/vec.h:42,
>>> >                       >                  from
>>> > /usr/include/vppinfra/error.h:53,
>>> >                       >                  from
>>> /usr/include/vlibapi/api.h:24,
>>> >                       >                  from vpp_api_client_test3.c:3:
>>> >                       > /usr/include/vppinfra/string.h:92:34: error:
>>> expected
>>> > ';', ',' or ')'
>>> >                       > before 'dst'
>>> >                       >  clib_memcpy_fast (void *restrict dst, const
>>> void
>>> > *restrict src, size_t n)
>>> >                       >                                   ^
>>> >                       > [root@8f57181df3a1 vpp_c_api_examples]# vim
>>> > /usr/include/vppinfra/clib.h
>>> >                       > +43
>>> >                       > [root@8f57181df3a1 vpp_c_api_examples]# vim
>>> > /usr/include/vppinfra/clib.h
>>> >                       > +43
>>> >                       > [root@8f57181df3a1 vpp_c_api_examples]# gcc
>>> --version
>>> >                       > gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
>>> >                       > Copyright (C) 2015 Free Software Foundation,
>>> Inc.
>>> >                       > This is free software; see the source for
>>> copying
>>> > conditions.  There is NO
>>> >                       > warranty; not even for MERCHANTABILITY or
>>> FITNESS FOR
>>> > A PARTICULAR
>>> >                       > PURPOSE.
>>> >                       >
>>> >                       > [root@8f57181df3a1 vpp_c_api_examples]#
>>> >                       >
>>> >                       >
>>> >                       > -----------------
>>> >                       >
>>> >                       > c -code
>>> >                       > ----------------
>>> >                       >
>>> >                       >
>>> >                       > #include<stdio.h>
>>> >                       > #include<stdlib.h>
>>> >                       > #include <vlibapi/api.h>
>>> >                       > #include <vlibmemory/api.h>
>>> >                       > #include <vpp/api/vpe_msg_enum.h>
>>> >                       >
>>> >                       > #define vl_typedefs
>>> >                       > #define vl_endianfun
>>> >                       > #include <vpp/api/vpe_all_api_h.h>
>>> >                       > #undef vl_typedefs
>>> >                       > #undef vl_endianfun
>>> >                       >
>>> >                       > int main()
>>> >                       > {
>>> >                       >    char *name = "vpp-test-app";
>>> >                       >
>>> >                       >    clib_mem_init_thread_safe (0, 64ULL << 20);
>>> >                       >
>>> >                       >    if (vl_client_api_map("/vpe-api"))
>>> >                       >    {
>>> >                       >         printf("unable to map....\n");
>>> >                       >         goto quit;
>>> >                       >    }
>>> >                       >    if (vl_client_connect("vpp-test-app", 0,
>>> 32) < 0)
>>> >                       >    {
>>> >                       >         printf("unable to connect \n");
>>> >                       >         vl_client_api_unmap();
>>> >                       >         goto quit;
>>> >                       >    }
>>> >                       >    printf("successfully connected... \n");
>>> >                       >  quit:
>>> >                       >         return 0;
>>> >                       > }
>>> >                       >
>>> >                       >
>>> >                       > ------------
>>> >                       >
>>> >                       >
>>> >                       > Can you please suggest what can i be doing
>>> worng ?
>>> >                       >
>>> >                       >
>>> >                       > Thanks,
>>> >                       > Regards,
>>> >                       > Venu
>>> >                       >
>>> >                       >
>>> >                       > On Thu, 30 Sept 2021 at 13:21, <
>>> otr...@employees.org
>>> > <mailto:otr...@employees.org>
>>> >                       > <mailto:otr...@employees.org
>>> > <mailto:otr...@employees.org> > > wrote:
>>> >                       >
>>> >                       >
>>> >                       >       Hi Venu,
>>> >                       >
>>> >                       >       > Any examples for VAPI shared to use
>>> binary
>>> > APIs ?
>>> >                       >
>>> >                       >       Try this for a start:
>>> >                       >       https://git.fd.io/vpp/tree/src/vpp-
>>> > api/vapi/vapi_c_test.c
>>> >                       >
>>> >                       >       Cheers,
>>> >                       >       Ole
>>> >                       >
>>> >                       >
>>> >
>>> >
>>> >
>>> >
>>> >
>>>
>>>
>> 
>>
>>
>
> --
> Best regards
> Stanislav Zaikin
>
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#20266): https://lists.fd.io/g/vpp-dev/message/20266
Mute This Topic: https://lists.fd.io/mt/85796959/21656
Mute #vpp:https://lists.fd.io/g/vpp-dev/mutehashtag/vpp
Mute #socket-api:https://lists.fd.io/g/vpp-dev/mutehashtag/socket-api
Mute #sock-api:https://lists.fd.io/g/vpp-dev/mutehashtag/sock-api
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