hs-test: more debug output in http3 test
[vpp.git] / src / plugins / lisp / lisp-gpe / lisp_gpe_test.c
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <vat/vat.h>
17 #include <vlibapi/api.h>
18 #include <vlibmemory/api.h>
19 #include <vppinfra/error.h>
20
21 #include <vnet/ip/ip_format_fns.h>
22 #include <vnet/ethernet/ethernet_format_fns.h>
23 #include <vnet/ethernet/mac_address.h>
24 #include <lisp/lisp-cp/lisp_types.h>
25
26 /* define message IDs */
27 #include <lisp/lisp-gpe/lisp_gpe.api_enum.h>
28 #include <lisp/lisp-gpe/lisp_gpe.api_types.h>
29 #include <vlibmemory/vlib.api_types.h>
30
31 typedef struct
32 {
33   /* API message ID base */
34   u16 msg_id_base;
35   vat_main_t *vat_main;
36   u32 ping_id;
37 } lisp_gpe_test_main_t;
38
39 lisp_gpe_test_main_t lisp_gpe_test_main;
40
41 #define __plugin_msg_base lisp_gpe_test_main.msg_id_base
42 #include <vlibapi/vat_helper_macros.h>
43
44 #define FINISH                                                                \
45   vec_add1 (s, 0);                                                            \
46   vlib_cli_output (handle, (char *) s);                                       \
47   vec_free (s);                                                               \
48   return handle;
49
50 #define LISP_PING(_lm, mp_ping)                                         \
51   if (!(_lm)->ping_id)                                                  \
52     (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \
53   mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));          \
54   mp_ping->_vl_msg_id = htons ((_lm)->ping_id);                         \
55   mp_ping->client_index = vam->my_client_index;                         \
56   fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id);           \
57   vam->result_ready = 0;                                                \
58
59 typedef struct
60 {
61   u32 spi;
62   u8 si;
63 } __attribute__ ((__packed__)) lisp_nsh_api_t;
64
65 static uword
66 unformat_nsh_address (unformat_input_t * input, va_list * args)
67 {
68   lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
69   return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
70 }
71
72 static u8 *
73 format_nsh_address_vat (u8 * s, va_list * args)
74 {
75   nsh_t *a = va_arg (*args, nsh_t *);
76   return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
77 }
78
79 static u8 *
80 format_lisp_flat_eid (u8 * s, va_list * args)
81 {
82   vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *);
83
84   switch (eid->type)
85     {
86     case EID_TYPE_API_PREFIX:
87       if (eid->address.prefix.address.af)
88         return format (s, "%U/%d", format_ip6_address,
89                        eid->address.prefix.address.un.ip6,
90                        eid->address.prefix.len);
91       return format (s, "%U/%d", format_ip4_address,
92                      eid->address.prefix.address.un.ip4,
93                      eid->address.prefix.len);
94     case EID_TYPE_API_MAC:
95       return format (s, "%U", format_ethernet_address, eid->address.mac);
96     case EID_TYPE_API_NSH:
97       return format (s, "%U", format_nsh_address_vat, eid->address.nsh);
98     }
99   return 0;
100 }
101
102 static void vl_api_gpe_add_del_fwd_entry_reply_t_handler
103   (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
104 {
105   vat_main_t *vam = &vat_main;
106   i32 retval = ntohl (mp->retval);
107   if (vam->async_mode)
108     {
109       vam->async_errors += (retval < 0);
110     }
111   else
112     {
113       vam->retval = retval;
114       vam->result_ready = 1;
115     }
116 }
117
118 static void
119 api_gpe_fwd_entry_net_to_host (vl_api_gpe_fwd_entry_t * e)
120 {
121   e->dp_table = clib_net_to_host_u32 (e->dp_table);
122   e->fwd_entry_index = clib_net_to_host_u32 (e->fwd_entry_index);
123   e->vni = clib_net_to_host_u32 (e->vni);
124 }
125
126 static void
127   gpe_fwd_entries_get_reply_t_net_to_host
128   (vl_api_gpe_fwd_entries_get_reply_t * mp)
129 {
130   u32 i;
131
132   mp->count = clib_net_to_host_u32 (mp->count);
133   for (i = 0; i < mp->count; i++)
134     {
135       api_gpe_fwd_entry_net_to_host (&mp->entries[i]);
136     }
137 }
138
139 static u8 *
140 format_gpe_encap_mode (u8 * s, va_list * args)
141 {
142   u32 mode = va_arg (*args, u32);
143
144   switch (mode)
145     {
146     case 0:
147       return format (s, "lisp");
148     case 1:
149       return format (s, "vxlan");
150     }
151   return 0;
152 }
153
154 static void
155   vl_api_gpe_get_encap_mode_reply_t_handler
156   (vl_api_gpe_get_encap_mode_reply_t * mp)
157 {
158   vat_main_t *vam = &vat_main;
159
160   print (vam->ofp, "gpe mode: %U", format_gpe_encap_mode, mp->encap_mode);
161   vam->retval = ntohl (mp->retval);
162   vam->result_ready = 1;
163 }
164
165 static void
166   vl_api_gpe_fwd_entry_path_details_t_handler
167   (vl_api_gpe_fwd_entry_path_details_t * mp)
168 {
169   vat_main_t *vam = &vat_main;
170   u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
171
172   if (mp->lcl_loc.addr.af)
173     format_ip_address_fcn = format_ip6_address;
174   else
175     format_ip_address_fcn = format_ip4_address;
176
177   print (vam->ofp, "w:%d %30U %30U", mp->rmt_loc.weight,
178          format_ip_address_fcn, &mp->lcl_loc.addr.un,
179          format_ip_address_fcn, &mp->rmt_loc.addr.un);
180 }
181
182 static void
183   vl_api_gpe_fwd_entries_get_reply_t_handler
184   (vl_api_gpe_fwd_entries_get_reply_t * mp)
185 {
186   vat_main_t *vam = &vat_main;
187   u32 i;
188   int retval = clib_net_to_host_u32 (mp->retval);
189   vl_api_gpe_fwd_entry_t *e;
190
191   if (retval)
192     goto end;
193
194   gpe_fwd_entries_get_reply_t_net_to_host (mp);
195
196   for (i = 0; i < mp->count; i++)
197     {
198       e = &mp->entries[i];
199       print (vam->ofp, "%10d %10d %U %40U", e->fwd_entry_index, e->dp_table,
200              format_lisp_flat_eid, e->leid, format_lisp_flat_eid, e->reid);
201     }
202
203 end:
204   vam->retval = retval;
205   vam->result_ready = 1;
206 }
207
208 static void
209   vl_api_gpe_native_fwd_rpaths_get_reply_t_handler
210   (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
211 {
212   vat_main_t *vam = &vat_main;
213   u32 i, n;
214   int retval = clib_net_to_host_u32 (mp->retval);
215   vl_api_gpe_native_fwd_rpath_t *r;
216
217   if (retval)
218     goto end;
219
220   n = clib_net_to_host_u32 (mp->count);
221
222   for (i = 0; i < n; i++)
223     {
224       r = &mp->entries[i];
225       print (vam->ofp, "fib_index: %d sw_if_index %d nh %U",
226              clib_net_to_host_u32 (r->fib_index),
227              clib_net_to_host_u32 (r->nh_sw_if_index),
228              r->nh_addr.af ? format_ip6_address : format_ip4_address,
229              r->nh_addr.un);
230     }
231
232 end:
233   vam->retval = retval;
234   vam->result_ready = 1;
235 }
236
237 static void
238   vl_api_gpe_fwd_entry_vnis_get_reply_t_handler
239   (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
240 {
241   vat_main_t *vam = &vat_main;
242   u32 i, n;
243   int retval = clib_net_to_host_u32 (mp->retval);
244
245   if (retval)
246     goto end;
247
248   n = clib_net_to_host_u32 (mp->count);
249
250   for (i = 0; i < n; i++)
251     print (vam->ofp, "%d", clib_net_to_host_u32 (mp->vnis[i]));
252
253 end:
254   vam->retval = retval;
255   vam->result_ready = 1;
256 }
257
258
259 /** Used for parsing LISP eids */
260 typedef CLIB_PACKED(struct{
261   union {
262           ip46_address_t ip;
263           mac_address_t mac;
264           lisp_nsh_api_t nsh;
265   } addr;
266   u32 len;       /**< prefix length if IP */
267   u8 type;      /**< type of eid */
268 }) lisp_eid_vat_t;
269
270 static uword
271 unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
272 {
273   lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
274
275   clib_memset (a, 0, sizeof (a[0]));
276
277   if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len))
278     {
279       a->type = 0;              /* ip prefix type */
280     }
281   else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac))
282     {
283       a->type = 1;              /* mac type */
284     }
285   else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh))
286     {
287       a->type = 2;              /* NSH type */
288       a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi);
289     }
290   else
291     {
292       return 0;
293     }
294
295   if (a->type == 0)
296     {
297       if (ip46_address_is_ip4 (&a->addr.ip))
298         return a->len > 32 ? 1 : 0;
299       else
300         return a->len > 128 ? 1 : 0;
301     }
302
303   return 1;
304 }
305
306 static void
307 lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid)
308 {
309   eid->type = vat_eid->type;
310   switch (eid->type)
311     {
312     case EID_TYPE_API_PREFIX:
313       if (ip46_address_is_ip4 (&vat_eid->addr.ip))
314         {
315           clib_memcpy (&eid->address.prefix.address.un.ip4,
316                        &vat_eid->addr.ip.ip4, 4);
317           eid->address.prefix.address.af = ADDRESS_IP4;
318           eid->address.prefix.len = vat_eid->len;
319         }
320       else
321         {
322           clib_memcpy (&eid->address.prefix.address.un.ip6,
323                        &vat_eid->addr.ip.ip6, 16);
324           eid->address.prefix.address.af = ADDRESS_IP6;
325           eid->address.prefix.len = vat_eid->len;
326         }
327       return;
328     case EID_TYPE_API_MAC:
329       clib_memcpy (&eid->address.mac, &vat_eid->addr.mac,
330                    sizeof (eid->address.mac));
331       return;
332     case EID_TYPE_API_NSH:
333       clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh,
334                    sizeof (eid->address.nsh));
335       return;
336     default:
337       ASSERT (0);
338       return;
339     }
340 }
341
342 static int
343 api_gpe_add_del_fwd_entry (vat_main_t * vam)
344 {
345   u32 dp_table = 0, vni = 0;;
346   unformat_input_t *input = vam->input;
347   vl_api_gpe_add_del_fwd_entry_t *mp;
348   u8 is_add = 1;
349   lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
350   lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
351   u8 rmt_eid_set = 0, lcl_eid_set = 0;
352   u32 action = ~0, w;
353   ip4_address_t rmt_rloc4, lcl_rloc4;
354   ip6_address_t rmt_rloc6, lcl_rloc6;
355   vl_api_gpe_locator_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
356   int ret;
357
358   clib_memset (&rloc, 0, sizeof (rloc));
359
360   /* Parse args required to build the message */
361   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
362     {
363       if (unformat (input, "del"))
364         is_add = 0;
365       else if (unformat (input, "add"))
366         is_add = 1;
367       else if (unformat (input, "reid %U", unformat_lisp_eid_vat, rmt_eid))
368         {
369           rmt_eid_set = 1;
370         }
371       else if (unformat (input, "leid %U", unformat_lisp_eid_vat, lcl_eid))
372         {
373           lcl_eid_set = 1;
374         }
375       else if (unformat (input, "vrf %d", &dp_table))
376         ;
377       else if (unformat (input, "bd %d", &dp_table))
378         ;
379       else if (unformat (input, "vni %d", &vni))
380         ;
381       else if (unformat (input, "w %d", &w))
382         {
383           if (!curr_rloc)
384             {
385               errmsg ("No RLOC configured for setting priority/weight!");
386               return -99;
387             }
388           curr_rloc->weight = w;
389         }
390       else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
391                          &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
392         {
393           rloc.addr.af = 0;
394           clib_memcpy (&rloc.addr.un.ip4, &lcl_rloc4, sizeof (lcl_rloc4));
395           rloc.weight = 0;
396           vec_add1 (lcl_locs, rloc);
397
398           clib_memcpy (&rloc.addr.un.ip4, &rmt_rloc4, sizeof (rmt_rloc4));
399           vec_add1 (rmt_locs, rloc);
400           /* weight saved in rmt loc */
401           curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
402         }
403       else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
404                          &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
405         {
406           rloc.addr.af = 1;
407           clib_memcpy (&rloc.addr.un.ip6, &lcl_rloc6, sizeof (lcl_rloc6));
408           rloc.weight = 0;
409           vec_add1 (lcl_locs, rloc);
410
411           clib_memcpy (&rloc.addr.un.ip6, &rmt_rloc6, sizeof (rmt_rloc6));
412           vec_add1 (rmt_locs, rloc);
413           /* weight saved in rmt loc */
414           curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
415         }
416       else if (unformat (input, "action %d", &action))
417         {
418           ;
419         }
420       else
421         {
422           clib_warning ("parse error '%U'", format_unformat_error, input);
423           return -99;
424         }
425     }
426
427   if (!rmt_eid_set)
428     {
429       errmsg ("remote eid addresses not set");
430       return -99;
431     }
432
433   if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
434     {
435       errmsg ("eid types don't match");
436       return -99;
437     }
438
439   if (0 == rmt_locs && (u32) ~ 0 == action)
440     {
441       errmsg ("action not set for negative mapping");
442       return -99;
443     }
444
445   /* Construct the API message */
446   M2 (GPE_ADD_DEL_FWD_ENTRY, mp,
447       sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs) * 2);
448
449   mp->is_add = is_add;
450   lisp_eid_put_vat (&mp->rmt_eid, rmt_eid);
451   lisp_eid_put_vat (&mp->lcl_eid, lcl_eid);
452   mp->dp_table = clib_host_to_net_u32 (dp_table);
453   mp->vni = clib_host_to_net_u32 (vni);
454   mp->action = action;
455
456   if (0 != rmt_locs && 0 != lcl_locs)
457     {
458       mp->loc_num = clib_host_to_net_u32 (vec_len (rmt_locs) * 2);
459       clib_memcpy (mp->locs, lcl_locs,
460                    (sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs)));
461
462       u32 offset = sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs);
463       clib_memcpy (((u8 *) mp->locs) + offset, rmt_locs,
464                    (sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs)));
465     }
466   vec_free (lcl_locs);
467   vec_free (rmt_locs);
468
469   /* send it... */
470   S (mp);
471
472   /* Wait for a reply... */
473   W (ret);
474   return ret;
475 }
476
477 static int
478 api_gpe_enable_disable (vat_main_t * vam)
479 {
480   unformat_input_t *input = vam->input;
481   vl_api_gpe_enable_disable_t *mp;
482   u8 is_set = 0;
483   u8 is_enable = 1;
484   int ret;
485
486   /* Parse args required to build the message */
487   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
488     {
489       if (unformat (input, "enable"))
490         {
491           is_set = 1;
492           is_enable = 1;
493         }
494       else if (unformat (input, "disable"))
495         {
496           is_set = 1;
497           is_enable = 0;
498         }
499       else
500         break;
501     }
502
503   if (is_set == 0)
504     {
505       errmsg ("Value not set");
506       return -99;
507     }
508
509   /* Construct the API message */
510   M (GPE_ENABLE_DISABLE, mp);
511
512   mp->is_enable = is_enable;
513
514   /* send it... */
515   S (mp);
516
517   /* Wait for a reply... */
518   W (ret);
519   return ret;
520 }
521
522 uword
523 unformat_gpe_encap_mode (unformat_input_t * input, va_list * args)
524 {
525   u32 *mode = va_arg (*args, u32 *);
526
527   if (unformat (input, "lisp"))
528     *mode = 0;
529   else if (unformat (input, "vxlan"))
530     *mode = 1;
531   else
532     return 0;
533
534   return 1;
535 }
536
537 static int
538 api_gpe_get_encap_mode (vat_main_t * vam)
539 {
540   vl_api_gpe_get_encap_mode_t *mp;
541   int ret;
542
543   /* Construct the API message */
544   M (GPE_GET_ENCAP_MODE, mp);
545
546   /* send it... */
547   S (mp);
548
549   /* Wait for a reply... */
550   W (ret);
551   return ret;
552 }
553
554 static int
555 api_gpe_set_encap_mode (vat_main_t * vam)
556 {
557   unformat_input_t *input = vam->input;
558   vl_api_gpe_set_encap_mode_t *mp;
559   int ret;
560   u32 mode = 0;
561
562   /* Parse args required to build the message */
563   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
564     {
565       if (unformat (input, "%U", unformat_gpe_encap_mode, &mode))
566         ;
567       else
568         break;
569     }
570
571   /* Construct the API message */
572   M (GPE_SET_ENCAP_MODE, mp);
573
574   mp->is_vxlan = mode;
575
576   /* send it... */
577   S (mp);
578
579   /* Wait for a reply... */
580   W (ret);
581   return ret;
582 }
583
584 static int
585 api_gpe_add_del_iface (vat_main_t * vam)
586 {
587   unformat_input_t *input = vam->input;
588   vl_api_gpe_add_del_iface_t *mp;
589   u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
590   u32 dp_table = 0, vni = 0;
591   int ret;
592
593   /* Parse args required to build the message */
594   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
595     {
596       if (unformat (input, "up"))
597         {
598           action_set = 1;
599           is_add = 1;
600         }
601       else if (unformat (input, "down"))
602         {
603           action_set = 1;
604           is_add = 0;
605         }
606       else if (unformat (input, "table_id %d", &dp_table))
607         {
608           dp_table_set = 1;
609         }
610       else if (unformat (input, "bd_id %d", &dp_table))
611         {
612           dp_table_set = 1;
613           is_l2 = 1;
614         }
615       else if (unformat (input, "vni %d", &vni))
616         {
617           vni_set = 1;
618         }
619       else
620         break;
621     }
622
623   if (action_set == 0)
624     {
625       errmsg ("Action not set");
626       return -99;
627     }
628   if (dp_table_set == 0 || vni_set == 0)
629     {
630       errmsg ("vni and dp_table must be set");
631       return -99;
632     }
633
634   /* Construct the API message */
635   M (GPE_ADD_DEL_IFACE, mp);
636
637   mp->is_add = is_add;
638   mp->dp_table = clib_host_to_net_u32 (dp_table);
639   mp->is_l2 = is_l2;
640   mp->vni = clib_host_to_net_u32 (vni);
641
642   /* send it... */
643   S (mp);
644
645   /* Wait for a reply... */
646   W (ret);
647   return ret;
648 }
649
650 static int
651 api_gpe_fwd_entries_get (vat_main_t * vam)
652 {
653   unformat_input_t *i = vam->input;
654   vl_api_gpe_fwd_entries_get_t *mp;
655   u8 vni_set = 0;
656   u32 vni = ~0;
657   int ret;
658
659   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
660     {
661       if (unformat (i, "vni %d", &vni))
662         {
663           vni_set = 1;
664         }
665       else
666         {
667           errmsg ("parse error '%U'", format_unformat_error, i);
668           return -99;
669         }
670     }
671
672   if (!vni_set)
673     {
674       errmsg ("vni not set!");
675       return -99;
676     }
677
678   if (!vam->json_output)
679     {
680       print (vam->ofp, "%10s %10s %s %40s", "fwd_index", "dp_table",
681              "leid", "reid");
682     }
683
684   M (GPE_FWD_ENTRIES_GET, mp);
685   mp->vni = clib_host_to_net_u32 (vni);
686
687   /* send it... */
688   S (mp);
689
690   /* Wait for a reply... */
691   W (ret);
692   return ret;
693 }
694
695 static int
696 api_gpe_native_fwd_rpaths_get (vat_main_t * vam)
697 {
698   unformat_input_t *i = vam->input;
699   vl_api_gpe_native_fwd_rpaths_get_t *mp;
700   int ret;
701   u8 ip_family_set = 0, is_ip4 = 1;
702
703   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
704     {
705       if (unformat (i, "ip4"))
706         {
707           ip_family_set = 1;
708           is_ip4 = 1;
709         }
710       else if (unformat (i, "ip6"))
711         {
712           ip_family_set = 1;
713           is_ip4 = 0;
714         }
715       else
716         {
717           errmsg ("parse error '%U'", format_unformat_error, i);
718           return -99;
719         }
720     }
721
722   if (!ip_family_set)
723     {
724       errmsg ("ip family not set!");
725       return -99;
726     }
727
728   M (GPE_NATIVE_FWD_RPATHS_GET, mp);
729   mp->is_ip4 = is_ip4;
730
731   /* send it... */
732   S (mp);
733
734   /* Wait for a reply... */
735   W (ret);
736   return ret;
737 }
738
739 static int
740 api_gpe_fwd_entry_vnis_get (vat_main_t * vam)
741 {
742   vl_api_gpe_fwd_entry_vnis_get_t *mp;
743   int ret;
744
745   if (!vam->json_output)
746     {
747       print (vam->ofp, "VNIs");
748     }
749
750   M (GPE_FWD_ENTRY_VNIS_GET, mp);
751
752   /* send it... */
753   S (mp);
754
755   /* Wait for a reply... */
756   W (ret);
757   return ret;
758 }
759
760 static int
761 api_gpe_add_del_native_fwd_rpath (vat_main_t * vam)
762 {
763   unformat_input_t *i = vam->input;
764   vl_api_gpe_add_del_native_fwd_rpath_t *mp;
765   int ret = 0;
766   u8 is_add = 1, ip_set = 0, is_ip4 = 1;
767   struct in_addr ip4;
768   struct in6_addr ip6;
769   u32 table_id = 0, nh_sw_if_index = ~0;
770
771   clib_memset (&ip4, 0, sizeof (ip4));
772   clib_memset (&ip6, 0, sizeof (ip6));
773
774   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
775     {
776       if (unformat (i, "del"))
777         is_add = 0;
778       else if (unformat (i, "via %U %U", unformat_ip4_address, &ip4,
779                          unformat_sw_if_index, vam, &nh_sw_if_index))
780         {
781           ip_set = 1;
782           is_ip4 = 1;
783         }
784       else if (unformat (i, "via %U %U", unformat_ip6_address, &ip6,
785                          unformat_sw_if_index, vam, &nh_sw_if_index))
786         {
787           ip_set = 1;
788           is_ip4 = 0;
789         }
790       else if (unformat (i, "via %U", unformat_ip4_address, &ip4))
791         {
792           ip_set = 1;
793           is_ip4 = 1;
794           nh_sw_if_index = ~0;
795         }
796       else if (unformat (i, "via %U", unformat_ip6_address, &ip6))
797         {
798           ip_set = 1;
799           is_ip4 = 0;
800           nh_sw_if_index = ~0;
801         }
802       else if (unformat (i, "table %d", &table_id))
803         ;
804       else
805         {
806           errmsg ("parse error '%U'", format_unformat_error, i);
807           return -99;
808         }
809     }
810
811   if (!ip_set)
812     {
813       errmsg ("nh addr not set!");
814       return -99;
815     }
816
817   M (GPE_ADD_DEL_NATIVE_FWD_RPATH, mp);
818   mp->is_add = is_add;
819   mp->table_id = clib_host_to_net_u32 (table_id);
820   mp->nh_sw_if_index = clib_host_to_net_u32 (nh_sw_if_index);
821   mp->nh_addr.af = is_ip4 ? 0 : 1;
822   if (is_ip4)
823     clib_memcpy (mp->nh_addr.un.ip4, &ip4, sizeof (ip4));
824   else
825     clib_memcpy (mp->nh_addr.un.ip6, &ip6, sizeof (ip6));
826
827   /* send it... */
828   S (mp);
829
830   /* Wait for a reply... */
831   W (ret);
832   return ret;
833 }
834
835 static int
836 api_gpe_fwd_entry_path_dump (vat_main_t * vam)
837 {
838   vl_api_gpe_fwd_entry_path_dump_t *mp;
839   vl_api_control_ping_t *mp_ping;
840   unformat_input_t *i = vam->input;
841   u32 fwd_entry_index = ~0;
842   int ret;
843
844   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
845     {
846       if (unformat (i, "index %d", &fwd_entry_index))
847         ;
848       else
849         break;
850     }
851
852   if (~0 == fwd_entry_index)
853     {
854       errmsg ("no index specified!");
855       return -99;
856     }
857
858   if (!vam->json_output)
859     {
860       print (vam->ofp, "first line");
861     }
862
863   M (GPE_FWD_ENTRY_PATH_DUMP, mp);
864
865   /* send it... */
866   S (mp);
867   /* Use a control ping for synchronization */
868   LISP_PING (&lisp_gpe_test_main, mp_ping);
869   S (mp_ping);
870
871   /* Wait for a reply... */
872   W (ret);
873   return ret;
874 }
875
876 #define vat_plugin_register vat_plugin_register_gpe
877 #include <lisp/lisp-gpe/lisp_gpe.api_test.c>
878
879 /*
880  * fd.io coding-style-patch-verification: ON
881  *
882  * Local Variables:
883  * eval: (c-set-style "gnu")
884  * End:
885  */