2 *------------------------------------------------------------------
3 * api.c - message handler registration
5 * Copyright (c) 2010 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>
25 #include <netinet/in.h>
32 #include <vppinfra/clib.h>
33 #include <vppinfra/vec.h>
34 #include <vppinfra/hash.h>
35 #include <vppinfra/bitmap.h>
36 #include <vppinfra/fifo.h>
37 #include <vppinfra/time.h>
38 #include <vppinfra/mheap.h>
39 #include <vppinfra/heap.h>
40 #include <vppinfra/pool.h>
41 #include <vppinfra/format.h>
42 #include <vppinfra/error.h>
44 #include <vnet/vnet.h>
45 #include <vlib/vlib.h>
46 #include <vlib/unix/unix.h>
47 #include <vlibapi/api.h>
48 #include <vlibmemory/api.h>
52 #include <vpp-api/vpe_msg_enum.h>
54 #include <vnet/ip/ip.h>
57 #define f64_print(a,b)
59 #define vl_typedefs /* define message structures */
60 #include <vpp-api/vpe_all_api_h.h>
63 #define vl_endianfun /* define message structures */
64 #include <vpp-api/vpe_all_api_h.h>
67 /* instantiate all the print functions we know about */
68 #define vl_print(handle, ...)
70 #include <vpp-api/vpe_all_api_h.h>
73 vl_shmem_hdr_t *shmem_hdr;
79 volatile u32 signal_received;
82 unix_shared_memory_queue_t *vl_input_queue;
84 svmdb_client_t *svmdb_client;
87 test_main_t test_main;
89 static void vl_api_control_ping_reply_t_handler
90 (vl_api_control_ping_reply_t * mp)
92 test_main_t *tm = &test_main;
94 fformat (stdout, "control ping reply from pid %d\n", ntohl (mp->vpe_pid));
99 vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...)
101 clib_warning ("BUG: vlib_cli_output callled...");
104 #define foreach_api_msg \
105 _(CONTROL_PING_REPLY,control_ping_reply)
108 ping (test_main_t * tm)
110 vl_api_control_ping_t *mp;
112 mp = vl_msg_api_alloc (sizeof (*mp));
113 memset (mp, 0, sizeof (*mp));
114 mp->_vl_msg_id = ntohs (VL_API_CONTROL_PING);
115 mp->client_index = tm->my_client_index;
116 mp->context = 0xdeadbeef;
118 vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
122 noop_handler (void *notused)
127 connect_to_vpe (char *name)
130 test_main_t *tm = &test_main;
131 api_main_t *am = &api_main;
133 rv = vl_client_connect_to_vlib ("/vpe-api", name, 32);
138 vl_msg_api_set_handlers(VL_API_##N, #n, \
139 vl_api_##n##_t_handler, \
141 vl_api_##n##_t_endian, \
142 vl_api_##n##_t_print, \
143 sizeof(vl_api_##n##_t), 1);
147 shmem_hdr = api_main.shmem_hdr;
148 tm->vl_input_queue = shmem_hdr->vl_input_queue;
149 tm->my_client_index = am->my_client_index;
154 disconnect_from_vpe (void)
156 vl_client_disconnect_from_vlib ();
162 signal_handler (int signo)
164 test_main_t *tm = &test_main;
166 tm->signal_received = 1;
171 main (int argc, char **argv)
173 test_main_t *tm = &test_main;
174 api_main_t *am = &api_main;
178 signal (SIGINT, signal_handler);
182 if (tm->signal_received)
186 swt_pid = am->shmem_hdr->vl_pid;
188 /* If kill returns 0, the vpe-f process is alive */
189 if (kill (swt_pid, 0) == 0)
194 fformat (stdout, "Connect to VPE-f\n");
195 if (connect_to_vpe ("test_ha_client") >= 0)
198 tm->pings_replied = 0;
203 fformat (stdout, "Connect failed, sleep and retry...\n");
213 /* havent heard back in 3 seconds, disco / reco */
214 if ((tm->pings_replied + 3) <= tm->pings_sent)
216 fformat (stdout, "VPE-f pid %d not responding\n", swt_pid);
218 disconnect_from_vpe ();
226 fformat (stdout, "VPE-f pid %d died\n", swt_pid);
228 disconnect_from_vpe ();
235 fformat (stdout, "Signal received, graceful exit\n");
236 disconnect_from_vpe ();
241 * fd.io coding-style-patch-verification: ON
244 * eval: (c-set-style "gnu")