2 *------------------------------------------------------------------
3 * test.c -- VPP API/Stats tests
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
22 #include <sys/types.h>
23 #include <sys/socket.h>
26 #include <netinet/in.h>
30 #include <vnet/vnet.h>
31 #include <vlib/vlib.h>
32 #include <vlib/unix/unix.h>
33 #include <vlibapi/api.h>
34 #include <vppinfra/time.h>
35 #include <vpp/api/vpe_msg_enum.h>
37 #include "vppapiclient.h"
38 #include "stat_client.h"
40 #define vl_typedefs /* define message structures */
41 #include <vpp/api/vpe_all_api_h.h>
44 /* we are not linking with vlib */
45 vlib_main_t vlib_global_main;
46 vlib_main_t **vlib_mains;
48 volatile int sigterm_received = 0;
49 volatile u32 result_ready;
50 volatile u16 result_msg_id;
52 /* M_NOALLOC: construct, but don't yet send a message */
54 #define M_NOALLOC(T,t) \
57 clib_memset (mp, 0, sizeof (*mp)); \
58 mp->_vl_msg_id = ntohs (VL_API_##T); \
59 mp->client_index = am->my_client_index; \
65 wrap_vac_callback (unsigned char *data, int len)
68 result_msg_id = ntohs(*((u16 *)data));
75 int rv = vac_connect("vac_client", NULL, wrap_vac_callback, 32 /* rx queue-length*/);
77 printf("Connect failed: %d\n", rv);
88 api_main_t * am = vlibapi_get_main();
89 vl_api_show_version_t message;
90 vl_api_show_version_t *mp;
93 int rv = vac_connect("vac_client", NULL, wrap_vac_callback, 32 /* rx queue-length*/);
95 printf("Connect failed: %d\n", rv);
99 double timestamp_start = unix_time_now_nsec() * 1e-6;
102 * Test vpe_api_write and vpe_api_read to send and recv message for an
106 long int no_msgs = 10000;
109 for (i = 0; i < no_msgs; i++) {
110 /* Construct the API message */
111 M_NOALLOC(SHOW_VERSION, show_version);
112 vac_write((char *)mp, sizeof(*mp));
114 /* As given, async is always 1. Shut up Coverity about it */
116 while (result_ready == 0);
120 vl_api_control_ping_t control;
121 vl_api_control_ping_t *mp;
123 M_NOALLOC(CONTROL_PING, control_ping);
124 vac_write((char *)mp, sizeof(*mp));
126 while (result_msg_id != VL_API_CONTROL_PING_REPLY);
129 double timestamp_end = unix_time_now_nsec() * 1e-6;
130 printf("\nTook %.2f msec, %.0f msgs/msec \n", (timestamp_end - timestamp_start),
131 no_msgs/(timestamp_end - timestamp_start));
132 printf("Exiting...\n");
139 clib_mem_trace_enable_disable(1);
142 int rv = stat_segment_connect (STAT_SEGMENT_SOCKET_FILE);
147 stat_segment_data_t *res;
149 vec_add1(pattern, (u8 *)"/if/names");
150 vec_add1(pattern, (u8 *)"/err");
152 dir = stat_segment_ls ((u8 **)pattern);
154 res = stat_segment_dump (dir);
155 for (i = 0; i < vec_len (res); i++) {
156 switch (res[i].type) {
157 case STAT_DIR_TYPE_NAME_VECTOR:
158 if (res[i].name_vector == 0)
160 for (k = 0; k < vec_len (res[i].name_vector); k++)
161 if (res[i].name_vector[k])
162 fformat (stdout, "[%d]: %s %s\n", k, res[i].name_vector[k],
165 case STAT_DIR_TYPE_ERROR_INDEX:
166 for (j = 0; j < vec_len (res[i].error_vector); j++)
167 fformat (stdout, "%llu %s\n", res[i].error_vector[j],
174 stat_segment_data_free (res);
175 stat_segment_disconnect();
180 (void) clib_mem_trace_enable_disable (0);
181 u8 *leak_report = format (0, "%U", format_mheap, clib_mem_get_heap (),
182 1 /* verbose, i.e. print leaks */ );
183 printf("%s", leak_report);
184 vec_free (leak_report);
188 int main (int argc, char ** argv)
190 clib_mem_init (0, 3ULL << 30);
195 for (i = 0; i < 1000; i++) {