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
399 vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args;
400 memset (map_args, 0, sizeof (map_args[0]));
401 gid_address_copy (&map_args->eid, &eid);
402 map_args->action = action;
403 map_args->is_static = 1;
404 map_args->authoritative = 0;
406 rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL);
409 rv = vnet_lisp_del_mapping (&eid, NULL);
412 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
416 unformat_free (line_input);
420 VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) =
422 .path = "lisp remote-mapping",.short_help =
423 "lisp remote-mapping add|del [del-all] vni <vni> "
424 "eid <est-eid> [action <no-action|natively-forward|"
425 "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
426 "[rloc <dst-locator> ... ]",.function =
427 lisp_add_del_remote_mapping_command_fn,};
430 * Handler for add/del adjacency CLI.
432 static clib_error_t *
433 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
434 vlib_cli_command_t * cmd)
436 clib_error_t *error = 0;
437 unformat_input_t _line_input, *line_input = &_line_input;
438 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
440 ip_prefix_t *reid_ippref, *leid_ippref;
441 gid_address_t leid, reid;
442 u8 *dmac = gid_address_mac (&reid);
443 u8 *smac = gid_address_mac (&leid);
444 u8 reid_set = 0, leid_set = 0;
447 /* Get a line of input. */
448 if (!unformat_user (input, unformat_line_input, line_input))
451 memset (&reid, 0, sizeof (reid));
452 memset (&leid, 0, sizeof (leid));
454 leid_ippref = &gid_address_ippref (&leid);
455 reid_ippref = &gid_address_ippref (&reid);
457 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
459 if (unformat (line_input, "del"))
461 else if (unformat (line_input, "add"))
463 else if (unformat (line_input, "reid %U",
464 unformat_ip_prefix, reid_ippref))
466 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
469 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
471 gid_address_type (&reid) = GID_ADDR_MAC;
474 else if (unformat (line_input, "vni %u", &vni))
476 gid_address_vni (&leid) = vni;
477 gid_address_vni (&reid) = vni;
479 else if (unformat (line_input, "leid %U",
480 unformat_ip_prefix, leid_ippref))
482 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
485 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
487 gid_address_type (&leid) = GID_ADDR_MAC;
492 clib_warning ("parse error");
497 if (!reid_set || !leid_set)
499 clib_warning ("missing remote or local eid!");
503 if ((gid_address_type (&leid) != gid_address_type (&reid))
504 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
505 && ip_prefix_version (reid_ippref)
506 != ip_prefix_version (leid_ippref)))
508 clib_warning ("remote and local EIDs are of different types!");
512 memset (a, 0, sizeof (a[0]));
513 gid_address_copy (&a->leid, &leid);
514 gid_address_copy (&a->reid, &reid);
517 if (vnet_lisp_add_del_adjacency (a))
518 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
521 unformat_free (line_input);
526 VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = {
527 .path = "lisp adjacency",
528 .short_help = "lisp adjacency add|del vni <vni> reid <remote-eid> "
530 .function = lisp_add_del_adjacency_command_fn,
535 static clib_error_t *
536 lisp_map_request_mode_command_fn (vlib_main_t * vm,
537 unformat_input_t * input,
538 vlib_cli_command_t * cmd)
540 unformat_input_t _i, *i = &_i;
541 map_request_mode_t mr_mode = _MR_MODE_MAX;
542 clib_error_t *error = NULL;
544 /* Get a line of input. */
545 if (!unformat_user (input, unformat_line_input, i))
548 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
550 if (unformat (i, "dst-only"))
551 mr_mode = MR_MODE_DST_ONLY;
552 else if (unformat (i, "src-dst"))
553 mr_mode = MR_MODE_SRC_DST;
556 clib_warning ("parse error '%U'", format_unformat_error, i);
561 if (_MR_MODE_MAX == mr_mode)
563 clib_warning ("No LISP map request mode entered!");
567 vnet_lisp_set_map_request_mode (mr_mode);
576 VLIB_CLI_COMMAND (lisp_map_request_mode_command) = {
577 .path = "lisp map-request mode",
578 .short_help = "lisp map-request mode dst-only|src-dst",
579 .function = lisp_map_request_mode_command_fn,
585 format_lisp_map_request_mode (u8 * s, va_list * args)
587 u32 mode = va_arg (*args, u32);
592 return format (0, "dst-only");
594 return format (0, "src-dst");
599 static clib_error_t *
600 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
601 unformat_input_t * input,
602 vlib_cli_command_t * cmd)
604 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
605 vnet_lisp_get_map_request_mode ());
610 VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = {
611 .path = "show lisp map-request mode",
612 .short_help = "show lisp map-request mode",
613 .function = lisp_show_map_request_mode_command_fn,
617 static clib_error_t *
618 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
619 unformat_input_t * input,
620 vlib_cli_command_t * cmd)
623 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
625 vec_foreach (mr, lcm->map_resolvers)
627 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
633 VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = {
634 .path = "show lisp map-resolvers",
635 .short_help = "show lisp map-resolvers",
636 .function = lisp_show_map_resolvers_command_fn,
641 static clib_error_t *
642 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
643 unformat_input_t * input,
644 vlib_cli_command_t * cmd)
646 u8 locator_name_set = 0;
647 u8 *locator_set_name = 0;
649 unformat_input_t _line_input, *line_input = &_line_input;
650 clib_error_t *error = 0;
653 /* Get a line of input. */
654 if (!unformat_user (input, unformat_line_input, line_input))
657 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
659 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
660 locator_name_set = 1;
661 else if (unformat (line_input, "disable"))
665 error = clib_error_return (0, "parse error");
670 if (!locator_name_set)
672 clib_warning ("No locator set specified!");
675 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
678 error = clib_error_return (0, "failed to %s pitr!",
679 is_add ? "add" : "delete");
683 if (locator_set_name)
684 vec_free (locator_set_name);
685 unformat_free (line_input);
691 VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = {
693 .short_help = "lisp pitr [disable] ls <locator-set-name>",
694 .function = lisp_pitr_set_locator_set_command_fn,
698 static clib_error_t *
699 lisp_show_pitr_command_fn (vlib_main_t * vm,
700 unformat_input_t * input, vlib_cli_command_t * cmd)
702 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
707 vlib_cli_output (vm, "%=20s%=16s",
708 "pitr", lcm->lisp_pitr ? "locator-set" : "");
712 vlib_cli_output (vm, "%=20s", "disable");
716 if (~0 == lcm->pitr_map_index)
718 tmp_str = format (0, "N/A");
722 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
723 if (~0 != m->locator_set_index)
726 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
727 tmp_str = format (0, "%s", ls->name);
731 tmp_str = format (0, "N/A");
734 vec_add1 (tmp_str, 0);
736 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
744 VLIB_CLI_COMMAND (lisp_show_pitr_command) = {
745 .path = "show lisp pitr",
746 .short_help = "Show pitr",
747 .function = lisp_show_pitr_command_fn,
752 format_eid_entry (u8 * s, va_list * args)
754 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
755 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
756 mapping_t *mapit = va_arg (*args, mapping_t *);
757 locator_set_t *ls = va_arg (*args, locator_set_t *);
758 gid_address_t *gid = &mapit->eid;
759 u32 ttl = mapit->ttl;
760 u8 aut = mapit->authoritative;
765 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
766 : format (0, "remote");
768 if (vec_len (ls->locator_indices) == 0)
770 s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
775 vec_foreach (loc_index, ls->locator_indices)
777 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
779 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
782 loc = format (0, "%U", format_ip_address,
783 &gid_address_ip (&l->address));
787 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
788 gid, type, loc, ttl, aut);
792 s = format (s, "%55s%v\n", "", loc);
798 static clib_error_t *
799 lisp_show_eid_table_command_fn (vlib_main_t * vm,
800 unformat_input_t * input,
801 vlib_cli_command_t * cmd)
803 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
805 unformat_input_t _line_input, *line_input = &_line_input;
810 clib_error_t *error = NULL;
812 memset (&eid, 0, sizeof (eid));
814 /* Get a line of input. */
815 if (!unformat_user (input, unformat_line_input, line_input))
818 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
820 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
822 else if (unformat (line_input, "local"))
824 else if (unformat (line_input, "remote"))
828 error = clib_error_return (0, "parse error: '%U'",
829 format_unformat_error, line_input);
834 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
835 "EID", "type", "locators", "ttl", "autoritative");
840 pool_foreach (mapit, lcm->mapping_pool,
845 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
846 mapit->locator_set_index);
847 if (filter && !((1 == filter && ls->local) ||
848 (2 == filter && !ls->local)))
852 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
859 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
863 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
864 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
865 mapit->locator_set_index);
867 if (filter && !((1 == filter && ls->local) ||
868 (2 == filter && !ls->local)))
873 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
878 unformat_free (line_input);
884 VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = {
885 .path = "show lisp eid-table",
886 .short_help = "Shows EID table",
887 .function = lisp_show_eid_table_command_fn,
892 static clib_error_t *
893 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
894 vlib_cli_command_t * cmd)
896 unformat_input_t _line_input, *line_input = &_line_input;
899 clib_error_t *error = NULL;
901 /* Get a line of input. */
902 if (!unformat_user (input, unformat_line_input, line_input))
905 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
907 if (unformat (line_input, "enable"))
912 else if (unformat (line_input, "disable"))
916 error = clib_error_return (0, "parse error: '%U'",
917 format_unformat_error, line_input);
924 error = clib_error_return (0, "state not set");
928 vnet_lisp_enable_disable (is_enabled);
931 unformat_free (line_input);
937 VLIB_CLI_COMMAND (lisp_cp_enable_disable_command) = {
939 .short_help = "lisp [enable|disable]",
940 .function = lisp_enable_disable_command_fn,
944 static clib_error_t *
945 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
946 unformat_input_t * input,
947 vlib_cli_command_t * cmd)
949 unformat_input_t _line_input, *line_input = &_line_input;
952 clib_error_t *error = NULL;
954 /* Get a line of input. */
955 if (!unformat_user (input, unformat_line_input, line_input))
958 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
960 if (unformat (line_input, "enable"))
965 else if (unformat (line_input, "disable"))
969 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
977 vlib_cli_output (vm, "state not set!");
981 vnet_lisp_map_register_enable_disable (is_enabled);
984 unformat_free (line_input);
990 VLIB_CLI_COMMAND (lisp_map_register_enable_disable_command) = {
991 .path = "lisp map-register",
992 .short_help = "lisp map-register [enable|disable]",
993 .function = lisp_map_register_enable_disable_command_fn,
997 static clib_error_t *
998 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
999 unformat_input_t * input,
1000 vlib_cli_command_t * cmd)
1002 unformat_input_t _line_input, *line_input = &_line_input;
1005 clib_error_t *error = NULL;
1007 /* Get a line of input. */
1008 if (!unformat_user (input, unformat_line_input, line_input))
1011 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1013 if (unformat (line_input, "enable"))
1018 else if (unformat (line_input, "disable"))
1022 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1030 vlib_cli_output (vm, "state not set!");
1034 vnet_lisp_rloc_probe_enable_disable (is_enabled);
1037 unformat_free (line_input);
1043 VLIB_CLI_COMMAND (lisp_rloc_probe_enable_disable_command) = {
1044 .path = "lisp rloc-probe",
1045 .short_help = "lisp rloc-probe [enable|disable]",
1046 .function = lisp_rloc_probe_enable_disable_command_fn,
1051 format_lisp_status (u8 * s, va_list * args)
1053 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1054 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
1057 static clib_error_t *
1058 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
1059 vlib_cli_command_t * cmd)
1062 msg = format (msg, "feature: %U\ngpe: %U\n",
1063 format_lisp_status, format_vnet_lisp_gpe_status);
1064 vlib_cli_output (vm, "%v", msg);
1070 VLIB_CLI_COMMAND (lisp_show_status_command) = {
1071 .path = "show lisp status",
1072 .short_help = "show lisp status",
1073 .function = lisp_show_status_command_fn,
1077 static clib_error_t *
1078 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1079 unformat_input_t * input,
1080 vlib_cli_command_t * cmd)
1083 unformat_input_t _line_input, *line_input = &_line_input;
1084 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1085 uword *vni_table = 0;
1087 clib_error_t *error = NULL;
1089 /* Get a line of input. */
1090 if (!unformat_user (input, unformat_line_input, line_input))
1093 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1095 if (unformat (line_input, "l2"))
1097 vni_table = lcm->bd_id_by_vni;
1100 else if (unformat (line_input, "l3"))
1102 vni_table = lcm->table_id_by_vni;
1107 error = clib_error_return (0, "parse error: '%U'",
1108 format_unformat_error, line_input);
1115 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1119 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1122 hash_foreach_pair (p, vni_table,
1124 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1129 unformat_free (line_input);
1135 VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = {
1136 .path = "show lisp eid-table map",
1137 .short_help = "show lisp eid-table l2|l3",
1138 .function = lisp_show_eid_table_map_command_fn,
1143 static clib_error_t *
1144 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1145 unformat_input_t * input,
1146 vlib_cli_command_t * cmd)
1148 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1149 vnet_main_t *vnm = lgm->vnet_main;
1150 unformat_input_t _line_input, *line_input = &_line_input;
1152 clib_error_t *error = 0;
1153 u8 *locator_set_name = 0;
1154 locator_t locator, *locators = 0;
1155 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1159 memset (&locator, 0, sizeof (locator));
1160 memset (a, 0, sizeof (a[0]));
1162 /* Get a line of input. */
1163 if (!unformat_user (input, unformat_line_input, line_input))
1166 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1168 if (unformat (line_input, "add %_%v%_", &locator_set_name))
1170 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1172 else if (unformat (line_input, "iface %U p %d w %d",
1173 unformat_vnet_sw_interface, vnm,
1174 &locator.sw_if_index, &locator.priority,
1178 vec_add1 (locators, locator);
1182 error = unformat_parse_error (line_input);
1187 a->name = locator_set_name;
1188 a->locators = locators;
1192 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1195 error = clib_error_return (0, "failed to %s locator-set!",
1196 is_add ? "add" : "delete");
1200 vec_free (locators);
1201 if (locator_set_name)
1202 vec_free (locator_set_name);
1203 unformat_free (line_input);
1209 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = {
1210 .path = "lisp locator-set",
1211 .short_help = "lisp locator-set add/del <name> [iface <iface-name> "
1212 "p <priority> w <weight>]",
1213 .function = lisp_add_del_locator_set_command_fn,
1217 static clib_error_t *
1218 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1219 unformat_input_t * input,
1220 vlib_cli_command_t * cmd)
1222 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1223 vnet_main_t *vnm = lgm->vnet_main;
1224 unformat_input_t _line_input, *line_input = &_line_input;
1226 clib_error_t *error = 0;
1227 u8 *locator_set_name = 0;
1228 u8 locator_set_name_set = 0;
1229 locator_t locator, *locators = 0;
1230 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1233 memset (&locator, 0, sizeof (locator));
1234 memset (a, 0, sizeof (a[0]));
1236 /* Get a line of input. */
1237 if (!unformat_user (input, unformat_line_input, line_input))
1240 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1242 if (unformat (line_input, "add"))
1244 else if (unformat (line_input, "del"))
1246 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1247 locator_set_name_set = 1;
1248 else if (unformat (line_input, "iface %U p %d w %d",
1249 unformat_vnet_sw_interface, vnm,
1250 &locator.sw_if_index, &locator.priority,
1254 vec_add1 (locators, locator);
1258 error = unformat_parse_error (line_input);
1263 if (!locator_set_name_set)
1265 error = clib_error_return (0, "locator_set name not set!");
1269 a->name = locator_set_name;
1270 a->locators = locators;
1274 vnet_lisp_add_del_locator (a, 0, &ls_index);
1277 vec_free (locators);
1278 vec_free (locator_set_name);
1279 unformat_free (line_input);
1285 VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = {
1286 .path = "lisp locator",
1287 .short_help = "lisp locator add/del locator-set <name> iface <iface-name> "
1288 "p <priority> w <weight>",
1289 .function = lisp_add_del_locator_in_set_command_fn,
1293 static clib_error_t *
1294 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1295 unformat_input_t * input,
1296 vlib_cli_command_t * cmd)
1298 locator_set_t *lsit;
1301 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1303 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1304 "Priority", "Weight");
1307 pool_foreach (lsit, lcm->locator_set_pool,
1313 msg = format (msg, "%v", lsit->name);
1317 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1319 vec_foreach (locit, lsit->locator_indices)
1323 msg = format (msg, "%16s", " ");
1325 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1327 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1330 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1331 &gid_address_ip(&loc->address), loc->priority,
1335 vlib_cli_output (vm, "%v", msg);
1343 VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = {
1344 .path = "show lisp locator-set",
1345 .short_help = "Shows locator-sets",
1346 .function = lisp_cp_show_locator_sets_command_fn,
1351 static clib_error_t *
1352 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1353 unformat_input_t * input,
1354 vlib_cli_command_t * cmd)
1356 unformat_input_t _line_input, *line_input = &_line_input;
1357 u8 is_add = 1, addr_set = 0;
1358 ip_address_t ip_addr;
1359 clib_error_t *error = 0;
1361 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1363 /* Get a line of input. */
1364 if (!unformat_user (input, unformat_line_input, line_input))
1367 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1369 if (unformat (line_input, "add"))
1371 else if (unformat (line_input, "del"))
1373 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1377 error = unformat_parse_error (line_input);
1384 error = clib_error_return (0, "Map-resolver address must be set!");
1389 a->address = ip_addr;
1390 rv = vnet_lisp_add_del_map_resolver (a);
1393 error = clib_error_return (0, "failed to %s map-resolver!",
1394 is_add ? "add" : "delete");
1398 unformat_free (line_input);
1404 VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = {
1405 .path = "lisp map-resolver",
1406 .short_help = "lisp map-resolver add/del <ip_address>",
1407 .function = lisp_add_del_map_resolver_command_fn,
1412 static clib_error_t *
1413 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1414 unformat_input_t * input,
1415 vlib_cli_command_t * cmd)
1417 unformat_input_t _line_input, *line_input = &_line_input;
1419 u8 *locator_set_name = 0;
1420 clib_error_t *error = 0;
1422 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1424 /* Get a line of input. */
1425 if (!unformat_user (input, unformat_line_input, line_input))
1428 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1430 if (unformat (line_input, "del"))
1432 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1436 error = unformat_parse_error (line_input);
1442 a->locator_set_name = locator_set_name;
1443 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1446 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1447 is_add ? "add" : "delete");
1451 vec_free (locator_set_name);
1452 unformat_free (line_input);
1458 VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = {
1459 .path = "lisp map-request itr-rlocs",
1460 .short_help = "lisp map-request itr-rlocs add/del <locator_set_name>",
1461 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
1465 static clib_error_t *
1466 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1467 unformat_input_t * input,
1468 vlib_cli_command_t * cmd)
1470 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1471 locator_set_t *loc_set;
1473 vlib_cli_output (vm, "%=20s", "itr-rlocs");
1475 if (~0 == lcm->mreq_itr_rlocs)
1480 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1482 vlib_cli_output (vm, "%=20s", loc_set->name);
1488 VLIB_CLI_COMMAND (lisp_show_map_request_command) = {
1489 .path = "show lisp map-request itr-rlocs",
1490 .short_help = "Shows map-request itr-rlocs",
1491 .function = lisp_show_mreq_itr_rlocs_command_fn,
1495 static clib_error_t *
1496 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
1497 unformat_input_t * input,
1498 vlib_cli_command_t * cmd)
1500 u8 is_add = 1, ip_set = 0;
1501 unformat_input_t _line_input, *line_input = &_line_input;
1502 clib_error_t *error = 0;
1505 /* Get a line of input. */
1506 if (!unformat_user (input, unformat_line_input, line_input))
1509 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1511 if (unformat (line_input, "%U", unformat_ip_address, &ip))
1513 else if (unformat (line_input, "disable"))
1517 error = clib_error_return (0, "parse error");
1524 clib_warning ("No petr IP specified!");
1528 if (vnet_lisp_use_petr (&ip, is_add))
1530 error = clib_error_return (0, "failed to %s petr!",
1531 is_add ? "add" : "delete");
1535 unformat_free (line_input);
1541 VLIB_CLI_COMMAND (lisp_use_petr_set_locator_set_command) = {
1542 .path = "lisp use-petr",
1543 .short_help = "lisp use-petr [disable] <petr-ip>",
1544 .function = lisp_use_petr_set_locator_set_command_fn,
1547 static clib_error_t *
1548 lisp_show_petr_command_fn (vlib_main_t * vm,
1549 unformat_input_t * input, vlib_cli_command_t * cmd)
1551 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1556 u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
1557 vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
1561 vlib_cli_output (vm, "%=20s", "disable");
1565 if (~0 == lcm->petr_map_index)
1567 tmp_str = format (0, "N/A");
1571 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1572 if (~0 != m->locator_set_index)
1574 ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
1575 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
1576 tmp_str = format (0, "%U", format_ip_address, &loc->address);
1580 tmp_str = format (0, "N/A");
1583 vec_add1 (tmp_str, 0);
1585 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1593 VLIB_CLI_COMMAND (lisp_show_petr_command) = {
1594 .path = "show lisp petr",
1595 .short_help = "Show petr",
1596 .function = lisp_show_petr_command_fn,
1601 * fd.io coding-style-patch-verification: ON
1604 * eval: (c-set-style "gnu")