Well we have a test client which I already mentioned - vapi_c_test.c in test/ext directory. It has different test cases covering connection to VPP, byte swaps, sending and receiving messages, registering and waiting for events etc. It is using new, higher-level API bindings, which should simplify the development. You can take a look at test/ext/Makefile to see what libraries you need to link when using these bindings.
Quoting 重新开始 (2017-09-28 10:28:19) > Sorry, I do not know how to write a client. There is no documents which i > can referece. I just know the steps which a client should have. But I do > not know which functions to use. I would appricate it if you can write a > draf client. I am studying.... > Yes, for study, I add some event apis int snat. > ------------------ 原始邮件 ------------------ > 发件人: "Klement Sekera -X (ksekera - PA";<ksek...@cisco.com>; > 发送时间: 2017年9月28日(星期四) 下午4:02 > 收件人: "重新开始"<15803846...@qq.com>; > 抄送: "vpp-dev"<vpp-dev@lists.fd.io>; "Keith Burns"<alaga...@gmail.com>; > 主题: Re: 回复: [vpp-dev] 回复: 回复: How to get interface stats using > C api? > Looking at your code it seems you're not waiting for the reply at all. I > don't have experience with VAT and I don't think this is the recommended > way to write a client. Nevertheless, looking at your code, I don't see > any attempt to wait for a response. You are sending a message to VPP, > but not waiting for the reply nor the event. > > Also I see that you are referencing VL_API_SNAT_DECRYPT_EVENT but I > don't see such event anywhere. Is this something which you added, but is > not committed yet? > > Quoting 重新开始 (2017-09-28 03:23:30) > > Thank you very much! After reading this email, I understand the > calling > > event api process. But in the step 3, i do not know call which > function > > and how to call? In the test/ext/vapi_c_test.c, i can not find the > > function proto which in using. Can you write a simple client which > get > > stat event by C ? Thank you very much! > > ------------------ 原始邮件 ------------------ > > 发件人: "Klement Sekera -X (ksekera - PANTHEON TECHNOLOGIES at > > Cisco)";<ksek...@cisco.com>; > > 发送时间: 2017年9月27日(星期三) 下午3:15 > > 收件人: "重新开始"<15803846...@qq.com>;"Keith > Burns"<alaga...@gmail.com>; > > 抄送: "vpp-dev"<vpp-dev@lists.fd.io>; > > 主题: Re: [vpp-dev] 回复: 回复: How to get interface stats using C > api? > > There are new C and C++ APIs added recently to vpp source code along > > with test programs. You can take a look at test/ext/vapi_c_test.c and > > vapi_cpp_test.cpp. Functions receiving stats are named > test_stats_XXX(). > > These are there to verify that receiving events works. Functionally, > > these are the same, they just test different ways of doing stuff. > > > > At shared memory level it looks like this: > > > > 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). > > > > HTH, > > Klement > > > > Quoting 重新开始 (2017-09-27 04:55:29) > > > That is ok! > > > Now I am research calling the plugin apis by C. Especially how > to > > call > > > the event apis. I would appreciate it if you can write a brief > > client. > > > ------------------ 原始邮件 ------------------ > > > 发件人: "Keith Burns";<alaga...@gmail.com>; > > > 发送时间: 2017年9月27日(星期三) 上午10:47 > > > 收件人: "重新开始"<15803846...@qq.com>; > > > 抄送: "vpp-dev"<vpp-dev@lists.fd.io>; > > > 主题: Re: 回复: [vpp-dev] How to get interface stats using C > api? > > > Apologies, > > > It's a callback. > > > We probably need some decent literature written for how to > consume > > the > > > various C, C++, Python and Lua APIs > > > If you have a preference for any of those languages I could > write a > > brief > > > client program for you and start work on documenting this stuff. > > > On Sep 26, 2017 6:04 PM, "重新开始" <[1]15803846...@qq.com> > wrote: > > > > > > Hi, > > > Thank you for your detail information. After reading this, i > can > > > understand. But after calling > "want_per_interface_simple_stats" > > with > > > enable_disable=1, num=1 and sw_ifs[4], i do not know how to > receive > > this > > > stats. calling other function or variable? Can you tell me how > to > > > receive stats in my c program? > > > Thanks! > > > ------------------ 原始邮件 ------------------ > > > 发件人: "Keith Burns";<[2]alaga...@gmail.com>; > > > 发送时间: 2017年9月27日(星期三) 上午6:39 > > > 收件人: "重新开 > > > 始"<[3]15803846...@qq.com>;"vpp-dev"<[4]vpp-dev@lists.fd.io>; > > > 主题: Re: [vpp-dev] How to get interface stats using C api? > > > Hi there, > > > As of 17.10 you can now register for statistics on a per > interface > > > level. > > > You need the sw_if_index of the interface you want stats for, > but > > the > > > calls are in > > > [5]https://git.fd.io/vpp/tree/src/vpp/stats/stats.api > > > but as an example: > > > Register: > > > > > > autoreply define want_per_interface_simple_stats > > > { > > > u32 client_index; > > > u32 context; > > > u32 enable_disable; > > > u32 pid; > > > u32 num; > > > u32 sw_ifs[num]; > > > > > > }; > > > > > > So calling "want_per_interface_simple_stats" with > enable_disable=1, > > num=1 and sw_ifs[4] will give you > > > > > > interface_simple_stats every 10sec for sw_if_index=4. > > > > > > The content of "interface_simple_stats" looks like: > > > > > > /** \brief Simple per interface stats counters structure > > > @param count - number of elements in message > > > @param timestamp - u32 vlib timestamp for control plane > > > @param data[count] - vl_api_vnet_simple_counter_t > > > > > > */ > > > manual_print manual_endian define > vnet_per_interface_simple_counters > > > { > > > u32 count; > > > u32 timestamp; > > > vl_api_vnet_simple_counter_t data[count]; > > > }; > > > > > > Where each "vnet_simple_counter_t" looks like: > > > > > > [6]https://git.fd.io/vpp/tree/src/vnet/interface.api > > > > > > /** \brief Simple interface counter data type for > > vnet_interface_simple_counters > > > @param sw_if_index - interface indexes for counters > > > @param drop - RX or TX drops due to buffer starvation > > > @param punt - used with VNET "punt" disposition > > > @param rx_ip4 - received IP4 packets > > > @param rx_ip6 - received IP6 packets > > > @param rx_no_buffer - no RX buffers available > > > @param rx_miss - receive misses > > > @param rx_error - receive errors > > > @param tx_error - transmit errors > > > @param rx_mpls - received MPLS packet > > > > > > */ > > > typeonly manual_print manual_endian define vnet_simple_counter > > > { > > > u32 sw_if_index; > > > u64 drop; > > > u64 punt; > > > u64 rx_ip4; > > > u64 rx_ip6; > > > u64 rx_no_buffer; > > > u64 rx_miss; > > > u64 rx_error; > > > u64 tx_error; > > > u64 rx_mpls; > > > }; > > > > > > So you will get back an array of counter structs for each > sw_if_index > > you registered for. > > > > > > At the moment the impl sends on sw_if_index per reply but that is > going > > to change so that for each client we send as much in one message as > > possible. > > > > > > On Tue, Sep 26, 2017 at 4:50 AM 重新开始 > <[7]15803846...@qq.com> > > wrote: > > > > > > Hi, everyone! > > > How to get interface stats using C api? > > > For example, I want to know "GigabitEthernete/0/1" rx packets , > what > > should I do? > > > > > > Thanks > > > > > > _______________________________________________ > > > vpp-dev mailing list > > > [8]vpp-dev@lists.fd.io > > > [9]https://lists.fd.io/mailman/listinfo/vpp-dev > > > > > > References > > > > > > Visible links > > > 1. mailto:15803846...@qq.com > > > 2. mailto:alaga...@gmail.com > > > 3. mailto:15803846...@qq.com > > > 4. mailto:vpp-dev@lists.fd.io > > > 5. https://git.fd.io/vpp/tree/src/vpp/stats/stats.api > > > 6. https://git.fd.io/vpp/tree/src/vnet/interface.api > > > 7. mailto:15803846...@qq.com > > > 8. mailto:vpp-dev@lists.fd.io > > > 9. https://lists.fd.io/mailman/listinfo/vpp-dev _______________________________________________ vpp-dev mailing list vpp-dev@lists.fd.io https://lists.fd.io/mailman/listinfo/vpp-dev