2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vnet/lisp-cp/control.h>
17 #include <vnet/lisp-gpe/lisp_gpe.h>
20 lisp_show_adjacencies_command_fn (vlib_main_t * vm,
21 unformat_input_t * input,
22 vlib_cli_command_t * cmd)
24 lisp_adjacency_t *adjs, *adj;
25 vlib_cli_output (vm, "%s %40s\n", "leid", "reid");
26 unformat_input_t _line_input, *line_input = &_line_input;
29 /* Get a line of input. */
30 if (!unformat_user (input, unformat_line_input, line_input))
33 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
35 if (unformat (line_input, "vni %d", &vni))
39 vlib_cli_output (vm, "parse error: '%U'",
40 format_unformat_error, line_input);
41 unformat_free (line_input);
45 unformat_free (line_input);
49 vlib_cli_output (vm, "error: no vni specified!");
53 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
55 vec_foreach (adj, adjs)
57 vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid,
58 format_gid_address, &adj->reid);
66 VLIB_CLI_COMMAND (one_show_adjacencies_command) = {
67 .path = "show one adjacencies",
68 .short_help = "show one adjacencies",
69 .function = lisp_show_adjacencies_command_fn,
74 lisp_add_del_map_server_command_fn (vlib_main_t * vm,
75 unformat_input_t * input,
76 vlib_cli_command_t * cmd)
79 u8 is_add = 1, ip_set = 0;
81 unformat_input_t _line_input, *line_input = &_line_input;
83 /* Get a line of input. */
84 if (!unformat_user (input, unformat_line_input, line_input))
87 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
89 if (unformat (line_input, "add"))
91 else if (unformat (line_input, "del"))
93 else if (unformat (line_input, "%U", unformat_ip_address, &ip))
97 vlib_cli_output (vm, "parse error: '%U'",
98 format_unformat_error, line_input);
99 unformat_free (line_input);
103 unformat_free (line_input);
107 vlib_cli_output (vm, "map-server ip address not set!");
111 rv = vnet_lisp_add_del_map_server (&ip, is_add);
113 vlib_cli_output (vm, "failed to %s map-server!",
114 is_add ? "add" : "delete");
120 VLIB_CLI_COMMAND (one_add_del_map_server_command) = {
121 .path = "one map-server",
122 .short_help = "one map-server add|del <ip>",
123 .function = lisp_add_del_map_server_command_fn,
128 static clib_error_t *
129 lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
130 vlib_cli_command_t * cmd)
132 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
133 unformat_input_t _line_input, *line_input = &_line_input;
136 gid_address_t *eids = 0;
137 clib_error_t *error = 0;
138 u8 *locator_set_name = 0;
139 u32 locator_set_index = 0, map_index = 0;
141 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
147 memset (&eid, 0, sizeof (eid));
148 memset (a, 0, sizeof (*a));
150 /* Get a line of input. */
151 if (!unformat_user (input, unformat_line_input, line_input))
154 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
156 if (unformat (line_input, "add"))
158 else if (unformat (line_input, "del"))
160 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
162 else if (unformat (line_input, "vni %d", &vni))
163 gid_address_vni (&eid) = vni;
164 else if (unformat (line_input, "secret-key %_%v%_", &key))
166 else if (unformat (line_input, "key-id %U", unformat_hmac_key_id,
169 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
171 p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
174 error = clib_error_return (0, "locator-set %s doesn't exist",
178 locator_set_index = p[0];
182 error = unformat_parse_error (line_input);
186 /* XXX treat batch configuration */
188 if (GID_ADDR_SRC_DST == gid_address_type (&eid))
191 clib_error_return (0, "src/dst is not supported for local EIDs!");
195 if (key && (0 == key_id))
197 vlib_cli_output (vm, "invalid key_id!");
201 gid_address_copy (&a->eid, &eid);
203 a->locator_set_index = locator_set_index;
208 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
211 error = clib_error_return (0, "failed to %s local mapping!",
212 is_add ? "add" : "delete");
216 if (locator_set_name)
217 vec_free (locator_set_name);
218 gid_address_free (&a->eid);
220 unformat_free (line_input);
225 VLIB_CLI_COMMAND (one_add_del_local_eid_command) = {
226 .path = "one eid-table",
227 .short_help = "one eid-table add/del [vni <vni>] eid <eid> "
228 "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]",
229 .function = lisp_add_del_local_eid_command_fn,
233 static clib_error_t *
234 lisp_eid_table_map_command_fn (vlib_main_t * vm,
235 unformat_input_t * input,
236 vlib_cli_command_t * cmd)
238 u8 is_add = 1, is_l2 = 0;
239 u32 vni = 0, dp_id = 0;
240 unformat_input_t _line_input, *line_input = &_line_input;
241 clib_error_t *error = NULL;
243 /* Get a line of input. */
244 if (!unformat_user (input, unformat_line_input, line_input))
247 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
249 if (unformat (line_input, "del"))
251 else if (unformat (line_input, "vni %d", &vni))
253 else if (unformat (line_input, "vrf %d", &dp_id))
255 else if (unformat (line_input, "bd %d", &dp_id))
259 error = unformat_parse_error (line_input);
263 vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
266 unformat_free (line_input);
272 VLIB_CLI_COMMAND (one_eid_table_map_command) = {
273 .path = "one eid-table map",
274 .short_help = "one eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
275 .function = lisp_eid_table_map_command_fn,
279 static clib_error_t *
280 lisp_add_del_l2_arp_entry_command_fn (vlib_main_t * vm,
281 unformat_input_t * input,
282 vlib_cli_command_t * cmd)
284 unformat_input_t _line_input, *line_input = &_line_input;
285 clib_error_t *error = NULL;
287 u8 hw_addr[6], bd = 0;
289 u32 hw_addr_set = 0, ip_set = 0, is_add = 1;
290 gid_address_t _arp, *arp = &_arp;
292 memset (&ip4, 0, sizeof (ip4));
293 memset (hw_addr, 0, sizeof (hw_addr));
294 memset (arp, 0, sizeof (*arp));
296 if (!unformat_user (input, unformat_line_input, line_input))
299 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
301 if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr))
303 else if (unformat (line_input, "ip %U", unformat_ip4_address, &ip4))
305 else if (unformat (line_input, "del"))
307 else if (unformat (line_input, "bd %d", &bd))
311 error = clib_error_return (0, "parse error");
316 if (!ip_set || (!hw_addr_set && is_add))
318 vlib_cli_output (vm, "expected IP and MAC addresses!");
322 /* build GID address */
323 gid_address_arp_ip4 (arp) = ip4;
324 gid_address_arp_bd (arp) = bd;
325 gid_address_type (arp) = GID_ADDR_ARP;
326 rc = vnet_lisp_add_del_l2_arp_entry (arp, hw_addr, is_add);
328 clib_warning ("Failed to %s l2 arp entry!", is_add ? "add" : "delete");
331 unformat_free (line_input);
336 VLIB_CLI_COMMAND (one_add_del_l2_arp_entry_command) = {
337 .path = "one l2 arp",
338 .short_help = "one l2 arp [del] bd <bd> mac <mac> ip <ipv4>",
339 .function = lisp_add_del_l2_arp_entry_command_fn,
343 static clib_error_t *
344 lisp_show_l2_arp_entries_command_fn (vlib_main_t * vm,
345 unformat_input_t * input,
346 vlib_cli_command_t * cmd)
348 u32 *ht = vnet_lisp_l2_arp_bds_get ();
349 lisp_api_l2_arp_entry_t *entries, *e;
353 hash_foreach_pair (p, ht,
355 entries = vnet_lisp_l2_arp_entries_get_by_bd (p->key);
356 vlib_cli_output (vm, "Table: %d", p->key);
358 vec_foreach (e, entries)
360 vlib_cli_output (vm, "\t%U -> %U", format_ip4_address, &e->ip4,
361 format_mac_address, e->mac);
372 VLIB_CLI_COMMAND (one_show_l2_arp_entries_command) = {
373 .path = "show one l2 arp entries",
374 .short_help = "Show ONE L2 ARP entries",
375 .function = lisp_show_l2_arp_entries_command_fn,
380 * Handler for add/del remote mapping CLI.
382 * @param vm vlib context
383 * @param input input from user
385 * @return pointer to clib error structure
387 static clib_error_t *
388 lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
389 unformat_input_t * input,
390 vlib_cli_command_t * cmd)
392 clib_error_t *error = 0;
393 unformat_input_t _line_input, *line_input = &_line_input;
394 u8 is_add = 1, del_all = 0;
395 locator_t rloc, *rlocs = 0, *curr_rloc = 0;
398 u32 vni, action = ~0, p, w;
401 /* Get a line of input. */
402 if (!unformat_user (input, unformat_line_input, line_input))
405 memset (&eid, 0, sizeof (eid));
406 memset (&rloc, 0, sizeof (rloc));
408 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
410 if (unformat (line_input, "del-all"))
412 else if (unformat (line_input, "del"))
414 else if (unformat (line_input, "add"))
416 else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
418 else if (unformat (line_input, "vni %u", &vni))
420 gid_address_vni (&eid) = vni;
422 else if (unformat (line_input, "p %d w %d", &p, &w))
427 ("No RLOC configured for setting priority/weight!");
430 curr_rloc->priority = p;
431 curr_rloc->weight = w;
433 else if (unformat (line_input, "rloc %U", unformat_ip_address,
434 &gid_address_ip (&rloc.address)))
436 /* since rloc is stored in ip prefix we need to set prefix length */
437 ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
439 u8 version = gid_address_ip_version (&rloc.address);
440 ip_prefix_len (pref) = ip_address_max_len (version);
442 vec_add1 (rlocs, rloc);
443 curr_rloc = &rlocs[vec_len (rlocs) - 1];
445 else if (unformat (line_input, "action %U",
446 unformat_negative_mapping_action, &action))
450 clib_warning ("parse error");
455 if (!del_all && !eid_set)
457 clib_warning ("missing eid!");
463 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
465 clib_warning ("no action set for negative map-reply!");
471 vnet_lisp_clear_all_remote_adjacencies ();
475 /* if it's a delete, clean forwarding */
478 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
479 memset (a, 0, sizeof (a[0]));
480 gid_address_copy (&a->reid, &eid);
481 if (vnet_lisp_add_del_adjacency (a))
483 clib_warning ("failed to delete adjacency!");
488 /* add as static remote mapping, i.e., not authoritative and infinite
490 rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add,
491 1 /* is_static */ , 0);
494 clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
498 unformat_free (line_input);
503 VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = {
504 .path = "one remote-mapping",
506 "one remote-mapping add|del [del-all] vni <vni> "
507 "eid <est-eid> [action <no-action|natively-forward|"
508 "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
509 "[rloc <dst-locator> ... ]",
510 .function = lisp_add_del_remote_mapping_command_fn,
515 * Handler for add/del adjacency CLI.
517 static clib_error_t *
518 lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
519 vlib_cli_command_t * cmd)
521 clib_error_t *error = 0;
522 unformat_input_t _line_input, *line_input = &_line_input;
523 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
525 ip_prefix_t *reid_ippref, *leid_ippref;
526 gid_address_t leid, reid;
527 u8 *dmac = gid_address_mac (&reid);
528 u8 *smac = gid_address_mac (&leid);
529 u8 reid_set = 0, leid_set = 0;
532 /* Get a line of input. */
533 if (!unformat_user (input, unformat_line_input, line_input))
536 memset (&reid, 0, sizeof (reid));
537 memset (&leid, 0, sizeof (leid));
539 leid_ippref = &gid_address_ippref (&leid);
540 reid_ippref = &gid_address_ippref (&reid);
542 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
544 if (unformat (line_input, "del"))
546 else if (unformat (line_input, "add"))
548 else if (unformat (line_input, "reid %U",
549 unformat_ip_prefix, reid_ippref))
551 gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
554 else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
556 gid_address_type (&reid) = GID_ADDR_MAC;
559 else if (unformat (line_input, "vni %u", &vni))
561 gid_address_vni (&leid) = vni;
562 gid_address_vni (&reid) = vni;
564 else if (unformat (line_input, "leid %U",
565 unformat_ip_prefix, leid_ippref))
567 gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
570 else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
572 gid_address_type (&leid) = GID_ADDR_MAC;
577 clib_warning ("parse error");
582 if (!reid_set || !leid_set)
584 clib_warning ("missing remote or local eid!");
588 if ((gid_address_type (&leid) != gid_address_type (&reid))
589 || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
590 && ip_prefix_version (reid_ippref)
591 != ip_prefix_version (leid_ippref)))
593 clib_warning ("remote and local EIDs are of different types!");
597 memset (a, 0, sizeof (a[0]));
598 gid_address_copy (&a->leid, &leid);
599 gid_address_copy (&a->reid, &reid);
602 if (vnet_lisp_add_del_adjacency (a))
603 clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
606 unformat_free (line_input);
611 VLIB_CLI_COMMAND (one_add_del_adjacency_command) = {
612 .path = "one adjacency",
613 .short_help = "one adjacency add|del vni <vni> reid <remote-eid> "
615 .function = lisp_add_del_adjacency_command_fn,
620 static clib_error_t *
621 lisp_map_request_mode_command_fn (vlib_main_t * vm,
622 unformat_input_t * input,
623 vlib_cli_command_t * cmd)
625 unformat_input_t _i, *i = &_i;
626 map_request_mode_t mr_mode = _MR_MODE_MAX;
628 /* Get a line of input. */
629 if (!unformat_user (input, unformat_line_input, i))
632 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
634 if (unformat (i, "dst-only"))
635 mr_mode = MR_MODE_DST_ONLY;
636 else if (unformat (i, "src-dst"))
637 mr_mode = MR_MODE_SRC_DST;
640 clib_warning ("parse error '%U'", format_unformat_error, i);
645 if (_MR_MODE_MAX == mr_mode)
647 clib_warning ("No map request mode entered!");
651 vnet_lisp_set_map_request_mode (mr_mode);
660 VLIB_CLI_COMMAND (one_map_request_mode_command) = {
661 .path = "one map-request mode",
662 .short_help = "one map-request mode dst-only|src-dst",
663 .function = lisp_map_request_mode_command_fn,
669 format_lisp_map_request_mode (u8 * s, va_list * args)
671 u32 mode = va_arg (*args, u32);
676 return format (0, "dst-only");
678 return format (0, "src-dst");
683 static clib_error_t *
684 lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
685 unformat_input_t * input,
686 vlib_cli_command_t * cmd)
688 vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
689 vnet_lisp_get_map_request_mode ());
694 VLIB_CLI_COMMAND (one_show_map_request_mode_command) = {
695 .path = "show one map-request mode",
696 .short_help = "show one map-request mode",
697 .function = lisp_show_map_request_mode_command_fn,
701 static clib_error_t *
702 lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
703 unformat_input_t * input,
704 vlib_cli_command_t * cmd)
707 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
709 vec_foreach (mr, lcm->map_resolvers)
711 vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
717 VLIB_CLI_COMMAND (one_show_map_resolvers_command) = {
718 .path = "show one map-resolvers",
719 .short_help = "show one map-resolvers",
720 .function = lisp_show_map_resolvers_command_fn,
724 static clib_error_t *
725 lisp_nsh_set_locator_set_command_fn (vlib_main_t * vm,
726 unformat_input_t * input,
727 vlib_cli_command_t * cmd)
729 u8 locator_name_set = 0;
730 u8 *locator_set_name = 0;
732 unformat_input_t _line_input, *line_input = &_line_input;
733 clib_error_t *error = 0;
736 /* Get a line of input. */
737 if (!unformat_user (input, unformat_line_input, line_input))
740 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
742 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
743 locator_name_set = 1;
744 else if (unformat (line_input, "disable"))
748 error = clib_error_return (0, "parse error");
753 if (!locator_name_set)
755 clib_warning ("No locator set specified!");
759 rv = vnet_lisp_nsh_set_locator_set (locator_set_name, is_add);
762 error = clib_error_return (0, "failed to %s NSH mapping!",
763 is_add ? "add" : "delete");
767 vec_free (locator_set_name);
768 unformat_free (line_input);
773 VLIB_CLI_COMMAND (one_nsh_set_locator_set_command) = {
774 .path = "one nsh-mapping",
775 .short_help = "one nsh-mapping [del] ls <locator-set-name>",
776 .function = lisp_nsh_set_locator_set_command_fn,
781 static clib_error_t *
782 lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
783 unformat_input_t * input,
784 vlib_cli_command_t * cmd)
786 u8 locator_name_set = 0;
787 u8 *locator_set_name = 0;
789 unformat_input_t _line_input, *line_input = &_line_input;
790 clib_error_t *error = 0;
793 /* Get a line of input. */
794 if (!unformat_user (input, unformat_line_input, line_input))
797 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
799 if (unformat (line_input, "ls %_%v%_", &locator_set_name))
800 locator_name_set = 1;
801 else if (unformat (line_input, "disable"))
805 error = clib_error_return (0, "parse error");
810 if (!locator_name_set)
812 clib_warning ("No locator set specified!");
815 rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
818 error = clib_error_return (0, "failed to %s pitr!",
819 is_add ? "add" : "delete");
823 if (locator_set_name)
824 vec_free (locator_set_name);
825 unformat_free (line_input);
830 VLIB_CLI_COMMAND (one_pitr_set_locator_set_command) = {
832 .short_help = "one pitr [disable] ls <locator-set-name>",
833 .function = lisp_pitr_set_locator_set_command_fn,
837 static clib_error_t *
838 lisp_show_pitr_command_fn (vlib_main_t * vm,
839 unformat_input_t * input, vlib_cli_command_t * cmd)
841 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
846 vlib_cli_output (vm, "%=20s%=16s",
847 "pitr", lcm->lisp_pitr ? "locator-set" : "");
851 vlib_cli_output (vm, "%=20s", "disable");
855 if (~0 == lcm->pitr_map_index)
857 tmp_str = format (0, "N/A");
861 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
862 if (~0 != m->locator_set_index)
865 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
866 tmp_str = format (0, "%s", ls->name);
870 tmp_str = format (0, "N/A");
873 vec_add1 (tmp_str, 0);
875 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
883 VLIB_CLI_COMMAND (one_show_pitr_command) = {
884 .path = "show one pitr",
885 .short_help = "Show pitr",
886 .function = lisp_show_pitr_command_fn,
891 format_eid_entry (u8 * s, va_list * args)
893 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
894 lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
895 mapping_t *mapit = va_arg (*args, mapping_t *);
896 locator_set_t *ls = va_arg (*args, locator_set_t *);
897 gid_address_t *gid = &mapit->eid;
898 u32 ttl = mapit->ttl;
899 u8 aut = mapit->authoritative;
904 u8 *type = ls->local ? format (0, "local(%s)", ls->name)
905 : format (0, "remote");
907 if (vec_len (ls->locator_indices) == 0)
909 s = format (s, "%-35U%-20saction:%-30U%-20u%-u", format_gid_address,
910 gid, type, format_negative_mapping_action, mapit->action,
915 vec_foreach (loc_index, ls->locator_indices)
917 locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
919 loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
922 loc = format (0, "%U", format_ip_address,
923 &gid_address_ip (&l->address));
927 s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
928 gid, type, loc, ttl, aut);
932 s = format (s, "%55s%v\n", "", loc);
938 static clib_error_t *
939 lisp_show_eid_table_command_fn (vlib_main_t * vm,
940 unformat_input_t * input,
941 vlib_cli_command_t * cmd)
943 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
945 unformat_input_t _line_input, *line_input = &_line_input;
950 clib_error_t *error = NULL;
952 memset (&eid, 0, sizeof (eid));
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, "eid %U", unformat_gid_address, &eid))
962 else if (unformat (line_input, "local"))
964 else if (unformat (line_input, "remote"))
968 error = clib_error_return (0, "parse error: '%U'",
969 format_unformat_error, line_input);
974 vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
975 "EID", "type", "locators", "ttl", "autoritative");
980 pool_foreach (mapit, lcm->mapping_pool,
982 if (mapit->pitr_set || mapit->nsh_set)
985 locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
986 mapit->locator_set_index);
987 if (filter && !((1 == filter && ls->local) ||
988 (2 == filter && !ls->local)))
992 vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
999 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
1000 if ((u32) ~ 0 == mi)
1003 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
1004 locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
1005 mapit->locator_set_index);
1007 if (filter && !((1 == filter && ls->local) ||
1008 (2 == filter && !ls->local)))
1013 vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
1018 unformat_free (line_input);
1024 VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = {
1025 .path = "show one eid-table",
1026 .short_help = "Shows EID table",
1027 .function = lisp_show_eid_table_command_fn,
1032 static clib_error_t *
1033 lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
1034 vlib_cli_command_t * cmd)
1036 unformat_input_t _line_input, *line_input = &_line_input;
1039 clib_error_t *error = NULL;
1041 /* Get a line of input. */
1042 if (!unformat_user (input, unformat_line_input, line_input))
1045 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1047 if (unformat (line_input, "enable"))
1052 else if (unformat (line_input, "disable"))
1056 error = clib_error_return (0, "parse error: '%U'",
1057 format_unformat_error, line_input);
1064 error = clib_error_return (0, "state not set");
1068 vnet_lisp_enable_disable (is_enabled);
1071 unformat_free (line_input);
1077 VLIB_CLI_COMMAND (one_cp_enable_disable_command) = {
1079 .short_help = "one [enable|disable]",
1080 .function = lisp_enable_disable_command_fn,
1084 static clib_error_t *
1085 lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
1086 unformat_input_t * input,
1087 vlib_cli_command_t * cmd)
1089 unformat_input_t _line_input, *line_input = &_line_input;
1092 clib_error_t *error = NULL;
1094 /* Get a line of input. */
1095 if (!unformat_user (input, unformat_line_input, line_input))
1098 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1100 if (unformat (line_input, "enable"))
1105 else if (unformat (line_input, "disable"))
1109 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1117 vlib_cli_output (vm, "state not set!");
1121 vnet_lisp_map_register_enable_disable (is_enabled);
1124 unformat_free (line_input);
1130 VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = {
1131 .path = "one map-register",
1132 .short_help = "one map-register [enable|disable]",
1133 .function = lisp_map_register_enable_disable_command_fn,
1137 static clib_error_t *
1138 lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
1139 unformat_input_t * input,
1140 vlib_cli_command_t * cmd)
1142 unformat_input_t _line_input, *line_input = &_line_input;
1145 clib_error_t *error = NULL;
1147 /* Get a line of input. */
1148 if (!unformat_user (input, unformat_line_input, line_input))
1151 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1153 if (unformat (line_input, "enable"))
1158 else if (unformat (line_input, "disable"))
1162 vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
1170 vlib_cli_output (vm, "state not set!");
1174 vnet_lisp_rloc_probe_enable_disable (is_enabled);
1177 unformat_free (line_input);
1183 VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = {
1184 .path = "one rloc-probe",
1185 .short_help = "one rloc-probe [enable|disable]",
1186 .function = lisp_rloc_probe_enable_disable_command_fn,
1191 format_lisp_status (u8 * s, va_list * args)
1193 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1194 return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
1197 static clib_error_t *
1198 lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
1199 vlib_cli_command_t * cmd)
1202 msg = format (msg, "feature: %U\ngpe: %U\n",
1203 format_lisp_status, format_vnet_lisp_gpe_status);
1204 vlib_cli_output (vm, "%v", msg);
1210 VLIB_CLI_COMMAND (one_show_status_command) = {
1211 .path = "show one status",
1212 .short_help = "show one status",
1213 .function = lisp_show_status_command_fn,
1217 static clib_error_t *
1218 lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
1219 unformat_input_t * input,
1220 vlib_cli_command_t * cmd)
1223 unformat_input_t _line_input, *line_input = &_line_input;
1224 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1225 uword *vni_table = 0;
1227 clib_error_t *error = NULL;
1229 /* Get a line of input. */
1230 if (!unformat_user (input, unformat_line_input, line_input))
1233 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1235 if (unformat (line_input, "l2"))
1237 vni_table = lcm->bd_id_by_vni;
1240 else if (unformat (line_input, "l3"))
1242 vni_table = lcm->table_id_by_vni;
1247 error = clib_error_return (0, "parse error: '%U'",
1248 format_unformat_error, line_input);
1255 vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
1259 vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1262 hash_foreach_pair (p, vni_table,
1264 vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
1269 unformat_free (line_input);
1275 VLIB_CLI_COMMAND (one_show_eid_table_map_command) = {
1276 .path = "show one eid-table map",
1277 .short_help = "show one eid-table l2|l3",
1278 .function = lisp_show_eid_table_map_command_fn,
1283 static clib_error_t *
1284 lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
1285 unformat_input_t * input,
1286 vlib_cli_command_t * cmd)
1288 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1289 vnet_main_t *vnm = lgm->vnet_main;
1290 unformat_input_t _line_input, *line_input = &_line_input;
1292 clib_error_t *error = 0;
1293 u8 *locator_set_name = 0;
1294 locator_t locator, *locators = 0;
1295 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1299 memset (&locator, 0, sizeof (locator));
1300 memset (a, 0, sizeof (a[0]));
1302 /* Get a line of input. */
1303 if (!unformat_user (input, unformat_line_input, line_input))
1306 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1308 if (unformat (line_input, "add %_%v%_", &locator_set_name))
1310 else if (unformat (line_input, "del %_%v%_", &locator_set_name))
1312 else if (unformat (line_input, "iface %U p %d w %d",
1313 unformat_vnet_sw_interface, vnm,
1314 &locator.sw_if_index, &locator.priority,
1318 vec_add1 (locators, locator);
1322 error = unformat_parse_error (line_input);
1327 a->name = locator_set_name;
1328 a->locators = locators;
1332 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
1335 error = clib_error_return (0, "failed to %s locator-set!",
1336 is_add ? "add" : "delete");
1340 vec_free (locators);
1341 if (locator_set_name)
1342 vec_free (locator_set_name);
1343 unformat_free (line_input);
1348 VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = {
1349 .path = "one locator-set",
1350 .short_help = "one locator-set add/del <name> [iface <iface-name> "
1351 "p <priority> w <weight>]",
1352 .function = lisp_add_del_locator_set_command_fn,
1356 static clib_error_t *
1357 lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
1358 unformat_input_t * input,
1359 vlib_cli_command_t * cmd)
1361 lisp_gpe_main_t *lgm = &lisp_gpe_main;
1362 vnet_main_t *vnm = lgm->vnet_main;
1363 unformat_input_t _line_input, *line_input = &_line_input;
1365 clib_error_t *error = 0;
1366 u8 *locator_set_name = 0;
1367 u8 locator_set_name_set = 0;
1368 locator_t locator, *locators = 0;
1369 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
1372 memset (&locator, 0, sizeof (locator));
1373 memset (a, 0, sizeof (a[0]));
1375 /* Get a line of input. */
1376 if (!unformat_user (input, unformat_line_input, line_input))
1379 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1381 if (unformat (line_input, "add"))
1383 else if (unformat (line_input, "del"))
1385 else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
1386 locator_set_name_set = 1;
1387 else if (unformat (line_input, "iface %U p %d w %d",
1388 unformat_vnet_sw_interface, vnm,
1389 &locator.sw_if_index, &locator.priority,
1393 vec_add1 (locators, locator);
1397 error = unformat_parse_error (line_input);
1402 if (!locator_set_name_set)
1404 error = clib_error_return (0, "locator_set name not set!");
1408 a->name = locator_set_name;
1409 a->locators = locators;
1413 vnet_lisp_add_del_locator (a, 0, &ls_index);
1416 vec_free (locators);
1417 vec_free (locator_set_name);
1418 unformat_free (line_input);
1423 VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = {
1424 .path = "one locator",
1425 .short_help = "one locator add/del locator-set <name> iface <iface-name> "
1426 "p <priority> w <weight>",
1427 .function = lisp_add_del_locator_in_set_command_fn,
1431 static clib_error_t *
1432 lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
1433 unformat_input_t * input,
1434 vlib_cli_command_t * cmd)
1436 locator_set_t *lsit;
1439 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1441 vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
1442 "Priority", "Weight");
1445 pool_foreach (lsit, lcm->locator_set_pool,
1451 msg = format (msg, "%v", lsit->name);
1455 msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
1457 vec_foreach (locit, lsit->locator_indices)
1461 msg = format (msg, "%16s", " ");
1463 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
1465 msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
1468 msg = format (msg, "%16U%16d%16d\n", format_ip_address,
1469 &gid_address_ip(&loc->address), loc->priority,
1473 vlib_cli_output (vm, "%v", msg);
1481 VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = {
1482 .path = "show one locator-set",
1483 .short_help = "Shows locator-sets",
1484 .function = lisp_cp_show_locator_sets_command_fn,
1489 static clib_error_t *
1490 lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
1491 unformat_input_t * input,
1492 vlib_cli_command_t * cmd)
1494 unformat_input_t _line_input, *line_input = &_line_input;
1495 u8 is_add = 1, addr_set = 0;
1496 ip_address_t ip_addr;
1497 clib_error_t *error = 0;
1499 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
1501 /* Get a line of input. */
1502 if (!unformat_user (input, unformat_line_input, line_input))
1505 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1507 if (unformat (line_input, "add"))
1509 else if (unformat (line_input, "del"))
1511 else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
1515 error = unformat_parse_error (line_input);
1522 error = clib_error_return (0, "Map-resolver address must be set!");
1527 a->address = ip_addr;
1528 rv = vnet_lisp_add_del_map_resolver (a);
1531 error = clib_error_return (0, "failed to %s map-resolver!",
1532 is_add ? "add" : "delete");
1536 unformat_free (line_input);
1541 VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = {
1542 .path = "one map-resolver",
1543 .short_help = "one map-resolver add/del <ip_address>",
1544 .function = lisp_add_del_map_resolver_command_fn,
1549 static clib_error_t *
1550 lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1551 unformat_input_t * input,
1552 vlib_cli_command_t * cmd)
1554 unformat_input_t _line_input, *line_input = &_line_input;
1556 u8 *locator_set_name = 0;
1557 clib_error_t *error = 0;
1559 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
1561 /* Get a line of input. */
1562 if (!unformat_user (input, unformat_line_input, line_input))
1565 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1567 if (unformat (line_input, "del"))
1569 else if (unformat (line_input, "add %_%v%_", &locator_set_name))
1573 error = unformat_parse_error (line_input);
1579 a->locator_set_name = locator_set_name;
1580 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
1583 error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
1584 is_add ? "add" : "delete");
1588 vec_free (locator_set_name);
1589 unformat_free (line_input);
1595 VLIB_CLI_COMMAND (one_add_del_map_request_command) = {
1596 .path = "one map-request itr-rlocs",
1597 .short_help = "one map-request itr-rlocs add/del <locator_set_name>",
1598 .function = lisp_add_del_mreq_itr_rlocs_command_fn,
1602 static clib_error_t *
1603 lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
1604 unformat_input_t * input,
1605 vlib_cli_command_t * cmd)
1607 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1608 locator_set_t *loc_set;
1610 vlib_cli_output (vm, "%=20s", "itr-rlocs");
1612 if (~0 == lcm->mreq_itr_rlocs)
1617 loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1619 vlib_cli_output (vm, "%=20s", loc_set->name);
1625 VLIB_CLI_COMMAND (one_show_map_request_command) = {
1626 .path = "show one map-request itr-rlocs",
1627 .short_help = "Shows map-request itr-rlocs",
1628 .function = lisp_show_mreq_itr_rlocs_command_fn,
1632 static clib_error_t *
1633 lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
1634 unformat_input_t * input,
1635 vlib_cli_command_t * cmd)
1637 u8 is_add = 1, ip_set = 0;
1638 unformat_input_t _line_input, *line_input = &_line_input;
1639 clib_error_t *error = 0;
1642 /* Get a line of input. */
1643 if (!unformat_user (input, unformat_line_input, line_input))
1646 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1648 if (unformat (line_input, "%U", unformat_ip_address, &ip))
1650 else if (unformat (line_input, "disable"))
1654 error = clib_error_return (0, "parse error");
1661 clib_warning ("No petr IP specified!");
1665 if (vnet_lisp_use_petr (&ip, is_add))
1667 error = clib_error_return (0, "failed to %s petr!",
1668 is_add ? "add" : "delete");
1672 unformat_free (line_input);
1677 VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = {
1678 .path = "one use-petr",
1679 .short_help = "one use-petr [disable] <petr-ip>",
1680 .function = lisp_use_petr_set_locator_set_command_fn,
1683 static clib_error_t *
1684 lisp_show_petr_command_fn (vlib_main_t * vm,
1685 unformat_input_t * input, vlib_cli_command_t * cmd)
1687 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1692 u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
1693 vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
1697 vlib_cli_output (vm, "%=20s", "disable");
1701 if (~0 == lcm->petr_map_index)
1703 tmp_str = format (0, "N/A");
1707 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
1708 if (~0 != m->locator_set_index)
1710 ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
1711 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
1712 tmp_str = format (0, "%U", format_ip_address, &loc->address);
1716 tmp_str = format (0, "N/A");
1719 vec_add1 (tmp_str, 0);
1721 vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
1729 VLIB_CLI_COMMAND (one_show_petr_command) = {
1730 .path = "show one petr",
1731 .short_help = "Show petr",
1732 .function = lisp_show_petr_command_fn,
1736 static clib_error_t *
1737 lisp_show_map_servers_command_fn (vlib_main_t * vm,
1738 unformat_input_t * input,
1739 vlib_cli_command_t * cmd)
1742 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1744 vec_foreach (ms, lcm->map_servers)
1746 vlib_cli_output (vm, "%U", format_ip_address, &ms->address);
1752 VLIB_CLI_COMMAND (one_show_map_servers_command) = {
1753 .path = "show one map-servers",
1754 .short_help = "show one map servers",
1755 .function = lisp_show_map_servers_command_fn,
1759 static clib_error_t *
1760 lisp_show_map_register_state_command_fn (vlib_main_t * vm,
1761 unformat_input_t * input,
1762 vlib_cli_command_t * cmd)
1765 u8 is_enabled = vnet_lisp_map_register_state_get ();
1767 msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
1768 vlib_cli_output (vm, "%v", msg);
1774 VLIB_CLI_COMMAND (one_show_map_register_state_command) = {
1775 .path = "show one map-register state",
1776 .short_help = "show one map-register state",
1777 .function = lisp_show_map_register_state_command_fn,
1781 static clib_error_t *
1782 lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm,
1783 unformat_input_t * input,
1784 vlib_cli_command_t * cmd)
1787 u8 is_enabled = vnet_lisp_rloc_probe_state_get ();
1789 msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled");
1790 vlib_cli_output (vm, "%v", msg);
1796 VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = {
1797 .path = "show one rloc state",
1798 .short_help = "show one RLOC state",
1799 .function = lisp_show_rloc_probe_state_command_fn,
1803 static clib_error_t *
1804 lisp_show_stats_command_fn (vlib_main_t * vm,
1805 unformat_input_t * input,
1806 vlib_cli_command_t * cmd)
1808 u8 is_enabled = vnet_lisp_stats_enable_disable_state ();
1809 vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled");
1814 VLIB_CLI_COMMAND (one_show_stats_command) = {
1815 .path = "show one statistics status",
1816 .short_help = "show ONE statistics enable/disable status",
1817 .function = lisp_show_stats_command_fn,
1821 static clib_error_t *
1822 lisp_show_stats_details_command_fn (vlib_main_t * vm,
1823 unformat_input_t * input,
1824 vlib_cli_command_t * cmd)
1826 lisp_api_stats_t *stat, *stats = vnet_lisp_get_stats ();
1828 if (vec_len (stats) > 0)
1829 vlib_cli_output (vm,
1830 "[src-EID, dst-EID] [loc-rloc, rmt-rloc] count bytes\n");
1832 vlib_cli_output (vm, "No statistics found.\n");
1834 vec_foreach (stat, stats)
1836 vlib_cli_output (vm, "[%U, %U] [%U, %U] %7u %7u\n",
1837 format_fid_address, &stat->seid,
1838 format_fid_address, &stat->deid,
1839 format_ip_address, &stat->loc_rloc,
1840 format_ip_address, &stat->rmt_rloc,
1841 stat->counters.packets, stat->counters.bytes);
1848 VLIB_CLI_COMMAND (one_show_stats_details_command) = {
1849 .path = "show one statistics details",
1850 .short_help = "show ONE statistics",
1851 .function = lisp_show_stats_details_command_fn,
1855 static clib_error_t *
1856 lisp_stats_enable_disable_command_fn (vlib_main_t * vm,
1857 unformat_input_t * input,
1858 vlib_cli_command_t * cmd)
1860 unformat_input_t _line_input, *line_input = &_line_input;
1863 /* Get a line of input. */
1864 if (!unformat_user (input, unformat_line_input, line_input))
1867 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1869 if (unformat (line_input, "enable"))
1871 else if (unformat (line_input, "disable"))
1875 clib_warning ("Error: expected enable/disable!");
1879 vnet_lisp_stats_enable_disable (enable);
1881 unformat_free (line_input);
1886 VLIB_CLI_COMMAND (one_stats_enable_disable_command) = {
1887 .path = "one statistics",
1888 .short_help = "enable/disable ONE statistics collecting",
1889 .function = lisp_stats_enable_disable_command_fn,
1893 static clib_error_t *
1894 lisp_stats_flush_command_fn (vlib_main_t * vm,
1895 unformat_input_t * input,
1896 vlib_cli_command_t * cmd)
1898 vnet_lisp_flush_stats ();
1903 VLIB_CLI_COMMAND (one_stats_flush_command) = {
1904 .path = "one statistics flush",
1905 .short_help = "Flush ONE statistics",
1906 .function = lisp_stats_flush_command_fn,
1911 * fd.io coding-style-patch-verification: ON
1914 * eval: (c-set-style "gnu")