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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/lisp-cp/control.h>
17 #include <vnet/lisp-gpe/lisp_gpe.h>
20 lisp_show_adjacencies_command_fn (vlib_main_t * vm,
21 unformat_input_t * input,
22 vlib_cli_command_t * cmd)
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;
28 clib_error_t *error = NULL;
30 /* Get a line of input. */
31 if (!unformat_user (input, unformat_line_input, line_input))
34 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
36 if (unformat (line_input, "vni %d", &vni))
40 vlib_cli_output (vm, "parse error: '%U'",
41 format_unformat_error, line_input);
48 vlib_cli_output (vm, "error: no vni specified!");
52 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
54 vec_foreach (adj, adjs)
56 vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid,
57 format_gid_address, &adj->reid);
62 unformat_free (line_input);
68 VLIB_CLI_COMMAND (lisp_show_adjacencies_command) = {
69 .path = "show lisp adjacencies",
70 .short_help = "show lisp adjacencies",
71 .function = lisp_show_adjacencies_command_fn,
76 lisp_add_del_map_server_command_fn (vlib_main_t * vm,
77 unformat_input_t * input,
78 vlib_cli_command_t * cmd)
81 u8 is_add = 1, ip_set = 0;
83 unformat_input_t _line_input, *line_input = &_line_input;
84 clib_error_t *error = NULL;
86 /* Get a line of input. */
87 if (!unformat_user (input, unformat_line_input, line_input))
90 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
92 if (unformat (line_input, "add"))
94 else if (unformat (line_input, "del"))
96 else if (unformat (line_input, "%U", unformat_ip_address, &ip))
100 vlib_cli_output (vm, "parse error: '%U'",
101 format_unformat_error, line_input);
108 vlib_cli_output (vm, "map-server ip address not set!");
112 rv = vnet_lisp_add_del_map_server (&ip, is_add);
114 vlib_cli_output (vm, "failed to %s map-server!",
115 is_add ? "add" : "delete");
118 unformat_free (line_input);
124 VLIB_CLI_COMMAND (lisp_add_del_map_server_command) = {
125 .path = "lisp map-server",
126 .short_help = "lisp map-server add|del <ip>",
127 .function = lisp_add_del_map_server_command_fn,
132 static clib_error_t *
133 lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
134 vlib_cli_command_t * cmd)
136 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
137 unformat_input_t _line_input, *line_input = &_line_input;
140 gid_address_t *eids = 0;
141 clib_error_t *error = 0;
142 u8 *locator_set_name = 0;
143 u32 locator_set_index = 0, map_index = 0;
145 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
151 clib_memset (&eid, 0, sizeof (eid));
152 clib_memset (a, 0, sizeof (*a));
154 /* Get a line of input. */
155 if (!unformat_user (input, unformat_line_input, line_input))
158 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
160 if (unformat (line_input, "add"))
162 else if (unformat (line_input, "del"))
164 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
166 else if (unformat (line_input, "vni %d", &vni))
167 gid_address_vni (&eid) = vni;
168 else if (unformat (line_input, "secret-key %_%v%_", &key))
170 else if (unformat (line_input, "key-id %U", unformat_hmac_key_id,
173 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
175 vec_terminate_c_string (locator_set_name);
176 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
179 error = clib_error_return (0, "locator-set %s doesn't exist",
183 locator_set_index = p[0];
187 error = unformat_parse_error (line_input);
191 /* XXX treat batch configuration */
193 if (GID_ADDR_SRC_DST == gid_address_type (&eid))
196 clib_error_return (0, "src/dst is not supported for local EIDs!");
200 if (key && (0 == key_id))
202 vlib_cli_output (vm, "invalid key_id!");
206 gid_address_copy (&a->eid, &eid);
208 a->locator_set_index = locator_set_index;
213 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
216 error = clib_error_return (0, "failed to %s local mapping!",
217 is_add ? "add" : "delete");
221 if (locator_set_name)
222 vec_free (locator_set_name);
223 gid_address_free (&a->eid);
225 unformat_free (line_input);
231 VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = {
232 .path = "lisp eid-table",
233 .short_help = "lisp eid-table add/del [vni <vni>] eid <eid> "
234 "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]",
235 .function = lisp_add_del_local_eid_command_fn,
239 static clib_error_t *
240 lisp_eid_table_map_command_fn (vlib_main_t * vm,
241 unformat_input_t * input,
242 vlib_cli_command_t * cmd)
244 u8 is_add = 1, is_l2 = 0;
245 u32 vni = 0, dp_id = 0;
246 unformat_input_t _line_input, *line_input = &_line_input;
247 clib_error_t *error = NULL;
249 /* Get a line of input. */
250 if (!unformat_user (input, unformat_line_input, line_input))
253 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
255 if (unformat (line_input, "del"))
257 else if (unformat (line_input, "vni %d", &vni))
259 else if (unformat (line_input, "vrf %d", &dp_id))
261 else if (unformat (line_input, "bd %d", &dp_id))
265 error = unformat_parse_error (line_input);
269 vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
272 unformat_free (line_input);
278 VLIB_CLI_COMMAND (lisp_eid_table_map_command) = {
279 .path = "lisp eid-table map",
280 .short_help = "lisp eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
281 .function = lisp_eid_table_map_command_fn,
286 * Handler for add/del remote mapping CLI.
288 * @param vm vlib context
289 * @param input input from user
291 * @return pointer to clib error structure
293 static clib_error_t *
294 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
295 unformat_input_t * input,
296 vlib_cli_command_t * cmd)
298 clib_error_t *error = 0;
299 unformat_input_t _line_input, *line_input = &_line_input;
300 u8 is_add = 1, del_all = 0;
301 locator_t rloc, *rlocs = 0, *curr_rloc = 0;
304 u32 vni, action = ~0, p, w;
307 /* Get a line of input. */
308 if (!unformat_user (input, unformat_line_input, line_input))
311 clib_memset (&eid, 0, sizeof (eid));
312 clib_memset (&rloc, 0, sizeof (rloc));
314 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
316 if (unformat (line_input, "del-all"))
318 else if (unformat (line_input, "del"))
320 else if (unformat (line_input, "add"))
322 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
324 else if (unformat (line_input, "vni %u", &vni))
326 gid_address_vni (&eid) = vni;
328 else if (unformat (line_input, "p %d w %d", &p, &w))
333 ("No RLOC configured for setting priority/weight!");
336 curr_rloc->priority = p;
337 curr_rloc->weight = w;
339 else if (unformat (line_input, "rloc %U", unformat_ip_address,
340 &gid_address_ip (&rloc.address)))
342 /* since rloc is stored in ip prefix we need to set prefix length */
343 ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
345 u8 version = gid_address_ip_version (&rloc.address);
346 ip_prefix_len (pref) = ip_address_max_len (version);
348 vec_add1 (rlocs, rloc);
349 curr_rloc = &rlocs[vec_len (rlocs) - 1];
351 else if (unformat (line_input, "action %U",
352 unformat_negative_mapping_action, &action))
356 clib_warning ("parse error");
363 clib_warning ("missing eid!");
369 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
371 clib_warning ("no action set for negative map-reply!");
377 vnet_lisp_clear_all_remote_adjacencies ();
381 /* TODO build src/dst with seid */
383 /* if it's a delete, clean forwarding */
386 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
387 clib_memset (a, 0, sizeof (a[0]));
388 gid_address_copy (&a->reid, &eid);
389 if (vnet_lisp_add_del_adjacency (a))
391 clib_warning ("failed to delete adjacency!");
396 /* add as static remote mapping, i.e., not authoritative and infinite
400 vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args;
401 clib_memset (map_args, 0, sizeof (map_args[0]));
402 gid_address_copy (&map_args->eid, &eid);
403 map_args->action = action;
404 map_args->is_static = 1;
405 map_args->authoritative = 0;
407 rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL);
410 rv = vnet_lisp_del_mapping (&eid, NULL);
413 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
417 unformat_free (line_input);
422 VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) = {
423 .path = "lisp remote-mapping",
424 .short_help = "lisp remote-mapping add|del [del-all] vni <vni> "
425 "eid <est-eid> [action <no-action|natively-forward|"
426 "send-map-request|drop>] rloc <dst-locator> p <prio> "
427 "w <weight> [rloc <dst-locator> ... ]",
428 .function = lisp_add_del_remote_mapping_command_fn,
433 * Handler for add/del adjacency CLI.
435 static clib_error_t *
436 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
437 vlib_cli_command_t * cmd)
439 clib_error_t *error = 0;
440 unformat_input_t _line_input, *line_input = &_line_input;
441 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
443 ip_prefix_t *reid_ippref, *leid_ippref;
444 gid_address_t leid, reid;
445 u8 *dmac = gid_address_mac (&reid);
446 u8 *smac = gid_address_mac (&leid);
447 u8 reid_set = 0, leid_set = 0;
450 /* Get a line of input. */
451 if (!unformat_user (input, unformat_line_input, line_input))
454 clib_memset (&reid, 0, sizeof (reid));
455 clib_memset (&leid, 0, sizeof (leid));
457 leid_ippref = &gid_address_ippref (&leid);
458 reid_ippref = &gid_address_ippref (&reid);
460 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
462 if (unformat (line_input, "del"))
464 else if (unformat (line_input, "add"))
466 else if (unformat (line_input, "reid %U",
467 unformat_ip_prefix, reid_ippref))
469 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
472 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
474 gid_address_type (&reid) = GID_ADDR_MAC;
477 else if (unformat (line_input, "vni %u", &vni))
479 gid_address_vni (&leid) = vni;
480 gid_address_vni (&reid) = vni;
482 else if (unformat (line_input, "leid %U",
483 unformat_ip_prefix, leid_ippref))
485 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
488 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
490 gid_address_type (&leid) = GID_ADDR_MAC;
495 clib_warning ("parse error");
500 if (!reid_set || !leid_set)
502 clib_warning ("missing remote or local eid!");
506 if ((gid_address_type (&leid) != gid_address_type (&reid))
507 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
508 && ip_prefix_version (reid_ippref)
509 != ip_prefix_version (leid_ippref)))
511 clib_warning ("remote and local EIDs are of different types!");
515 clib_memset (a, 0, sizeof (a[0]));
516 gid_address_copy (&a->leid, &leid);
517 gid_address_copy (&a->reid, &reid);
520 if (vnet_lisp_add_del_adjacency (a))
521 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
524 unformat_free (line_input);
529 VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = {
530 .path = "lisp adjacency",
531 .short_help = "lisp adjacency add|del vni <vni> reid <remote-eid> "
533 .function = lisp_add_del_adjacency_command_fn,
538 static clib_error_t *
539 lisp_map_request_mode_command_fn (vlib_main_t * vm,
540 unformat_input_t * input,
541 vlib_cli_command_t * cmd)
543 unformat_input_t _i, *i = &_i;
544 map_request_mode_t mr_mode = _MR_MODE_MAX;
545 clib_error_t *error = NULL;
547 /* Get a line of input. */
548 if (!unformat_user (input, unformat_line_input, i))
551 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
553 if (unformat (i, "dst-only"))
554 mr_mode = MR_MODE_DST_ONLY;
555 else if (unformat (i, "src-dst"))
556 mr_mode = MR_MODE_SRC_DST;
559 clib_warning ("parse error '%U'", format_unformat_error, i);
564 if (_MR_MODE_MAX == mr_mode)
566 clib_warning ("No LISP map request mode entered!");
570 vnet_lisp_set_map_request_mode (mr_mode);
579 VLIB_CLI_COMMAND (lisp_map_request_mode_command) = {
580 .path = "lisp map-request mode",
581 .short_help = "lisp map-request mode dst-only|src-dst",
582 .function = lisp_map_request_mode_command_fn,
588 format_lisp_map_request_mode (u8 * s, va_list * args)
590 u32 mode = va_arg (*args, u32);
595 return format (0, "dst-only");
597 return format (0, "src-dst");
602 static clib_error_t *
603 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
604 unformat_input_t * input,
605 vlib_cli_command_t * cmd)
607 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
608 vnet_lisp_get_map_request_mode ());
613 VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = {
614 .path = "show lisp map-request mode",
615 .short_help = "show lisp map-request mode",
616 .function = lisp_show_map_request_mode_command_fn,
620 static clib_error_t *
621 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
622 unformat_input_t * input,
623 vlib_cli_command_t * cmd)
626 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
628 vec_foreach (mr, lcm->map_resolvers)
630 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
636 VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = {
637 .path = "show lisp map-resolvers",
638 .short_help = "show lisp map-resolvers",
639 .function = lisp_show_map_resolvers_command_fn,
644 static clib_error_t *
645 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
646 unformat_input_t * input,
647 vlib_cli_command_t * cmd)
649 u8 locator_name_set = 0;
650 u8 *locator_set_name = 0;
652 unformat_input_t _line_input, *line_input = &_line_input;
653 clib_error_t *error = 0;
656 /* Get a line of input. */
657 if (!unformat_user (input, unformat_line_input, line_input))
660 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
662 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
663 locator_name_set = 1;
664 else if (unformat (line_input, "disable"))
668 error = clib_error_return (0, "parse error");
673 if (!locator_name_set)
675 clib_warning ("No locator set specified!");
678 vec_terminate_c_string (locator_set_name);
679 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
682 error = clib_error_return (0, "failed to %s pitr!",
683 is_add ? "add" : "delete");
687 if (locator_set_name)
688 vec_free (locator_set_name);
689 unformat_free (line_input);
695 VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = {
697 .short_help = "lisp pitr [disable] ls <locator-set-name>",
698 .function = lisp_pitr_set_locator_set_command_fn,
702 static clib_error_t *
703 lisp_show_pitr_command_fn (vlib_main_t * vm,
704 unformat_input_t * input, vlib_cli_command_t * cmd)
706 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
710 u8 status = lcm->flags & LISP_FLAG_PITR_MODE;
712 vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : "");
716 vlib_cli_output (vm, "%=20s", "disable");
720 if (~0 == lcm->pitr_map_index)
722 tmp_str = format (0, "N/A");
726 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
727 if (~0 != m->locator_set_index)
730 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
731 tmp_str = format (0, "%s", ls->name);
735 tmp_str = format (0, "N/A");
738 vec_add1 (tmp_str, 0);
740 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
748 VLIB_CLI_COMMAND (lisp_show_pitr_command) = {
749 .path = "show lisp pitr",
750 .short_help = "Show pitr",
751 .function = lisp_show_pitr_command_fn,
756 format_eid_entry (u8 * s, va_list * args)
758 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
759 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
760 mapping_t *mapit = va_arg (*args, mapping_t *);
761 locator_set_t *ls = va_arg (*args, locator_set_t *);
762 gid_address_t *gid = &mapit->eid;
763 u32 ttl = mapit->ttl;
764 u8 aut = mapit->authoritative;
769 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
770 : format (0, "remote");
772 if (vec_len (ls->locator_indices) == 0)
774 s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
779 vec_foreach (loc_index, ls->locator_indices)
781 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
783 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
786 loc = format (0, "%U", format_ip_address,
787 &gid_address_ip (&l->address));
791 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
792 gid, type, loc, ttl, aut);
796 s = format (s, "%55s%v\n", "", loc);
802 static clib_error_t *
803 lisp_show_eid_table_command_fn (vlib_main_t * vm,
804 unformat_input_t * input,
805 vlib_cli_command_t * cmd)
807 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
809 unformat_input_t _line_input, *line_input = &_line_input;
814 clib_error_t *error = NULL;
816 clib_memset (&eid, 0, sizeof (eid));
818 /* Get a line of input. */
819 if (!unformat_user (input, unformat_line_input, line_input))
822 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
824 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
826 else if (unformat (line_input, "local"))
828 else if (unformat (line_input, "remote"))
832 error = clib_error_return (0, "parse error: '%U'",
833 format_unformat_error, line_input);
838 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
839 "EID", "type", "locators", "ttl", "authoritative");
844 pool_foreach (mapit, lcm->mapping_pool,
849 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
850 mapit->locator_set_index);
851 if (filter && !((1 == filter && ls->local) ||
852 (2 == filter && !ls->local)))
856 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
863 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
867 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
868 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
869 mapit->locator_set_index);
871 if (filter && !((1 == filter && ls->local) ||
872 (2 == filter && !ls->local)))
877 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
882 unformat_free (line_input);
888 VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = {
889 .path = "show lisp eid-table",
890 .short_help = "Shows EID table",
891 .function = lisp_show_eid_table_command_fn,
896 static clib_error_t *
897 lisp_enable_command_fn (vlib_main_t * vm, unformat_input_t * input,
898 vlib_cli_command_t * cmd)
900 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
901 return clib_error_return (0, "parse error: '%U'", format_unformat_error,
904 vnet_lisp_enable_disable (1);
910 VLIB_CLI_COMMAND (lisp_cp_enable_command) = {
911 .path = "lisp enable",
912 .short_help = "lisp enable",
913 .function = lisp_enable_command_fn,
917 static clib_error_t *
918 lisp_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
919 vlib_cli_command_t * cmd)
921 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
922 return clib_error_return (0, "parse error: '%U'", format_unformat_error,
925 vnet_lisp_enable_disable (0);
931 VLIB_CLI_COMMAND (lisp_cp_disable_command) = {
932 .path = "lisp disable",
933 .short_help = "lisp disable",
934 .function = lisp_disable_command_fn,
938 static clib_error_t *
939 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
940 unformat_input_t * input,
941 vlib_cli_command_t * cmd)
943 unformat_input_t _line_input, *line_input = &_line_input;
946 clib_error_t *error = NULL;
948 /* Get a line of input. */
949 if (!unformat_user (input, unformat_line_input, line_input))
950 return clib_error_return (0, "expected enable | disable");
952 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
954 if (unformat (line_input, "enable"))
959 else if (unformat (line_input, "disable"))
963 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
971 vlib_cli_output (vm, "state not set!");
975 vnet_lisp_map_register_enable_disable (is_enabled);
978 unformat_free (line_input);
984 VLIB_CLI_COMMAND (lisp_map_register_enable_disable_command) = {
985 .path = "lisp map-register",
986 .short_help = "lisp map-register [enable|disable]",
987 .function = lisp_map_register_enable_disable_command_fn,
991 static clib_error_t *
992 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
993 unformat_input_t * input,
994 vlib_cli_command_t * cmd)
996 unformat_input_t _line_input, *line_input = &_line_input;
999 clib_error_t *error = NULL;
1001 /* Get a line of input. */
1002 if (!unformat_user (input, unformat_line_input, line_input))
1003 return clib_error_return (0, "expected enable | disable");
1005 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1007 if (unformat (line_input, "enable"))
1012 else if (unformat (line_input, "disable"))
1016 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1024 vlib_cli_output (vm, "state not set!");
1028 vnet_lisp_rloc_probe_enable_disable (is_enabled);
1031 unformat_free (line_input);
1037 VLIB_CLI_COMMAND (lisp_rloc_probe_enable_disable_command) = {
1038 .path = "lisp rloc-probe",
1039 .short_help = "lisp rloc-probe [enable|disable]",
1040 .function = lisp_rloc_probe_enable_disable_command_fn,
1045 format_lisp_status (u8 * s, va_list * args)
1047 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1048 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
1051 static clib_error_t *
1052 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
1053 vlib_cli_command_t * cmd)
1056 msg = format (msg, "feature: %U\ngpe: %U\n",
1057 format_lisp_status, format_vnet_lisp_gpe_status);
1058 vlib_cli_output (vm, "%v", msg);
1064 VLIB_CLI_COMMAND (lisp_show_status_command) = {
1065 .path = "show lisp status",
1066 .short_help = "show lisp status",
1067 .function = lisp_show_status_command_fn,
1071 static clib_error_t *
1072 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1073 unformat_input_t * input,
1074 vlib_cli_command_t * cmd)
1077 unformat_input_t _line_input, *line_input = &_line_input;
1078 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1079 uword *vni_table = 0;
1081 clib_error_t *error = NULL;
1083 /* Get a line of input. */
1084 if (!unformat_user (input, unformat_line_input, line_input))
1087 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1089 if (unformat (line_input, "l2"))
1091 vni_table = lcm->bd_id_by_vni;
1094 else if (unformat (line_input, "l3"))
1096 vni_table = lcm->table_id_by_vni;
1101 error = clib_error_return (0, "parse error: '%U'",
1102 format_unformat_error, line_input);
1109 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1113 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1116 hash_foreach_pair (p, vni_table,
1118 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1123 unformat_free (line_input);
1129 VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = {
1130 .path = "show lisp eid-table map",
1131 .short_help = "show lisp eid-table l2|l3",
1132 .function = lisp_show_eid_table_map_command_fn,
1137 static clib_error_t *
1138 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1139 unformat_input_t * input,
1140 vlib_cli_command_t * cmd)
1142 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1143 vnet_main_t *vnm = lgm->vnet_main;
1144 unformat_input_t _line_input, *line_input = &_line_input;
1146 clib_error_t *error = 0;
1147 u8 *locator_set_name = 0;
1148 locator_t locator, *locators = 0;
1149 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1153 clib_memset (&locator, 0, sizeof (locator));
1154 clib_memset (a, 0, sizeof (a[0]));
1156 /* Get a line of input. */
1157 if (!unformat_user (input, unformat_line_input, line_input))
1158 return clib_error_return (0, "missing parameters");
1160 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1162 if (unformat (line_input, "add %_%v%_", &locator_set_name))
1164 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1166 else if (unformat (line_input, "iface %U p %d w %d",
1167 unformat_vnet_sw_interface, vnm,
1168 &locator.sw_if_index, &locator.priority,
1173 vec_add1 (locators, locator);
1177 error = unformat_parse_error (line_input);
1182 a->name = locator_set_name;
1183 a->locators = locators;
1187 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1190 error = clib_error_return (0, "failed to %s locator-set!",
1191 is_add ? "add" : "delete");
1195 vec_free (locators);
1196 if (locator_set_name)
1197 vec_free (locator_set_name);
1198 unformat_free (line_input);
1204 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = {
1205 .path = "lisp locator-set",
1206 .short_help = "lisp locator-set add/del <name> [iface <iface-name> "
1207 "p <priority> w <weight>]",
1208 .function = lisp_add_del_locator_set_command_fn,
1212 static clib_error_t *
1213 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1214 unformat_input_t * input,
1215 vlib_cli_command_t * cmd)
1217 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1218 vnet_main_t *vnm = lgm->vnet_main;
1219 unformat_input_t _line_input, *line_input = &_line_input;
1221 clib_error_t *error = 0;
1222 u8 *locator_set_name = 0;
1223 u8 locator_set_name_set = 0;
1224 locator_t locator, *locators = 0;
1225 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1228 clib_memset (&locator, 0, sizeof (locator));
1229 clib_memset (a, 0, sizeof (a[0]));
1231 /* Get a line of input. */
1232 if (!unformat_user (input, unformat_line_input, line_input))
1235 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1237 if (unformat (line_input, "add"))
1239 else if (unformat (line_input, "del"))
1241 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1242 locator_set_name_set = 1;
1243 else if (unformat (line_input, "iface %U p %d w %d",
1244 unformat_vnet_sw_interface, vnm,
1245 &locator.sw_if_index, &locator.priority,
1249 vec_add1 (locators, locator);
1253 error = unformat_parse_error (line_input);
1258 if (!locator_set_name_set)
1260 error = clib_error_return (0, "locator_set name not set!");
1264 a->name = locator_set_name;
1265 a->locators = locators;
1269 vnet_lisp_add_del_locator (a, 0, &ls_index);
1272 vec_free (locators);
1273 vec_free (locator_set_name);
1274 unformat_free (line_input);
1280 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = {
1281 .path = "lisp locator",
1282 .short_help = "lisp locator add/del locator-set <name> iface <iface-name> "
1283 "p <priority> w <weight>",
1284 .function = lisp_add_del_locator_in_set_command_fn,
1288 static clib_error_t *
1289 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1290 unformat_input_t * input,
1291 vlib_cli_command_t * cmd)
1293 locator_set_t *lsit;
1296 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1298 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1299 "Priority", "Weight");
1302 pool_foreach (lsit, lcm->locator_set_pool,
1308 msg = format (msg, "%v", lsit->name);
1312 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1314 vec_foreach (locit, lsit->locator_indices)
1318 msg = format (msg, "%16s", " ");
1320 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1322 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1325 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1326 &gid_address_ip(&loc->address), loc->priority,
1330 vlib_cli_output (vm, "%v", msg);
1338 VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = {
1339 .path = "show lisp locator-set",
1340 .short_help = "Shows locator-sets",
1341 .function = lisp_cp_show_locator_sets_command_fn,
1346 static clib_error_t *
1347 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1348 unformat_input_t * input,
1349 vlib_cli_command_t * cmd)
1351 unformat_input_t _line_input, *line_input = &_line_input;
1352 u8 is_add = 1, addr_set = 0;
1353 ip_address_t ip_addr;
1354 clib_error_t *error = 0;
1356 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1358 /* Get a line of input. */
1359 if (!unformat_user (input, unformat_line_input, line_input))
1362 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1364 if (unformat (line_input, "add"))
1366 else if (unformat (line_input, "del"))
1368 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1372 error = unformat_parse_error (line_input);
1379 error = clib_error_return (0, "Map-resolver address must be set!");
1384 a->address = ip_addr;
1385 rv = vnet_lisp_add_del_map_resolver (a);
1388 error = clib_error_return (0, "failed to %s map-resolver!",
1389 is_add ? "add" : "delete");
1393 unformat_free (line_input);
1399 VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = {
1400 .path = "lisp map-resolver",
1401 .short_help = "lisp map-resolver add/del <ip_address>",
1402 .function = lisp_add_del_map_resolver_command_fn,
1407 static clib_error_t *
1408 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1409 unformat_input_t * input,
1410 vlib_cli_command_t * cmd)
1412 unformat_input_t _line_input, *line_input = &_line_input;
1414 u8 *locator_set_name = 0;
1415 clib_error_t *error = 0;
1417 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1419 /* Get a line of input. */
1420 if (!unformat_user (input, unformat_line_input, line_input))
1423 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1425 if (unformat (line_input, "del"))
1427 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1431 error = unformat_parse_error (line_input);
1436 vec_terminate_c_string (locator_set_name);
1438 a->locator_set_name = locator_set_name;
1439 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1442 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1443 is_add ? "add" : "delete");
1447 vec_free (locator_set_name);
1448 unformat_free (line_input);
1454 VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = {
1455 .path = "lisp map-request itr-rlocs",
1456 .short_help = "lisp map-request itr-rlocs add/del <locator_set_name>",
1457 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
1461 static clib_error_t *
1462 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1463 unformat_input_t * input,
1464 vlib_cli_command_t * cmd)
1466 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1467 locator_set_t *loc_set;
1469 vlib_cli_output (vm, "%=20s", "itr-rlocs");
1471 if (~0 == lcm->mreq_itr_rlocs)
1476 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1478 vlib_cli_output (vm, "%=20s", loc_set->name);
1484 VLIB_CLI_COMMAND (lisp_show_map_request_command) = {
1485 .path = "show lisp map-request itr-rlocs",
1486 .short_help = "Shows map-request itr-rlocs",
1487 .function = lisp_show_mreq_itr_rlocs_command_fn,
1491 static clib_error_t *
1492 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
1493 unformat_input_t * input,
1494 vlib_cli_command_t * cmd)
1496 u8 is_add = 1, ip_set = 0;
1497 unformat_input_t _line_input, *line_input = &_line_input;
1498 clib_error_t *error = 0;
1501 /* Get a line of input. */
1502 if (!unformat_user (input, unformat_line_input, line_input))
1505 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1507 if (unformat (line_input, "%U", unformat_ip_address, &ip))
1509 else if (unformat (line_input, "disable"))
1513 error = clib_error_return (0, "parse error");
1520 clib_warning ("No petr IP specified!");
1524 if (vnet_lisp_use_petr (&ip, is_add))
1526 error = clib_error_return (0, "failed to %s petr!",
1527 is_add ? "add" : "delete");
1531 unformat_free (line_input);
1537 VLIB_CLI_COMMAND (lisp_use_petr_set_locator_set_command) = {
1538 .path = "lisp use-petr",
1539 .short_help = "lisp use-petr [disable] <petr-ip>",
1540 .function = lisp_use_petr_set_locator_set_command_fn,
1543 static clib_error_t *
1544 lisp_show_petr_command_fn (vlib_main_t * vm,
1545 unformat_input_t * input, vlib_cli_command_t * cmd)
1547 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1552 u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
1553 vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
1557 vlib_cli_output (vm, "%=20s", "disable");
1561 if (~0 == lcm->petr_map_index)
1563 tmp_str = format (0, "N/A");
1567 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1568 if (~0 != m->locator_set_index)
1570 ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
1571 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
1572 tmp_str = format (0, "%U", format_ip_address, &loc->address);
1576 tmp_str = format (0, "N/A");
1579 vec_add1 (tmp_str, 0);
1581 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1589 VLIB_CLI_COMMAND (lisp_show_petr_command) = {
1590 .path = "show lisp petr",
1591 .short_help = "Show petr",
1592 .function = lisp_show_petr_command_fn,
1597 * fd.io coding-style-patch-verification: ON
1600 * eval: (c-set-style "gnu")