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;
29 /* Get a line of input. */
30 if (!unformat_user (input, unformat_line_input, line_input))
33 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
35 if (unformat (line_input, "vni %d", &vni))
39 vlib_cli_output (vm, "parse error: '%U'",
40 format_unformat_error, line_input);
47 vlib_cli_output (vm, "error: no vni specified!");
51 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
53 vec_foreach (adj, adjs)
55 vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid,
56 format_gid_address, &adj->reid);
64 VLIB_CLI_COMMAND (lisp_show_adjacencies_command) = {
65 .path = "show lisp adjacencies",
66 .short_help = "show lisp adjacencies",
67 .function = lisp_show_adjacencies_command_fn,
72 lisp_add_del_map_server_command_fn (vlib_main_t * vm,
73 unformat_input_t * input,
74 vlib_cli_command_t * cmd)
77 u8 is_add = 1, ip_set = 0;
79 unformat_input_t _line_input, *line_input = &_line_input;
81 /* Get a line of input. */
82 if (!unformat_user (input, unformat_line_input, line_input))
85 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
87 if (unformat (line_input, "add"))
89 else if (unformat (line_input, "del"))
91 else if (unformat (line_input, "%U", unformat_ip_address, &ip))
95 vlib_cli_output (vm, "parse error: '%U'",
96 format_unformat_error, line_input);
103 vlib_cli_output (vm, "map-server ip address not set!");
107 rv = vnet_lisp_add_del_map_server (&ip, is_add);
109 vlib_cli_output (vm, "failed to %s map-server!",
110 is_add ? "add" : "delete");
116 VLIB_CLI_COMMAND (lisp_add_del_map_server_command) = {
117 .path = "lisp map-server",
118 .short_help = "lisp map-server add|del <ip>",
119 .function = lisp_add_del_map_server_command_fn,
124 static clib_error_t *
125 lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
126 vlib_cli_command_t * cmd)
128 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
129 unformat_input_t _line_input, *line_input = &_line_input;
132 gid_address_t *eids = 0;
133 clib_error_t *error = 0;
134 u8 *locator_set_name = 0;
135 u32 locator_set_index = 0, map_index = 0;
137 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
143 memset (&eid, 0, sizeof (eid));
144 memset (a, 0, sizeof (*a));
146 /* Get a line of input. */
147 if (!unformat_user (input, unformat_line_input, line_input))
150 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
152 if (unformat (line_input, "add"))
154 else if (unformat (line_input, "del"))
156 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
158 else if (unformat (line_input, "vni %d", &vni))
159 gid_address_vni (&eid) = vni;
160 else if (unformat (line_input, "secret-key %_%v%_", &key))
162 else if (unformat (line_input, "key-id %U", unformat_hmac_key_id,
165 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
167 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
170 error = clib_error_return (0, "locator-set %s doesn't exist",
174 locator_set_index = p[0];
178 error = unformat_parse_error (line_input);
182 /* XXX treat batch configuration */
184 if (GID_ADDR_SRC_DST == gid_address_type (&eid))
187 clib_error_return (0, "src/dst is not supported for local EIDs!");
191 if (key && (0 == key_id))
193 vlib_cli_output (vm, "invalid key_id!");
197 gid_address_copy (&a->eid, &eid);
199 a->locator_set_index = locator_set_index;
204 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
207 error = clib_error_return (0, "failed to %s local mapping!",
208 is_add ? "add" : "delete");
212 if (locator_set_name)
213 vec_free (locator_set_name);
214 gid_address_free (&a->eid);
220 VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = {
221 .path = "lisp eid-table",
222 .short_help = "lisp eid-table add/del [vni <vni>] eid <eid> "
223 "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]",
224 .function = lisp_add_del_local_eid_command_fn,
228 static clib_error_t *
229 lisp_eid_table_map_command_fn (vlib_main_t * vm,
230 unformat_input_t * input,
231 vlib_cli_command_t * cmd)
233 u8 is_add = 1, is_l2 = 0;
234 u32 vni = 0, dp_id = 0;
235 unformat_input_t _line_input, *line_input = &_line_input;
237 /* Get a line of input. */
238 if (!unformat_user (input, unformat_line_input, line_input))
241 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
243 if (unformat (line_input, "del"))
245 else if (unformat (line_input, "vni %d", &vni))
247 else if (unformat (line_input, "vrf %d", &dp_id))
249 else if (unformat (line_input, "bd %d", &dp_id))
253 return unformat_parse_error (line_input);
256 vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
261 VLIB_CLI_COMMAND (lisp_eid_table_map_command) = {
262 .path = "lisp eid-table map",
263 .short_help = "lisp eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
264 .function = lisp_eid_table_map_command_fn,
269 * Handler for add/del remote mapping CLI.
271 * @param vm vlib context
272 * @param input input from user
274 * @return pointer to clib error structure
276 static clib_error_t *
277 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
278 unformat_input_t * input,
279 vlib_cli_command_t * cmd)
281 clib_error_t *error = 0;
282 unformat_input_t _line_input, *line_input = &_line_input;
283 u8 is_add = 1, del_all = 0;
284 locator_t rloc, *rlocs = 0, *curr_rloc = 0;
287 u32 vni, action = ~0, p, w;
290 /* Get a line of input. */
291 if (!unformat_user (input, unformat_line_input, line_input))
294 memset (&eid, 0, sizeof (eid));
295 memset (&rloc, 0, sizeof (rloc));
297 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
299 if (unformat (line_input, "del-all"))
301 else if (unformat (line_input, "del"))
303 else if (unformat (line_input, "add"))
305 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
307 else if (unformat (line_input, "vni %u", &vni))
309 gid_address_vni (&eid) = vni;
311 else if (unformat (line_input, "p %d w %d", &p, &w))
316 ("No RLOC configured for setting priority/weight!");
319 curr_rloc->priority = p;
320 curr_rloc->weight = w;
322 else if (unformat (line_input, "rloc %U", unformat_ip_address,
323 &gid_address_ip (&rloc.address)))
325 /* since rloc is stored in ip prefix we need to set prefix length */
326 ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
328 u8 version = gid_address_ip_version (&rloc.address);
329 ip_prefix_len (pref) = ip_address_max_len (version);
331 vec_add1 (rlocs, rloc);
332 curr_rloc = &rlocs[vec_len (rlocs) - 1];
334 else if (unformat (line_input, "action %U",
335 unformat_negative_mapping_action, &action))
339 clib_warning ("parse error");
346 clib_warning ("missing eid!");
352 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
354 clib_warning ("no action set for negative map-reply!");
360 vnet_lisp_clear_all_remote_adjacencies ();
364 /* TODO build src/dst with seid */
366 /* if it's a delete, clean forwarding */
369 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
370 memset (a, 0, sizeof (a[0]));
371 gid_address_copy (&a->reid, &eid);
372 if (vnet_lisp_add_del_adjacency (a))
374 clib_warning ("failed to delete adjacency!");
379 /* add as static remote mapping, i.e., not authoritative and infinite
381 rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add,
382 1 /* is_static */ , 0);
385 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
389 unformat_free (line_input);
393 VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) =
395 .path = "lisp remote-mapping",.short_help =
396 "lisp remote-mapping add|del [del-all] vni <vni> "
397 "eid <est-eid> [action <no-action|natively-forward|"
398 "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
399 "[rloc <dst-locator> ... ]",.function =
400 lisp_add_del_remote_mapping_command_fn,};
403 * Handler for add/del adjacency CLI.
405 static clib_error_t *
406 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
407 vlib_cli_command_t * cmd)
409 clib_error_t *error = 0;
410 unformat_input_t _line_input, *line_input = &_line_input;
411 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
413 ip_prefix_t *reid_ippref, *leid_ippref;
414 gid_address_t leid, reid;
415 u8 *dmac = gid_address_mac (&reid);
416 u8 *smac = gid_address_mac (&leid);
417 u8 reid_set = 0, leid_set = 0;
420 /* Get a line of input. */
421 if (!unformat_user (input, unformat_line_input, line_input))
424 memset (&reid, 0, sizeof (reid));
425 memset (&leid, 0, sizeof (leid));
427 leid_ippref = &gid_address_ippref (&leid);
428 reid_ippref = &gid_address_ippref (&reid);
430 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
432 if (unformat (line_input, "del"))
434 else if (unformat (line_input, "add"))
436 else if (unformat (line_input, "reid %U",
437 unformat_ip_prefix, reid_ippref))
439 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
442 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
444 gid_address_type (&reid) = GID_ADDR_MAC;
447 else if (unformat (line_input, "vni %u", &vni))
449 gid_address_vni (&leid) = vni;
450 gid_address_vni (&reid) = vni;
452 else if (unformat (line_input, "leid %U",
453 unformat_ip_prefix, leid_ippref))
455 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
458 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
460 gid_address_type (&leid) = GID_ADDR_MAC;
465 clib_warning ("parse error");
470 if (!reid_set || !leid_set)
472 clib_warning ("missing remote or local eid!");
476 if ((gid_address_type (&leid) != gid_address_type (&reid))
477 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
478 && ip_prefix_version (reid_ippref)
479 != ip_prefix_version (leid_ippref)))
481 clib_warning ("remote and local EIDs are of different types!");
485 memset (a, 0, sizeof (a[0]));
486 gid_address_copy (&a->leid, &leid);
487 gid_address_copy (&a->reid, &reid);
490 if (vnet_lisp_add_del_adjacency (a))
491 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
494 unformat_free (line_input);
499 VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = {
500 .path = "lisp adjacency",
501 .short_help = "lisp adjacency add|del vni <vni> reid <remote-eid> "
503 .function = lisp_add_del_adjacency_command_fn,
508 static clib_error_t *
509 lisp_map_request_mode_command_fn (vlib_main_t * vm,
510 unformat_input_t * input,
511 vlib_cli_command_t * cmd)
513 unformat_input_t _i, *i = &_i;
514 map_request_mode_t mr_mode = _MR_MODE_MAX;
516 /* Get a line of input. */
517 if (!unformat_user (input, unformat_line_input, i))
520 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
522 if (unformat (i, "dst-only"))
523 mr_mode = MR_MODE_DST_ONLY;
524 else if (unformat (i, "src-dst"))
525 mr_mode = MR_MODE_SRC_DST;
528 clib_warning ("parse error '%U'", format_unformat_error, i);
533 if (_MR_MODE_MAX == mr_mode)
535 clib_warning ("No LISP map request mode entered!");
539 vnet_lisp_set_map_request_mode (mr_mode);
545 VLIB_CLI_COMMAND (lisp_map_request_mode_command) = {
546 .path = "lisp map-request mode",
547 .short_help = "lisp map-request mode dst-only|src-dst",
548 .function = lisp_map_request_mode_command_fn,
554 format_lisp_map_request_mode (u8 * s, va_list * args)
556 u32 mode = va_arg (*args, u32);
561 return format (0, "dst-only");
563 return format (0, "src-dst");
568 static clib_error_t *
569 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
570 unformat_input_t * input,
571 vlib_cli_command_t * cmd)
573 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
574 vnet_lisp_get_map_request_mode ());
579 VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = {
580 .path = "show lisp map-request mode",
581 .short_help = "show lisp map-request mode",
582 .function = lisp_show_map_request_mode_command_fn,
586 static clib_error_t *
587 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
588 unformat_input_t * input,
589 vlib_cli_command_t * cmd)
592 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
594 vec_foreach (mr, lcm->map_resolvers)
596 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
602 VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = {
603 .path = "show lisp map-resolvers",
604 .short_help = "show lisp map-resolvers",
605 .function = lisp_show_map_resolvers_command_fn,
610 static clib_error_t *
611 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
612 unformat_input_t * input,
613 vlib_cli_command_t * cmd)
615 u8 locator_name_set = 0;
616 u8 *locator_set_name = 0;
618 unformat_input_t _line_input, *line_input = &_line_input;
619 clib_error_t *error = 0;
622 /* Get a line of input. */
623 if (!unformat_user (input, unformat_line_input, line_input))
626 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
628 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
629 locator_name_set = 1;
630 else if (unformat (line_input, "disable"))
633 return clib_error_return (0, "parse error");
636 if (!locator_name_set)
638 clib_warning ("No locator set specified!");
641 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
644 error = clib_error_return (0, "failed to %s pitr!",
645 is_add ? "add" : "delete");
649 if (locator_set_name)
650 vec_free (locator_set_name);
655 VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = {
657 .short_help = "lisp pitr [disable] ls <locator-set-name>",
658 .function = lisp_pitr_set_locator_set_command_fn,
662 static clib_error_t *
663 lisp_show_pitr_command_fn (vlib_main_t * vm,
664 unformat_input_t * input, vlib_cli_command_t * cmd)
666 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
671 vlib_cli_output (vm, "%=20s%=16s",
672 "pitr", lcm->lisp_pitr ? "locator-set" : "");
676 vlib_cli_output (vm, "%=20s", "disable");
680 if (~0 == lcm->pitr_map_index)
682 tmp_str = format (0, "N/A");
686 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
687 if (~0 != m->locator_set_index)
690 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
691 tmp_str = format (0, "%s", ls->name);
695 tmp_str = format (0, "N/A");
698 vec_add1 (tmp_str, 0);
700 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
708 VLIB_CLI_COMMAND (lisp_show_pitr_command) = {
709 .path = "show lisp pitr",
710 .short_help = "Show pitr",
711 .function = lisp_show_pitr_command_fn,
716 format_eid_entry (u8 * s, va_list * args)
718 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
719 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
720 mapping_t *mapit = va_arg (*args, mapping_t *);
721 locator_set_t *ls = va_arg (*args, locator_set_t *);
722 gid_address_t *gid = &mapit->eid;
723 u32 ttl = mapit->ttl;
724 u8 aut = mapit->authoritative;
729 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
730 : format (0, "remote");
732 if (vec_len (ls->locator_indices) == 0)
734 s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
739 vec_foreach (loc_index, ls->locator_indices)
741 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
743 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
746 loc = format (0, "%U", format_ip_address,
747 &gid_address_ip (&l->address));
751 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
752 gid, type, loc, ttl, aut);
756 s = format (s, "%55s%v\n", "", loc);
762 static clib_error_t *
763 lisp_show_eid_table_command_fn (vlib_main_t * vm,
764 unformat_input_t * input,
765 vlib_cli_command_t * cmd)
767 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
769 unformat_input_t _line_input, *line_input = &_line_input;
775 memset (&eid, 0, sizeof (eid));
777 /* Get a line of input. */
778 if (!unformat_user (input, unformat_line_input, line_input))
781 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
783 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
785 else if (unformat (line_input, "local"))
787 else if (unformat (line_input, "remote"))
790 return clib_error_return (0, "parse error: '%U'",
791 format_unformat_error, line_input);
794 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
795 "EID", "type", "locators", "ttl", "autoritative");
800 pool_foreach (mapit, lcm->mapping_pool,
802 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
803 mapit->locator_set_index);
804 if (filter && !((1 == filter && ls->local) ||
805 (2 == filter && !ls->local)))
809 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
816 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
820 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
821 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
822 mapit->locator_set_index);
824 if (filter && !((1 == filter && ls->local) ||
825 (2 == filter && !ls->local)))
830 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
838 VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = {
839 .path = "show lisp eid-table",
840 .short_help = "Shows EID table",
841 .function = lisp_show_eid_table_command_fn,
846 static clib_error_t *
847 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
848 vlib_cli_command_t * cmd)
850 unformat_input_t _line_input, *line_input = &_line_input;
854 /* Get a line of input. */
855 if (!unformat_user (input, unformat_line_input, line_input))
858 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
860 if (unformat (line_input, "enable"))
865 else if (unformat (line_input, "disable"))
869 return clib_error_return (0, "parse error: '%U'",
870 format_unformat_error, line_input);
875 return clib_error_return (0, "state not set");
877 vnet_lisp_enable_disable (is_enabled);
882 VLIB_CLI_COMMAND (lisp_cp_enable_disable_command) = {
884 .short_help = "lisp [enable|disable]",
885 .function = lisp_enable_disable_command_fn,
889 static clib_error_t *
890 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
891 unformat_input_t * input,
892 vlib_cli_command_t * cmd)
894 unformat_input_t _line_input, *line_input = &_line_input;
898 /* Get a line of input. */
899 if (!unformat_user (input, unformat_line_input, line_input))
902 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
904 if (unformat (line_input, "enable"))
909 else if (unformat (line_input, "disable"))
913 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
921 vlib_cli_output (vm, "state not set!");
925 vnet_lisp_map_register_enable_disable (is_enabled);
930 VLIB_CLI_COMMAND (lisp_map_register_enable_disable_command) = {
931 .path = "lisp map-register",
932 .short_help = "lisp map-register [enable|disable]",
933 .function = lisp_map_register_enable_disable_command_fn,
937 static clib_error_t *
938 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
939 unformat_input_t * input,
940 vlib_cli_command_t * cmd)
942 unformat_input_t _line_input, *line_input = &_line_input;
946 /* Get a line of input. */
947 if (!unformat_user (input, unformat_line_input, line_input))
950 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
952 if (unformat (line_input, "enable"))
957 else if (unformat (line_input, "disable"))
961 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
969 vlib_cli_output (vm, "state not set!");
973 vnet_lisp_rloc_probe_enable_disable (is_enabled);
978 VLIB_CLI_COMMAND (lisp_rloc_probe_enable_disable_command) = {
979 .path = "lisp rloc-probe",
980 .short_help = "lisp rloc-probe [enable|disable]",
981 .function = lisp_rloc_probe_enable_disable_command_fn,
986 format_lisp_status (u8 * s, va_list * args)
988 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
989 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
992 static clib_error_t *
993 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
994 vlib_cli_command_t * cmd)
997 msg = format (msg, "feature: %U\ngpe: %U\n",
998 format_lisp_status, format_vnet_lisp_gpe_status);
999 vlib_cli_output (vm, "%v", msg);
1005 VLIB_CLI_COMMAND (lisp_show_status_command) = {
1006 .path = "show lisp status",
1007 .short_help = "show lisp status",
1008 .function = lisp_show_status_command_fn,
1012 static clib_error_t *
1013 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1014 unformat_input_t * input,
1015 vlib_cli_command_t * cmd)
1018 unformat_input_t _line_input, *line_input = &_line_input;
1019 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1020 uword *vni_table = 0;
1023 /* Get a line of input. */
1024 if (!unformat_user (input, unformat_line_input, line_input))
1027 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1029 if (unformat (line_input, "l2"))
1031 vni_table = lcm->bd_id_by_vni;
1034 else if (unformat (line_input, "l3"))
1036 vni_table = lcm->table_id_by_vni;
1040 return clib_error_return (0, "parse error: '%U'",
1041 format_unformat_error, line_input);
1046 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1050 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1053 hash_foreach_pair (p, vni_table,
1055 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1063 VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = {
1064 .path = "show lisp eid-table map",
1065 .short_help = "show lisp eid-table l2|l3",
1066 .function = lisp_show_eid_table_map_command_fn,
1071 static clib_error_t *
1072 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1073 unformat_input_t * input,
1074 vlib_cli_command_t * cmd)
1076 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1077 vnet_main_t *vnm = lgm->vnet_main;
1078 unformat_input_t _line_input, *line_input = &_line_input;
1080 clib_error_t *error = 0;
1081 u8 *locator_set_name = 0;
1082 locator_t locator, *locators = 0;
1083 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1087 memset (&locator, 0, sizeof (locator));
1088 memset (a, 0, sizeof (a[0]));
1090 /* Get a line of input. */
1091 if (!unformat_user (input, unformat_line_input, line_input))
1094 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1096 if (unformat (line_input, "add %_%v%_", &locator_set_name))
1098 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1100 else if (unformat (line_input, "iface %U p %d w %d",
1101 unformat_vnet_sw_interface, vnm,
1102 &locator.sw_if_index, &locator.priority,
1106 vec_add1 (locators, locator);
1110 error = unformat_parse_error (line_input);
1115 a->name = locator_set_name;
1116 a->locators = locators;
1120 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1123 error = clib_error_return (0, "failed to %s locator-set!",
1124 is_add ? "add" : "delete");
1128 vec_free (locators);
1129 if (locator_set_name)
1130 vec_free (locator_set_name);
1135 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = {
1136 .path = "lisp locator-set",
1137 .short_help = "lisp locator-set add/del <name> [iface <iface-name> "
1138 "p <priority> w <weight>]",
1139 .function = lisp_add_del_locator_set_command_fn,
1143 static clib_error_t *
1144 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1145 unformat_input_t * input,
1146 vlib_cli_command_t * cmd)
1148 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1149 vnet_main_t *vnm = lgm->vnet_main;
1150 unformat_input_t _line_input, *line_input = &_line_input;
1152 clib_error_t *error = 0;
1153 u8 *locator_set_name = 0;
1154 u8 locator_set_name_set = 0;
1155 locator_t locator, *locators = 0;
1156 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1159 memset (&locator, 0, sizeof (locator));
1160 memset (a, 0, sizeof (a[0]));
1162 /* Get a line of input. */
1163 if (!unformat_user (input, unformat_line_input, line_input))
1166 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1168 if (unformat (line_input, "add"))
1170 else if (unformat (line_input, "del"))
1172 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1173 locator_set_name_set = 1;
1174 else if (unformat (line_input, "iface %U p %d w %d",
1175 unformat_vnet_sw_interface, vnm,
1176 &locator.sw_if_index, &locator.priority,
1180 vec_add1 (locators, locator);
1184 error = unformat_parse_error (line_input);
1189 if (!locator_set_name_set)
1191 error = clib_error_return (0, "locator_set name not set!");
1195 a->name = locator_set_name;
1196 a->locators = locators;
1200 vnet_lisp_add_del_locator (a, 0, &ls_index);
1203 vec_free (locators);
1204 vec_free (locator_set_name);
1209 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = {
1210 .path = "lisp locator",
1211 .short_help = "lisp locator add/del locator-set <name> iface <iface-name> "
1212 "p <priority> w <weight>",
1213 .function = lisp_add_del_locator_in_set_command_fn,
1217 static clib_error_t *
1218 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1219 unformat_input_t * input,
1220 vlib_cli_command_t * cmd)
1222 locator_set_t *lsit;
1225 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1227 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1228 "Priority", "Weight");
1231 pool_foreach (lsit, lcm->locator_set_pool,
1237 msg = format (msg, "%v", lsit->name);
1241 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1243 vec_foreach (locit, lsit->locator_indices)
1247 msg = format (msg, "%16s", " ");
1249 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1251 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1254 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1255 &gid_address_ip(&loc->address), loc->priority,
1259 vlib_cli_output (vm, "%v", msg);
1267 VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = {
1268 .path = "show lisp locator-set",
1269 .short_help = "Shows locator-sets",
1270 .function = lisp_cp_show_locator_sets_command_fn,
1275 static clib_error_t *
1276 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1277 unformat_input_t * input,
1278 vlib_cli_command_t * cmd)
1280 unformat_input_t _line_input, *line_input = &_line_input;
1281 u8 is_add = 1, addr_set = 0;
1282 ip_address_t ip_addr;
1283 clib_error_t *error = 0;
1285 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1287 /* Get a line of input. */
1288 if (!unformat_user (input, unformat_line_input, line_input))
1291 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1293 if (unformat (line_input, "add"))
1295 else if (unformat (line_input, "del"))
1297 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1301 error = unformat_parse_error (line_input);
1308 error = clib_error_return (0, "Map-resolver address must be set!");
1313 a->address = ip_addr;
1314 rv = vnet_lisp_add_del_map_resolver (a);
1317 error = clib_error_return (0, "failed to %s map-resolver!",
1318 is_add ? "add" : "delete");
1326 VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = {
1327 .path = "lisp map-resolver",
1328 .short_help = "lisp map-resolver add/del <ip_address>",
1329 .function = lisp_add_del_map_resolver_command_fn,
1334 static clib_error_t *
1335 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1336 unformat_input_t * input,
1337 vlib_cli_command_t * cmd)
1339 unformat_input_t _line_input, *line_input = &_line_input;
1341 u8 *locator_set_name = 0;
1342 clib_error_t *error = 0;
1344 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1346 /* Get a line of input. */
1347 if (!unformat_user (input, unformat_line_input, line_input))
1350 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1352 if (unformat (line_input, "del"))
1354 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1358 error = unformat_parse_error (line_input);
1364 a->locator_set_name = locator_set_name;
1365 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1368 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1369 is_add ? "add" : "delete");
1372 vec_free (locator_set_name);
1380 VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = {
1381 .path = "lisp map-request itr-rlocs",
1382 .short_help = "lisp map-request itr-rlocs add/del <locator_set_name>",
1383 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
1387 static clib_error_t *
1388 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1389 unformat_input_t * input,
1390 vlib_cli_command_t * cmd)
1392 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1393 locator_set_t *loc_set;
1395 vlib_cli_output (vm, "%=20s", "itr-rlocs");
1397 if (~0 == lcm->mreq_itr_rlocs)
1402 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1404 vlib_cli_output (vm, "%=20s", loc_set->name);
1410 VLIB_CLI_COMMAND (lisp_show_map_request_command) = {
1411 .path = "show lisp map-request itr-rlocs",
1412 .short_help = "Shows map-request itr-rlocs",
1413 .function = lisp_show_mreq_itr_rlocs_command_fn,
1417 static clib_error_t *
1418 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
1419 unformat_input_t * input,
1420 vlib_cli_command_t * cmd)
1422 u8 is_add = 1, ip_set = 0;
1423 unformat_input_t _line_input, *line_input = &_line_input;
1424 clib_error_t *error = 0;
1427 /* Get a line of input. */
1428 if (!unformat_user (input, unformat_line_input, line_input))
1431 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1433 if (unformat (line_input, "%U", unformat_ip_address, &ip))
1435 else if (unformat (line_input, "disable"))
1438 return clib_error_return (0, "parse error");
1443 clib_warning ("No petr IP specified!");
1447 if (vnet_lisp_use_petr (&ip, is_add))
1449 error = clib_error_return (0, "failed to %s petr!",
1450 is_add ? "add" : "delete");
1458 VLIB_CLI_COMMAND (lisp_use_petr_set_locator_set_command) = {
1459 .path = "lisp use-petr",
1460 .short_help = "lisp use-petr [disable] <petr-ip>",
1461 .function = lisp_use_petr_set_locator_set_command_fn,
1464 static clib_error_t *
1465 lisp_show_petr_command_fn (vlib_main_t * vm,
1466 unformat_input_t * input, vlib_cli_command_t * cmd)
1468 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1473 u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
1474 vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
1478 vlib_cli_output (vm, "%=20s", "disable");
1482 if (~0 == lcm->petr_map_index)
1484 tmp_str = format (0, "N/A");
1488 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1489 if (~0 != m->locator_set_index)
1491 ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
1492 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
1493 tmp_str = format (0, "%U", format_ip_address, &loc->address);
1497 tmp_str = format (0, "N/A");
1500 vec_add1 (tmp_str, 0);
1502 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1510 VLIB_CLI_COMMAND (lisp_show_petr_command) = {
1511 .path = "show lisp petr",
1512 .short_help = "Show petr",
1513 .function = lisp_show_petr_command_fn,
1520 * fd.io coding-style-patch-verification: ON
1523 * eval: (c-set-style "gnu")