vlib: clean up r2 plugin registration relocator
[vpp.git] / src / plugins / lisp / lisp-cp / lisp_cp_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-cp/lisp.api_enum.h>
28 #include <lisp/lisp-cp/lisp.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_test_main_t;
38
39 lisp_test_main_t lisp_test_main;
40
41 #define __plugin_msg_base lisp_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 typedef struct
51 {
52   u32 spi;
53   u8 si;
54 } __attribute__ ((__packed__)) lisp_nsh_api_t;
55
56 #define LISP_PING(_lm, mp_ping)                                         \
57   if (!(_lm)->ping_id)                                                  \
58     (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \
59   mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));          \
60   mp_ping->_vl_msg_id = htons ((_lm)->ping_id);                         \
61   mp_ping->client_index = vam->my_client_index;                         \
62   fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id);           \
63   vam->result_ready = 0;                                                \
64
65 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 u8 *
103 format_lisp_eid_vat (u8 * s, va_list * args)
104 {
105   vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *);
106   vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *);
107   u8 is_src_dst = (u8) va_arg (*args, int);
108
109   if (is_src_dst)
110     s = format (s, "%U|", format_lisp_flat_eid, seid);
111
112   s = format (s, "%U", format_lisp_flat_eid, deid);
113
114   return s;
115 }
116
117
118
119 /** Used for parsing LISP eids */
120 typedef struct lisp_eid_vat_t_
121 {
122   union {
123     ip46_address_t ip;
124     mac_address_t mac;
125     lisp_nsh_api_t nsh;
126   } addr;
127   /**< prefix length if IP */
128   u32 len;
129   /**< type of eid */
130   u8 type;
131 } __clib_packed lisp_eid_vat_t;
132
133 static uword
134 unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
135 {
136   lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
137
138   clib_memset (a, 0, sizeof (a[0]));
139
140   if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len))
141     {
142       a->type = 0;              /* ip prefix type */
143     }
144   else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac))
145     {
146       a->type = 1;              /* mac type */
147     }
148   else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh))
149     {
150       a->type = 2;              /* NSH type */
151       a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi);
152     }
153   else
154     {
155       return 0;
156     }
157
158   if (a->type == 0)
159     {
160       if (ip46_address_is_ip4 (&a->addr.ip))
161         return a->len > 32 ? 1 : 0;
162       else
163         return a->len > 128 ? 1 : 0;
164     }
165
166   return 1;
167 }
168
169 static void
170 lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid)
171 {
172   eid->type = vat_eid->type;
173   switch (eid->type)
174     {
175     case EID_TYPE_API_PREFIX:
176       if (ip46_address_is_ip4 (&vat_eid->addr.ip))
177         {
178           clib_memcpy (&eid->address.prefix.address.un.ip4,
179                        &vat_eid->addr.ip.ip4, 4);
180           eid->address.prefix.address.af = ADDRESS_IP4;
181           eid->address.prefix.len = vat_eid->len;
182         }
183       else
184         {
185           clib_memcpy (&eid->address.prefix.address.un.ip6,
186                        &vat_eid->addr.ip.ip6, 16);
187           eid->address.prefix.address.af = ADDRESS_IP6;
188           eid->address.prefix.len = vat_eid->len;
189         }
190       return;
191     case EID_TYPE_API_MAC:
192       clib_memcpy (&eid->address.mac, &vat_eid->addr.mac,
193                    sizeof (eid->address.mac));
194       return;
195     case EID_TYPE_API_NSH:
196       clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh,
197                    sizeof (eid->address.nsh));
198       return;
199     default:
200       ASSERT (0);
201       return;
202     }
203 }
204
205 static int
206 api_lisp_add_del_locator_set (vat_main_t * vam)
207 {
208   unformat_input_t *input = vam->input;
209   vl_api_lisp_add_del_locator_set_t *mp;
210   u8 is_add = 1;
211   u8 *locator_set_name = NULL;
212   u8 locator_set_name_set = 0;
213   vl_api_local_locator_t locator, *locators = 0;
214   u32 sw_if_index, priority, weight;
215   u32 data_len = 0;
216
217   int ret;
218   /* Parse args required to build the message */
219   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
220     {
221       if (unformat (input, "del"))
222         {
223           is_add = 0;
224         }
225       else if (unformat (input, "locator-set %s", &locator_set_name))
226         {
227           locator_set_name_set = 1;
228         }
229       else if (unformat (input, "sw_if_index %u p %u w %u",
230                          &sw_if_index, &priority, &weight))
231         {
232           locator.sw_if_index = htonl (sw_if_index);
233           locator.priority = priority;
234           locator.weight = weight;
235           vec_add1 (locators, locator);
236         }
237       else
238         if (unformat
239             (input, "iface %U p %u w %u", unformat_sw_if_index, vam,
240              &sw_if_index, &priority, &weight))
241         {
242           locator.sw_if_index = htonl (sw_if_index);
243           locator.priority = priority;
244           locator.weight = weight;
245           vec_add1 (locators, locator);
246         }
247       else
248         break;
249     }
250
251   if (locator_set_name_set == 0)
252     {
253       errmsg ("missing locator-set name");
254       vec_free (locators);
255       return -99;
256     }
257
258   if (vec_len (locator_set_name) > 64)
259     {
260       errmsg ("locator-set name too long");
261       vec_free (locator_set_name);
262       vec_free (locators);
263       return -99;
264     }
265   vec_add1 (locator_set_name, 0);
266
267   data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
268
269   /* Construct the API message */
270   M2 (LISP_ADD_DEL_LOCATOR_SET, mp, data_len);
271
272   mp->is_add = is_add;
273   clib_memcpy (mp->locator_set_name, locator_set_name,
274                vec_len (locator_set_name));
275   vec_free (locator_set_name);
276
277   mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
278   if (locators)
279     clib_memcpy (mp->locators, locators, data_len);
280   vec_free (locators);
281
282   /* send it... */
283   S (mp);
284
285   /* Wait for a reply... */
286   W (ret);
287   return ret;
288 }
289
290 static int
291 api_lisp_add_del_locator (vat_main_t * vam)
292 {
293   unformat_input_t *input = vam->input;
294   vl_api_lisp_add_del_locator_t *mp;
295   u32 tmp_if_index = ~0;
296   u32 sw_if_index = ~0;
297   u8 sw_if_index_set = 0;
298   u8 sw_if_index_if_name_set = 0;
299   u32 priority = ~0;
300   u8 priority_set = 0;
301   u32 weight = ~0;
302   u8 weight_set = 0;
303   u8 is_add = 1;
304   u8 *locator_set_name = NULL;
305   u8 locator_set_name_set = 0;
306   int ret;
307
308   /* Parse args required to build the message */
309   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
310     {
311       if (unformat (input, "del"))
312         {
313           is_add = 0;
314         }
315       else if (unformat (input, "locator-set %s", &locator_set_name))
316         {
317           locator_set_name_set = 1;
318         }
319       else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
320                          &tmp_if_index))
321         {
322           sw_if_index_if_name_set = 1;
323           sw_if_index = tmp_if_index;
324         }
325       else if (unformat (input, "sw_if_index %d", &tmp_if_index))
326         {
327           sw_if_index_set = 1;
328           sw_if_index = tmp_if_index;
329         }
330       else if (unformat (input, "p %d", &priority))
331         {
332           priority_set = 1;
333         }
334       else if (unformat (input, "w %d", &weight))
335         {
336           weight_set = 1;
337         }
338       else
339         break;
340     }
341
342   if (locator_set_name_set == 0)
343     {
344       errmsg ("missing locator-set name");
345       return -99;
346     }
347
348   if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
349     {
350       errmsg ("missing sw_if_index");
351       vec_free (locator_set_name);
352       return -99;
353     }
354
355   if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
356     {
357       errmsg ("cannot use both params interface name and sw_if_index");
358       vec_free (locator_set_name);
359       return -99;
360     }
361
362   if (priority_set == 0)
363     {
364       errmsg ("missing locator-set priority");
365       vec_free (locator_set_name);
366       return -99;
367     }
368
369   if (weight_set == 0)
370     {
371       errmsg ("missing locator-set weight");
372       vec_free (locator_set_name);
373       return -99;
374     }
375
376   if (vec_len (locator_set_name) > 64)
377     {
378       errmsg ("locator-set name too long");
379       vec_free (locator_set_name);
380       return -99;
381     }
382   vec_add1 (locator_set_name, 0);
383
384   /* Construct the API message */
385   M (LISP_ADD_DEL_LOCATOR, mp);
386
387   mp->is_add = is_add;
388   mp->sw_if_index = ntohl (sw_if_index);
389   mp->priority = priority;
390   mp->weight = weight;
391   clib_memcpy (mp->locator_set_name, locator_set_name,
392                vec_len (locator_set_name));
393   vec_free (locator_set_name);
394
395   /* send it... */
396   S (mp);
397
398   /* Wait for a reply... */
399   W (ret);
400   return ret;
401 }
402
403 static int
404 api_lisp_add_del_local_eid (vat_main_t * vam)
405 {
406   unformat_input_t *input = vam->input;
407   vl_api_lisp_add_del_local_eid_t *mp;
408   u8 is_add = 1;
409   u8 eid_set = 0;
410   lisp_eid_vat_t _eid, *eid = &_eid;
411   u8 *locator_set_name = 0;
412   u8 locator_set_name_set = 0;
413   u32 vni = 0;
414   u16 key_id = 0;
415   u8 *key = 0;
416   int ret;
417
418   /* Parse args required to build the message */
419   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
420     {
421       if (unformat (input, "del"))
422         {
423           is_add = 0;
424         }
425       else if (unformat (input, "vni %d", &vni))
426         {
427           ;
428         }
429       else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
430         {
431           eid_set = 1;
432         }
433       else if (unformat (input, "locator-set %s", &locator_set_name))
434         {
435           locator_set_name_set = 1;
436         }
437       else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
438         ;
439       else if (unformat (input, "secret-key %_%v%_", &key))
440         ;
441       else
442         break;
443     }
444
445   if (locator_set_name_set == 0)
446     {
447       errmsg ("missing locator-set name");
448       return -99;
449     }
450
451   if (0 == eid_set)
452     {
453       errmsg ("EID address not set!");
454       vec_free (locator_set_name);
455       return -99;
456     }
457
458   if (key && (0 == key_id))
459     {
460       errmsg ("invalid key_id!");
461       return -99;
462     }
463
464   if (vec_len (key) > 64)
465     {
466       errmsg ("key too long");
467       vec_free (key);
468       return -99;
469     }
470
471   if (vec_len (locator_set_name) > 64)
472     {
473       errmsg ("locator-set name too long");
474       vec_free (locator_set_name);
475       return -99;
476     }
477   vec_add1 (locator_set_name, 0);
478
479   /* Construct the API message */
480   M (LISP_ADD_DEL_LOCAL_EID, mp);
481
482   mp->is_add = is_add;
483   lisp_eid_put_vat (&mp->eid, eid);
484   mp->vni = clib_host_to_net_u32 (vni);
485   mp->key.id = key_id;
486   clib_memcpy (mp->locator_set_name, locator_set_name,
487                vec_len (locator_set_name));
488   clib_memcpy (mp->key.key, key, vec_len (key));
489
490   vec_free (locator_set_name);
491   vec_free (key);
492
493   /* send it... */
494   S (mp);
495
496   /* Wait for a reply... */
497   W (ret);
498   return ret;
499 }
500
501 static int
502 api_lisp_add_del_map_server (vat_main_t * vam)
503 {
504   unformat_input_t *input = vam->input;
505   vl_api_lisp_add_del_map_server_t *mp;
506   u8 is_add = 1;
507   u8 ipv4_set = 0;
508   u8 ipv6_set = 0;
509   ip4_address_t ipv4;
510   ip6_address_t ipv6;
511   int ret;
512
513   /* Parse args required to build the message */
514   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
515     {
516       if (unformat (input, "del"))
517         {
518           is_add = 0;
519         }
520       else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
521         {
522           ipv4_set = 1;
523         }
524       else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
525         {
526           ipv6_set = 1;
527         }
528       else
529         break;
530     }
531
532   if (ipv4_set && ipv6_set)
533     {
534       errmsg ("both eid v4 and v6 addresses set");
535       return -99;
536     }
537
538   if (!ipv4_set && !ipv6_set)
539     {
540       errmsg ("eid addresses not set");
541       return -99;
542     }
543
544   /* Construct the API message */
545   M (LISP_ADD_DEL_MAP_SERVER, mp);
546
547   mp->is_add = is_add;
548   if (ipv6_set)
549     {
550       mp->ip_address.af = 1;
551       clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
552     }
553   else
554     {
555       mp->ip_address.af = 0;
556       clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4));
557     }
558
559   /* send it... */
560   S (mp);
561
562   /* Wait for a reply... */
563   W (ret);
564   return ret;
565 }
566
567 static int
568 api_lisp_add_del_map_resolver (vat_main_t * vam)
569 {
570   unformat_input_t *input = vam->input;
571   vl_api_lisp_add_del_map_resolver_t *mp;
572   u8 is_add = 1;
573   u8 ipv4_set = 0;
574   u8 ipv6_set = 0;
575   ip4_address_t ipv4;
576   ip6_address_t ipv6;
577   int ret;
578
579   /* Parse args required to build the message */
580   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
581     {
582       if (unformat (input, "del"))
583         {
584           is_add = 0;
585         }
586       else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
587         {
588           ipv4_set = 1;
589         }
590       else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
591         {
592           ipv6_set = 1;
593         }
594       else
595         break;
596     }
597
598   if (ipv4_set && ipv6_set)
599     {
600       errmsg ("both eid v4 and v6 addresses set");
601       return -99;
602     }
603
604   if (!ipv4_set && !ipv6_set)
605     {
606       errmsg ("eid addresses not set");
607       return -99;
608     }
609
610   /* Construct the API message */
611   M (LISP_ADD_DEL_MAP_RESOLVER, mp);
612
613   mp->is_add = is_add;
614   if (ipv6_set)
615     {
616       mp->ip_address.af = 1;
617       clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
618     }
619   else
620     {
621       mp->ip_address.af = 0;
622       clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4));
623     }
624
625   /* send it... */
626   S (mp);
627
628   /* Wait for a reply... */
629   W (ret);
630   return ret;
631 }
632
633 static int
634 api_lisp_enable_disable (vat_main_t * vam)
635 {
636   unformat_input_t *input = vam->input;
637   vl_api_lisp_enable_disable_t *mp;
638   u8 is_set = 0;
639   u8 is_enable = 0;
640   int ret;
641
642   /* Parse args required to build the message */
643   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
644     {
645       if (unformat (input, "enable"))
646         {
647           is_set = 1;
648           is_enable = 1;
649         }
650       else if (unformat (input, "disable"))
651         {
652           is_set = 1;
653         }
654       else
655         break;
656     }
657
658   if (!is_set)
659     {
660       errmsg ("Value not set");
661       return -99;
662     }
663
664   /* Construct the API message */
665   M (LISP_ENABLE_DISABLE, mp);
666
667   mp->is_enable = is_enable;
668
669   /* send it... */
670   S (mp);
671
672   /* Wait for a reply... */
673   W (ret);
674   return ret;
675 }
676
677 /**
678  * Enable/disable LISP proxy ITR.
679  *
680  * @param vam vpp API test context
681  * @return return code
682  */
683 static int
684 api_lisp_pitr_set_locator_set (vat_main_t * vam)
685 {
686   u8 ls_name_set = 0;
687   unformat_input_t *input = vam->input;
688   vl_api_lisp_pitr_set_locator_set_t *mp;
689   u8 is_add = 1;
690   u8 *ls_name = 0;
691   int ret;
692
693   /* Parse args required to build the message */
694   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
695     {
696       if (unformat (input, "del"))
697         is_add = 0;
698       else if (unformat (input, "locator-set %s", &ls_name))
699         ls_name_set = 1;
700       else
701         {
702           errmsg ("parse error '%U'", format_unformat_error, input);
703           return -99;
704         }
705     }
706
707   if (!ls_name_set)
708     {
709       errmsg ("locator-set name not set!");
710       return -99;
711     }
712
713   M (LISP_PITR_SET_LOCATOR_SET, mp);
714
715   mp->is_add = is_add;
716   clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
717   vec_free (ls_name);
718
719   /* send */
720   S (mp);
721
722   /* wait for reply */
723   W (ret);
724   return ret;
725 }
726
727 static int
728 api_lisp_use_petr (vat_main_t * vam)
729 {
730   unformat_input_t *input = vam->input;
731   vl_api_lisp_use_petr_t *mp;
732   u8 is_add = 0;
733   ip_address_t ip;
734   int ret;
735
736   clib_memset (&ip, 0, sizeof (ip));
737
738   /* Parse args required to build the message */
739   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
740     {
741       if (unformat (input, "disable"))
742         is_add = 0;
743       else
744         if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
745         {
746           is_add = 1;
747           ip_addr_version (&ip) = AF_IP4;
748         }
749       else
750         if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
751         {
752           is_add = 1;
753           ip_addr_version (&ip) = AF_IP6;
754         }
755       else
756         {
757           errmsg ("parse error '%U'", format_unformat_error, input);
758           return -99;
759         }
760     }
761
762   M (LISP_USE_PETR, mp);
763
764   mp->is_add = is_add;
765   if (is_add)
766     {
767       mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1;
768       if (mp->ip_address.af)
769         clib_memcpy (mp->ip_address.un.ip6, &ip, 16);
770       else
771         clib_memcpy (mp->ip_address.un.ip4, &ip, 4);
772     }
773
774   /* send */
775   S (mp);
776
777   /* wait for reply */
778   W (ret);
779   return ret;
780 }
781
782 static void
783   vl_api_show_lisp_use_petr_reply_t_handler
784   (vl_api_show_lisp_use_petr_reply_t * mp)
785 {
786   vat_main_t *vam = &vat_main;
787   i32 retval = ntohl (mp->retval);
788
789   if (0 <= retval)
790     {
791       print (vam->ofp, "%s\n", mp->is_petr_enable ? "enabled" : "disabled");
792       if (mp->is_petr_enable)
793         {
794           print (vam->ofp, "Proxy-ETR address; %U",
795                  mp->ip_address.af ? format_ip6_address : format_ip4_address,
796                  mp->ip_address.un);
797         }
798     }
799
800   vam->retval = retval;
801   vam->result_ready = 1;
802 }
803
804 static int
805 api_show_lisp_use_petr (vat_main_t * vam)
806 {
807   vl_api_show_lisp_use_petr_t *mp;
808   int ret;
809
810   if (!vam->json_output)
811     {
812       print (vam->ofp, "%=20s", "Proxy-ETR status:");
813     }
814
815   M (SHOW_LISP_USE_PETR, mp);
816   /* send it... */
817   S (mp);
818
819   /* Wait for a reply... */
820   W (ret);
821   return ret;
822 }
823
824 static void
825   vl_api_show_lisp_rloc_probe_state_reply_t_handler
826   (vl_api_show_lisp_rloc_probe_state_reply_t * mp)
827 {
828   vat_main_t *vam = &vat_main;
829   int retval = clib_net_to_host_u32 (mp->retval);
830
831   if (retval)
832     goto end;
833
834   print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
835 end:
836   vam->retval = retval;
837   vam->result_ready = 1;
838 }
839
840 static int
841 api_show_lisp_map_register_state (vat_main_t * vam)
842 {
843   vl_api_show_lisp_map_register_state_t *mp;
844   int ret;
845
846   M (SHOW_LISP_MAP_REGISTER_STATE, mp);
847
848   /* send */
849   S (mp);
850
851   /* wait for reply */
852   W (ret);
853   return ret;
854 }
855
856 static int
857 api_show_lisp_rloc_probe_state (vat_main_t * vam)
858 {
859   vl_api_show_lisp_rloc_probe_state_t *mp;
860   int ret;
861
862   M (SHOW_LISP_RLOC_PROBE_STATE, mp);
863
864   /* send */
865   S (mp);
866
867   /* wait for reply */
868   W (ret);
869   return ret;
870 }
871
872 static int
873 api_lisp_rloc_probe_enable_disable (vat_main_t * vam)
874 {
875   unformat_input_t *input = vam->input;
876   vl_api_lisp_rloc_probe_enable_disable_t *mp;
877   u8 is_set = 0;
878   u8 is_enable = 0;
879   int ret;
880
881   /* Parse args required to build the message */
882   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
883     {
884       if (unformat (input, "enable"))
885         {
886           is_set = 1;
887           is_enable = 1;
888         }
889       else if (unformat (input, "disable"))
890         is_set = 1;
891       else
892         break;
893     }
894
895   if (!is_set)
896     {
897       errmsg ("Value not set");
898       return -99;
899     }
900
901   /* Construct the API message */
902   M (LISP_RLOC_PROBE_ENABLE_DISABLE, mp);
903
904   mp->is_enable = is_enable;
905
906   /* send it... */
907   S (mp);
908
909   /* Wait for a reply... */
910   W (ret);
911   return ret;
912 }
913
914 static int
915 api_lisp_map_register_enable_disable (vat_main_t * vam)
916 {
917   unformat_input_t *input = vam->input;
918   vl_api_lisp_map_register_enable_disable_t *mp;
919   u8 is_set = 0;
920   u8 is_enable = 0;
921   int ret;
922
923   /* Parse args required to build the message */
924   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
925     {
926       if (unformat (input, "enable"))
927         {
928           is_set = 1;
929           is_enable = 1;
930         }
931       else if (unformat (input, "disable"))
932         is_set = 1;
933       else
934         break;
935     }
936
937   if (!is_set)
938     {
939       errmsg ("Value not set");
940       return -99;
941     }
942
943   /* Construct the API message */
944   M (LISP_MAP_REGISTER_ENABLE_DISABLE, mp);
945
946   mp->is_enable = is_enable;
947
948   /* send it... */
949   S (mp);
950
951   /* Wait for a reply... */
952   W (ret);
953   return ret;
954 }
955
956 static void
957   vl_api_show_lisp_map_request_mode_reply_t_handler
958   (vl_api_show_lisp_map_request_mode_reply_t * mp)
959 {
960   vat_main_t *vam = &vat_main;
961   i32 retval = ntohl (mp->retval);
962
963   if (0 <= retval)
964     {
965       print (vam->ofp, "map_request_mode: %s",
966              mp->is_src_dst ? "src-dst" : "dst-only");
967     }
968
969   vam->retval = retval;
970   vam->result_ready = 1;
971 }
972
973 static void
974   vl_api_show_lisp_map_register_state_reply_t_handler
975   (vl_api_show_lisp_map_register_state_reply_t * mp)
976 {
977   vat_main_t *vam = &vat_main;
978   int retval = clib_net_to_host_u32 (mp->retval);
979
980   print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
981
982   vam->retval = retval;
983   vam->result_ready = 1;
984 }
985
986 static void
987 vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
988 {
989   vat_main_t *vam = &vat_main;
990   u8 *s = 0;
991
992   if (mp->local)
993     {
994       s = format (s, "%=16d%=16d%=16d",
995                   ntohl (mp->sw_if_index), mp->priority, mp->weight);
996     }
997   else
998     {
999       s = format (s, "%=16U%=16d%=16d",
1000                   format_ip46_address,
1001                   mp->ip_address, mp->priority, mp->weight);
1002     }
1003
1004   print (vam->ofp, "%v", s);
1005   vec_free (s);
1006 }
1007
1008 static void
1009 vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
1010                                            mp)
1011 {
1012   vat_main_t *vam = &vat_main;
1013   u8 *ls_name = 0;
1014
1015   ls_name = format (0, "%s", mp->ls_name);
1016
1017   print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
1018          ls_name);
1019   vec_free (ls_name);
1020 }
1021
1022 static void vl_api_lisp_add_del_locator_set_reply_t_handler
1023   (vl_api_lisp_add_del_locator_set_reply_t * mp)
1024 {
1025   vat_main_t *vam = &vat_main;
1026   i32 retval = ntohl (mp->retval);
1027   if (vam->async_mode)
1028     {
1029       vam->async_errors += (retval < 0);
1030     }
1031   else
1032     {
1033       vam->retval = retval;
1034       vam->result_ready = 1;
1035     }
1036 }
1037
1038
1039 static void
1040 vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
1041 {
1042   vat_main_t *vam = &vat_main;
1043   u8 *s = 0, *eid = 0;
1044
1045   if (~0 == mp->locator_set_index)
1046     s = format (0, "action: %d", mp->action);
1047   else
1048     s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
1049
1050   eid = format (0, "%U", format_lisp_eid_vat,
1051                 &mp->deid, &mp->seid, mp->is_src_dst);
1052   vec_add1 (eid, 0);
1053
1054   print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
1055          clib_net_to_host_u32 (mp->vni),
1056          eid,
1057          mp->is_local ? "local" : "remote",
1058          s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
1059          clib_net_to_host_u16 (mp->key.id), mp->key.key);
1060
1061   vec_free (s);
1062   vec_free (eid);
1063 }
1064
1065 static void
1066   vl_api_lisp_eid_table_map_details_t_handler
1067   (vl_api_lisp_eid_table_map_details_t * mp)
1068 {
1069   vat_main_t *vam = &vat_main;
1070
1071   u8 *line = format (0, "%=10d%=10d",
1072                      clib_net_to_host_u32 (mp->vni),
1073                      clib_net_to_host_u32 (mp->dp_table));
1074   print (vam->ofp, "%v", line);
1075   vec_free (line);
1076 }
1077
1078 static void
1079   vl_api_lisp_eid_table_vni_details_t_handler
1080   (vl_api_lisp_eid_table_vni_details_t * mp)
1081 {
1082   vat_main_t *vam = &vat_main;
1083
1084   u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
1085   print (vam->ofp, "%v", line);
1086   vec_free (line);
1087 }
1088
1089 static void
1090   vl_api_lisp_adjacencies_get_reply_t_handler
1091   (vl_api_lisp_adjacencies_get_reply_t * mp)
1092 {
1093   vat_main_t *vam = &vat_main;
1094   u32 i, n;
1095   int retval = clib_net_to_host_u32 (mp->retval);
1096   vl_api_lisp_adjacency_t *a;
1097
1098   if (retval)
1099     goto end;
1100
1101   n = clib_net_to_host_u32 (mp->count);
1102
1103   for (i = 0; i < n; i++)
1104     {
1105       a = &mp->adjacencies[i];
1106       print (vam->ofp, "%U %40U",
1107              format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid);
1108     }
1109
1110 end:
1111   vam->retval = retval;
1112   vam->result_ready = 1;
1113 }
1114
1115 static void
1116 vl_api_lisp_map_server_details_t_handler (vl_api_lisp_map_server_details_t *
1117                                           mp)
1118 {
1119   vat_main_t *vam = &vat_main;
1120
1121   print (vam->ofp, "%=20U",
1122          mp->ip_address.af ? format_ip6_address : format_ip4_address,
1123          mp->ip_address.un);
1124 }
1125
1126 static void
1127 vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
1128                                             * mp)
1129 {
1130   vat_main_t *vam = &vat_main;
1131
1132   print (vam->ofp, "%=20U",
1133          mp->ip_address.af ? format_ip6_address : format_ip4_address,
1134          mp->ip_address.un);
1135 }
1136
1137 static void
1138 vl_api_show_lisp_status_reply_t_handler (vl_api_show_lisp_status_reply_t * mp)
1139 {
1140   vat_main_t *vam = &vat_main;
1141   i32 retval = ntohl (mp->retval);
1142
1143   if (0 <= retval)
1144     {
1145       print (vam->ofp, "feature: %s\ngpe: %s",
1146              mp->is_lisp_enabled ? "enabled" : "disabled",
1147              mp->is_gpe_enabled ? "enabled" : "disabled");
1148     }
1149
1150   vam->retval = retval;
1151   vam->result_ready = 1;
1152 }
1153
1154 static void
1155   vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
1156   (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
1157 {
1158   vat_main_t *vam = &vat_main;
1159   i32 retval = ntohl (mp->retval);
1160
1161   if (retval >= 0)
1162     {
1163       print (vam->ofp, "%=20s", mp->locator_set_name);
1164     }
1165
1166   vam->retval = retval;
1167   vam->result_ready = 1;
1168 }
1169
1170 static void
1171 vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
1172 {
1173   vat_main_t *vam = &vat_main;
1174   i32 retval = ntohl (mp->retval);
1175
1176   if (0 <= retval)
1177     {
1178       print (vam->ofp, "%-20s%-16s",
1179              mp->is_enabled ? "enabled" : "disabled",
1180              mp->is_enabled ? (char *) mp->locator_set_name : "");
1181     }
1182
1183   vam->retval = retval;
1184   vam->result_ready = 1;
1185 }
1186
1187 uword
1188 unformat_hmac_key_id (unformat_input_t * input, va_list * args)
1189 {
1190   u32 *key_id = va_arg (*args, u32 *);
1191   u8 *s = 0;
1192
1193   if (unformat (input, "%s", &s))
1194     {
1195       if (!strcmp ((char *) s, "sha1"))
1196         key_id[0] = HMAC_SHA_1_96;
1197       else if (!strcmp ((char *) s, "sha256"))
1198         key_id[0] = HMAC_SHA_256_128;
1199       else
1200         {
1201           clib_warning ("invalid key_id: '%s'", s);
1202           key_id[0] = HMAC_NO_KEY;
1203         }
1204     }
1205   else
1206     return 0;
1207
1208   vec_free (s);
1209   return 1;
1210 }
1211
1212
1213
1214 static int
1215 api_show_lisp_map_request_mode (vat_main_t * vam)
1216 {
1217   vl_api_show_lisp_map_request_mode_t *mp;
1218   int ret;
1219
1220   M (SHOW_LISP_MAP_REQUEST_MODE, mp);
1221
1222   /* send */
1223   S (mp);
1224
1225   /* wait for reply */
1226   W (ret);
1227   return ret;
1228 }
1229
1230 static int
1231 api_lisp_map_request_mode (vat_main_t * vam)
1232 {
1233   unformat_input_t *input = vam->input;
1234   vl_api_lisp_map_request_mode_t *mp;
1235   u8 mode = 0;
1236   int ret;
1237
1238   /* Parse args required to build the message */
1239   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1240     {
1241       if (unformat (input, "dst-only"))
1242         mode = 0;
1243       else if (unformat (input, "src-dst"))
1244         mode = 1;
1245       else
1246         {
1247           errmsg ("parse error '%U'", format_unformat_error, input);
1248           return -99;
1249         }
1250     }
1251
1252   M (LISP_MAP_REQUEST_MODE, mp);
1253
1254   mp->is_src_dst = mode == 1;
1255
1256   /* send */
1257   S (mp);
1258
1259   /* wait for reply */
1260   W (ret);
1261   return ret;
1262 }
1263
1264 static int
1265 api_show_lisp_pitr (vat_main_t * vam)
1266 {
1267   vl_api_show_lisp_pitr_t *mp;
1268   int ret;
1269
1270   if (!vam->json_output)
1271     {
1272       print (vam->ofp, "%=20s", "lisp status:");
1273     }
1274
1275   M (SHOW_LISP_PITR, mp);
1276   /* send it... */
1277   S (mp);
1278
1279   /* Wait for a reply... */
1280   W (ret);
1281   return ret;
1282 }
1283
1284 /**
1285  * Add/delete mapping between vni and vrf
1286  */
1287 static int
1288 api_lisp_eid_table_add_del_map (vat_main_t * vam)
1289 {
1290   unformat_input_t *input = vam->input;
1291   vl_api_lisp_eid_table_add_del_map_t *mp;
1292   u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
1293   u32 vni, vrf, bd_index;
1294   int ret;
1295
1296   /* Parse args required to build the message */
1297   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1298     {
1299       if (unformat (input, "del"))
1300         is_add = 0;
1301       else if (unformat (input, "vrf %d", &vrf))
1302         vrf_set = 1;
1303       else if (unformat (input, "bd_index %d", &bd_index))
1304         bd_index_set = 1;
1305       else if (unformat (input, "vni %d", &vni))
1306         vni_set = 1;
1307       else
1308         break;
1309     }
1310
1311   if (!vni_set || (!vrf_set && !bd_index_set))
1312     {
1313       errmsg ("missing arguments!");
1314       return -99;
1315     }
1316
1317   if (vrf_set && bd_index_set)
1318     {
1319       errmsg ("error: both vrf and bd entered!");
1320       return -99;
1321     }
1322
1323   M (LISP_EID_TABLE_ADD_DEL_MAP, mp);
1324
1325   mp->is_add = is_add;
1326   mp->vni = htonl (vni);
1327   mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
1328   mp->is_l2 = bd_index_set;
1329
1330   /* send */
1331   S (mp);
1332
1333   /* wait for reply */
1334   W (ret);
1335   return ret;
1336 }
1337
1338 /**
1339  * Add/del remote mapping to/from LISP control plane
1340  *
1341  * @param vam vpp API test context
1342  * @return return code
1343  */
1344 static int
1345 api_lisp_add_del_remote_mapping (vat_main_t * vam)
1346 {
1347   unformat_input_t *input = vam->input;
1348   vl_api_lisp_add_del_remote_mapping_t *mp;
1349   u32 vni = 0;
1350   lisp_eid_vat_t _eid, *eid = &_eid;
1351   lisp_eid_vat_t _seid, *seid = &_seid;
1352   u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
1353   u32 action = ~0, p, w, data_len;
1354   ip4_address_t rloc4;
1355   ip6_address_t rloc6;
1356   vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
1357   int ret;
1358
1359   clib_memset (&rloc, 0, sizeof (rloc));
1360
1361   /* Parse args required to build the message */
1362   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1363     {
1364       if (unformat (input, "del-all"))
1365         {
1366           del_all = 1;
1367         }
1368       else if (unformat (input, "del"))
1369         {
1370           is_add = 0;
1371         }
1372       else if (unformat (input, "add"))
1373         {
1374           is_add = 1;
1375         }
1376       else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
1377         {
1378           eid_set = 1;
1379         }
1380       else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
1381         {
1382           seid_set = 1;
1383         }
1384       else if (unformat (input, "vni %d", &vni))
1385         {
1386           ;
1387         }
1388       else if (unformat (input, "p %d w %d", &p, &w))
1389         {
1390           if (!curr_rloc)
1391             {
1392               errmsg ("No RLOC configured for setting priority/weight!");
1393               return -99;
1394             }
1395           curr_rloc->priority = p;
1396           curr_rloc->weight = w;
1397         }
1398       else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
1399         {
1400           rloc.ip_address.af = 0;
1401           clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6));
1402           vec_add1 (rlocs, rloc);
1403           curr_rloc = &rlocs[vec_len (rlocs) - 1];
1404         }
1405       else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
1406         {
1407           rloc.ip_address.af = 1;
1408           clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4));
1409           vec_add1 (rlocs, rloc);
1410           curr_rloc = &rlocs[vec_len (rlocs) - 1];
1411         }
1412       else if (unformat (input, "action %U",
1413                          unformat_negative_mapping_action, &action))
1414         {
1415           ;
1416         }
1417       else
1418         {
1419           clib_warning ("parse error '%U'", format_unformat_error, input);
1420           return -99;
1421         }
1422     }
1423
1424   if (0 == eid_set)
1425     {
1426       errmsg ("missing params!");
1427       return -99;
1428     }
1429
1430   if (is_add && (~0 == action) && 0 == vec_len (rlocs))
1431     {
1432       errmsg ("no action set for negative map-reply!");
1433       return -99;
1434     }
1435
1436   data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
1437
1438   M2 (LISP_ADD_DEL_REMOTE_MAPPING, mp, data_len);
1439   mp->is_add = is_add;
1440   mp->vni = htonl (vni);
1441   mp->action = (u8) action;
1442   mp->is_src_dst = seid_set;
1443   mp->del_all = del_all;
1444   lisp_eid_put_vat (&mp->deid, eid);
1445   lisp_eid_put_vat (&mp->seid, seid);
1446
1447   mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
1448   clib_memcpy (mp->rlocs, rlocs, data_len);
1449   vec_free (rlocs);
1450
1451   /* send it... */
1452   S (mp);
1453
1454   /* Wait for a reply... */
1455   W (ret);
1456   return ret;
1457 }
1458
1459 /**
1460  * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
1461  * forwarding entries in data-plane accordingly.
1462  *
1463  * @param vam vpp API test context
1464  * @return return code
1465  */
1466 static int
1467 api_lisp_add_del_adjacency (vat_main_t * vam)
1468 {
1469   unformat_input_t *input = vam->input;
1470   vl_api_lisp_add_del_adjacency_t *mp;
1471   u32 vni = 0;
1472   u8 is_add = 1;
1473   int ret;
1474   lisp_eid_vat_t leid, reid;
1475
1476   leid.type = reid.type = (u8) ~ 0;
1477
1478   /* Parse args required to build the message */
1479   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1480     {
1481       if (unformat (input, "del"))
1482         {
1483           is_add = 0;
1484         }
1485       else if (unformat (input, "add"))
1486         {
1487           is_add = 1;
1488         }
1489       else if (unformat (input, "reid %U/%d", unformat_ip46_address,
1490                          &reid.addr.ip, &reid.len))
1491         {
1492           reid.type = 0;        /* ipv4 */
1493         }
1494       else if (unformat (input, "reid %U", unformat_ethernet_address,
1495                          &reid.addr.mac))
1496         {
1497           reid.type = 1;        /* mac */
1498         }
1499       else if (unformat (input, "leid %U/%d", unformat_ip46_address,
1500                          &leid.addr.ip, &leid.len))
1501         {
1502           leid.type = 0;        /* ipv4 */
1503         }
1504       else if (unformat (input, "leid %U", unformat_ethernet_address,
1505                          &leid.addr.mac))
1506         {
1507           leid.type = 1;        /* mac */
1508         }
1509       else if (unformat (input, "vni %d", &vni))
1510         {
1511           ;
1512         }
1513       else
1514         {
1515           errmsg ("parse error '%U'", format_unformat_error, input);
1516           return -99;
1517         }
1518     }
1519
1520   if ((u8) ~ 0 == reid.type)
1521     {
1522       errmsg ("missing params!");
1523       return -99;
1524     }
1525
1526   if (leid.type != reid.type)
1527     {
1528       errmsg ("remote and local EIDs are of different types!");
1529       return -99;
1530     }
1531
1532   M (LISP_ADD_DEL_ADJACENCY, mp);
1533   mp->is_add = is_add;
1534   mp->vni = htonl (vni);
1535   lisp_eid_put_vat (&mp->leid, &leid);
1536   lisp_eid_put_vat (&mp->reid, &reid);
1537
1538   /* send it... */
1539   S (mp);
1540
1541   /* Wait for a reply... */
1542   W (ret);
1543   return ret;
1544 }
1545
1546 /**
1547  * Add/del map request itr rlocs from LISP control plane and updates
1548  *
1549  * @param vam vpp API test context
1550  * @return return code
1551  */
1552 static int
1553 api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
1554 {
1555   unformat_input_t *input = vam->input;
1556   vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
1557   u8 *locator_set_name = 0;
1558   u8 locator_set_name_set = 0;
1559   u8 is_add = 1;
1560   int ret;
1561
1562   /* Parse args required to build the message */
1563   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1564     {
1565       if (unformat (input, "del"))
1566         {
1567           is_add = 0;
1568         }
1569       else if (unformat (input, "%_%v%_", &locator_set_name))
1570         {
1571           locator_set_name_set = 1;
1572         }
1573       else
1574         {
1575           clib_warning ("parse error '%U'", format_unformat_error, input);
1576           return -99;
1577         }
1578     }
1579
1580   if (is_add && !locator_set_name_set)
1581     {
1582       errmsg ("itr-rloc is not set!");
1583       return -99;
1584     }
1585
1586   if (is_add && vec_len (locator_set_name) > 64)
1587     {
1588       errmsg ("itr-rloc locator-set name too long");
1589       vec_free (locator_set_name);
1590       return -99;
1591     }
1592
1593   M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
1594   mp->is_add = is_add;
1595   if (is_add)
1596     {
1597       clib_memcpy (mp->locator_set_name, locator_set_name,
1598                    vec_len (locator_set_name));
1599     }
1600   else
1601     {
1602       clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
1603     }
1604   vec_free (locator_set_name);
1605
1606   /* send it... */
1607   S (mp);
1608
1609   /* Wait for a reply... */
1610   W (ret);
1611   return ret;
1612 }
1613
1614 static int
1615 api_lisp_locator_dump (vat_main_t * vam)
1616 {
1617   unformat_input_t *input = vam->input;
1618   vl_api_lisp_locator_dump_t *mp;
1619   vl_api_control_ping_t *mp_ping;
1620   u8 is_index_set = 0, is_name_set = 0;
1621   u8 *ls_name = 0;
1622   u32 ls_index = ~0;
1623   int ret;
1624
1625   /* Parse args required to build the message */
1626   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1627     {
1628       if (unformat (input, "ls_name %_%v%_", &ls_name))
1629         {
1630           is_name_set = 1;
1631         }
1632       else if (unformat (input, "ls_index %d", &ls_index))
1633         {
1634           is_index_set = 1;
1635         }
1636       else
1637         {
1638           errmsg ("parse error '%U'", format_unformat_error, input);
1639           return -99;
1640         }
1641     }
1642
1643   if (!is_index_set && !is_name_set)
1644     {
1645       errmsg ("error: expected lisp of index or name!");
1646       return -99;
1647     }
1648
1649   if (is_index_set && is_name_set)
1650     {
1651       errmsg ("error: only lisp param expected!");
1652       return -99;
1653     }
1654
1655   if (vec_len (ls_name) > 62)
1656     {
1657       errmsg ("error: locator set name too long!");
1658       return -99;
1659     }
1660
1661   if (!vam->json_output)
1662     {
1663       print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
1664     }
1665
1666   M (LISP_LOCATOR_DUMP, mp);
1667   mp->is_index_set = is_index_set;
1668
1669   if (is_index_set)
1670     mp->ls_index = clib_host_to_net_u32 (ls_index);
1671   else
1672     {
1673       vec_add1 (ls_name, 0);
1674       strncpy ((char *) mp->ls_name, (char *) ls_name,
1675                sizeof (mp->ls_name) - 1);
1676     }
1677
1678   /* send it... */
1679   S (mp);
1680
1681   /* Use a control ping for synchronization */
1682   if (!lisp_test_main.ping_id)
1683     lisp_test_main.ping_id =
1684       vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
1685   mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
1686   mp_ping->_vl_msg_id = htons (lisp_test_main.ping_id);
1687   mp_ping->client_index = vam->my_client_index;
1688
1689   fformat (vam->ofp, "Sending ping id=%d\n", lisp_test_main.ping_id);
1690
1691   vam->result_ready = 0;
1692   S (mp_ping);
1693
1694   /* Wait for a reply... */
1695   W (ret);
1696   return ret;
1697 }
1698
1699 static int
1700 api_lisp_locator_set_dump (vat_main_t * vam)
1701 {
1702   vl_api_lisp_locator_set_dump_t *mp;
1703   vl_api_control_ping_t *mp_ping;
1704   unformat_input_t *input = vam->input;
1705   u8 filter = 0;
1706   int ret;
1707
1708   /* Parse args required to build the message */
1709   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1710     {
1711       if (unformat (input, "local"))
1712         {
1713           filter = 1;
1714         }
1715       else if (unformat (input, "remote"))
1716         {
1717           filter = 2;
1718         }
1719       else
1720         {
1721           errmsg ("parse error '%U'", format_unformat_error, input);
1722           return -99;
1723         }
1724     }
1725
1726   if (!vam->json_output)
1727     {
1728       print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
1729     }
1730
1731   M (LISP_LOCATOR_SET_DUMP, mp);
1732
1733   mp->filter = filter;
1734
1735   /* send it... */
1736   S (mp);
1737
1738   /* Use a control ping for synchronization */
1739   LISP_PING (&lisp_test_main, mp_ping);
1740   S (mp_ping);
1741
1742   /* Wait for a reply... */
1743   W (ret);
1744   return ret;
1745 }
1746
1747 static int
1748 api_lisp_eid_table_map_dump (vat_main_t * vam)
1749 {
1750   u8 is_l2 = 0;
1751   u8 mode_set = 0;
1752   unformat_input_t *input = vam->input;
1753   vl_api_lisp_eid_table_map_dump_t *mp;
1754   vl_api_control_ping_t *mp_ping;
1755   int ret;
1756
1757   /* Parse args required to build the message */
1758   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1759     {
1760       if (unformat (input, "l2"))
1761         {
1762           is_l2 = 1;
1763           mode_set = 1;
1764         }
1765       else if (unformat (input, "l3"))
1766         {
1767           is_l2 = 0;
1768           mode_set = 1;
1769         }
1770       else
1771         {
1772           errmsg ("parse error '%U'", format_unformat_error, input);
1773           return -99;
1774         }
1775     }
1776
1777   if (!mode_set)
1778     {
1779       errmsg ("expected lisp of 'l2' or 'l3' parameter!");
1780       return -99;
1781     }
1782
1783   if (!vam->json_output)
1784     {
1785       print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1786     }
1787
1788   M (LISP_EID_TABLE_MAP_DUMP, mp);
1789   mp->is_l2 = is_l2;
1790
1791   /* send it... */
1792   S (mp);
1793
1794   /* Use a control ping for synchronization */
1795   LISP_PING (&lisp_test_main, mp_ping);
1796   S (mp_ping);
1797
1798   /* Wait for a reply... */
1799   W (ret);
1800   return ret;
1801 }
1802
1803 static int
1804 api_lisp_eid_table_vni_dump (vat_main_t * vam)
1805 {
1806   vl_api_lisp_eid_table_vni_dump_t *mp;
1807   vl_api_control_ping_t *mp_ping;
1808   int ret;
1809
1810   if (!vam->json_output)
1811     {
1812       print (vam->ofp, "VNI");
1813     }
1814
1815   M (LISP_EID_TABLE_VNI_DUMP, mp);
1816
1817   /* send it... */
1818   S (mp);
1819
1820   /* Use a control ping for synchronization */
1821   LISP_PING (&lisp_test_main, mp_ping);
1822   S (mp_ping);
1823
1824   /* Wait for a reply... */
1825   W (ret);
1826   return ret;
1827 }
1828
1829 static int
1830 api_lisp_eid_table_dump (vat_main_t * vam)
1831 {
1832   unformat_input_t *i = vam->input;
1833   vl_api_lisp_eid_table_dump_t *mp;
1834   vl_api_control_ping_t *mp_ping;
1835   u8 filter = 0;
1836   int ret;
1837   u32 vni, t = 0;
1838   lisp_eid_vat_t eid;
1839   u8 eid_set = 0;
1840
1841   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1842     {
1843       if (unformat
1844           (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len))
1845         {
1846           eid_set = 1;
1847           eid.type = 0;
1848         }
1849       else
1850         if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac))
1851         {
1852           eid_set = 1;
1853           eid.type = 1;
1854         }
1855       else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh))
1856         {
1857           eid_set = 1;
1858           eid.type = 2;
1859         }
1860       else if (unformat (i, "vni %d", &t))
1861         {
1862           vni = t;
1863         }
1864       else if (unformat (i, "local"))
1865         {
1866           filter = 1;
1867         }
1868       else if (unformat (i, "remote"))
1869         {
1870           filter = 2;
1871         }
1872       else
1873         {
1874           errmsg ("parse error '%U'", format_unformat_error, i);
1875           return -99;
1876         }
1877     }
1878
1879   if (!vam->json_output)
1880     {
1881       print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
1882              "type", "ls_index", "ttl", "authoritative", "key_id", "key");
1883     }
1884
1885   M (LISP_EID_TABLE_DUMP, mp);
1886
1887   mp->filter = filter;
1888   if (eid_set)
1889     {
1890       mp->eid_set = 1;
1891       mp->vni = htonl (vni);
1892       lisp_eid_put_vat (&mp->eid, &eid);
1893     }
1894
1895   /* send it... */
1896   S (mp);
1897
1898   /* Use a control ping for synchronization */
1899   LISP_PING (&lisp_test_main, mp_ping);
1900   S (mp_ping);
1901
1902   /* Wait for a reply... */
1903   W (ret);
1904   return ret;
1905 }
1906
1907
1908 static int
1909 api_lisp_adjacencies_get (vat_main_t * vam)
1910 {
1911   unformat_input_t *i = vam->input;
1912   vl_api_lisp_adjacencies_get_t *mp;
1913   u8 vni_set = 0;
1914   u32 vni = ~0;
1915   int ret;
1916
1917   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1918     {
1919       if (unformat (i, "vni %d", &vni))
1920         {
1921           vni_set = 1;
1922         }
1923       else
1924         {
1925           errmsg ("parse error '%U'", format_unformat_error, i);
1926           return -99;
1927         }
1928     }
1929
1930   if (!vni_set)
1931     {
1932       errmsg ("vni not set!");
1933       return -99;
1934     }
1935
1936   if (!vam->json_output)
1937     {
1938       print (vam->ofp, "%s %40s", "leid", "reid");
1939     }
1940
1941   M (LISP_ADJACENCIES_GET, mp);
1942   mp->vni = clib_host_to_net_u32 (vni);
1943
1944   /* send it... */
1945   S (mp);
1946
1947   /* Wait for a reply... */
1948   W (ret);
1949   return ret;
1950 }
1951
1952 static int
1953 api_lisp_map_server_dump (vat_main_t * vam)
1954 {
1955   vl_api_lisp_map_server_dump_t *mp;
1956   vl_api_control_ping_t *mp_ping;
1957   int ret;
1958
1959   if (!vam->json_output)
1960     {
1961       print (vam->ofp, "%=20s", "Map server");
1962     }
1963
1964   M (LISP_MAP_SERVER_DUMP, mp);
1965   /* send it... */
1966   S (mp);
1967
1968   /* Use a control ping for synchronization */
1969   LISP_PING (&lisp_test_main, mp_ping);
1970   S (mp_ping);
1971
1972   /* Wait for a reply... */
1973   W (ret);
1974   return ret;
1975 }
1976
1977 static int
1978 api_lisp_map_resolver_dump (vat_main_t * vam)
1979 {
1980   vl_api_lisp_map_resolver_dump_t *mp;
1981   vl_api_control_ping_t *mp_ping;
1982   int ret;
1983
1984   if (!vam->json_output)
1985     {
1986       print (vam->ofp, "%=20s", "Map resolver");
1987     }
1988
1989   M (LISP_MAP_RESOLVER_DUMP, mp);
1990   /* send it... */
1991   S (mp);
1992
1993   /* Use a control ping for synchronization */
1994   LISP_PING (&lisp_test_main, mp_ping);
1995   S (mp_ping);
1996
1997   /* Wait for a reply... */
1998   W (ret);
1999   return ret;
2000 }
2001
2002 static int
2003 api_show_lisp_status (vat_main_t * vam)
2004 {
2005   vl_api_show_lisp_status_t *mp;
2006   int ret;
2007
2008   if (!vam->json_output)
2009     {
2010       print (vam->ofp, "%-20s%-16s", "LISP status", "locator-set");
2011     }
2012
2013   M (SHOW_LISP_STATUS, mp);
2014   /* send it... */
2015   S (mp);
2016   /* Wait for a reply... */
2017   W (ret);
2018   return ret;
2019 }
2020
2021 static int
2022 api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
2023 {
2024   vl_api_lisp_get_map_request_itr_rlocs_t *mp;
2025   int ret;
2026
2027   if (!vam->json_output)
2028     {
2029       print (vam->ofp, "%=20s", "itr-rlocs:");
2030     }
2031
2032   M (LISP_GET_MAP_REQUEST_ITR_RLOCS, mp);
2033   /* send it... */
2034   S (mp);
2035   /* Wait for a reply... */
2036   W (ret);
2037   return ret;
2038 }
2039
2040 #define vat_plugin_register vat_plugin_register_cp
2041 #include <lisp/lisp-cp/lisp.api_test.c>
2042
2043 /*
2044  * fd.io coding-style-patch-verification: ON
2045  *
2046  * Local Variables:
2047  * eval: (c-set-style "gnu")
2048  * End:
2049  */