Trivial: Cleanup some typos.
[vpp.git] / src / vpp / api / test_client.c
1 /*
2  *------------------------------------------------------------------
3  * api.c - message handler registration
4  *
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:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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  *------------------------------------------------------------------
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <sys/types.h>
23 #include <sys/mman.h>
24 #include <sys/stat.h>
25 #include <netinet/in.h>
26 #include <signal.h>
27 #include <pthread.h>
28 #include <unistd.h>
29 #include <time.h>
30 #include <fcntl.h>
31 #include <string.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>
43
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>
49
50 #include <vpp/api/vpe_msg_enum.h>
51
52 #include <vnet/ip/ip.h>
53 #include <vnet/interface.h>
54
55 #define f64_endian(a)
56 #define f64_print(a,b)
57
58 #define vl_typedefs             /* define message structures */
59 #include <vpp/api/vpe_all_api_h.h>
60 #undef vl_typedefs
61
62 #define vl_endianfun            /* define message structures */
63 #include <vpp/api/vpe_all_api_h.h>
64 #undef vl_endianfun
65
66 /* instantiate all the print functions we know about */
67 #define vl_print(handle, ...)
68 #define vl_printfun
69 #include <vpp/api/vpe_all_api_h.h>
70 #undef vl_printfun
71
72 vl_shmem_hdr_t *shmem_hdr;
73
74 typedef struct
75 {
76   int link_events_on;
77   int stats_on;
78   int oam_events_on;
79
80   /* convenience */
81   svm_queue_t *vl_input_queue;
82   u32 my_client_index;
83 } test_main_t;
84
85 test_main_t test_main;
86
87 /*
88  * Satisfy external references when -lvlib is not available.
89  */
90 vlib_main_t vlib_global_main;
91 vlib_main_t **vlib_mains;
92
93 void
94 vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...)
95 {
96   clib_warning ("vlib_cli_output called...");
97 }
98
99 u8 *
100 format_ethernet_address (u8 * s, va_list * args)
101 {
102   u8 *a = va_arg (*args, u8 *);
103
104   return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
105                  a[0], a[1], a[2], a[3], a[4], a[5]);
106 }
107
108 static void
109 vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
110 {
111   char *duplex, *speed;
112
113   switch (mp->link_duplex << VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT)
114     {
115     case VNET_HW_INTERFACE_FLAG_HALF_DUPLEX:
116       duplex = "half";
117       break;
118     case VNET_HW_INTERFACE_FLAG_FULL_DUPLEX:
119       duplex = "full";
120       break;
121     default:
122       duplex = "bogus";
123       break;
124     }
125   switch (mp->link_speed << VNET_HW_INTERFACE_FLAG_SPEED_SHIFT)
126     {
127     case VNET_HW_INTERFACE_FLAG_SPEED_10M:
128       speed = "10Mbps";
129       break;
130     case VNET_HW_INTERFACE_FLAG_SPEED_100M:
131       speed = "100Mbps";
132       break;
133     case VNET_HW_INTERFACE_FLAG_SPEED_1G:
134       speed = "1Gbps";
135       break;
136     case VNET_HW_INTERFACE_FLAG_SPEED_2_5G:
137       speed = "2.5Gbps";
138       break;
139     case VNET_HW_INTERFACE_FLAG_SPEED_5G:
140       speed = "5Gbps";
141       break;
142     case VNET_HW_INTERFACE_FLAG_SPEED_10G:
143       speed = "10Gbps";
144       break;
145     case VNET_HW_INTERFACE_FLAG_SPEED_20G:
146       speed = "20Gbps";
147       break;
148     case VNET_HW_INTERFACE_FLAG_SPEED_25G:
149       speed = "25Gbps";
150       break;
151     case VNET_HW_INTERFACE_FLAG_SPEED_40G:
152       speed = "40Gbps";
153       break;
154     case VNET_HW_INTERFACE_FLAG_SPEED_50G:
155       speed = "50Gbps";
156       break;
157     case VNET_HW_INTERFACE_FLAG_SPEED_56G:
158       speed = "56Gbps";
159       break;
160     case VNET_HW_INTERFACE_FLAG_SPEED_100G:
161       speed = "100Gbps";
162       break;
163     default:
164       speed = "bogus";
165       break;
166     }
167   fformat (stdout, "details: %s sw_if_index %d sup_sw_if_index %d "
168            "link_duplex %s link_speed %s",
169            mp->interface_name, ntohl (mp->sw_if_index),
170            ntohl (mp->sup_sw_if_index), duplex, speed);
171
172   if (mp->l2_address_length)
173     fformat (stdout, "  l2 address: %U\n",
174              format_ethernet_address, mp->l2_address);
175   else
176     fformat (stdout, "\n");
177 }
178
179 static void
180 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
181 {
182   fformat (stdout, "set flags: sw_if_index %d, admin %s\n",
183            ntohl (mp->sw_if_index), mp->admin_up_down ? "up" : "down");
184 }
185
186 static void
187   vl_api_sw_interface_set_flags_reply_t_handler
188   (vl_api_sw_interface_set_flags_reply_t * mp)
189 {
190   fformat (stdout, "set flags reply: reply %d\n", ntohl (mp->retval));
191 }
192
193 static void
194   vl_api_want_interface_events_reply_t_handler
195   (vl_api_want_interface_events_reply_t * mp)
196 {
197 }
198
199 static void
200 vl_api_want_stats_reply_t_handler (vl_api_want_stats_reply_t * mp)
201 {
202   fformat (stdout, "want stats reply %d\n", ntohl (mp->retval));
203 }
204
205 static void
206 vl_api_want_oam_events_reply_t_handler (vl_api_want_oam_events_reply_t * mp)
207 {
208   fformat (stdout, "want oam reply %d\n", ntohl (mp->retval));
209 }
210
211 static void
212 vl_api_ip_add_del_route_reply_t_handler (vl_api_ip_add_del_route_reply_t * mp)
213 {
214   fformat (stdout, "add_route reply %d\n", ntohl (mp->retval));
215 }
216
217 static void
218   vl_api_sw_interface_add_del_address_reply_t_handler
219   (vl_api_sw_interface_add_del_address_reply_t * mp)
220 {
221   fformat (stdout, "add_del_address reply %d\n", ntohl (mp->retval));
222 }
223
224 static void
225   vl_api_sw_interface_set_table_reply_t_handler
226   (vl_api_sw_interface_set_table_reply_t * mp)
227 {
228   fformat (stdout, "set_table reply %d\n", ntohl (mp->retval));
229 }
230
231 static void
232 vl_api_tap_connect_reply_t_handler (vl_api_tap_connect_reply_t * mp)
233 {
234   fformat (stdout, "tap connect reply %d, sw_if_index %d\n",
235            ntohl (mp->retval), ntohl (mp->sw_if_index));
236 }
237
238 static void
239 vl_api_create_vlan_subif_reply_t_handler (vl_api_create_vlan_subif_reply_t *
240                                           mp)
241 {
242   fformat (stdout, "create vlan subif reply %d, sw_if_index %d\n",
243            ntohl (mp->retval), ntohl (mp->sw_if_index));
244 }
245
246 static void vl_api_proxy_arp_add_del_reply_t_handler
247   (vl_api_proxy_arp_add_del_reply_t * mp)
248 {
249   fformat (stdout, "add del proxy arp reply %d\n", ntohl (mp->retval));
250 }
251
252 static void vl_api_proxy_arp_intfc_enable_disable_reply_t_handler
253   (vl_api_proxy_arp_intfc_enable_disable_reply_t * mp)
254 {
255   fformat (stdout, "proxy arp intfc ena/dis reply %d\n", ntohl (mp->retval));
256 }
257
258 static void vl_api_ip_neighbor_add_del_reply_t_handler
259   (vl_api_ip_neighbor_add_del_reply_t * mp)
260 {
261   fformat (stdout, "ip neighbor add del reply %d\n", ntohl (mp->retval));
262 }
263
264 #if 0
265 static void
266 vl_api_vnet_interface_counters_t_handler (vl_api_vnet_interface_counters_t *
267                                           mp)
268 {
269   char *counter_name;
270   u32 count, sw_if_index;
271   int i;
272
273   count = ntohl (mp->count);
274   sw_if_index = ntohl (mp->first_sw_if_index);
275   if (mp->is_combined == 0)
276     {
277       u64 *vp, v;
278       vp = (u64 *) mp->data;
279
280       switch (mp->vnet_counter_type)
281         {
282         case VNET_INTERFACE_COUNTER_DROP:
283           counter_name = "drop";
284           break;
285         case VNET_INTERFACE_COUNTER_PUNT:
286           counter_name = "punt";
287           break;
288         case VNET_INTERFACE_COUNTER_IP4:
289           counter_name = "ip4";
290           break;
291         case VNET_INTERFACE_COUNTER_IP6:
292           counter_name = "ip6";
293           break;
294         case VNET_INTERFACE_COUNTER_RX_NO_BUF:
295           counter_name = "rx-no-buf";
296           break;
297         case VNET_INTERFACE_COUNTER_RX_MISS:
298           counter_name = "rx-miss";
299           break;
300         case VNET_INTERFACE_COUNTER_RX_ERROR:
301           counter_name = "rx-error";
302           break;
303         case VNET_INTERFACE_COUNTER_TX_ERROR:
304           counter_name = "tx-error (fifo-full)";
305           break;
306         default:
307           counter_name = "bogus";
308           break;
309         }
310       for (i = 0; i < count; i++)
311         {
312           v = clib_mem_unaligned (vp, u64);
313           v = clib_net_to_host_u64 (v);
314           vp++;
315           fformat (stdout, "%d.%s %lld\n", sw_if_index, counter_name, v);
316           sw_if_index++;
317         }
318     }
319   else
320     {
321       vlib_counter_t *vp;
322       u64 packets, bytes;
323       vp = (vlib_counter_t *) mp->data;
324
325       switch (mp->vnet_counter_type)
326         {
327         case VNET_INTERFACE_COUNTER_RX:
328           counter_name = "rx";
329           break;
330         case VNET_INTERFACE_COUNTER_TX:
331           counter_name = "tx";
332           break;
333         default:
334           counter_name = "bogus";
335           break;
336         }
337       for (i = 0; i < count; i++)
338         {
339           packets = clib_mem_unaligned (&vp->packets, u64);
340           packets = clib_net_to_host_u64 (packets);
341           bytes = clib_mem_unaligned (&vp->bytes, u64);
342           bytes = clib_net_to_host_u64 (bytes);
343           vp++;
344           fformat (stdout, "%d.%s.packets %lld\n",
345                    sw_if_index, counter_name, packets);
346           fformat (stdout, "%d.%s.bytes %lld\n",
347                    sw_if_index, counter_name, bytes);
348           sw_if_index++;
349         }
350     }
351 }
352 #endif
353
354 /* Format an IP4 address. */
355 u8 *
356 format_ip4_address (u8 * s, va_list * args)
357 {
358   u8 *a = va_arg (*args, u8 *);
359   return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
360 }
361
362 /* Format an IP4 route destination and length. */
363 u8 *
364 format_ip4_address_and_length (u8 * s, va_list * args)
365 {
366   u8 *a = va_arg (*args, u8 *);
367   u8 l = va_arg (*args, u32);
368   return format (s, "%U/%d", format_ip4_address, a, l);
369 }
370
371 static void
372 vl_api_vnet_ip4_fib_counters_t_handler (vl_api_vnet_ip4_fib_counters_t * mp)
373 {
374   int i;
375   vl_api_ip4_fib_counter_t *ctrp;
376   u32 count;
377
378   count = ntohl (mp->count);
379
380   fformat (stdout, "fib id %d, count this msg %d\n",
381            ntohl (mp->vrf_id), count);
382
383   ctrp = mp->c;
384   for (i = 0; i < count; i++)
385     {
386       fformat (stdout, "%U: %lld packets, %lld bytes\n",
387                format_ip4_address_and_length, &ctrp->address,
388                (u32) ctrp->address_length,
389                clib_net_to_host_u64 (ctrp->packets),
390                clib_net_to_host_u64 (ctrp->bytes));
391       ctrp++;
392     }
393 }
394
395 /* Format an IP6 address. */
396 u8 *
397 format_ip6_address (u8 * s, va_list * args)
398 {
399   ip6_address_t *a = va_arg (*args, ip6_address_t *);
400   u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
401
402   i_max_n_zero = ARRAY_LEN (a->as_u16);
403   max_n_zeros = 0;
404   i_first_zero = i_max_n_zero;
405   n_zeros = 0;
406   for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
407     {
408       u32 is_zero = a->as_u16[i] == 0;
409       if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
410         {
411           i_first_zero = i;
412           n_zeros = 0;
413         }
414       n_zeros += is_zero;
415       if ((!is_zero && n_zeros > max_n_zeros)
416           || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
417         {
418           i_max_n_zero = i_first_zero;
419           max_n_zeros = n_zeros;
420           i_first_zero = ARRAY_LEN (a->as_u16);
421           n_zeros = 0;
422         }
423     }
424
425   last_double_colon = 0;
426   for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
427     {
428       if (i == i_max_n_zero && max_n_zeros > 1)
429         {
430           s = format (s, "::");
431           i += max_n_zeros - 1;
432           last_double_colon = 1;
433         }
434       else
435         {
436           s = format (s, "%s%x",
437                       (last_double_colon || i == 0) ? "" : ":",
438                       clib_net_to_host_u16 (a->as_u16[i]));
439           last_double_colon = 0;
440         }
441     }
442
443   return s;
444 }
445
446 /* Format an IP6 route destination and length. */
447 u8 *
448 format_ip6_address_and_length (u8 * s, va_list * args)
449 {
450   ip6_address_t *a = va_arg (*args, ip6_address_t *);
451   u8 l = va_arg (*args, u32);
452   return format (s, "%U/%d", format_ip6_address, a, l);
453 }
454
455 static void
456 vl_api_vnet_ip6_fib_counters_t_handler (vl_api_vnet_ip6_fib_counters_t * mp)
457 {
458   int i;
459   vl_api_ip6_fib_counter_t *ctrp;
460   u32 count;
461
462   count = ntohl (mp->count);
463
464   fformat (stdout, "fib id %d, count this msg %d\n",
465            ntohl (mp->vrf_id), count);
466
467   ctrp = mp->c;
468   for (i = 0; i < count; i++)
469     {
470       fformat (stdout, "%U: %lld packets, %lld bytes\n",
471                format_ip6_address_and_length, &ctrp->address,
472                (u32) ctrp->address_length,
473                clib_net_to_host_u64 (ctrp->packets),
474                clib_net_to_host_u64 (ctrp->bytes));
475       ctrp++;
476     }
477 }
478
479 static void
480 vl_api_oam_event_t_handler (vl_api_oam_event_t * mp)
481 {
482   fformat (stdout, "OAM: %U now %s\n",
483            format_ip4_address, &mp->dst_address,
484            mp->state == 1 ? "alive" : "dead");
485 }
486
487 static void
488 vl_api_oam_add_del_reply_t_handler (vl_api_oam_add_del_reply_t * mp)
489 {
490   fformat (stdout, "oam add del reply %d\n", ntohl (mp->retval));
491 }
492
493 static void
494 vl_api_reset_fib_reply_t_handler (vl_api_reset_fib_reply_t * mp)
495 {
496   fformat (stdout, "fib reset reply %d\n", ntohl (mp->retval));
497 }
498
499 static void
500 vl_api_dhcp_proxy_set_vss_reply_t_handler (vl_api_dhcp_proxy_set_vss_reply_t *
501                                            mp)
502 {
503   fformat (stdout, "dhcp proxy set vss reply %d\n", ntohl (mp->retval));
504 }
505
506 static void
507 vl_api_dhcp_proxy_config_reply_t_handler (vl_api_dhcp_proxy_config_reply_t *
508                                           mp)
509 {
510   fformat (stdout, "dhcp proxy config reply %d\n", ntohl (mp->retval));
511 }
512
513 static void
514 vl_api_set_ip_flow_hash_reply_t_handler (vl_api_set_ip_flow_hash_reply_t * mp)
515 {
516   fformat (stdout, "set ip flow hash reply %d\n", ntohl (mp->retval));
517 }
518
519 static void
520   vl_api_sw_interface_ip6nd_ra_config_reply_t_handler
521   (vl_api_sw_interface_ip6nd_ra_config_reply_t * mp)
522 {
523   fformat (stdout, "ip6 nd ra-config  reply %d\n", ntohl (mp->retval));
524 }
525
526 static void
527   vl_api_sw_interface_ip6nd_ra_prefix_reply_t_handler
528   (vl_api_sw_interface_ip6nd_ra_prefix_reply_t * mp)
529 {
530   fformat (stdout, "ip6 nd ra-prefix  reply %d\n", ntohl (mp->retval));
531 }
532
533 static void
534   vl_api_sw_interface_ip6_enable_disable_reply_t_handler
535   (vl_api_sw_interface_ip6_enable_disable_reply_t * mp)
536 {
537   fformat (stdout, "ip6 enable/disable reply %d\n", ntohl (mp->retval));
538 }
539
540 static void
541   vl_api_sw_interface_ip6_set_link_local_address_reply_t_handler
542   (vl_api_sw_interface_ip6_set_link_local_address_reply_t * mp)
543 {
544   fformat (stdout, "ip6 set link-local address reply %d\n",
545            ntohl (mp->retval));
546 }
547
548 static void vl_api_create_loopback_reply_t_handler
549   (vl_api_create_loopback_reply_t * mp)
550 {
551   fformat (stdout, "create loopback status %d, sw_if_index %d\n",
552            ntohl (mp->retval), ntohl (mp->sw_if_index));
553 }
554
555 static void vl_api_create_loopback_instance_reply_t_handler
556   (vl_api_create_loopback_instance_reply_t * mp)
557 {
558   fformat (stdout, "create loopback status %d, sw_if_index %d\n",
559            ntohl (mp->retval), ntohl (mp->sw_if_index));
560 }
561
562 static void vl_api_l2_patch_add_del_reply_t_handler
563   (vl_api_l2_patch_add_del_reply_t * mp)
564 {
565   fformat (stdout, "l2 patch reply %d\n", ntohl (mp->retval));
566 }
567
568 static void vl_api_sw_interface_set_l2_xconnect_reply_t_handler
569   (vl_api_sw_interface_set_l2_xconnect_reply_t * mp)
570 {
571   fformat (stdout, "l2_xconnect reply %d\n", ntohl (mp->retval));
572 }
573
574 static void vl_api_sw_interface_set_l2_bridge_reply_t_handler
575   (vl_api_sw_interface_set_l2_bridge_reply_t * mp)
576 {
577   fformat (stdout, "l2_bridge reply %d\n", ntohl (mp->retval));
578 }
579
580 static void
581 noop_handler (void *notused)
582 {
583 }
584
585 #define vl_api_vnet_ip4_fib_counters_t_endian noop_handler
586 #define vl_api_vnet_ip4_fib_counters_t_print noop_handler
587 #define vl_api_vnet_ip6_fib_counters_t_endian noop_handler
588 #define vl_api_vnet_ip6_fib_counters_t_print noop_handler
589
590 #define foreach_api_msg                                                 \
591 _(SW_INTERFACE_DETAILS, sw_interface_details)                           \
592 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags)                       \
593 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply)           \
594 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply)             \
595 _(WANT_STATS_REPLY, want_stats_reply)                                   \
596 _(WANT_OAM_EVENTS_REPLY, want_oam_events_reply)                         \
597 _(OAM_EVENT, oam_event)                                                 \
598 _(OAM_ADD_DEL_REPLY, oam_add_del_reply)                                 \
599 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters)                         \
600 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters)                         \
601 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply)                       \
602 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, sw_interface_add_del_address_reply) \
603 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply)           \
604 _(TAP_CONNECT_REPLY, tap_connect_reply)                                 \
605 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply)                     \
606 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply)                     \
607 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, proxy_arp_intfc_enable_disable_reply) \
608 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply)                 \
609 _(RESET_FIB_REPLY, reset_fib_reply)                                     \
610 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply)                     \
611 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply)                   \
612 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply)                       \
613 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, sw_interface_ip6nd_ra_config_reply) \
614 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, sw_interface_ip6nd_ra_prefix_reply) \
615 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, sw_interface_ip6_enable_disable_reply) \
616 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, sw_interface_ip6_set_link_local_address_reply) \
617  _(CREATE_LOOPBACK_REPLY, create_loopback_reply)                        \
618  _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply)      \
619 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply)                       \
620 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, sw_interface_set_l2_xconnect_reply) \
621 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, sw_interface_set_l2_bridge_reply)
622
623 int
624 connect_to_vpe (char *name)
625 {
626   int rv = 0;
627
628   rv = vl_client_connect_to_vlib ("/vpe-api", name, 32);
629
630 #define _(N,n)                                                  \
631     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
632                            vl_api_##n##_t_handler,              \
633                            noop_handler,                        \
634                            vl_api_##n##_t_endian,               \
635                            vl_api_##n##_t_print,                \
636                            sizeof(vl_api_##n##_t), 1);
637   foreach_api_msg;
638 #undef _
639
640   shmem_hdr = api_main.shmem_hdr;
641
642   return rv;
643 }
644
645 int
646 disconnect_from_vpe (void)
647 {
648   vl_client_disconnect_from_vlib ();
649   return 0;
650 }
651
652 void
653 link_up_down_enable_disable (test_main_t * tm, int enable)
654 {
655   vl_api_want_interface_events_t *mp;
656
657   /* Request admin / link up down messages */
658   mp = vl_msg_api_alloc (sizeof (*mp));
659   memset (mp, 0, sizeof (*mp));
660   mp->_vl_msg_id = ntohs (VL_API_WANT_INTERFACE_EVENTS);
661   mp->client_index = tm->my_client_index;
662   mp->context = 0xdeadbeef;
663   mp->enable_disable = enable;
664   mp->pid = getpid ();
665   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
666   tm->link_events_on = enable;
667 }
668
669 void
670 stats_enable_disable (test_main_t * tm, int enable)
671 {
672   vl_api_want_stats_t *mp;
673
674   mp = vl_msg_api_alloc (sizeof (*mp));
675   memset (mp, 0, sizeof (*mp));
676   mp->_vl_msg_id = ntohs (VL_API_WANT_STATS);
677   mp->client_index = tm->my_client_index;
678   mp->context = 0xdeadbeef;
679   mp->enable_disable = enable;
680   mp->pid = getpid ();
681   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
682   tm->stats_on = enable;
683 }
684
685 void
686 oam_events_enable_disable (test_main_t * tm, int enable)
687 {
688   vl_api_want_oam_events_t *mp;
689
690   mp = vl_msg_api_alloc (sizeof (*mp));
691   memset (mp, 0, sizeof (*mp));
692   mp->_vl_msg_id = ntohs (VL_API_WANT_OAM_EVENTS);
693   mp->client_index = tm->my_client_index;
694   mp->context = 0xdeadbeef;
695   mp->enable_disable = enable;
696   mp->pid = getpid ();
697   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
698   tm->oam_events_on = enable;
699 }
700
701 void
702 oam_add_del (test_main_t * tm, int is_add)
703 {
704   vl_api_oam_add_del_t *mp;
705   ip4_address_t tmp;
706
707   mp = vl_msg_api_alloc (sizeof (*mp));
708   memset (mp, 0, sizeof (*mp));
709   mp->_vl_msg_id = ntohs (VL_API_OAM_ADD_DEL);
710   mp->client_index = tm->my_client_index;
711   mp->context = 0xdeadbeef;
712   mp->is_add = is_add;
713
714   tmp.as_u32 = ntohl (0xc0a80101);      /* 192.168.1.1 */
715   clib_memcpy (mp->src_address, tmp.as_u8, 4);
716
717   tmp.as_u32 = ntohl (0xc0a80103);      /* 192.168.1.3 */
718   clib_memcpy (mp->dst_address, tmp.as_u8, 4);
719
720   mp->vrf_id = 0;
721   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
722 }
723
724 void
725 dump (test_main_t * tm)
726 {
727   vl_api_sw_interface_dump_t *mp;
728
729   mp = vl_msg_api_alloc (sizeof (*mp));
730   memset (mp, 0, sizeof (*mp));
731   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DUMP);
732   mp->client_index = tm->my_client_index;
733   mp->name_filter_valid = 1;
734   strncpy ((char *) mp->name_filter, "eth", sizeof (mp->name_filter) - 1);
735
736   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
737 }
738
739 void
740 add_del_ip4_route (test_main_t * tm, int enable_disable)
741 {
742   vl_api_ip_add_del_route_t *mp;
743   u32 tmp;
744
745   mp = vl_msg_api_alloc (sizeof (*mp));
746   memset (mp, 0, sizeof (*mp));
747   mp->_vl_msg_id = ntohs (VL_API_IP_ADD_DEL_ROUTE);
748   mp->client_index = tm->my_client_index;
749   mp->context = 0xdeadbeef;
750   mp->table_id = ntohl (0);
751
752   mp->next_hop_sw_if_index = ntohl (5);
753   mp->is_add = enable_disable;
754   mp->next_hop_weight = 1;
755
756   /* Next hop: 6.0.0.1 */
757   tmp = ntohl (0x06000001);
758   clib_memcpy (mp->next_hop_address, &tmp, sizeof (tmp));
759
760   /* Destination: 10.0.0.1/32 */
761   tmp = ntohl (0x0);
762   clib_memcpy (mp->dst_address, &tmp, sizeof (tmp));
763   mp->dst_address_length = 0;
764
765   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
766 }
767
768 void
769 add_del_ip6_route (test_main_t * tm, int enable_disable)
770 {
771   vl_api_ip_add_del_route_t *mp;
772   u64 tmp[2];
773
774   mp = vl_msg_api_alloc (sizeof (*mp));
775   memset (mp, 0, sizeof (*mp));
776   mp->_vl_msg_id = ntohs (VL_API_IP_ADD_DEL_ROUTE);
777   mp->client_index = tm->my_client_index;
778   mp->context = 0xdeadbeef;
779   mp->next_hop_sw_if_index = ntohl (5);
780   mp->is_add = enable_disable;
781   mp->is_ipv6 = 1;
782   mp->next_hop_weight = 1;
783   mp->dst_address_length = 64;
784
785   /* add/del dabe::/64 via db01::11 */
786
787   tmp[0] = clib_host_to_net_u64 (0xdabe000000000000ULL);
788   tmp[1] = clib_host_to_net_u64 (0x0ULL);
789   clib_memcpy (mp->dst_address, &tmp[0], 8);
790   clib_memcpy (&mp->dst_address[8], &tmp[1], 8);
791
792   tmp[0] = clib_host_to_net_u64 (0xdb01000000000000ULL);
793   tmp[1] = clib_host_to_net_u64 (0x11ULL);
794   clib_memcpy (mp->next_hop_address, &tmp[0], 8);
795   clib_memcpy (&mp->next_hop_address[8], &tmp[1], 8);
796
797   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
798 }
799
800 void
801 add_del_interface_address (test_main_t * tm, int enable_disable)
802 {
803   vl_api_sw_interface_add_del_address_t *mp;
804   u32 tmp;
805
806   mp = vl_msg_api_alloc (sizeof (*mp));
807   memset (mp, 0, sizeof (*mp));
808   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS);
809   mp->client_index = tm->my_client_index;
810   mp->context = 0xdeadbeef;
811   mp->sw_if_index = ntohl (5);
812   mp->is_add = enable_disable;
813   mp->address_length = 8;
814
815   tmp = ntohl (0x01020304);
816   clib_memcpy (mp->address, &tmp, 4);
817
818   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
819 }
820
821 void
822 add_del_v6_interface_address (test_main_t * tm, int enable_disable)
823 {
824   vl_api_sw_interface_add_del_address_t *mp;
825   u64 tmp[2];
826
827   mp = vl_msg_api_alloc (sizeof (*mp));
828   memset (mp, 0, sizeof (*mp));
829   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS);
830   mp->client_index = tm->my_client_index;
831   mp->context = 0xdeadbeef;
832   mp->is_ipv6 = 1;
833   mp->sw_if_index = ntohl (5);
834   mp->is_add = enable_disable;
835   mp->address_length = 64;
836
837   tmp[0] = clib_host_to_net_u64 (0xdb01000000000000ULL);
838   tmp[1] = clib_host_to_net_u64 (0x11ULL);
839
840   clib_memcpy (mp->address, &tmp[0], 8);
841   clib_memcpy (&mp->address[8], &tmp[1], 8);
842
843   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
844 }
845
846 void
847 del_all_interface_addresses (test_main_t * tm)
848 {
849   vl_api_sw_interface_add_del_address_t *mp;
850
851   mp = vl_msg_api_alloc (sizeof (*mp));
852   memset (mp, 0, sizeof (*mp));
853   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS);
854   mp->client_index = tm->my_client_index;
855   mp->context = 0xdeadbeef;
856   mp->sw_if_index = ntohl (5);
857   mp->del_all = 1;
858
859   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
860 }
861
862 void
863 set_interface_table (test_main_t * tm, int is_ipv6, u32 vrf_id)
864 {
865   vl_api_sw_interface_set_table_t *mp;
866
867   mp = vl_msg_api_alloc (sizeof (*mp));
868   memset (mp, 0, sizeof (*mp));
869   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_TABLE);
870   mp->client_index = tm->my_client_index;
871   mp->context = 0xdeadbeef;
872   mp->sw_if_index = ntohl (5);
873   mp->is_ipv6 = is_ipv6;
874   mp->vrf_id = ntohl (vrf_id);
875
876   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
877 }
878
879 void
880 connect_unix_tap (test_main_t * tm, char *name)
881 {
882   vl_api_tap_connect_t *mp;
883
884   mp = vl_msg_api_alloc (sizeof (*mp));
885   memset (mp, 0, sizeof (*mp));
886   mp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT);
887   mp->client_index = tm->my_client_index;
888   mp->context = 0xdeadbeef;
889   strncpy ((char *) mp->tap_name, name, sizeof (mp->tap_name) - 1);
890   mp->use_random_mac = 1;
891   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
892 }
893
894 void
895 create_vlan_subif (test_main_t * tm, u32 vlan_id)
896 {
897   vl_api_create_vlan_subif_t *mp;
898
899   mp = vl_msg_api_alloc (sizeof (*mp));
900   memset (mp, 0, sizeof (*mp));
901   mp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF);
902   mp->client_index = tm->my_client_index;
903   mp->context = 0xdeadbeef;
904   mp->sw_if_index = ntohl (5);
905   mp->vlan_id = ntohl (vlan_id);
906
907   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
908 }
909
910 void
911 add_del_proxy_arp (test_main_t * tm, int is_add)
912 {
913   vl_api_proxy_arp_add_del_t *mp;
914   u32 tmp;
915
916   mp = vl_msg_api_alloc (sizeof (*mp));
917   memset (mp, 0, sizeof (*mp));
918   mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_ADD_DEL);
919   mp->client_index = tm->my_client_index;
920   mp->context = 0xdeadbeef;
921   mp->proxy.vrf_id = ntohl (11);
922   mp->is_add = is_add;
923
924   /* proxy fib 11, 1.1.1.1 -> 1.1.1.10 */
925   tmp = ntohl (0x01010101);
926   clib_memcpy (mp->proxy.low_address, &tmp, 4);
927
928   tmp = ntohl (0x0101010a);
929   clib_memcpy (mp->proxy.hi_address, &tmp, 4);
930
931   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
932 }
933
934 void
935 proxy_arp_intfc_enable_disable (test_main_t * tm, int enable_disable)
936 {
937   vl_api_proxy_arp_intfc_enable_disable_t *mp;
938
939   mp = vl_msg_api_alloc (sizeof (*mp));
940   memset (mp, 0, sizeof (*mp));
941   mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE);
942   mp->client_index = tm->my_client_index;
943   mp->context = 0xdeadbeef;
944   mp->sw_if_index = ntohl (6);
945   mp->enable_disable = enable_disable;
946
947   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
948 }
949
950 void
951 add_ip4_neighbor (test_main_t * tm, int add_del)
952 {
953   vl_api_ip_neighbor_add_del_t *mp;
954   u32 tmp;
955
956   mp = vl_msg_api_alloc (sizeof (*mp));
957   memset (mp, 0, sizeof (*mp));
958   mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_ADD_DEL);
959   mp->client_index = tm->my_client_index;
960   mp->context = 0xdeadbeef;
961   mp->sw_if_index = ntohl (6);
962   mp->is_add = add_del;
963
964   memset (mp->mac_address, 0xbe, sizeof (mp->mac_address));
965
966   tmp = ntohl (0x0101010a);
967   clib_memcpy (mp->dst_address, &tmp, 4);
968
969   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
970 }
971
972 void
973 add_ip6_neighbor (test_main_t * tm, int add_del)
974 {
975   vl_api_ip_neighbor_add_del_t *mp;
976   u64 tmp[2];
977
978   mp = vl_msg_api_alloc (sizeof (*mp));
979   memset (mp, 0, sizeof (*mp));
980   mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_ADD_DEL);
981   mp->client_index = tm->my_client_index;
982   mp->context = 0xdeadbeef;
983   mp->sw_if_index = ntohl (6);
984   mp->is_add = add_del;
985   mp->is_ipv6 = 1;
986
987   memset (mp->mac_address, 0xbe, sizeof (mp->mac_address));
988
989   tmp[0] = clib_host_to_net_u64 (0xdb01000000000000ULL);
990   tmp[1] = clib_host_to_net_u64 (0x11ULL);
991
992   clib_memcpy (mp->dst_address, &tmp[0], 8);
993   clib_memcpy (&mp->dst_address[8], &tmp[1], 8);
994
995   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
996 }
997
998 void
999 reset_fib (test_main_t * tm, u8 is_ip6)
1000 {
1001   vl_api_reset_fib_t *mp;
1002
1003   mp = vl_msg_api_alloc (sizeof (*mp));
1004   memset (mp, 0, sizeof (*mp));
1005   mp->_vl_msg_id = ntohs (VL_API_RESET_FIB);
1006   mp->client_index = tm->my_client_index;
1007   mp->context = 0xdeadbeef;
1008   mp->vrf_id = ntohl (11);
1009   mp->is_ipv6 = is_ip6;
1010
1011   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1012 }
1013
1014 void
1015 dhcpv6_set_vss (test_main_t * tm)
1016 {
1017   vl_api_dhcp_proxy_set_vss_t *mp;
1018
1019   mp = vl_msg_api_alloc (sizeof (*mp));
1020   memset (mp, 0, sizeof (*mp));
1021   mp->_vl_msg_id = ntohs (VL_API_DHCP_PROXY_SET_VSS);
1022   mp->client_index = tm->my_client_index;
1023   mp->context = 0xdeadbeef;
1024   mp->oui = ntohl (6);
1025   mp->tbl_id = ntohl (60);
1026   mp->is_add = 1;
1027   mp->is_ipv6 = 1;
1028   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1029 }
1030
1031 void
1032 dhcpv4_set_vss (test_main_t * tm)
1033 {
1034   vl_api_dhcp_proxy_set_vss_t *mp;
1035
1036   mp = vl_msg_api_alloc (sizeof (*mp));
1037   memset (mp, 0, sizeof (*mp));
1038   mp->_vl_msg_id = ntohs (VL_API_DHCP_PROXY_SET_VSS);
1039   mp->client_index = tm->my_client_index;
1040   mp->context = 0xdeadbeef;
1041   mp->oui = ntohl (4);
1042   mp->tbl_id = ntohl (40);
1043   mp->is_add = 1;
1044   mp->is_ipv6 = 0;
1045   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1046 }
1047
1048 void
1049 dhcp_set_vss (test_main_t * tm)
1050 {
1051   dhcpv4_set_vss (tm);
1052   dhcpv6_set_vss (tm);
1053 }
1054
1055 void
1056 dhcp_set_proxy (test_main_t * tm, int ipv6)
1057 {
1058   vl_api_dhcp_proxy_config_t *mp;
1059
1060   mp = vl_msg_api_alloc (sizeof (*mp));
1061   memset (mp, 0, sizeof (*mp));
1062   mp->_vl_msg_id = ntohs (VL_API_DHCP_PROXY_CONFIG);
1063   mp->client_index = tm->my_client_index;
1064   mp->context = 0xdeadbeef;
1065   mp->is_ipv6 = ipv6;
1066   mp->is_add = 1;
1067   mp->dhcp_server[0] = 0x20;
1068   mp->dhcp_server[1] = 0x01;
1069   mp->dhcp_server[2] = 0xab;
1070   mp->dhcp_server[3] = 0xcd;
1071   mp->dhcp_server[4] = 0x12;
1072   mp->dhcp_server[5] = 0x34;
1073   mp->dhcp_server[6] = 0xfe;
1074   mp->dhcp_server[7] = 0xdc;
1075   mp->dhcp_server[14] = 0;
1076   mp->dhcp_server[15] = 0x2;
1077
1078   mp->dhcp_src_address[0] = 0x20;
1079   mp->dhcp_src_address[1] = 0x01;
1080   mp->dhcp_src_address[2] = 0xab;
1081   mp->dhcp_src_address[3] = 0xcd;
1082   mp->dhcp_src_address[4] = 0x12;
1083   mp->dhcp_src_address[5] = 0x34;
1084   mp->dhcp_src_address[6] = 0x56;
1085   mp->dhcp_src_address[7] = 0x78;
1086   mp->dhcp_src_address[14] = 0;
1087   mp->dhcp_src_address[15] = 0x2;
1088
1089   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1090 }
1091
1092 void
1093 set_ip_flow_hash (test_main_t * tm, u8 is_ip6)
1094 {
1095   vl_api_set_ip_flow_hash_t *mp;
1096
1097   mp = vl_msg_api_alloc (sizeof (*mp));
1098   memset (mp, 0, sizeof (*mp));
1099   mp->_vl_msg_id = ntohs (VL_API_SET_IP_FLOW_HASH);
1100   mp->client_index = tm->my_client_index;
1101   mp->context = 0xdeadbeef;
1102   mp->vrf_id = 0;
1103   mp->is_ipv6 = is_ip6;
1104   mp->dst = 1;
1105   mp->reverse = 1;
1106
1107   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1108 }
1109
1110 void
1111 ip6nd_ra_config (test_main_t * tm, int is_no)
1112 {
1113   vl_api_sw_interface_ip6nd_ra_config_t *mp;
1114
1115   mp = vl_msg_api_alloc (sizeof (*mp));
1116   memset (mp, 0, sizeof (*mp));
1117
1118   mp->client_index = tm->my_client_index;
1119   mp->context = 0xdeadbeef;
1120   mp->sw_if_index = ntohl (5);
1121   mp->is_no = is_no;
1122
1123   mp->suppress = 1;
1124
1125
1126   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG);
1127   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1128 }
1129
1130 void
1131 ip6nd_ra_prefix (test_main_t * tm, int is_no)
1132 {
1133   vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
1134   u64 tmp[2];
1135
1136   mp = vl_msg_api_alloc (sizeof (*mp));
1137   memset (mp, 0, sizeof (*mp));
1138
1139   mp->client_index = tm->my_client_index;
1140   mp->context = 0xdeadbeef;
1141   mp->sw_if_index = ntohl (5);
1142   mp->is_no = is_no;
1143
1144   mp->use_default = 1;
1145
1146
1147   tmp[0] = clib_host_to_net_u64 (0xdb01000000000000ULL);
1148   tmp[1] = clib_host_to_net_u64 (0x11ULL);
1149
1150
1151   clib_memcpy (mp->address, &tmp[0], 8);
1152   clib_memcpy (&mp->address[8], &tmp[1], 8);
1153
1154   mp->address_length = 64;
1155
1156
1157   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX);
1158   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1159 }
1160
1161 void
1162 ip6_enable_disable (test_main_t * tm, int enable)
1163 {
1164   vl_api_sw_interface_ip6_enable_disable_t *mp;
1165
1166   mp = vl_msg_api_alloc (sizeof (*mp));
1167   memset (mp, 0, sizeof (*mp));
1168
1169   mp->client_index = tm->my_client_index;
1170   mp->context = 0xdeadbeef;
1171   mp->sw_if_index = ntohl (5);
1172   mp->enable = (enable == 1);;
1173
1174   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE);
1175   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1176 }
1177
1178 void
1179 loop_create (test_main_t * tm)
1180 {
1181   vl_api_create_loopback_t *mp;
1182
1183   mp = vl_msg_api_alloc (sizeof (*mp));
1184   memset (mp, 0, sizeof (*mp));
1185
1186   mp->_vl_msg_id = ntohs (VL_API_CREATE_LOOPBACK);
1187   mp->client_index = tm->my_client_index;
1188   mp->context = 0xdeadbeef;
1189   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1190 }
1191
1192 void
1193 ip6_set_link_local_address (test_main_t * tm)
1194 {
1195   vl_api_sw_interface_ip6_set_link_local_address_t *mp;
1196   u64 tmp[2];
1197
1198   mp = vl_msg_api_alloc (sizeof (*mp));
1199   memset (mp, 0, sizeof (*mp));
1200
1201   mp->client_index = tm->my_client_index;
1202   mp->context = 0xdeadbeef;
1203   mp->sw_if_index = ntohl (5);
1204
1205   tmp[0] = clib_host_to_net_u64 (0xfe80000000000000ULL);
1206   tmp[1] = clib_host_to_net_u64 (0x11ULL);
1207
1208   clib_memcpy (mp->address, &tmp[0], 8);
1209   clib_memcpy (&mp->address[8], &tmp[1], 8);
1210
1211   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS);
1212
1213   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1214 }
1215
1216
1217 void
1218 set_flags (test_main_t * tm, int up_down)
1219 {
1220   vl_api_sw_interface_set_flags_t *mp;
1221
1222   mp = vl_msg_api_alloc (sizeof (*mp));
1223   memset (mp, 0, sizeof (*mp));
1224
1225   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
1226   mp->client_index = tm->my_client_index;
1227   mp->context = 0xdeadbeef;
1228   mp->sw_if_index = ntohl (5);
1229   mp->admin_up_down = up_down;
1230   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1231
1232 }
1233
1234 void
1235 l2_patch_add_del (test_main_t * tm, int is_add)
1236 {
1237   vl_api_l2_patch_add_del_t *mp;
1238
1239   mp = vl_msg_api_alloc (sizeof (*mp));
1240   memset (mp, 0, sizeof (*mp));
1241   mp->_vl_msg_id = ntohs (VL_API_L2_PATCH_ADD_DEL);
1242   mp->client_index = tm->my_client_index;
1243   mp->context = 0xdeadbeef;
1244   mp->is_add = is_add;
1245   mp->rx_sw_if_index = ntohl (1);
1246   mp->tx_sw_if_index = ntohl (2);
1247
1248   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1249 }
1250
1251 void
1252 l2_xconnect (test_main_t * tm)
1253 {
1254   vl_api_sw_interface_set_l2_xconnect_t *mp;
1255
1256   mp = vl_msg_api_alloc (sizeof (*mp));
1257   memset (mp, 0, sizeof (*mp));
1258   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_L2_XCONNECT);
1259   mp->client_index = tm->my_client_index;
1260   mp->context = 0xdeadbeef;
1261   mp->rx_sw_if_index = ntohl (5);
1262   mp->tx_sw_if_index = ntohl (6);
1263   mp->enable = 1;
1264
1265   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1266 }
1267
1268 void
1269 l2_bridge (test_main_t * tm)
1270 {
1271   vl_api_sw_interface_set_l2_bridge_t *mp;
1272
1273   mp = vl_msg_api_alloc (sizeof (*mp));
1274   memset (mp, 0, sizeof (*mp));
1275   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_L2_BRIDGE);
1276   mp->client_index = tm->my_client_index;
1277   mp->context = 0xdeadbeef;
1278   mp->rx_sw_if_index = ntohl (5);
1279   mp->bd_id = ntohl (6);
1280   mp->bvi = ntohl (1);
1281   mp->shg = ntohl (0);
1282   mp->enable = 1;
1283
1284   vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
1285 }
1286
1287 int
1288 main (int argc, char **argv)
1289 {
1290   api_main_t *am = &api_main;
1291   test_main_t *tm = &test_main;
1292   int ch;
1293
1294   connect_to_vpe ("test_client");
1295
1296   tm->vl_input_queue = shmem_hdr->vl_input_queue;
1297   tm->my_client_index = am->my_client_index;
1298
1299   fformat (stdout, "Type 'h' for help, 'q' to quit...\n");
1300
1301   while (1)
1302     {
1303       ch = getchar ();
1304       switch (ch)
1305         {
1306         case 'q':
1307           goto done;
1308         case 'd':
1309           dump (tm);
1310           break;
1311         case 'L':
1312           link_up_down_enable_disable (tm, 1 /* enable_disable */ );
1313           break;
1314         case 'l':
1315           link_up_down_enable_disable (tm, 0 /* enable_disable */ );
1316           break;
1317         case 'S':
1318           stats_enable_disable (tm, 1 /* enable_disable */ );
1319           break;
1320         case 's':
1321           stats_enable_disable (tm, 0 /* enable_disable */ );
1322           break;
1323         case '3':
1324           add_del_ip4_route (tm, 0 /* add */ );
1325           break;
1326         case '4':
1327           add_del_ip4_route (tm, 1 /* add */ );
1328           break;
1329         case '5':
1330           add_del_ip6_route (tm, 0 /* add */ );
1331           break;
1332         case '6':
1333           add_del_ip6_route (tm, 1 /* add */ );
1334           break;
1335         case 'A':
1336           add_del_interface_address (tm, 1 /* add */ );
1337           break;
1338         case 'a':
1339           add_del_interface_address (tm, 0 /* add */ );
1340           break;
1341         case 'B':
1342           add_del_v6_interface_address (tm, 1 /* add */ );
1343           break;
1344         case 'b':
1345           add_del_v6_interface_address (tm, 0 /* add */ );
1346           break;
1347         case 'E':
1348           l2_patch_add_del (tm, 1 /* is_add */ );
1349           break;
1350         case 'e':
1351           l2_patch_add_del (tm, 0 /* is_add */ );
1352           break;
1353         case 'z':
1354           del_all_interface_addresses (tm);
1355           break;
1356         case 't':
1357           set_interface_table (tm, 0 /* is_ipv6 */ ,
1358                                11 /* my amp goes to 11 */ );
1359           break;
1360         case 'T':
1361           set_interface_table (tm, 1 /* is_ipv6 */ ,
1362                                12 /* my amp goes to 12 */ );
1363           break;
1364
1365         case 'u':
1366           create_vlan_subif (tm, 123);
1367           break;
1368
1369         case 'c':
1370           connect_unix_tap (tm, "foo");
1371           break;
1372
1373         case 'n':
1374           add_ip4_neighbor (tm, 1 /* is_add */ );
1375           add_ip6_neighbor (tm, 1 /* is_add */ );
1376           break;
1377
1378         case 'N':
1379           add_ip4_neighbor (tm, 0 /* is_add */ );
1380           add_ip6_neighbor (tm, 0 /* is_add */ );
1381           break;
1382
1383         case 'p':
1384           add_del_proxy_arp (tm, 1 /* add */ );
1385           break;
1386
1387         case 'i':
1388           proxy_arp_intfc_enable_disable (tm, 1 /* enable */ );
1389           break;
1390
1391         case 'O':
1392           oam_events_enable_disable (tm, 0 /* enable */ );
1393           break;
1394
1395         case 'o':
1396           oam_events_enable_disable (tm, 1 /* enable */ );
1397           break;
1398
1399         case '0':
1400           oam_add_del (tm, 0 /* is_add */ );
1401           break;
1402
1403         case '1':
1404           oam_add_del (tm, 1 /* is_add */ );
1405           break;
1406
1407         case 'r':
1408           reset_fib (tm, 0 /* is_ip6 */ );
1409           break;
1410
1411         case 'R':
1412           reset_fib (tm, 1 /* is_ip6 */ );
1413           break;
1414
1415         case 'j':
1416           dhcp_set_vss (tm);
1417           break;
1418
1419         case 'k':
1420           dhcp_set_proxy (tm, 0);
1421           break;
1422
1423         case 'K':
1424           dhcp_set_proxy (tm, 1 /*ipv6 */ );
1425           break;
1426
1427         case 'v':
1428           set_ip_flow_hash (tm, 0 /* is_ip6 */ );
1429           break;
1430
1431         case 'V':
1432           ip6_set_link_local_address (tm);
1433           break;
1434
1435         case 'w':
1436           ip6_enable_disable (tm, 1 /* enable */ );
1437           break;
1438
1439         case 'W':
1440           ip6_enable_disable (tm, 0 /* disable */ );
1441           break;
1442
1443         case 'x':
1444           ip6nd_ra_config (tm, 0 /* is_no */ );
1445           break;
1446         case 'X':
1447           ip6nd_ra_config (tm, 1 /* is_no */ );
1448           break;
1449         case 'y':
1450           ip6nd_ra_prefix (tm, 0 /* is_no */ );
1451           break;
1452         case 'Y':
1453           ip6nd_ra_prefix (tm, 1 /* is_no */ );
1454           break;
1455
1456         case '7':
1457           loop_create (tm);
1458           break;
1459
1460         case 'F':
1461           set_flags (tm, 1 /* up_down */ );
1462           break;
1463
1464         case 'f':
1465           set_flags (tm, 0 /* up_down */ );
1466           break;
1467
1468         case '@':
1469           l2_xconnect (tm);
1470           break;
1471
1472         case '#':
1473           l2_bridge (tm);
1474           break;
1475
1476         case 'h':
1477           fformat (stdout, "q=quit,d=dump,L=link evts on,l=link evts off\n");
1478           fformat (stdout, "S=stats on,s=stats off\n");
1479           fformat (stdout, "4=add v4 route, 3=del v4 route\n");
1480           fformat (stdout, "6=add v6 route, 5=del v6 route\n");
1481           fformat (stdout, "A=add v4 intfc route, a=del v4 intfc route\n");
1482           fformat (stdout, "B=add v6 intfc route, b=del v6 intfc route\n");
1483           fformat (stdout, "z=del all intfc routes\n");
1484           fformat (stdout, "t=set v4 intfc table, T=set v6 intfc table\n");
1485           fformat (stdout, "c=connect unix tap\n");
1486           fformat (stdout,
1487                    "j=set dhcpv4 and v6 link-address/option-82 params\n");
1488           fformat (stdout, "k=set dhcpv4 relay agent params\n");
1489           fformat (stdout, "K=set dhcpv6 relay agent params\n");
1490           fformat (stdout, "E=add l2 patch, e=del l2 patch\n");
1491           fformat (stdout, "V=ip6 set link-local address \n");
1492           fformat (stdout, "w=ip6 enable \n");
1493           fformat (stdout, "W=ip6 disable \n");
1494           fformat (stdout, "x=ip6 nd config \n");
1495           fformat (stdout, "X=no ip6 nd config\n");
1496           fformat (stdout, "y=ip6 nd prefix \n");
1497           fformat (stdout, "Y=no ip6 nd prefix\n");
1498           fformat (stdout, "@=l2 xconnect\n");
1499           fformat (stdout, "#=l2 bridge\n");
1500
1501         default:
1502           break;
1503         }
1504
1505     }
1506
1507 done:
1508
1509   if (tm->link_events_on)
1510     link_up_down_enable_disable (tm, 0 /* enable */ );
1511   if (tm->stats_on)
1512     stats_enable_disable (tm, 0 /* enable */ );
1513   if (tm->oam_events_on)
1514     oam_events_enable_disable (tm, 0 /* enable */ );
1515
1516   disconnect_from_vpe ();
1517   exit (0);
1518 }
1519
1520 #undef vl_api_version
1521 #define vl_api_version(n,v) static u32 vpe_api_version = v;
1522 #include <vpp/api/vpe.api.h>
1523 #undef vl_api_version
1524
1525 void
1526 vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
1527 {
1528   /*
1529    * Send the main API signature in slot 0. This bit of code must
1530    * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
1531    */
1532   mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
1533 }
1534
1535 /*
1536  * fd.io coding-style-patch-verification: ON
1537  *
1538  * Local Variables:
1539  * eval: (c-set-style "gnu")
1540  * End:
1541  */