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 <lisp/lisp-cp/control.h>
17 #include <lisp/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);
67 VLIB_CLI_COMMAND (lisp_show_adjacencies_command) = {
68 .path = "show lisp adjacencies",
69 .short_help = "show lisp adjacencies",
70 .function = lisp_show_adjacencies_command_fn,
74 lisp_add_del_map_server_command_fn (vlib_main_t * vm,
75 unformat_input_t * input,
76 vlib_cli_command_t * cmd)
79 u8 is_add = 1, ip_set = 0;
81 unformat_input_t _line_input, *line_input = &_line_input;
82 clib_error_t *error = NULL;
84 /* Get a line of input. */
85 if (!unformat_user (input, unformat_line_input, line_input))
88 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
90 if (unformat (line_input, "add"))
92 else if (unformat (line_input, "del"))
94 else if (unformat (line_input, "%U", unformat_ip_address, &ip))
98 vlib_cli_output (vm, "parse error: '%U'",
99 format_unformat_error, line_input);
106 vlib_cli_output (vm, "map-server ip address not set!");
110 rv = vnet_lisp_add_del_map_server (&ip, is_add);
112 vlib_cli_output (vm, "failed to %s map-server!",
113 is_add ? "add" : "delete");
116 unformat_free (line_input);
121 VLIB_CLI_COMMAND (lisp_add_del_map_server_command) = {
122 .path = "lisp map-server",
123 .short_help = "lisp map-server add|del <ip>",
124 .function = lisp_add_del_map_server_command_fn,
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)
132 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
133 unformat_input_t _line_input, *line_input = &_line_input;
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;
141 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
147 clib_memset (&eid, 0, sizeof (eid));
148 clib_memset (a, 0, sizeof (*a));
150 /* Get a line of input. */
151 if (!unformat_user (input, unformat_line_input, line_input))
154 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
156 if (unformat (line_input, "add"))
158 else if (unformat (line_input, "del"))
160 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
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))
166 else if (unformat (line_input, "key-id %U", unformat_hmac_key_id,
169 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
171 vec_terminate_c_string (locator_set_name);
172 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
175 error = clib_error_return (0, "locator-set %s doesn't exist",
179 locator_set_index = p[0];
183 error = unformat_parse_error (line_input);
187 /* XXX treat batch configuration */
189 if (GID_ADDR_SRC_DST == gid_address_type (&eid))
192 clib_error_return (0, "src/dst is not supported for local EIDs!");
196 if (key && (0 == key_id))
198 vlib_cli_output (vm, "invalid key_id!");
202 gid_address_copy (&a->eid, &eid);
204 a->locator_set_index = locator_set_index;
209 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
212 error = clib_error_return (0, "failed to %s local mapping!",
213 is_add ? "add" : "delete");
217 if (locator_set_name)
218 vec_free (locator_set_name);
219 gid_address_free (&a->eid);
221 unformat_free (line_input);
226 VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = {
227 .path = "lisp eid-table",
228 .short_help = "lisp eid-table add/del [vni <vni>] eid <eid> "
229 "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]",
230 .function = lisp_add_del_local_eid_command_fn,
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)
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;
243 /* Get a line of input. */
244 if (!unformat_user (input, unformat_line_input, line_input))
247 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
249 if (unformat (line_input, "del"))
251 else if (unformat (line_input, "vni %d", &vni))
253 else if (unformat (line_input, "vrf %d", &dp_id))
255 else if (unformat (line_input, "bd %d", &dp_id))
259 error = unformat_parse_error (line_input);
263 vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
266 unformat_free (line_input);
271 VLIB_CLI_COMMAND (lisp_eid_table_map_command) = {
272 .path = "lisp eid-table map",
273 .short_help = "lisp eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
274 .function = lisp_eid_table_map_command_fn,
278 * Handler for add/del remote mapping CLI.
280 * @param vm vlib context
281 * @param input input from user
283 * @return pointer to clib error structure
285 static clib_error_t *
286 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
287 unformat_input_t * input,
288 vlib_cli_command_t * cmd)
290 clib_error_t *error = 0;
291 unformat_input_t _line_input, *line_input = &_line_input;
292 u8 is_add = 1, del_all = 0;
293 locator_t rloc, *rlocs = 0, *curr_rloc = 0;
296 u32 vni, action = ~0, p, w;
299 /* Get a line of input. */
300 if (!unformat_user (input, unformat_line_input, line_input))
303 clib_memset (&eid, 0, sizeof (eid));
304 clib_memset (&rloc, 0, sizeof (rloc));
306 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
308 if (unformat (line_input, "del-all"))
310 else if (unformat (line_input, "del"))
312 else if (unformat (line_input, "add"))
314 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
316 else if (unformat (line_input, "vni %u", &vni))
318 gid_address_vni (&eid) = vni;
320 else if (unformat (line_input, "p %d w %d", &p, &w))
325 ("No RLOC configured for setting priority/weight!");
328 curr_rloc->priority = p;
329 curr_rloc->weight = w;
331 else if (unformat (line_input, "rloc %U", unformat_ip_address,
332 &gid_address_ip (&rloc.address)))
334 /* since rloc is stored in ip prefix we need to set prefix length */
335 ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
337 u8 version = gid_address_ip_version (&rloc.address);
338 ip_prefix_len (pref) = ip_address_max_len (version);
340 vec_add1 (rlocs, rloc);
341 curr_rloc = &rlocs[vec_len (rlocs) - 1];
343 else if (unformat (line_input, "action %U",
344 unformat_negative_mapping_action, &action))
348 clib_warning ("parse error");
355 clib_warning ("missing eid!");
361 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
363 clib_warning ("no action set for negative map-reply!");
369 vnet_lisp_clear_all_remote_adjacencies ();
373 /* TODO build src/dst with seid */
375 /* if it's a delete, clean forwarding */
378 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
379 clib_memset (a, 0, sizeof (a[0]));
380 gid_address_copy (&a->reid, &eid);
381 if (vnet_lisp_add_del_adjacency (a))
383 clib_warning ("failed to delete adjacency!");
388 /* add as static remote mapping, i.e., not authoritative and infinite
392 vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args;
393 clib_memset (map_args, 0, sizeof (map_args[0]));
394 gid_address_copy (&map_args->eid, &eid);
395 map_args->action = action;
396 map_args->is_static = 1;
397 map_args->authoritative = 0;
399 rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL);
402 rv = vnet_lisp_del_mapping (&eid, NULL);
405 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
409 unformat_free (line_input);
413 VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) = {
414 .path = "lisp remote-mapping",
415 .short_help = "lisp remote-mapping add|del [del-all] vni <vni> "
416 "eid <est-eid> [action <no-action|natively-forward|"
417 "send-map-request|drop>] rloc <dst-locator> p <prio> "
418 "w <weight> [rloc <dst-locator> ... ]",
419 .function = lisp_add_del_remote_mapping_command_fn,
423 * Handler for add/del adjacency CLI.
425 static clib_error_t *
426 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
427 vlib_cli_command_t * cmd)
429 clib_error_t *error = 0;
430 unformat_input_t _line_input, *line_input = &_line_input;
431 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
433 ip_prefix_t *reid_ippref, *leid_ippref;
434 gid_address_t leid, reid;
435 u8 *dmac = gid_address_mac (&reid);
436 u8 *smac = gid_address_mac (&leid);
437 u8 reid_set = 0, leid_set = 0;
440 /* Get a line of input. */
441 if (!unformat_user (input, unformat_line_input, line_input))
444 clib_memset (&reid, 0, sizeof (reid));
445 clib_memset (&leid, 0, sizeof (leid));
447 leid_ippref = &gid_address_ippref (&leid);
448 reid_ippref = &gid_address_ippref (&reid);
450 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
452 if (unformat (line_input, "del"))
454 else if (unformat (line_input, "add"))
456 else if (unformat (line_input, "reid %U",
457 unformat_ip_prefix, reid_ippref))
459 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
462 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
464 gid_address_type (&reid) = GID_ADDR_MAC;
467 else if (unformat (line_input, "vni %u", &vni))
469 gid_address_vni (&leid) = vni;
470 gid_address_vni (&reid) = vni;
472 else if (unformat (line_input, "leid %U",
473 unformat_ip_prefix, leid_ippref))
475 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
478 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
480 gid_address_type (&leid) = GID_ADDR_MAC;
485 clib_warning ("parse error");
490 if (!reid_set || !leid_set)
492 clib_warning ("missing remote or local eid!");
496 if ((gid_address_type (&leid) != gid_address_type (&reid))
497 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
498 && ip_prefix_version (reid_ippref)
499 != ip_prefix_version (leid_ippref)))
501 clib_warning ("remote and local EIDs are of different types!");
505 clib_memset (a, 0, sizeof (a[0]));
506 gid_address_copy (&a->leid, &leid);
507 gid_address_copy (&a->reid, &reid);
510 if (vnet_lisp_add_del_adjacency (a))
511 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
514 unformat_free (line_input);
518 VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = {
519 .path = "lisp adjacency",
520 .short_help = "lisp adjacency add|del vni <vni> reid <remote-eid> "
522 .function = lisp_add_del_adjacency_command_fn,
526 static clib_error_t *
527 lisp_map_request_mode_command_fn (vlib_main_t * vm,
528 unformat_input_t * input,
529 vlib_cli_command_t * cmd)
531 unformat_input_t _i, *i = &_i;
532 map_request_mode_t mr_mode = _MR_MODE_MAX;
533 clib_error_t *error = NULL;
535 /* Get a line of input. */
536 if (!unformat_user (input, unformat_line_input, i))
539 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
541 if (unformat (i, "dst-only"))
542 mr_mode = MR_MODE_DST_ONLY;
543 else if (unformat (i, "src-dst"))
544 mr_mode = MR_MODE_SRC_DST;
547 clib_warning ("parse error '%U'", format_unformat_error, i);
552 if (_MR_MODE_MAX == mr_mode)
554 clib_warning ("No LISP map request mode entered!");
558 vnet_lisp_set_map_request_mode (mr_mode);
566 VLIB_CLI_COMMAND (lisp_map_request_mode_command) = {
567 .path = "lisp map-request mode",
568 .short_help = "lisp map-request mode dst-only|src-dst",
569 .function = lisp_map_request_mode_command_fn,
574 format_lisp_map_request_mode (u8 * s, va_list * args)
576 u32 mode = va_arg (*args, u32);
581 return format (0, "dst-only");
583 return format (0, "src-dst");
588 static clib_error_t *
589 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
590 unformat_input_t * input,
591 vlib_cli_command_t * cmd)
593 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
594 vnet_lisp_get_map_request_mode ());
598 VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = {
599 .path = "show lisp map-request mode",
600 .short_help = "show lisp map-request mode",
601 .function = lisp_show_map_request_mode_command_fn,
604 static clib_error_t *
605 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
606 unformat_input_t * input,
607 vlib_cli_command_t * cmd)
610 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
612 vec_foreach (mr, lcm->map_resolvers)
614 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
619 VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = {
620 .path = "show lisp map-resolvers",
621 .short_help = "show lisp map-resolvers",
622 .function = lisp_show_map_resolvers_command_fn,
626 static clib_error_t *
627 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
628 unformat_input_t * input,
629 vlib_cli_command_t * cmd)
631 u8 locator_name_set = 0;
632 u8 *locator_set_name = 0;
634 unformat_input_t _line_input, *line_input = &_line_input;
635 clib_error_t *error = 0;
638 /* Get a line of input. */
639 if (!unformat_user (input, unformat_line_input, line_input))
642 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
644 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
645 locator_name_set = 1;
646 else if (unformat (line_input, "disable"))
650 error = clib_error_return (0, "parse error");
655 if (!locator_name_set)
657 clib_warning ("No locator set specified!");
660 vec_terminate_c_string (locator_set_name);
661 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
664 error = clib_error_return (0, "failed to %s pitr!",
665 is_add ? "add" : "delete");
669 if (locator_set_name)
670 vec_free (locator_set_name);
671 unformat_free (line_input);
676 VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = {
678 .short_help = "lisp pitr [disable] ls <locator-set-name>",
679 .function = lisp_pitr_set_locator_set_command_fn,
682 static clib_error_t *
683 lisp_show_pitr_command_fn (vlib_main_t * vm,
684 unformat_input_t * input, vlib_cli_command_t * cmd)
686 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
690 u8 status = lcm->flags & LISP_FLAG_PITR_MODE;
692 vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : "");
696 vlib_cli_output (vm, "%=20s", "disable");
700 if (~0 == lcm->pitr_map_index)
702 tmp_str = format (0, "N/A");
706 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
707 if (~0 != m->locator_set_index)
710 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
711 tmp_str = format (0, "%s", ls->name);
715 tmp_str = format (0, "N/A");
718 vec_add1 (tmp_str, 0);
720 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
727 VLIB_CLI_COMMAND (lisp_show_pitr_command) = {
728 .path = "show lisp pitr",
729 .short_help = "Show pitr",
730 .function = lisp_show_pitr_command_fn,
734 format_eid_entry (u8 * s, va_list * args)
736 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
737 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
738 mapping_t *mapit = va_arg (*args, mapping_t *);
739 locator_set_t *ls = va_arg (*args, locator_set_t *);
740 gid_address_t *gid = &mapit->eid;
741 u32 ttl = mapit->ttl;
742 u8 aut = mapit->authoritative;
747 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
748 : format (0, "remote");
750 if (vec_len (ls->locator_indices) == 0)
752 s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
757 vec_foreach (loc_index, ls->locator_indices)
759 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
761 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
764 loc = format (0, "%U", format_ip_address,
765 &gid_address_ip (&l->address));
769 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
770 gid, type, loc, ttl, aut);
774 s = format (s, "%55s%v\n", "", loc);
780 static clib_error_t *
781 lisp_show_eid_table_command_fn (vlib_main_t * vm,
782 unformat_input_t * input,
783 vlib_cli_command_t * cmd)
785 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
787 unformat_input_t _line_input, *line_input = &_line_input;
792 clib_error_t *error = NULL;
794 clib_memset (&eid, 0, sizeof (eid));
796 /* Get a line of input. */
797 if (!unformat_user (input, unformat_line_input, line_input))
800 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
802 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
804 else if (unformat (line_input, "local"))
806 else if (unformat (line_input, "remote"))
810 error = clib_error_return (0, "parse error: '%U'",
811 format_unformat_error, line_input);
816 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
817 "EID", "type", "locators", "ttl", "authoritative");
821 pool_foreach (mapit, lcm->mapping_pool)
826 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
827 mapit->locator_set_index);
828 if (filter && !((1 == filter && ls->local) ||
829 (2 == filter && !ls->local)))
833 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
839 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
843 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
844 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
845 mapit->locator_set_index);
847 if (filter && !((1 == filter && ls->local) ||
848 (2 == filter && !ls->local)))
853 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
858 unformat_free (line_input);
863 VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = {
864 .path = "show lisp eid-table",
865 .short_help = "show lisp eid-table [local|remote|eid <eid>]",
866 .function = lisp_show_eid_table_command_fn,
870 static clib_error_t *
871 lisp_enable_command_fn (vlib_main_t * vm, unformat_input_t * input,
872 vlib_cli_command_t * cmd)
874 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
875 return clib_error_return (0, "parse error: '%U'", format_unformat_error,
878 vnet_lisp_enable_disable (1);
883 VLIB_CLI_COMMAND (lisp_cp_enable_command) = {
884 .path = "lisp enable",
885 .short_help = "lisp enable",
886 .function = lisp_enable_command_fn,
889 static clib_error_t *
890 lisp_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
891 vlib_cli_command_t * cmd)
893 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
894 return clib_error_return (0, "parse error: '%U'", format_unformat_error,
897 vnet_lisp_enable_disable (0);
902 VLIB_CLI_COMMAND (lisp_cp_disable_command) = {
903 .path = "lisp disable",
904 .short_help = "lisp disable",
905 .function = lisp_disable_command_fn,
908 static clib_error_t *
909 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
910 unformat_input_t * input,
911 vlib_cli_command_t * cmd)
913 unformat_input_t _line_input, *line_input = &_line_input;
916 clib_error_t *error = NULL;
918 /* Get a line of input. */
919 if (!unformat_user (input, unformat_line_input, line_input))
920 return clib_error_return (0, "expected enable | disable");
922 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
924 if (unformat (line_input, "enable"))
929 else if (unformat (line_input, "disable"))
933 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
941 vlib_cli_output (vm, "state not set!");
945 vnet_lisp_map_register_enable_disable (is_enabled);
948 unformat_free (line_input);
953 VLIB_CLI_COMMAND (lisp_map_register_enable_disable_command) = {
954 .path = "lisp map-register",
955 .short_help = "lisp map-register [enable|disable]",
956 .function = lisp_map_register_enable_disable_command_fn,
959 static clib_error_t *
960 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
961 unformat_input_t * input,
962 vlib_cli_command_t * cmd)
964 unformat_input_t _line_input, *line_input = &_line_input;
967 clib_error_t *error = NULL;
969 /* Get a line of input. */
970 if (!unformat_user (input, unformat_line_input, line_input))
971 return clib_error_return (0, "expected enable | disable");
973 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
975 if (unformat (line_input, "enable"))
980 else if (unformat (line_input, "disable"))
984 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
992 vlib_cli_output (vm, "state not set!");
996 vnet_lisp_rloc_probe_enable_disable (is_enabled);
999 unformat_free (line_input);
1004 VLIB_CLI_COMMAND (lisp_rloc_probe_enable_disable_command) = {
1005 .path = "lisp rloc-probe",
1006 .short_help = "lisp rloc-probe [enable|disable]",
1007 .function = lisp_rloc_probe_enable_disable_command_fn,
1011 format_lisp_status (u8 * s, va_list * args)
1013 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1014 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
1017 static clib_error_t *
1018 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
1019 vlib_cli_command_t * cmd)
1022 msg = format (msg, "feature: %U\ngpe: %U\n",
1023 format_lisp_status, format_vnet_lisp_gpe_status);
1024 vlib_cli_output (vm, "%v", msg);
1029 VLIB_CLI_COMMAND (lisp_show_status_command) = {
1030 .path = "show lisp status",
1031 .short_help = "show lisp status",
1032 .function = lisp_show_status_command_fn,
1035 static clib_error_t *
1036 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1037 unformat_input_t * input,
1038 vlib_cli_command_t * cmd)
1041 unformat_input_t _line_input, *line_input = &_line_input;
1042 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1043 uword *vni_table = 0;
1045 clib_error_t *error = NULL;
1047 /* Get a line of input. */
1048 if (!unformat_user (input, unformat_line_input, line_input))
1051 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1053 if (unformat (line_input, "l2"))
1055 vni_table = lcm->bd_id_by_vni;
1058 else if (unformat (line_input, "l3"))
1060 vni_table = lcm->table_id_by_vni;
1065 error = clib_error_return (0, "parse error: '%U'",
1066 format_unformat_error, line_input);
1073 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1077 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1079 hash_foreach_pair (p, vni_table,
1081 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1085 unformat_free (line_input);
1090 VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = {
1091 .path = "show lisp eid-table map",
1092 .short_help = "show lisp eid-table map l2|l3",
1093 .function = lisp_show_eid_table_map_command_fn,
1097 static clib_error_t *
1098 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1099 unformat_input_t * input,
1100 vlib_cli_command_t * cmd)
1102 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1103 vnet_main_t *vnm = lgm->vnet_main;
1104 unformat_input_t _line_input, *line_input = &_line_input;
1106 clib_error_t *error = 0;
1107 u8 *locator_set_name = 0;
1108 locator_t locator, *locators = 0;
1109 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1113 clib_memset (&locator, 0, sizeof (locator));
1114 clib_memset (a, 0, sizeof (a[0]));
1116 /* Get a line of input. */
1117 if (!unformat_user (input, unformat_line_input, line_input))
1118 return clib_error_return (0, "missing parameters");
1120 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1122 if (unformat (line_input, "add %_%v%_", &locator_set_name))
1124 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1126 else if (unformat (line_input, "iface %U p %d w %d",
1127 unformat_vnet_sw_interface, vnm,
1128 &locator.sw_if_index, &locator.priority,
1133 vec_add1 (locators, locator);
1137 error = unformat_parse_error (line_input);
1142 vec_terminate_c_string (locator_set_name);
1143 a->name = locator_set_name;
1144 a->locators = locators;
1148 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1151 error = clib_error_return (0, "failed to %s locator-set!",
1152 is_add ? "add" : "delete");
1156 vec_free (locators);
1157 if (locator_set_name)
1158 vec_free (locator_set_name);
1159 unformat_free (line_input);
1164 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = {
1165 .path = "lisp locator-set",
1166 .short_help = "lisp locator-set add/del <name> [iface <iface-name> "
1167 "p <priority> w <weight>]",
1168 .function = lisp_add_del_locator_set_command_fn,
1171 static clib_error_t *
1172 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1173 unformat_input_t * input,
1174 vlib_cli_command_t * cmd)
1176 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1177 vnet_main_t *vnm = lgm->vnet_main;
1178 unformat_input_t _line_input, *line_input = &_line_input;
1180 clib_error_t *error = 0;
1181 u8 *locator_set_name = 0;
1182 u8 locator_set_name_set = 0;
1183 locator_t locator, *locators = 0;
1184 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1187 clib_memset (&locator, 0, sizeof (locator));
1188 clib_memset (a, 0, sizeof (a[0]));
1190 /* Get a line of input. */
1191 if (!unformat_user (input, unformat_line_input, line_input))
1194 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1196 if (unformat (line_input, "add"))
1198 else if (unformat (line_input, "del"))
1200 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1201 locator_set_name_set = 1;
1202 else if (unformat (line_input, "iface %U p %d w %d",
1203 unformat_vnet_sw_interface, vnm,
1204 &locator.sw_if_index, &locator.priority,
1208 vec_add1 (locators, locator);
1212 error = unformat_parse_error (line_input);
1217 if (!locator_set_name_set)
1219 error = clib_error_return (0, "locator_set name not set!");
1223 a->name = locator_set_name;
1224 a->locators = locators;
1228 vnet_lisp_add_del_locator (a, 0, &ls_index);
1231 vec_free (locators);
1232 vec_free (locator_set_name);
1233 unformat_free (line_input);
1238 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = {
1239 .path = "lisp locator",
1240 .short_help = "lisp locator add/del locator-set <name> iface <iface-name> "
1241 "p <priority> w <weight>",
1242 .function = lisp_add_del_locator_in_set_command_fn,
1245 static clib_error_t *
1246 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1247 unformat_input_t * input,
1248 vlib_cli_command_t * cmd)
1250 locator_set_t *lsit;
1253 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1255 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1256 "Priority", "Weight");
1258 pool_foreach (lsit, lcm->locator_set_pool)
1264 msg = format (msg, "%v", lsit->name);
1268 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1270 vec_foreach (locit, lsit->locator_indices)
1274 msg = format (msg, "%16s", " ");
1276 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1278 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1281 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1282 &gid_address_ip(&loc->address), loc->priority,
1286 vlib_cli_output (vm, "%v", msg);
1292 VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = {
1293 .path = "show lisp locator-set",
1294 .short_help = "Shows locator-sets",
1295 .function = lisp_cp_show_locator_sets_command_fn,
1299 static clib_error_t *
1300 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1301 unformat_input_t * input,
1302 vlib_cli_command_t * cmd)
1304 unformat_input_t _line_input, *line_input = &_line_input;
1305 u8 is_add = 1, addr_set = 0;
1306 ip_address_t ip_addr;
1307 clib_error_t *error = 0;
1309 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1311 /* Get a line of input. */
1312 if (!unformat_user (input, unformat_line_input, line_input))
1315 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1317 if (unformat (line_input, "add"))
1319 else if (unformat (line_input, "del"))
1321 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1325 error = unformat_parse_error (line_input);
1332 error = clib_error_return (0, "Map-resolver address must be set!");
1337 a->address = ip_addr;
1338 rv = vnet_lisp_add_del_map_resolver (a);
1341 error = clib_error_return (0, "failed to %s map-resolver!",
1342 is_add ? "add" : "delete");
1346 unformat_free (line_input);
1351 VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = {
1352 .path = "lisp map-resolver",
1353 .short_help = "lisp map-resolver add/del <ip_address>",
1354 .function = lisp_add_del_map_resolver_command_fn,
1358 static clib_error_t *
1359 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1360 unformat_input_t * input,
1361 vlib_cli_command_t * cmd)
1363 unformat_input_t _line_input, *line_input = &_line_input;
1365 u8 *locator_set_name = 0;
1366 clib_error_t *error = 0;
1368 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1370 /* Get a line of input. */
1371 if (!unformat_user (input, unformat_line_input, line_input))
1374 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1376 if (unformat (line_input, "del"))
1378 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1382 error = unformat_parse_error (line_input);
1387 vec_terminate_c_string (locator_set_name);
1389 a->locator_set_name = locator_set_name;
1390 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1393 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1394 is_add ? "add" : "delete");
1398 vec_free (locator_set_name);
1399 unformat_free (line_input);
1404 VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = {
1405 .path = "lisp map-request itr-rlocs",
1406 .short_help = "lisp map-request itr-rlocs add/del <locator_set_name>",
1407 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
1410 static clib_error_t *
1411 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1412 unformat_input_t * input,
1413 vlib_cli_command_t * cmd)
1415 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1416 locator_set_t *loc_set;
1418 vlib_cli_output (vm, "%=20s", "itr-rlocs");
1420 if (~0 == lcm->mreq_itr_rlocs)
1425 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1427 vlib_cli_output (vm, "%=20s", loc_set->name);
1432 VLIB_CLI_COMMAND (lisp_show_map_request_command) = {
1433 .path = "show lisp map-request itr-rlocs",
1434 .short_help = "Shows map-request itr-rlocs",
1435 .function = lisp_show_mreq_itr_rlocs_command_fn,
1438 static clib_error_t *
1439 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
1440 unformat_input_t * input,
1441 vlib_cli_command_t * cmd)
1443 u8 is_add = 1, ip_set = 0;
1444 unformat_input_t _line_input, *line_input = &_line_input;
1445 clib_error_t *error = 0;
1448 /* Get a line of input. */
1449 if (!unformat_user (input, unformat_line_input, line_input))
1452 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1454 if (unformat (line_input, "%U", unformat_ip_address, &ip))
1456 else if (unformat (line_input, "disable"))
1460 error = clib_error_return (0, "parse error");
1467 clib_warning ("No petr IP specified!");
1471 if (vnet_lisp_use_petr (&ip, is_add))
1473 error = clib_error_return (0, "failed to %s petr!",
1474 is_add ? "add" : "delete");
1478 unformat_free (line_input);
1483 VLIB_CLI_COMMAND (lisp_use_petr_set_locator_set_command) = {
1484 .path = "lisp use-petr",
1485 .short_help = "lisp use-petr [disable] <petr-ip>",
1486 .function = lisp_use_petr_set_locator_set_command_fn,
1489 static clib_error_t *
1490 lisp_show_petr_command_fn (vlib_main_t * vm,
1491 unformat_input_t * input, vlib_cli_command_t * cmd)
1493 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1498 u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
1499 vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
1503 vlib_cli_output (vm, "%=20s", "disable");
1507 if (~0 == lcm->petr_map_index)
1509 tmp_str = format (0, "N/A");
1513 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1514 if (~0 != m->locator_set_index)
1516 ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
1517 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
1518 tmp_str = format (0, "%U", format_ip_address, &loc->address);
1522 tmp_str = format (0, "N/A");
1525 vec_add1 (tmp_str, 0);
1527 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1534 VLIB_CLI_COMMAND (lisp_show_petr_command) = {
1535 .path = "show lisp petr",
1536 .short_help = "Show petr",
1537 .function = lisp_show_petr_command_fn,
1541 * fd.io coding-style-patch-verification: ON
1544 * eval: (c-set-style "gnu")