LISP: add debug cli for neighbor discovery
[vpp.git] / src / vnet / lisp-cp / one_cli.c
1 /*
2  * Copyright (c) 2017 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 <vnet/lisp-cp/control.h>
17 #include <vnet/lisp-gpe/lisp_gpe.h>
18
19 static clib_error_t *
20 lisp_show_adjacencies_command_fn (vlib_main_t * vm,
21                                   unformat_input_t * input,
22                                   vlib_cli_command_t * cmd)
23 {
24   lisp_adjacency_t *adjs, *adj;
25   vlib_cli_output (vm, "%s %40s\n", "leid", "reid");
26   unformat_input_t _line_input, *line_input = &_line_input;
27   u32 vni = ~0;
28
29   /* Get a line of input. */
30   if (!unformat_user (input, unformat_line_input, line_input))
31     return 0;
32
33   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
34     {
35       if (unformat (line_input, "vni %d", &vni))
36         ;
37       else
38         {
39           vlib_cli_output (vm, "parse error: '%U'",
40                            format_unformat_error, line_input);
41           unformat_free (line_input);
42           return 0;
43         }
44     }
45   unformat_free (line_input);
46
47   if (~0 == vni)
48     {
49       vlib_cli_output (vm, "error: no vni specified!");
50       return 0;
51     }
52
53   adjs = vnet_lisp_adjacencies_get_by_vni (vni);
54
55   vec_foreach (adj, adjs)
56   {
57     vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid,
58                      format_gid_address, &adj->reid);
59   }
60   vec_free (adjs);
61
62   return 0;
63 }
64
65 /* *INDENT-OFF* */
66 VLIB_CLI_COMMAND (one_show_adjacencies_command) = {
67     .path = "show one adjacencies",
68     .short_help = "show one adjacencies",
69     .function = lisp_show_adjacencies_command_fn,
70 };
71 /* *INDENT-ON* */
72
73 static clib_error_t *
74 lisp_add_del_map_server_command_fn (vlib_main_t * vm,
75                                     unformat_input_t * input,
76                                     vlib_cli_command_t * cmd)
77 {
78   int rv = 0;
79   u8 is_add = 1, ip_set = 0;
80   ip_address_t ip;
81   unformat_input_t _line_input, *line_input = &_line_input;
82
83   /* Get a line of input. */
84   if (!unformat_user (input, unformat_line_input, line_input))
85     return 0;
86
87   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
88     {
89       if (unformat (line_input, "add"))
90         is_add = 1;
91       else if (unformat (line_input, "del"))
92         is_add = 0;
93       else if (unformat (line_input, "%U", unformat_ip_address, &ip))
94         ip_set = 1;
95       else
96         {
97           vlib_cli_output (vm, "parse error: '%U'",
98                            format_unformat_error, line_input);
99           unformat_free (line_input);
100           return 0;
101         }
102     }
103   unformat_free (line_input);
104
105   if (!ip_set)
106     {
107       vlib_cli_output (vm, "map-server ip address not set!");
108       return 0;
109     }
110
111   rv = vnet_lisp_add_del_map_server (&ip, is_add);
112   if (!rv)
113     vlib_cli_output (vm, "failed to %s map-server!",
114                      is_add ? "add" : "delete");
115
116   return 0;
117 }
118
119 /* *INDENT-OFF* */
120 VLIB_CLI_COMMAND (one_add_del_map_server_command) = {
121     .path = "one map-server",
122     .short_help = "one map-server add|del <ip>",
123     .function = lisp_add_del_map_server_command_fn,
124 };
125 /* *INDENT-ON* */
126
127
128 static clib_error_t *
129 lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
130                                    vlib_cli_command_t * cmd)
131 {
132   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
133   unformat_input_t _line_input, *line_input = &_line_input;
134   u8 is_add = 1;
135   gid_address_t eid;
136   gid_address_t *eids = 0;
137   clib_error_t *error = 0;
138   u8 *locator_set_name = 0;
139   u32 locator_set_index = 0, map_index = 0;
140   uword *p;
141   vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
142   int rv = 0;
143   u32 vni = 0;
144   u8 *key = 0;
145   u32 key_id = 0;
146
147   memset (&eid, 0, sizeof (eid));
148   memset (a, 0, sizeof (*a));
149
150   /* Get a line of input. */
151   if (!unformat_user (input, unformat_line_input, line_input))
152     return 0;
153
154   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
155     {
156       if (unformat (line_input, "add"))
157         is_add = 1;
158       else if (unformat (line_input, "del"))
159         is_add = 0;
160       else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
161         ;
162       else if (unformat (line_input, "vni %d", &vni))
163         gid_address_vni (&eid) = vni;
164       else if (unformat (line_input, "secret-key %_%v%_", &key))
165         ;
166       else if (unformat (line_input, "key-id %U", unformat_hmac_key_id,
167                          &key_id))
168         ;
169       else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
170         {
171           p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
172           if (!p)
173             {
174               error = clib_error_return (0, "locator-set %s doesn't exist",
175                                          locator_set_name);
176               goto done;
177             }
178           locator_set_index = p[0];
179         }
180       else
181         {
182           error = unformat_parse_error (line_input);
183           goto done;
184         }
185     }
186   /* XXX treat batch configuration */
187
188   if (GID_ADDR_SRC_DST == gid_address_type (&eid))
189     {
190       error =
191         clib_error_return (0, "src/dst is not supported for local EIDs!");
192       goto done;
193     }
194
195   if (key && (0 == key_id))
196     {
197       vlib_cli_output (vm, "invalid key_id!");
198       goto done;
199     }
200
201   gid_address_copy (&a->eid, &eid);
202   a->is_add = is_add;
203   a->locator_set_index = locator_set_index;
204   a->local = 1;
205   a->key = key;
206   a->key_id = key_id;
207
208   rv = vnet_lisp_add_del_local_mapping (a, &map_index);
209   if (0 != rv)
210     {
211       error = clib_error_return (0, "failed to %s local mapping!",
212                                  is_add ? "add" : "delete");
213     }
214 done:
215   vec_free (eids);
216   if (locator_set_name)
217     vec_free (locator_set_name);
218   gid_address_free (&a->eid);
219   vec_free (a->key);
220   unformat_free (line_input);
221   return error;
222 }
223
224 /* *INDENT-OFF* */
225 VLIB_CLI_COMMAND (one_add_del_local_eid_command) = {
226     .path = "one eid-table",
227     .short_help = "one eid-table add/del [vni <vni>] eid <eid> "
228       "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]",
229     .function = lisp_add_del_local_eid_command_fn,
230 };
231 /* *INDENT-ON* */
232
233 static clib_error_t *
234 lisp_eid_table_map_command_fn (vlib_main_t * vm,
235                                unformat_input_t * input,
236                                vlib_cli_command_t * cmd)
237 {
238   u8 is_add = 1, is_l2 = 0;
239   u32 vni = 0, dp_id = 0;
240   unformat_input_t _line_input, *line_input = &_line_input;
241   clib_error_t *error = NULL;
242
243   /* Get a line of input. */
244   if (!unformat_user (input, unformat_line_input, line_input))
245     return 0;
246
247   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
248     {
249       if (unformat (line_input, "del"))
250         is_add = 0;
251       else if (unformat (line_input, "vni %d", &vni))
252         ;
253       else if (unformat (line_input, "vrf %d", &dp_id))
254         ;
255       else if (unformat (line_input, "bd %d", &dp_id))
256         is_l2 = 1;
257       else
258         {
259           error = unformat_parse_error (line_input);
260           goto done;
261         }
262     }
263   vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
264
265 done:
266   unformat_free (line_input);
267
268   return error;
269 }
270
271 /* *INDENT-OFF* */
272 VLIB_CLI_COMMAND (one_eid_table_map_command) = {
273     .path = "one eid-table map",
274     .short_help = "one eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
275     .function = lisp_eid_table_map_command_fn,
276 };
277 /* *INDENT-ON* */
278
279 static clib_error_t *
280 lisp_add_del_ndp_entry_command_fn (vlib_main_t * vm,
281                                    unformat_input_t * input,
282                                    vlib_cli_command_t * cmd)
283 {
284   unformat_input_t _line_input, *line_input = &_line_input;
285   clib_error_t *error = NULL;
286   int rc = 0;
287   u8 hw_addr[6], bd = 0;
288   ip6_address_t ip6;
289   u32 hw_addr_set = 0, ip_set = 0, is_add = 1;
290   gid_address_t _g, *g = &_g;
291
292   memset (&ip6, 0, sizeof (ip6));
293   memset (hw_addr, 0, sizeof (hw_addr));
294   memset (g, 0, sizeof (*g));
295
296   if (!unformat_user (input, unformat_line_input, line_input))
297     return 0;
298
299   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
300     {
301       if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr))
302         hw_addr_set = 1;
303       else if (unformat (line_input, "ip %U", unformat_ip6_address, &ip6))
304         ip_set = 1;
305       else if (unformat (line_input, "del"))
306         is_add = 0;
307       else if (unformat (line_input, "bd %d", &bd))
308         ;
309       else
310         {
311           error = clib_error_return (0, "parse error");
312           goto done;
313         }
314     }
315
316   if (!ip_set || (!hw_addr_set && is_add))
317     {
318       vlib_cli_output (vm, "expected IP and MAC addresses!");
319       return 0;
320     }
321
322   /* build GID address */
323   ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, IP6);
324   gid_address_ndp_bd (g) = bd;
325   gid_address_type (g) = GID_ADDR_NDP;
326   rc = vnet_lisp_add_del_l2_arp_ndp_entry (g, hw_addr, is_add);
327   if (rc)
328     clib_warning ("Failed to %s ndp entry!", is_add ? "add" : "delete");
329
330 done:
331   unformat_free (line_input);
332   return error;
333 }
334
335 /* *INDENT-OFF* */
336 VLIB_CLI_COMMAND (one_add_del_ndp_entry_command) = {
337     .path = "one ndp",
338     .short_help = "one ndp [del] bd <bd> mac <mac> ip <ipv6>",
339     .function = lisp_add_del_ndp_entry_command_fn,
340 };
341 /* *INDENT-ON* */
342
343 static clib_error_t *
344 lisp_add_del_l2_arp_entry_command_fn (vlib_main_t * vm,
345                                       unformat_input_t * input,
346                                       vlib_cli_command_t * cmd)
347 {
348   unformat_input_t _line_input, *line_input = &_line_input;
349   clib_error_t *error = NULL;
350   int rc = 0;
351   u8 hw_addr[6], bd = 0;
352   ip4_address_t ip4;
353   u32 hw_addr_set = 0, ip_set = 0, is_add = 1;
354   gid_address_t _arp, *arp = &_arp;
355
356   memset (&ip4, 0, sizeof (ip4));
357   memset (hw_addr, 0, sizeof (hw_addr));
358   memset (arp, 0, sizeof (*arp));
359
360   if (!unformat_user (input, unformat_line_input, line_input))
361     return 0;
362
363   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
364     {
365       if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr))
366         hw_addr_set = 1;
367       else if (unformat (line_input, "ip %U", unformat_ip4_address, &ip4))
368         ip_set = 1;
369       else if (unformat (line_input, "del"))
370         is_add = 0;
371       else if (unformat (line_input, "bd %d", &bd))
372         ;
373       else
374         {
375           error = clib_error_return (0, "parse error");
376           goto done;
377         }
378     }
379
380   if (!ip_set || (!hw_addr_set && is_add))
381     {
382       vlib_cli_output (vm, "expected IP and MAC addresses!");
383       return 0;
384     }
385
386   /* build GID address */
387   gid_address_arp_ip4 (arp) = ip4;
388   gid_address_arp_bd (arp) = bd;
389   gid_address_type (arp) = GID_ADDR_ARP;
390   rc = vnet_lisp_add_del_l2_arp_ndp_entry (arp, hw_addr, is_add);
391   if (rc)
392     clib_warning ("Failed to %s l2 arp entry!", is_add ? "add" : "delete");
393
394 done:
395   unformat_free (line_input);
396   return error;
397 }
398
399 /* *INDENT-OFF* */
400 VLIB_CLI_COMMAND (one_add_del_l2_arp_entry_command) = {
401     .path = "one l2 arp",
402     .short_help = "one l2 arp [del] bd <bd> mac <mac> ip <ipv4>",
403     .function = lisp_add_del_l2_arp_entry_command_fn,
404 };
405 /* *INDENT-ON* */
406
407 static clib_error_t *
408 lisp_show_l2_arp_entries_command_fn (vlib_main_t * vm,
409                                      unformat_input_t * input,
410                                      vlib_cli_command_t * cmd)
411 {
412   u32 *ht = vnet_lisp_l2_arp_bds_get ();
413   lisp_api_l2_arp_entry_t *entries, *e;
414   hash_pair_t *p;
415
416   /* *INDENT-OFF* */
417   hash_foreach_pair (p, ht,
418   ({
419     entries = vnet_lisp_l2_arp_entries_get_by_bd (p->key);
420     vlib_cli_output (vm, "Table: %d", p->key);
421
422     vec_foreach (e, entries)
423       {
424         vlib_cli_output (vm, "\t%U -> %U", format_ip4_address, &e->ip4,
425                          format_mac_address, e->mac);
426       }
427     vec_free (entries);
428   }));
429   /* *INDENT-ON* */
430
431   hash_free (ht);
432   return 0;
433 }
434
435 /* *INDENT-OFF* */
436 VLIB_CLI_COMMAND (one_show_l2_arp_entries_command) = {
437     .path = "show one l2 arp entries",
438     .short_help = "Show ONE L2 ARP entries",
439     .function = lisp_show_l2_arp_entries_command_fn,
440 };
441 /* *INDENT-ON* */
442
443 static clib_error_t *
444 lisp_show_ndp_entries_command_fn (vlib_main_t * vm,
445                                   unformat_input_t * input,
446                                   vlib_cli_command_t * cmd)
447 {
448   u32 *ht = vnet_lisp_ndp_bds_get ();
449   lisp_api_ndp_entry_t *entries, *e;
450   hash_pair_t *p;
451
452   /* *INDENT-OFF* */
453   hash_foreach_pair (p, ht,
454   ({
455     entries = vnet_lisp_ndp_entries_get_by_bd (p->key);
456     vlib_cli_output (vm, "Table: %d", p->key);
457
458     vec_foreach (e, entries)
459       {
460         vlib_cli_output (vm, "\t%U -> %U", format_ip6_address, &e->ip6,
461                          format_mac_address, e->mac);
462       }
463     vec_free (entries);
464   }));
465   /* *INDENT-ON* */
466
467   hash_free (ht);
468   return 0;
469 }
470
471 /* *INDENT-OFF* */
472 VLIB_CLI_COMMAND (one_show_ndp_entries_command) = {
473     .path = "show one ndp entries",
474     .short_help = "Show ONE NDP entries",
475     .function = lisp_show_ndp_entries_command_fn,
476 };
477 /* *INDENT-ON* */
478
479 /**
480  * Handler for add/del remote mapping CLI.
481  *
482  * @param vm vlib context
483  * @param input input from user
484  * @param cmd cmd
485  * @return pointer to clib error structure
486  */
487 static clib_error_t *
488 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
489                                         unformat_input_t * input,
490                                         vlib_cli_command_t * cmd)
491 {
492   clib_error_t *error = 0;
493   unformat_input_t _line_input, *line_input = &_line_input;
494   u8 is_add = 1, del_all = 0;
495   locator_t rloc, *rlocs = 0, *curr_rloc = 0;
496   gid_address_t eid;
497   u8 eid_set = 0;
498   u32 vni, action = ~0, p, w;
499   int rv;
500
501   /* Get a line of input. */
502   if (!unformat_user (input, unformat_line_input, line_input))
503     return 0;
504
505   memset (&eid, 0, sizeof (eid));
506   memset (&rloc, 0, sizeof (rloc));
507
508   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
509     {
510       if (unformat (line_input, "del-all"))
511         del_all = 1;
512       else if (unformat (line_input, "del"))
513         is_add = 0;
514       else if (unformat (line_input, "add"))
515         ;
516       else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
517         eid_set = 1;
518       else if (unformat (line_input, "vni %u", &vni))
519         {
520           gid_address_vni (&eid) = vni;
521         }
522       else if (unformat (line_input, "p %d w %d", &p, &w))
523         {
524           if (!curr_rloc)
525             {
526               clib_warning
527                 ("No RLOC configured for setting priority/weight!");
528               goto done;
529             }
530           curr_rloc->priority = p;
531           curr_rloc->weight = w;
532         }
533       else if (unformat (line_input, "rloc %U", unformat_ip_address,
534                          &gid_address_ip (&rloc.address)))
535         {
536           /* since rloc is stored in ip prefix we need to set prefix length */
537           ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
538
539           u8 version = gid_address_ip_version (&rloc.address);
540           ip_prefix_len (pref) = ip_address_max_len (version);
541
542           vec_add1 (rlocs, rloc);
543           curr_rloc = &rlocs[vec_len (rlocs) - 1];
544         }
545       else if (unformat (line_input, "action %U",
546                          unformat_negative_mapping_action, &action))
547         ;
548       else
549         {
550           clib_warning ("parse error");
551           goto done;
552         }
553     }
554
555   if (!del_all && !eid_set)
556     {
557       clib_warning ("missing eid!");
558       goto done;
559     }
560
561   if (!del_all)
562     {
563       if (is_add && (~0 == action) && 0 == vec_len (rlocs))
564         {
565           clib_warning ("no action set for negative map-reply!");
566           goto done;
567         }
568     }
569   else
570     {
571       vnet_lisp_clear_all_remote_adjacencies ();
572       goto done;
573     }
574
575   /* if it's a delete, clean forwarding */
576   if (!is_add)
577     {
578       vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
579       memset (a, 0, sizeof (a[0]));
580       gid_address_copy (&a->reid, &eid);
581       if (vnet_lisp_add_del_adjacency (a))
582         {
583           clib_warning ("failed to delete adjacency!");
584           goto done;
585         }
586     }
587
588   /* add as static remote mapping, i.e., not authoritative and infinite
589    * ttl */
590   if (is_add)
591     {
592       vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args;
593       memset (map_args, 0, sizeof (map_args[0]));
594       gid_address_copy (&map_args->eid, &eid);
595       map_args->action = action;
596       map_args->is_static = 1;
597       map_args->authoritative = 0;
598       map_args->ttl = ~0;
599       rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL);
600     }
601   else
602     rv = vnet_lisp_del_mapping (&eid, NULL);
603
604   if (rv)
605     clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
606
607 done:
608   vec_free (rlocs);
609   unformat_free (line_input);
610   return error;
611 }
612
613 /* *INDENT-OFF* */
614 VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = {
615   .path = "one remote-mapping",
616   .short_help =
617     "one remote-mapping add|del [del-all] vni <vni> "
618     "eid <est-eid> [action <no-action|natively-forward|"
619     "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
620     "[rloc <dst-locator> ... ]",
621   .function = lisp_add_del_remote_mapping_command_fn,
622 };
623 /* *INDENT-ON* */
624
625 /**
626  * Handler for add/del adjacency CLI.
627  */
628 static clib_error_t *
629 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
630                                    vlib_cli_command_t * cmd)
631 {
632   clib_error_t *error = 0;
633   unformat_input_t _line_input, *line_input = &_line_input;
634   vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
635   u8 is_add = 1;
636   ip_prefix_t *reid_ippref, *leid_ippref;
637   gid_address_t leid, reid;
638   u8 *dmac = gid_address_mac (&reid);
639   u8 *smac = gid_address_mac (&leid);
640   u8 reid_set = 0, leid_set = 0;
641   u32 vni;
642
643   /* Get a line of input. */
644   if (!unformat_user (input, unformat_line_input, line_input))
645     return 0;
646
647   memset (&reid, 0, sizeof (reid));
648   memset (&leid, 0, sizeof (leid));
649
650   leid_ippref = &gid_address_ippref (&leid);
651   reid_ippref = &gid_address_ippref (&reid);
652
653   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
654     {
655       if (unformat (line_input, "del"))
656         is_add = 0;
657       else if (unformat (line_input, "add"))
658         ;
659       else if (unformat (line_input, "reid %U",
660                          unformat_ip_prefix, reid_ippref))
661         {
662           gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
663           reid_set = 1;
664         }
665       else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
666         {
667           gid_address_type (&reid) = GID_ADDR_MAC;
668           reid_set = 1;
669         }
670       else if (unformat (line_input, "vni %u", &vni))
671         {
672           gid_address_vni (&leid) = vni;
673           gid_address_vni (&reid) = vni;
674         }
675       else if (unformat (line_input, "leid %U",
676                          unformat_ip_prefix, leid_ippref))
677         {
678           gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
679           leid_set = 1;
680         }
681       else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
682         {
683           gid_address_type (&leid) = GID_ADDR_MAC;
684           leid_set = 1;
685         }
686       else
687         {
688           clib_warning ("parse error");
689           goto done;
690         }
691     }
692
693   if (!reid_set || !leid_set)
694     {
695       clib_warning ("missing remote or local eid!");
696       goto done;
697     }
698
699   if ((gid_address_type (&leid) != gid_address_type (&reid))
700       || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
701           && ip_prefix_version (reid_ippref)
702           != ip_prefix_version (leid_ippref)))
703     {
704       clib_warning ("remote and local EIDs are of different types!");
705       goto done;
706     }
707
708   memset (a, 0, sizeof (a[0]));
709   gid_address_copy (&a->leid, &leid);
710   gid_address_copy (&a->reid, &reid);
711   a->is_add = is_add;
712
713   if (vnet_lisp_add_del_adjacency (a))
714     clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
715
716 done:
717   unformat_free (line_input);
718   return error;
719 }
720
721 /* *INDENT-OFF* */
722 VLIB_CLI_COMMAND (one_add_del_adjacency_command) = {
723     .path = "one adjacency",
724     .short_help = "one adjacency add|del vni <vni> reid <remote-eid> "
725       "leid <local-eid>",
726     .function = lisp_add_del_adjacency_command_fn,
727 };
728 /* *INDENT-ON* */
729
730
731 static clib_error_t *
732 lisp_map_request_mode_command_fn (vlib_main_t * vm,
733                                   unformat_input_t * input,
734                                   vlib_cli_command_t * cmd)
735 {
736   unformat_input_t _i, *i = &_i;
737   map_request_mode_t mr_mode = _MR_MODE_MAX;
738
739   /* Get a line of input. */
740   if (!unformat_user (input, unformat_line_input, i))
741     return 0;
742
743   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
744     {
745       if (unformat (i, "dst-only"))
746         mr_mode = MR_MODE_DST_ONLY;
747       else if (unformat (i, "src-dst"))
748         mr_mode = MR_MODE_SRC_DST;
749       else
750         {
751           clib_warning ("parse error '%U'", format_unformat_error, i);
752           goto done;
753         }
754     }
755
756   if (_MR_MODE_MAX == mr_mode)
757     {
758       clib_warning ("No map request mode entered!");
759       goto done;
760     }
761
762   vnet_lisp_set_map_request_mode (mr_mode);
763
764 done:
765   unformat_free (i);
766
767   return 0;
768 }
769
770 /* *INDENT-OFF* */
771 VLIB_CLI_COMMAND (one_map_request_mode_command) = {
772     .path = "one map-request mode",
773     .short_help = "one map-request mode dst-only|src-dst",
774     .function = lisp_map_request_mode_command_fn,
775 };
776 /* *INDENT-ON* */
777
778
779 static u8 *
780 format_lisp_map_request_mode (u8 * s, va_list * args)
781 {
782   u32 mode = va_arg (*args, u32);
783
784   switch (mode)
785     {
786     case 0:
787       return format (0, "dst-only");
788     case 1:
789       return format (0, "src-dst");
790     }
791   return 0;
792 }
793
794 static clib_error_t *
795 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
796                                        unformat_input_t * input,
797                                        vlib_cli_command_t * cmd)
798 {
799   vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
800                    vnet_lisp_get_map_request_mode ());
801   return 0;
802 }
803
804 /* *INDENT-OFF* */
805 VLIB_CLI_COMMAND (one_show_map_request_mode_command) = {
806     .path = "show one map-request mode",
807     .short_help = "show one map-request mode",
808     .function = lisp_show_map_request_mode_command_fn,
809 };
810 /* *INDENT-ON* */
811
812 static clib_error_t *
813 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
814                                     unformat_input_t * input,
815                                     vlib_cli_command_t * cmd)
816 {
817   lisp_msmr_t *mr;
818   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
819
820   vec_foreach (mr, lcm->map_resolvers)
821   {
822     vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
823   }
824   return 0;
825 }
826
827 /* *INDENT-OFF* */
828 VLIB_CLI_COMMAND (one_show_map_resolvers_command) = {
829     .path = "show one map-resolvers",
830     .short_help = "show one map-resolvers",
831     .function = lisp_show_map_resolvers_command_fn,
832 };
833 /* *INDENT-ON* */
834
835 static clib_error_t *
836 lisp_nsh_set_locator_set_command_fn (vlib_main_t * vm,
837                                      unformat_input_t * input,
838                                      vlib_cli_command_t * cmd)
839 {
840   u8 locator_name_set = 0;
841   u8 *locator_set_name = 0;
842   u8 is_add = 1;
843   unformat_input_t _line_input, *line_input = &_line_input;
844   clib_error_t *error = 0;
845   int rv = 0;
846
847   /* Get a line of input. */
848   if (!unformat_user (input, unformat_line_input, line_input))
849     return 0;
850
851   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
852     {
853       if (unformat (line_input, "ls %_%v%_", &locator_set_name))
854         locator_name_set = 1;
855       else if (unformat (line_input, "disable"))
856         is_add = 0;
857       else
858         {
859           error = clib_error_return (0, "parse error");
860           goto done;
861         }
862     }
863
864   if (!locator_name_set)
865     {
866       clib_warning ("No locator set specified!");
867       goto done;
868     }
869
870   rv = vnet_lisp_nsh_set_locator_set (locator_set_name, is_add);
871   if (0 != rv)
872     {
873       error = clib_error_return (0, "failed to %s NSH mapping!",
874                                  is_add ? "add" : "delete");
875     }
876
877 done:
878   vec_free (locator_set_name);
879   unformat_free (line_input);
880   return error;
881 }
882
883 /* *INDENT-OFF* */
884 VLIB_CLI_COMMAND (one_nsh_set_locator_set_command) = {
885     .path = "one nsh-mapping",
886     .short_help = "one nsh-mapping [del] ls <locator-set-name>",
887     .function = lisp_nsh_set_locator_set_command_fn,
888 };
889 /* *INDENT-ON* */
890
891 static clib_error_t *
892 lisp_map_register_fallback_threshold_show_command_fn (vlib_main_t * vm,
893                                                       unformat_input_t *
894                                                       input,
895                                                       vlib_cli_command_t *
896                                                       cmd)
897 {
898   u32 val = vnet_lisp_map_register_fallback_threshold_get ();
899   vlib_cli_output (vm, "map register fallback treshold value: %d", val);
900   return 0;
901 }
902
903 /* *INDENT-OFF* */
904 VLIB_CLI_COMMAND (one_map_register_fallback_threshold_show_command) = {
905     .path = "show one map-register fallback-threshold",
906     .short_help = "show one map-register fallback-threshold",
907     .function = lisp_map_register_fallback_threshold_show_command_fn,
908 };
909
910 /* *INDENT-ON* */
911
912 static clib_error_t *
913 lisp_map_register_fallback_threshold_command_fn (vlib_main_t * vm,
914                                                  unformat_input_t * input,
915                                                  vlib_cli_command_t * cmd)
916 {
917   unformat_input_t _line_input, *line_input = &_line_input;
918   clib_error_t *error = 0;
919   u32 val = 0;
920   int rv = 0;
921
922   /* Get a line of input. */
923   if (!unformat_user (input, unformat_line_input, line_input))
924     return 0;
925
926   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
927     {
928       if (unformat (line_input, "%d", &val))
929         ;
930       else
931         {
932           error = clib_error_return (0, "parse error");
933           goto done;
934         }
935     }
936
937   rv = vnet_lisp_map_register_fallback_threshold_set (val);
938   if (rv)
939     {
940       error = clib_error_return (0, "setting fallback threshold failed!");
941     }
942
943 done:
944   unformat_free (line_input);
945   return error;
946 }
947
948 /* *INDENT-OFF* */
949 VLIB_CLI_COMMAND (one_map_register_fallback_threshold_command) = {
950     .path = "one map-register fallback-threshold",
951     .short_help = "one map-register fallback-threshold <count>",
952     .function = lisp_map_register_fallback_threshold_command_fn,
953 };
954 /* *INDENT-ON* */
955
956 static clib_error_t *
957 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
958                                       unformat_input_t * input,
959                                       vlib_cli_command_t * cmd)
960 {
961   u8 locator_name_set = 0;
962   u8 *locator_set_name = 0;
963   u8 is_add = 1;
964   unformat_input_t _line_input, *line_input = &_line_input;
965   clib_error_t *error = 0;
966   int rv = 0;
967
968   /* Get a line of input. */
969   if (!unformat_user (input, unformat_line_input, line_input))
970     return 0;
971
972   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
973     {
974       if (unformat (line_input, "ls %_%v%_", &locator_set_name))
975         locator_name_set = 1;
976       else if (unformat (line_input, "disable"))
977         is_add = 0;
978       else
979         {
980           error = clib_error_return (0, "parse error");
981           goto done;
982         }
983     }
984
985   if (!locator_name_set)
986     {
987       clib_warning ("No locator set specified!");
988       goto done;
989     }
990   rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
991   if (0 != rv)
992     {
993       error = clib_error_return (0, "failed to %s pitr!",
994                                  is_add ? "add" : "delete");
995     }
996
997 done:
998   if (locator_set_name)
999     vec_free (locator_set_name);
1000   unformat_free (line_input);
1001   return error;
1002 }
1003
1004 /* *INDENT-OFF* */
1005 VLIB_CLI_COMMAND (one_pitr_set_locator_set_command) = {
1006     .path = "one pitr",
1007     .short_help = "one pitr [disable] ls <locator-set-name>",
1008     .function = lisp_pitr_set_locator_set_command_fn,
1009 };
1010 /* *INDENT-ON* */
1011
1012 static clib_error_t *
1013 lisp_show_pitr_command_fn (vlib_main_t * vm,
1014                            unformat_input_t * input, vlib_cli_command_t * cmd)
1015 {
1016   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1017   mapping_t *m;
1018   locator_set_t *ls;
1019   u8 *tmp_str = 0;
1020
1021   vlib_cli_output (vm, "%=20s%=16s",
1022                    "pitr", lcm->lisp_pitr ? "locator-set" : "");
1023
1024   if (!lcm->lisp_pitr)
1025     {
1026       vlib_cli_output (vm, "%=20s", "disable");
1027       return 0;
1028     }
1029
1030   if (~0 == lcm->pitr_map_index)
1031     {
1032       tmp_str = format (0, "N/A");
1033     }
1034   else
1035     {
1036       m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1037       if (~0 != m->locator_set_index)
1038         {
1039           ls =
1040             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1041           tmp_str = format (0, "%s", ls->name);
1042         }
1043       else
1044         {
1045           tmp_str = format (0, "N/A");
1046         }
1047     }
1048   vec_add1 (tmp_str, 0);
1049
1050   vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1051
1052   vec_free (tmp_str);
1053
1054   return 0;
1055 }
1056
1057 /* *INDENT-OFF* */
1058 VLIB_CLI_COMMAND (one_show_pitr_command) = {
1059     .path = "show one pitr",
1060     .short_help = "Show pitr",
1061     .function = lisp_show_pitr_command_fn,
1062 };
1063 /* *INDENT-ON* */
1064
1065 static u8 *
1066 format_eid_entry (u8 * s, va_list * args)
1067 {
1068   vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
1069   lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
1070   mapping_t *mapit = va_arg (*args, mapping_t *);
1071   locator_set_t *ls = va_arg (*args, locator_set_t *);
1072   gid_address_t *gid = &mapit->eid;
1073   u32 ttl = mapit->ttl;
1074   u8 aut = mapit->authoritative;
1075   u32 *loc_index;
1076   u8 first_line = 1;
1077   u8 *loc;
1078
1079   u8 *type = ls->local ? format (0, "local(%s)", ls->name)
1080     : format (0, "remote");
1081
1082   if (vec_len (ls->locator_indices) == 0)
1083     {
1084       s = format (s, "%-35U%-20saction:%-30U%-20u%-u", format_gid_address,
1085                   gid, type, format_negative_mapping_action, mapit->action,
1086                   ttl, aut);
1087     }
1088   else
1089     {
1090       vec_foreach (loc_index, ls->locator_indices)
1091       {
1092         locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
1093         if (l->local)
1094           loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
1095                         l->sw_if_index);
1096         else
1097           loc = format (0, "%U", format_ip_address,
1098                         &gid_address_ip (&l->address));
1099
1100         if (first_line)
1101           {
1102             s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
1103                         gid, type, loc, ttl, aut);
1104             first_line = 0;
1105           }
1106         else
1107           s = format (s, "%55s%v\n", "", loc);
1108       }
1109     }
1110   return s;
1111 }
1112
1113 static clib_error_t *
1114 lisp_show_eid_table_command_fn (vlib_main_t * vm,
1115                                 unformat_input_t * input,
1116                                 vlib_cli_command_t * cmd)
1117 {
1118   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1119   mapping_t *mapit;
1120   unformat_input_t _line_input, *line_input = &_line_input;
1121   u32 mi;
1122   gid_address_t eid;
1123   u8 print_all = 1;
1124   u8 filter = 0;
1125   clib_error_t *error = NULL;
1126
1127   memset (&eid, 0, sizeof (eid));
1128
1129   /* Get a line of input. */
1130   if (!unformat_user (input, unformat_line_input, line_input))
1131     return 0;
1132
1133   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1134     {
1135       if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
1136         print_all = 0;
1137       else if (unformat (line_input, "local"))
1138         filter = 1;
1139       else if (unformat (line_input, "remote"))
1140         filter = 2;
1141       else
1142         {
1143           error = clib_error_return (0, "parse error: '%U'",
1144                                      format_unformat_error, line_input);
1145           goto done;
1146         }
1147     }
1148
1149   vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
1150                    "EID", "type", "locators", "ttl", "autoritative");
1151
1152   if (print_all)
1153     {
1154       /* *INDENT-OFF* */
1155       pool_foreach (mapit, lcm->mapping_pool,
1156       ({
1157         if (mapit->pitr_set || mapit->nsh_set)
1158           continue;
1159
1160         locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
1161                                                 mapit->locator_set_index);
1162         if (filter && !((1 == filter && ls->local) ||
1163           (2 == filter && !ls->local)))
1164           {
1165             continue;
1166           }
1167         vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
1168                          lcm, mapit, ls);
1169       }));
1170       /* *INDENT-ON* */
1171     }
1172   else
1173     {
1174       mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
1175       if ((u32) ~ 0 == mi)
1176         goto done;
1177
1178       mapit = pool_elt_at_index (lcm->mapping_pool, mi);
1179       locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
1180                                              mapit->locator_set_index);
1181
1182       if (filter && !((1 == filter && ls->local) ||
1183                       (2 == filter && !ls->local)))
1184         {
1185           goto done;
1186         }
1187
1188       vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
1189                        lcm, mapit, ls);
1190     }
1191
1192 done:
1193   unformat_free (line_input);
1194
1195   return error;
1196 }
1197
1198 /* *INDENT-OFF* */
1199 VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = {
1200     .path = "show one eid-table",
1201     .short_help = "Shows EID table",
1202     .function = lisp_show_eid_table_command_fn,
1203 };
1204 /* *INDENT-ON* */
1205
1206
1207 static clib_error_t *
1208 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
1209                                 vlib_cli_command_t * cmd)
1210 {
1211   unformat_input_t _line_input, *line_input = &_line_input;
1212   u8 is_enabled = 0;
1213   u8 is_set = 0;
1214   clib_error_t *error = NULL;
1215
1216   /* Get a line of input. */
1217   if (!unformat_user (input, unformat_line_input, line_input))
1218     return 0;
1219
1220   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1221     {
1222       if (unformat (line_input, "enable"))
1223         {
1224           is_set = 1;
1225           is_enabled = 1;
1226         }
1227       else if (unformat (line_input, "disable"))
1228         is_set = 1;
1229       else
1230         {
1231           error = clib_error_return (0, "parse error: '%U'",
1232                                      format_unformat_error, line_input);
1233           goto done;
1234         }
1235     }
1236
1237   if (!is_set)
1238     {
1239       error = clib_error_return (0, "state not set");
1240       goto done;
1241     }
1242
1243   vnet_lisp_enable_disable (is_enabled);
1244
1245 done:
1246   unformat_free (line_input);
1247
1248   return error;
1249 }
1250
1251 /* *INDENT-OFF* */
1252 VLIB_CLI_COMMAND (one_cp_enable_disable_command) = {
1253     .path = "one",
1254     .short_help = "one [enable|disable]",
1255     .function = lisp_enable_disable_command_fn,
1256 };
1257 /* *INDENT-ON* */
1258
1259 static clib_error_t *
1260 lisp_map_register_set_ttl_command_fn (vlib_main_t * vm,
1261                                       unformat_input_t * input,
1262                                       vlib_cli_command_t * cmd)
1263 {
1264   unformat_input_t _line_input, *line_input = &_line_input;
1265   u32 ttl = 0;
1266   u8 is_set = 0;
1267   clib_error_t *error = NULL;
1268
1269   /* Get a line of input. */
1270   if (!unformat_user (input, unformat_line_input, line_input))
1271     return 0;
1272
1273   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1274     {
1275       if (unformat (line_input, "%u", &ttl))
1276         is_set = 1;
1277       else
1278         {
1279           vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1280                            line_input);
1281           goto done;
1282         }
1283     }
1284
1285   if (!is_set)
1286     {
1287       vlib_cli_output (vm, "expected integer value for TTL!");
1288       goto done;
1289     }
1290
1291   vnet_lisp_map_register_set_ttl (ttl);
1292
1293 done:
1294   unformat_free (line_input);
1295   return error;
1296 }
1297
1298 /* *INDENT-OFF* */
1299 VLIB_CLI_COMMAND (one_map_register_set_ttl_command) = {
1300     .path = "one map-register ttl",
1301     .short_help = "one map-register ttl",
1302     .function = lisp_map_register_set_ttl_command_fn,
1303 };
1304 /* *INDENT-ON* */
1305
1306 static clib_error_t *
1307 lisp_map_register_show_ttl_command_fn (vlib_main_t * vm,
1308                                        unformat_input_t * input,
1309                                        vlib_cli_command_t * cmd)
1310 {
1311   u32 ttl = vnet_lisp_map_register_get_ttl ();
1312
1313   vlib_cli_output (vm, "map-register TTL: %u", ttl);
1314   return 0;
1315 }
1316
1317 /* *INDENT-OFF* */
1318 VLIB_CLI_COMMAND (one_map_register_show_ttl_command) = {
1319     .path = "show one map-register ttl",
1320     .short_help = "show one map-register ttl",
1321     .function = lisp_map_register_show_ttl_command_fn,
1322 };
1323
1324 /* *INDENT-ON* */
1325
1326 static clib_error_t *
1327 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
1328                                              unformat_input_t * input,
1329                                              vlib_cli_command_t * cmd)
1330 {
1331   unformat_input_t _line_input, *line_input = &_line_input;
1332   u8 is_enabled = 0;
1333   u8 is_set = 0;
1334   clib_error_t *error = NULL;
1335
1336   /* Get a line of input. */
1337   if (!unformat_user (input, unformat_line_input, line_input))
1338     return 0;
1339
1340   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1341     {
1342       if (unformat (line_input, "enable"))
1343         {
1344           is_set = 1;
1345           is_enabled = 1;
1346         }
1347       else if (unformat (line_input, "disable"))
1348         is_set = 1;
1349       else
1350         {
1351           vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1352                            line_input);
1353           goto done;
1354         }
1355     }
1356
1357   if (!is_set)
1358     {
1359       vlib_cli_output (vm, "state not set!");
1360       goto done;
1361     }
1362
1363   vnet_lisp_map_register_enable_disable (is_enabled);
1364
1365 done:
1366   unformat_free (line_input);
1367
1368   return error;
1369 }
1370
1371 /* *INDENT-OFF* */
1372 VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = {
1373     .path = "one map-register",
1374     .short_help = "one map-register [enable|disable]",
1375     .function = lisp_map_register_enable_disable_command_fn,
1376 };
1377 /* *INDENT-ON* */
1378
1379 static clib_error_t *
1380 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
1381                                            unformat_input_t * input,
1382                                            vlib_cli_command_t * cmd)
1383 {
1384   unformat_input_t _line_input, *line_input = &_line_input;
1385   u8 is_enabled = 0;
1386   u8 is_set = 0;
1387   clib_error_t *error = NULL;
1388
1389   /* Get a line of input. */
1390   if (!unformat_user (input, unformat_line_input, line_input))
1391     return 0;
1392
1393   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1394     {
1395       if (unformat (line_input, "enable"))
1396         {
1397           is_set = 1;
1398           is_enabled = 1;
1399         }
1400       else if (unformat (line_input, "disable"))
1401         is_set = 1;
1402       else
1403         {
1404           vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1405                            line_input);
1406           goto done;
1407         }
1408     }
1409
1410   if (!is_set)
1411     {
1412       vlib_cli_output (vm, "state not set!");
1413       goto done;
1414     }
1415
1416   vnet_lisp_rloc_probe_enable_disable (is_enabled);
1417
1418 done:
1419   unformat_free (line_input);
1420
1421   return error;
1422 }
1423
1424 /* *INDENT-OFF* */
1425 VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = {
1426     .path = "one rloc-probe",
1427     .short_help = "one rloc-probe [enable|disable]",
1428     .function = lisp_rloc_probe_enable_disable_command_fn,
1429 };
1430 /* *INDENT-ON* */
1431
1432 static u8 *
1433 format_lisp_status (u8 * s, va_list * args)
1434 {
1435   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1436   return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
1437 }
1438
1439 static clib_error_t *
1440 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
1441                              vlib_cli_command_t * cmd)
1442 {
1443   u8 *msg = 0;
1444   msg = format (msg, "feature: %U\ngpe: %U\n",
1445                 format_lisp_status, format_vnet_lisp_gpe_status);
1446   vlib_cli_output (vm, "%v", msg);
1447   vec_free (msg);
1448   return 0;
1449 }
1450
1451 /* *INDENT-OFF* */
1452 VLIB_CLI_COMMAND (one_show_status_command) = {
1453     .path = "show one status",
1454     .short_help = "show one status",
1455     .function = lisp_show_status_command_fn,
1456 };
1457 /* *INDENT-ON* */
1458
1459 static clib_error_t *
1460 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1461                                     unformat_input_t * input,
1462                                     vlib_cli_command_t * cmd)
1463 {
1464   hash_pair_t *p;
1465   unformat_input_t _line_input, *line_input = &_line_input;
1466   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1467   uword *vni_table = 0;
1468   u8 is_l2 = 0;
1469   clib_error_t *error = NULL;
1470
1471   /* Get a line of input. */
1472   if (!unformat_user (input, unformat_line_input, line_input))
1473     return 0;
1474
1475   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1476     {
1477       if (unformat (line_input, "l2"))
1478         {
1479           vni_table = lcm->bd_id_by_vni;
1480           is_l2 = 1;
1481         }
1482       else if (unformat (line_input, "l3"))
1483         {
1484           vni_table = lcm->table_id_by_vni;
1485           is_l2 = 0;
1486         }
1487       else
1488         {
1489           error = clib_error_return (0, "parse error: '%U'",
1490                                      format_unformat_error, line_input);
1491           goto done;
1492         }
1493     }
1494
1495   if (!vni_table)
1496     {
1497       vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1498       goto done;
1499     }
1500
1501   vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1502
1503   /* *INDENT-OFF* */
1504   hash_foreach_pair (p, vni_table,
1505   ({
1506     vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1507   }));
1508   /* *INDENT-ON* */
1509
1510 done:
1511   unformat_free (line_input);
1512
1513   return error;
1514 }
1515
1516 /* *INDENT-OFF* */
1517 VLIB_CLI_COMMAND (one_show_eid_table_map_command) = {
1518     .path = "show one eid-table map",
1519     .short_help = "show one eid-table l2|l3",
1520     .function = lisp_show_eid_table_map_command_fn,
1521 };
1522 /* *INDENT-ON* */
1523
1524
1525 static clib_error_t *
1526 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1527                                      unformat_input_t * input,
1528                                      vlib_cli_command_t * cmd)
1529 {
1530   lisp_gpe_main_t *lgm = &lisp_gpe_main;
1531   vnet_main_t *vnm = lgm->vnet_main;
1532   unformat_input_t _line_input, *line_input = &_line_input;
1533   u8 is_add = 1;
1534   clib_error_t *error = 0;
1535   u8 *locator_set_name = 0;
1536   locator_t locator, *locators = 0;
1537   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1538   u32 ls_index = 0;
1539   int rv = 0;
1540
1541   memset (&locator, 0, sizeof (locator));
1542   memset (a, 0, sizeof (a[0]));
1543
1544   /* Get a line of input. */
1545   if (!unformat_user (input, unformat_line_input, line_input))
1546     return 0;
1547
1548   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1549     {
1550       if (unformat (line_input, "add %_%v%_", &locator_set_name))
1551         is_add = 1;
1552       else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1553         is_add = 0;
1554       else if (unformat (line_input, "iface %U p %d w %d",
1555                          unformat_vnet_sw_interface, vnm,
1556                          &locator.sw_if_index, &locator.priority,
1557                          &locator.weight))
1558         {
1559           locator.local = 1;
1560           vec_add1 (locators, locator);
1561         }
1562       else
1563         {
1564           error = unformat_parse_error (line_input);
1565           goto done;
1566         }
1567     }
1568
1569   a->name = locator_set_name;
1570   a->locators = locators;
1571   a->is_add = is_add;
1572   a->local = 1;
1573
1574   rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1575   if (0 != rv)
1576     {
1577       error = clib_error_return (0, "failed to %s locator-set!",
1578                                  is_add ? "add" : "delete");
1579     }
1580
1581 done:
1582   vec_free (locators);
1583   if (locator_set_name)
1584     vec_free (locator_set_name);
1585   unformat_free (line_input);
1586   return error;
1587 }
1588
1589 /* *INDENT-OFF* */
1590 VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = {
1591     .path = "one locator-set",
1592     .short_help = "one locator-set add/del <name> [iface <iface-name> "
1593         "p <priority> w <weight>]",
1594     .function = lisp_add_del_locator_set_command_fn,
1595 };
1596 /* *INDENT-ON* */
1597
1598 static clib_error_t *
1599 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1600                                         unformat_input_t * input,
1601                                         vlib_cli_command_t * cmd)
1602 {
1603   lisp_gpe_main_t *lgm = &lisp_gpe_main;
1604   vnet_main_t *vnm = lgm->vnet_main;
1605   unformat_input_t _line_input, *line_input = &_line_input;
1606   u8 is_add = 1;
1607   clib_error_t *error = 0;
1608   u8 *locator_set_name = 0;
1609   u8 locator_set_name_set = 0;
1610   locator_t locator, *locators = 0;
1611   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1612   u32 ls_index = 0;
1613
1614   memset (&locator, 0, sizeof (locator));
1615   memset (a, 0, sizeof (a[0]));
1616
1617   /* Get a line of input. */
1618   if (!unformat_user (input, unformat_line_input, line_input))
1619     return 0;
1620
1621   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1622     {
1623       if (unformat (line_input, "add"))
1624         is_add = 1;
1625       else if (unformat (line_input, "del"))
1626         is_add = 0;
1627       else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1628         locator_set_name_set = 1;
1629       else if (unformat (line_input, "iface %U p %d w %d",
1630                          unformat_vnet_sw_interface, vnm,
1631                          &locator.sw_if_index, &locator.priority,
1632                          &locator.weight))
1633         {
1634           locator.local = 1;
1635           vec_add1 (locators, locator);
1636         }
1637       else
1638         {
1639           error = unformat_parse_error (line_input);
1640           goto done;
1641         }
1642     }
1643
1644   if (!locator_set_name_set)
1645     {
1646       error = clib_error_return (0, "locator_set name not set!");
1647       goto done;
1648     }
1649
1650   a->name = locator_set_name;
1651   a->locators = locators;
1652   a->is_add = is_add;
1653   a->local = 1;
1654
1655   vnet_lisp_add_del_locator (a, 0, &ls_index);
1656
1657 done:
1658   vec_free (locators);
1659   vec_free (locator_set_name);
1660   unformat_free (line_input);
1661   return error;
1662 }
1663
1664 /* *INDENT-OFF* */
1665 VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = {
1666     .path = "one locator",
1667     .short_help = "one locator add/del locator-set <name> iface <iface-name> "
1668                   "p <priority> w <weight>",
1669     .function = lisp_add_del_locator_in_set_command_fn,
1670 };
1671 /* *INDENT-ON* */
1672
1673 static clib_error_t *
1674 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1675                                       unformat_input_t * input,
1676                                       vlib_cli_command_t * cmd)
1677 {
1678   locator_set_t *lsit;
1679   locator_t *loc;
1680   u32 *locit;
1681   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1682
1683   vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1684                    "Priority", "Weight");
1685
1686   /* *INDENT-OFF* */
1687   pool_foreach (lsit, lcm->locator_set_pool,
1688   ({
1689     u8 * msg = 0;
1690     int next_line = 0;
1691     if (lsit->local)
1692       {
1693         msg = format (msg, "%v", lsit->name);
1694       }
1695     else
1696       {
1697         msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1698       }
1699     vec_foreach (locit, lsit->locator_indices)
1700       {
1701         if (next_line)
1702           {
1703             msg = format (msg, "%16s", " ");
1704           }
1705         loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1706         if (loc->local)
1707           msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1708                         loc->weight);
1709         else
1710           msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1711                         &gid_address_ip(&loc->address), loc->priority,
1712                         loc->weight);
1713         next_line = 1;
1714       }
1715     vlib_cli_output (vm, "%v", msg);
1716     vec_free (msg);
1717   }));
1718   /* *INDENT-ON* */
1719   return 0;
1720 }
1721
1722 /* *INDENT-OFF* */
1723 VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = {
1724     .path = "show one locator-set",
1725     .short_help = "Shows locator-sets",
1726     .function = lisp_cp_show_locator_sets_command_fn,
1727 };
1728 /* *INDENT-ON* */
1729
1730
1731 static clib_error_t *
1732 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1733                                       unformat_input_t * input,
1734                                       vlib_cli_command_t * cmd)
1735 {
1736   unformat_input_t _line_input, *line_input = &_line_input;
1737   u8 is_add = 1, addr_set = 0;
1738   ip_address_t ip_addr;
1739   clib_error_t *error = 0;
1740   int rv = 0;
1741   vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1742
1743   /* Get a line of input. */
1744   if (!unformat_user (input, unformat_line_input, line_input))
1745     return 0;
1746
1747   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1748     {
1749       if (unformat (line_input, "add"))
1750         is_add = 1;
1751       else if (unformat (line_input, "del"))
1752         is_add = 0;
1753       else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1754         addr_set = 1;
1755       else
1756         {
1757           error = unformat_parse_error (line_input);
1758           goto done;
1759         }
1760     }
1761
1762   if (!addr_set)
1763     {
1764       error = clib_error_return (0, "Map-resolver address must be set!");
1765       goto done;
1766     }
1767
1768   a->is_add = is_add;
1769   a->address = ip_addr;
1770   rv = vnet_lisp_add_del_map_resolver (a);
1771   if (0 != rv)
1772     {
1773       error = clib_error_return (0, "failed to %s map-resolver!",
1774                                  is_add ? "add" : "delete");
1775     }
1776
1777 done:
1778   unformat_free (line_input);
1779   return error;
1780 }
1781
1782 /* *INDENT-OFF* */
1783 VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = {
1784     .path = "one map-resolver",
1785     .short_help = "one map-resolver add/del <ip_address>",
1786     .function = lisp_add_del_map_resolver_command_fn,
1787 };
1788 /* *INDENT-ON* */
1789
1790
1791 static clib_error_t *
1792 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1793                                         unformat_input_t * input,
1794                                         vlib_cli_command_t * cmd)
1795 {
1796   unformat_input_t _line_input, *line_input = &_line_input;
1797   u8 is_add = 1;
1798   u8 *locator_set_name = 0;
1799   clib_error_t *error = 0;
1800   int rv = 0;
1801   vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1802
1803   /* Get a line of input. */
1804   if (!unformat_user (input, unformat_line_input, line_input))
1805     return 0;
1806
1807   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1808     {
1809       if (unformat (line_input, "del"))
1810         is_add = 0;
1811       else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1812         is_add = 1;
1813       else
1814         {
1815           error = unformat_parse_error (line_input);
1816           goto done;
1817         }
1818     }
1819
1820   a->is_add = is_add;
1821   a->locator_set_name = locator_set_name;
1822   rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1823   if (0 != rv)
1824     {
1825       error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1826                                  is_add ? "add" : "delete");
1827     }
1828
1829 done:
1830   vec_free (locator_set_name);
1831   unformat_free (line_input);
1832   return error;
1833
1834 }
1835
1836 /* *INDENT-OFF* */
1837 VLIB_CLI_COMMAND (one_add_del_map_request_command) = {
1838     .path = "one map-request itr-rlocs",
1839     .short_help = "one map-request itr-rlocs add/del <locator_set_name>",
1840     .function = lisp_add_del_mreq_itr_rlocs_command_fn,
1841 };
1842 /* *INDENT-ON* */
1843
1844 static clib_error_t *
1845 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1846                                      unformat_input_t * input,
1847                                      vlib_cli_command_t * cmd)
1848 {
1849   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1850   locator_set_t *loc_set;
1851
1852   vlib_cli_output (vm, "%=20s", "itr-rlocs");
1853
1854   if (~0 == lcm->mreq_itr_rlocs)
1855     {
1856       return 0;
1857     }
1858
1859   loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1860
1861   vlib_cli_output (vm, "%=20s", loc_set->name);
1862
1863   return 0;
1864 }
1865
1866 /* *INDENT-OFF* */
1867 VLIB_CLI_COMMAND (one_show_map_request_command) = {
1868     .path = "show one map-request itr-rlocs",
1869     .short_help = "Shows map-request itr-rlocs",
1870     .function = lisp_show_mreq_itr_rlocs_command_fn,
1871 };
1872 /* *INDENT-ON* */
1873
1874 static clib_error_t *
1875 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
1876                                           unformat_input_t * input,
1877                                           vlib_cli_command_t * cmd)
1878 {
1879   u8 is_add = 1, ip_set = 0;
1880   unformat_input_t _line_input, *line_input = &_line_input;
1881   clib_error_t *error = 0;
1882   ip_address_t ip;
1883
1884   /* Get a line of input. */
1885   if (!unformat_user (input, unformat_line_input, line_input))
1886     return 0;
1887
1888   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1889     {
1890       if (unformat (line_input, "%U", unformat_ip_address, &ip))
1891         ip_set = 1;
1892       else if (unformat (line_input, "disable"))
1893         is_add = 0;
1894       else
1895         {
1896           error = clib_error_return (0, "parse error");
1897           goto done;
1898         }
1899     }
1900
1901   if (!ip_set)
1902     {
1903       clib_warning ("No petr IP specified!");
1904       goto done;
1905     }
1906
1907   if (vnet_lisp_use_petr (&ip, is_add))
1908     {
1909       error = clib_error_return (0, "failed to %s petr!",
1910                                  is_add ? "add" : "delete");
1911     }
1912
1913 done:
1914   unformat_free (line_input);
1915   return error;
1916 }
1917
1918 /* *INDENT-OFF* */
1919 VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = {
1920     .path = "one use-petr",
1921     .short_help = "one use-petr [disable] <petr-ip>",
1922     .function = lisp_use_petr_set_locator_set_command_fn,
1923 };
1924
1925 static clib_error_t *
1926 lisp_show_petr_command_fn (vlib_main_t * vm,
1927                            unformat_input_t * input, vlib_cli_command_t * cmd)
1928 {
1929   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1930   mapping_t *m;
1931   locator_set_t *ls;
1932   locator_t *loc;
1933   u8 *tmp_str = 0;
1934   u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
1935   vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
1936
1937   if (!use_petr)
1938     {
1939       vlib_cli_output (vm, "%=20s", "disable");
1940       return 0;
1941     }
1942
1943   if (~0 == lcm->petr_map_index)
1944     {
1945       tmp_str = format (0, "N/A");
1946     }
1947   else
1948     {
1949       m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1950       if (~0 != m->locator_set_index)
1951         {
1952           ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
1953           loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
1954           tmp_str = format (0, "%U", format_ip_address, &loc->address);
1955         }
1956       else
1957         {
1958           tmp_str = format (0, "N/A");
1959         }
1960     }
1961   vec_add1 (tmp_str, 0);
1962
1963   vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1964
1965   vec_free (tmp_str);
1966
1967   return 0;
1968 }
1969
1970 /* *INDENT-OFF* */
1971 VLIB_CLI_COMMAND (one_show_petr_command) = {
1972     .path = "show one petr",
1973     .short_help = "Show petr",
1974     .function = lisp_show_petr_command_fn,
1975 };
1976 /* *INDENT-ON* */
1977
1978 static clib_error_t *
1979 lisp_show_map_servers_command_fn (vlib_main_t * vm,
1980                                   unformat_input_t * input,
1981                                   vlib_cli_command_t * cmd)
1982 {
1983   lisp_msmr_t *ms;
1984   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1985
1986   vec_foreach (ms, lcm->map_servers)
1987   {
1988     vlib_cli_output (vm, "%U", format_ip_address, &ms->address);
1989   }
1990   return 0;
1991 }
1992
1993 /* *INDENT-OFF* */
1994 VLIB_CLI_COMMAND (one_show_map_servers_command) = {
1995     .path = "show one map-servers",
1996     .short_help = "show one map servers",
1997     .function = lisp_show_map_servers_command_fn,
1998 };
1999 /* *INDENT-ON* */
2000
2001 static clib_error_t *
2002 lisp_show_map_register_state_command_fn (vlib_main_t * vm,
2003                                          unformat_input_t * input,
2004                                          vlib_cli_command_t * cmd)
2005 {
2006   u8 *msg = 0;
2007   u8 is_enabled = vnet_lisp_map_register_state_get ();
2008
2009   msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
2010   vlib_cli_output (vm, "%v", msg);
2011   vec_free (msg);
2012   return 0;
2013 }
2014
2015 /* *INDENT-OFF* */
2016 VLIB_CLI_COMMAND (one_show_map_register_state_command) = {
2017     .path = "show one map-register state",
2018     .short_help = "show one map-register state",
2019     .function = lisp_show_map_register_state_command_fn,
2020 };
2021 /* *INDENT-ON* */
2022
2023 static clib_error_t *
2024 lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm,
2025                                        unformat_input_t * input,
2026                                        vlib_cli_command_t * cmd)
2027 {
2028   u8 *msg = 0;
2029   u8 is_enabled = vnet_lisp_rloc_probe_state_get ();
2030
2031   msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
2032   vlib_cli_output (vm, "%v", msg);
2033   vec_free (msg);
2034   return 0;
2035 }
2036
2037 /* *INDENT-OFF* */
2038 VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = {
2039     .path = "show one rloc state",
2040     .short_help = "show one RLOC state",
2041     .function = lisp_show_rloc_probe_state_command_fn,
2042 };
2043 /* *INDENT-ON* */
2044
2045 static clib_error_t *
2046 lisp_show_stats_command_fn (vlib_main_t * vm,
2047                             unformat_input_t * input,
2048                             vlib_cli_command_t * cmd)
2049 {
2050   u8 is_enabled = vnet_lisp_stats_enable_disable_state ();
2051   vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled");
2052   return 0;
2053 }
2054
2055 /* *INDENT-OFF* */
2056 VLIB_CLI_COMMAND (one_show_stats_command) = {
2057     .path = "show one statistics status",
2058     .short_help = "show ONE statistics enable/disable status",
2059     .function = lisp_show_stats_command_fn,
2060 };
2061 /* *INDENT-ON* */
2062
2063 static clib_error_t *
2064 lisp_show_stats_details_command_fn (vlib_main_t * vm,
2065                                     unformat_input_t * input,
2066                                     vlib_cli_command_t * cmd)
2067 {
2068   lisp_api_stats_t *stat, *stats = vnet_lisp_get_stats ();
2069
2070   if (vec_len (stats) > 0)
2071     vlib_cli_output (vm,
2072                      "[src-EID, dst-EID] [loc-rloc, rmt-rloc] count bytes\n");
2073   else
2074     vlib_cli_output (vm, "No statistics found.\n");
2075
2076   vec_foreach (stat, stats)
2077   {
2078     vlib_cli_output (vm, "[%U, %U] [%U, %U] %7u %7u\n",
2079                      format_fid_address, &stat->seid,
2080                      format_fid_address, &stat->deid,
2081                      format_ip_address, &stat->loc_rloc,
2082                      format_ip_address, &stat->rmt_rloc,
2083                      stat->counters.packets, stat->counters.bytes);
2084   }
2085   vec_free (stats);
2086   return 0;
2087 }
2088
2089 /* *INDENT-OFF* */
2090 VLIB_CLI_COMMAND (one_show_stats_details_command) = {
2091     .path = "show one statistics details",
2092     .short_help = "show ONE statistics",
2093     .function = lisp_show_stats_details_command_fn,
2094 };
2095 /* *INDENT-ON* */
2096
2097 static clib_error_t *
2098 lisp_stats_enable_disable_command_fn (vlib_main_t * vm,
2099                                       unformat_input_t * input,
2100                                       vlib_cli_command_t * cmd)
2101 {
2102   unformat_input_t _line_input, *line_input = &_line_input;
2103   u8 enable = 0;
2104
2105   /* Get a line of input. */
2106   if (!unformat_user (input, unformat_line_input, line_input))
2107     return 0;
2108
2109   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2110     {
2111       if (unformat (line_input, "enable"))
2112         enable = 1;
2113       else if (unformat (line_input, "disable"))
2114         enable = 0;
2115       else
2116         {
2117           clib_warning ("Error: expected enable/disable!");
2118           goto done;
2119         }
2120     }
2121   vnet_lisp_stats_enable_disable (enable);
2122 done:
2123   unformat_free (line_input);
2124   return 0;
2125 }
2126
2127 /* *INDENT-OFF* */
2128 VLIB_CLI_COMMAND (one_stats_enable_disable_command) = {
2129     .path = "one statistics",
2130     .short_help = "enable/disable ONE statistics collecting",
2131     .function = lisp_stats_enable_disable_command_fn,
2132 };
2133 /* *INDENT-ON* */
2134
2135 static clib_error_t *
2136 lisp_stats_flush_command_fn (vlib_main_t * vm,
2137                              unformat_input_t * input,
2138                              vlib_cli_command_t * cmd)
2139 {
2140   vnet_lisp_flush_stats ();
2141   return 0;
2142 }
2143
2144 /* *INDENT-OFF* */
2145 VLIB_CLI_COMMAND (one_stats_flush_command) = {
2146     .path = "one statistics flush",
2147     .short_help = "Flush ONE statistics",
2148     .function = lisp_stats_flush_command_fn,
2149 };
2150 /* *INDENT-ON* */
2151
2152 /*
2153  * fd.io coding-style-patch-verification: ON
2154  *
2155  * Local Variables:
2156  * eval: (c-set-style "gnu")
2157  * End:
2158  */