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);
41 unformat_free (line_input);
45 unformat_free (line_input);
49 vlib_cli_output (vm, "error: no vni specified!");
53 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
55 vec_foreach (adj, adjs)
57 vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid,
58 format_gid_address, &adj->reid);
66 VLIB_CLI_COMMAND (one_show_adjacencies_command) = {
67 .path = "show one adjacencies",
68 .short_help = "show one adjacencies",
69 .function = lisp_show_adjacencies_command_fn,
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;
83 /* Get a line of input. */
84 if (!unformat_user (input, unformat_line_input, line_input))
87 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
89 if (unformat (line_input, "add"))
91 else if (unformat (line_input, "del"))
93 else if (unformat (line_input, "%U", unformat_ip_address, &ip))
97 vlib_cli_output (vm, "parse error: '%U'",
98 format_unformat_error, line_input);
99 unformat_free (line_input);
103 unformat_free (line_input);
107 vlib_cli_output (vm, "map-server ip address not set!");
111 rv = vnet_lisp_add_del_map_server (&ip, is_add);
113 vlib_cli_output (vm, "failed to %s map-server!",
114 is_add ? "add" : "delete");
120 VLIB_CLI_COMMAND (one_add_del_map_server_command) = {
121 .path = "one map-server",
122 .short_help = "one map-server add|del <ip>",
123 .function = lisp_add_del_map_server_command_fn,
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 memset (&eid, 0, sizeof (eid));
148 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 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
174 error = clib_error_return (0, "locator-set %s doesn't exist",
178 locator_set_index = p[0];
182 error = unformat_parse_error (line_input);
186 /* XXX treat batch configuration */
188 if (GID_ADDR_SRC_DST == gid_address_type (&eid))
191 clib_error_return (0, "src/dst is not supported for local EIDs!");
195 if (key && (0 == key_id))
197 vlib_cli_output (vm, "invalid key_id!");
201 gid_address_copy (&a->eid, &eid);
203 a->locator_set_index = locator_set_index;
208 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
211 error = clib_error_return (0, "failed to %s local mapping!",
212 is_add ? "add" : "delete");
216 if (locator_set_name)
217 vec_free (locator_set_name);
218 gid_address_free (&a->eid);
220 unformat_free (line_input);
225 VLIB_CLI_COMMAND (one_add_del_local_eid_command) = {
226 .path = "one eid-table",
227 .short_help = "one eid-table add/del [vni <vni>] eid <eid> "
228 "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]",
229 .function = lisp_add_del_local_eid_command_fn,
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);
272 VLIB_CLI_COMMAND (one_eid_table_map_command) = {
273 .path = "one eid-table map",
274 .short_help = "one eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
275 .function = lisp_eid_table_map_command_fn,
280 * Handler for add/del remote mapping CLI.
282 * @param vm vlib context
283 * @param input input from user
285 * @return pointer to clib error structure
287 static clib_error_t *
288 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
289 unformat_input_t * input,
290 vlib_cli_command_t * cmd)
292 clib_error_t *error = 0;
293 unformat_input_t _line_input, *line_input = &_line_input;
294 u8 is_add = 1, del_all = 0;
295 locator_t rloc, *rlocs = 0, *curr_rloc = 0;
298 u32 vni, action = ~0, p, w;
301 /* Get a line of input. */
302 if (!unformat_user (input, unformat_line_input, line_input))
305 memset (&eid, 0, sizeof (eid));
306 memset (&rloc, 0, sizeof (rloc));
308 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
310 if (unformat (line_input, "del-all"))
312 else if (unformat (line_input, "del"))
314 else if (unformat (line_input, "add"))
316 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
318 else if (unformat (line_input, "vni %u", &vni))
320 gid_address_vni (&eid) = vni;
322 else if (unformat (line_input, "p %d w %d", &p, &w))
327 ("No RLOC configured for setting priority/weight!");
330 curr_rloc->priority = p;
331 curr_rloc->weight = w;
333 else if (unformat (line_input, "rloc %U", unformat_ip_address,
334 &gid_address_ip (&rloc.address)))
336 /* since rloc is stored in ip prefix we need to set prefix length */
337 ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
339 u8 version = gid_address_ip_version (&rloc.address);
340 ip_prefix_len (pref) = ip_address_max_len (version);
342 vec_add1 (rlocs, rloc);
343 curr_rloc = &rlocs[vec_len (rlocs) - 1];
345 else if (unformat (line_input, "action %U",
346 unformat_negative_mapping_action, &action))
350 clib_warning ("parse error");
355 if (!del_all && !eid_set)
357 clib_warning ("missing eid!");
363 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
365 clib_warning ("no action set for negative map-reply!");
371 vnet_lisp_clear_all_remote_adjacencies ();
375 /* if it's a delete, clean forwarding */
378 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
379 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
390 rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add,
391 1 /* is_static */ , 0);
394 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
398 unformat_free (line_input);
403 VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = {
404 .path = "one remote-mapping",
406 "one remote-mapping add|del [del-all] vni <vni> "
407 "eid <est-eid> [action <no-action|natively-forward|"
408 "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
409 "[rloc <dst-locator> ... ]",
410 .function = lisp_add_del_remote_mapping_command_fn,
415 * Handler for add/del adjacency CLI.
417 static clib_error_t *
418 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
419 vlib_cli_command_t * cmd)
421 clib_error_t *error = 0;
422 unformat_input_t _line_input, *line_input = &_line_input;
423 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
425 ip_prefix_t *reid_ippref, *leid_ippref;
426 gid_address_t leid, reid;
427 u8 *dmac = gid_address_mac (&reid);
428 u8 *smac = gid_address_mac (&leid);
429 u8 reid_set = 0, leid_set = 0;
432 /* Get a line of input. */
433 if (!unformat_user (input, unformat_line_input, line_input))
436 memset (&reid, 0, sizeof (reid));
437 memset (&leid, 0, sizeof (leid));
439 leid_ippref = &gid_address_ippref (&leid);
440 reid_ippref = &gid_address_ippref (&reid);
442 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
444 if (unformat (line_input, "del"))
446 else if (unformat (line_input, "add"))
448 else if (unformat (line_input, "reid %U",
449 unformat_ip_prefix, reid_ippref))
451 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
454 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
456 gid_address_type (&reid) = GID_ADDR_MAC;
459 else if (unformat (line_input, "vni %u", &vni))
461 gid_address_vni (&leid) = vni;
462 gid_address_vni (&reid) = vni;
464 else if (unformat (line_input, "leid %U",
465 unformat_ip_prefix, leid_ippref))
467 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
470 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
472 gid_address_type (&leid) = GID_ADDR_MAC;
477 clib_warning ("parse error");
482 if (!reid_set || !leid_set)
484 clib_warning ("missing remote or local eid!");
488 if ((gid_address_type (&leid) != gid_address_type (&reid))
489 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
490 && ip_prefix_version (reid_ippref)
491 != ip_prefix_version (leid_ippref)))
493 clib_warning ("remote and local EIDs are of different types!");
497 memset (a, 0, sizeof (a[0]));
498 gid_address_copy (&a->leid, &leid);
499 gid_address_copy (&a->reid, &reid);
502 if (vnet_lisp_add_del_adjacency (a))
503 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
506 unformat_free (line_input);
511 VLIB_CLI_COMMAND (one_add_del_adjacency_command) = {
512 .path = "one adjacency",
513 .short_help = "one adjacency add|del vni <vni> reid <remote-eid> "
515 .function = lisp_add_del_adjacency_command_fn,
520 static clib_error_t *
521 lisp_map_request_mode_command_fn (vlib_main_t * vm,
522 unformat_input_t * input,
523 vlib_cli_command_t * cmd)
525 unformat_input_t _i, *i = &_i;
526 map_request_mode_t mr_mode = _MR_MODE_MAX;
528 /* Get a line of input. */
529 if (!unformat_user (input, unformat_line_input, i))
532 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
534 if (unformat (i, "dst-only"))
535 mr_mode = MR_MODE_DST_ONLY;
536 else if (unformat (i, "src-dst"))
537 mr_mode = MR_MODE_SRC_DST;
540 clib_warning ("parse error '%U'", format_unformat_error, i);
545 if (_MR_MODE_MAX == mr_mode)
547 clib_warning ("No map request mode entered!");
551 vnet_lisp_set_map_request_mode (mr_mode);
560 VLIB_CLI_COMMAND (one_map_request_mode_command) = {
561 .path = "one map-request mode",
562 .short_help = "one map-request mode dst-only|src-dst",
563 .function = lisp_map_request_mode_command_fn,
569 format_lisp_map_request_mode (u8 * s, va_list * args)
571 u32 mode = va_arg (*args, u32);
576 return format (0, "dst-only");
578 return format (0, "src-dst");
583 static clib_error_t *
584 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
585 unformat_input_t * input,
586 vlib_cli_command_t * cmd)
588 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
589 vnet_lisp_get_map_request_mode ());
594 VLIB_CLI_COMMAND (one_show_map_request_mode_command) = {
595 .path = "show one map-request mode",
596 .short_help = "show one map-request mode",
597 .function = lisp_show_map_request_mode_command_fn,
601 static clib_error_t *
602 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
603 unformat_input_t * input,
604 vlib_cli_command_t * cmd)
607 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
609 vec_foreach (mr, lcm->map_resolvers)
611 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
617 VLIB_CLI_COMMAND (one_show_map_resolvers_command) = {
618 .path = "show one map-resolvers",
619 .short_help = "show one map-resolvers",
620 .function = lisp_show_map_resolvers_command_fn,
625 static clib_error_t *
626 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
627 unformat_input_t * input,
628 vlib_cli_command_t * cmd)
630 u8 locator_name_set = 0;
631 u8 *locator_set_name = 0;
633 unformat_input_t _line_input, *line_input = &_line_input;
634 clib_error_t *error = 0;
637 /* Get a line of input. */
638 if (!unformat_user (input, unformat_line_input, line_input))
641 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
643 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
644 locator_name_set = 1;
645 else if (unformat (line_input, "disable"))
649 error = clib_error_return (0, "parse error");
654 if (!locator_name_set)
656 clib_warning ("No locator set specified!");
659 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
662 error = clib_error_return (0, "failed to %s pitr!",
663 is_add ? "add" : "delete");
667 if (locator_set_name)
668 vec_free (locator_set_name);
669 unformat_free (line_input);
674 VLIB_CLI_COMMAND (one_pitr_set_locator_set_command) = {
676 .short_help = "one pitr [disable] ls <locator-set-name>",
677 .function = lisp_pitr_set_locator_set_command_fn,
681 static clib_error_t *
682 lisp_show_pitr_command_fn (vlib_main_t * vm,
683 unformat_input_t * input, vlib_cli_command_t * cmd)
685 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
690 vlib_cli_output (vm, "%=20s%=16s",
691 "pitr", lcm->lisp_pitr ? "locator-set" : "");
695 vlib_cli_output (vm, "%=20s", "disable");
699 if (~0 == lcm->pitr_map_index)
701 tmp_str = format (0, "N/A");
705 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
706 if (~0 != m->locator_set_index)
709 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
710 tmp_str = format (0, "%s", ls->name);
714 tmp_str = format (0, "N/A");
717 vec_add1 (tmp_str, 0);
719 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
727 VLIB_CLI_COMMAND (one_show_pitr_command) = {
728 .path = "show one pitr",
729 .short_help = "Show pitr",
730 .function = lisp_show_pitr_command_fn,
735 format_eid_entry (u8 * s, va_list * args)
737 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
738 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
739 mapping_t *mapit = va_arg (*args, mapping_t *);
740 locator_set_t *ls = va_arg (*args, locator_set_t *);
741 gid_address_t *gid = &mapit->eid;
742 u32 ttl = mapit->ttl;
743 u8 aut = mapit->authoritative;
748 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
749 : format (0, "remote");
751 if (vec_len (ls->locator_indices) == 0)
753 s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
758 vec_foreach (loc_index, ls->locator_indices)
760 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
762 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
765 loc = format (0, "%U", format_ip_address,
766 &gid_address_ip (&l->address));
770 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
771 gid, type, loc, ttl, aut);
775 s = format (s, "%55s%v\n", "", loc);
781 static clib_error_t *
782 lisp_show_eid_table_command_fn (vlib_main_t * vm,
783 unformat_input_t * input,
784 vlib_cli_command_t * cmd)
786 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
788 unformat_input_t _line_input, *line_input = &_line_input;
793 clib_error_t *error = NULL;
795 memset (&eid, 0, sizeof (eid));
797 /* Get a line of input. */
798 if (!unformat_user (input, unformat_line_input, line_input))
801 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
803 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
805 else if (unformat (line_input, "local"))
807 else if (unformat (line_input, "remote"))
811 error = clib_error_return (0, "parse error: '%U'",
812 format_unformat_error, line_input);
817 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
818 "EID", "type", "locators", "ttl", "autoritative");
823 pool_foreach (mapit, lcm->mapping_pool,
828 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
829 mapit->locator_set_index);
830 if (filter && !((1 == filter && ls->local) ||
831 (2 == filter && !ls->local)))
835 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
842 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
846 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
847 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
848 mapit->locator_set_index);
850 if (filter && !((1 == filter && ls->local) ||
851 (2 == filter && !ls->local)))
856 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
861 unformat_free (line_input);
867 VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = {
868 .path = "show one eid-table",
869 .short_help = "Shows EID table",
870 .function = lisp_show_eid_table_command_fn,
875 static clib_error_t *
876 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
877 vlib_cli_command_t * cmd)
879 unformat_input_t _line_input, *line_input = &_line_input;
882 clib_error_t *error = NULL;
884 /* Get a line of input. */
885 if (!unformat_user (input, unformat_line_input, line_input))
888 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
890 if (unformat (line_input, "enable"))
895 else if (unformat (line_input, "disable"))
899 error = clib_error_return (0, "parse error: '%U'",
900 format_unformat_error, line_input);
907 error = clib_error_return (0, "state not set");
911 vnet_lisp_enable_disable (is_enabled);
914 unformat_free (line_input);
920 VLIB_CLI_COMMAND (one_cp_enable_disable_command) = {
922 .short_help = "one [enable|disable]",
923 .function = lisp_enable_disable_command_fn,
927 static clib_error_t *
928 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
929 unformat_input_t * input,
930 vlib_cli_command_t * cmd)
932 unformat_input_t _line_input, *line_input = &_line_input;
935 clib_error_t *error = NULL;
937 /* Get a line of input. */
938 if (!unformat_user (input, unformat_line_input, line_input))
941 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
943 if (unformat (line_input, "enable"))
948 else if (unformat (line_input, "disable"))
952 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
960 vlib_cli_output (vm, "state not set!");
964 vnet_lisp_map_register_enable_disable (is_enabled);
967 unformat_free (line_input);
973 VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = {
974 .path = "one map-register",
975 .short_help = "one map-register [enable|disable]",
976 .function = lisp_map_register_enable_disable_command_fn,
980 static clib_error_t *
981 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
982 unformat_input_t * input,
983 vlib_cli_command_t * cmd)
985 unformat_input_t _line_input, *line_input = &_line_input;
988 clib_error_t *error = NULL;
990 /* Get a line of input. */
991 if (!unformat_user (input, unformat_line_input, line_input))
994 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
996 if (unformat (line_input, "enable"))
1001 else if (unformat (line_input, "disable"))
1005 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1013 vlib_cli_output (vm, "state not set!");
1017 vnet_lisp_rloc_probe_enable_disable (is_enabled);
1020 unformat_free (line_input);
1026 VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = {
1027 .path = "one rloc-probe",
1028 .short_help = "one rloc-probe [enable|disable]",
1029 .function = lisp_rloc_probe_enable_disable_command_fn,
1034 format_lisp_status (u8 * s, va_list * args)
1036 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1037 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
1040 static clib_error_t *
1041 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
1042 vlib_cli_command_t * cmd)
1045 msg = format (msg, "feature: %U\ngpe: %U\n",
1046 format_lisp_status, format_vnet_lisp_gpe_status);
1047 vlib_cli_output (vm, "%v", msg);
1053 VLIB_CLI_COMMAND (one_show_status_command) = {
1054 .path = "show one status",
1055 .short_help = "show one status",
1056 .function = lisp_show_status_command_fn,
1060 static clib_error_t *
1061 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1062 unformat_input_t * input,
1063 vlib_cli_command_t * cmd)
1066 unformat_input_t _line_input, *line_input = &_line_input;
1067 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1068 uword *vni_table = 0;
1070 clib_error_t *error = NULL;
1072 /* Get a line of input. */
1073 if (!unformat_user (input, unformat_line_input, line_input))
1076 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1078 if (unformat (line_input, "l2"))
1080 vni_table = lcm->bd_id_by_vni;
1083 else if (unformat (line_input, "l3"))
1085 vni_table = lcm->table_id_by_vni;
1090 error = clib_error_return (0, "parse error: '%U'",
1091 format_unformat_error, line_input);
1098 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1102 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1105 hash_foreach_pair (p, vni_table,
1107 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1112 unformat_free (line_input);
1118 VLIB_CLI_COMMAND (one_show_eid_table_map_command) = {
1119 .path = "show one eid-table map",
1120 .short_help = "show one eid-table l2|l3",
1121 .function = lisp_show_eid_table_map_command_fn,
1126 static clib_error_t *
1127 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1128 unformat_input_t * input,
1129 vlib_cli_command_t * cmd)
1131 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1132 vnet_main_t *vnm = lgm->vnet_main;
1133 unformat_input_t _line_input, *line_input = &_line_input;
1135 clib_error_t *error = 0;
1136 u8 *locator_set_name = 0;
1137 locator_t locator, *locators = 0;
1138 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1142 memset (&locator, 0, sizeof (locator));
1143 memset (a, 0, sizeof (a[0]));
1145 /* Get a line of input. */
1146 if (!unformat_user (input, unformat_line_input, line_input))
1149 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1151 if (unformat (line_input, "add %_%v%_", &locator_set_name))
1153 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1155 else if (unformat (line_input, "iface %U p %d w %d",
1156 unformat_vnet_sw_interface, vnm,
1157 &locator.sw_if_index, &locator.priority,
1161 vec_add1 (locators, locator);
1165 error = unformat_parse_error (line_input);
1170 a->name = locator_set_name;
1171 a->locators = locators;
1175 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1178 error = clib_error_return (0, "failed to %s locator-set!",
1179 is_add ? "add" : "delete");
1183 vec_free (locators);
1184 if (locator_set_name)
1185 vec_free (locator_set_name);
1186 unformat_free (line_input);
1191 VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = {
1192 .path = "one locator-set",
1193 .short_help = "one locator-set add/del <name> [iface <iface-name> "
1194 "p <priority> w <weight>]",
1195 .function = lisp_add_del_locator_set_command_fn,
1199 static clib_error_t *
1200 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1201 unformat_input_t * input,
1202 vlib_cli_command_t * cmd)
1204 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1205 vnet_main_t *vnm = lgm->vnet_main;
1206 unformat_input_t _line_input, *line_input = &_line_input;
1208 clib_error_t *error = 0;
1209 u8 *locator_set_name = 0;
1210 u8 locator_set_name_set = 0;
1211 locator_t locator, *locators = 0;
1212 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1215 memset (&locator, 0, sizeof (locator));
1216 memset (a, 0, sizeof (a[0]));
1218 /* Get a line of input. */
1219 if (!unformat_user (input, unformat_line_input, line_input))
1222 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1224 if (unformat (line_input, "add"))
1226 else if (unformat (line_input, "del"))
1228 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1229 locator_set_name_set = 1;
1230 else if (unformat (line_input, "iface %U p %d w %d",
1231 unformat_vnet_sw_interface, vnm,
1232 &locator.sw_if_index, &locator.priority,
1236 vec_add1 (locators, locator);
1240 error = unformat_parse_error (line_input);
1245 if (!locator_set_name_set)
1247 error = clib_error_return (0, "locator_set name not set!");
1251 a->name = locator_set_name;
1252 a->locators = locators;
1256 vnet_lisp_add_del_locator (a, 0, &ls_index);
1259 vec_free (locators);
1260 vec_free (locator_set_name);
1261 unformat_free (line_input);
1266 VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = {
1267 .path = "one locator",
1268 .short_help = "one locator add/del locator-set <name> iface <iface-name> "
1269 "p <priority> w <weight>",
1270 .function = lisp_add_del_locator_in_set_command_fn,
1274 static clib_error_t *
1275 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1276 unformat_input_t * input,
1277 vlib_cli_command_t * cmd)
1279 locator_set_t *lsit;
1282 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1284 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1285 "Priority", "Weight");
1288 pool_foreach (lsit, lcm->locator_set_pool,
1294 msg = format (msg, "%v", lsit->name);
1298 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1300 vec_foreach (locit, lsit->locator_indices)
1304 msg = format (msg, "%16s", " ");
1306 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1308 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1311 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1312 &gid_address_ip(&loc->address), loc->priority,
1316 vlib_cli_output (vm, "%v", msg);
1324 VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = {
1325 .path = "show one locator-set",
1326 .short_help = "Shows locator-sets",
1327 .function = lisp_cp_show_locator_sets_command_fn,
1332 static clib_error_t *
1333 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1334 unformat_input_t * input,
1335 vlib_cli_command_t * cmd)
1337 unformat_input_t _line_input, *line_input = &_line_input;
1338 u8 is_add = 1, addr_set = 0;
1339 ip_address_t ip_addr;
1340 clib_error_t *error = 0;
1342 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1344 /* Get a line of input. */
1345 if (!unformat_user (input, unformat_line_input, line_input))
1348 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1350 if (unformat (line_input, "add"))
1352 else if (unformat (line_input, "del"))
1354 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1358 error = unformat_parse_error (line_input);
1365 error = clib_error_return (0, "Map-resolver address must be set!");
1370 a->address = ip_addr;
1371 rv = vnet_lisp_add_del_map_resolver (a);
1374 error = clib_error_return (0, "failed to %s map-resolver!",
1375 is_add ? "add" : "delete");
1379 unformat_free (line_input);
1384 VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = {
1385 .path = "one map-resolver",
1386 .short_help = "one map-resolver add/del <ip_address>",
1387 .function = lisp_add_del_map_resolver_command_fn,
1392 static clib_error_t *
1393 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1394 unformat_input_t * input,
1395 vlib_cli_command_t * cmd)
1397 unformat_input_t _line_input, *line_input = &_line_input;
1399 u8 *locator_set_name = 0;
1400 clib_error_t *error = 0;
1402 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1404 /* Get a line of input. */
1405 if (!unformat_user (input, unformat_line_input, line_input))
1408 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1410 if (unformat (line_input, "del"))
1412 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1416 error = unformat_parse_error (line_input);
1422 a->locator_set_name = locator_set_name;
1423 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1426 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1427 is_add ? "add" : "delete");
1431 vec_free (locator_set_name);
1432 unformat_free (line_input);
1438 VLIB_CLI_COMMAND (one_add_del_map_request_command) = {
1439 .path = "one map-request itr-rlocs",
1440 .short_help = "one map-request itr-rlocs add/del <locator_set_name>",
1441 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
1445 static clib_error_t *
1446 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1447 unformat_input_t * input,
1448 vlib_cli_command_t * cmd)
1450 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1451 locator_set_t *loc_set;
1453 vlib_cli_output (vm, "%=20s", "itr-rlocs");
1455 if (~0 == lcm->mreq_itr_rlocs)
1460 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1462 vlib_cli_output (vm, "%=20s", loc_set->name);
1468 VLIB_CLI_COMMAND (one_show_map_request_command) = {
1469 .path = "show one map-request itr-rlocs",
1470 .short_help = "Shows map-request itr-rlocs",
1471 .function = lisp_show_mreq_itr_rlocs_command_fn,
1475 static clib_error_t *
1476 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
1477 unformat_input_t * input,
1478 vlib_cli_command_t * cmd)
1480 u8 is_add = 1, ip_set = 0;
1481 unformat_input_t _line_input, *line_input = &_line_input;
1482 clib_error_t *error = 0;
1485 /* Get a line of input. */
1486 if (!unformat_user (input, unformat_line_input, line_input))
1489 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1491 if (unformat (line_input, "%U", unformat_ip_address, &ip))
1493 else if (unformat (line_input, "disable"))
1497 error = clib_error_return (0, "parse error");
1504 clib_warning ("No petr IP specified!");
1508 if (vnet_lisp_use_petr (&ip, is_add))
1510 error = clib_error_return (0, "failed to %s petr!",
1511 is_add ? "add" : "delete");
1515 unformat_free (line_input);
1520 VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = {
1521 .path = "one use-petr",
1522 .short_help = "one use-petr [disable] <petr-ip>",
1523 .function = lisp_use_petr_set_locator_set_command_fn,
1526 static clib_error_t *
1527 lisp_show_petr_command_fn (vlib_main_t * vm,
1528 unformat_input_t * input, vlib_cli_command_t * cmd)
1530 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1535 u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
1536 vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
1540 vlib_cli_output (vm, "%=20s", "disable");
1544 if (~0 == lcm->petr_map_index)
1546 tmp_str = format (0, "N/A");
1550 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1551 if (~0 != m->locator_set_index)
1553 ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
1554 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
1555 tmp_str = format (0, "%U", format_ip_address, &loc->address);
1559 tmp_str = format (0, "N/A");
1562 vec_add1 (tmp_str, 0);
1564 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1572 VLIB_CLI_COMMAND (one_show_petr_command) = {
1573 .path = "show one petr",
1574 .short_help = "Show petr",
1575 .function = lisp_show_petr_command_fn,
1579 static clib_error_t *
1580 lisp_show_map_servers_command_fn (vlib_main_t * vm,
1581 unformat_input_t * input,
1582 vlib_cli_command_t * cmd)
1585 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1587 vec_foreach (ms, lcm->map_servers)
1589 vlib_cli_output (vm, "%U", format_ip_address, &ms->address);
1595 VLIB_CLI_COMMAND (one_show_map_servers_command) = {
1596 .path = "show one map-servers",
1597 .short_help = "show one map servers",
1598 .function = lisp_show_map_servers_command_fn,
1602 static clib_error_t *
1603 lisp_show_map_register_state_command_fn (vlib_main_t * vm,
1604 unformat_input_t * input,
1605 vlib_cli_command_t * cmd)
1608 u8 is_enabled = vnet_lisp_map_register_state_get ();
1610 msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
1611 vlib_cli_output (vm, "%v", msg);
1617 VLIB_CLI_COMMAND (one_show_map_register_state_command) = {
1618 .path = "show one map-register state",
1619 .short_help = "show one map-register state",
1620 .function = lisp_show_map_register_state_command_fn,
1624 static clib_error_t *
1625 lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm,
1626 unformat_input_t * input,
1627 vlib_cli_command_t * cmd)
1630 u8 is_enabled = vnet_lisp_rloc_probe_state_get ();
1632 msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
1633 vlib_cli_output (vm, "%v", msg);
1639 VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = {
1640 .path = "show one rloc state",
1641 .short_help = "show one RLOC state",
1642 .function = lisp_show_rloc_probe_state_command_fn,
1646 static clib_error_t *
1647 lisp_show_stats_command_fn (vlib_main_t * vm,
1648 unformat_input_t * input,
1649 vlib_cli_command_t * cmd)
1651 u8 is_enabled = vnet_lisp_stats_enable_disable_state ();
1652 vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled");
1657 VLIB_CLI_COMMAND (one_show_stats_command) = {
1658 .path = "show one statistics status",
1659 .short_help = "show ONE statistics enable/disable status",
1660 .function = lisp_show_stats_command_fn,
1664 static clib_error_t *
1665 lisp_show_stats_details_command_fn (vlib_main_t * vm,
1666 unformat_input_t * input,
1667 vlib_cli_command_t * cmd)
1669 lisp_api_stats_t *stat, *stats = vnet_lisp_get_stats ();
1671 if (vec_len (stats) > 0)
1672 vlib_cli_output (vm,
1673 "[src-EID, dst-EID] [loc-rloc, rmt-rloc] count bytes\n");
1675 vlib_cli_output (vm, "No statistics found.\n");
1677 vec_foreach (stat, stats)
1679 vlib_cli_output (vm, "[%U, %U] [%U, %U] %7u %7u\n",
1680 format_fid_address, &stat->seid,
1681 format_fid_address, &stat->deid,
1682 format_ip_address, &stat->loc_rloc,
1683 format_ip_address, &stat->rmt_rloc,
1684 stat->stats.pkt_count, stat->stats.bytes);
1691 VLIB_CLI_COMMAND (one_show_stats_details_command) = {
1692 .path = "show one statistics details",
1693 .short_help = "show ONE statistics",
1694 .function = lisp_show_stats_details_command_fn,
1698 static clib_error_t *
1699 lisp_stats_enable_disable_command_fn (vlib_main_t * vm,
1700 unformat_input_t * input,
1701 vlib_cli_command_t * cmd)
1703 unformat_input_t _line_input, *line_input = &_line_input;
1706 /* Get a line of input. */
1707 if (!unformat_user (input, unformat_line_input, line_input))
1710 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1712 if (unformat (line_input, "enable"))
1714 else if (unformat (line_input, "disable"))
1718 clib_warning ("Error: expected enable/disable!");
1722 vnet_lisp_stats_enable_disable (enable);
1724 unformat_free (line_input);
1729 VLIB_CLI_COMMAND (one_stats_enable_disable_command) = {
1730 .path = "one statistics",
1731 .short_help = "enable/disable ONE statistics collecting",
1732 .function = lisp_stats_enable_disable_command_fn,
1736 static clib_error_t *
1737 lisp_stats_flush_command_fn (vlib_main_t * vm,
1738 unformat_input_t * input,
1739 vlib_cli_command_t * cmd)
1741 vnet_lisp_flush_stats ();
1746 VLIB_CLI_COMMAND (one_stats_flush_command) = {
1747 .path = "one statistics flush",
1748 .short_help = "Flush ONE statistics",
1749 .function = lisp_stats_flush_command_fn,
1754 * fd.io coding-style-patch-verification: ON
1757 * eval: (c-set-style "gnu")