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");
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 /* TODO build src/dst with seid */
377 /* if it's a delete, clean forwarding */
380 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
381 memset (a, 0, sizeof (a[0]));
382 gid_address_copy (&a->reid, &eid);
383 if (vnet_lisp_add_del_adjacency (a))
385 clib_warning ("failed to delete adjacency!");
390 /* add as static remote mapping, i.e., not authoritative and infinite
392 rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add,
393 1 /* is_static */ , 0);
396 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
400 unformat_free (line_input);
405 VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = {
406 .path = "one remote-mapping",
408 "one remote-mapping add|del [del-all] vni <vni> "
409 "eid <est-eid> [action <no-action|natively-forward|"
410 "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
411 "[rloc <dst-locator> ... ]",
412 .function = lisp_add_del_remote_mapping_command_fn,
417 * Handler for add/del adjacency CLI.
419 static clib_error_t *
420 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
421 vlib_cli_command_t * cmd)
423 clib_error_t *error = 0;
424 unformat_input_t _line_input, *line_input = &_line_input;
425 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
427 ip_prefix_t *reid_ippref, *leid_ippref;
428 gid_address_t leid, reid;
429 u8 *dmac = gid_address_mac (&reid);
430 u8 *smac = gid_address_mac (&leid);
431 u8 reid_set = 0, leid_set = 0;
434 /* Get a line of input. */
435 if (!unformat_user (input, unformat_line_input, line_input))
438 memset (&reid, 0, sizeof (reid));
439 memset (&leid, 0, sizeof (leid));
441 leid_ippref = &gid_address_ippref (&leid);
442 reid_ippref = &gid_address_ippref (&reid);
444 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
446 if (unformat (line_input, "del"))
448 else if (unformat (line_input, "add"))
450 else if (unformat (line_input, "reid %U",
451 unformat_ip_prefix, reid_ippref))
453 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
456 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
458 gid_address_type (&reid) = GID_ADDR_MAC;
461 else if (unformat (line_input, "vni %u", &vni))
463 gid_address_vni (&leid) = vni;
464 gid_address_vni (&reid) = vni;
466 else if (unformat (line_input, "leid %U",
467 unformat_ip_prefix, leid_ippref))
469 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
472 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
474 gid_address_type (&leid) = GID_ADDR_MAC;
479 clib_warning ("parse error");
484 if (!reid_set || !leid_set)
486 clib_warning ("missing remote or local eid!");
490 if ((gid_address_type (&leid) != gid_address_type (&reid))
491 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
492 && ip_prefix_version (reid_ippref)
493 != ip_prefix_version (leid_ippref)))
495 clib_warning ("remote and local EIDs are of different types!");
499 memset (a, 0, sizeof (a[0]));
500 gid_address_copy (&a->leid, &leid);
501 gid_address_copy (&a->reid, &reid);
504 if (vnet_lisp_add_del_adjacency (a))
505 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
508 unformat_free (line_input);
513 VLIB_CLI_COMMAND (one_add_del_adjacency_command) = {
514 .path = "one adjacency",
515 .short_help = "one adjacency add|del vni <vni> reid <remote-eid> "
517 .function = lisp_add_del_adjacency_command_fn,
522 static clib_error_t *
523 lisp_map_request_mode_command_fn (vlib_main_t * vm,
524 unformat_input_t * input,
525 vlib_cli_command_t * cmd)
527 unformat_input_t _i, *i = &_i;
528 map_request_mode_t mr_mode = _MR_MODE_MAX;
530 /* Get a line of input. */
531 if (!unformat_user (input, unformat_line_input, i))
534 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
536 if (unformat (i, "dst-only"))
537 mr_mode = MR_MODE_DST_ONLY;
538 else if (unformat (i, "src-dst"))
539 mr_mode = MR_MODE_SRC_DST;
542 clib_warning ("parse error '%U'", format_unformat_error, i);
547 if (_MR_MODE_MAX == mr_mode)
549 clib_warning ("No map request mode entered!");
553 vnet_lisp_set_map_request_mode (mr_mode);
562 VLIB_CLI_COMMAND (one_map_request_mode_command) = {
563 .path = "one map-request mode",
564 .short_help = "one map-request mode dst-only|src-dst",
565 .function = lisp_map_request_mode_command_fn,
571 format_lisp_map_request_mode (u8 * s, va_list * args)
573 u32 mode = va_arg (*args, u32);
578 return format (0, "dst-only");
580 return format (0, "src-dst");
585 static clib_error_t *
586 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
587 unformat_input_t * input,
588 vlib_cli_command_t * cmd)
590 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
591 vnet_lisp_get_map_request_mode ());
596 VLIB_CLI_COMMAND (one_show_map_request_mode_command) = {
597 .path = "show one map-request mode",
598 .short_help = "show one map-request mode",
599 .function = lisp_show_map_request_mode_command_fn,
603 static clib_error_t *
604 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
605 unformat_input_t * input,
606 vlib_cli_command_t * cmd)
609 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
611 vec_foreach (mr, lcm->map_resolvers)
613 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
619 VLIB_CLI_COMMAND (one_show_map_resolvers_command) = {
620 .path = "show one map-resolvers",
621 .short_help = "show one map-resolvers",
622 .function = lisp_show_map_resolvers_command_fn,
627 static clib_error_t *
628 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
629 unformat_input_t * input,
630 vlib_cli_command_t * cmd)
632 u8 locator_name_set = 0;
633 u8 *locator_set_name = 0;
635 unformat_input_t _line_input, *line_input = &_line_input;
636 clib_error_t *error = 0;
639 /* Get a line of input. */
640 if (!unformat_user (input, unformat_line_input, line_input))
643 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
645 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
646 locator_name_set = 1;
647 else if (unformat (line_input, "disable"))
651 error = clib_error_return (0, "parse error");
656 if (!locator_name_set)
658 clib_warning ("No locator set specified!");
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 (one_pitr_set_locator_set_command) = {
678 .short_help = "one pitr [disable] ls <locator-set-name>",
679 .function = lisp_pitr_set_locator_set_command_fn,
683 static clib_error_t *
684 lisp_show_pitr_command_fn (vlib_main_t * vm,
685 unformat_input_t * input, vlib_cli_command_t * cmd)
687 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
692 vlib_cli_output (vm, "%=20s%=16s",
693 "pitr", lcm->lisp_pitr ? "locator-set" : "");
697 vlib_cli_output (vm, "%=20s", "disable");
701 if (~0 == lcm->pitr_map_index)
703 tmp_str = format (0, "N/A");
707 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
708 if (~0 != m->locator_set_index)
711 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
712 tmp_str = format (0, "%s", ls->name);
716 tmp_str = format (0, "N/A");
719 vec_add1 (tmp_str, 0);
721 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
729 VLIB_CLI_COMMAND (one_show_pitr_command) = {
730 .path = "show one pitr",
731 .short_help = "Show pitr",
732 .function = lisp_show_pitr_command_fn,
737 format_eid_entry (u8 * s, va_list * args)
739 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
740 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
741 mapping_t *mapit = va_arg (*args, mapping_t *);
742 locator_set_t *ls = va_arg (*args, locator_set_t *);
743 gid_address_t *gid = &mapit->eid;
744 u32 ttl = mapit->ttl;
745 u8 aut = mapit->authoritative;
750 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
751 : format (0, "remote");
753 if (vec_len (ls->locator_indices) == 0)
755 s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
760 vec_foreach (loc_index, ls->locator_indices)
762 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
764 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
767 loc = format (0, "%U", format_ip_address,
768 &gid_address_ip (&l->address));
772 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
773 gid, type, loc, ttl, aut);
777 s = format (s, "%55s%v\n", "", loc);
783 static clib_error_t *
784 lisp_show_eid_table_command_fn (vlib_main_t * vm,
785 unformat_input_t * input,
786 vlib_cli_command_t * cmd)
788 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
790 unformat_input_t _line_input, *line_input = &_line_input;
795 clib_error_t *error = NULL;
797 memset (&eid, 0, sizeof (eid));
799 /* Get a line of input. */
800 if (!unformat_user (input, unformat_line_input, line_input))
803 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
805 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
807 else if (unformat (line_input, "local"))
809 else if (unformat (line_input, "remote"))
813 error = clib_error_return (0, "parse error: '%U'",
814 format_unformat_error, line_input);
819 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
820 "EID", "type", "locators", "ttl", "autoritative");
825 pool_foreach (mapit, lcm->mapping_pool,
827 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
828 mapit->locator_set_index);
829 if (filter && !((1 == filter && ls->local) ||
830 (2 == filter && !ls->local)))
834 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
841 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
845 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
846 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
847 mapit->locator_set_index);
849 if (filter && !((1 == filter && ls->local) ||
850 (2 == filter && !ls->local)))
855 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
860 unformat_free (line_input);
866 VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = {
867 .path = "show one eid-table",
868 .short_help = "Shows EID table",
869 .function = lisp_show_eid_table_command_fn,
874 static clib_error_t *
875 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
876 vlib_cli_command_t * cmd)
878 unformat_input_t _line_input, *line_input = &_line_input;
881 clib_error_t *error = NULL;
883 /* Get a line of input. */
884 if (!unformat_user (input, unformat_line_input, line_input))
887 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
889 if (unformat (line_input, "enable"))
894 else if (unformat (line_input, "disable"))
898 error = clib_error_return (0, "parse error: '%U'",
899 format_unformat_error, line_input);
906 error = clib_error_return (0, "state not set");
910 vnet_lisp_enable_disable (is_enabled);
913 unformat_free (line_input);
919 VLIB_CLI_COMMAND (one_cp_enable_disable_command) = {
921 .short_help = "one [enable|disable]",
922 .function = lisp_enable_disable_command_fn,
926 static clib_error_t *
927 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
928 unformat_input_t * input,
929 vlib_cli_command_t * cmd)
931 unformat_input_t _line_input, *line_input = &_line_input;
934 clib_error_t *error = NULL;
936 /* Get a line of input. */
937 if (!unformat_user (input, unformat_line_input, line_input))
940 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
942 if (unformat (line_input, "enable"))
947 else if (unformat (line_input, "disable"))
951 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
959 vlib_cli_output (vm, "state not set!");
963 vnet_lisp_map_register_enable_disable (is_enabled);
966 unformat_free (line_input);
972 VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = {
973 .path = "one map-register",
974 .short_help = "one map-register [enable|disable]",
975 .function = lisp_map_register_enable_disable_command_fn,
979 static clib_error_t *
980 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
981 unformat_input_t * input,
982 vlib_cli_command_t * cmd)
984 unformat_input_t _line_input, *line_input = &_line_input;
987 clib_error_t *error = NULL;
989 /* Get a line of input. */
990 if (!unformat_user (input, unformat_line_input, line_input))
993 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
995 if (unformat (line_input, "enable"))
1000 else if (unformat (line_input, "disable"))
1004 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1012 vlib_cli_output (vm, "state not set!");
1016 vnet_lisp_rloc_probe_enable_disable (is_enabled);
1019 unformat_free (line_input);
1025 VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = {
1026 .path = "one rloc-probe",
1027 .short_help = "one rloc-probe [enable|disable]",
1028 .function = lisp_rloc_probe_enable_disable_command_fn,
1033 format_lisp_status (u8 * s, va_list * args)
1035 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1036 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
1039 static clib_error_t *
1040 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
1041 vlib_cli_command_t * cmd)
1044 msg = format (msg, "feature: %U\ngpe: %U\n",
1045 format_lisp_status, format_vnet_lisp_gpe_status);
1046 vlib_cli_output (vm, "%v", msg);
1052 VLIB_CLI_COMMAND (one_show_status_command) = {
1053 .path = "show one status",
1054 .short_help = "show one status",
1055 .function = lisp_show_status_command_fn,
1059 static clib_error_t *
1060 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1061 unformat_input_t * input,
1062 vlib_cli_command_t * cmd)
1065 unformat_input_t _line_input, *line_input = &_line_input;
1066 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1067 uword *vni_table = 0;
1069 clib_error_t *error = NULL;
1071 /* Get a line of input. */
1072 if (!unformat_user (input, unformat_line_input, line_input))
1075 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1077 if (unformat (line_input, "l2"))
1079 vni_table = lcm->bd_id_by_vni;
1082 else if (unformat (line_input, "l3"))
1084 vni_table = lcm->table_id_by_vni;
1089 error = clib_error_return (0, "parse error: '%U'",
1090 format_unformat_error, line_input);
1097 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1101 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1104 hash_foreach_pair (p, vni_table,
1106 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1111 unformat_free (line_input);
1117 VLIB_CLI_COMMAND (one_show_eid_table_map_command) = {
1118 .path = "show one eid-table map",
1119 .short_help = "show one eid-table l2|l3",
1120 .function = lisp_show_eid_table_map_command_fn,
1125 static clib_error_t *
1126 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1127 unformat_input_t * input,
1128 vlib_cli_command_t * cmd)
1130 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1131 vnet_main_t *vnm = lgm->vnet_main;
1132 unformat_input_t _line_input, *line_input = &_line_input;
1134 clib_error_t *error = 0;
1135 u8 *locator_set_name = 0;
1136 locator_t locator, *locators = 0;
1137 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1141 memset (&locator, 0, sizeof (locator));
1142 memset (a, 0, sizeof (a[0]));
1144 /* Get a line of input. */
1145 if (!unformat_user (input, unformat_line_input, line_input))
1148 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1150 if (unformat (line_input, "add %_%v%_", &locator_set_name))
1152 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1154 else if (unformat (line_input, "iface %U p %d w %d",
1155 unformat_vnet_sw_interface, vnm,
1156 &locator.sw_if_index, &locator.priority,
1160 vec_add1 (locators, locator);
1164 error = unformat_parse_error (line_input);
1169 a->name = locator_set_name;
1170 a->locators = locators;
1174 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1177 error = clib_error_return (0, "failed to %s locator-set!",
1178 is_add ? "add" : "delete");
1182 vec_free (locators);
1183 if (locator_set_name)
1184 vec_free (locator_set_name);
1185 unformat_free (line_input);
1190 VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = {
1191 .path = "one locator-set",
1192 .short_help = "one locator-set add/del <name> [iface <iface-name> "
1193 "p <priority> w <weight>]",
1194 .function = lisp_add_del_locator_set_command_fn,
1198 static clib_error_t *
1199 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1200 unformat_input_t * input,
1201 vlib_cli_command_t * cmd)
1203 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1204 vnet_main_t *vnm = lgm->vnet_main;
1205 unformat_input_t _line_input, *line_input = &_line_input;
1207 clib_error_t *error = 0;
1208 u8 *locator_set_name = 0;
1209 u8 locator_set_name_set = 0;
1210 locator_t locator, *locators = 0;
1211 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1214 memset (&locator, 0, sizeof (locator));
1215 memset (a, 0, sizeof (a[0]));
1217 /* Get a line of input. */
1218 if (!unformat_user (input, unformat_line_input, line_input))
1221 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1223 if (unformat (line_input, "add"))
1225 else if (unformat (line_input, "del"))
1227 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1228 locator_set_name_set = 1;
1229 else if (unformat (line_input, "iface %U p %d w %d",
1230 unformat_vnet_sw_interface, vnm,
1231 &locator.sw_if_index, &locator.priority,
1235 vec_add1 (locators, locator);
1239 error = unformat_parse_error (line_input);
1244 if (!locator_set_name_set)
1246 error = clib_error_return (0, "locator_set name not set!");
1250 a->name = locator_set_name;
1251 a->locators = locators;
1255 vnet_lisp_add_del_locator (a, 0, &ls_index);
1258 vec_free (locators);
1259 vec_free (locator_set_name);
1260 unformat_free (line_input);
1265 VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = {
1266 .path = "one locator",
1267 .short_help = "one locator add/del locator-set <name> iface <iface-name> "
1268 "p <priority> w <weight>",
1269 .function = lisp_add_del_locator_in_set_command_fn,
1273 static clib_error_t *
1274 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1275 unformat_input_t * input,
1276 vlib_cli_command_t * cmd)
1278 locator_set_t *lsit;
1281 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1283 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1284 "Priority", "Weight");
1287 pool_foreach (lsit, lcm->locator_set_pool,
1293 msg = format (msg, "%v", lsit->name);
1297 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1299 vec_foreach (locit, lsit->locator_indices)
1303 msg = format (msg, "%16s", " ");
1305 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1307 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1310 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1311 &gid_address_ip(&loc->address), loc->priority,
1315 vlib_cli_output (vm, "%v", msg);
1323 VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = {
1324 .path = "show one locator-set",
1325 .short_help = "Shows locator-sets",
1326 .function = lisp_cp_show_locator_sets_command_fn,
1331 static clib_error_t *
1332 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1333 unformat_input_t * input,
1334 vlib_cli_command_t * cmd)
1336 unformat_input_t _line_input, *line_input = &_line_input;
1337 u8 is_add = 1, addr_set = 0;
1338 ip_address_t ip_addr;
1339 clib_error_t *error = 0;
1341 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1343 /* Get a line of input. */
1344 if (!unformat_user (input, unformat_line_input, line_input))
1347 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1349 if (unformat (line_input, "add"))
1351 else if (unformat (line_input, "del"))
1353 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1357 error = unformat_parse_error (line_input);
1364 error = clib_error_return (0, "Map-resolver address must be set!");
1369 a->address = ip_addr;
1370 rv = vnet_lisp_add_del_map_resolver (a);
1373 error = clib_error_return (0, "failed to %s map-resolver!",
1374 is_add ? "add" : "delete");
1378 unformat_free (line_input);
1383 VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = {
1384 .path = "one map-resolver",
1385 .short_help = "one map-resolver add/del <ip_address>",
1386 .function = lisp_add_del_map_resolver_command_fn,
1391 static clib_error_t *
1392 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1393 unformat_input_t * input,
1394 vlib_cli_command_t * cmd)
1396 unformat_input_t _line_input, *line_input = &_line_input;
1398 u8 *locator_set_name = 0;
1399 clib_error_t *error = 0;
1401 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1403 /* Get a line of input. */
1404 if (!unformat_user (input, unformat_line_input, line_input))
1407 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1409 if (unformat (line_input, "del"))
1411 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1415 error = unformat_parse_error (line_input);
1421 a->locator_set_name = locator_set_name;
1422 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1425 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1426 is_add ? "add" : "delete");
1430 vec_free (locator_set_name);
1431 unformat_free (line_input);
1437 VLIB_CLI_COMMAND (one_add_del_map_request_command) = {
1438 .path = "one map-request itr-rlocs",
1439 .short_help = "one map-request itr-rlocs add/del <locator_set_name>",
1440 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
1444 static clib_error_t *
1445 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1446 unformat_input_t * input,
1447 vlib_cli_command_t * cmd)
1449 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1450 locator_set_t *loc_set;
1452 vlib_cli_output (vm, "%=20s", "itr-rlocs");
1454 if (~0 == lcm->mreq_itr_rlocs)
1459 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1461 vlib_cli_output (vm, "%=20s", loc_set->name);
1467 VLIB_CLI_COMMAND (one_show_map_request_command) = {
1468 .path = "show one map-request itr-rlocs",
1469 .short_help = "Shows map-request itr-rlocs",
1470 .function = lisp_show_mreq_itr_rlocs_command_fn,
1474 static clib_error_t *
1475 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
1476 unformat_input_t * input,
1477 vlib_cli_command_t * cmd)
1479 u8 is_add = 1, ip_set = 0;
1480 unformat_input_t _line_input, *line_input = &_line_input;
1481 clib_error_t *error = 0;
1484 /* Get a line of input. */
1485 if (!unformat_user (input, unformat_line_input, line_input))
1488 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1490 if (unformat (line_input, "%U", unformat_ip_address, &ip))
1492 else if (unformat (line_input, "disable"))
1496 error = clib_error_return (0, "parse error");
1503 clib_warning ("No petr IP specified!");
1507 if (vnet_lisp_use_petr (&ip, is_add))
1509 error = clib_error_return (0, "failed to %s petr!",
1510 is_add ? "add" : "delete");
1514 unformat_free (line_input);
1519 VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = {
1520 .path = "one use-petr",
1521 .short_help = "one use-petr [disable] <petr-ip>",
1522 .function = lisp_use_petr_set_locator_set_command_fn,
1525 static clib_error_t *
1526 lisp_show_petr_command_fn (vlib_main_t * vm,
1527 unformat_input_t * input, vlib_cli_command_t * cmd)
1529 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1534 u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
1535 vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
1539 vlib_cli_output (vm, "%=20s", "disable");
1543 if (~0 == lcm->petr_map_index)
1545 tmp_str = format (0, "N/A");
1549 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1550 if (~0 != m->locator_set_index)
1552 ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
1553 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
1554 tmp_str = format (0, "%U", format_ip_address, &loc->address);
1558 tmp_str = format (0, "N/A");
1561 vec_add1 (tmp_str, 0);
1563 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1571 VLIB_CLI_COMMAND (one_show_petr_command) = {
1572 .path = "show one petr",
1573 .short_help = "Show petr",
1574 .function = lisp_show_petr_command_fn,
1578 static clib_error_t *
1579 lisp_show_map_servers_command_fn (vlib_main_t * vm,
1580 unformat_input_t * input,
1581 vlib_cli_command_t * cmd)
1584 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1586 vec_foreach (ms, lcm->map_servers)
1588 vlib_cli_output (vm, "%U", format_ip_address, &ms->address);
1594 VLIB_CLI_COMMAND (one_show_map_servers_command) = {
1595 .path = "show one map-servers",
1596 .short_help = "show one map servers",
1597 .function = lisp_show_map_servers_command_fn,
1601 static clib_error_t *
1602 lisp_show_map_register_state_command_fn (vlib_main_t * vm,
1603 unformat_input_t * input,
1604 vlib_cli_command_t * cmd)
1607 u8 is_enabled = vnet_lisp_map_register_state_get ();
1609 msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
1610 vlib_cli_output (vm, "%v", msg);
1616 VLIB_CLI_COMMAND (one_show_map_register_state_command) = {
1617 .path = "show one map-register state",
1618 .short_help = "show one map-register state",
1619 .function = lisp_show_map_register_state_command_fn,
1623 static clib_error_t *
1624 lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm,
1625 unformat_input_t * input,
1626 vlib_cli_command_t * cmd)
1629 u8 is_enabled = vnet_lisp_rloc_probe_state_get ();
1631 msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
1632 vlib_cli_output (vm, "%v", msg);
1638 VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = {
1639 .path = "show one rloc state",
1640 .short_help = "show one RLOC state",
1641 .function = lisp_show_rloc_probe_state_command_fn,
1646 * fd.io coding-style-patch-verification: ON
1649 * eval: (c-set-style "gnu")