2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vnet/lisp-cp/control.h>
17 #include <vnet/lisp-gpe/lisp_gpe.h>
20 lisp_show_adjacencies_command_fn (vlib_main_t * vm,
21 unformat_input_t * input,
22 vlib_cli_command_t * cmd)
24 lisp_adjacency_t *adjs, *adj;
25 vlib_cli_output (vm, "%s %40s\n", "leid", "reid");
26 unformat_input_t _line_input, *line_input = &_line_input;
28 clib_error_t *error = NULL;
30 /* Get a line of input. */
31 if (!unformat_user (input, unformat_line_input, line_input))
34 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
36 if (unformat (line_input, "vni %d", &vni))
40 vlib_cli_output (vm, "parse error: '%U'",
41 format_unformat_error, line_input);
48 vlib_cli_output (vm, "error: no vni specified!");
52 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
54 vec_foreach (adj, adjs)
56 vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid,
57 format_gid_address, &adj->reid);
62 unformat_free (line_input);
68 VLIB_CLI_COMMAND (lisp_show_adjacencies_command) = {
69 .path = "show lisp adjacencies",
70 .short_help = "show lisp adjacencies",
71 .function = lisp_show_adjacencies_command_fn,
76 lisp_add_del_map_server_command_fn (vlib_main_t * vm,
77 unformat_input_t * input,
78 vlib_cli_command_t * cmd)
81 u8 is_add = 1, ip_set = 0;
83 unformat_input_t _line_input, *line_input = &_line_input;
84 clib_error_t *error = NULL;
86 /* Get a line of input. */
87 if (!unformat_user (input, unformat_line_input, line_input))
90 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
92 if (unformat (line_input, "add"))
94 else if (unformat (line_input, "del"))
96 else if (unformat (line_input, "%U", unformat_ip_address, &ip))
100 vlib_cli_output (vm, "parse error: '%U'",
101 format_unformat_error, line_input);
108 vlib_cli_output (vm, "map-server ip address not set!");
112 rv = vnet_lisp_add_del_map_server (&ip, is_add);
114 vlib_cli_output (vm, "failed to %s map-server!",
115 is_add ? "add" : "delete");
118 unformat_free (line_input);
124 VLIB_CLI_COMMAND (lisp_add_del_map_server_command) = {
125 .path = "lisp map-server",
126 .short_help = "lisp map-server add|del <ip>",
127 .function = lisp_add_del_map_server_command_fn,
132 static clib_error_t *
133 lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
134 vlib_cli_command_t * cmd)
136 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
137 unformat_input_t _line_input, *line_input = &_line_input;
140 gid_address_t *eids = 0;
141 clib_error_t *error = 0;
142 u8 *locator_set_name = 0;
143 u32 locator_set_index = 0, map_index = 0;
145 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
151 memset (&eid, 0, sizeof (eid));
152 memset (a, 0, sizeof (*a));
154 /* Get a line of input. */
155 if (!unformat_user (input, unformat_line_input, line_input))
158 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
160 if (unformat (line_input, "add"))
162 else if (unformat (line_input, "del"))
164 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
166 else if (unformat (line_input, "vni %d", &vni))
167 gid_address_vni (&eid) = vni;
168 else if (unformat (line_input, "secret-key %_%v%_", &key))
170 else if (unformat (line_input, "key-id %U", unformat_hmac_key_id,
173 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
175 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
178 error = clib_error_return (0, "locator-set %s doesn't exist",
182 locator_set_index = p[0];
186 error = unformat_parse_error (line_input);
190 /* XXX treat batch configuration */
192 if (GID_ADDR_SRC_DST == gid_address_type (&eid))
195 clib_error_return (0, "src/dst is not supported for local EIDs!");
199 if (key && (0 == key_id))
201 vlib_cli_output (vm, "invalid key_id!");
205 gid_address_copy (&a->eid, &eid);
207 a->locator_set_index = locator_set_index;
212 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
215 error = clib_error_return (0, "failed to %s local mapping!",
216 is_add ? "add" : "delete");
220 if (locator_set_name)
221 vec_free (locator_set_name);
222 gid_address_free (&a->eid);
224 unformat_free (line_input);
230 VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = {
231 .path = "lisp eid-table",
232 .short_help = "lisp eid-table add/del [vni <vni>] eid <eid> "
233 "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]",
234 .function = lisp_add_del_local_eid_command_fn,
238 static clib_error_t *
239 lisp_eid_table_map_command_fn (vlib_main_t * vm,
240 unformat_input_t * input,
241 vlib_cli_command_t * cmd)
243 u8 is_add = 1, is_l2 = 0;
244 u32 vni = 0, dp_id = 0;
245 unformat_input_t _line_input, *line_input = &_line_input;
246 clib_error_t *error = NULL;
248 /* Get a line of input. */
249 if (!unformat_user (input, unformat_line_input, line_input))
252 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
254 if (unformat (line_input, "del"))
256 else if (unformat (line_input, "vni %d", &vni))
258 else if (unformat (line_input, "vrf %d", &dp_id))
260 else if (unformat (line_input, "bd %d", &dp_id))
264 error = unformat_parse_error (line_input);
268 vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
271 unformat_free (line_input);
277 VLIB_CLI_COMMAND (lisp_eid_table_map_command) = {
278 .path = "lisp eid-table map",
279 .short_help = "lisp eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
280 .function = lisp_eid_table_map_command_fn,
285 * Handler for add/del remote mapping CLI.
287 * @param vm vlib context
288 * @param input input from user
290 * @return pointer to clib error structure
292 static clib_error_t *
293 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
294 unformat_input_t * input,
295 vlib_cli_command_t * cmd)
297 clib_error_t *error = 0;
298 unformat_input_t _line_input, *line_input = &_line_input;
299 u8 is_add = 1, del_all = 0;
300 locator_t rloc, *rlocs = 0, *curr_rloc = 0;
303 u32 vni, action = ~0, p, w;
306 /* Get a line of input. */
307 if (!unformat_user (input, unformat_line_input, line_input))
310 memset (&eid, 0, sizeof (eid));
311 memset (&rloc, 0, sizeof (rloc));
313 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
315 if (unformat (line_input, "del-all"))
317 else if (unformat (line_input, "del"))
319 else if (unformat (line_input, "add"))
321 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
323 else if (unformat (line_input, "vni %u", &vni))
325 gid_address_vni (&eid) = vni;
327 else if (unformat (line_input, "p %d w %d", &p, &w))
332 ("No RLOC configured for setting priority/weight!");
335 curr_rloc->priority = p;
336 curr_rloc->weight = w;
338 else if (unformat (line_input, "rloc %U", unformat_ip_address,
339 &gid_address_ip (&rloc.address)))
341 /* since rloc is stored in ip prefix we need to set prefix length */
342 ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
344 u8 version = gid_address_ip_version (&rloc.address);
345 ip_prefix_len (pref) = ip_address_max_len (version);
347 vec_add1 (rlocs, rloc);
348 curr_rloc = &rlocs[vec_len (rlocs) - 1];
350 else if (unformat (line_input, "action %U",
351 unformat_negative_mapping_action, &action))
355 clib_warning ("parse error");
362 clib_warning ("missing eid!");
368 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
370 clib_warning ("no action set for negative map-reply!");
376 vnet_lisp_clear_all_remote_adjacencies ();
380 /* TODO build src/dst with seid */
382 /* if it's a delete, clean forwarding */
385 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
386 memset (a, 0, sizeof (a[0]));
387 gid_address_copy (&a->reid, &eid);
388 if (vnet_lisp_add_del_adjacency (a))
390 clib_warning ("failed to delete adjacency!");
395 /* add as static remote mapping, i.e., not authoritative and infinite
397 rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add,
398 1 /* is_static */ , 0);
401 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
405 unformat_free (line_input);
409 VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) =
411 .path = "lisp remote-mapping",.short_help =
412 "lisp remote-mapping add|del [del-all] vni <vni> "
413 "eid <est-eid> [action <no-action|natively-forward|"
414 "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
415 "[rloc <dst-locator> ... ]",.function =
416 lisp_add_del_remote_mapping_command_fn,};
419 * Handler for add/del adjacency CLI.
421 static clib_error_t *
422 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
423 vlib_cli_command_t * cmd)
425 clib_error_t *error = 0;
426 unformat_input_t _line_input, *line_input = &_line_input;
427 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
429 ip_prefix_t *reid_ippref, *leid_ippref;
430 gid_address_t leid, reid;
431 u8 *dmac = gid_address_mac (&reid);
432 u8 *smac = gid_address_mac (&leid);
433 u8 reid_set = 0, leid_set = 0;
436 /* Get a line of input. */
437 if (!unformat_user (input, unformat_line_input, line_input))
440 memset (&reid, 0, sizeof (reid));
441 memset (&leid, 0, sizeof (leid));
443 leid_ippref = &gid_address_ippref (&leid);
444 reid_ippref = &gid_address_ippref (&reid);
446 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
448 if (unformat (line_input, "del"))
450 else if (unformat (line_input, "add"))
452 else if (unformat (line_input, "reid %U",
453 unformat_ip_prefix, reid_ippref))
455 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
458 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
460 gid_address_type (&reid) = GID_ADDR_MAC;
463 else if (unformat (line_input, "vni %u", &vni))
465 gid_address_vni (&leid) = vni;
466 gid_address_vni (&reid) = vni;
468 else if (unformat (line_input, "leid %U",
469 unformat_ip_prefix, leid_ippref))
471 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
474 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
476 gid_address_type (&leid) = GID_ADDR_MAC;
481 clib_warning ("parse error");
486 if (!reid_set || !leid_set)
488 clib_warning ("missing remote or local eid!");
492 if ((gid_address_type (&leid) != gid_address_type (&reid))
493 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
494 && ip_prefix_version (reid_ippref)
495 != ip_prefix_version (leid_ippref)))
497 clib_warning ("remote and local EIDs are of different types!");
501 memset (a, 0, sizeof (a[0]));
502 gid_address_copy (&a->leid, &leid);
503 gid_address_copy (&a->reid, &reid);
506 if (vnet_lisp_add_del_adjacency (a))
507 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
510 unformat_free (line_input);
515 VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = {
516 .path = "lisp adjacency",
517 .short_help = "lisp adjacency add|del vni <vni> reid <remote-eid> "
519 .function = lisp_add_del_adjacency_command_fn,
524 static clib_error_t *
525 lisp_map_request_mode_command_fn (vlib_main_t * vm,
526 unformat_input_t * input,
527 vlib_cli_command_t * cmd)
529 unformat_input_t _i, *i = &_i;
530 map_request_mode_t mr_mode = _MR_MODE_MAX;
531 clib_error_t *error = NULL;
533 /* Get a line of input. */
534 if (!unformat_user (input, unformat_line_input, i))
537 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
539 if (unformat (i, "dst-only"))
540 mr_mode = MR_MODE_DST_ONLY;
541 else if (unformat (i, "src-dst"))
542 mr_mode = MR_MODE_SRC_DST;
545 clib_warning ("parse error '%U'", format_unformat_error, i);
550 if (_MR_MODE_MAX == mr_mode)
552 clib_warning ("No LISP map request mode entered!");
556 vnet_lisp_set_map_request_mode (mr_mode);
565 VLIB_CLI_COMMAND (lisp_map_request_mode_command) = {
566 .path = "lisp map-request mode",
567 .short_help = "lisp map-request mode dst-only|src-dst",
568 .function = lisp_map_request_mode_command_fn,
574 format_lisp_map_request_mode (u8 * s, va_list * args)
576 u32 mode = va_arg (*args, u32);
581 return format (0, "dst-only");
583 return format (0, "src-dst");
588 static clib_error_t *
589 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
590 unformat_input_t * input,
591 vlib_cli_command_t * cmd)
593 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
594 vnet_lisp_get_map_request_mode ());
599 VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = {
600 .path = "show lisp map-request mode",
601 .short_help = "show lisp map-request mode",
602 .function = lisp_show_map_request_mode_command_fn,
606 static clib_error_t *
607 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
608 unformat_input_t * input,
609 vlib_cli_command_t * cmd)
612 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
614 vec_foreach (mr, lcm->map_resolvers)
616 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
622 VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = {
623 .path = "show lisp map-resolvers",
624 .short_help = "show lisp map-resolvers",
625 .function = lisp_show_map_resolvers_command_fn,
630 static clib_error_t *
631 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
632 unformat_input_t * input,
633 vlib_cli_command_t * cmd)
635 u8 locator_name_set = 0;
636 u8 *locator_set_name = 0;
638 unformat_input_t _line_input, *line_input = &_line_input;
639 clib_error_t *error = 0;
642 /* Get a line of input. */
643 if (!unformat_user (input, unformat_line_input, line_input))
646 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
648 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
649 locator_name_set = 1;
650 else if (unformat (line_input, "disable"))
654 error = clib_error_return (0, "parse error");
659 if (!locator_name_set)
661 clib_warning ("No locator set specified!");
664 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
667 error = clib_error_return (0, "failed to %s pitr!",
668 is_add ? "add" : "delete");
672 if (locator_set_name)
673 vec_free (locator_set_name);
674 unformat_free (line_input);
680 VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = {
682 .short_help = "lisp pitr [disable] ls <locator-set-name>",
683 .function = lisp_pitr_set_locator_set_command_fn,
687 static clib_error_t *
688 lisp_show_pitr_command_fn (vlib_main_t * vm,
689 unformat_input_t * input, vlib_cli_command_t * cmd)
691 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
696 vlib_cli_output (vm, "%=20s%=16s",
697 "pitr", lcm->lisp_pitr ? "locator-set" : "");
701 vlib_cli_output (vm, "%=20s", "disable");
705 if (~0 == lcm->pitr_map_index)
707 tmp_str = format (0, "N/A");
711 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
712 if (~0 != m->locator_set_index)
715 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
716 tmp_str = format (0, "%s", ls->name);
720 tmp_str = format (0, "N/A");
723 vec_add1 (tmp_str, 0);
725 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
733 VLIB_CLI_COMMAND (lisp_show_pitr_command) = {
734 .path = "show lisp pitr",
735 .short_help = "Show pitr",
736 .function = lisp_show_pitr_command_fn,
741 format_eid_entry (u8 * s, va_list * args)
743 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
744 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
745 mapping_t *mapit = va_arg (*args, mapping_t *);
746 locator_set_t *ls = va_arg (*args, locator_set_t *);
747 gid_address_t *gid = &mapit->eid;
748 u32 ttl = mapit->ttl;
749 u8 aut = mapit->authoritative;
754 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
755 : format (0, "remote");
757 if (vec_len (ls->locator_indices) == 0)
759 s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
764 vec_foreach (loc_index, ls->locator_indices)
766 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
768 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
771 loc = format (0, "%U", format_ip_address,
772 &gid_address_ip (&l->address));
776 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
777 gid, type, loc, ttl, aut);
781 s = format (s, "%55s%v\n", "", loc);
787 static clib_error_t *
788 lisp_show_eid_table_command_fn (vlib_main_t * vm,
789 unformat_input_t * input,
790 vlib_cli_command_t * cmd)
792 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
794 unformat_input_t _line_input, *line_input = &_line_input;
799 clib_error_t *error = NULL;
801 memset (&eid, 0, sizeof (eid));
803 /* Get a line of input. */
804 if (!unformat_user (input, unformat_line_input, line_input))
807 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
809 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
811 else if (unformat (line_input, "local"))
813 else if (unformat (line_input, "remote"))
817 error = clib_error_return (0, "parse error: '%U'",
818 format_unformat_error, line_input);
823 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
824 "EID", "type", "locators", "ttl", "autoritative");
829 pool_foreach (mapit, lcm->mapping_pool,
834 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
835 mapit->locator_set_index);
836 if (filter && !((1 == filter && ls->local) ||
837 (2 == filter && !ls->local)))
841 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
848 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
852 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
853 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
854 mapit->locator_set_index);
856 if (filter && !((1 == filter && ls->local) ||
857 (2 == filter && !ls->local)))
862 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
867 unformat_free (line_input);
873 VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = {
874 .path = "show lisp eid-table",
875 .short_help = "Shows EID table",
876 .function = lisp_show_eid_table_command_fn,
881 static clib_error_t *
882 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
883 vlib_cli_command_t * cmd)
885 unformat_input_t _line_input, *line_input = &_line_input;
888 clib_error_t *error = NULL;
890 /* Get a line of input. */
891 if (!unformat_user (input, unformat_line_input, line_input))
894 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
896 if (unformat (line_input, "enable"))
901 else if (unformat (line_input, "disable"))
905 error = clib_error_return (0, "parse error: '%U'",
906 format_unformat_error, line_input);
913 error = clib_error_return (0, "state not set");
917 vnet_lisp_enable_disable (is_enabled);
920 unformat_free (line_input);
926 VLIB_CLI_COMMAND (lisp_cp_enable_disable_command) = {
928 .short_help = "lisp [enable|disable]",
929 .function = lisp_enable_disable_command_fn,
933 static clib_error_t *
934 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
935 unformat_input_t * input,
936 vlib_cli_command_t * cmd)
938 unformat_input_t _line_input, *line_input = &_line_input;
941 clib_error_t *error = NULL;
943 /* Get a line of input. */
944 if (!unformat_user (input, unformat_line_input, line_input))
947 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
949 if (unformat (line_input, "enable"))
954 else if (unformat (line_input, "disable"))
958 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
966 vlib_cli_output (vm, "state not set!");
970 vnet_lisp_map_register_enable_disable (is_enabled);
973 unformat_free (line_input);
979 VLIB_CLI_COMMAND (lisp_map_register_enable_disable_command) = {
980 .path = "lisp map-register",
981 .short_help = "lisp map-register [enable|disable]",
982 .function = lisp_map_register_enable_disable_command_fn,
986 static clib_error_t *
987 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
988 unformat_input_t * input,
989 vlib_cli_command_t * cmd)
991 unformat_input_t _line_input, *line_input = &_line_input;
994 clib_error_t *error = NULL;
996 /* Get a line of input. */
997 if (!unformat_user (input, unformat_line_input, line_input))
1000 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1002 if (unformat (line_input, "enable"))
1007 else if (unformat (line_input, "disable"))
1011 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1019 vlib_cli_output (vm, "state not set!");
1023 vnet_lisp_rloc_probe_enable_disable (is_enabled);
1026 unformat_free (line_input);
1032 VLIB_CLI_COMMAND (lisp_rloc_probe_enable_disable_command) = {
1033 .path = "lisp rloc-probe",
1034 .short_help = "lisp rloc-probe [enable|disable]",
1035 .function = lisp_rloc_probe_enable_disable_command_fn,
1040 format_lisp_status (u8 * s, va_list * args)
1042 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1043 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
1046 static clib_error_t *
1047 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
1048 vlib_cli_command_t * cmd)
1051 msg = format (msg, "feature: %U\ngpe: %U\n",
1052 format_lisp_status, format_vnet_lisp_gpe_status);
1053 vlib_cli_output (vm, "%v", msg);
1059 VLIB_CLI_COMMAND (lisp_show_status_command) = {
1060 .path = "show lisp status",
1061 .short_help = "show lisp status",
1062 .function = lisp_show_status_command_fn,
1066 static clib_error_t *
1067 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1068 unformat_input_t * input,
1069 vlib_cli_command_t * cmd)
1072 unformat_input_t _line_input, *line_input = &_line_input;
1073 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1074 uword *vni_table = 0;
1076 clib_error_t *error = NULL;
1078 /* Get a line of input. */
1079 if (!unformat_user (input, unformat_line_input, line_input))
1082 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1084 if (unformat (line_input, "l2"))
1086 vni_table = lcm->bd_id_by_vni;
1089 else if (unformat (line_input, "l3"))
1091 vni_table = lcm->table_id_by_vni;
1096 error = clib_error_return (0, "parse error: '%U'",
1097 format_unformat_error, line_input);
1104 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1108 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1111 hash_foreach_pair (p, vni_table,
1113 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1118 unformat_free (line_input);
1124 VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = {
1125 .path = "show lisp eid-table map",
1126 .short_help = "show lisp eid-table l2|l3",
1127 .function = lisp_show_eid_table_map_command_fn,
1132 static clib_error_t *
1133 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1134 unformat_input_t * input,
1135 vlib_cli_command_t * cmd)
1137 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1138 vnet_main_t *vnm = lgm->vnet_main;
1139 unformat_input_t _line_input, *line_input = &_line_input;
1141 clib_error_t *error = 0;
1142 u8 *locator_set_name = 0;
1143 locator_t locator, *locators = 0;
1144 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1148 memset (&locator, 0, sizeof (locator));
1149 memset (a, 0, sizeof (a[0]));
1151 /* Get a line of input. */
1152 if (!unformat_user (input, unformat_line_input, line_input))
1155 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1157 if (unformat (line_input, "add %_%v%_", &locator_set_name))
1159 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1161 else if (unformat (line_input, "iface %U p %d w %d",
1162 unformat_vnet_sw_interface, vnm,
1163 &locator.sw_if_index, &locator.priority,
1167 vec_add1 (locators, locator);
1171 error = unformat_parse_error (line_input);
1176 a->name = locator_set_name;
1177 a->locators = locators;
1181 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1184 error = clib_error_return (0, "failed to %s locator-set!",
1185 is_add ? "add" : "delete");
1189 vec_free (locators);
1190 if (locator_set_name)
1191 vec_free (locator_set_name);
1192 unformat_free (line_input);
1198 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = {
1199 .path = "lisp locator-set",
1200 .short_help = "lisp locator-set add/del <name> [iface <iface-name> "
1201 "p <priority> w <weight>]",
1202 .function = lisp_add_del_locator_set_command_fn,
1206 static clib_error_t *
1207 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1208 unformat_input_t * input,
1209 vlib_cli_command_t * cmd)
1211 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1212 vnet_main_t *vnm = lgm->vnet_main;
1213 unformat_input_t _line_input, *line_input = &_line_input;
1215 clib_error_t *error = 0;
1216 u8 *locator_set_name = 0;
1217 u8 locator_set_name_set = 0;
1218 locator_t locator, *locators = 0;
1219 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1222 memset (&locator, 0, sizeof (locator));
1223 memset (a, 0, sizeof (a[0]));
1225 /* Get a line of input. */
1226 if (!unformat_user (input, unformat_line_input, line_input))
1229 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1231 if (unformat (line_input, "add"))
1233 else if (unformat (line_input, "del"))
1235 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1236 locator_set_name_set = 1;
1237 else if (unformat (line_input, "iface %U p %d w %d",
1238 unformat_vnet_sw_interface, vnm,
1239 &locator.sw_if_index, &locator.priority,
1243 vec_add1 (locators, locator);
1247 error = unformat_parse_error (line_input);
1252 if (!locator_set_name_set)
1254 error = clib_error_return (0, "locator_set name not set!");
1258 a->name = locator_set_name;
1259 a->locators = locators;
1263 vnet_lisp_add_del_locator (a, 0, &ls_index);
1266 vec_free (locators);
1267 vec_free (locator_set_name);
1268 unformat_free (line_input);
1274 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = {
1275 .path = "lisp locator",
1276 .short_help = "lisp locator add/del locator-set <name> iface <iface-name> "
1277 "p <priority> w <weight>",
1278 .function = lisp_add_del_locator_in_set_command_fn,
1282 static clib_error_t *
1283 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1284 unformat_input_t * input,
1285 vlib_cli_command_t * cmd)
1287 locator_set_t *lsit;
1290 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1292 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1293 "Priority", "Weight");
1296 pool_foreach (lsit, lcm->locator_set_pool,
1302 msg = format (msg, "%v", lsit->name);
1306 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1308 vec_foreach (locit, lsit->locator_indices)
1312 msg = format (msg, "%16s", " ");
1314 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1316 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1319 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1320 &gid_address_ip(&loc->address), loc->priority,
1324 vlib_cli_output (vm, "%v", msg);
1332 VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = {
1333 .path = "show lisp locator-set",
1334 .short_help = "Shows locator-sets",
1335 .function = lisp_cp_show_locator_sets_command_fn,
1340 static clib_error_t *
1341 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1342 unformat_input_t * input,
1343 vlib_cli_command_t * cmd)
1345 unformat_input_t _line_input, *line_input = &_line_input;
1346 u8 is_add = 1, addr_set = 0;
1347 ip_address_t ip_addr;
1348 clib_error_t *error = 0;
1350 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1352 /* Get a line of input. */
1353 if (!unformat_user (input, unformat_line_input, line_input))
1356 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1358 if (unformat (line_input, "add"))
1360 else if (unformat (line_input, "del"))
1362 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1366 error = unformat_parse_error (line_input);
1373 error = clib_error_return (0, "Map-resolver address must be set!");
1378 a->address = ip_addr;
1379 rv = vnet_lisp_add_del_map_resolver (a);
1382 error = clib_error_return (0, "failed to %s map-resolver!",
1383 is_add ? "add" : "delete");
1387 unformat_free (line_input);
1393 VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = {
1394 .path = "lisp map-resolver",
1395 .short_help = "lisp map-resolver add/del <ip_address>",
1396 .function = lisp_add_del_map_resolver_command_fn,
1401 static clib_error_t *
1402 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1403 unformat_input_t * input,
1404 vlib_cli_command_t * cmd)
1406 unformat_input_t _line_input, *line_input = &_line_input;
1408 u8 *locator_set_name = 0;
1409 clib_error_t *error = 0;
1411 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1413 /* Get a line of input. */
1414 if (!unformat_user (input, unformat_line_input, line_input))
1417 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1419 if (unformat (line_input, "del"))
1421 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1425 error = unformat_parse_error (line_input);
1431 a->locator_set_name = locator_set_name;
1432 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1435 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1436 is_add ? "add" : "delete");
1440 vec_free (locator_set_name);
1441 unformat_free (line_input);
1447 VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = {
1448 .path = "lisp map-request itr-rlocs",
1449 .short_help = "lisp map-request itr-rlocs add/del <locator_set_name>",
1450 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
1454 static clib_error_t *
1455 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1456 unformat_input_t * input,
1457 vlib_cli_command_t * cmd)
1459 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1460 locator_set_t *loc_set;
1462 vlib_cli_output (vm, "%=20s", "itr-rlocs");
1464 if (~0 == lcm->mreq_itr_rlocs)
1469 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1471 vlib_cli_output (vm, "%=20s", loc_set->name);
1477 VLIB_CLI_COMMAND (lisp_show_map_request_command) = {
1478 .path = "show lisp map-request itr-rlocs",
1479 .short_help = "Shows map-request itr-rlocs",
1480 .function = lisp_show_mreq_itr_rlocs_command_fn,
1484 static clib_error_t *
1485 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
1486 unformat_input_t * input,
1487 vlib_cli_command_t * cmd)
1489 u8 is_add = 1, ip_set = 0;
1490 unformat_input_t _line_input, *line_input = &_line_input;
1491 clib_error_t *error = 0;
1494 /* Get a line of input. */
1495 if (!unformat_user (input, unformat_line_input, line_input))
1498 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1500 if (unformat (line_input, "%U", unformat_ip_address, &ip))
1502 else if (unformat (line_input, "disable"))
1506 error = clib_error_return (0, "parse error");
1513 clib_warning ("No petr IP specified!");
1517 if (vnet_lisp_use_petr (&ip, is_add))
1519 error = clib_error_return (0, "failed to %s petr!",
1520 is_add ? "add" : "delete");
1524 unformat_free (line_input);
1530 VLIB_CLI_COMMAND (lisp_use_petr_set_locator_set_command) = {
1531 .path = "lisp use-petr",
1532 .short_help = "lisp use-petr [disable] <petr-ip>",
1533 .function = lisp_use_petr_set_locator_set_command_fn,
1536 static clib_error_t *
1537 lisp_show_petr_command_fn (vlib_main_t * vm,
1538 unformat_input_t * input, vlib_cli_command_t * cmd)
1540 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1545 u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
1546 vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
1550 vlib_cli_output (vm, "%=20s", "disable");
1554 if (~0 == lcm->petr_map_index)
1556 tmp_str = format (0, "N/A");
1560 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1561 if (~0 != m->locator_set_index)
1563 ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
1564 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
1565 tmp_str = format (0, "%U", format_ip_address, &loc->address);
1569 tmp_str = format (0, "N/A");
1572 vec_add1 (tmp_str, 0);
1574 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1582 VLIB_CLI_COMMAND (lisp_show_petr_command) = {
1583 .path = "show lisp petr",
1584 .short_help = "Show petr",
1585 .function = lisp_show_petr_command_fn,
1590 * fd.io coding-style-patch-verification: ON
1593 * eval: (c-set-style "gnu")