2 * Copyright (c) 2015 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.
17 #include <vlibapi/api.h>
18 #include <vlibmemory/api.h>
19 #include <vppinfra/error.h>
21 #include <vnet/ip/ip_format_fns.h>
22 #include <vnet/ethernet/ethernet_format_fns.h>
23 #include <vnet/ethernet/mac_address.h>
24 #include <lisp/lisp-cp/lisp_types.h>
26 /* define message IDs */
27 #include <lisp/lisp-cp/lisp.api_enum.h>
28 #include <lisp/lisp-cp/lisp.api_types.h>
29 #include <vlibmemory/vlib.api_types.h>
33 /* API message ID base */
39 lisp_test_main_t lisp_test_main;
41 #define __plugin_msg_base lisp_test_main.msg_id_base
42 #include <vlibapi/vat_helper_macros.h>
46 vlib_cli_output (handle, (char *) s); \
54 } __attribute__ ((__packed__)) lisp_nsh_api_t;
56 #define LISP_PING(_lm, mp_ping) \
57 if (!(_lm)->ping_id) \
58 (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \
59 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); \
60 mp_ping->_vl_msg_id = htons ((_lm)->ping_id); \
61 mp_ping->client_index = vam->my_client_index; \
62 fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id); \
63 vam->result_ready = 0; \
66 unformat_nsh_address (unformat_input_t * input, va_list * args)
68 lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
69 return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
73 format_nsh_address_vat (u8 * s, va_list * args)
75 nsh_t *a = va_arg (*args, nsh_t *);
76 return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
80 format_lisp_flat_eid (u8 * s, va_list * args)
82 vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *);
86 case EID_TYPE_API_PREFIX:
87 if (eid->address.prefix.address.af)
88 return format (s, "%U/%d", format_ip6_address,
89 eid->address.prefix.address.un.ip6,
90 eid->address.prefix.len);
91 return format (s, "%U/%d", format_ip4_address,
92 eid->address.prefix.address.un.ip4,
93 eid->address.prefix.len);
94 case EID_TYPE_API_MAC:
95 return format (s, "%U", format_ethernet_address, eid->address.mac);
96 case EID_TYPE_API_NSH:
97 return format (s, "%U", format_nsh_address_vat, eid->address.nsh);
103 format_lisp_eid_vat (u8 * s, va_list * args)
105 vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *);
106 vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *);
107 u8 is_src_dst = (u8) va_arg (*args, int);
110 s = format (s, "%U|", format_lisp_flat_eid, seid);
112 s = format (s, "%U", format_lisp_flat_eid, deid);
119 /** Used for parsing LISP eids */
120 typedef struct lisp_eid_vat_t_
127 /**< prefix length if IP */
131 } __clib_packed lisp_eid_vat_t;
134 unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
136 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
138 clib_memset (a, 0, sizeof (a[0]));
140 if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len))
142 a->type = 0; /* ip prefix type */
144 else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac))
146 a->type = 1; /* mac type */
148 else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh))
150 a->type = 2; /* NSH type */
151 a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi);
160 if (ip46_address_is_ip4 (&a->addr.ip))
161 return a->len > 32 ? 1 : 0;
163 return a->len > 128 ? 1 : 0;
170 lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid)
172 eid->type = vat_eid->type;
175 case EID_TYPE_API_PREFIX:
176 if (ip46_address_is_ip4 (&vat_eid->addr.ip))
178 clib_memcpy (&eid->address.prefix.address.un.ip4,
179 &vat_eid->addr.ip.ip4, 4);
180 eid->address.prefix.address.af = ADDRESS_IP4;
181 eid->address.prefix.len = vat_eid->len;
185 clib_memcpy (&eid->address.prefix.address.un.ip6,
186 &vat_eid->addr.ip.ip6, 16);
187 eid->address.prefix.address.af = ADDRESS_IP6;
188 eid->address.prefix.len = vat_eid->len;
191 case EID_TYPE_API_MAC:
192 clib_memcpy (&eid->address.mac, &vat_eid->addr.mac,
193 sizeof (eid->address.mac));
195 case EID_TYPE_API_NSH:
196 clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh,
197 sizeof (eid->address.nsh));
206 api_lisp_add_del_locator_set (vat_main_t * vam)
208 unformat_input_t *input = vam->input;
209 vl_api_lisp_add_del_locator_set_t *mp;
211 u8 *locator_set_name = NULL;
212 u8 locator_set_name_set = 0;
213 vl_api_local_locator_t locator, *locators = 0;
214 u32 sw_if_index, priority, weight;
218 /* Parse args required to build the message */
219 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
221 if (unformat (input, "del"))
225 else if (unformat (input, "locator-set %s", &locator_set_name))
227 locator_set_name_set = 1;
229 else if (unformat (input, "sw_if_index %u p %u w %u",
230 &sw_if_index, &priority, &weight))
232 locator.sw_if_index = htonl (sw_if_index);
233 locator.priority = priority;
234 locator.weight = weight;
235 vec_add1 (locators, locator);
239 (input, "iface %U p %u w %u", unformat_sw_if_index, vam,
240 &sw_if_index, &priority, &weight))
242 locator.sw_if_index = htonl (sw_if_index);
243 locator.priority = priority;
244 locator.weight = weight;
245 vec_add1 (locators, locator);
251 if (locator_set_name_set == 0)
253 errmsg ("missing locator-set name");
258 if (vec_len (locator_set_name) > 64)
260 errmsg ("locator-set name too long");
261 vec_free (locator_set_name);
265 vec_add1 (locator_set_name, 0);
267 data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
269 /* Construct the API message */
270 M2 (LISP_ADD_DEL_LOCATOR_SET, mp, data_len);
273 clib_memcpy (mp->locator_set_name, locator_set_name,
274 vec_len (locator_set_name));
275 vec_free (locator_set_name);
277 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
279 clib_memcpy (mp->locators, locators, data_len);
285 /* Wait for a reply... */
291 api_lisp_add_del_locator (vat_main_t * vam)
293 unformat_input_t *input = vam->input;
294 vl_api_lisp_add_del_locator_t *mp;
295 u32 tmp_if_index = ~0;
296 u32 sw_if_index = ~0;
297 u8 sw_if_index_set = 0;
298 u8 sw_if_index_if_name_set = 0;
304 u8 *locator_set_name = NULL;
305 u8 locator_set_name_set = 0;
308 /* Parse args required to build the message */
309 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
311 if (unformat (input, "del"))
315 else if (unformat (input, "locator-set %s", &locator_set_name))
317 locator_set_name_set = 1;
319 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
322 sw_if_index_if_name_set = 1;
323 sw_if_index = tmp_if_index;
325 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
328 sw_if_index = tmp_if_index;
330 else if (unformat (input, "p %d", &priority))
334 else if (unformat (input, "w %d", &weight))
342 if (locator_set_name_set == 0)
344 errmsg ("missing locator-set name");
348 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
350 errmsg ("missing sw_if_index");
351 vec_free (locator_set_name);
355 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
357 errmsg ("cannot use both params interface name and sw_if_index");
358 vec_free (locator_set_name);
362 if (priority_set == 0)
364 errmsg ("missing locator-set priority");
365 vec_free (locator_set_name);
371 errmsg ("missing locator-set weight");
372 vec_free (locator_set_name);
376 if (vec_len (locator_set_name) > 64)
378 errmsg ("locator-set name too long");
379 vec_free (locator_set_name);
382 vec_add1 (locator_set_name, 0);
384 /* Construct the API message */
385 M (LISP_ADD_DEL_LOCATOR, mp);
388 mp->sw_if_index = ntohl (sw_if_index);
389 mp->priority = priority;
391 clib_memcpy (mp->locator_set_name, locator_set_name,
392 vec_len (locator_set_name));
393 vec_free (locator_set_name);
398 /* Wait for a reply... */
404 api_lisp_add_del_local_eid (vat_main_t * vam)
406 unformat_input_t *input = vam->input;
407 vl_api_lisp_add_del_local_eid_t *mp;
410 lisp_eid_vat_t _eid, *eid = &_eid;
411 u8 *locator_set_name = 0;
412 u8 locator_set_name_set = 0;
418 /* Parse args required to build the message */
419 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
421 if (unformat (input, "del"))
425 else if (unformat (input, "vni %d", &vni))
429 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
433 else if (unformat (input, "locator-set %s", &locator_set_name))
435 locator_set_name_set = 1;
437 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
439 else if (unformat (input, "secret-key %_%v%_", &key))
445 if (locator_set_name_set == 0)
447 errmsg ("missing locator-set name");
453 errmsg ("EID address not set!");
454 vec_free (locator_set_name);
458 if (key && (0 == key_id))
460 errmsg ("invalid key_id!");
464 if (vec_len (key) > 64)
466 errmsg ("key too long");
471 if (vec_len (locator_set_name) > 64)
473 errmsg ("locator-set name too long");
474 vec_free (locator_set_name);
477 vec_add1 (locator_set_name, 0);
479 /* Construct the API message */
480 M (LISP_ADD_DEL_LOCAL_EID, mp);
483 lisp_eid_put_vat (&mp->eid, eid);
484 mp->vni = clib_host_to_net_u32 (vni);
486 clib_memcpy (mp->locator_set_name, locator_set_name,
487 vec_len (locator_set_name));
488 clib_memcpy (mp->key.key, key, vec_len (key));
490 vec_free (locator_set_name);
496 /* Wait for a reply... */
502 api_lisp_add_del_map_server (vat_main_t * vam)
504 unformat_input_t *input = vam->input;
505 vl_api_lisp_add_del_map_server_t *mp;
513 /* Parse args required to build the message */
514 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
516 if (unformat (input, "del"))
520 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
524 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
532 if (ipv4_set && ipv6_set)
534 errmsg ("both eid v4 and v6 addresses set");
538 if (!ipv4_set && !ipv6_set)
540 errmsg ("eid addresses not set");
544 /* Construct the API message */
545 M (LISP_ADD_DEL_MAP_SERVER, mp);
550 mp->ip_address.af = 1;
551 clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
555 mp->ip_address.af = 0;
556 clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4));
562 /* Wait for a reply... */
568 api_lisp_add_del_map_resolver (vat_main_t * vam)
570 unformat_input_t *input = vam->input;
571 vl_api_lisp_add_del_map_resolver_t *mp;
579 /* Parse args required to build the message */
580 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
582 if (unformat (input, "del"))
586 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
590 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
598 if (ipv4_set && ipv6_set)
600 errmsg ("both eid v4 and v6 addresses set");
604 if (!ipv4_set && !ipv6_set)
606 errmsg ("eid addresses not set");
610 /* Construct the API message */
611 M (LISP_ADD_DEL_MAP_RESOLVER, mp);
616 mp->ip_address.af = 1;
617 clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
621 mp->ip_address.af = 0;
622 clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4));
628 /* Wait for a reply... */
634 api_lisp_enable_disable (vat_main_t * vam)
636 unformat_input_t *input = vam->input;
637 vl_api_lisp_enable_disable_t *mp;
642 /* Parse args required to build the message */
643 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
645 if (unformat (input, "enable"))
650 else if (unformat (input, "disable"))
660 errmsg ("Value not set");
664 /* Construct the API message */
665 M (LISP_ENABLE_DISABLE, mp);
667 mp->is_enable = is_enable;
672 /* Wait for a reply... */
678 * Enable/disable LISP proxy ITR.
680 * @param vam vpp API test context
681 * @return return code
684 api_lisp_pitr_set_locator_set (vat_main_t * vam)
687 unformat_input_t *input = vam->input;
688 vl_api_lisp_pitr_set_locator_set_t *mp;
693 /* Parse args required to build the message */
694 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
696 if (unformat (input, "del"))
698 else if (unformat (input, "locator-set %s", &ls_name))
702 errmsg ("parse error '%U'", format_unformat_error, input);
709 errmsg ("locator-set name not set!");
713 M (LISP_PITR_SET_LOCATOR_SET, mp);
716 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
728 api_lisp_use_petr (vat_main_t * vam)
730 unformat_input_t *input = vam->input;
731 vl_api_lisp_use_petr_t *mp;
736 clib_memset (&ip, 0, sizeof (ip));
738 /* Parse args required to build the message */
739 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
741 if (unformat (input, "disable"))
744 if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
747 ip_addr_version (&ip) = AF_IP4;
750 if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
753 ip_addr_version (&ip) = AF_IP6;
757 errmsg ("parse error '%U'", format_unformat_error, input);
762 M (LISP_USE_PETR, mp);
767 mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1;
768 if (mp->ip_address.af)
769 clib_memcpy (mp->ip_address.un.ip6, &ip, 16);
771 clib_memcpy (mp->ip_address.un.ip4, &ip, 4);
783 vl_api_show_lisp_use_petr_reply_t_handler
784 (vl_api_show_lisp_use_petr_reply_t * mp)
786 vat_main_t *vam = &vat_main;
787 i32 retval = ntohl (mp->retval);
791 print (vam->ofp, "%s\n", mp->is_petr_enable ? "enabled" : "disabled");
792 if (mp->is_petr_enable)
794 print (vam->ofp, "Proxy-ETR address; %U",
795 mp->ip_address.af ? format_ip6_address : format_ip4_address,
800 vam->retval = retval;
801 vam->result_ready = 1;
805 api_show_lisp_use_petr (vat_main_t * vam)
807 vl_api_show_lisp_use_petr_t *mp;
810 if (!vam->json_output)
812 print (vam->ofp, "%=20s", "Proxy-ETR status:");
815 M (SHOW_LISP_USE_PETR, mp);
819 /* Wait for a reply... */
825 vl_api_show_lisp_rloc_probe_state_reply_t_handler
826 (vl_api_show_lisp_rloc_probe_state_reply_t * mp)
828 vat_main_t *vam = &vat_main;
829 int retval = clib_net_to_host_u32 (mp->retval);
834 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
836 vam->retval = retval;
837 vam->result_ready = 1;
841 api_show_lisp_map_register_state (vat_main_t * vam)
843 vl_api_show_lisp_map_register_state_t *mp;
846 M (SHOW_LISP_MAP_REGISTER_STATE, mp);
857 api_show_lisp_rloc_probe_state (vat_main_t * vam)
859 vl_api_show_lisp_rloc_probe_state_t *mp;
862 M (SHOW_LISP_RLOC_PROBE_STATE, mp);
873 api_lisp_rloc_probe_enable_disable (vat_main_t * vam)
875 unformat_input_t *input = vam->input;
876 vl_api_lisp_rloc_probe_enable_disable_t *mp;
881 /* Parse args required to build the message */
882 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
884 if (unformat (input, "enable"))
889 else if (unformat (input, "disable"))
897 errmsg ("Value not set");
901 /* Construct the API message */
902 M (LISP_RLOC_PROBE_ENABLE_DISABLE, mp);
904 mp->is_enable = is_enable;
909 /* Wait for a reply... */
915 api_lisp_map_register_enable_disable (vat_main_t * vam)
917 unformat_input_t *input = vam->input;
918 vl_api_lisp_map_register_enable_disable_t *mp;
923 /* Parse args required to build the message */
924 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
926 if (unformat (input, "enable"))
931 else if (unformat (input, "disable"))
939 errmsg ("Value not set");
943 /* Construct the API message */
944 M (LISP_MAP_REGISTER_ENABLE_DISABLE, mp);
946 mp->is_enable = is_enable;
951 /* Wait for a reply... */
957 vl_api_show_lisp_map_request_mode_reply_t_handler
958 (vl_api_show_lisp_map_request_mode_reply_t * mp)
960 vat_main_t *vam = &vat_main;
961 i32 retval = ntohl (mp->retval);
965 print (vam->ofp, "map_request_mode: %s",
966 mp->is_src_dst ? "src-dst" : "dst-only");
969 vam->retval = retval;
970 vam->result_ready = 1;
974 vl_api_show_lisp_map_register_state_reply_t_handler
975 (vl_api_show_lisp_map_register_state_reply_t * mp)
977 vat_main_t *vam = &vat_main;
978 int retval = clib_net_to_host_u32 (mp->retval);
980 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
982 vam->retval = retval;
983 vam->result_ready = 1;
987 vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
989 vat_main_t *vam = &vat_main;
994 s = format (s, "%=16d%=16d%=16d",
995 ntohl (mp->sw_if_index), mp->priority, mp->weight);
999 s = format (s, "%=16U%=16d%=16d",
1000 format_ip46_address,
1001 mp->ip_address, mp->priority, mp->weight);
1004 print (vam->ofp, "%v", s);
1009 vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
1012 vat_main_t *vam = &vat_main;
1015 ls_name = format (0, "%s", mp->ls_name);
1017 print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
1022 static void vl_api_lisp_add_del_locator_set_reply_t_handler
1023 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1025 vat_main_t *vam = &vat_main;
1026 i32 retval = ntohl (mp->retval);
1027 if (vam->async_mode)
1029 vam->async_errors += (retval < 0);
1033 vam->retval = retval;
1034 vam->result_ready = 1;
1040 vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
1042 vat_main_t *vam = &vat_main;
1043 u8 *s = 0, *eid = 0;
1045 if (~0 == mp->locator_set_index)
1046 s = format (0, "action: %d", mp->action);
1048 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
1050 eid = format (0, "%U", format_lisp_eid_vat,
1051 &mp->deid, &mp->seid, mp->is_src_dst);
1054 print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
1055 clib_net_to_host_u32 (mp->vni),
1057 mp->is_local ? "local" : "remote",
1058 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
1059 clib_net_to_host_u16 (mp->key.id), mp->key.key);
1066 vl_api_lisp_eid_table_map_details_t_handler
1067 (vl_api_lisp_eid_table_map_details_t * mp)
1069 vat_main_t *vam = &vat_main;
1071 u8 *line = format (0, "%=10d%=10d",
1072 clib_net_to_host_u32 (mp->vni),
1073 clib_net_to_host_u32 (mp->dp_table));
1074 print (vam->ofp, "%v", line);
1079 vl_api_lisp_eid_table_vni_details_t_handler
1080 (vl_api_lisp_eid_table_vni_details_t * mp)
1082 vat_main_t *vam = &vat_main;
1084 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
1085 print (vam->ofp, "%v", line);
1090 vl_api_lisp_adjacencies_get_reply_t_handler
1091 (vl_api_lisp_adjacencies_get_reply_t * mp)
1093 vat_main_t *vam = &vat_main;
1095 int retval = clib_net_to_host_u32 (mp->retval);
1096 vl_api_lisp_adjacency_t *a;
1101 n = clib_net_to_host_u32 (mp->count);
1103 for (i = 0; i < n; i++)
1105 a = &mp->adjacencies[i];
1106 print (vam->ofp, "%U %40U",
1107 format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid);
1111 vam->retval = retval;
1112 vam->result_ready = 1;
1116 vl_api_lisp_map_server_details_t_handler (vl_api_lisp_map_server_details_t *
1119 vat_main_t *vam = &vat_main;
1121 print (vam->ofp, "%=20U",
1122 mp->ip_address.af ? format_ip6_address : format_ip4_address,
1127 vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
1130 vat_main_t *vam = &vat_main;
1132 print (vam->ofp, "%=20U",
1133 mp->ip_address.af ? format_ip6_address : format_ip4_address,
1138 vl_api_show_lisp_status_reply_t_handler (vl_api_show_lisp_status_reply_t * mp)
1140 vat_main_t *vam = &vat_main;
1141 i32 retval = ntohl (mp->retval);
1145 print (vam->ofp, "feature: %s\ngpe: %s",
1146 mp->is_lisp_enabled ? "enabled" : "disabled",
1147 mp->is_gpe_enabled ? "enabled" : "disabled");
1150 vam->retval = retval;
1151 vam->result_ready = 1;
1155 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
1156 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
1158 vat_main_t *vam = &vat_main;
1159 i32 retval = ntohl (mp->retval);
1163 print (vam->ofp, "%=20s", mp->locator_set_name);
1166 vam->retval = retval;
1167 vam->result_ready = 1;
1171 vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
1173 vat_main_t *vam = &vat_main;
1174 i32 retval = ntohl (mp->retval);
1178 print (vam->ofp, "%-20s%-16s",
1179 mp->is_enabled ? "enabled" : "disabled",
1180 mp->is_enabled ? (char *) mp->locator_set_name : "");
1183 vam->retval = retval;
1184 vam->result_ready = 1;
1188 unformat_hmac_key_id (unformat_input_t * input, va_list * args)
1190 u32 *key_id = va_arg (*args, u32 *);
1193 if (unformat (input, "%s", &s))
1195 if (!strcmp ((char *) s, "sha1"))
1196 key_id[0] = HMAC_SHA_1_96;
1197 else if (!strcmp ((char *) s, "sha256"))
1198 key_id[0] = HMAC_SHA_256_128;
1201 clib_warning ("invalid key_id: '%s'", s);
1202 key_id[0] = HMAC_NO_KEY;
1215 api_show_lisp_map_request_mode (vat_main_t * vam)
1217 vl_api_show_lisp_map_request_mode_t *mp;
1220 M (SHOW_LISP_MAP_REQUEST_MODE, mp);
1225 /* wait for reply */
1231 api_lisp_map_request_mode (vat_main_t * vam)
1233 unformat_input_t *input = vam->input;
1234 vl_api_lisp_map_request_mode_t *mp;
1238 /* Parse args required to build the message */
1239 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1241 if (unformat (input, "dst-only"))
1243 else if (unformat (input, "src-dst"))
1247 errmsg ("parse error '%U'", format_unformat_error, input);
1252 M (LISP_MAP_REQUEST_MODE, mp);
1254 mp->is_src_dst = mode == 1;
1259 /* wait for reply */
1265 api_show_lisp_pitr (vat_main_t * vam)
1267 vl_api_show_lisp_pitr_t *mp;
1270 if (!vam->json_output)
1272 print (vam->ofp, "%=20s", "lisp status:");
1275 M (SHOW_LISP_PITR, mp);
1279 /* Wait for a reply... */
1285 * Add/delete mapping between vni and vrf
1288 api_lisp_eid_table_add_del_map (vat_main_t * vam)
1290 unformat_input_t *input = vam->input;
1291 vl_api_lisp_eid_table_add_del_map_t *mp;
1292 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
1293 u32 vni, vrf, bd_index;
1296 /* Parse args required to build the message */
1297 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1299 if (unformat (input, "del"))
1301 else if (unformat (input, "vrf %d", &vrf))
1303 else if (unformat (input, "bd_index %d", &bd_index))
1305 else if (unformat (input, "vni %d", &vni))
1311 if (!vni_set || (!vrf_set && !bd_index_set))
1313 errmsg ("missing arguments!");
1317 if (vrf_set && bd_index_set)
1319 errmsg ("error: both vrf and bd entered!");
1323 M (LISP_EID_TABLE_ADD_DEL_MAP, mp);
1325 mp->is_add = is_add;
1326 mp->vni = htonl (vni);
1327 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
1328 mp->is_l2 = bd_index_set;
1333 /* wait for reply */
1339 * Add/del remote mapping to/from LISP control plane
1341 * @param vam vpp API test context
1342 * @return return code
1345 api_lisp_add_del_remote_mapping (vat_main_t * vam)
1347 unformat_input_t *input = vam->input;
1348 vl_api_lisp_add_del_remote_mapping_t *mp;
1350 lisp_eid_vat_t _eid, *eid = &_eid;
1351 lisp_eid_vat_t _seid, *seid = &_seid;
1352 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
1353 u32 action = ~0, p, w, data_len;
1354 ip4_address_t rloc4;
1355 ip6_address_t rloc6;
1356 vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
1359 clib_memset (&rloc, 0, sizeof (rloc));
1361 /* Parse args required to build the message */
1362 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1364 if (unformat (input, "del-all"))
1368 else if (unformat (input, "del"))
1372 else if (unformat (input, "add"))
1376 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
1380 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
1384 else if (unformat (input, "vni %d", &vni))
1388 else if (unformat (input, "p %d w %d", &p, &w))
1392 errmsg ("No RLOC configured for setting priority/weight!");
1395 curr_rloc->priority = p;
1396 curr_rloc->weight = w;
1398 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
1400 rloc.ip_address.af = 0;
1401 clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6));
1402 vec_add1 (rlocs, rloc);
1403 curr_rloc = &rlocs[vec_len (rlocs) - 1];
1405 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
1407 rloc.ip_address.af = 1;
1408 clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4));
1409 vec_add1 (rlocs, rloc);
1410 curr_rloc = &rlocs[vec_len (rlocs) - 1];
1412 else if (unformat (input, "action %U",
1413 unformat_negative_mapping_action, &action))
1419 clib_warning ("parse error '%U'", format_unformat_error, input);
1426 errmsg ("missing params!");
1430 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
1432 errmsg ("no action set for negative map-reply!");
1436 data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
1438 M2 (LISP_ADD_DEL_REMOTE_MAPPING, mp, data_len);
1439 mp->is_add = is_add;
1440 mp->vni = htonl (vni);
1441 mp->action = (u8) action;
1442 mp->is_src_dst = seid_set;
1443 mp->del_all = del_all;
1444 lisp_eid_put_vat (&mp->deid, eid);
1445 lisp_eid_put_vat (&mp->seid, seid);
1447 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
1448 clib_memcpy (mp->rlocs, rlocs, data_len);
1454 /* Wait for a reply... */
1460 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
1461 * forwarding entries in data-plane accordingly.
1463 * @param vam vpp API test context
1464 * @return return code
1467 api_lisp_add_del_adjacency (vat_main_t * vam)
1469 unformat_input_t *input = vam->input;
1470 vl_api_lisp_add_del_adjacency_t *mp;
1474 lisp_eid_vat_t leid, reid;
1476 leid.type = reid.type = (u8) ~ 0;
1478 /* Parse args required to build the message */
1479 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1481 if (unformat (input, "del"))
1485 else if (unformat (input, "add"))
1489 else if (unformat (input, "reid %U/%d", unformat_ip46_address,
1490 &reid.addr.ip, &reid.len))
1492 reid.type = 0; /* ipv4 */
1494 else if (unformat (input, "reid %U", unformat_ethernet_address,
1497 reid.type = 1; /* mac */
1499 else if (unformat (input, "leid %U/%d", unformat_ip46_address,
1500 &leid.addr.ip, &leid.len))
1502 leid.type = 0; /* ipv4 */
1504 else if (unformat (input, "leid %U", unformat_ethernet_address,
1507 leid.type = 1; /* mac */
1509 else if (unformat (input, "vni %d", &vni))
1515 errmsg ("parse error '%U'", format_unformat_error, input);
1520 if ((u8) ~ 0 == reid.type)
1522 errmsg ("missing params!");
1526 if (leid.type != reid.type)
1528 errmsg ("remote and local EIDs are of different types!");
1532 M (LISP_ADD_DEL_ADJACENCY, mp);
1533 mp->is_add = is_add;
1534 mp->vni = htonl (vni);
1535 lisp_eid_put_vat (&mp->leid, &leid);
1536 lisp_eid_put_vat (&mp->reid, &reid);
1541 /* Wait for a reply... */
1547 * Add/del map request itr rlocs from LISP control plane and updates
1549 * @param vam vpp API test context
1550 * @return return code
1553 api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
1555 unformat_input_t *input = vam->input;
1556 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
1557 u8 *locator_set_name = 0;
1558 u8 locator_set_name_set = 0;
1562 /* Parse args required to build the message */
1563 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1565 if (unformat (input, "del"))
1569 else if (unformat (input, "%_%v%_", &locator_set_name))
1571 locator_set_name_set = 1;
1575 clib_warning ("parse error '%U'", format_unformat_error, input);
1580 if (is_add && !locator_set_name_set)
1582 errmsg ("itr-rloc is not set!");
1586 if (is_add && vec_len (locator_set_name) > 64)
1588 errmsg ("itr-rloc locator-set name too long");
1589 vec_free (locator_set_name);
1593 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
1594 mp->is_add = is_add;
1597 clib_memcpy (mp->locator_set_name, locator_set_name,
1598 vec_len (locator_set_name));
1602 clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
1604 vec_free (locator_set_name);
1609 /* Wait for a reply... */
1615 api_lisp_locator_dump (vat_main_t * vam)
1617 unformat_input_t *input = vam->input;
1618 vl_api_lisp_locator_dump_t *mp;
1619 vl_api_control_ping_t *mp_ping;
1620 u8 is_index_set = 0, is_name_set = 0;
1625 /* Parse args required to build the message */
1626 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1628 if (unformat (input, "ls_name %_%v%_", &ls_name))
1632 else if (unformat (input, "ls_index %d", &ls_index))
1638 errmsg ("parse error '%U'", format_unformat_error, input);
1643 if (!is_index_set && !is_name_set)
1645 errmsg ("error: expected lisp of index or name!");
1649 if (is_index_set && is_name_set)
1651 errmsg ("error: only lisp param expected!");
1655 if (vec_len (ls_name) > 62)
1657 errmsg ("error: locator set name too long!");
1661 if (!vam->json_output)
1663 print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
1666 M (LISP_LOCATOR_DUMP, mp);
1667 mp->is_index_set = is_index_set;
1670 mp->ls_index = clib_host_to_net_u32 (ls_index);
1673 vec_add1 (ls_name, 0);
1674 strncpy ((char *) mp->ls_name, (char *) ls_name,
1675 sizeof (mp->ls_name) - 1);
1681 /* Use a control ping for synchronization */
1682 if (!lisp_test_main.ping_id)
1683 lisp_test_main.ping_id =
1684 vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
1685 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
1686 mp_ping->_vl_msg_id = htons (lisp_test_main.ping_id);
1687 mp_ping->client_index = vam->my_client_index;
1689 fformat (vam->ofp, "Sending ping id=%d\n", lisp_test_main.ping_id);
1691 vam->result_ready = 0;
1694 /* Wait for a reply... */
1700 api_lisp_locator_set_dump (vat_main_t * vam)
1702 vl_api_lisp_locator_set_dump_t *mp;
1703 vl_api_control_ping_t *mp_ping;
1704 unformat_input_t *input = vam->input;
1708 /* Parse args required to build the message */
1709 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1711 if (unformat (input, "local"))
1715 else if (unformat (input, "remote"))
1721 errmsg ("parse error '%U'", format_unformat_error, input);
1726 if (!vam->json_output)
1728 print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
1731 M (LISP_LOCATOR_SET_DUMP, mp);
1733 mp->filter = filter;
1738 /* Use a control ping for synchronization */
1739 LISP_PING (&lisp_test_main, mp_ping);
1742 /* Wait for a reply... */
1748 api_lisp_eid_table_map_dump (vat_main_t * vam)
1752 unformat_input_t *input = vam->input;
1753 vl_api_lisp_eid_table_map_dump_t *mp;
1754 vl_api_control_ping_t *mp_ping;
1757 /* Parse args required to build the message */
1758 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1760 if (unformat (input, "l2"))
1765 else if (unformat (input, "l3"))
1772 errmsg ("parse error '%U'", format_unformat_error, input);
1779 errmsg ("expected lisp of 'l2' or 'l3' parameter!");
1783 if (!vam->json_output)
1785 print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1788 M (LISP_EID_TABLE_MAP_DUMP, mp);
1794 /* Use a control ping for synchronization */
1795 LISP_PING (&lisp_test_main, mp_ping);
1798 /* Wait for a reply... */
1804 api_lisp_eid_table_vni_dump (vat_main_t * vam)
1806 vl_api_lisp_eid_table_vni_dump_t *mp;
1807 vl_api_control_ping_t *mp_ping;
1810 if (!vam->json_output)
1812 print (vam->ofp, "VNI");
1815 M (LISP_EID_TABLE_VNI_DUMP, mp);
1820 /* Use a control ping for synchronization */
1821 LISP_PING (&lisp_test_main, mp_ping);
1824 /* Wait for a reply... */
1830 api_lisp_eid_table_dump (vat_main_t * vam)
1832 unformat_input_t *i = vam->input;
1833 vl_api_lisp_eid_table_dump_t *mp;
1834 vl_api_control_ping_t *mp_ping;
1841 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1844 (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len))
1850 if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac))
1855 else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh))
1860 else if (unformat (i, "vni %d", &t))
1864 else if (unformat (i, "local"))
1868 else if (unformat (i, "remote"))
1874 errmsg ("parse error '%U'", format_unformat_error, i);
1879 if (!vam->json_output)
1881 print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
1882 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
1885 M (LISP_EID_TABLE_DUMP, mp);
1887 mp->filter = filter;
1891 mp->vni = htonl (vni);
1892 lisp_eid_put_vat (&mp->eid, &eid);
1898 /* Use a control ping for synchronization */
1899 LISP_PING (&lisp_test_main, mp_ping);
1902 /* Wait for a reply... */
1909 api_lisp_adjacencies_get (vat_main_t * vam)
1911 unformat_input_t *i = vam->input;
1912 vl_api_lisp_adjacencies_get_t *mp;
1917 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1919 if (unformat (i, "vni %d", &vni))
1925 errmsg ("parse error '%U'", format_unformat_error, i);
1932 errmsg ("vni not set!");
1936 if (!vam->json_output)
1938 print (vam->ofp, "%s %40s", "leid", "reid");
1941 M (LISP_ADJACENCIES_GET, mp);
1942 mp->vni = clib_host_to_net_u32 (vni);
1947 /* Wait for a reply... */
1953 api_lisp_map_server_dump (vat_main_t * vam)
1955 vl_api_lisp_map_server_dump_t *mp;
1956 vl_api_control_ping_t *mp_ping;
1959 if (!vam->json_output)
1961 print (vam->ofp, "%=20s", "Map server");
1964 M (LISP_MAP_SERVER_DUMP, mp);
1968 /* Use a control ping for synchronization */
1969 LISP_PING (&lisp_test_main, mp_ping);
1972 /* Wait for a reply... */
1978 api_lisp_map_resolver_dump (vat_main_t * vam)
1980 vl_api_lisp_map_resolver_dump_t *mp;
1981 vl_api_control_ping_t *mp_ping;
1984 if (!vam->json_output)
1986 print (vam->ofp, "%=20s", "Map resolver");
1989 M (LISP_MAP_RESOLVER_DUMP, mp);
1993 /* Use a control ping for synchronization */
1994 LISP_PING (&lisp_test_main, mp_ping);
1997 /* Wait for a reply... */
2003 api_show_lisp_status (vat_main_t * vam)
2005 vl_api_show_lisp_status_t *mp;
2008 if (!vam->json_output)
2010 print (vam->ofp, "%-20s%-16s", "LISP status", "locator-set");
2013 M (SHOW_LISP_STATUS, mp);
2016 /* Wait for a reply... */
2022 api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
2024 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
2027 if (!vam->json_output)
2029 print (vam->ofp, "%=20s", "itr-rlocs:");
2032 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, mp);
2035 /* Wait for a reply... */
2040 #define vat_plugin_register vat_plugin_register_cp
2041 #include <lisp/lisp-cp/lisp.api_test.c>
2044 * fd.io coding-style-patch-verification: ON
2047 * eval: (c-set-style "gnu")