2 *------------------------------------------------------------------
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 *------------------------------------------------------------------
21 #include <sys/types.h>
22 #include <sys/socket.h>
25 #include <netinet/in.h>
28 #include <time.h> /* time_t, time (for timestamp in second) */
29 #include <sys/timeb.h> /* ftime, timeb (for timestamp in millisecond) */
30 #include <sys/time.h> /* gettimeofday, timeval (for timestamp in microsecond) */
32 #include <vnet/vnet.h>
33 #include <vlib/vlib.h>
34 #include <vlib/unix/unix.h>
35 #include <vlibapi/api.h>
36 #include <vlibmemory/api.h>
37 #include <vnet/ip/ip.h>
39 #include <vpp-api/vpe_msg_enum.h>
44 #define vl_typedefs /* define message structures */
45 #include <vpp-api/vpe_all_api_h.h>
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 memset (mp, 0, sizeof (*mp)); \
58 mp->_vl_msg_id = ntohs (VL_API_##T); \
59 mp->client_index = am->my_client_index; \
65 wrap_pneum_callback (char *data, int len)
67 //printf("Callback %d\n", len);
69 result_msg_id = ntohs(*((u16 *)data));
73 int main (int argc, char ** argv)
75 api_main_t * am = &api_main;
76 vl_api_show_version_t message;
77 vl_api_show_version_t *mp;
79 int rv = pneum_connect("pneum_client", NULL);
82 printf("Connect failed: %d\n", rv);
86 struct timeb timer_msec;
87 long long int timestamp_msec_start; /* timestamp in millisecond. */
88 if (!ftime(&timer_msec)) {
89 timestamp_msec_start = ((long long int) timer_msec.time) * 1000ll +
90 (long long int) timer_msec.millitm;
93 timestamp_msec_start = -1;
98 * Test vpe_api_write and vpe_api_read to send and recv message for an
102 long int no_msgs = 10000;
105 for (i = 0; i < no_msgs; i++) {
106 /* Construct the API message */
107 M_NOALLOC(SHOW_VERSION, show_version);
108 pneum_write((char *)mp, sizeof(*mp));
110 while (result_ready == 0);
113 vl_api_control_ping_t control;
114 vl_api_control_ping_t *mp;
116 M_NOALLOC(CONTROL_PING, control_ping);
117 pneum_write((char *)mp, sizeof(*mp));
119 while (result_msg_id != VL_API_CONTROL_PING_REPLY);
122 long long int timestamp_msec_end; /* timestamp in millisecond. */
123 if (!ftime(&timer_msec)) {
124 timestamp_msec_end = ((long long int) timer_msec.time) * 1000ll +
125 (long long int) timer_msec.millitm;
128 timestamp_msec_end = -1;
131 printf("Took %lld msec, %lld msgs/msec \n", (timestamp_msec_end - timestamp_msec_start),
132 no_msgs/(timestamp_msec_end - timestamp_msec_start));
133 fformat(stdout, "Exiting...\n");