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 <lisp/lisp-cp/lisp_types.h>
25 /* define message IDs */
26 #include <lisp/lisp-cp/lisp.api_enum.h>
27 #include <lisp/lisp-cp/lisp.api_types.h>
28 #include <vpp/api/vpe.api_types.h>
32 /* API message ID base */
38 lisp_test_main_t lisp_test_main;
40 #define __plugin_msg_base lisp_test_main.msg_id_base
41 #include <vlibapi/vat_helper_macros.h>
43 /* Macro to finish up custom dump fns */
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
47 vl_print (handle, (char *)s); \
55 } __attribute__ ((__packed__)) lisp_nsh_api_t;
57 #define LISP_PING(_lm, mp_ping) \
58 if (!(_lm)->ping_id) \
59 (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \
60 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); \
61 mp_ping->_vl_msg_id = htons ((_lm)->ping_id); \
62 mp_ping->client_index = vam->my_client_index; \
63 fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id); \
64 vam->result_ready = 0; \
67 unformat_nsh_address (unformat_input_t * input, va_list * args)
69 lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
70 return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
74 format_nsh_address_vat (u8 * s, va_list * args)
76 nsh_t *a = va_arg (*args, nsh_t *);
77 return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
81 format_lisp_flat_eid (u8 * s, va_list * args)
83 vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *);
87 case EID_TYPE_API_PREFIX:
88 if (eid->address.prefix.address.af)
89 return format (s, "%U/%d", format_ip6_address,
90 eid->address.prefix.address.un.ip6,
91 eid->address.prefix.len);
92 return format (s, "%U/%d", format_ip4_address,
93 eid->address.prefix.address.un.ip4,
94 eid->address.prefix.len);
95 case EID_TYPE_API_MAC:
96 return format (s, "%U", format_ethernet_address, eid->address.mac);
97 case EID_TYPE_API_NSH:
98 return format (s, "%U", format_nsh_address_vat, eid->address.nsh);
104 format_lisp_eid_vat (u8 * s, va_list * args)
106 vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *);
107 vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *);
108 u8 is_src_dst = (u8) va_arg (*args, int);
111 s = format (s, "%U|", format_lisp_flat_eid, seid);
113 s = format (s, "%U", format_lisp_flat_eid, deid);
121 /** Used for parsing LISP eids */
122 typedef struct lisp_eid_vat_t_
129 /**< prefix length if IP */
133 } __clib_packed lisp_eid_vat_t;
137 unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
139 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
141 clib_memset (a, 0, sizeof (a[0]));
143 if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len))
145 a->type = 0; /* ip prefix type */
147 else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac))
149 a->type = 1; /* mac type */
151 else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh))
153 a->type = 2; /* NSH type */
154 a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi);
163 if (ip46_address_is_ip4 (&a->addr.ip))
164 return a->len > 32 ? 1 : 0;
166 return a->len > 128 ? 1 : 0;
173 lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid)
175 eid->type = vat_eid->type;
178 case EID_TYPE_API_PREFIX:
179 if (ip46_address_is_ip4 (&vat_eid->addr.ip))
181 clib_memcpy (&eid->address.prefix.address.un.ip4,
182 &vat_eid->addr.ip.ip4, 4);
183 eid->address.prefix.address.af = ADDRESS_IP4;
184 eid->address.prefix.len = vat_eid->len;
188 clib_memcpy (&eid->address.prefix.address.un.ip6,
189 &vat_eid->addr.ip.ip6, 16);
190 eid->address.prefix.address.af = ADDRESS_IP6;
191 eid->address.prefix.len = vat_eid->len;
194 case EID_TYPE_API_MAC:
195 clib_memcpy (&eid->address.mac, &vat_eid->addr.mac,
196 sizeof (eid->address.mac));
198 case EID_TYPE_API_NSH:
199 clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh,
200 sizeof (eid->address.nsh));
209 api_lisp_add_del_locator_set (vat_main_t * vam)
211 unformat_input_t *input = vam->input;
212 vl_api_lisp_add_del_locator_set_t *mp;
214 u8 *locator_set_name = NULL;
215 u8 locator_set_name_set = 0;
216 vl_api_local_locator_t locator, *locators = 0;
217 u32 sw_if_index, priority, weight;
221 /* Parse args required to build the message */
222 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
224 if (unformat (input, "del"))
228 else if (unformat (input, "locator-set %s", &locator_set_name))
230 locator_set_name_set = 1;
232 else if (unformat (input, "sw_if_index %u p %u w %u",
233 &sw_if_index, &priority, &weight))
235 locator.sw_if_index = htonl (sw_if_index);
236 locator.priority = priority;
237 locator.weight = weight;
238 vec_add1 (locators, locator);
242 (input, "iface %U p %u w %u", unformat_sw_if_index, vam,
243 &sw_if_index, &priority, &weight))
245 locator.sw_if_index = htonl (sw_if_index);
246 locator.priority = priority;
247 locator.weight = weight;
248 vec_add1 (locators, locator);
254 if (locator_set_name_set == 0)
256 errmsg ("missing locator-set name");
261 if (vec_len (locator_set_name) > 64)
263 errmsg ("locator-set name too long");
264 vec_free (locator_set_name);
268 vec_add1 (locator_set_name, 0);
270 data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
272 /* Construct the API message */
273 M2 (LISP_ADD_DEL_LOCATOR_SET, mp, data_len);
276 clib_memcpy (mp->locator_set_name, locator_set_name,
277 vec_len (locator_set_name));
278 vec_free (locator_set_name);
280 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
282 clib_memcpy (mp->locators, locators, data_len);
288 /* Wait for a reply... */
294 api_lisp_add_del_locator (vat_main_t * vam)
296 unformat_input_t *input = vam->input;
297 vl_api_lisp_add_del_locator_t *mp;
298 u32 tmp_if_index = ~0;
299 u32 sw_if_index = ~0;
300 u8 sw_if_index_set = 0;
301 u8 sw_if_index_if_name_set = 0;
307 u8 *locator_set_name = NULL;
308 u8 locator_set_name_set = 0;
311 /* Parse args required to build the message */
312 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
314 if (unformat (input, "del"))
318 else if (unformat (input, "locator-set %s", &locator_set_name))
320 locator_set_name_set = 1;
322 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
325 sw_if_index_if_name_set = 1;
326 sw_if_index = tmp_if_index;
328 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
331 sw_if_index = tmp_if_index;
333 else if (unformat (input, "p %d", &priority))
337 else if (unformat (input, "w %d", &weight))
345 if (locator_set_name_set == 0)
347 errmsg ("missing locator-set name");
351 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
353 errmsg ("missing sw_if_index");
354 vec_free (locator_set_name);
358 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
360 errmsg ("cannot use both params interface name and sw_if_index");
361 vec_free (locator_set_name);
365 if (priority_set == 0)
367 errmsg ("missing locator-set priority");
368 vec_free (locator_set_name);
374 errmsg ("missing locator-set weight");
375 vec_free (locator_set_name);
379 if (vec_len (locator_set_name) > 64)
381 errmsg ("locator-set name too long");
382 vec_free (locator_set_name);
385 vec_add1 (locator_set_name, 0);
387 /* Construct the API message */
388 M (LISP_ADD_DEL_LOCATOR, mp);
391 mp->sw_if_index = ntohl (sw_if_index);
392 mp->priority = priority;
394 clib_memcpy (mp->locator_set_name, locator_set_name,
395 vec_len (locator_set_name));
396 vec_free (locator_set_name);
401 /* Wait for a reply... */
407 api_lisp_add_del_local_eid (vat_main_t * vam)
409 unformat_input_t *input = vam->input;
410 vl_api_lisp_add_del_local_eid_t *mp;
413 lisp_eid_vat_t _eid, *eid = &_eid;
414 u8 *locator_set_name = 0;
415 u8 locator_set_name_set = 0;
421 /* Parse args required to build the message */
422 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
424 if (unformat (input, "del"))
428 else if (unformat (input, "vni %d", &vni))
432 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
436 else if (unformat (input, "locator-set %s", &locator_set_name))
438 locator_set_name_set = 1;
440 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
442 else if (unformat (input, "secret-key %_%v%_", &key))
448 if (locator_set_name_set == 0)
450 errmsg ("missing locator-set name");
456 errmsg ("EID address not set!");
457 vec_free (locator_set_name);
461 if (key && (0 == key_id))
463 errmsg ("invalid key_id!");
467 if (vec_len (key) > 64)
469 errmsg ("key too long");
474 if (vec_len (locator_set_name) > 64)
476 errmsg ("locator-set name too long");
477 vec_free (locator_set_name);
480 vec_add1 (locator_set_name, 0);
482 /* Construct the API message */
483 M (LISP_ADD_DEL_LOCAL_EID, mp);
486 lisp_eid_put_vat (&mp->eid, eid);
487 mp->vni = clib_host_to_net_u32 (vni);
489 clib_memcpy (mp->locator_set_name, locator_set_name,
490 vec_len (locator_set_name));
491 clib_memcpy (mp->key.key, key, vec_len (key));
493 vec_free (locator_set_name);
499 /* Wait for a reply... */
505 api_lisp_add_del_map_server (vat_main_t * vam)
507 unformat_input_t *input = vam->input;
508 vl_api_lisp_add_del_map_server_t *mp;
516 /* Parse args required to build the message */
517 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
519 if (unformat (input, "del"))
523 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
527 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
535 if (ipv4_set && ipv6_set)
537 errmsg ("both eid v4 and v6 addresses set");
541 if (!ipv4_set && !ipv6_set)
543 errmsg ("eid addresses not set");
547 /* Construct the API message */
548 M (LISP_ADD_DEL_MAP_SERVER, mp);
553 mp->ip_address.af = 1;
554 clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
558 mp->ip_address.af = 0;
559 clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4));
565 /* Wait for a reply... */
571 api_lisp_add_del_map_resolver (vat_main_t * vam)
573 unformat_input_t *input = vam->input;
574 vl_api_lisp_add_del_map_resolver_t *mp;
582 /* Parse args required to build the message */
583 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
585 if (unformat (input, "del"))
589 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
593 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
601 if (ipv4_set && ipv6_set)
603 errmsg ("both eid v4 and v6 addresses set");
607 if (!ipv4_set && !ipv6_set)
609 errmsg ("eid addresses not set");
613 /* Construct the API message */
614 M (LISP_ADD_DEL_MAP_RESOLVER, mp);
619 mp->ip_address.af = 1;
620 clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
624 mp->ip_address.af = 0;
625 clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4));
631 /* Wait for a reply... */
637 api_lisp_enable_disable (vat_main_t * vam)
639 unformat_input_t *input = vam->input;
640 vl_api_lisp_enable_disable_t *mp;
645 /* Parse args required to build the message */
646 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
648 if (unformat (input, "enable"))
653 else if (unformat (input, "disable"))
663 errmsg ("Value not set");
667 /* Construct the API message */
668 M (LISP_ENABLE_DISABLE, mp);
670 mp->is_enable = is_enable;
675 /* Wait for a reply... */
681 * Enable/disable LISP proxy ITR.
683 * @param vam vpp API test context
684 * @return return code
687 api_lisp_pitr_set_locator_set (vat_main_t * vam)
690 unformat_input_t *input = vam->input;
691 vl_api_lisp_pitr_set_locator_set_t *mp;
696 /* Parse args required to build the message */
697 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
699 if (unformat (input, "del"))
701 else if (unformat (input, "locator-set %s", &ls_name))
705 errmsg ("parse error '%U'", format_unformat_error, input);
712 errmsg ("locator-set name not set!");
716 M (LISP_PITR_SET_LOCATOR_SET, mp);
719 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
731 api_lisp_use_petr (vat_main_t * vam)
733 unformat_input_t *input = vam->input;
734 vl_api_lisp_use_petr_t *mp;
739 clib_memset (&ip, 0, sizeof (ip));
741 /* Parse args required to build the message */
742 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
744 if (unformat (input, "disable"))
747 if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
750 ip_addr_version (&ip) = AF_IP4;
753 if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
756 ip_addr_version (&ip) = AF_IP6;
760 errmsg ("parse error '%U'", format_unformat_error, input);
765 M (LISP_USE_PETR, mp);
770 mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1;
771 if (mp->ip_address.af)
772 clib_memcpy (mp->ip_address.un.ip6, &ip, 16);
774 clib_memcpy (mp->ip_address.un.ip4, &ip, 4);
786 vl_api_show_lisp_use_petr_reply_t_handler
787 (vl_api_show_lisp_use_petr_reply_t * mp)
789 vat_main_t *vam = &vat_main;
790 i32 retval = ntohl (mp->retval);
794 print (vam->ofp, "%s\n", mp->is_petr_enable ? "enabled" : "disabled");
795 if (mp->is_petr_enable)
797 print (vam->ofp, "Proxy-ETR address; %U",
798 mp->ip_address.af ? format_ip6_address : format_ip4_address,
803 vam->retval = retval;
804 vam->result_ready = 1;
808 api_show_lisp_use_petr (vat_main_t * vam)
810 vl_api_show_lisp_use_petr_t *mp;
813 if (!vam->json_output)
815 print (vam->ofp, "%=20s", "Proxy-ETR status:");
818 M (SHOW_LISP_USE_PETR, mp);
822 /* Wait for a reply... */
828 vl_api_show_lisp_rloc_probe_state_reply_t_handler
829 (vl_api_show_lisp_rloc_probe_state_reply_t * mp)
831 vat_main_t *vam = &vat_main;
832 int retval = clib_net_to_host_u32 (mp->retval);
837 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
839 vam->retval = retval;
840 vam->result_ready = 1;
844 api_show_lisp_map_register_state (vat_main_t * vam)
846 vl_api_show_lisp_map_register_state_t *mp;
849 M (SHOW_LISP_MAP_REGISTER_STATE, mp);
860 api_show_lisp_rloc_probe_state (vat_main_t * vam)
862 vl_api_show_lisp_rloc_probe_state_t *mp;
865 M (SHOW_LISP_RLOC_PROBE_STATE, mp);
876 api_lisp_rloc_probe_enable_disable (vat_main_t * vam)
878 unformat_input_t *input = vam->input;
879 vl_api_lisp_rloc_probe_enable_disable_t *mp;
884 /* Parse args required to build the message */
885 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
887 if (unformat (input, "enable"))
892 else if (unformat (input, "disable"))
900 errmsg ("Value not set");
904 /* Construct the API message */
905 M (LISP_RLOC_PROBE_ENABLE_DISABLE, mp);
907 mp->is_enable = is_enable;
912 /* Wait for a reply... */
918 api_lisp_map_register_enable_disable (vat_main_t * vam)
920 unformat_input_t *input = vam->input;
921 vl_api_lisp_map_register_enable_disable_t *mp;
926 /* Parse args required to build the message */
927 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
929 if (unformat (input, "enable"))
934 else if (unformat (input, "disable"))
942 errmsg ("Value not set");
946 /* Construct the API message */
947 M (LISP_MAP_REGISTER_ENABLE_DISABLE, mp);
949 mp->is_enable = is_enable;
954 /* Wait for a reply... */
960 vl_api_show_lisp_map_request_mode_reply_t_handler
961 (vl_api_show_lisp_map_request_mode_reply_t * mp)
963 vat_main_t *vam = &vat_main;
964 i32 retval = ntohl (mp->retval);
968 print (vam->ofp, "map_request_mode: %s",
969 mp->is_src_dst ? "src-dst" : "dst-only");
972 vam->retval = retval;
973 vam->result_ready = 1;
977 vl_api_show_lisp_map_register_state_reply_t_handler
978 (vl_api_show_lisp_map_register_state_reply_t * mp)
980 vat_main_t *vam = &vat_main;
981 int retval = clib_net_to_host_u32 (mp->retval);
983 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
985 vam->retval = retval;
986 vam->result_ready = 1;
990 vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
992 vat_main_t *vam = &vat_main;
997 s = format (s, "%=16d%=16d%=16d",
998 ntohl (mp->sw_if_index), mp->priority, mp->weight);
1002 s = format (s, "%=16U%=16d%=16d",
1003 format_ip46_address,
1004 mp->ip_address, mp->priority, mp->weight);
1007 print (vam->ofp, "%v", s);
1012 vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
1015 vat_main_t *vam = &vat_main;
1018 ls_name = format (0, "%s", mp->ls_name);
1020 print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
1025 static void vl_api_lisp_add_del_locator_set_reply_t_handler
1026 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1028 vat_main_t *vam = &vat_main;
1029 i32 retval = ntohl (mp->retval);
1030 if (vam->async_mode)
1032 vam->async_errors += (retval < 0);
1036 vam->retval = retval;
1037 vam->result_ready = 1;
1043 vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
1045 vat_main_t *vam = &vat_main;
1046 u8 *s = 0, *eid = 0;
1048 if (~0 == mp->locator_set_index)
1049 s = format (0, "action: %d", mp->action);
1051 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
1053 eid = format (0, "%U", format_lisp_eid_vat,
1054 &mp->deid, &mp->seid, mp->is_src_dst);
1057 print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
1058 clib_net_to_host_u32 (mp->vni),
1060 mp->is_local ? "local" : "remote",
1061 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
1062 clib_net_to_host_u16 (mp->key.id), mp->key.key);
1069 vl_api_lisp_eid_table_map_details_t_handler
1070 (vl_api_lisp_eid_table_map_details_t * mp)
1072 vat_main_t *vam = &vat_main;
1074 u8 *line = format (0, "%=10d%=10d",
1075 clib_net_to_host_u32 (mp->vni),
1076 clib_net_to_host_u32 (mp->dp_table));
1077 print (vam->ofp, "%v", line);
1082 vl_api_lisp_eid_table_vni_details_t_handler
1083 (vl_api_lisp_eid_table_vni_details_t * mp)
1085 vat_main_t *vam = &vat_main;
1087 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
1088 print (vam->ofp, "%v", line);
1093 vl_api_lisp_adjacencies_get_reply_t_handler
1094 (vl_api_lisp_adjacencies_get_reply_t * mp)
1096 vat_main_t *vam = &vat_main;
1098 int retval = clib_net_to_host_u32 (mp->retval);
1099 vl_api_lisp_adjacency_t *a;
1104 n = clib_net_to_host_u32 (mp->count);
1106 for (i = 0; i < n; i++)
1108 a = &mp->adjacencies[i];
1109 print (vam->ofp, "%U %40U",
1110 format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid);
1114 vam->retval = retval;
1115 vam->result_ready = 1;
1119 vl_api_lisp_map_server_details_t_handler (vl_api_lisp_map_server_details_t *
1122 vat_main_t *vam = &vat_main;
1124 print (vam->ofp, "%=20U",
1125 mp->ip_address.af ? format_ip6_address : format_ip4_address,
1130 vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
1133 vat_main_t *vam = &vat_main;
1135 print (vam->ofp, "%=20U",
1136 mp->ip_address.af ? format_ip6_address : format_ip4_address,
1141 vl_api_show_lisp_status_reply_t_handler (vl_api_show_lisp_status_reply_t * mp)
1143 vat_main_t *vam = &vat_main;
1144 i32 retval = ntohl (mp->retval);
1148 print (vam->ofp, "feature: %s\ngpe: %s",
1149 mp->is_lisp_enabled ? "enabled" : "disabled",
1150 mp->is_gpe_enabled ? "enabled" : "disabled");
1153 vam->retval = retval;
1154 vam->result_ready = 1;
1158 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
1159 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
1161 vat_main_t *vam = &vat_main;
1162 i32 retval = ntohl (mp->retval);
1166 print (vam->ofp, "%=20s", mp->locator_set_name);
1169 vam->retval = retval;
1170 vam->result_ready = 1;
1174 vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
1176 vat_main_t *vam = &vat_main;
1177 i32 retval = ntohl (mp->retval);
1181 print (vam->ofp, "%-20s%-16s",
1182 mp->is_enabled ? "enabled" : "disabled",
1183 mp->is_enabled ? (char *) mp->locator_set_name : "");
1186 vam->retval = retval;
1187 vam->result_ready = 1;
1191 unformat_hmac_key_id (unformat_input_t * input, va_list * args)
1193 u32 *key_id = va_arg (*args, u32 *);
1196 if (unformat (input, "%s", &s))
1198 if (!strcmp ((char *) s, "sha1"))
1199 key_id[0] = HMAC_SHA_1_96;
1200 else if (!strcmp ((char *) s, "sha256"))
1201 key_id[0] = HMAC_SHA_256_128;
1204 clib_warning ("invalid key_id: '%s'", s);
1205 key_id[0] = HMAC_NO_KEY;
1218 api_show_lisp_map_request_mode (vat_main_t * vam)
1220 vl_api_show_lisp_map_request_mode_t *mp;
1223 M (SHOW_LISP_MAP_REQUEST_MODE, mp);
1228 /* wait for reply */
1234 api_lisp_map_request_mode (vat_main_t * vam)
1236 unformat_input_t *input = vam->input;
1237 vl_api_lisp_map_request_mode_t *mp;
1241 /* Parse args required to build the message */
1242 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1244 if (unformat (input, "dst-only"))
1246 else if (unformat (input, "src-dst"))
1250 errmsg ("parse error '%U'", format_unformat_error, input);
1255 M (LISP_MAP_REQUEST_MODE, mp);
1257 mp->is_src_dst = mode == 1;
1262 /* wait for reply */
1268 api_show_lisp_pitr (vat_main_t * vam)
1270 vl_api_show_lisp_pitr_t *mp;
1273 if (!vam->json_output)
1275 print (vam->ofp, "%=20s", "lisp status:");
1278 M (SHOW_LISP_PITR, mp);
1282 /* Wait for a reply... */
1288 * Add/delete mapping between vni and vrf
1291 api_lisp_eid_table_add_del_map (vat_main_t * vam)
1293 unformat_input_t *input = vam->input;
1294 vl_api_lisp_eid_table_add_del_map_t *mp;
1295 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
1296 u32 vni, vrf, bd_index;
1299 /* Parse args required to build the message */
1300 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1302 if (unformat (input, "del"))
1304 else if (unformat (input, "vrf %d", &vrf))
1306 else if (unformat (input, "bd_index %d", &bd_index))
1308 else if (unformat (input, "vni %d", &vni))
1314 if (!vni_set || (!vrf_set && !bd_index_set))
1316 errmsg ("missing arguments!");
1320 if (vrf_set && bd_index_set)
1322 errmsg ("error: both vrf and bd entered!");
1326 M (LISP_EID_TABLE_ADD_DEL_MAP, mp);
1328 mp->is_add = is_add;
1329 mp->vni = htonl (vni);
1330 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
1331 mp->is_l2 = bd_index_set;
1336 /* wait for reply */
1342 * Add/del remote mapping to/from LISP control plane
1344 * @param vam vpp API test context
1345 * @return return code
1348 api_lisp_add_del_remote_mapping (vat_main_t * vam)
1350 unformat_input_t *input = vam->input;
1351 vl_api_lisp_add_del_remote_mapping_t *mp;
1353 lisp_eid_vat_t _eid, *eid = &_eid;
1354 lisp_eid_vat_t _seid, *seid = &_seid;
1355 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
1356 u32 action = ~0, p, w, data_len;
1357 ip4_address_t rloc4;
1358 ip6_address_t rloc6;
1359 vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
1362 clib_memset (&rloc, 0, sizeof (rloc));
1364 /* Parse args required to build the message */
1365 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1367 if (unformat (input, "del-all"))
1371 else if (unformat (input, "del"))
1375 else if (unformat (input, "add"))
1379 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
1383 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
1387 else if (unformat (input, "vni %d", &vni))
1391 else if (unformat (input, "p %d w %d", &p, &w))
1395 errmsg ("No RLOC configured for setting priority/weight!");
1398 curr_rloc->priority = p;
1399 curr_rloc->weight = w;
1401 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
1403 rloc.ip_address.af = 0;
1404 clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6));
1405 vec_add1 (rlocs, rloc);
1406 curr_rloc = &rlocs[vec_len (rlocs) - 1];
1408 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
1410 rloc.ip_address.af = 1;
1411 clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4));
1412 vec_add1 (rlocs, rloc);
1413 curr_rloc = &rlocs[vec_len (rlocs) - 1];
1415 else if (unformat (input, "action %U",
1416 unformat_negative_mapping_action, &action))
1422 clib_warning ("parse error '%U'", format_unformat_error, input);
1429 errmsg ("missing params!");
1433 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
1435 errmsg ("no action set for negative map-reply!");
1439 data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
1441 M2 (LISP_ADD_DEL_REMOTE_MAPPING, mp, data_len);
1442 mp->is_add = is_add;
1443 mp->vni = htonl (vni);
1444 mp->action = (u8) action;
1445 mp->is_src_dst = seid_set;
1446 mp->del_all = del_all;
1447 lisp_eid_put_vat (&mp->deid, eid);
1448 lisp_eid_put_vat (&mp->seid, seid);
1450 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
1451 clib_memcpy (mp->rlocs, rlocs, data_len);
1457 /* Wait for a reply... */
1463 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
1464 * forwarding entries in data-plane accordingly.
1466 * @param vam vpp API test context
1467 * @return return code
1470 api_lisp_add_del_adjacency (vat_main_t * vam)
1472 unformat_input_t *input = vam->input;
1473 vl_api_lisp_add_del_adjacency_t *mp;
1477 lisp_eid_vat_t leid, reid;
1479 leid.type = reid.type = (u8) ~ 0;
1481 /* Parse args required to build the message */
1482 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1484 if (unformat (input, "del"))
1488 else if (unformat (input, "add"))
1492 else if (unformat (input, "reid %U/%d", unformat_ip46_address,
1493 &reid.addr.ip, &reid.len))
1495 reid.type = 0; /* ipv4 */
1497 else if (unformat (input, "reid %U", unformat_ethernet_address,
1500 reid.type = 1; /* mac */
1502 else if (unformat (input, "leid %U/%d", unformat_ip46_address,
1503 &leid.addr.ip, &leid.len))
1505 leid.type = 0; /* ipv4 */
1507 else if (unformat (input, "leid %U", unformat_ethernet_address,
1510 leid.type = 1; /* mac */
1512 else if (unformat (input, "vni %d", &vni))
1518 errmsg ("parse error '%U'", format_unformat_error, input);
1523 if ((u8) ~ 0 == reid.type)
1525 errmsg ("missing params!");
1529 if (leid.type != reid.type)
1531 errmsg ("remote and local EIDs are of different types!");
1535 M (LISP_ADD_DEL_ADJACENCY, mp);
1536 mp->is_add = is_add;
1537 mp->vni = htonl (vni);
1538 lisp_eid_put_vat (&mp->leid, &leid);
1539 lisp_eid_put_vat (&mp->reid, &reid);
1544 /* Wait for a reply... */
1550 * Add/del map request itr rlocs from LISP control plane and updates
1552 * @param vam vpp API test context
1553 * @return return code
1556 api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
1558 unformat_input_t *input = vam->input;
1559 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
1560 u8 *locator_set_name = 0;
1561 u8 locator_set_name_set = 0;
1565 /* Parse args required to build the message */
1566 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1568 if (unformat (input, "del"))
1572 else if (unformat (input, "%_%v%_", &locator_set_name))
1574 locator_set_name_set = 1;
1578 clib_warning ("parse error '%U'", format_unformat_error, input);
1583 if (is_add && !locator_set_name_set)
1585 errmsg ("itr-rloc is not set!");
1589 if (is_add && vec_len (locator_set_name) > 64)
1591 errmsg ("itr-rloc locator-set name too long");
1592 vec_free (locator_set_name);
1596 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
1597 mp->is_add = is_add;
1600 clib_memcpy (mp->locator_set_name, locator_set_name,
1601 vec_len (locator_set_name));
1605 clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
1607 vec_free (locator_set_name);
1612 /* Wait for a reply... */
1618 api_lisp_locator_dump (vat_main_t * vam)
1620 unformat_input_t *input = vam->input;
1621 vl_api_lisp_locator_dump_t *mp;
1622 vl_api_control_ping_t *mp_ping;
1623 u8 is_index_set = 0, is_name_set = 0;
1628 /* Parse args required to build the message */
1629 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1631 if (unformat (input, "ls_name %_%v%_", &ls_name))
1635 else if (unformat (input, "ls_index %d", &ls_index))
1641 errmsg ("parse error '%U'", format_unformat_error, input);
1646 if (!is_index_set && !is_name_set)
1648 errmsg ("error: expected lisp of index or name!");
1652 if (is_index_set && is_name_set)
1654 errmsg ("error: only lisp param expected!");
1658 if (vec_len (ls_name) > 62)
1660 errmsg ("error: locator set name too long!");
1664 if (!vam->json_output)
1666 print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
1669 M (LISP_LOCATOR_DUMP, mp);
1670 mp->is_index_set = is_index_set;
1673 mp->ls_index = clib_host_to_net_u32 (ls_index);
1676 vec_add1 (ls_name, 0);
1677 strncpy ((char *) mp->ls_name, (char *) ls_name,
1678 sizeof (mp->ls_name) - 1);
1684 /* Use a control ping for synchronization */
1685 if (!lisp_test_main.ping_id)
1686 lisp_test_main.ping_id =
1687 vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
1688 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
1689 mp_ping->_vl_msg_id = htons (lisp_test_main.ping_id);
1690 mp_ping->client_index = vam->my_client_index;
1692 fformat (vam->ofp, "Sending ping id=%d\n", lisp_test_main.ping_id);
1694 vam->result_ready = 0;
1697 /* Wait for a reply... */
1703 api_lisp_locator_set_dump (vat_main_t * vam)
1705 vl_api_lisp_locator_set_dump_t *mp;
1706 vl_api_control_ping_t *mp_ping;
1707 unformat_input_t *input = vam->input;
1711 /* Parse args required to build the message */
1712 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1714 if (unformat (input, "local"))
1718 else if (unformat (input, "remote"))
1724 errmsg ("parse error '%U'", format_unformat_error, input);
1729 if (!vam->json_output)
1731 print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
1734 M (LISP_LOCATOR_SET_DUMP, mp);
1736 mp->filter = filter;
1741 /* Use a control ping for synchronization */
1742 LISP_PING (&lisp_test_main, mp_ping);
1745 /* Wait for a reply... */
1751 api_lisp_eid_table_map_dump (vat_main_t * vam)
1755 unformat_input_t *input = vam->input;
1756 vl_api_lisp_eid_table_map_dump_t *mp;
1757 vl_api_control_ping_t *mp_ping;
1760 /* Parse args required to build the message */
1761 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1763 if (unformat (input, "l2"))
1768 else if (unformat (input, "l3"))
1775 errmsg ("parse error '%U'", format_unformat_error, input);
1782 errmsg ("expected lisp of 'l2' or 'l3' parameter!");
1786 if (!vam->json_output)
1788 print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1791 M (LISP_EID_TABLE_MAP_DUMP, mp);
1797 /* Use a control ping for synchronization */
1798 LISP_PING (&lisp_test_main, mp_ping);
1801 /* Wait for a reply... */
1807 api_lisp_eid_table_vni_dump (vat_main_t * vam)
1809 vl_api_lisp_eid_table_vni_dump_t *mp;
1810 vl_api_control_ping_t *mp_ping;
1813 if (!vam->json_output)
1815 print (vam->ofp, "VNI");
1818 M (LISP_EID_TABLE_VNI_DUMP, mp);
1823 /* Use a control ping for synchronization */
1824 LISP_PING (&lisp_test_main, mp_ping);
1827 /* Wait for a reply... */
1833 api_lisp_eid_table_dump (vat_main_t * vam)
1835 unformat_input_t *i = vam->input;
1836 vl_api_lisp_eid_table_dump_t *mp;
1837 vl_api_control_ping_t *mp_ping;
1844 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1847 (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len))
1853 if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac))
1858 else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh))
1863 else if (unformat (i, "vni %d", &t))
1867 else if (unformat (i, "local"))
1871 else if (unformat (i, "remote"))
1877 errmsg ("parse error '%U'", format_unformat_error, i);
1882 if (!vam->json_output)
1884 print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
1885 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
1888 M (LISP_EID_TABLE_DUMP, mp);
1890 mp->filter = filter;
1894 mp->vni = htonl (vni);
1895 lisp_eid_put_vat (&mp->eid, &eid);
1901 /* Use a control ping for synchronization */
1902 LISP_PING (&lisp_test_main, mp_ping);
1905 /* Wait for a reply... */
1912 api_lisp_adjacencies_get (vat_main_t * vam)
1914 unformat_input_t *i = vam->input;
1915 vl_api_lisp_adjacencies_get_t *mp;
1920 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1922 if (unformat (i, "vni %d", &vni))
1928 errmsg ("parse error '%U'", format_unformat_error, i);
1935 errmsg ("vni not set!");
1939 if (!vam->json_output)
1941 print (vam->ofp, "%s %40s", "leid", "reid");
1944 M (LISP_ADJACENCIES_GET, mp);
1945 mp->vni = clib_host_to_net_u32 (vni);
1950 /* Wait for a reply... */
1956 api_lisp_map_server_dump (vat_main_t * vam)
1958 vl_api_lisp_map_server_dump_t *mp;
1959 vl_api_control_ping_t *mp_ping;
1962 if (!vam->json_output)
1964 print (vam->ofp, "%=20s", "Map server");
1967 M (LISP_MAP_SERVER_DUMP, mp);
1971 /* Use a control ping for synchronization */
1972 LISP_PING (&lisp_test_main, mp_ping);
1975 /* Wait for a reply... */
1981 api_lisp_map_resolver_dump (vat_main_t * vam)
1983 vl_api_lisp_map_resolver_dump_t *mp;
1984 vl_api_control_ping_t *mp_ping;
1987 if (!vam->json_output)
1989 print (vam->ofp, "%=20s", "Map resolver");
1992 M (LISP_MAP_RESOLVER_DUMP, mp);
1996 /* Use a control ping for synchronization */
1997 LISP_PING (&lisp_test_main, mp_ping);
2000 /* Wait for a reply... */
2006 api_show_lisp_status (vat_main_t * vam)
2008 vl_api_show_lisp_status_t *mp;
2011 if (!vam->json_output)
2013 print (vam->ofp, "%-20s%-16s", "LISP status", "locator-set");
2016 M (SHOW_LISP_STATUS, mp);
2019 /* Wait for a reply... */
2025 api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
2027 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
2030 if (!vam->json_output)
2032 print (vam->ofp, "%=20s", "itr-rlocs:");
2035 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, mp);
2038 /* Wait for a reply... */
2043 #define vat_plugin_register vat_plugin_register_cp
2044 #include <lisp/lisp-cp/lisp.api_test.c>
2047 * fd.io coding-style-patch-verification: ON
2050 * eval: (c-set-style "gnu")