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 <vpp/api/vpe.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>
44 /* Macro to finish up custom dump fns */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
48 vl_print (handle, (char *)s); \
56 } __attribute__ ((__packed__)) lisp_nsh_api_t;
58 #define LISP_PING(_lm, mp_ping) \
59 if (!(_lm)->ping_id) \
60 (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \
61 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); \
62 mp_ping->_vl_msg_id = htons ((_lm)->ping_id); \
63 mp_ping->client_index = vam->my_client_index; \
64 fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id); \
65 vam->result_ready = 0; \
68 unformat_nsh_address (unformat_input_t * input, va_list * args)
70 lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
71 return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
75 format_nsh_address_vat (u8 * s, va_list * args)
77 nsh_t *a = va_arg (*args, nsh_t *);
78 return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
82 format_lisp_flat_eid (u8 * s, va_list * args)
84 vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *);
88 case EID_TYPE_API_PREFIX:
89 if (eid->address.prefix.address.af)
90 return format (s, "%U/%d", format_ip6_address,
91 eid->address.prefix.address.un.ip6,
92 eid->address.prefix.len);
93 return format (s, "%U/%d", format_ip4_address,
94 eid->address.prefix.address.un.ip4,
95 eid->address.prefix.len);
96 case EID_TYPE_API_MAC:
97 return format (s, "%U", format_ethernet_address, eid->address.mac);
98 case EID_TYPE_API_NSH:
99 return format (s, "%U", format_nsh_address_vat, eid->address.nsh);
105 format_lisp_eid_vat (u8 * s, va_list * args)
107 vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *);
108 vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *);
109 u8 is_src_dst = (u8) va_arg (*args, int);
112 s = format (s, "%U|", format_lisp_flat_eid, seid);
114 s = format (s, "%U", format_lisp_flat_eid, deid);
122 /** Used for parsing LISP eids */
123 typedef struct lisp_eid_vat_t_
130 /**< prefix length if IP */
134 } __clib_packed lisp_eid_vat_t;
138 unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
140 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
142 clib_memset (a, 0, sizeof (a[0]));
144 if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len))
146 a->type = 0; /* ip prefix type */
148 else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac))
150 a->type = 1; /* mac type */
152 else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh))
154 a->type = 2; /* NSH type */
155 a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi);
164 if (ip46_address_is_ip4 (&a->addr.ip))
165 return a->len > 32 ? 1 : 0;
167 return a->len > 128 ? 1 : 0;
174 lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid)
176 eid->type = vat_eid->type;
179 case EID_TYPE_API_PREFIX:
180 if (ip46_address_is_ip4 (&vat_eid->addr.ip))
182 clib_memcpy (&eid->address.prefix.address.un.ip4,
183 &vat_eid->addr.ip.ip4, 4);
184 eid->address.prefix.address.af = ADDRESS_IP4;
185 eid->address.prefix.len = vat_eid->len;
189 clib_memcpy (&eid->address.prefix.address.un.ip6,
190 &vat_eid->addr.ip.ip6, 16);
191 eid->address.prefix.address.af = ADDRESS_IP6;
192 eid->address.prefix.len = vat_eid->len;
195 case EID_TYPE_API_MAC:
196 clib_memcpy (&eid->address.mac, &vat_eid->addr.mac,
197 sizeof (eid->address.mac));
199 case EID_TYPE_API_NSH:
200 clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh,
201 sizeof (eid->address.nsh));
210 api_lisp_add_del_locator_set (vat_main_t * vam)
212 unformat_input_t *input = vam->input;
213 vl_api_lisp_add_del_locator_set_t *mp;
215 u8 *locator_set_name = NULL;
216 u8 locator_set_name_set = 0;
217 vl_api_local_locator_t locator, *locators = 0;
218 u32 sw_if_index, priority, weight;
222 /* Parse args required to build the message */
223 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
225 if (unformat (input, "del"))
229 else if (unformat (input, "locator-set %s", &locator_set_name))
231 locator_set_name_set = 1;
233 else if (unformat (input, "sw_if_index %u p %u w %u",
234 &sw_if_index, &priority, &weight))
236 locator.sw_if_index = htonl (sw_if_index);
237 locator.priority = priority;
238 locator.weight = weight;
239 vec_add1 (locators, locator);
243 (input, "iface %U p %u w %u", unformat_sw_if_index, vam,
244 &sw_if_index, &priority, &weight))
246 locator.sw_if_index = htonl (sw_if_index);
247 locator.priority = priority;
248 locator.weight = weight;
249 vec_add1 (locators, locator);
255 if (locator_set_name_set == 0)
257 errmsg ("missing locator-set name");
262 if (vec_len (locator_set_name) > 64)
264 errmsg ("locator-set name too long");
265 vec_free (locator_set_name);
269 vec_add1 (locator_set_name, 0);
271 data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
273 /* Construct the API message */
274 M2 (LISP_ADD_DEL_LOCATOR_SET, mp, data_len);
277 clib_memcpy (mp->locator_set_name, locator_set_name,
278 vec_len (locator_set_name));
279 vec_free (locator_set_name);
281 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
283 clib_memcpy (mp->locators, locators, data_len);
289 /* Wait for a reply... */
295 api_lisp_add_del_locator (vat_main_t * vam)
297 unformat_input_t *input = vam->input;
298 vl_api_lisp_add_del_locator_t *mp;
299 u32 tmp_if_index = ~0;
300 u32 sw_if_index = ~0;
301 u8 sw_if_index_set = 0;
302 u8 sw_if_index_if_name_set = 0;
308 u8 *locator_set_name = NULL;
309 u8 locator_set_name_set = 0;
312 /* Parse args required to build the message */
313 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
315 if (unformat (input, "del"))
319 else if (unformat (input, "locator-set %s", &locator_set_name))
321 locator_set_name_set = 1;
323 else if (unformat (input, "iface %U", unformat_sw_if_index, vam,
326 sw_if_index_if_name_set = 1;
327 sw_if_index = tmp_if_index;
329 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
332 sw_if_index = tmp_if_index;
334 else if (unformat (input, "p %d", &priority))
338 else if (unformat (input, "w %d", &weight))
346 if (locator_set_name_set == 0)
348 errmsg ("missing locator-set name");
352 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
354 errmsg ("missing sw_if_index");
355 vec_free (locator_set_name);
359 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
361 errmsg ("cannot use both params interface name and sw_if_index");
362 vec_free (locator_set_name);
366 if (priority_set == 0)
368 errmsg ("missing locator-set priority");
369 vec_free (locator_set_name);
375 errmsg ("missing locator-set weight");
376 vec_free (locator_set_name);
380 if (vec_len (locator_set_name) > 64)
382 errmsg ("locator-set name too long");
383 vec_free (locator_set_name);
386 vec_add1 (locator_set_name, 0);
388 /* Construct the API message */
389 M (LISP_ADD_DEL_LOCATOR, mp);
392 mp->sw_if_index = ntohl (sw_if_index);
393 mp->priority = priority;
395 clib_memcpy (mp->locator_set_name, locator_set_name,
396 vec_len (locator_set_name));
397 vec_free (locator_set_name);
402 /* Wait for a reply... */
408 api_lisp_add_del_local_eid (vat_main_t * vam)
410 unformat_input_t *input = vam->input;
411 vl_api_lisp_add_del_local_eid_t *mp;
414 lisp_eid_vat_t _eid, *eid = &_eid;
415 u8 *locator_set_name = 0;
416 u8 locator_set_name_set = 0;
422 /* Parse args required to build the message */
423 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
425 if (unformat (input, "del"))
429 else if (unformat (input, "vni %d", &vni))
433 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
437 else if (unformat (input, "locator-set %s", &locator_set_name))
439 locator_set_name_set = 1;
441 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
443 else if (unformat (input, "secret-key %_%v%_", &key))
449 if (locator_set_name_set == 0)
451 errmsg ("missing locator-set name");
457 errmsg ("EID address not set!");
458 vec_free (locator_set_name);
462 if (key && (0 == key_id))
464 errmsg ("invalid key_id!");
468 if (vec_len (key) > 64)
470 errmsg ("key too long");
475 if (vec_len (locator_set_name) > 64)
477 errmsg ("locator-set name too long");
478 vec_free (locator_set_name);
481 vec_add1 (locator_set_name, 0);
483 /* Construct the API message */
484 M (LISP_ADD_DEL_LOCAL_EID, mp);
487 lisp_eid_put_vat (&mp->eid, eid);
488 mp->vni = clib_host_to_net_u32 (vni);
490 clib_memcpy (mp->locator_set_name, locator_set_name,
491 vec_len (locator_set_name));
492 clib_memcpy (mp->key.key, key, vec_len (key));
494 vec_free (locator_set_name);
500 /* Wait for a reply... */
506 api_lisp_add_del_map_server (vat_main_t * vam)
508 unformat_input_t *input = vam->input;
509 vl_api_lisp_add_del_map_server_t *mp;
517 /* Parse args required to build the message */
518 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
520 if (unformat (input, "del"))
524 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
528 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
536 if (ipv4_set && ipv6_set)
538 errmsg ("both eid v4 and v6 addresses set");
542 if (!ipv4_set && !ipv6_set)
544 errmsg ("eid addresses not set");
548 /* Construct the API message */
549 M (LISP_ADD_DEL_MAP_SERVER, mp);
554 mp->ip_address.af = 1;
555 clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
559 mp->ip_address.af = 0;
560 clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4));
566 /* Wait for a reply... */
572 api_lisp_add_del_map_resolver (vat_main_t * vam)
574 unformat_input_t *input = vam->input;
575 vl_api_lisp_add_del_map_resolver_t *mp;
583 /* Parse args required to build the message */
584 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
586 if (unformat (input, "del"))
590 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
594 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
602 if (ipv4_set && ipv6_set)
604 errmsg ("both eid v4 and v6 addresses set");
608 if (!ipv4_set && !ipv6_set)
610 errmsg ("eid addresses not set");
614 /* Construct the API message */
615 M (LISP_ADD_DEL_MAP_RESOLVER, mp);
620 mp->ip_address.af = 1;
621 clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6));
625 mp->ip_address.af = 0;
626 clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4));
632 /* Wait for a reply... */
638 api_lisp_enable_disable (vat_main_t * vam)
640 unformat_input_t *input = vam->input;
641 vl_api_lisp_enable_disable_t *mp;
646 /* Parse args required to build the message */
647 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
649 if (unformat (input, "enable"))
654 else if (unformat (input, "disable"))
664 errmsg ("Value not set");
668 /* Construct the API message */
669 M (LISP_ENABLE_DISABLE, mp);
671 mp->is_enable = is_enable;
676 /* Wait for a reply... */
682 * Enable/disable LISP proxy ITR.
684 * @param vam vpp API test context
685 * @return return code
688 api_lisp_pitr_set_locator_set (vat_main_t * vam)
691 unformat_input_t *input = vam->input;
692 vl_api_lisp_pitr_set_locator_set_t *mp;
697 /* Parse args required to build the message */
698 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
700 if (unformat (input, "del"))
702 else if (unformat (input, "locator-set %s", &ls_name))
706 errmsg ("parse error '%U'", format_unformat_error, input);
713 errmsg ("locator-set name not set!");
717 M (LISP_PITR_SET_LOCATOR_SET, mp);
720 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
732 api_lisp_use_petr (vat_main_t * vam)
734 unformat_input_t *input = vam->input;
735 vl_api_lisp_use_petr_t *mp;
740 clib_memset (&ip, 0, sizeof (ip));
742 /* Parse args required to build the message */
743 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
745 if (unformat (input, "disable"))
748 if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
751 ip_addr_version (&ip) = AF_IP4;
754 if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
757 ip_addr_version (&ip) = AF_IP6;
761 errmsg ("parse error '%U'", format_unformat_error, input);
766 M (LISP_USE_PETR, mp);
771 mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1;
772 if (mp->ip_address.af)
773 clib_memcpy (mp->ip_address.un.ip6, &ip, 16);
775 clib_memcpy (mp->ip_address.un.ip4, &ip, 4);
787 vl_api_show_lisp_use_petr_reply_t_handler
788 (vl_api_show_lisp_use_petr_reply_t * mp)
790 vat_main_t *vam = &vat_main;
791 i32 retval = ntohl (mp->retval);
795 print (vam->ofp, "%s\n", mp->is_petr_enable ? "enabled" : "disabled");
796 if (mp->is_petr_enable)
798 print (vam->ofp, "Proxy-ETR address; %U",
799 mp->ip_address.af ? format_ip6_address : format_ip4_address,
804 vam->retval = retval;
805 vam->result_ready = 1;
809 api_show_lisp_use_petr (vat_main_t * vam)
811 vl_api_show_lisp_use_petr_t *mp;
814 if (!vam->json_output)
816 print (vam->ofp, "%=20s", "Proxy-ETR status:");
819 M (SHOW_LISP_USE_PETR, mp);
823 /* Wait for a reply... */
829 vl_api_show_lisp_rloc_probe_state_reply_t_handler
830 (vl_api_show_lisp_rloc_probe_state_reply_t * mp)
832 vat_main_t *vam = &vat_main;
833 int retval = clib_net_to_host_u32 (mp->retval);
838 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
840 vam->retval = retval;
841 vam->result_ready = 1;
845 api_show_lisp_map_register_state (vat_main_t * vam)
847 vl_api_show_lisp_map_register_state_t *mp;
850 M (SHOW_LISP_MAP_REGISTER_STATE, mp);
861 api_show_lisp_rloc_probe_state (vat_main_t * vam)
863 vl_api_show_lisp_rloc_probe_state_t *mp;
866 M (SHOW_LISP_RLOC_PROBE_STATE, mp);
877 api_lisp_rloc_probe_enable_disable (vat_main_t * vam)
879 unformat_input_t *input = vam->input;
880 vl_api_lisp_rloc_probe_enable_disable_t *mp;
885 /* Parse args required to build the message */
886 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
888 if (unformat (input, "enable"))
893 else if (unformat (input, "disable"))
901 errmsg ("Value not set");
905 /* Construct the API message */
906 M (LISP_RLOC_PROBE_ENABLE_DISABLE, mp);
908 mp->is_enable = is_enable;
913 /* Wait for a reply... */
919 api_lisp_map_register_enable_disable (vat_main_t * vam)
921 unformat_input_t *input = vam->input;
922 vl_api_lisp_map_register_enable_disable_t *mp;
927 /* Parse args required to build the message */
928 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
930 if (unformat (input, "enable"))
935 else if (unformat (input, "disable"))
943 errmsg ("Value not set");
947 /* Construct the API message */
948 M (LISP_MAP_REGISTER_ENABLE_DISABLE, mp);
950 mp->is_enable = is_enable;
955 /* Wait for a reply... */
961 vl_api_show_lisp_map_request_mode_reply_t_handler
962 (vl_api_show_lisp_map_request_mode_reply_t * mp)
964 vat_main_t *vam = &vat_main;
965 i32 retval = ntohl (mp->retval);
969 print (vam->ofp, "map_request_mode: %s",
970 mp->is_src_dst ? "src-dst" : "dst-only");
973 vam->retval = retval;
974 vam->result_ready = 1;
978 vl_api_show_lisp_map_register_state_reply_t_handler
979 (vl_api_show_lisp_map_register_state_reply_t * mp)
981 vat_main_t *vam = &vat_main;
982 int retval = clib_net_to_host_u32 (mp->retval);
984 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
986 vam->retval = retval;
987 vam->result_ready = 1;
991 vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp)
993 vat_main_t *vam = &vat_main;
998 s = format (s, "%=16d%=16d%=16d",
999 ntohl (mp->sw_if_index), mp->priority, mp->weight);
1003 s = format (s, "%=16U%=16d%=16d",
1004 format_ip46_address,
1005 mp->ip_address, mp->priority, mp->weight);
1008 print (vam->ofp, "%v", s);
1013 vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t *
1016 vat_main_t *vam = &vat_main;
1019 ls_name = format (0, "%s", mp->ls_name);
1021 print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
1026 static void vl_api_lisp_add_del_locator_set_reply_t_handler
1027 (vl_api_lisp_add_del_locator_set_reply_t * mp)
1029 vat_main_t *vam = &vat_main;
1030 i32 retval = ntohl (mp->retval);
1031 if (vam->async_mode)
1033 vam->async_errors += (retval < 0);
1037 vam->retval = retval;
1038 vam->result_ready = 1;
1044 vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp)
1046 vat_main_t *vam = &vat_main;
1047 u8 *s = 0, *eid = 0;
1049 if (~0 == mp->locator_set_index)
1050 s = format (0, "action: %d", mp->action);
1052 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
1054 eid = format (0, "%U", format_lisp_eid_vat,
1055 &mp->deid, &mp->seid, mp->is_src_dst);
1058 print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
1059 clib_net_to_host_u32 (mp->vni),
1061 mp->is_local ? "local" : "remote",
1062 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
1063 clib_net_to_host_u16 (mp->key.id), mp->key.key);
1070 vl_api_lisp_eid_table_map_details_t_handler
1071 (vl_api_lisp_eid_table_map_details_t * mp)
1073 vat_main_t *vam = &vat_main;
1075 u8 *line = format (0, "%=10d%=10d",
1076 clib_net_to_host_u32 (mp->vni),
1077 clib_net_to_host_u32 (mp->dp_table));
1078 print (vam->ofp, "%v", line);
1083 vl_api_lisp_eid_table_vni_details_t_handler
1084 (vl_api_lisp_eid_table_vni_details_t * mp)
1086 vat_main_t *vam = &vat_main;
1088 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
1089 print (vam->ofp, "%v", line);
1094 vl_api_lisp_adjacencies_get_reply_t_handler
1095 (vl_api_lisp_adjacencies_get_reply_t * mp)
1097 vat_main_t *vam = &vat_main;
1099 int retval = clib_net_to_host_u32 (mp->retval);
1100 vl_api_lisp_adjacency_t *a;
1105 n = clib_net_to_host_u32 (mp->count);
1107 for (i = 0; i < n; i++)
1109 a = &mp->adjacencies[i];
1110 print (vam->ofp, "%U %40U",
1111 format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid);
1115 vam->retval = retval;
1116 vam->result_ready = 1;
1120 vl_api_lisp_map_server_details_t_handler (vl_api_lisp_map_server_details_t *
1123 vat_main_t *vam = &vat_main;
1125 print (vam->ofp, "%=20U",
1126 mp->ip_address.af ? format_ip6_address : format_ip4_address,
1131 vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
1134 vat_main_t *vam = &vat_main;
1136 print (vam->ofp, "%=20U",
1137 mp->ip_address.af ? format_ip6_address : format_ip4_address,
1142 vl_api_show_lisp_status_reply_t_handler (vl_api_show_lisp_status_reply_t * mp)
1144 vat_main_t *vam = &vat_main;
1145 i32 retval = ntohl (mp->retval);
1149 print (vam->ofp, "feature: %s\ngpe: %s",
1150 mp->is_lisp_enabled ? "enabled" : "disabled",
1151 mp->is_gpe_enabled ? "enabled" : "disabled");
1154 vam->retval = retval;
1155 vam->result_ready = 1;
1159 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler
1160 (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
1162 vat_main_t *vam = &vat_main;
1163 i32 retval = ntohl (mp->retval);
1167 print (vam->ofp, "%=20s", mp->locator_set_name);
1170 vam->retval = retval;
1171 vam->result_ready = 1;
1175 vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
1177 vat_main_t *vam = &vat_main;
1178 i32 retval = ntohl (mp->retval);
1182 print (vam->ofp, "%-20s%-16s",
1183 mp->is_enabled ? "enabled" : "disabled",
1184 mp->is_enabled ? (char *) mp->locator_set_name : "");
1187 vam->retval = retval;
1188 vam->result_ready = 1;
1192 unformat_hmac_key_id (unformat_input_t * input, va_list * args)
1194 u32 *key_id = va_arg (*args, u32 *);
1197 if (unformat (input, "%s", &s))
1199 if (!strcmp ((char *) s, "sha1"))
1200 key_id[0] = HMAC_SHA_1_96;
1201 else if (!strcmp ((char *) s, "sha256"))
1202 key_id[0] = HMAC_SHA_256_128;
1205 clib_warning ("invalid key_id: '%s'", s);
1206 key_id[0] = HMAC_NO_KEY;
1219 api_show_lisp_map_request_mode (vat_main_t * vam)
1221 vl_api_show_lisp_map_request_mode_t *mp;
1224 M (SHOW_LISP_MAP_REQUEST_MODE, mp);
1229 /* wait for reply */
1235 api_lisp_map_request_mode (vat_main_t * vam)
1237 unformat_input_t *input = vam->input;
1238 vl_api_lisp_map_request_mode_t *mp;
1242 /* Parse args required to build the message */
1243 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1245 if (unformat (input, "dst-only"))
1247 else if (unformat (input, "src-dst"))
1251 errmsg ("parse error '%U'", format_unformat_error, input);
1256 M (LISP_MAP_REQUEST_MODE, mp);
1258 mp->is_src_dst = mode == 1;
1263 /* wait for reply */
1269 api_show_lisp_pitr (vat_main_t * vam)
1271 vl_api_show_lisp_pitr_t *mp;
1274 if (!vam->json_output)
1276 print (vam->ofp, "%=20s", "lisp status:");
1279 M (SHOW_LISP_PITR, mp);
1283 /* Wait for a reply... */
1289 * Add/delete mapping between vni and vrf
1292 api_lisp_eid_table_add_del_map (vat_main_t * vam)
1294 unformat_input_t *input = vam->input;
1295 vl_api_lisp_eid_table_add_del_map_t *mp;
1296 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
1297 u32 vni, vrf, bd_index;
1300 /* Parse args required to build the message */
1301 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1303 if (unformat (input, "del"))
1305 else if (unformat (input, "vrf %d", &vrf))
1307 else if (unformat (input, "bd_index %d", &bd_index))
1309 else if (unformat (input, "vni %d", &vni))
1315 if (!vni_set || (!vrf_set && !bd_index_set))
1317 errmsg ("missing arguments!");
1321 if (vrf_set && bd_index_set)
1323 errmsg ("error: both vrf and bd entered!");
1327 M (LISP_EID_TABLE_ADD_DEL_MAP, mp);
1329 mp->is_add = is_add;
1330 mp->vni = htonl (vni);
1331 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
1332 mp->is_l2 = bd_index_set;
1337 /* wait for reply */
1343 * Add/del remote mapping to/from LISP control plane
1345 * @param vam vpp API test context
1346 * @return return code
1349 api_lisp_add_del_remote_mapping (vat_main_t * vam)
1351 unformat_input_t *input = vam->input;
1352 vl_api_lisp_add_del_remote_mapping_t *mp;
1354 lisp_eid_vat_t _eid, *eid = &_eid;
1355 lisp_eid_vat_t _seid, *seid = &_seid;
1356 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
1357 u32 action = ~0, p, w, data_len;
1358 ip4_address_t rloc4;
1359 ip6_address_t rloc6;
1360 vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
1363 clib_memset (&rloc, 0, sizeof (rloc));
1365 /* Parse args required to build the message */
1366 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1368 if (unformat (input, "del-all"))
1372 else if (unformat (input, "del"))
1376 else if (unformat (input, "add"))
1380 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
1384 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
1388 else if (unformat (input, "vni %d", &vni))
1392 else if (unformat (input, "p %d w %d", &p, &w))
1396 errmsg ("No RLOC configured for setting priority/weight!");
1399 curr_rloc->priority = p;
1400 curr_rloc->weight = w;
1402 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
1404 rloc.ip_address.af = 0;
1405 clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6));
1406 vec_add1 (rlocs, rloc);
1407 curr_rloc = &rlocs[vec_len (rlocs) - 1];
1409 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
1411 rloc.ip_address.af = 1;
1412 clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4));
1413 vec_add1 (rlocs, rloc);
1414 curr_rloc = &rlocs[vec_len (rlocs) - 1];
1416 else if (unformat (input, "action %U",
1417 unformat_negative_mapping_action, &action))
1423 clib_warning ("parse error '%U'", format_unformat_error, input);
1430 errmsg ("missing params!");
1434 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
1436 errmsg ("no action set for negative map-reply!");
1440 data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
1442 M2 (LISP_ADD_DEL_REMOTE_MAPPING, mp, data_len);
1443 mp->is_add = is_add;
1444 mp->vni = htonl (vni);
1445 mp->action = (u8) action;
1446 mp->is_src_dst = seid_set;
1447 mp->del_all = del_all;
1448 lisp_eid_put_vat (&mp->deid, eid);
1449 lisp_eid_put_vat (&mp->seid, seid);
1451 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
1452 clib_memcpy (mp->rlocs, rlocs, data_len);
1458 /* Wait for a reply... */
1464 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
1465 * forwarding entries in data-plane accordingly.
1467 * @param vam vpp API test context
1468 * @return return code
1471 api_lisp_add_del_adjacency (vat_main_t * vam)
1473 unformat_input_t *input = vam->input;
1474 vl_api_lisp_add_del_adjacency_t *mp;
1478 lisp_eid_vat_t leid, reid;
1480 leid.type = reid.type = (u8) ~ 0;
1482 /* Parse args required to build the message */
1483 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1485 if (unformat (input, "del"))
1489 else if (unformat (input, "add"))
1493 else if (unformat (input, "reid %U/%d", unformat_ip46_address,
1494 &reid.addr.ip, &reid.len))
1496 reid.type = 0; /* ipv4 */
1498 else if (unformat (input, "reid %U", unformat_ethernet_address,
1501 reid.type = 1; /* mac */
1503 else if (unformat (input, "leid %U/%d", unformat_ip46_address,
1504 &leid.addr.ip, &leid.len))
1506 leid.type = 0; /* ipv4 */
1508 else if (unformat (input, "leid %U", unformat_ethernet_address,
1511 leid.type = 1; /* mac */
1513 else if (unformat (input, "vni %d", &vni))
1519 errmsg ("parse error '%U'", format_unformat_error, input);
1524 if ((u8) ~ 0 == reid.type)
1526 errmsg ("missing params!");
1530 if (leid.type != reid.type)
1532 errmsg ("remote and local EIDs are of different types!");
1536 M (LISP_ADD_DEL_ADJACENCY, mp);
1537 mp->is_add = is_add;
1538 mp->vni = htonl (vni);
1539 lisp_eid_put_vat (&mp->leid, &leid);
1540 lisp_eid_put_vat (&mp->reid, &reid);
1545 /* Wait for a reply... */
1551 * Add/del map request itr rlocs from LISP control plane and updates
1553 * @param vam vpp API test context
1554 * @return return code
1557 api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam)
1559 unformat_input_t *input = vam->input;
1560 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
1561 u8 *locator_set_name = 0;
1562 u8 locator_set_name_set = 0;
1566 /* Parse args required to build the message */
1567 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1569 if (unformat (input, "del"))
1573 else if (unformat (input, "%_%v%_", &locator_set_name))
1575 locator_set_name_set = 1;
1579 clib_warning ("parse error '%U'", format_unformat_error, input);
1584 if (is_add && !locator_set_name_set)
1586 errmsg ("itr-rloc is not set!");
1590 if (is_add && vec_len (locator_set_name) > 64)
1592 errmsg ("itr-rloc locator-set name too long");
1593 vec_free (locator_set_name);
1597 M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
1598 mp->is_add = is_add;
1601 clib_memcpy (mp->locator_set_name, locator_set_name,
1602 vec_len (locator_set_name));
1606 clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
1608 vec_free (locator_set_name);
1613 /* Wait for a reply... */
1619 api_lisp_locator_dump (vat_main_t * vam)
1621 unformat_input_t *input = vam->input;
1622 vl_api_lisp_locator_dump_t *mp;
1623 vl_api_control_ping_t *mp_ping;
1624 u8 is_index_set = 0, is_name_set = 0;
1629 /* Parse args required to build the message */
1630 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1632 if (unformat (input, "ls_name %_%v%_", &ls_name))
1636 else if (unformat (input, "ls_index %d", &ls_index))
1642 errmsg ("parse error '%U'", format_unformat_error, input);
1647 if (!is_index_set && !is_name_set)
1649 errmsg ("error: expected lisp of index or name!");
1653 if (is_index_set && is_name_set)
1655 errmsg ("error: only lisp param expected!");
1659 if (vec_len (ls_name) > 62)
1661 errmsg ("error: locator set name too long!");
1665 if (!vam->json_output)
1667 print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
1670 M (LISP_LOCATOR_DUMP, mp);
1671 mp->is_index_set = is_index_set;
1674 mp->ls_index = clib_host_to_net_u32 (ls_index);
1677 vec_add1 (ls_name, 0);
1678 strncpy ((char *) mp->ls_name, (char *) ls_name,
1679 sizeof (mp->ls_name) - 1);
1685 /* Use a control ping for synchronization */
1686 if (!lisp_test_main.ping_id)
1687 lisp_test_main.ping_id =
1688 vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
1689 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
1690 mp_ping->_vl_msg_id = htons (lisp_test_main.ping_id);
1691 mp_ping->client_index = vam->my_client_index;
1693 fformat (vam->ofp, "Sending ping id=%d\n", lisp_test_main.ping_id);
1695 vam->result_ready = 0;
1698 /* Wait for a reply... */
1704 api_lisp_locator_set_dump (vat_main_t * vam)
1706 vl_api_lisp_locator_set_dump_t *mp;
1707 vl_api_control_ping_t *mp_ping;
1708 unformat_input_t *input = vam->input;
1712 /* Parse args required to build the message */
1713 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1715 if (unformat (input, "local"))
1719 else if (unformat (input, "remote"))
1725 errmsg ("parse error '%U'", format_unformat_error, input);
1730 if (!vam->json_output)
1732 print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
1735 M (LISP_LOCATOR_SET_DUMP, mp);
1737 mp->filter = filter;
1742 /* Use a control ping for synchronization */
1743 LISP_PING (&lisp_test_main, mp_ping);
1746 /* Wait for a reply... */
1752 api_lisp_eid_table_map_dump (vat_main_t * vam)
1756 unformat_input_t *input = vam->input;
1757 vl_api_lisp_eid_table_map_dump_t *mp;
1758 vl_api_control_ping_t *mp_ping;
1761 /* Parse args required to build the message */
1762 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1764 if (unformat (input, "l2"))
1769 else if (unformat (input, "l3"))
1776 errmsg ("parse error '%U'", format_unformat_error, input);
1783 errmsg ("expected lisp of 'l2' or 'l3' parameter!");
1787 if (!vam->json_output)
1789 print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
1792 M (LISP_EID_TABLE_MAP_DUMP, mp);
1798 /* Use a control ping for synchronization */
1799 LISP_PING (&lisp_test_main, mp_ping);
1802 /* Wait for a reply... */
1808 api_lisp_eid_table_vni_dump (vat_main_t * vam)
1810 vl_api_lisp_eid_table_vni_dump_t *mp;
1811 vl_api_control_ping_t *mp_ping;
1814 if (!vam->json_output)
1816 print (vam->ofp, "VNI");
1819 M (LISP_EID_TABLE_VNI_DUMP, mp);
1824 /* Use a control ping for synchronization */
1825 LISP_PING (&lisp_test_main, mp_ping);
1828 /* Wait for a reply... */
1834 api_lisp_eid_table_dump (vat_main_t * vam)
1836 unformat_input_t *i = vam->input;
1837 vl_api_lisp_eid_table_dump_t *mp;
1838 vl_api_control_ping_t *mp_ping;
1845 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1848 (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len))
1854 if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac))
1859 else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh))
1864 else if (unformat (i, "vni %d", &t))
1868 else if (unformat (i, "local"))
1872 else if (unformat (i, "remote"))
1878 errmsg ("parse error '%U'", format_unformat_error, i);
1883 if (!vam->json_output)
1885 print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
1886 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
1889 M (LISP_EID_TABLE_DUMP, mp);
1891 mp->filter = filter;
1895 mp->vni = htonl (vni);
1896 lisp_eid_put_vat (&mp->eid, &eid);
1902 /* Use a control ping for synchronization */
1903 LISP_PING (&lisp_test_main, mp_ping);
1906 /* Wait for a reply... */
1913 api_lisp_adjacencies_get (vat_main_t * vam)
1915 unformat_input_t *i = vam->input;
1916 vl_api_lisp_adjacencies_get_t *mp;
1921 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1923 if (unformat (i, "vni %d", &vni))
1929 errmsg ("parse error '%U'", format_unformat_error, i);
1936 errmsg ("vni not set!");
1940 if (!vam->json_output)
1942 print (vam->ofp, "%s %40s", "leid", "reid");
1945 M (LISP_ADJACENCIES_GET, mp);
1946 mp->vni = clib_host_to_net_u32 (vni);
1951 /* Wait for a reply... */
1957 api_lisp_map_server_dump (vat_main_t * vam)
1959 vl_api_lisp_map_server_dump_t *mp;
1960 vl_api_control_ping_t *mp_ping;
1963 if (!vam->json_output)
1965 print (vam->ofp, "%=20s", "Map server");
1968 M (LISP_MAP_SERVER_DUMP, mp);
1972 /* Use a control ping for synchronization */
1973 LISP_PING (&lisp_test_main, mp_ping);
1976 /* Wait for a reply... */
1982 api_lisp_map_resolver_dump (vat_main_t * vam)
1984 vl_api_lisp_map_resolver_dump_t *mp;
1985 vl_api_control_ping_t *mp_ping;
1988 if (!vam->json_output)
1990 print (vam->ofp, "%=20s", "Map resolver");
1993 M (LISP_MAP_RESOLVER_DUMP, mp);
1997 /* Use a control ping for synchronization */
1998 LISP_PING (&lisp_test_main, mp_ping);
2001 /* Wait for a reply... */
2007 api_show_lisp_status (vat_main_t * vam)
2009 vl_api_show_lisp_status_t *mp;
2012 if (!vam->json_output)
2014 print (vam->ofp, "%-20s%-16s", "LISP status", "locator-set");
2017 M (SHOW_LISP_STATUS, mp);
2020 /* Wait for a reply... */
2026 api_lisp_get_map_request_itr_rlocs (vat_main_t * vam)
2028 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
2031 if (!vam->json_output)
2033 print (vam->ofp, "%=20s", "itr-rlocs:");
2036 M (LISP_GET_MAP_REQUEST_ITR_RLOCS, mp);
2039 /* Wait for a reply... */
2044 #define vat_plugin_register vat_plugin_register_cp
2045 #include <lisp/lisp-cp/lisp.api_test.c>
2048 * fd.io coding-style-patch-verification: ON
2051 * eval: (c-set-style "gnu")