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