misc: api move continued
[vpp.git] / src / plugins / lisp / lisp-cp / one_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/one.api_enum.h>
28 #include <lisp/lisp-cp/one.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   u32 ping_id;
36   vat_main_t *vat_main;
37 } one_test_main_t;
38
39 one_test_main_t one_test_main;
40
41 #define __plugin_msg_base one_test_main.msg_id_base
42 #include <vlibapi/vat_helper_macros.h>
43
44 /* Macro to finish up custom dump fns */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
46 #define FINISH                                  \
47     vec_add1 (s, 0);                            \
48     vl_print (handle, (char *)s);               \
49     vec_free (s);                               \
50     return handle;
51
52 #define LISP_PING(_lm, mp_ping)                                         \
53   if (!(_lm)->ping_id)                                                  \
54     (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \
55   mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));          \
56   mp_ping->_vl_msg_id = htons ((_lm)->ping_id);                         \
57   mp_ping->client_index = vam->my_client_index;                         \
58   fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id);           \
59   vam->result_ready = 0;                                                \
60
61 typedef struct
62 {
63   u32 spi;
64   u8 si;
65 } __attribute__ ((__packed__)) lisp_nsh_api_t;
66
67 static uword
68 unformat_nsh_address (unformat_input_t * input, va_list * args)
69 {
70   lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
71   return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
72 }
73
74 static u8 *
75 format_nsh_address_vat (u8 * s, va_list * args)
76 {
77   nsh_t *a = va_arg (*args, nsh_t *);
78   return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
79 }
80
81 static u8 *
82 format_lisp_transport_protocol (u8 * s, va_list * args)
83 {
84   u32 proto = va_arg (*args, u32);
85
86   switch (proto)
87     {
88     case 1:
89       return format (s, "udp");
90     case 2:
91       return format (s, "api");
92     default:
93       return 0;
94     }
95   return 0;
96 }
97
98 static void
99 vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp)
100 {
101   vat_main_t *vam = &vat_main;
102   u8 *s = 0;
103
104   if (mp->local)
105     {
106       s = format (s, "%=16d%=16d%=16d",
107                   ntohl (mp->sw_if_index), mp->priority, mp->weight);
108     }
109   else
110     {
111       s = format (s, "%=16U%=16d%=16d",
112                   format_ip46_address,
113                   mp->ip_address, mp->priority, mp->weight);
114     }
115
116   print (vam->ofp, "%v", s);
117   vec_free (s);
118 }
119
120 static void
121 vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t *
122                                           mp)
123 {
124   vat_main_t *vam = &vat_main;
125   u8 *ls_name = 0;
126
127   ls_name = format (0, "%s", mp->ls_name);
128
129   print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
130          ls_name);
131   vec_free (ls_name);
132 }
133
134 static void vl_api_one_get_transport_protocol_reply_t_handler
135   (vl_api_one_get_transport_protocol_reply_t * mp)
136 {
137   vat_main_t *vam = &vat_main;
138   i32 retval = ntohl (mp->retval);
139   if (vam->async_mode)
140     {
141       vam->async_errors += (retval < 0);
142     }
143   else
144     {
145       u32 proto = mp->protocol;
146       print (vam->ofp, "Transport protocol: %U",
147              format_lisp_transport_protocol, proto);
148       vam->retval = retval;
149       vam->result_ready = 1;
150     }
151 }
152
153 static void vl_api_one_add_del_locator_set_reply_t_handler
154   (vl_api_one_add_del_locator_set_reply_t * mp)
155 {
156   vat_main_t *vam = &vat_main;
157   i32 retval = ntohl (mp->retval);
158   if (vam->async_mode)
159     {
160       vam->async_errors += (retval < 0);
161     }
162   else
163     {
164       vam->retval = retval;
165       vam->result_ready = 1;
166     }
167 }
168
169 static u8 *
170 format_lisp_flat_eid (u8 * s, va_list * args)
171 {
172   vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *);
173
174   switch (eid->type)
175     {
176     case EID_TYPE_API_PREFIX:
177       if (eid->address.prefix.address.af)
178         return format (s, "%U/%d", format_ip6_address,
179                        eid->address.prefix.address.un.ip6,
180                        eid->address.prefix.len);
181       return format (s, "%U/%d", format_ip4_address,
182                      eid->address.prefix.address.un.ip4,
183                      eid->address.prefix.len);
184     case EID_TYPE_API_MAC:
185       return format (s, "%U", format_ethernet_address, eid->address.mac);
186     case EID_TYPE_API_NSH:
187       return format (s, "%U", format_nsh_address_vat, eid->address.nsh);
188     }
189   return 0;
190 }
191
192 static u8 *
193 format_lisp_eid_vat (u8 * s, va_list * args)
194 {
195   vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *);
196   vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *);
197   u8 is_src_dst = (u8) va_arg (*args, int);
198
199   if (is_src_dst)
200     s = format (s, "%U|", format_lisp_flat_eid, seid);
201
202   s = format (s, "%U", format_lisp_flat_eid, deid);
203
204   return s;
205 }
206
207 static void
208 vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp)
209 {
210   vat_main_t *vam = &vat_main;
211   u8 *s = 0, *eid = 0;
212
213   if (~0 == mp->locator_set_index)
214     s = format (0, "action: %d", mp->action);
215   else
216     s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
217
218   eid = format (0, "%U", format_lisp_eid_vat,
219                 &mp->deid, &mp->seid, mp->is_src_dst);
220   vec_add1 (eid, 0);
221
222   print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
223          clib_net_to_host_u32 (mp->vni),
224          eid,
225          mp->is_local ? "local" : "remote",
226          s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
227          clib_net_to_host_u16 (mp->key.id), mp->key.key);
228
229   vec_free (s);
230   vec_free (eid);
231 }
232
233 static void
234 vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp)
235 {
236   vat_main_t *vam = &vat_main;
237   u8 *seid = 0, *deid = 0;
238   ip46_address_t lloc, rloc;
239
240   deid = format (0, "%U", format_lisp_eid_vat, &mp->deid, 0, 0);
241
242   seid = format (0, "%U", format_lisp_eid_vat, &mp->seid, 0, 0);
243
244   vec_add1 (deid, 0);
245   vec_add1 (seid, 0);
246
247   if (mp->lloc.af)
248     {
249       clib_memcpy (&lloc.ip6, mp->lloc.un.ip6, 16);
250       clib_memcpy (&rloc.ip6, mp->rloc.un.ip6, 16);
251     }
252   else
253     {
254       clib_memcpy (&lloc.ip4, mp->lloc.un.ip4, 4);
255       clib_memcpy (&rloc.ip4, mp->rloc.un.ip4, 4);
256     }
257
258
259   print (vam->ofp, "([%d] %s %s) (%U %U) %u %u",
260          clib_net_to_host_u32 (mp->vni),
261          seid, deid,
262          format_ip46_address, lloc,
263          format_ip46_address, rloc,
264          clib_net_to_host_u32 (mp->pkt_count),
265          clib_net_to_host_u32 (mp->bytes));
266
267   vec_free (deid);
268   vec_free (seid);
269 }
270
271 static void
272   vl_api_one_eid_table_map_details_t_handler
273   (vl_api_one_eid_table_map_details_t * mp)
274 {
275   vat_main_t *vam = &vat_main;
276
277   u8 *line = format (0, "%=10d%=10d",
278                      clib_net_to_host_u32 (mp->vni),
279                      clib_net_to_host_u32 (mp->dp_table));
280   print (vam->ofp, "%v", line);
281   vec_free (line);
282 }
283
284 static void
285   vl_api_one_eid_table_vni_details_t_handler
286   (vl_api_one_eid_table_vni_details_t * mp)
287 {
288   vat_main_t *vam = &vat_main;
289
290   u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
291   print (vam->ofp, "%v", line);
292   vec_free (line);
293 }
294
295 static void
296   vl_api_show_one_map_register_fallback_threshold_reply_t_handler
297   (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
298 {
299   vat_main_t *vam = &vat_main;
300   int retval = clib_net_to_host_u32 (mp->retval);
301
302   print (vam->ofp, "fallback threshold value: %d", mp->value);
303
304   vam->retval = retval;
305   vam->result_ready = 1;
306 }
307
308 static void
309   vl_api_show_one_map_register_state_reply_t_handler
310   (vl_api_show_one_map_register_state_reply_t * mp)
311 {
312   vat_main_t *vam = &vat_main;
313   int retval = clib_net_to_host_u32 (mp->retval);
314
315   print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled");
316
317   vam->retval = retval;
318   vam->result_ready = 1;
319 }
320
321 static void
322   vl_api_show_one_rloc_probe_state_reply_t_handler
323   (vl_api_show_one_rloc_probe_state_reply_t * mp)
324 {
325   vat_main_t *vam = &vat_main;
326   int retval = clib_net_to_host_u32 (mp->retval);
327
328   if (retval)
329     goto end;
330
331   print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled");
332 end:
333   vam->retval = retval;
334   vam->result_ready = 1;
335 }
336
337 static void
338   vl_api_show_one_stats_enable_disable_reply_t_handler
339   (vl_api_show_one_stats_enable_disable_reply_t * mp)
340 {
341   vat_main_t *vam = &vat_main;
342   int retval = clib_net_to_host_u32 (mp->retval);
343
344   if (retval)
345     goto end;
346
347   print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled");
348 end:
349   vam->retval = retval;
350   vam->result_ready = 1;
351 }
352
353 static void
354   vl_api_one_ndp_entries_get_reply_t_handler
355   (vl_api_one_ndp_entries_get_reply_t * mp)
356 {
357   vat_main_t *vam = &vat_main;
358   u32 i, n;
359   int retval = clib_net_to_host_u32 (mp->retval);
360
361   if (retval)
362     goto end;
363
364   n = clib_net_to_host_u32 (mp->count);
365
366   for (i = 0; i < n; i++)
367     print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6,
368            format_ethernet_address, mp->entries[i].mac);
369
370 end:
371   vam->retval = retval;
372   vam->result_ready = 1;
373 }
374
375 static void
376   vl_api_one_l2_arp_entries_get_reply_t_handler
377   (vl_api_one_l2_arp_entries_get_reply_t * mp)
378 {
379   vat_main_t *vam = &vat_main;
380   u32 i, n;
381   int retval = clib_net_to_host_u32 (mp->retval);
382
383   if (retval)
384     goto end;
385
386   n = clib_net_to_host_u32 (mp->count);
387
388   for (i = 0; i < n; i++)
389     print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4,
390            format_ethernet_address, mp->entries[i].mac);
391
392 end:
393   vam->retval = retval;
394   vam->result_ready = 1;
395 }
396
397 static void
398 vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp)
399 {
400   vat_main_t *vam = &vat_main;
401   u32 i, n;
402   int retval = clib_net_to_host_u32 (mp->retval);
403
404   if (retval)
405     goto end;
406
407   n = clib_net_to_host_u32 (mp->count);
408
409   for (i = 0; i < n; i++)
410     {
411       print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
412     }
413
414 end:
415   vam->retval = retval;
416   vam->result_ready = 1;
417 }
418
419 static void
420   vl_api_one_l2_arp_bd_get_reply_t_handler
421   (vl_api_one_l2_arp_bd_get_reply_t * mp)
422 {
423   vat_main_t *vam = &vat_main;
424   u32 i, n;
425   int retval = clib_net_to_host_u32 (mp->retval);
426
427   if (retval)
428     goto end;
429
430   n = clib_net_to_host_u32 (mp->count);
431
432   for (i = 0; i < n; i++)
433     {
434       print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
435     }
436
437 end:
438   vam->retval = retval;
439   vam->result_ready = 1;
440 }
441
442 static void
443   vl_api_one_adjacencies_get_reply_t_handler
444   (vl_api_one_adjacencies_get_reply_t * mp)
445 {
446   vat_main_t *vam = &vat_main;
447   u32 i, n;
448   int retval = clib_net_to_host_u32 (mp->retval);
449   vl_api_one_adjacency_t *a;
450
451   if (retval)
452     goto end;
453
454   n = clib_net_to_host_u32 (mp->count);
455
456   for (i = 0; i < n; i++)
457     {
458       a = &mp->adjacencies[i];
459       print (vam->ofp, "%U %40U",
460              format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid);
461     }
462
463 end:
464   vam->retval = retval;
465   vam->result_ready = 1;
466 }
467
468 static void
469 vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp)
470 {
471   vat_main_t *vam = &vat_main;
472
473   print (vam->ofp, "%=20U",
474          mp->ip_address.af ? format_ip6_address : format_ip4_address,
475          mp->ip_address.un);
476 }
477
478 static void
479 vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t
480                                            * mp)
481 {
482   vat_main_t *vam = &vat_main;
483
484   print (vam->ofp, "%=20U",
485          mp->ip_address.af ? format_ip6_address : format_ip4_address,
486          mp->ip_address.un);
487 }
488
489 static void
490 vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp)
491 {
492   vat_main_t *vam = &vat_main;
493   i32 retval = ntohl (mp->retval);
494
495   if (0 <= retval)
496     {
497       print (vam->ofp, "feature: %s\ngpe: %s",
498              mp->feature_status ? "enabled" : "disabled",
499              mp->gpe_status ? "enabled" : "disabled");
500     }
501
502   vam->retval = retval;
503   vam->result_ready = 1;
504 }
505
506 static void
507   vl_api_one_get_map_request_itr_rlocs_reply_t_handler
508   (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
509 {
510   vat_main_t *vam = &vat_main;
511   i32 retval = ntohl (mp->retval);
512
513   if (retval >= 0)
514     {
515       print (vam->ofp, "%=20s", mp->locator_set_name);
516     }
517
518   vam->retval = retval;
519   vam->result_ready = 1;
520 }
521
522 static u8 *
523 format_lisp_map_request_mode (u8 * s, va_list * args)
524 {
525   u32 mode = va_arg (*args, u32);
526
527   switch (mode)
528     {
529     case 0:
530       return format (0, "dst-only");
531     case 1:
532       return format (0, "src-dst");
533     }
534   return 0;
535 }
536
537 static void
538   vl_api_show_one_map_request_mode_reply_t_handler
539   (vl_api_show_one_map_request_mode_reply_t * mp)
540 {
541   vat_main_t *vam = &vat_main;
542   i32 retval = ntohl (mp->retval);
543
544   if (0 <= retval)
545     {
546       u32 mode = mp->mode;
547       print (vam->ofp, "map_request_mode: %U",
548              format_lisp_map_request_mode, mode);
549     }
550
551   vam->retval = retval;
552   vam->result_ready = 1;
553 }
554
555 static void
556   vl_api_one_show_xtr_mode_reply_t_handler
557   (vl_api_one_show_xtr_mode_reply_t * mp)
558 {
559   vat_main_t *vam = &vat_main;
560   i32 retval = ntohl (mp->retval);
561
562   if (0 <= retval)
563     {
564       print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled");
565     }
566
567   vam->retval = retval;
568   vam->result_ready = 1;
569 }
570
571 static void
572   vl_api_one_show_pitr_mode_reply_t_handler
573   (vl_api_one_show_pitr_mode_reply_t * mp)
574 {
575   vat_main_t *vam = &vat_main;
576   i32 retval = ntohl (mp->retval);
577
578   if (0 <= retval)
579     {
580       print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled");
581     }
582
583   vam->retval = retval;
584   vam->result_ready = 1;
585 }
586
587 static void
588   vl_api_one_show_petr_mode_reply_t_handler
589   (vl_api_one_show_petr_mode_reply_t * mp)
590 {
591   vat_main_t *vam = &vat_main;
592   i32 retval = ntohl (mp->retval);
593
594   if (0 <= retval)
595     {
596       print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled");
597     }
598
599   vam->retval = retval;
600   vam->result_ready = 1;
601 }
602
603 static void
604   vl_api_show_one_use_petr_reply_t_handler
605   (vl_api_show_one_use_petr_reply_t * mp)
606 {
607   vat_main_t *vam = &vat_main;
608   i32 retval = ntohl (mp->retval);
609
610   if (0 <= retval)
611     {
612       print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled");
613       if (mp->status)
614         {
615           print (vam->ofp, "Proxy-ETR address; %U",
616                  mp->ip_address.af ? format_ip6_address : format_ip4_address,
617                  mp->ip_address.un);
618         }
619     }
620
621   vam->retval = retval;
622   vam->result_ready = 1;
623 }
624
625 static void
626   vl_api_show_one_nsh_mapping_reply_t_handler
627   (vl_api_show_one_nsh_mapping_reply_t * mp)
628 {
629   vat_main_t *vam = &vat_main;
630   i32 retval = ntohl (mp->retval);
631
632   if (0 <= retval)
633     {
634       print (vam->ofp, "%-20s%-16s",
635              mp->is_set ? "set" : "not-set",
636              mp->is_set ? (char *) mp->locator_set_name : "");
637     }
638
639   vam->retval = retval;
640   vam->result_ready = 1;
641 }
642
643 static void
644   vl_api_show_one_map_register_ttl_reply_t_handler
645   (vl_api_show_one_map_register_ttl_reply_t * mp)
646 {
647   vat_main_t *vam = &vat_main;
648   i32 retval = ntohl (mp->retval);
649
650   if (0 <= retval)
651     {
652       print (vam->ofp, "ttl: %u", mp->ttl);
653     }
654
655   vam->retval = retval;
656   vam->result_ready = 1;
657 }
658
659 static void
660 vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp)
661 {
662   vat_main_t *vam = &vat_main;
663   i32 retval = ntohl (mp->retval);
664
665   if (0 <= retval)
666     {
667       print (vam->ofp, "%-20s%-16s",
668              mp->status ? "enabled" : "disabled",
669              mp->status ? (char *) mp->locator_set_name : "");
670     }
671
672   vam->retval = retval;
673   vam->result_ready = 1;
674 }
675
676 /* *INDENT-OFF* */
677 /** Used for parsing LISP eids */
678 typedef CLIB_PACKED(struct{
679   union {
680           ip46_address_t ip;
681           mac_address_t mac;
682           lisp_nsh_api_t nsh;
683   } addr;
684   u32 len;       /**< prefix length if IP */
685   u8 type;      /**< type of eid */
686 }) lisp_eid_vat_t;
687 /* *INDENT-ON* */
688
689 static uword
690 unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
691 {
692   lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
693
694   clib_memset (a, 0, sizeof (a[0]));
695
696   if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len))
697     {
698       a->type = 0;              /* ip prefix type */
699     }
700   else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac))
701     {
702       a->type = 1;              /* mac type */
703     }
704   else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh))
705     {
706       a->type = 2;              /* NSH type */
707       a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi);
708     }
709   else
710     {
711       return 0;
712     }
713
714   if (a->type == 0)
715     {
716       if (ip46_address_is_ip4 (&a->addr.ip))
717         return a->len > 32 ? 1 : 0;
718       else
719         return a->len > 128 ? 1 : 0;
720     }
721
722   return 1;
723 }
724
725 static void
726 lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid)
727 {
728   eid->type = vat_eid->type;
729   switch (eid->type)
730     {
731     case EID_TYPE_API_PREFIX:
732       if (ip46_address_is_ip4 (&vat_eid->addr.ip))
733         {
734           clib_memcpy (&eid->address.prefix.address.un.ip4,
735                        &vat_eid->addr.ip.ip4, 4);
736           eid->address.prefix.address.af = ADDRESS_IP4;
737           eid->address.prefix.len = vat_eid->len;
738         }
739       else
740         {
741           clib_memcpy (&eid->address.prefix.address.un.ip6,
742                        &vat_eid->addr.ip.ip6, 16);
743           eid->address.prefix.address.af = ADDRESS_IP6;
744           eid->address.prefix.len = vat_eid->len;
745         }
746       return;
747     case EID_TYPE_API_MAC:
748       clib_memcpy (&eid->address.mac, &vat_eid->addr.mac,
749                    sizeof (eid->address.mac));
750       return;
751     case EID_TYPE_API_NSH:
752       clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh,
753                    sizeof (eid->address.nsh));
754       return;
755     default:
756       ASSERT (0);
757       return;
758     }
759 }
760
761 static int
762 api_one_add_del_locator_set (vat_main_t * vam)
763 {
764   unformat_input_t *input = vam->input;
765   vl_api_one_add_del_locator_set_t *mp;
766   u8 is_add = 1;
767   u8 *locator_set_name = NULL;
768   u8 locator_set_name_set = 0;
769   vl_api_local_locator_t locator, *locators = 0;
770   u32 sw_if_index, priority, weight;
771   u32 data_len = 0;
772
773   int ret;
774   /* Parse args required to build the message */
775   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
776     {
777       if (unformat (input, "del"))
778         {
779           is_add = 0;
780         }
781       else if (unformat (input, "locator-set %s", &locator_set_name))
782         {
783           locator_set_name_set = 1;
784         }
785       else if (unformat (input, "sw_if_index %u p %u w %u",
786                          &sw_if_index, &priority, &weight))
787         {
788           locator.sw_if_index = htonl (sw_if_index);
789           locator.priority = priority;
790           locator.weight = weight;
791           vec_add1 (locators, locator);
792         }
793       else
794         if (unformat
795             (input, "iface %U p %u w %u", unformat_sw_if_index, vam,
796              &sw_if_index, &priority, &weight))
797         {
798           locator.sw_if_index = htonl (sw_if_index);
799           locator.priority = priority;
800           locator.weight = weight;
801           vec_add1 (locators, locator);
802         }
803       else
804         break;
805     }
806
807   if (locator_set_name_set == 0)
808     {
809       errmsg ("missing locator-set name");
810       vec_free (locators);
811       return -99;
812     }
813
814   if (vec_len (locator_set_name) > 64)
815     {
816       errmsg ("locator-set name too long");
817       vec_free (locator_set_name);
818       vec_free (locators);
819       return -99;
820     }
821   vec_add1 (locator_set_name, 0);
822
823   data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
824
825   /* Construct the API message */
826   M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len);
827
828   mp->is_add = is_add;
829   clib_memcpy (mp->locator_set_name, locator_set_name,
830                vec_len (locator_set_name));
831   vec_free (locator_set_name);
832
833   mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
834   if (locators)
835     clib_memcpy (mp->locators, locators, data_len);
836   vec_free (locators);
837
838   /* send it... */
839   S (mp);
840
841   /* Wait for a reply... */
842   W (ret);
843   return ret;
844 }
845
846 #define api_lisp_add_del_locator_set api_one_add_del_locator_set
847
848 static int
849 api_one_add_del_locator (vat_main_t * vam)
850 {
851   unformat_input_t *input = vam->input;
852   vl_api_one_add_del_locator_t *mp;
853   u32 tmp_if_index = ~0;
854   u32 sw_if_index = ~0;
855   u8 sw_if_index_set = 0;
856   u8 sw_if_index_if_name_set = 0;
857   u32 priority = ~0;
858   u8 priority_set = 0;
859   u32 weight = ~0;
860   u8 weight_set = 0;
861   u8 is_add = 1;
862   u8 *locator_set_name = NULL;
863   u8 locator_set_name_set = 0;
864   int ret;
865
866   /* Parse args required to build the message */
867   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
868     {
869       if (unformat (input, "del"))
870         {
871           is_add = 0;
872         }
873       else if (unformat (input, "locator-set %s", &locator_set_name))
874         {
875           locator_set_name_set = 1;
876         }
877       else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
878                          &tmp_if_index))
879         {
880           sw_if_index_if_name_set = 1;
881           sw_if_index = tmp_if_index;
882         }
883       else if (unformat (input, "sw_if_index %d", &tmp_if_index))
884         {
885           sw_if_index_set = 1;
886           sw_if_index = tmp_if_index;
887         }
888       else if (unformat (input, "p %d", &priority))
889         {
890           priority_set = 1;
891         }
892       else if (unformat (input, "w %d", &weight))
893         {
894           weight_set = 1;
895         }
896       else
897         break;
898     }
899
900   if (locator_set_name_set == 0)
901     {
902       errmsg ("missing locator-set name");
903       return -99;
904     }
905
906   if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
907     {
908       errmsg ("missing sw_if_index");
909       vec_free (locator_set_name);
910       return -99;
911     }
912
913   if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
914     {
915       errmsg ("cannot use both params interface name and sw_if_index");
916       vec_free (locator_set_name);
917       return -99;
918     }
919
920   if (priority_set == 0)
921     {
922       errmsg ("missing locator-set priority");
923       vec_free (locator_set_name);
924       return -99;
925     }
926
927   if (weight_set == 0)
928     {
929       errmsg ("missing locator-set weight");
930       vec_free (locator_set_name);
931       return -99;
932     }
933
934   if (vec_len (locator_set_name) > 64)
935     {
936       errmsg ("locator-set name too long");
937       vec_free (locator_set_name);
938       return -99;
939     }
940   vec_add1 (locator_set_name, 0);
941
942   /* Construct the API message */
943   M (ONE_ADD_DEL_LOCATOR, mp);
944
945   mp->is_add = is_add;
946   mp->sw_if_index = ntohl (sw_if_index);
947   mp->priority = priority;
948   mp->weight = weight;
949   clib_memcpy (mp->locator_set_name, locator_set_name,
950                vec_len (locator_set_name));
951   vec_free (locator_set_name);
952
953   /* send it... */
954   S (mp);
955
956   /* Wait for a reply... */
957   W (ret);
958   return ret;
959 }
960
961 #define api_lisp_add_del_locator api_one_add_del_locator
962
963 static int
964 api_one_add_del_local_eid (vat_main_t * vam)
965 {
966   unformat_input_t *input = vam->input;
967   vl_api_one_add_del_local_eid_t *mp;
968   u8 is_add = 1;
969   u8 eid_set = 0;
970   lisp_eid_vat_t _eid, *eid = &_eid;
971   u8 *locator_set_name = 0;
972   u8 locator_set_name_set = 0;
973   u32 vni = 0;
974   u16 key_id = 0;
975   u8 *key = 0;
976   int ret;
977
978   /* Parse args required to build the message */
979   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
980     {
981       if (unformat (input, "del"))
982         {
983           is_add = 0;
984         }
985       else if (unformat (input, "vni %d", &vni))
986         {
987           ;
988         }
989       else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
990         {
991           eid_set = 1;
992         }
993       else if (unformat (input, "locator-set %s", &locator_set_name))
994         {
995           locator_set_name_set = 1;
996         }
997       else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
998         ;
999       else if (unformat (input, "secret-key %_%v%_", &key))
1000         ;
1001       else
1002         break;
1003     }
1004
1005   if (locator_set_name_set == 0)
1006     {
1007       errmsg ("missing locator-set name");
1008       return -99;
1009     }
1010
1011   if (0 == eid_set)
1012     {
1013       errmsg ("EID address not set!");
1014       vec_free (locator_set_name);
1015       return -99;
1016     }
1017
1018   if (key && (0 == key_id))
1019     {
1020       errmsg ("invalid key_id!");
1021       return -99;
1022     }
1023
1024   if (vec_len (key) > 64)
1025     {
1026       errmsg ("key too long");
1027       vec_free (key);
1028       return -99;
1029     }
1030
1031   if (vec_len (locator_set_name) > 64)
1032     {
1033       errmsg ("locator-set name too long");
1034       vec_free (locator_set_name);
1035       return -99;
1036     }
1037   vec_add1 (locator_set_name, 0);
1038
1039   /* Construct the API message */
1040   M (ONE_ADD_DEL_LOCAL_EID, mp);
1041
1042   mp->is_add = is_add;
1043   lisp_eid_put_vat (&mp->eid, eid);
1044   mp->vni = clib_host_to_net_u32 (vni);
1045   mp->key.id = key_id;
1046   clib_memcpy (mp->locator_set_name, locator_set_name,
1047                vec_len (locator_set_name));
1048   clib_memcpy (mp->key.key, key, vec_len (key));
1049
1050   vec_free (locator_set_name);
1051   vec_free (key);
1052
1053   /* send it... */
1054   S (mp);
1055
1056   /* Wait for a reply... */
1057   W (ret);
1058   return ret;
1059 }
1060
1061 static int
1062 api_one_add_del_map_server (vat_main_t * vam)
1063 {
1064   unformat_input_t *input = vam->input;
1065   vl_api_one_add_del_map_server_t *mp;
1066   u8 is_add = 1;
1067   u8 ipv4_set = 0;
1068   u8 ipv6_set = 0;
1069   ip4_address_t ipv4;
1070   ip6_address_t ipv6;
1071   int ret;
1072
1073   /* Parse args required to build the message */
1074   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1075     {
1076       if (unformat (input, "del"))
1077         {
1078           is_add = 0;
1079         }
1080       else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
1081         {
1082           ipv4_set = 1;
1083         }
1084       else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
1085         {
1086           ipv6_set = 1;
1087         }
1088       else
1089         break;
1090     }
1091
1092   if (ipv4_set && ipv6_set)
1093     {
1094       errmsg ("both eid v4 and v6 addresses set");
1095       return -99;
1096     }
1097
1098   if (!ipv4_set && !ipv6_set)
1099     {
1100       errmsg ("eid addresses not set");
1101       return -99;
1102     }
1103
1104   /* Construct the API message */
1105   M (ONE_ADD_DEL_MAP_SERVER, mp);
1106
1107   mp->is_add = is_add;
1108   if (ipv6_set)
1109     {
1110       mp->ip_address.af = 1;
1111       clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
1112     }
1113   else
1114     {
1115       mp->ip_address.af = 0;
1116       clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4));
1117     }
1118
1119   /* send it... */
1120   S (mp);
1121
1122   /* Wait for a reply... */
1123   W (ret);
1124   return ret;
1125 }
1126
1127 #define api_lisp_add_del_map_server api_one_add_del_map_server
1128
1129 static int
1130 api_one_add_del_map_resolver (vat_main_t * vam)
1131 {
1132   unformat_input_t *input = vam->input;
1133   vl_api_one_add_del_map_resolver_t *mp;
1134   u8 is_add = 1;
1135   u8 ipv4_set = 0;
1136   u8 ipv6_set = 0;
1137   ip4_address_t ipv4;
1138   ip6_address_t ipv6;
1139   int ret;
1140
1141   /* Parse args required to build the message */
1142   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1143     {
1144       if (unformat (input, "del"))
1145         {
1146           is_add = 0;
1147         }
1148       else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
1149         {
1150           ipv4_set = 1;
1151         }
1152       else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
1153         {
1154           ipv6_set = 1;
1155         }
1156       else
1157         break;
1158     }
1159
1160   if (ipv4_set && ipv6_set)
1161     {
1162       errmsg ("both eid v4 and v6 addresses set");
1163       return -99;
1164     }
1165
1166   if (!ipv4_set && !ipv6_set)
1167     {
1168       errmsg ("eid addresses not set");
1169       return -99;
1170     }
1171
1172   /* Construct the API message */
1173   M (ONE_ADD_DEL_MAP_RESOLVER, mp);
1174
1175   mp->is_add = is_add;
1176   if (ipv6_set)
1177     {
1178       mp->ip_address.af = 1;
1179       clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
1180     }
1181   else
1182     {
1183       mp->ip_address.af = 0;
1184       clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4));
1185     }
1186
1187   /* send it... */
1188   S (mp);
1189
1190   /* Wait for a reply... */
1191   W (ret);
1192   return ret;
1193 }
1194
1195 static int
1196 api_one_rloc_probe_enable_disable (vat_main_t * vam)
1197 {
1198   unformat_input_t *input = vam->input;
1199   vl_api_one_rloc_probe_enable_disable_t *mp;
1200   u8 is_set = 0;
1201   u8 is_enable = 0;
1202   int ret;
1203
1204   /* Parse args required to build the message */
1205   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1206     {
1207       if (unformat (input, "enable"))
1208         {
1209           is_set = 1;
1210           is_enable = 1;
1211         }
1212       else if (unformat (input, "disable"))
1213         is_set = 1;
1214       else
1215         break;
1216     }
1217
1218   if (!is_set)
1219     {
1220       errmsg ("Value not set");
1221       return -99;
1222     }
1223
1224   /* Construct the API message */
1225   M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp);
1226
1227   mp->is_enable = is_enable;
1228
1229   /* send it... */
1230   S (mp);
1231
1232   /* Wait for a reply... */
1233   W (ret);
1234   return ret;
1235 }
1236
1237 #define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable
1238
1239 static int
1240 api_one_map_register_enable_disable (vat_main_t * vam)
1241 {
1242   unformat_input_t *input = vam->input;
1243   vl_api_one_map_register_enable_disable_t *mp;
1244   u8 is_set = 0;
1245   u8 is_enable = 0;
1246   int ret;
1247
1248   /* Parse args required to build the message */
1249   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1250     {
1251       if (unformat (input, "enable"))
1252         {
1253           is_set = 1;
1254           is_enable = 1;
1255         }
1256       else if (unformat (input, "disable"))
1257         is_set = 1;
1258       else
1259         break;
1260     }
1261
1262   if (!is_set)
1263     {
1264       errmsg ("Value not set");
1265       return -99;
1266     }
1267
1268   /* Construct the API message */
1269   M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp);
1270
1271   mp->is_enable = is_enable;
1272
1273   /* send it... */
1274   S (mp);
1275
1276   /* Wait for a reply... */
1277   W (ret);
1278   return ret;
1279 }
1280
1281 #define api_lisp_map_register_enable_disable api_one_map_register_enable_disable
1282
1283 static int
1284 api_one_enable_disable (vat_main_t * vam)
1285 {
1286   unformat_input_t *input = vam->input;
1287   vl_api_one_enable_disable_t *mp;
1288   u8 is_set = 0;
1289   u8 is_enable = 0;
1290   int ret;
1291
1292   /* Parse args required to build the message */
1293   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1294     {
1295       if (unformat (input, "enable"))
1296         {
1297           is_set = 1;
1298           is_enable = 1;
1299         }
1300       else if (unformat (input, "disable"))
1301         {
1302           is_set = 1;
1303         }
1304       else
1305         break;
1306     }
1307
1308   if (!is_set)
1309     {
1310       errmsg ("Value not set");
1311       return -99;
1312     }
1313
1314   /* Construct the API message */
1315   M (ONE_ENABLE_DISABLE, mp);
1316
1317   mp->is_enable = is_enable;
1318
1319   /* send it... */
1320   S (mp);
1321
1322   /* Wait for a reply... */
1323   W (ret);
1324   return ret;
1325 }
1326
1327 #define api_lisp_enable_disable api_one_enable_disable
1328
1329 static int
1330 api_one_enable_disable_xtr_mode (vat_main_t * vam)
1331 {
1332   unformat_input_t *input = vam->input;
1333   vl_api_one_enable_disable_xtr_mode_t *mp;
1334   u8 is_set = 0;
1335   u8 is_enable = 0;
1336   int ret;
1337
1338   /* Parse args required to build the message */
1339   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1340     {
1341       if (unformat (input, "enable"))
1342         {
1343           is_set = 1;
1344           is_enable = 1;
1345         }
1346       else if (unformat (input, "disable"))
1347         {
1348           is_set = 1;
1349         }
1350       else
1351         break;
1352     }
1353
1354   if (!is_set)
1355     {
1356       errmsg ("Value not set");
1357       return -99;
1358     }
1359
1360   /* Construct the API message */
1361   M (ONE_ENABLE_DISABLE_XTR_MODE, mp);
1362
1363   mp->is_enable = is_enable;
1364
1365   /* send it... */
1366   S (mp);
1367
1368   /* Wait for a reply... */
1369   W (ret);
1370   return ret;
1371 }
1372
1373 static int
1374 api_one_show_xtr_mode (vat_main_t * vam)
1375 {
1376   vl_api_one_show_xtr_mode_t *mp;
1377   int ret;
1378
1379   /* Construct the API message */
1380   M (ONE_SHOW_XTR_MODE, mp);
1381
1382   /* send it... */
1383   S (mp);
1384
1385   /* Wait for a reply... */
1386   W (ret);
1387   return ret;
1388 }
1389
1390 static int
1391 api_one_enable_disable_pitr_mode (vat_main_t * vam)
1392 {
1393   unformat_input_t *input = vam->input;
1394   vl_api_one_enable_disable_pitr_mode_t *mp;
1395   u8 is_set = 0;
1396   u8 is_enable = 0;
1397   int ret;
1398
1399   /* Parse args required to build the message */
1400   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1401     {
1402       if (unformat (input, "enable"))
1403         {
1404           is_set = 1;
1405           is_enable = 1;
1406         }
1407       else if (unformat (input, "disable"))
1408         {
1409           is_set = 1;
1410         }
1411       else
1412         break;
1413     }
1414
1415   if (!is_set)
1416     {
1417       errmsg ("Value not set");
1418       return -99;
1419     }
1420
1421   /* Construct the API message */
1422   M (ONE_ENABLE_DISABLE_PITR_MODE, mp);
1423
1424   mp->is_enable = is_enable;
1425
1426   /* send it... */
1427   S (mp);
1428
1429   /* Wait for a reply... */
1430   W (ret);
1431   return ret;
1432 }
1433
1434 static int
1435 api_one_show_pitr_mode (vat_main_t * vam)
1436 {
1437   vl_api_one_show_pitr_mode_t *mp;
1438   int ret;
1439
1440   /* Construct the API message */
1441   M (ONE_SHOW_PITR_MODE, mp);
1442
1443   /* send it... */
1444   S (mp);
1445
1446   /* Wait for a reply... */
1447   W (ret);
1448   return ret;
1449 }
1450
1451 static int
1452 api_one_enable_disable_petr_mode (vat_main_t * vam)
1453 {
1454   unformat_input_t *input = vam->input;
1455   vl_api_one_enable_disable_petr_mode_t *mp;
1456   u8 is_set = 0;
1457   u8 is_enable = 0;
1458   int ret;
1459
1460   /* Parse args required to build the message */
1461   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1462     {
1463       if (unformat (input, "enable"))
1464         {
1465           is_set = 1;
1466           is_enable = 1;
1467         }
1468       else if (unformat (input, "disable"))
1469         {
1470           is_set = 1;
1471         }
1472       else
1473         break;
1474     }
1475
1476   if (!is_set)
1477     {
1478       errmsg ("Value not set");
1479       return -99;
1480     }
1481
1482   /* Construct the API message */
1483   M (ONE_ENABLE_DISABLE_PETR_MODE, mp);
1484
1485   mp->is_enable = is_enable;
1486
1487   /* send it... */
1488   S (mp);
1489
1490   /* Wait for a reply... */
1491   W (ret);
1492   return ret;
1493 }
1494
1495 static int
1496 api_one_show_petr_mode (vat_main_t * vam)
1497 {
1498   vl_api_one_show_petr_mode_t *mp;
1499   int ret;
1500
1501   /* Construct the API message */
1502   M (ONE_SHOW_PETR_MODE, mp);
1503
1504   /* send it... */
1505   S (mp);
1506
1507   /* Wait for a reply... */
1508   W (ret);
1509   return ret;
1510 }
1511
1512 static int
1513 api_show_one_map_register_state (vat_main_t * vam)
1514 {
1515   vl_api_show_one_map_register_state_t *mp;
1516   int ret;
1517
1518   M (SHOW_ONE_MAP_REGISTER_STATE, mp);
1519
1520   /* send */
1521   S (mp);
1522
1523   /* wait for reply */
1524   W (ret);
1525   return ret;
1526 }
1527
1528 #define api_show_lisp_map_register_state api_show_one_map_register_state
1529
1530 static int
1531 api_show_one_rloc_probe_state (vat_main_t * vam)
1532 {
1533   vl_api_show_one_rloc_probe_state_t *mp;
1534   int ret;
1535
1536   M (SHOW_ONE_RLOC_PROBE_STATE, mp);
1537
1538   /* send */
1539   S (mp);
1540
1541   /* wait for reply */
1542   W (ret);
1543   return ret;
1544 }
1545
1546 #define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state
1547
1548 static int
1549 api_one_add_del_ndp_entry (vat_main_t * vam)
1550 {
1551   vl_api_one_add_del_ndp_entry_t *mp;
1552   unformat_input_t *input = vam->input;
1553   u8 is_add = 1;
1554   u8 mac_set = 0;
1555   u8 bd_set = 0;
1556   u8 ip_set = 0;
1557   u8 mac[6] = { 0, };
1558   u8 ip6[16] = { 0, };
1559   u32 bd = ~0;
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         is_add = 0;
1567       else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
1568         mac_set = 1;
1569       else if (unformat (input, "ip %U", unformat_ip6_address, ip6))
1570         ip_set = 1;
1571       else if (unformat (input, "bd %d", &bd))
1572         bd_set = 1;
1573       else
1574         {
1575           errmsg ("parse error '%U'", format_unformat_error, input);
1576           return -99;
1577         }
1578     }
1579
1580   if (!bd_set || !ip_set || (!mac_set && is_add))
1581     {
1582       errmsg ("Missing BD, IP or MAC!");
1583       return -99;
1584     }
1585
1586   M (ONE_ADD_DEL_NDP_ENTRY, mp);
1587   mp->is_add = is_add;
1588   clib_memcpy (&mp->entry.mac, mac, 6);
1589   mp->bd = clib_host_to_net_u32 (bd);
1590   clib_memcpy (&mp->entry.ip6, ip6, sizeof (mp->entry.ip6));
1591
1592   /* send */
1593   S (mp);
1594
1595   /* wait for reply */
1596   W (ret);
1597   return ret;
1598 }
1599
1600 static int
1601 api_one_add_del_l2_arp_entry (vat_main_t * vam)
1602 {
1603   vl_api_one_add_del_l2_arp_entry_t *mp;
1604   unformat_input_t *input = vam->input;
1605   u8 is_add = 1;
1606   u8 mac_set = 0;
1607   u8 bd_set = 0;
1608   u8 ip_set = 0;
1609   u8 mac[6] = { 0, };
1610   u32 ip4 = 0, bd = ~0;
1611   int ret;
1612
1613   /* Parse args required to build the message */
1614   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1615     {
1616       if (unformat (input, "del"))
1617         is_add = 0;
1618       else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
1619         mac_set = 1;
1620       else if (unformat (input, "ip %U", unformat_ip4_address, &ip4))
1621         ip_set = 1;
1622       else if (unformat (input, "bd %d", &bd))
1623         bd_set = 1;
1624       else
1625         {
1626           errmsg ("parse error '%U'", format_unformat_error, input);
1627           return -99;
1628         }
1629     }
1630
1631   if (!bd_set || !ip_set || (!mac_set && is_add))
1632     {
1633       errmsg ("Missing BD, IP or MAC!");
1634       return -99;
1635     }
1636
1637   M (ONE_ADD_DEL_L2_ARP_ENTRY, mp);
1638   mp->is_add = is_add;
1639   clib_memcpy (&mp->entry.mac, mac, 6);
1640   mp->bd = clib_host_to_net_u32 (bd);
1641   clib_memcpy (mp->entry.ip4, &ip4, sizeof (mp->entry.ip4));
1642
1643   /* send */
1644   S (mp);
1645
1646   /* wait for reply */
1647   W (ret);
1648   return ret;
1649 }
1650
1651 static int
1652 api_one_ndp_bd_get (vat_main_t * vam)
1653 {
1654   vl_api_one_ndp_bd_get_t *mp;
1655   int ret;
1656
1657   M (ONE_NDP_BD_GET, mp);
1658
1659   /* send */
1660   S (mp);
1661
1662   /* wait for reply */
1663   W (ret);
1664   return ret;
1665 }
1666
1667 static int
1668 api_one_ndp_entries_get (vat_main_t * vam)
1669 {
1670   vl_api_one_ndp_entries_get_t *mp;
1671   unformat_input_t *input = vam->input;
1672   u8 bd_set = 0;
1673   u32 bd = ~0;
1674   int ret;
1675
1676   /* Parse args required to build the message */
1677   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1678     {
1679       if (unformat (input, "bd %d", &bd))
1680         bd_set = 1;
1681       else
1682         {
1683           errmsg ("parse error '%U'", format_unformat_error, input);
1684           return -99;
1685         }
1686     }
1687
1688   if (!bd_set)
1689     {
1690       errmsg ("Expected bridge domain!");
1691       return -99;
1692     }
1693
1694   M (ONE_NDP_ENTRIES_GET, mp);
1695   mp->bd = clib_host_to_net_u32 (bd);
1696
1697   /* send */
1698   S (mp);
1699
1700   /* wait for reply */
1701   W (ret);
1702   return ret;
1703 }
1704
1705 static int
1706 api_one_l2_arp_bd_get (vat_main_t * vam)
1707 {
1708   vl_api_one_l2_arp_bd_get_t *mp;
1709   int ret;
1710
1711   M (ONE_L2_ARP_BD_GET, mp);
1712
1713   /* send */
1714   S (mp);
1715
1716   /* wait for reply */
1717   W (ret);
1718   return ret;
1719 }
1720
1721 static int
1722 api_one_l2_arp_entries_get (vat_main_t * vam)
1723 {
1724   vl_api_one_l2_arp_entries_get_t *mp;
1725   unformat_input_t *input = vam->input;
1726   u8 bd_set = 0;
1727   u32 bd = ~0;
1728   int ret;
1729
1730   /* Parse args required to build the message */
1731   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1732     {
1733       if (unformat (input, "bd %d", &bd))
1734         bd_set = 1;
1735       else
1736         {
1737           errmsg ("parse error '%U'", format_unformat_error, input);
1738           return -99;
1739         }
1740     }
1741
1742   if (!bd_set)
1743     {
1744       errmsg ("Expected bridge domain!");
1745       return -99;
1746     }
1747
1748   M (ONE_L2_ARP_ENTRIES_GET, mp);
1749   mp->bd = clib_host_to_net_u32 (bd);
1750
1751   /* send */
1752   S (mp);
1753
1754   /* wait for reply */
1755   W (ret);
1756   return ret;
1757 }
1758
1759 static int
1760 api_one_stats_enable_disable (vat_main_t * vam)
1761 {
1762   vl_api_one_stats_enable_disable_t *mp;
1763   unformat_input_t *input = vam->input;
1764   u8 is_set = 0;
1765   u8 is_enable = 0;
1766   int ret;
1767
1768   /* Parse args required to build the message */
1769   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1770     {
1771       if (unformat (input, "enable"))
1772         {
1773           is_set = 1;
1774           is_enable = 1;
1775         }
1776       else if (unformat (input, "disable"))
1777         {
1778           is_set = 1;
1779         }
1780       else
1781         break;
1782     }
1783
1784   if (!is_set)
1785     {
1786       errmsg ("Value not set");
1787       return -99;
1788     }
1789
1790   M (ONE_STATS_ENABLE_DISABLE, mp);
1791   mp->is_enable = is_enable;
1792
1793   /* send */
1794   S (mp);
1795
1796   /* wait for reply */
1797   W (ret);
1798   return ret;
1799 }
1800
1801 static int
1802 api_show_one_stats_enable_disable (vat_main_t * vam)
1803 {
1804   vl_api_show_one_stats_enable_disable_t *mp;
1805   int ret;
1806
1807   M (SHOW_ONE_STATS_ENABLE_DISABLE, mp);
1808
1809   /* send */
1810   S (mp);
1811
1812   /* wait for reply */
1813   W (ret);
1814   return ret;
1815 }
1816
1817 static int
1818 api_show_one_map_request_mode (vat_main_t * vam)
1819 {
1820   vl_api_show_one_map_request_mode_t *mp;
1821   int ret;
1822
1823   M (SHOW_ONE_MAP_REQUEST_MODE, mp);
1824
1825   /* send */
1826   S (mp);
1827
1828   /* wait for reply */
1829   W (ret);
1830   return ret;
1831 }
1832
1833 #define api_show_lisp_map_request_mode api_show_one_map_request_mode
1834
1835 static int
1836 api_one_map_request_mode (vat_main_t * vam)
1837 {
1838   unformat_input_t *input = vam->input;
1839   vl_api_one_map_request_mode_t *mp;
1840   u8 mode = 0;
1841   int ret;
1842
1843   /* Parse args required to build the message */
1844   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1845     {
1846       if (unformat (input, "dst-only"))
1847         mode = 0;
1848       else if (unformat (input, "src-dst"))
1849         mode = 1;
1850       else
1851         {
1852           errmsg ("parse error '%U'", format_unformat_error, input);
1853           return -99;
1854         }
1855     }
1856
1857   M (ONE_MAP_REQUEST_MODE, mp);
1858
1859   mp->mode = mode;
1860
1861   /* send */
1862   S (mp);
1863
1864   /* wait for reply */
1865   W (ret);
1866   return ret;
1867 }
1868
1869 #define api_lisp_map_request_mode api_one_map_request_mode
1870
1871 /**
1872  * Enable/disable ONE proxy ITR.
1873  *
1874  * @param vam vpp API test context
1875  * @return return code
1876  */
1877 static int
1878 api_one_pitr_set_locator_set (vat_main_t * vam)
1879 {
1880   u8 ls_name_set = 0;
1881   unformat_input_t *input = vam->input;
1882   vl_api_one_pitr_set_locator_set_t *mp;
1883   u8 is_add = 1;
1884   u8 *ls_name = 0;
1885   int ret;
1886
1887   /* Parse args required to build the message */
1888   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1889     {
1890       if (unformat (input, "del"))
1891         is_add = 0;
1892       else if (unformat (input, "locator-set %s", &ls_name))
1893         ls_name_set = 1;
1894       else
1895         {
1896           errmsg ("parse error '%U'", format_unformat_error, input);
1897           return -99;
1898         }
1899     }
1900
1901   if (!ls_name_set)
1902     {
1903       errmsg ("locator-set name not set!");
1904       return -99;
1905     }
1906
1907   M (ONE_PITR_SET_LOCATOR_SET, mp);
1908
1909   mp->is_add = is_add;
1910   clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
1911   vec_free (ls_name);
1912
1913   /* send */
1914   S (mp);
1915
1916   /* wait for reply */
1917   W (ret);
1918   return ret;
1919 }
1920
1921 #define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set
1922
1923 static int
1924 api_one_nsh_set_locator_set (vat_main_t * vam)
1925 {
1926   u8 ls_name_set = 0;
1927   unformat_input_t *input = vam->input;
1928   vl_api_one_nsh_set_locator_set_t *mp;
1929   u8 is_add = 1;
1930   u8 *ls_name = 0;
1931   int ret;
1932
1933   /* Parse args required to build the message */
1934   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1935     {
1936       if (unformat (input, "del"))
1937         is_add = 0;
1938       else if (unformat (input, "ls %s", &ls_name))
1939         ls_name_set = 1;
1940       else
1941         {
1942           errmsg ("parse error '%U'", format_unformat_error, input);
1943           return -99;
1944         }
1945     }
1946
1947   if (!ls_name_set && is_add)
1948     {
1949       errmsg ("locator-set name not set!");
1950       return -99;
1951     }
1952
1953   M (ONE_NSH_SET_LOCATOR_SET, mp);
1954
1955   mp->is_add = is_add;
1956   clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
1957   vec_free (ls_name);
1958
1959   /* send */
1960   S (mp);
1961
1962   /* wait for reply */
1963   W (ret);
1964   return ret;
1965 }
1966
1967 static int
1968 api_show_one_pitr (vat_main_t * vam)
1969 {
1970   vl_api_show_one_pitr_t *mp;
1971   int ret;
1972
1973   if (!vam->json_output)
1974     {
1975       print (vam->ofp, "%=20s", "lisp status:");
1976     }
1977
1978   M (SHOW_ONE_PITR, mp);
1979   /* send it... */
1980   S (mp);
1981
1982   /* Wait for a reply... */
1983   W (ret);
1984   return ret;
1985 }
1986
1987 #define api_show_lisp_pitr api_show_one_pitr
1988
1989 static int
1990 api_one_use_petr (vat_main_t * vam)
1991 {
1992   unformat_input_t *input = vam->input;
1993   vl_api_one_use_petr_t *mp;
1994   u8 is_add = 0;
1995   ip_address_t ip;
1996   int ret;
1997
1998   clib_memset (&ip, 0, sizeof (ip));
1999
2000   /* Parse args required to build the message */
2001   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2002     {
2003       if (unformat (input, "disable"))
2004         is_add = 0;
2005       else
2006         if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
2007         {
2008           is_add = 1;
2009           ip_addr_version (&ip) = AF_IP4;
2010         }
2011       else
2012         if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
2013         {
2014           is_add = 1;
2015           ip_addr_version (&ip) = AF_IP6;
2016         }
2017       else
2018         {
2019           errmsg ("parse error '%U'", format_unformat_error, input);
2020           return -99;
2021         }
2022     }
2023
2024   M (ONE_USE_PETR, mp);
2025
2026   mp->is_add = is_add;
2027   if (is_add)
2028     {
2029       mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1;
2030       if (mp->ip_address.af)
2031         clib_memcpy (mp->ip_address.un.ip6, &ip, 16);
2032       else
2033         clib_memcpy (mp->ip_address.un.ip4, &ip, 4);
2034     }
2035
2036   /* send */
2037   S (mp);
2038
2039   /* wait for reply */
2040   W (ret);
2041   return ret;
2042 }
2043
2044 #define api_lisp_use_petr api_one_use_petr
2045
2046 static int
2047 api_show_one_nsh_mapping (vat_main_t * vam)
2048 {
2049   vl_api_show_one_use_petr_t *mp;
2050   int ret;
2051
2052   if (!vam->json_output)
2053     {
2054       print (vam->ofp, "%=20s", "local ONE NSH mapping:");
2055     }
2056
2057   M (SHOW_ONE_NSH_MAPPING, mp);
2058   /* send it... */
2059   S (mp);
2060
2061   /* Wait for a reply... */
2062   W (ret);
2063   return ret;
2064 }
2065
2066 static int
2067 api_show_one_use_petr (vat_main_t * vam)
2068 {
2069   vl_api_show_one_use_petr_t *mp;
2070   int ret;
2071
2072   if (!vam->json_output)
2073     {
2074       print (vam->ofp, "%=20s", "Proxy-ETR status:");
2075     }
2076
2077   M (SHOW_ONE_USE_PETR, mp);
2078   /* send it... */
2079   S (mp);
2080
2081   /* Wait for a reply... */
2082   W (ret);
2083   return ret;
2084 }
2085
2086 #define api_show_lisp_use_petr api_show_one_use_petr
2087
2088 /**
2089  * Add/delete mapping between vni and vrf
2090  */
2091 static int
2092 api_one_eid_table_add_del_map (vat_main_t * vam)
2093 {
2094   unformat_input_t *input = vam->input;
2095   vl_api_one_eid_table_add_del_map_t *mp;
2096   u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
2097   u32 vni, vrf, bd_index;
2098   int ret;
2099
2100   /* Parse args required to build the message */
2101   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2102     {
2103       if (unformat (input, "del"))
2104         is_add = 0;
2105       else if (unformat (input, "vrf %d", &vrf))
2106         vrf_set = 1;
2107       else if (unformat (input, "bd_index %d", &bd_index))
2108         bd_index_set = 1;
2109       else if (unformat (input, "vni %d", &vni))
2110         vni_set = 1;
2111       else
2112         break;
2113     }
2114
2115   if (!vni_set || (!vrf_set && !bd_index_set))
2116     {
2117       errmsg ("missing arguments!");
2118       return -99;
2119     }
2120
2121   if (vrf_set && bd_index_set)
2122     {
2123       errmsg ("error: both vrf and bd entered!");
2124       return -99;
2125     }
2126
2127   M (ONE_EID_TABLE_ADD_DEL_MAP, mp);
2128
2129   mp->is_add = is_add;
2130   mp->vni = htonl (vni);
2131   mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
2132   mp->is_l2 = bd_index_set;
2133
2134   /* send */
2135   S (mp);
2136
2137   /* wait for reply */
2138   W (ret);
2139   return ret;
2140 }
2141
2142 #define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map
2143
2144 uword
2145 unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
2146 {
2147   u32 *action = va_arg (*args, u32 *);
2148   u8 *s = 0;
2149
2150   if (unformat (input, "%s", &s))
2151     {
2152       if (!strcmp ((char *) s, "no-action"))
2153         action[0] = 0;
2154       else if (!strcmp ((char *) s, "natively-forward"))
2155         action[0] = 1;
2156       else if (!strcmp ((char *) s, "send-map-request"))
2157         action[0] = 2;
2158       else if (!strcmp ((char *) s, "drop"))
2159         action[0] = 3;
2160       else
2161         {
2162           clib_warning ("invalid action: '%s'", s);
2163           action[0] = 3;
2164         }
2165     }
2166   else
2167     return 0;
2168
2169   vec_free (s);
2170   return 1;
2171 }
2172
2173 /**
2174  * Add/del remote mapping to/from ONE control plane
2175  *
2176  * @param vam vpp API test context
2177  * @return return code
2178  */
2179 static int
2180 api_one_add_del_remote_mapping (vat_main_t * vam)
2181 {
2182   unformat_input_t *input = vam->input;
2183   vl_api_one_add_del_remote_mapping_t *mp;
2184   u32 vni = 0;
2185   lisp_eid_vat_t _eid, *eid = &_eid;
2186   lisp_eid_vat_t _seid, *seid = &_seid;
2187   u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
2188   u32 action = ~0, p, w, data_len;
2189   ip4_address_t rloc4;
2190   ip6_address_t rloc6;
2191   vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
2192   int ret;
2193
2194   clib_memset (&rloc, 0, sizeof (rloc));
2195
2196   /* Parse args required to build the message */
2197   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2198     {
2199       if (unformat (input, "del-all"))
2200         {
2201           del_all = 1;
2202         }
2203       else if (unformat (input, "del"))
2204         {
2205           is_add = 0;
2206         }
2207       else if (unformat (input, "add"))
2208         {
2209           is_add = 1;
2210         }
2211       else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
2212         {
2213           eid_set = 1;
2214         }
2215       else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
2216         {
2217           seid_set = 1;
2218         }
2219       else if (unformat (input, "vni %d", &vni))
2220         {
2221           ;
2222         }
2223       else if (unformat (input, "p %d w %d", &p, &w))
2224         {
2225           if (!curr_rloc)
2226             {
2227               errmsg ("No RLOC configured for setting priority/weight!");
2228               return -99;
2229             }
2230           curr_rloc->priority = p;
2231           curr_rloc->weight = w;
2232         }
2233       else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
2234         {
2235           rloc.ip_address.af = 0;
2236           clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6));
2237           vec_add1 (rlocs, rloc);
2238           curr_rloc = &rlocs[vec_len (rlocs) - 1];
2239         }
2240       else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
2241         {
2242           rloc.ip_address.af = 1;
2243           clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4));
2244           vec_add1 (rlocs, rloc);
2245           curr_rloc = &rlocs[vec_len (rlocs) - 1];
2246         }
2247       else if (unformat (input, "action %U",
2248                          unformat_negative_mapping_action, &action))
2249         {
2250           ;
2251         }
2252       else
2253         {
2254           clib_warning ("parse error '%U'", format_unformat_error, input);
2255           return -99;
2256         }
2257     }
2258
2259   if (0 == eid_set)
2260     {
2261       errmsg ("missing params!");
2262       return -99;
2263     }
2264
2265   if (is_add && (~0 == action) && 0 == vec_len (rlocs))
2266     {
2267       errmsg ("no action set for negative map-reply!");
2268       return -99;
2269     }
2270
2271   data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
2272
2273   M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len);
2274   mp->is_add = is_add;
2275   mp->vni = htonl (vni);
2276   mp->action = (u8) action;
2277   mp->is_src_dst = seid_set;
2278   mp->del_all = del_all;
2279   lisp_eid_put_vat (&mp->deid, eid);
2280   lisp_eid_put_vat (&mp->seid, seid);
2281
2282   mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
2283   clib_memcpy (mp->rlocs, rlocs, data_len);
2284   vec_free (rlocs);
2285
2286   /* send it... */
2287   S (mp);
2288
2289   /* Wait for a reply... */
2290   W (ret);
2291   return ret;
2292 }
2293
2294 #define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping
2295
2296 /**
2297  * Add/del ONE adjacency. Saves mapping in ONE control plane and updates
2298  * forwarding entries in data-plane accordingly.
2299  *
2300  * @param vam vpp API test context
2301  * @return return code
2302  */
2303 static int
2304 api_one_add_del_adjacency (vat_main_t * vam)
2305 {
2306   unformat_input_t *input = vam->input;
2307   vl_api_one_add_del_adjacency_t *mp;
2308   u32 vni = 0;
2309   u8 is_add = 1;
2310   int ret;
2311   lisp_eid_vat_t leid, reid;
2312
2313   leid.type = reid.type = (u8) ~ 0;
2314
2315   /* Parse args required to build the message */
2316   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2317     {
2318       if (unformat (input, "del"))
2319         {
2320           is_add = 0;
2321         }
2322       else if (unformat (input, "add"))
2323         {
2324           is_add = 1;
2325         }
2326       else if (unformat (input, "reid %U/%d", unformat_ip46_address,
2327                          &reid.addr.ip, &reid.len))
2328         {
2329           reid.type = 0;        /* ipv4 */
2330         }
2331       else if (unformat (input, "reid %U", unformat_ethernet_address,
2332                          &reid.addr.mac))
2333         {
2334           reid.type = 1;        /* mac */
2335         }
2336       else if (unformat (input, "leid %U/%d", unformat_ip46_address,
2337                          &leid.addr.ip, &leid.len))
2338         {
2339           leid.type = 0;        /* ipv4 */
2340         }
2341       else if (unformat (input, "leid %U", unformat_ethernet_address,
2342                          &leid.addr.mac))
2343         {
2344           leid.type = 1;        /* mac */
2345         }
2346       else if (unformat (input, "vni %d", &vni))
2347         {
2348           ;
2349         }
2350       else
2351         {
2352           errmsg ("parse error '%U'", format_unformat_error, input);
2353           return -99;
2354         }
2355     }
2356
2357   if ((u8) ~ 0 == reid.type)
2358     {
2359       errmsg ("missing params!");
2360       return -99;
2361     }
2362
2363   if (leid.type != reid.type)
2364     {
2365       errmsg ("remote and local EIDs are of different types!");
2366       return -99;
2367     }
2368
2369   M (ONE_ADD_DEL_ADJACENCY, mp);
2370   mp->is_add = is_add;
2371   mp->vni = htonl (vni);
2372   lisp_eid_put_vat (&mp->leid, &leid);
2373   lisp_eid_put_vat (&mp->reid, &reid);
2374
2375   /* send it... */
2376   S (mp);
2377
2378   /* Wait for a reply... */
2379   W (ret);
2380   return ret;
2381 }
2382
2383 #define api_lisp_add_del_adjacency api_one_add_del_adjacency
2384
2385
2386 static int
2387 api_one_map_register_fallback_threshold (vat_main_t * vam)
2388 {
2389   unformat_input_t *input = vam->input;
2390   vl_api_one_map_register_fallback_threshold_t *mp;
2391   u32 value = 0;
2392   u8 is_set = 0;
2393   int ret;
2394
2395   /* Parse args required to build the message */
2396   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2397     {
2398       if (unformat (input, "%u", &value))
2399         is_set = 1;
2400       else
2401         {
2402           clib_warning ("parse error '%U'", format_unformat_error, input);
2403           return -99;
2404         }
2405     }
2406
2407   if (!is_set)
2408     {
2409       errmsg ("fallback threshold value is missing!");
2410       return -99;
2411     }
2412
2413   M (ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
2414   mp->value = clib_host_to_net_u32 (value);
2415
2416   /* send it... */
2417   S (mp);
2418
2419   /* Wait for a reply... */
2420   W (ret);
2421   return ret;
2422 }
2423
2424 static int
2425 api_show_one_map_register_fallback_threshold (vat_main_t * vam)
2426 {
2427   vl_api_show_one_map_register_fallback_threshold_t *mp;
2428   int ret;
2429
2430   M (SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
2431
2432   /* send it... */
2433   S (mp);
2434
2435   /* Wait for a reply... */
2436   W (ret);
2437   return ret;
2438 }
2439
2440 uword
2441 unformat_lisp_transport_protocol (unformat_input_t * input, va_list * args)
2442 {
2443   u32 *proto = va_arg (*args, u32 *);
2444
2445   if (unformat (input, "udp"))
2446     *proto = 1;
2447   else if (unformat (input, "api"))
2448     *proto = 2;
2449   else
2450     return 0;
2451
2452   return 1;
2453 }
2454
2455 static int
2456 api_one_set_transport_protocol (vat_main_t * vam)
2457 {
2458   unformat_input_t *input = vam->input;
2459   vl_api_one_set_transport_protocol_t *mp;
2460   u8 is_set = 0;
2461   u32 protocol = 0;
2462   int ret;
2463
2464   /* Parse args required to build the message */
2465   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2466     {
2467       if (unformat (input, "%U", unformat_lisp_transport_protocol, &protocol))
2468         is_set = 1;
2469       else
2470         {
2471           clib_warning ("parse error '%U'", format_unformat_error, input);
2472           return -99;
2473         }
2474     }
2475
2476   if (!is_set)
2477     {
2478       errmsg ("Transport protocol missing!");
2479       return -99;
2480     }
2481
2482   M (ONE_SET_TRANSPORT_PROTOCOL, mp);
2483   mp->protocol = (u8) protocol;
2484
2485   /* send it... */
2486   S (mp);
2487
2488   /* Wait for a reply... */
2489   W (ret);
2490   return ret;
2491 }
2492
2493 static int
2494 api_one_get_transport_protocol (vat_main_t * vam)
2495 {
2496   vl_api_one_get_transport_protocol_t *mp;
2497   int ret;
2498
2499   M (ONE_GET_TRANSPORT_PROTOCOL, mp);
2500
2501   /* send it... */
2502   S (mp);
2503
2504   /* Wait for a reply... */
2505   W (ret);
2506   return ret;
2507 }
2508
2509 static int
2510 api_one_map_register_set_ttl (vat_main_t * vam)
2511 {
2512   unformat_input_t *input = vam->input;
2513   vl_api_one_map_register_set_ttl_t *mp;
2514   u32 ttl = 0;
2515   u8 is_set = 0;
2516   int ret;
2517
2518   /* Parse args required to build the message */
2519   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2520     {
2521       if (unformat (input, "%u", &ttl))
2522         is_set = 1;
2523       else
2524         {
2525           clib_warning ("parse error '%U'", format_unformat_error, input);
2526           return -99;
2527         }
2528     }
2529
2530   if (!is_set)
2531     {
2532       errmsg ("TTL value missing!");
2533       return -99;
2534     }
2535
2536   M (ONE_MAP_REGISTER_SET_TTL, mp);
2537   mp->ttl = clib_host_to_net_u32 (ttl);
2538
2539   /* send it... */
2540   S (mp);
2541
2542   /* Wait for a reply... */
2543   W (ret);
2544   return ret;
2545 }
2546
2547 static int
2548 api_show_one_map_register_ttl (vat_main_t * vam)
2549 {
2550   vl_api_show_one_map_register_ttl_t *mp;
2551   int ret;
2552
2553   M (SHOW_ONE_MAP_REGISTER_TTL, mp);
2554
2555   /* send it... */
2556   S (mp);
2557
2558   /* Wait for a reply... */
2559   W (ret);
2560   return ret;
2561 }
2562
2563 /**
2564  * Add/del map request itr rlocs from ONE control plane and updates
2565  *
2566  * @param vam vpp API test context
2567  * @return return code
2568  */
2569 static int
2570 api_one_add_del_map_request_itr_rlocs (vat_main_t * vam)
2571 {
2572   unformat_input_t *input = vam->input;
2573   vl_api_one_add_del_map_request_itr_rlocs_t *mp;
2574   u8 *locator_set_name = 0;
2575   u8 locator_set_name_set = 0;
2576   u8 is_add = 1;
2577   int ret;
2578
2579   /* Parse args required to build the message */
2580   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2581     {
2582       if (unformat (input, "del"))
2583         {
2584           is_add = 0;
2585         }
2586       else if (unformat (input, "%_%v%_", &locator_set_name))
2587         {
2588           locator_set_name_set = 1;
2589         }
2590       else
2591         {
2592           clib_warning ("parse error '%U'", format_unformat_error, input);
2593           return -99;
2594         }
2595     }
2596
2597   if (is_add && !locator_set_name_set)
2598     {
2599       errmsg ("itr-rloc is not set!");
2600       return -99;
2601     }
2602
2603   if (is_add && vec_len (locator_set_name) > 64)
2604     {
2605       errmsg ("itr-rloc locator-set name too long");
2606       vec_free (locator_set_name);
2607       return -99;
2608     }
2609
2610   M (ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
2611   mp->is_add = is_add;
2612   if (is_add)
2613     {
2614       clib_memcpy (mp->locator_set_name, locator_set_name,
2615                    vec_len (locator_set_name));
2616     }
2617   else
2618     {
2619       clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
2620     }
2621   vec_free (locator_set_name);
2622
2623   /* send it... */
2624   S (mp);
2625
2626   /* Wait for a reply... */
2627   W (ret);
2628   return ret;
2629 }
2630
2631 #define api_lisp_add_del_map_request_itr_rlocs api_one_add_del_map_request_itr_rlocs
2632
2633 static int
2634 api_one_locator_dump (vat_main_t * vam)
2635 {
2636   unformat_input_t *input = vam->input;
2637   vl_api_one_locator_dump_t *mp;
2638   vl_api_control_ping_t *mp_ping;
2639   u8 is_index_set = 0, is_name_set = 0;
2640   u8 *ls_name = 0;
2641   u32 ls_index = ~0;
2642   int ret;
2643
2644   /* Parse args required to build the message */
2645   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2646     {
2647       if (unformat (input, "ls_name %_%v%_", &ls_name))
2648         {
2649           is_name_set = 1;
2650         }
2651       else if (unformat (input, "ls_index %d", &ls_index))
2652         {
2653           is_index_set = 1;
2654         }
2655       else
2656         {
2657           errmsg ("parse error '%U'", format_unformat_error, input);
2658           return -99;
2659         }
2660     }
2661
2662   if (!is_index_set && !is_name_set)
2663     {
2664       errmsg ("error: expected one of index or name!");
2665       return -99;
2666     }
2667
2668   if (is_index_set && is_name_set)
2669     {
2670       errmsg ("error: only one param expected!");
2671       return -99;
2672     }
2673
2674   if (vec_len (ls_name) > 62)
2675     {
2676       errmsg ("error: locator set name too long!");
2677       return -99;
2678     }
2679
2680   if (!vam->json_output)
2681     {
2682       print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
2683     }
2684
2685   M (ONE_LOCATOR_DUMP, mp);
2686   mp->is_index_set = is_index_set;
2687
2688   if (is_index_set)
2689     mp->ls_index = clib_host_to_net_u32 (ls_index);
2690   else
2691     {
2692       vec_add1 (ls_name, 0);
2693       strncpy ((char *) mp->ls_name, (char *) ls_name,
2694                sizeof (mp->ls_name) - 1);
2695     }
2696
2697   /* send it... */
2698   S (mp);
2699
2700   /* Use a control ping for synchronization */
2701   LISP_PING (&one_test_main, mp_ping);
2702   S (mp_ping);
2703
2704   /* Wait for a reply... */
2705   W (ret);
2706   return ret;
2707 }
2708
2709 #define api_lisp_locator_dump api_one_locator_dump
2710
2711 static int
2712 api_one_locator_set_dump (vat_main_t * vam)
2713 {
2714   vl_api_one_locator_set_dump_t *mp;
2715   vl_api_control_ping_t *mp_ping;
2716   unformat_input_t *input = vam->input;
2717   u8 filter = 0;
2718   int ret;
2719
2720   /* Parse args required to build the message */
2721   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2722     {
2723       if (unformat (input, "local"))
2724         {
2725           filter = 1;
2726         }
2727       else if (unformat (input, "remote"))
2728         {
2729           filter = 2;
2730         }
2731       else
2732         {
2733           errmsg ("parse error '%U'", format_unformat_error, input);
2734           return -99;
2735         }
2736     }
2737
2738   if (!vam->json_output)
2739     {
2740       print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
2741     }
2742
2743   M (ONE_LOCATOR_SET_DUMP, mp);
2744
2745   mp->filter = filter;
2746
2747   /* send it... */
2748   S (mp);
2749
2750   /* Use a control ping for synchronization */
2751   LISP_PING (&one_test_main, mp_ping);
2752   S (mp_ping);
2753
2754   /* Wait for a reply... */
2755   W (ret);
2756   return ret;
2757 }
2758
2759 #define api_lisp_locator_set_dump api_one_locator_set_dump
2760
2761 static int
2762 api_one_eid_table_map_dump (vat_main_t * vam)
2763 {
2764   u8 is_l2 = 0;
2765   u8 mode_set = 0;
2766   unformat_input_t *input = vam->input;
2767   vl_api_one_eid_table_map_dump_t *mp;
2768   vl_api_control_ping_t *mp_ping;
2769   int ret;
2770
2771   /* Parse args required to build the message */
2772   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2773     {
2774       if (unformat (input, "l2"))
2775         {
2776           is_l2 = 1;
2777           mode_set = 1;
2778         }
2779       else if (unformat (input, "l3"))
2780         {
2781           is_l2 = 0;
2782           mode_set = 1;
2783         }
2784       else
2785         {
2786           errmsg ("parse error '%U'", format_unformat_error, input);
2787           return -99;
2788         }
2789     }
2790
2791   if (!mode_set)
2792     {
2793       errmsg ("expected one of 'l2' or 'l3' parameter!");
2794       return -99;
2795     }
2796
2797   if (!vam->json_output)
2798     {
2799       print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
2800     }
2801
2802   M (ONE_EID_TABLE_MAP_DUMP, mp);
2803   mp->is_l2 = is_l2;
2804
2805   /* send it... */
2806   S (mp);
2807
2808   /* Use a control ping for synchronization */
2809   LISP_PING (&one_test_main, mp_ping);
2810   S (mp_ping);
2811
2812   /* Wait for a reply... */
2813   W (ret);
2814   return ret;
2815 }
2816
2817 #define api_lisp_eid_table_map_dump api_one_eid_table_map_dump
2818
2819 static int
2820 api_one_eid_table_vni_dump (vat_main_t * vam)
2821 {
2822   vl_api_one_eid_table_vni_dump_t *mp;
2823   vl_api_control_ping_t *mp_ping;
2824   int ret;
2825
2826   if (!vam->json_output)
2827     {
2828       print (vam->ofp, "VNI");
2829     }
2830
2831   M (ONE_EID_TABLE_VNI_DUMP, mp);
2832
2833   /* send it... */
2834   S (mp);
2835
2836   /* Use a control ping for synchronization */
2837   LISP_PING (&one_test_main, mp_ping);
2838   S (mp_ping);
2839
2840   /* Wait for a reply... */
2841   W (ret);
2842   return ret;
2843 }
2844
2845 #define api_lisp_eid_table_vni_dump api_one_eid_table_vni_dump
2846
2847 static int
2848 api_one_eid_table_dump (vat_main_t * vam)
2849 {
2850   unformat_input_t *i = vam->input;
2851   vl_api_one_eid_table_dump_t *mp;
2852   vl_api_control_ping_t *mp_ping;
2853   u8 filter = 0;
2854   int ret;
2855   u32 vni, t = 0;
2856   lisp_eid_vat_t eid;
2857   u8 eid_set = 0;
2858
2859   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2860     {
2861       if (unformat
2862           (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len))
2863         {
2864           eid_set = 1;
2865           eid.type = 0;
2866         }
2867       else
2868         if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac))
2869         {
2870           eid_set = 1;
2871           eid.type = 1;
2872         }
2873       else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh))
2874         {
2875           eid_set = 1;
2876           eid.type = 2;
2877         }
2878       else if (unformat (i, "vni %d", &t))
2879         {
2880           vni = t;
2881         }
2882       else if (unformat (i, "local"))
2883         {
2884           filter = 1;
2885         }
2886       else if (unformat (i, "remote"))
2887         {
2888           filter = 2;
2889         }
2890       else
2891         {
2892           errmsg ("parse error '%U'", format_unformat_error, i);
2893           return -99;
2894         }
2895     }
2896
2897   if (!vam->json_output)
2898     {
2899       print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
2900              "type", "ls_index", "ttl", "authoritative", "key_id", "key");
2901     }
2902
2903   M (ONE_EID_TABLE_DUMP, mp);
2904
2905   mp->filter = filter;
2906   if (eid_set)
2907     {
2908       mp->eid_set = 1;
2909       mp->vni = htonl (vni);
2910       lisp_eid_put_vat (&mp->eid, &eid);
2911     }
2912
2913   /* send it... */
2914   S (mp);
2915
2916   /* Use a control ping for synchronization */
2917   LISP_PING (&one_test_main, mp_ping);
2918   S (mp_ping);
2919
2920   /* Wait for a reply... */
2921   W (ret);
2922   return ret;
2923 }
2924
2925 static int
2926 api_one_adjacencies_get (vat_main_t * vam)
2927 {
2928   unformat_input_t *i = vam->input;
2929   vl_api_one_adjacencies_get_t *mp;
2930   u8 vni_set = 0;
2931   u32 vni = ~0;
2932   int ret;
2933
2934   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2935     {
2936       if (unformat (i, "vni %d", &vni))
2937         {
2938           vni_set = 1;
2939         }
2940       else
2941         {
2942           errmsg ("parse error '%U'", format_unformat_error, i);
2943           return -99;
2944         }
2945     }
2946
2947   if (!vni_set)
2948     {
2949       errmsg ("vni not set!");
2950       return -99;
2951     }
2952
2953   if (!vam->json_output)
2954     {
2955       print (vam->ofp, "%s %40s", "leid", "reid");
2956     }
2957
2958   M (ONE_ADJACENCIES_GET, mp);
2959   mp->vni = clib_host_to_net_u32 (vni);
2960
2961   /* send it... */
2962   S (mp);
2963
2964   /* Wait for a reply... */
2965   W (ret);
2966   return ret;
2967 }
2968
2969 static int
2970 api_one_map_server_dump (vat_main_t * vam)
2971 {
2972   vl_api_one_map_server_dump_t *mp;
2973   vl_api_control_ping_t *mp_ping;
2974   int ret;
2975
2976   if (!vam->json_output)
2977     {
2978       print (vam->ofp, "%=20s", "Map server");
2979     }
2980
2981   M (ONE_MAP_SERVER_DUMP, mp);
2982   /* send it... */
2983   S (mp);
2984
2985   /* Use a control ping for synchronization */
2986   LISP_PING (&one_test_main, mp_ping);
2987   S (mp_ping);
2988
2989   /* Wait for a reply... */
2990   W (ret);
2991   return ret;
2992 }
2993
2994 #define api_lisp_map_server_dump api_one_map_server_dump
2995
2996 static int
2997 api_one_map_resolver_dump (vat_main_t * vam)
2998 {
2999   vl_api_one_map_resolver_dump_t *mp;
3000   vl_api_control_ping_t *mp_ping;
3001   int ret;
3002
3003   if (!vam->json_output)
3004     {
3005       print (vam->ofp, "%=20s", "Map resolver");
3006     }
3007
3008   M (ONE_MAP_RESOLVER_DUMP, mp);
3009   /* send it... */
3010   S (mp);
3011
3012   /* Use a control ping for synchronization */
3013   LISP_PING (&one_test_main, mp_ping);
3014   S (mp_ping);
3015
3016   /* Wait for a reply... */
3017   W (ret);
3018   return ret;
3019 }
3020
3021 #define api_lisp_map_resolver_dump api_one_map_resolver_dump
3022
3023 static int
3024 api_one_stats_flush (vat_main_t * vam)
3025 {
3026   vl_api_one_stats_flush_t *mp;
3027   int ret = 0;
3028
3029   M (ONE_STATS_FLUSH, mp);
3030   S (mp);
3031   W (ret);
3032   return ret;
3033 }
3034
3035 static int
3036 api_one_stats_dump (vat_main_t * vam)
3037 {
3038   vl_api_one_stats_dump_t *mp;
3039   vl_api_control_ping_t *mp_ping;
3040   int ret;
3041
3042   M (ONE_STATS_DUMP, mp);
3043   /* send it... */
3044   S (mp);
3045
3046   /* Use a control ping for synchronization */
3047   LISP_PING (&one_test_main, mp_ping);
3048   S (mp_ping);
3049
3050   /* Wait for a reply... */
3051   W (ret);
3052   return ret;
3053 }
3054
3055 static int
3056 api_show_one_status (vat_main_t * vam)
3057 {
3058   vl_api_show_one_status_t *mp;
3059   int ret;
3060
3061   if (!vam->json_output)
3062     {
3063       print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set");
3064     }
3065
3066   M (SHOW_ONE_STATUS, mp);
3067   /* send it... */
3068   S (mp);
3069   /* Wait for a reply... */
3070   W (ret);
3071   return ret;
3072 }
3073
3074 static int
3075 api_one_get_map_request_itr_rlocs (vat_main_t * vam)
3076 {
3077   vl_api_one_get_map_request_itr_rlocs_t *mp;
3078   int ret;
3079
3080   if (!vam->json_output)
3081     {
3082       print (vam->ofp, "%=20s", "itr-rlocs:");
3083     }
3084
3085   M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp);
3086   /* send it... */
3087   S (mp);
3088   /* Wait for a reply... */
3089   W (ret);
3090   return ret;
3091 }
3092
3093 #define vat_plugin_register vat_plugin_register_one
3094 #include <lisp/lisp-cp/one.api_test.c>
3095
3096 /*
3097  * fd.io coding-style-patch-verification: ON
3098  *
3099  * Local Variables:
3100  * eval: (c-set-style "gnu")
3101  * End:
3102  */