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 clib_memset (&eid, 0, sizeof (eid));
148 clib_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 vec_terminate_c_string (locator_set_name);
172 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
175 error = clib_error_return (0, "locator-set %s doesn't exist",
179 locator_set_index = p[0];
181 else if (unformat (line_input, "authoritative"))
182 a->authoritative = 1;
185 error = unformat_parse_error (line_input);
189 /* XXX treat batch configuration */
191 if (GID_ADDR_SRC_DST == gid_address_type (&eid))
194 clib_error_return (0, "src/dst is not supported for local EIDs!");
198 if (key && (0 == key_id))
200 vlib_cli_output (vm, "invalid key_id!");
204 gid_address_copy (&a->eid, &eid);
206 a->locator_set_index = locator_set_index;
211 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
214 error = clib_error_return (0, "failed to %s local mapping!",
215 is_add ? "add" : "delete");
219 if (locator_set_name)
220 vec_free (locator_set_name);
221 gid_address_free (&a->eid);
223 unformat_free (line_input);
228 VLIB_CLI_COMMAND (one_add_del_local_eid_command) = {
229 .path = "one eid-table",
230 .short_help = "one eid-table add/del [vni <vni>] eid <eid> "
231 "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]",
232 .function = lisp_add_del_local_eid_command_fn,
236 static clib_error_t *
237 lisp_eid_table_map_command_fn (vlib_main_t * vm,
238 unformat_input_t * input,
239 vlib_cli_command_t * cmd)
241 u8 is_add = 1, is_l2 = 0;
242 u32 vni = 0, dp_id = 0;
243 unformat_input_t _line_input, *line_input = &_line_input;
244 clib_error_t *error = NULL;
246 /* Get a line of input. */
247 if (!unformat_user (input, unformat_line_input, line_input))
250 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
252 if (unformat (line_input, "del"))
254 else if (unformat (line_input, "vni %d", &vni))
256 else if (unformat (line_input, "vrf %d", &dp_id))
258 else if (unformat (line_input, "bd %d", &dp_id))
262 error = unformat_parse_error (line_input);
266 vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
269 unformat_free (line_input);
275 VLIB_CLI_COMMAND (one_eid_table_map_command) = {
276 .path = "one eid-table map",
277 .short_help = "one eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
278 .function = lisp_eid_table_map_command_fn,
282 static clib_error_t *
283 lisp_add_del_ndp_entry_command_fn (vlib_main_t * vm,
284 unformat_input_t * input,
285 vlib_cli_command_t * cmd)
287 unformat_input_t _line_input, *line_input = &_line_input;
288 clib_error_t *error = NULL;
290 u8 hw_addr[6], bd = 0;
292 u32 hw_addr_set = 0, ip_set = 0, is_add = 1;
293 gid_address_t _g, *g = &_g;
295 clib_memset (&ip6, 0, sizeof (ip6));
296 clib_memset (hw_addr, 0, sizeof (hw_addr));
297 clib_memset (g, 0, sizeof (*g));
299 if (!unformat_user (input, unformat_line_input, line_input))
302 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
304 if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr))
306 else if (unformat (line_input, "ip %U", unformat_ip6_address, &ip6))
308 else if (unformat (line_input, "del"))
310 else if (unformat (line_input, "bd %d", &bd))
314 error = clib_error_return (0, "parse error");
319 if (!ip_set || (!hw_addr_set && is_add))
321 vlib_cli_output (vm, "expected IP and MAC addresses!");
325 /* build GID address */
326 ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, AF_IP6);
327 gid_address_ndp_bd (g) = bd;
328 gid_address_type (g) = GID_ADDR_NDP;
329 rc = vnet_lisp_add_del_l2_arp_ndp_entry (g, hw_addr, is_add);
331 clib_warning ("Failed to %s ndp entry!", is_add ? "add" : "delete");
334 unformat_free (line_input);
339 VLIB_CLI_COMMAND (one_add_del_ndp_entry_command) = {
341 .short_help = "one ndp [del] bd <bd> mac <mac> ip <ipv6>",
342 .function = lisp_add_del_ndp_entry_command_fn,
346 static clib_error_t *
347 lisp_add_del_l2_arp_entry_command_fn (vlib_main_t * vm,
348 unformat_input_t * input,
349 vlib_cli_command_t * cmd)
351 unformat_input_t _line_input, *line_input = &_line_input;
352 clib_error_t *error = NULL;
354 u8 hw_addr[6], bd = 0;
356 u32 hw_addr_set = 0, ip_set = 0, is_add = 1;
357 gid_address_t _arp, *arp = &_arp;
359 clib_memset (&ip4, 0, sizeof (ip4));
360 clib_memset (hw_addr, 0, sizeof (hw_addr));
361 clib_memset (arp, 0, sizeof (*arp));
363 if (!unformat_user (input, unformat_line_input, line_input))
366 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
368 if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr))
370 else if (unformat (line_input, "ip %U", unformat_ip4_address, &ip4))
372 else if (unformat (line_input, "del"))
374 else if (unformat (line_input, "bd %d", &bd))
378 error = clib_error_return (0, "parse error");
383 if (!ip_set || (!hw_addr_set && is_add))
385 vlib_cli_output (vm, "expected IP and MAC addresses!");
389 /* build GID address */
390 gid_address_arp_ip4 (arp) = ip4;
391 gid_address_arp_bd (arp) = bd;
392 gid_address_type (arp) = GID_ADDR_ARP;
393 rc = vnet_lisp_add_del_l2_arp_ndp_entry (arp, hw_addr, is_add);
395 clib_warning ("Failed to %s l2 arp entry!", is_add ? "add" : "delete");
398 unformat_free (line_input);
403 VLIB_CLI_COMMAND (one_add_del_l2_arp_entry_command) = {
404 .path = "one l2 arp",
405 .short_help = "one l2 arp [del] bd <bd> mac <mac> ip <ipv4>",
406 .function = lisp_add_del_l2_arp_entry_command_fn,
410 static clib_error_t *
411 lisp_show_l2_arp_entries_command_fn (vlib_main_t * vm,
412 unformat_input_t * input,
413 vlib_cli_command_t * cmd)
415 u32 *ht = vnet_lisp_l2_arp_bds_get ();
416 lisp_api_l2_arp_entry_t *entries, *e;
420 hash_foreach_pair (p, ht,
422 entries = vnet_lisp_l2_arp_entries_get_by_bd (p->key);
423 vlib_cli_output (vm, "Table: %d", p->key);
425 vec_foreach (e, entries)
427 vlib_cli_output (vm, "\t%U -> %U", format_ip4_address, &e->ip4,
428 format_mac_address, e->mac);
439 VLIB_CLI_COMMAND (one_show_l2_arp_entries_command) = {
440 .path = "show one l2 arp entries",
441 .short_help = "Show ONE L2 ARP entries",
442 .function = lisp_show_l2_arp_entries_command_fn,
446 static clib_error_t *
447 lisp_show_ndp_entries_command_fn (vlib_main_t * vm,
448 unformat_input_t * input,
449 vlib_cli_command_t * cmd)
451 u32 *ht = vnet_lisp_ndp_bds_get ();
452 lisp_api_ndp_entry_t *entries, *e;
456 hash_foreach_pair (p, ht,
458 entries = vnet_lisp_ndp_entries_get_by_bd (p->key);
459 vlib_cli_output (vm, "Table: %d", p->key);
461 vec_foreach (e, entries)
463 vlib_cli_output (vm, "\t%U -> %U", format_ip6_address, &e->ip6,
464 format_mac_address, e->mac);
475 VLIB_CLI_COMMAND (one_show_ndp_entries_command) = {
476 .path = "show one ndp entries",
477 .short_help = "Show ONE NDP entries",
478 .function = lisp_show_ndp_entries_command_fn,
483 * Handler for add/del remote mapping CLI.
485 * @param vm vlib context
486 * @param input input from user
488 * @return pointer to clib error structure
490 static clib_error_t *
491 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
492 unformat_input_t * input,
493 vlib_cli_command_t * cmd)
495 clib_error_t *error = 0;
496 unformat_input_t _line_input, *line_input = &_line_input;
497 u8 is_add = 1, del_all = 0;
498 locator_t rloc, *rlocs = 0, *curr_rloc = 0;
501 u32 vni, action = ~0, p, w;
504 /* Get a line of input. */
505 if (!unformat_user (input, unformat_line_input, line_input))
508 clib_memset (&eid, 0, sizeof (eid));
509 clib_memset (&rloc, 0, sizeof (rloc));
511 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
513 if (unformat (line_input, "del-all"))
515 else if (unformat (line_input, "del"))
517 else if (unformat (line_input, "add"))
519 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
521 else if (unformat (line_input, "vni %u", &vni))
523 gid_address_vni (&eid) = vni;
525 else if (unformat (line_input, "p %d w %d", &p, &w))
530 ("No RLOC configured for setting priority/weight!");
533 curr_rloc->priority = p;
534 curr_rloc->weight = w;
536 else if (unformat (line_input, "rloc %U", unformat_ip_address,
537 &gid_address_ip (&rloc.address)))
539 /* since rloc is stored in ip prefix we need to set prefix length */
540 ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
542 u8 version = gid_address_ip_version (&rloc.address);
543 ip_prefix_len (pref) = ip_address_max_len (version);
545 vec_add1 (rlocs, rloc);
546 curr_rloc = &rlocs[vec_len (rlocs) - 1];
548 else if (unformat (line_input, "action %U",
549 unformat_negative_mapping_action, &action))
553 clib_warning ("parse error");
558 if (!del_all && !eid_set)
560 clib_warning ("missing eid!");
566 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
568 clib_warning ("no action set for negative map-reply!");
574 vnet_lisp_clear_all_remote_adjacencies ();
578 /* if it's a delete, clean forwarding */
581 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
582 clib_memset (a, 0, sizeof (a[0]));
583 gid_address_copy (&a->reid, &eid);
584 if (vnet_lisp_add_del_adjacency (a))
586 clib_warning ("failed to delete adjacency!");
591 /* add as static remote mapping, i.e., not authoritative and infinite
595 vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args;
596 clib_memset (map_args, 0, sizeof (map_args[0]));
597 gid_address_copy (&map_args->eid, &eid);
598 map_args->action = action;
599 map_args->is_static = 1;
600 map_args->authoritative = 0;
602 rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL);
605 rv = vnet_lisp_del_mapping (&eid, NULL);
608 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
612 unformat_free (line_input);
617 VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = {
618 .path = "one remote-mapping",
620 "one remote-mapping add|del [del-all] vni <vni> "
621 "eid <est-eid> [action <no-action|natively-forward|"
622 "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
623 "[rloc <dst-locator> ... ]",
624 .function = lisp_add_del_remote_mapping_command_fn,
629 * Handler for add/del adjacency CLI.
631 static clib_error_t *
632 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
633 vlib_cli_command_t * cmd)
635 clib_error_t *error = 0;
636 unformat_input_t _line_input, *line_input = &_line_input;
637 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
639 ip_prefix_t *reid_ippref, *leid_ippref;
640 gid_address_t leid, reid;
641 u8 *dmac = gid_address_mac (&reid);
642 u8 *smac = gid_address_mac (&leid);
643 u8 reid_set = 0, leid_set = 0;
646 /* Get a line of input. */
647 if (!unformat_user (input, unformat_line_input, line_input))
650 clib_memset (&reid, 0, sizeof (reid));
651 clib_memset (&leid, 0, sizeof (leid));
653 leid_ippref = &gid_address_ippref (&leid);
654 reid_ippref = &gid_address_ippref (&reid);
656 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
658 if (unformat (line_input, "del"))
660 else if (unformat (line_input, "add"))
662 else if (unformat (line_input, "reid %U",
663 unformat_ip_prefix, reid_ippref))
665 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
668 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
670 gid_address_type (&reid) = GID_ADDR_MAC;
673 else if (unformat (line_input, "vni %u", &vni))
675 gid_address_vni (&leid) = vni;
676 gid_address_vni (&reid) = vni;
678 else if (unformat (line_input, "leid %U",
679 unformat_ip_prefix, leid_ippref))
681 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
684 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
686 gid_address_type (&leid) = GID_ADDR_MAC;
691 clib_warning ("parse error");
696 if (!reid_set || !leid_set)
698 clib_warning ("missing remote or local eid!");
702 if ((gid_address_type (&leid) != gid_address_type (&reid))
703 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
704 && ip_prefix_version (reid_ippref)
705 != ip_prefix_version (leid_ippref)))
707 clib_warning ("remote and local EIDs are of different types!");
711 clib_memset (a, 0, sizeof (a[0]));
712 gid_address_copy (&a->leid, &leid);
713 gid_address_copy (&a->reid, &reid);
716 if (vnet_lisp_add_del_adjacency (a))
717 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
720 unformat_free (line_input);
725 VLIB_CLI_COMMAND (one_add_del_adjacency_command) = {
726 .path = "one adjacency",
727 .short_help = "one adjacency add|del vni <vni> reid <remote-eid> "
729 .function = lisp_add_del_adjacency_command_fn,
734 static clib_error_t *
735 lisp_map_request_mode_command_fn (vlib_main_t * vm,
736 unformat_input_t * input,
737 vlib_cli_command_t * cmd)
739 unformat_input_t _i, *i = &_i;
740 map_request_mode_t mr_mode = _MR_MODE_MAX;
742 /* Get a line of input. */
743 if (!unformat_user (input, unformat_line_input, i))
746 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
748 if (unformat (i, "dst-only"))
749 mr_mode = MR_MODE_DST_ONLY;
750 else if (unformat (i, "src-dst"))
751 mr_mode = MR_MODE_SRC_DST;
754 clib_warning ("parse error '%U'", format_unformat_error, i);
759 if (_MR_MODE_MAX == mr_mode)
761 clib_warning ("No map request mode entered!");
765 vnet_lisp_set_map_request_mode (mr_mode);
774 VLIB_CLI_COMMAND (one_map_request_mode_command) = {
775 .path = "one map-request mode",
776 .short_help = "one map-request mode dst-only|src-dst",
777 .function = lisp_map_request_mode_command_fn,
783 format_lisp_map_request_mode (u8 * s, va_list * args)
785 u32 mode = va_arg (*args, u32);
790 return format (0, "dst-only");
792 return format (0, "src-dst");
797 static clib_error_t *
798 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
799 unformat_input_t * input,
800 vlib_cli_command_t * cmd)
802 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
803 vnet_lisp_get_map_request_mode ());
808 VLIB_CLI_COMMAND (one_show_map_request_mode_command) = {
809 .path = "show one map-request mode",
810 .short_help = "show one map-request mode",
811 .function = lisp_show_map_request_mode_command_fn,
815 static clib_error_t *
816 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
817 unformat_input_t * input,
818 vlib_cli_command_t * cmd)
821 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
823 vec_foreach (mr, lcm->map_resolvers)
825 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
831 VLIB_CLI_COMMAND (one_show_map_resolvers_command) = {
832 .path = "show one map-resolvers",
833 .short_help = "show one map-resolvers",
834 .function = lisp_show_map_resolvers_command_fn,
838 static clib_error_t *
839 lisp_nsh_set_locator_set_command_fn (vlib_main_t * vm,
840 unformat_input_t * input,
841 vlib_cli_command_t * cmd)
843 u8 locator_name_set = 0;
844 u8 *locator_set_name = 0;
846 unformat_input_t _line_input, *line_input = &_line_input;
847 clib_error_t *error = 0;
850 /* Get a line of input. */
851 if (!unformat_user (input, unformat_line_input, line_input))
854 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
856 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
857 locator_name_set = 1;
858 else if (unformat (line_input, "disable"))
862 error = clib_error_return (0, "parse error");
867 if (!locator_name_set)
869 clib_warning ("No locator set specified!");
873 vec_terminate_c_string (locator_set_name);
874 rv = vnet_lisp_nsh_set_locator_set (locator_set_name, is_add);
877 error = clib_error_return (0, "failed to %s NSH mapping!",
878 is_add ? "add" : "delete");
882 vec_free (locator_set_name);
883 unformat_free (line_input);
888 VLIB_CLI_COMMAND (one_nsh_set_locator_set_command) = {
889 .path = "one nsh-mapping",
890 .short_help = "one nsh-mapping [del] ls <locator-set-name>",
891 .function = lisp_nsh_set_locator_set_command_fn,
895 static clib_error_t *
896 lisp_map_register_fallback_threshold_show_command_fn (vlib_main_t * vm,
902 u32 val = vnet_lisp_map_register_fallback_threshold_get ();
903 vlib_cli_output (vm, "map register fallback threshold value: %d", val);
908 VLIB_CLI_COMMAND (one_map_register_fallback_threshold_show_command) = {
909 .path = "show one map-register fallback-threshold",
910 .short_help = "show one map-register fallback-threshold",
911 .function = lisp_map_register_fallback_threshold_show_command_fn,
916 static clib_error_t *
917 lisp_map_register_fallback_threshold_command_fn (vlib_main_t * vm,
918 unformat_input_t * input,
919 vlib_cli_command_t * cmd)
921 unformat_input_t _line_input, *line_input = &_line_input;
922 clib_error_t *error = 0;
926 /* Get a line of input. */
927 if (!unformat_user (input, unformat_line_input, line_input))
930 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
932 if (unformat (line_input, "%d", &val))
936 error = clib_error_return (0, "parse error");
941 rv = vnet_lisp_map_register_fallback_threshold_set (val);
944 error = clib_error_return (0, "setting fallback threshold failed!");
948 unformat_free (line_input);
953 VLIB_CLI_COMMAND (one_map_register_fallback_threshold_command) = {
954 .path = "one map-register fallback-threshold",
955 .short_help = "one map-register fallback-threshold <count>",
956 .function = lisp_map_register_fallback_threshold_command_fn,
960 static clib_error_t *
961 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
962 unformat_input_t * input,
963 vlib_cli_command_t * cmd)
965 u8 locator_name_set = 0;
966 u8 *locator_set_name = 0;
968 unformat_input_t _line_input, *line_input = &_line_input;
969 clib_error_t *error = 0;
972 /* Get a line of input. */
973 if (!unformat_user (input, unformat_line_input, line_input))
976 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
978 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
979 locator_name_set = 1;
980 else if (unformat (line_input, "disable"))
984 error = clib_error_return (0, "parse error");
989 if (!locator_name_set)
991 clib_warning ("No locator set specified!");
994 vec_terminate_c_string (locator_set_name);
995 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
998 error = clib_error_return (0, "failed to %s pitr!",
999 is_add ? "add" : "delete");
1003 if (locator_set_name)
1004 vec_free (locator_set_name);
1005 unformat_free (line_input);
1010 VLIB_CLI_COMMAND (one_pitr_set_locator_set_command) = {
1012 .short_help = "one pitr [disable] ls <locator-set-name>",
1013 .function = lisp_pitr_set_locator_set_command_fn,
1017 static clib_error_t *
1018 lisp_show_pitr_command_fn (vlib_main_t * vm,
1019 unformat_input_t * input, vlib_cli_command_t * cmd)
1021 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1025 u8 status = lcm->flags & LISP_FLAG_PITR_MODE;
1027 vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : "");
1031 vlib_cli_output (vm, "%=20s", "disable");
1035 if (~0 == lcm->pitr_map_index)
1037 tmp_str = format (0, "N/A");
1041 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1042 if (~0 != m->locator_set_index)
1045 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1046 tmp_str = format (0, "%s", ls->name);
1050 tmp_str = format (0, "N/A");
1053 vec_add1 (tmp_str, 0);
1055 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1063 VLIB_CLI_COMMAND (one_show_pitr_command) = {
1064 .path = "show one pitr",
1065 .short_help = "Show pitr",
1066 .function = lisp_show_pitr_command_fn,
1071 format_eid_entry (u8 * s, va_list * args)
1073 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
1074 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
1075 mapping_t *mapit = va_arg (*args, mapping_t *);
1076 locator_set_t *ls = va_arg (*args, locator_set_t *);
1077 gid_address_t *gid = &mapit->eid;
1078 u32 ttl = mapit->ttl;
1079 u8 aut = mapit->authoritative;
1084 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
1085 : format (0, "remote");
1087 if (vec_len (ls->locator_indices) == 0)
1089 s = format (s, "%-35U%-20saction:%-30U%-20u%-u", format_gid_address,
1090 gid, type, format_negative_mapping_action, mapit->action,
1095 vec_foreach (loc_index, ls->locator_indices)
1097 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
1099 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
1102 loc = format (0, "%U", format_ip_address,
1103 &gid_address_ip (&l->address));
1107 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
1108 gid, type, loc, ttl, aut);
1112 s = format (s, "%55s%v\n", "", loc);
1118 static clib_error_t *
1119 lisp_show_eid_table_command_fn (vlib_main_t * vm,
1120 unformat_input_t * input,
1121 vlib_cli_command_t * cmd)
1123 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1125 unformat_input_t _line_input, *line_input = &_line_input;
1130 clib_error_t *error = NULL;
1132 clib_memset (&eid, 0, sizeof (eid));
1134 /* Get a line of input. */
1135 if (!unformat_user (input, unformat_line_input, line_input))
1138 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1140 if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
1142 else if (unformat (line_input, "local"))
1144 else if (unformat (line_input, "remote"))
1148 error = clib_error_return (0, "parse error: '%U'",
1149 format_unformat_error, line_input);
1154 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
1155 "EID", "type", "locators", "ttl", "authoritative");
1160 pool_foreach (mapit, lcm->mapping_pool,
1162 if (mapit->pitr_set || mapit->nsh_set)
1165 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
1166 mapit->locator_set_index);
1167 if (filter && !((1 == filter && ls->local) ||
1168 (2 == filter && !ls->local)))
1172 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
1179 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
1180 if ((u32) ~ 0 == mi)
1183 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
1184 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
1185 mapit->locator_set_index);
1187 if (filter && !((1 == filter && ls->local) ||
1188 (2 == filter && !ls->local)))
1193 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
1198 unformat_free (line_input);
1204 VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = {
1205 .path = "show one eid-table",
1206 .short_help = "Shows EID table",
1207 .function = lisp_show_eid_table_command_fn,
1211 static clib_error_t *
1212 lisp_enable_disable_pitr_mode_command_fn (vlib_main_t * vm,
1213 unformat_input_t * input,
1214 vlib_cli_command_t * cmd)
1216 unformat_input_t _line_input, *line_input = &_line_input;
1219 clib_error_t *error = NULL;
1221 /* Get a line of input. */
1222 if (!unformat_user (input, unformat_line_input, line_input))
1223 return clib_error_return (0, "expected enable | disable");
1225 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1227 if (unformat (line_input, "enable"))
1232 else if (unformat (line_input, "disable"))
1236 error = clib_error_return (0, "parse error: '%U'",
1237 format_unformat_error, line_input);
1244 error = clib_error_return (0, "state not set");
1248 vnet_lisp_enable_disable_pitr_mode (is_enabled);
1251 unformat_free (line_input);
1257 VLIB_CLI_COMMAND (one_cp_enable_disable_pitr_mode_command) = {
1258 .path = "one pitr mode",
1259 .short_help = "one pitr mode [enable|disable]",
1260 .function = lisp_enable_disable_pitr_mode_command_fn,
1265 static clib_error_t *
1266 lisp_enable_disable_petr_mode_command_fn (vlib_main_t * vm,
1267 unformat_input_t * input,
1268 vlib_cli_command_t * cmd)
1270 unformat_input_t _line_input, *line_input = &_line_input;
1273 clib_error_t *error = NULL;
1275 /* Get a line of input. */
1276 if (!unformat_user (input, unformat_line_input, line_input))
1277 return clib_error_return (0, "expected enable | disable");
1279 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1281 if (unformat (line_input, "enable"))
1286 else if (unformat (line_input, "disable"))
1290 error = clib_error_return (0, "parse error: '%U'",
1291 format_unformat_error, line_input);
1298 error = clib_error_return (0, "state not set");
1302 vnet_lisp_enable_disable_petr_mode (is_enabled);
1305 unformat_free (line_input);
1311 VLIB_CLI_COMMAND (one_cp_enable_disable_petr_mode_command) = {
1312 .path = "one petr mode",
1313 .short_help = "one petr mode [enable|disable]",
1314 .function = lisp_enable_disable_petr_mode_command_fn,
1318 static clib_error_t *
1319 lisp_enable_disable_xtr_mode_command_fn (vlib_main_t * vm,
1320 unformat_input_t * input,
1321 vlib_cli_command_t * cmd)
1323 unformat_input_t _line_input, *line_input = &_line_input;
1326 clib_error_t *error = NULL;
1328 /* Get a line of input. */
1329 if (!unformat_user (input, unformat_line_input, line_input))
1330 return clib_error_return (0, "expected enable | disable");
1332 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1334 if (unformat (line_input, "enable"))
1339 else if (unformat (line_input, "disable"))
1343 error = clib_error_return (0, "parse error: '%U'",
1344 format_unformat_error, line_input);
1351 error = clib_error_return (0, "state not set");
1355 vnet_lisp_enable_disable_xtr_mode (is_enabled);
1358 unformat_free (line_input);
1364 VLIB_CLI_COMMAND (one_cp_enable_disable_xtr_mode_command) = {
1365 .path = "one xtr mode",
1366 .short_help = "one xtr mode [enable|disable]",
1367 .function = lisp_enable_disable_xtr_mode_command_fn,
1371 static clib_error_t *
1372 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
1373 vlib_cli_command_t * cmd)
1375 unformat_input_t _line_input, *line_input = &_line_input;
1378 clib_error_t *error = NULL;
1380 /* Get a line of input. */
1381 if (!unformat_user (input, unformat_line_input, line_input))
1382 return clib_error_return (0, "expected enable | disable");
1384 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1386 if (unformat (line_input, "enable"))
1391 else if (unformat (line_input, "disable"))
1395 error = clib_error_return (0, "parse error: '%U'",
1396 format_unformat_error, line_input);
1403 error = clib_error_return (0, "state not set");
1407 vnet_lisp_enable_disable (is_enabled);
1410 unformat_free (line_input);
1416 VLIB_CLI_COMMAND (one_cp_enable_disable_command) = {
1418 .short_help = "one [enable|disable]",
1419 .function = lisp_enable_disable_command_fn,
1423 static clib_error_t *
1424 lisp_map_register_set_ttl_command_fn (vlib_main_t * vm,
1425 unformat_input_t * input,
1426 vlib_cli_command_t * cmd)
1428 unformat_input_t _line_input, *line_input = &_line_input;
1431 clib_error_t *error = NULL;
1433 /* Get a line of input. */
1434 if (!unformat_user (input, unformat_line_input, line_input))
1435 return clib_error_return (0, "expected enable | disable");
1437 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1439 if (unformat (line_input, "%u", &ttl))
1443 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1451 vlib_cli_output (vm, "expected integer value for TTL!");
1455 vnet_lisp_map_register_set_ttl (ttl);
1458 unformat_free (line_input);
1463 VLIB_CLI_COMMAND (one_map_register_set_ttl_command) = {
1464 .path = "one map-register ttl",
1465 .short_help = "one map-register ttl",
1466 .function = lisp_map_register_set_ttl_command_fn,
1470 static clib_error_t *
1471 lisp_map_register_show_ttl_command_fn (vlib_main_t * vm,
1472 unformat_input_t * input,
1473 vlib_cli_command_t * cmd)
1475 u32 ttl = vnet_lisp_map_register_get_ttl ();
1477 vlib_cli_output (vm, "map-register TTL: %u", ttl);
1482 VLIB_CLI_COMMAND (one_map_register_show_ttl_command) = {
1483 .path = "show one map-register ttl",
1484 .short_help = "show one map-register ttl",
1485 .function = lisp_map_register_show_ttl_command_fn,
1490 static clib_error_t *
1491 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
1492 unformat_input_t * input,
1493 vlib_cli_command_t * cmd)
1495 unformat_input_t _line_input, *line_input = &_line_input;
1498 clib_error_t *error = NULL;
1500 /* Get a line of input. */
1501 if (!unformat_user (input, unformat_line_input, line_input))
1502 return clib_error_return (0, "expected enable | disable");
1504 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1506 if (unformat (line_input, "enable"))
1511 else if (unformat (line_input, "disable"))
1515 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1523 vlib_cli_output (vm, "state not set!");
1527 vnet_lisp_map_register_enable_disable (is_enabled);
1530 unformat_free (line_input);
1536 VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = {
1537 .path = "one map-register",
1538 .short_help = "one map-register [enable|disable]",
1539 .function = lisp_map_register_enable_disable_command_fn,
1543 static clib_error_t *
1544 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
1545 unformat_input_t * input,
1546 vlib_cli_command_t * cmd)
1548 unformat_input_t _line_input, *line_input = &_line_input;
1551 clib_error_t *error = NULL;
1553 /* Get a line of input. */
1554 if (!unformat_user (input, unformat_line_input, line_input))
1555 return clib_error_return (0, "expected enable | disable");
1557 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1559 if (unformat (line_input, "enable"))
1564 else if (unformat (line_input, "disable"))
1568 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1576 vlib_cli_output (vm, "state not set!");
1580 vnet_lisp_rloc_probe_enable_disable (is_enabled);
1583 unformat_free (line_input);
1589 VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = {
1590 .path = "one rloc-probe",
1591 .short_help = "one rloc-probe [enable|disable]",
1592 .function = lisp_rloc_probe_enable_disable_command_fn,
1597 format_lisp_status (u8 * s, va_list * args)
1599 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1600 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
1603 static clib_error_t *
1604 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
1605 vlib_cli_command_t * cmd)
1608 msg = format (msg, "feature: %U\ngpe: %U\n",
1609 format_lisp_status, format_vnet_lisp_gpe_status);
1610 vlib_cli_output (vm, "%v", msg);
1616 VLIB_CLI_COMMAND (one_show_status_command) = {
1617 .path = "show one status",
1618 .short_help = "show one status",
1619 .function = lisp_show_status_command_fn,
1623 static clib_error_t *
1624 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1625 unformat_input_t * input,
1626 vlib_cli_command_t * cmd)
1629 unformat_input_t _line_input, *line_input = &_line_input;
1630 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1631 uword *vni_table = 0;
1633 clib_error_t *error = NULL;
1635 /* Get a line of input. */
1636 if (!unformat_user (input, unformat_line_input, line_input))
1639 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1641 if (unformat (line_input, "l2"))
1643 vni_table = lcm->bd_id_by_vni;
1646 else if (unformat (line_input, "l3"))
1648 vni_table = lcm->table_id_by_vni;
1653 error = clib_error_return (0, "parse error: '%U'",
1654 format_unformat_error, line_input);
1661 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1665 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1668 hash_foreach_pair (p, vni_table,
1670 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1675 unformat_free (line_input);
1681 VLIB_CLI_COMMAND (one_show_eid_table_map_command) = {
1682 .path = "show one eid-table map",
1683 .short_help = "show one eid-table l2|l3",
1684 .function = lisp_show_eid_table_map_command_fn,
1689 static clib_error_t *
1690 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1691 unformat_input_t * input,
1692 vlib_cli_command_t * cmd)
1694 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1695 vnet_main_t *vnm = lgm->vnet_main;
1696 unformat_input_t _line_input, *line_input = &_line_input;
1698 clib_error_t *error = 0;
1699 u8 *locator_set_name = 0;
1700 locator_t locator, *locators = 0;
1701 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1705 clib_memset (&locator, 0, sizeof (locator));
1706 clib_memset (a, 0, sizeof (a[0]));
1708 /* Get a line of input. */
1709 if (!unformat_user (input, unformat_line_input, line_input))
1712 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1714 if (unformat (line_input, "add %_%v%_", &locator_set_name))
1716 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1718 else if (unformat (line_input, "iface %U p %d w %d",
1719 unformat_vnet_sw_interface, vnm,
1720 &locator.sw_if_index, &locator.priority,
1725 vec_add1 (locators, locator);
1729 error = unformat_parse_error (line_input);
1734 vec_terminate_c_string (locator_set_name);
1735 a->name = locator_set_name;
1736 a->locators = locators;
1740 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1743 error = clib_error_return (0, "failed to %s locator-set!",
1744 is_add ? "add" : "delete");
1748 vec_free (locators);
1749 if (locator_set_name)
1750 vec_free (locator_set_name);
1751 unformat_free (line_input);
1756 VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = {
1757 .path = "one locator-set",
1758 .short_help = "one locator-set add/del <name> [iface <iface-name> "
1759 "p <priority> w <weight>]",
1760 .function = lisp_add_del_locator_set_command_fn,
1764 static clib_error_t *
1765 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1766 unformat_input_t * input,
1767 vlib_cli_command_t * cmd)
1769 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1770 vnet_main_t *vnm = lgm->vnet_main;
1771 unformat_input_t _line_input, *line_input = &_line_input;
1773 clib_error_t *error = 0;
1774 u8 *locator_set_name = 0;
1775 u8 locator_set_name_set = 0;
1776 locator_t locator, *locators = 0;
1777 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1780 clib_memset (&locator, 0, sizeof (locator));
1781 clib_memset (a, 0, sizeof (a[0]));
1783 /* Get a line of input. */
1784 if (!unformat_user (input, unformat_line_input, line_input))
1787 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1789 if (unformat (line_input, "add"))
1791 else if (unformat (line_input, "del"))
1793 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1794 locator_set_name_set = 1;
1795 else if (unformat (line_input, "iface %U p %d w %d",
1796 unformat_vnet_sw_interface, vnm,
1797 &locator.sw_if_index, &locator.priority,
1801 vec_add1 (locators, locator);
1805 error = unformat_parse_error (line_input);
1810 if (!locator_set_name_set)
1812 error = clib_error_return (0, "locator_set name not set!");
1816 vec_terminate_c_string (locator_set_name);
1817 a->name = locator_set_name;
1818 a->locators = locators;
1822 vnet_lisp_add_del_locator (a, 0, &ls_index);
1825 vec_free (locators);
1826 vec_free (locator_set_name);
1827 unformat_free (line_input);
1832 VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = {
1833 .path = "one locator",
1834 .short_help = "one locator add/del locator-set <name> iface <iface-name> "
1835 "p <priority> w <weight>",
1836 .function = lisp_add_del_locator_in_set_command_fn,
1840 static clib_error_t *
1841 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1842 unformat_input_t * input,
1843 vlib_cli_command_t * cmd)
1845 locator_set_t *lsit;
1848 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1850 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1851 "Priority", "Weight");
1854 pool_foreach (lsit, lcm->locator_set_pool,
1860 msg = format (msg, "%s", lsit->name);
1864 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1866 vec_foreach (locit, lsit->locator_indices)
1870 msg = format (msg, "%16s", " ");
1872 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1874 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1877 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1878 &gid_address_ip(&loc->address), loc->priority,
1882 vlib_cli_output (vm, "%v", msg);
1890 VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = {
1891 .path = "show one locator-set",
1892 .short_help = "Shows locator-sets",
1893 .function = lisp_cp_show_locator_sets_command_fn,
1898 static clib_error_t *
1899 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1900 unformat_input_t * input,
1901 vlib_cli_command_t * cmd)
1903 unformat_input_t _line_input, *line_input = &_line_input;
1904 u8 is_add = 1, addr_set = 0;
1905 ip_address_t ip_addr;
1906 clib_error_t *error = 0;
1908 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1910 /* Get a line of input. */
1911 if (!unformat_user (input, unformat_line_input, line_input))
1914 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1916 if (unformat (line_input, "add"))
1918 else if (unformat (line_input, "del"))
1920 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1924 error = unformat_parse_error (line_input);
1931 error = clib_error_return (0, "Map-resolver address must be set!");
1936 a->address = ip_addr;
1937 rv = vnet_lisp_add_del_map_resolver (a);
1940 error = clib_error_return (0, "failed to %s map-resolver!",
1941 is_add ? "add" : "delete");
1945 unformat_free (line_input);
1950 VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = {
1951 .path = "one map-resolver",
1952 .short_help = "one map-resolver add/del <ip_address>",
1953 .function = lisp_add_del_map_resolver_command_fn,
1958 static clib_error_t *
1959 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1960 unformat_input_t * input,
1961 vlib_cli_command_t * cmd)
1963 unformat_input_t _line_input, *line_input = &_line_input;
1965 u8 *locator_set_name = 0;
1966 clib_error_t *error = 0;
1968 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1970 /* Get a line of input. */
1971 if (!unformat_user (input, unformat_line_input, line_input))
1974 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1976 if (unformat (line_input, "del"))
1978 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1982 error = unformat_parse_error (line_input);
1987 vec_terminate_c_string (locator_set_name);
1989 a->locator_set_name = locator_set_name;
1990 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1993 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1994 is_add ? "add" : "delete");
1998 vec_free (locator_set_name);
1999 unformat_free (line_input);
2005 VLIB_CLI_COMMAND (one_add_del_map_request_command) = {
2006 .path = "one map-request itr-rlocs",
2007 .short_help = "one map-request itr-rlocs add/del <locator_set_name>",
2008 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
2012 static clib_error_t *
2013 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
2014 unformat_input_t * input,
2015 vlib_cli_command_t * cmd)
2017 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2018 locator_set_t *loc_set;
2020 vlib_cli_output (vm, "%=20s", "itr-rlocs");
2022 if (~0 == lcm->mreq_itr_rlocs)
2027 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
2029 vlib_cli_output (vm, "%=20s", loc_set->name);
2035 VLIB_CLI_COMMAND (one_show_map_request_command) = {
2036 .path = "show one map-request itr-rlocs",
2037 .short_help = "Shows map-request itr-rlocs",
2038 .function = lisp_show_mreq_itr_rlocs_command_fn,
2042 static clib_error_t *
2043 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
2044 unformat_input_t * input,
2045 vlib_cli_command_t * cmd)
2047 u8 is_add = 1, ip_set = 0;
2048 unformat_input_t _line_input, *line_input = &_line_input;
2049 clib_error_t *error = 0;
2052 /* Get a line of input. */
2053 if (!unformat_user (input, unformat_line_input, line_input))
2056 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2058 if (unformat (line_input, "%U", unformat_ip_address, &ip))
2060 else if (unformat (line_input, "disable"))
2064 error = clib_error_return (0, "parse error");
2071 clib_warning ("No petr IP specified!");
2075 if (vnet_lisp_use_petr (&ip, is_add))
2077 error = clib_error_return (0, "failed to %s petr!",
2078 is_add ? "add" : "delete");
2082 unformat_free (line_input);
2087 VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = {
2088 .path = "one use-petr",
2089 .short_help = "one use-petr [disable] <petr-ip>",
2090 .function = lisp_use_petr_set_locator_set_command_fn,
2093 static clib_error_t *
2094 lisp_show_petr_command_fn (vlib_main_t * vm,
2095 unformat_input_t * input, vlib_cli_command_t * cmd)
2097 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2102 u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
2103 vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
2107 vlib_cli_output (vm, "%=20s", "disable");
2111 if (~0 == lcm->petr_map_index)
2113 tmp_str = format (0, "N/A");
2117 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
2118 if (~0 != m->locator_set_index)
2120 ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
2121 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
2122 tmp_str = format (0, "%U", format_ip_address, &loc->address);
2126 tmp_str = format (0, "N/A");
2129 vec_add1 (tmp_str, 0);
2131 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
2139 VLIB_CLI_COMMAND (one_show_petr_command) = {
2140 .path = "show one petr",
2141 .short_help = "Show petr",
2142 .function = lisp_show_petr_command_fn,
2146 static clib_error_t *
2147 lisp_show_map_servers_command_fn (vlib_main_t * vm,
2148 unformat_input_t * input,
2149 vlib_cli_command_t * cmd)
2152 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
2154 vec_foreach (ms, lcm->map_servers)
2156 vlib_cli_output (vm, "%U", format_ip_address, &ms->address);
2162 VLIB_CLI_COMMAND (one_show_map_servers_command) = {
2163 .path = "show one map-servers",
2164 .short_help = "show one map servers",
2165 .function = lisp_show_map_servers_command_fn,
2169 static clib_error_t *
2170 lisp_show_map_register_state_command_fn (vlib_main_t * vm,
2171 unformat_input_t * input,
2172 vlib_cli_command_t * cmd)
2175 u8 is_enabled = vnet_lisp_map_register_state_get ();
2177 msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
2178 vlib_cli_output (vm, "%v", msg);
2184 VLIB_CLI_COMMAND (one_show_map_register_state_command) = {
2185 .path = "show one map-register state",
2186 .short_help = "show one map-register state",
2187 .function = lisp_show_map_register_state_command_fn,
2191 static clib_error_t *
2192 lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm,
2193 unformat_input_t * input,
2194 vlib_cli_command_t * cmd)
2197 u8 is_enabled = vnet_lisp_rloc_probe_state_get ();
2199 msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
2200 vlib_cli_output (vm, "%v", msg);
2206 VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = {
2207 .path = "show one rloc state",
2208 .short_help = "show one RLOC state",
2209 .function = lisp_show_rloc_probe_state_command_fn,
2213 static clib_error_t *
2214 lisp_show_stats_command_fn (vlib_main_t * vm,
2215 unformat_input_t * input,
2216 vlib_cli_command_t * cmd)
2218 u8 is_enabled = vnet_lisp_stats_enable_disable_state ();
2219 vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled");
2224 VLIB_CLI_COMMAND (one_show_stats_command) = {
2225 .path = "show one statistics status",
2226 .short_help = "show ONE statistics enable/disable status",
2227 .function = lisp_show_stats_command_fn,
2231 static clib_error_t *
2232 lisp_show_stats_details_command_fn (vlib_main_t * vm,
2233 unformat_input_t * input,
2234 vlib_cli_command_t * cmd)
2236 lisp_api_stats_t *stat, *stats = vnet_lisp_get_stats ();
2238 if (vec_len (stats) > 0)
2239 vlib_cli_output (vm,
2240 "[src-EID, dst-EID] [loc-rloc, rmt-rloc] count bytes\n");
2242 vlib_cli_output (vm, "No statistics found.\n");
2244 vec_foreach (stat, stats)
2246 vlib_cli_output (vm, "[%U, %U] [%U, %U] %7u %7u\n",
2247 format_fid_address, &stat->seid,
2248 format_fid_address, &stat->deid,
2249 format_ip_address, &stat->loc_rloc,
2250 format_ip_address, &stat->rmt_rloc,
2251 stat->counters.packets, stat->counters.bytes);
2258 VLIB_CLI_COMMAND (one_show_stats_details_command) = {
2259 .path = "show one statistics details",
2260 .short_help = "show ONE statistics",
2261 .function = lisp_show_stats_details_command_fn,
2265 static clib_error_t *
2266 lisp_stats_enable_disable_command_fn (vlib_main_t * vm,
2267 unformat_input_t * input,
2268 vlib_cli_command_t * cmd)
2270 unformat_input_t _line_input, *line_input = &_line_input;
2273 /* Get a line of input. */
2274 if (!unformat_user (input, unformat_line_input, line_input))
2275 return clib_error_return (0, "expected enable | disable");
2277 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2279 if (unformat (line_input, "enable"))
2281 else if (unformat (line_input, "disable"))
2285 clib_warning ("Error: expected enable/disable!");
2289 vnet_lisp_stats_enable_disable (enable);
2291 unformat_free (line_input);
2296 VLIB_CLI_COMMAND (one_stats_enable_disable_command) = {
2297 .path = "one statistics",
2298 .short_help = "enable/disable ONE statistics collecting",
2299 .function = lisp_stats_enable_disable_command_fn,
2303 static clib_error_t *
2304 lisp_stats_flush_command_fn (vlib_main_t * vm,
2305 unformat_input_t * input,
2306 vlib_cli_command_t * cmd)
2308 vnet_lisp_flush_stats ();
2313 VLIB_CLI_COMMAND (one_stats_flush_command) = {
2314 .path = "one statistics flush",
2315 .short_help = "Flush ONE statistics",
2316 .function = lisp_stats_flush_command_fn,
2320 static clib_error_t *
2321 lisp_show_one_modes_command_fn (vlib_main_t * vm,
2322 unformat_input_t * input,
2323 vlib_cli_command_t * cmd)
2325 u8 pitr_mode = vnet_lisp_get_pitr_mode ();
2326 u8 petr_mode = vnet_lisp_get_petr_mode ();
2327 u8 xtr_mode = vnet_lisp_get_xtr_mode ();
2329 vlib_cli_output (vm, "xTR: %s\n", xtr_mode ? "enabled" : "disabled");
2330 vlib_cli_output (vm, "P-ITR: %s\n", pitr_mode ? "enabled" : "disabled");
2331 vlib_cli_output (vm, "P-ETR: %s\n", petr_mode ? "enabled" : "disabled");
2337 VLIB_CLI_COMMAND (one_cp_show_one_modes_modes_command) = {
2338 .path = "show one modes",
2339 .short_help = "show one modes",
2340 .function = lisp_show_one_modes_command_fn,
2345 * fd.io coding-style-patch-verification: ON
2348 * eval: (c-set-style "gnu")