2 *------------------------------------------------------------------
3 * one_api.c - Overlay Network Engine API
5 * Copyright (c) 2016-2017 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/lisp-cp/control.h>
26 #include <vnet/lisp-gpe/lisp_gpe.h>
28 #include <vnet/vnet_msg_enum.h>
30 #define vl_api_one_remote_locator_t_endian vl_noop_handler
31 #define vl_api_one_remote_locator_t_print vl_noop_handler
32 #define vl_api_one_local_locator_t_endian vl_noop_handler
33 #define vl_api_one_local_locator_t_print vl_noop_handler
35 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
36 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
37 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
38 #define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
40 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
41 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
42 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
43 #define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
45 #define vl_api_one_l2_arp_entry_t_endian vl_noop_handler
46 #define vl_api_one_l2_arp_entry_t_print vl_noop_handler
47 #define vl_api_one_add_del_l2_arp_entry vl_noop_handler
48 #define vl_api_one_l2_arp_bd_get vl_noop_handler
50 #define vl_api_one_ndp_entry_t_endian vl_noop_handler
51 #define vl_api_one_ndp_entry_t_print vl_noop_handler
52 #define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
53 #define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
55 #define vl_typedefs /* define message structures */
56 #include <vnet/vnet_all_api_h.h>
59 #define vl_endianfun /* define message structures */
60 #include <vnet/vnet_all_api_h.h>
63 /* instantiate all the print functions we know about */
64 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
66 #include <vnet/vnet_all_api_h.h>
69 #include <vlibapi/api_helper_macros.h>
71 #define REPLY_DETAILS(t, body) \
73 unix_shared_memory_queue_t * q; \
74 rv = vl_msg_api_pd_handler (mp, rv); \
75 q = vl_api_client_index_to_input_queue (mp->client_index); \
79 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
80 rmp->_vl_msg_id = ntohs((t)); \
81 rmp->context = mp->context; \
82 do {body;} while (0); \
83 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
86 #define foreach_vpe_api_msg \
87 _(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
88 _(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
89 _(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
90 _(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
91 _(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
92 _(ONE_ENABLE_DISABLE, one_enable_disable) \
93 _(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
94 _(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
95 _(ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \
96 one_map_register_fallback_threshold) \
97 _(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
98 _(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
99 _(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
100 _(ONE_NSH_SET_LOCATOR_SET, one_nsh_set_locator_set) \
101 _(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
102 _(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
103 _(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
104 _(ONE_LOCATOR_DUMP, one_locator_dump) \
105 _(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
106 _(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
107 _(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
108 _(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
109 _(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
110 _(ONE_ADJACENCIES_GET, one_adjacencies_get) \
111 _(ONE_MAP_REGISTER_SET_TTL, one_map_register_set_ttl) \
112 _(SHOW_ONE_NSH_MAPPING, show_one_nsh_mapping) \
113 _(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
114 _(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
115 _(SHOW_ONE_MAP_REGISTER_TTL, show_one_map_register_ttl) \
116 _(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \
117 show_one_map_register_fallback_threshold) \
118 _(SHOW_ONE_STATUS, show_one_status) \
119 _(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
120 one_add_del_map_request_itr_rlocs) \
121 _(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
122 _(SHOW_ONE_PITR, show_one_pitr) \
123 _(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
124 _(ONE_USE_PETR, one_use_petr) \
125 _(SHOW_ONE_USE_PETR, show_one_use_petr) \
126 _(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
127 _(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
128 _(ONE_STATS_DUMP, one_stats_dump) \
129 _(ONE_STATS_FLUSH, one_stats_flush) \
130 _(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get) \
131 _(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get) \
132 _(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry) \
133 _(ONE_ADD_DEL_NDP_ENTRY, one_add_del_ndp_entry) \
134 _(ONE_NDP_BD_GET, one_ndp_bd_get) \
135 _(ONE_NDP_ENTRIES_GET, one_ndp_entries_get) \
136 _(ONE_SET_TRANSPORT_PROTOCOL, one_set_transport_protocol) \
137 _(ONE_GET_TRANSPORT_PROTOCOL, one_get_transport_protocol) \
138 _(ONE_ENABLE_DISABLE_XTR_MODE, one_enable_disable_xtr_mode) \
139 _(ONE_SHOW_XTR_MODE, one_show_xtr_mode) \
140 _(ONE_ENABLE_DISABLE_PITR_MODE, one_enable_disable_pitr_mode) \
141 _(ONE_SHOW_PITR_MODE, one_show_pitr_mode) \
142 _(ONE_ENABLE_DISABLE_PETR_MODE, one_enable_disable_petr_mode) \
143 _(ONE_SHOW_PETR_MODE, one_show_petr_mode) \
147 unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
150 locator_t *locs = 0, loc;
151 vl_api_one_remote_locator_t *r;
153 for (i = 0; i < rloc_num; i++)
155 /* remote locators */
157 memset (&loc, 0, sizeof (loc));
158 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
160 loc.priority = r->priority;
161 loc.weight = r->weight;
163 vec_add1 (locs, loc);
169 vl_api_one_map_register_set_ttl_t_handler (vl_api_one_map_register_set_ttl_t *
172 vl_api_one_map_register_set_ttl_reply_t *rmp;
175 mp->ttl = clib_net_to_host_u32 (mp->ttl);
176 rv = vnet_lisp_map_register_set_ttl (mp->ttl);
178 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_SET_TTL_REPLY);
182 vl_api_show_one_map_register_ttl_t_handler
183 (vl_api_show_one_map_register_ttl_t * mp)
185 vl_api_show_one_map_register_ttl_reply_t *rmp;
188 u32 ttl = vnet_lisp_map_register_get_ttl ();
190 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_TTL_REPLY,
192 rmp->ttl = clib_host_to_net_u32 (ttl);
198 vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
201 vl_api_one_add_del_locator_set_reply_t *rmp;
203 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
205 vl_api_one_local_locator_t *ls_loc;
206 u32 ls_index = ~0, locator_num;
207 u8 *locator_name = NULL;
210 memset (a, 0, sizeof (a[0]));
212 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
213 locator_name = format (0, "%s", mp->locator_set_name);
214 vec_terminate_c_string (locator_name);
216 a->name = locator_name;
217 a->is_add = mp->is_add;
219 locator_num = clib_net_to_host_u32 (mp->locator_num);
221 memset (&locator, 0, sizeof (locator));
222 for (i = 0; i < locator_num; i++)
224 ls_loc = &mp->locators[i];
225 VALIDATE_SW_IF_INDEX (ls_loc);
227 locator.sw_if_index = htonl (ls_loc->sw_if_index);
228 locator.priority = ls_loc->priority;
229 locator.weight = ls_loc->weight;
231 vec_add1 (a->locators, locator);
234 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
236 BAD_SW_IF_INDEX_LABEL;
238 vec_free (locator_name);
239 vec_free (a->locators);
242 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
244 rmp->ls_index = clib_host_to_net_u32 (ls_index);
250 vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
252 vl_api_one_add_del_locator_reply_t *rmp;
254 locator_t locator, *locators = NULL;
255 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
257 u8 *locator_name = NULL;
259 memset (&locator, 0, sizeof (locator));
260 memset (a, 0, sizeof (a[0]));
262 locator.sw_if_index = ntohl (mp->sw_if_index);
263 locator.priority = mp->priority;
264 locator.weight = mp->weight;
266 vec_add1 (locators, locator);
268 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
269 locator_name = format (0, "%s", mp->locator_set_name);
270 vec_terminate_c_string (locator_name);
272 a->name = locator_name;
273 a->locators = locators;
274 a->is_add = mp->is_add;
277 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
280 vec_free (locator_name);
282 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
289 } __attribute__ ((__packed__)) lisp_nsh_api_t;
292 unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
300 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
301 gid_address_ip_set (dst, src, IP4);
302 gid_address_ippref_len (dst) = len;
303 ip_prefix_normalize (&gid_address_ippref (dst));
306 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
307 gid_address_ip_set (dst, src, IP6);
308 gid_address_ippref_len (dst) = len;
309 ip_prefix_normalize (&gid_address_ippref (dst));
312 gid_address_type (dst) = GID_ADDR_MAC;
313 clib_memcpy (&gid_address_mac (dst), src, 6);
316 gid_address_type (dst) = GID_ADDR_NSH;
318 gid_address_nsh_spi (dst) = clib_net_to_host_u32 (nsh->spi);
319 gid_address_nsh_si (dst) = nsh->si;
323 return VNET_API_ERROR_INVALID_VALUE;
326 gid_address_vni (dst) = vni;
332 vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
334 vl_api_one_add_del_local_eid_reply_t *rmp;
335 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
337 gid_address_t _eid, *eid = &_eid;
339 u32 locator_set_index = ~0, map_index = ~0;
340 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
341 u8 *name = NULL, *key = NULL;
342 memset (a, 0, sizeof (a[0]));
343 memset (eid, 0, sizeof (eid[0]));
345 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
346 mp->eid_type, mp->eid, mp->prefix_len);
350 if (gid_address_type (eid) == GID_ADDR_NSH)
352 rv = VNET_API_ERROR_INVALID_VALUE;
356 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
357 name = format (0, "%s", mp->locator_set_name);
358 vec_terminate_c_string (name);
359 p = hash_get_mem (lcm->locator_set_index_by_name, name);
362 rv = VNET_API_ERROR_INVALID_VALUE;
365 locator_set_index = p[0];
368 key = format (0, "%s", mp->key);
370 /* XXX treat batch configuration */
371 a->is_add = mp->is_add;
372 gid_address_copy (&a->eid, eid);
373 a->locator_set_index = locator_set_index;
376 a->key_id = clib_net_to_host_u16 (mp->key_id);
378 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
383 gid_address_free (&a->eid);
385 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
389 vl_api_one_eid_table_add_del_map_t_handler
390 (vl_api_one_eid_table_add_del_map_t * mp)
392 vl_api_one_eid_table_add_del_map_reply_t *rmp;
394 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
395 clib_net_to_host_u32 (mp->dp_table),
396 mp->is_l2, mp->is_add);
397 REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
400 vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
402 vl_api_one_add_del_map_server_reply_t *rmp;
406 memset (&addr, 0, sizeof (addr));
408 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
409 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
411 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
415 vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
418 vl_api_one_add_del_map_resolver_reply_t *rmp;
420 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
422 memset (a, 0, sizeof (a[0]));
424 a->is_add = mp->is_add;
425 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
427 rv = vnet_lisp_add_del_map_resolver (a);
429 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
433 vl_api_one_map_register_enable_disable_t_handler
434 (vl_api_one_map_register_enable_disable_t * mp)
436 vl_api_one_map_register_enable_disable_reply_t *rmp;
439 vnet_lisp_map_register_enable_disable (mp->is_enabled);
440 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
444 vl_api_one_rloc_probe_enable_disable_t_handler
445 (vl_api_one_rloc_probe_enable_disable_t * mp)
447 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
450 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
451 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
455 vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
457 vl_api_one_enable_disable_reply_t *rmp;
460 vnet_lisp_enable_disable (mp->is_en);
461 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
465 vl_api_show_one_map_request_mode_t_handler
466 (vl_api_show_one_map_request_mode_t * mp)
469 vl_api_show_one_map_request_mode_reply_t *rmp;
472 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
474 rmp->mode = vnet_lisp_get_map_request_mode ();
480 vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
482 vl_api_one_map_request_mode_reply_t *rmp;
485 rv = vnet_lisp_set_map_request_mode (mp->mode);
487 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
491 vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t
494 vl_api_one_nsh_set_locator_set_reply_t *rmp;
498 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
499 ls_name = format (0, "%s", mp->ls_name);
500 vec_terminate_c_string (ls_name);
501 rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add);
504 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
508 vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
511 vl_api_one_pitr_set_locator_set_reply_t *rmp;
515 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
516 ls_name = format (0, "%s", mp->ls_name);
517 vec_terminate_c_string (ls_name);
518 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
521 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
525 vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
527 vl_api_one_use_petr_reply_t *rmp;
531 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
532 rv = vnet_lisp_use_petr (&addr, mp->is_add);
534 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
538 vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
540 unix_shared_memory_queue_t *q = NULL;
541 vl_api_show_one_use_petr_reply_t *rmp = NULL;
542 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
544 locator_set_t *ls = 0;
550 q = vl_api_client_index_to_input_queue (mp->client_index);
556 memset (&addr, 0, sizeof (addr));
557 status = lcm->flags & LISP_FLAG_USE_PETR;
560 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
561 if (~0 != m->locator_set_index)
564 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
565 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
566 gid_address_copy (&addr, &loc->address);
571 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
573 rmp->status = status;
574 ip_address_t *ip = &gid_address_ip (&addr);
575 switch (ip_addr_version (ip))
578 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
579 sizeof (ip_addr_v4 (ip)));
583 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
584 sizeof (ip_addr_v6 (ip)));
590 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
596 vl_api_one_add_del_map_request_itr_rlocs_t_handler
597 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
599 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
601 u8 *locator_set_name = NULL;
602 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
604 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
605 locator_set_name = format (0, "%s", mp->locator_set_name);
606 vec_terminate_c_string (locator_set_name);
608 a->is_add = mp->is_add;
609 a->locator_set_name = locator_set_name;
611 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
613 vec_free (locator_set_name);
615 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
619 vl_api_one_add_del_remote_mapping_t_handler
620 (vl_api_one_add_del_remote_mapping_t * mp)
622 locator_t *rlocs = 0;
623 vl_api_one_add_del_remote_mapping_reply_t *rmp;
625 gid_address_t _eid, *eid = &_eid;
626 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
628 memset (eid, 0, sizeof (eid[0]));
630 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
631 mp->eid_type, mp->eid, mp->eid_len);
635 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
639 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
640 memset (a, 0, sizeof (a[0]));
641 gid_address_copy (&a->reid, eid);
643 rv = vnet_lisp_add_del_adjacency (a);
650 /* NOTE: for now this works as a static remote mapping, i.e.,
651 * not authoritative and ttl infinite. */
654 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
655 memset (m_args, 0, sizeof (m_args[0]));
656 gid_address_copy (&m_args->eid, eid);
657 m_args->action = mp->action;
658 m_args->is_static = 1;
660 m_args->authoritative = 0;
661 rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
664 rv = vnet_lisp_del_mapping (eid, NULL);
667 vnet_lisp_clear_all_remote_adjacencies ();
672 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
676 vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
678 vl_api_one_add_del_adjacency_reply_t *rmp;
679 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
682 memset (a, 0, sizeof (a[0]));
684 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
685 mp->eid_type, mp->leid, mp->leid_len);
686 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
687 mp->eid_type, mp->reid, mp->reid_len);
692 a->is_add = mp->is_add;
693 rv = vnet_lisp_add_del_adjacency (a);
696 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
700 send_one_locator_details (lisp_cp_main_t * lcm,
702 unix_shared_memory_queue_t * q, u32 context)
704 vl_api_one_locator_details_t *rmp;
706 rmp = vl_msg_api_alloc (sizeof (*rmp));
707 memset (rmp, 0, sizeof (*rmp));
708 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
709 rmp->context = context;
711 rmp->local = loc->local;
714 rmp->sw_if_index = ntohl (loc->sw_if_index);
718 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
719 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
721 rmp->priority = loc->priority;
722 rmp->weight = loc->weight;
724 vl_msg_api_send_shmem (q, (u8 *) & rmp);
728 vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
731 unix_shared_memory_queue_t *q = 0;
732 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
733 locator_set_t *lsit = 0;
735 u32 ls_index = ~0, *locit = 0;
738 q = vl_api_client_index_to_input_queue (mp->client_index);
744 if (mp->is_index_set)
745 ls_index = htonl (mp->ls_index);
748 /* make sure we get a proper C-string */
749 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
750 ls_name = format (0, "%s", mp->ls_name);
751 vec_terminate_c_string (ls_name);
752 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
758 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
761 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
763 vec_foreach (locit, lsit->locator_indices)
765 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
766 send_one_locator_details (lcm, loc, q, mp->context);
773 send_one_locator_set_details (lisp_cp_main_t * lcm,
774 locator_set_t * lsit,
775 unix_shared_memory_queue_t * q,
776 u32 context, u32 ls_index)
778 vl_api_one_locator_set_details_t *rmp;
781 rmp = vl_msg_api_alloc (sizeof (*rmp));
782 memset (rmp, 0, sizeof (*rmp));
783 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
784 rmp->context = context;
786 rmp->ls_index = htonl (ls_index);
789 ASSERT (lsit->name != NULL);
790 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
791 vec_len (lsit->name));
795 str = format (0, "<remote-%d>", ls_index);
796 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
800 vl_msg_api_send_shmem (q, (u8 *) & rmp);
804 vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
806 unix_shared_memory_queue_t *q = NULL;
807 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
808 locator_set_t *lsit = NULL;
811 q = vl_api_client_index_to_input_queue (mp->client_index);
819 pool_foreach (lsit, lcm->locator_set_pool,
821 if (filter && !((1 == filter && lsit->local) ||
822 (2 == filter && !lsit->local)))
826 send_one_locator_set_details (lcm, lsit, q, mp->context,
827 lsit - lcm->locator_set_pool);
833 one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
835 ASSERT (prefix_length);
836 ip_prefix_t *ippref = &fid_addr_ippref (src);
838 switch (fid_addr_type (src))
840 case FID_ADDR_IP_PREF:
841 if (ip_prefix_version (ippref) == IP4)
842 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
844 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
845 prefix_length[0] = ip_prefix_len (ippref);
849 prefix_length[0] = 0;
850 clib_memcpy (dst, fid_addr_mac (src), 6);
854 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
860 fid_type_to_api_type (fid_address_t * fid)
864 switch (fid_addr_type (fid))
866 case FID_ADDR_IP_PREF:
867 ippref = &fid_addr_ippref (fid);
868 if (ip_prefix_version (ippref) == IP4)
870 else if (ip_prefix_version (ippref) == IP6)
885 send_one_eid_table_details (mapping_t * mapit,
886 unix_shared_memory_queue_t * q,
887 u32 context, u8 filter)
890 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
891 locator_set_t *ls = 0;
892 vl_api_one_eid_table_details_t *rmp = NULL;
893 gid_address_t *gid = NULL;
895 ip_prefix_t *ip_prefix = NULL;
897 if (mapit->pitr_set || mapit->nsh_set)
902 case 0: /* all mappings */
905 case 1: /* local only */
909 case 2: /* remote only */
914 clib_warning ("Filter error, unknown filter: %d", filter);
919 ip_prefix = &gid_address_ippref (gid);
920 mac = gid_address_mac (gid);
922 rmp = vl_msg_api_alloc (sizeof (*rmp));
923 memset (rmp, 0, sizeof (*rmp));
924 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
926 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
927 if (vec_len (ls->locator_indices) == 0)
928 rmp->locator_set_index = ~0;
930 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
932 rmp->is_local = mapit->local;
933 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
934 rmp->action = mapit->action;
935 rmp->authoritative = mapit->authoritative;
937 switch (gid_address_type (gid))
939 case GID_ADDR_SRC_DST:
941 fid = &gid_address_sd_src (gid);
942 rmp->eid_type = fid_type_to_api_type (fid);
943 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
944 &rmp->seid_prefix_len);
945 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
946 &rmp->eid_prefix_len);
948 case GID_ADDR_IP_PREFIX:
949 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
950 if (ip_prefix_version (ip_prefix) == IP4)
952 rmp->eid_type = 0; /* ipv4 type */
953 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
954 sizeof (ip_prefix_v4 (ip_prefix)));
958 rmp->eid_type = 1; /* ipv6 type */
959 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
960 sizeof (ip_prefix_v6 (ip_prefix)));
964 rmp->eid_type = 2; /* l2 mac type */
965 clib_memcpy (rmp->eid, mac, 6);
968 rmp->eid_type = 3; /* NSH type */
970 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (gid));
971 nsh.si = gid_address_nsh_si (gid);
972 clib_memcpy (rmp->eid, &nsh, sizeof (nsh));
977 rmp->context = context;
978 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
979 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
980 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
981 vl_msg_api_send_shmem (q, (u8 *) & rmp);
985 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
988 unix_shared_memory_queue_t *q = NULL;
989 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
990 mapping_t *mapit = NULL;
991 gid_address_t _eid, *eid = &_eid;
993 q = vl_api_client_index_to_input_queue (mp->client_index);
1001 memset (eid, 0, sizeof (*eid));
1003 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
1004 mp->eid_type, mp->eid, mp->prefix_length);
1006 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
1007 if ((u32) ~ 0 == mi)
1010 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
1011 send_one_eid_table_details (mapit, q, mp->context,
1012 0 /* ignore filter */ );
1017 pool_foreach (mapit, lcm->mapping_pool,
1019 send_one_eid_table_details(mapit, q, mp->context,
1027 send_one_map_server_details (ip_address_t * ip,
1028 unix_shared_memory_queue_t * q, u32 context)
1030 vl_api_one_map_server_details_t *rmp = NULL;
1032 rmp = vl_msg_api_alloc (sizeof (*rmp));
1033 memset (rmp, 0, sizeof (*rmp));
1034 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
1036 switch (ip_addr_version (ip))
1040 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1041 sizeof (ip_addr_v4 (ip)));
1046 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1047 sizeof (ip_addr_v6 (ip)));
1053 rmp->context = context;
1055 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1059 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
1061 unix_shared_memory_queue_t *q = NULL;
1062 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1065 q = vl_api_client_index_to_input_queue (mp->client_index);
1071 vec_foreach (mr, lcm->map_servers)
1073 send_one_map_server_details (&mr->address, q, mp->context);
1078 send_one_map_resolver_details (ip_address_t * ip,
1079 unix_shared_memory_queue_t * q, u32 context)
1081 vl_api_one_map_resolver_details_t *rmp = NULL;
1083 rmp = vl_msg_api_alloc (sizeof (*rmp));
1084 memset (rmp, 0, sizeof (*rmp));
1085 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
1087 switch (ip_addr_version (ip))
1091 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1092 sizeof (ip_addr_v4 (ip)));
1097 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1098 sizeof (ip_addr_v6 (ip)));
1104 rmp->context = context;
1106 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1110 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
1112 unix_shared_memory_queue_t *q = NULL;
1113 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1116 q = vl_api_client_index_to_input_queue (mp->client_index);
1122 vec_foreach (mr, lcm->map_resolvers)
1124 send_one_map_resolver_details (&mr->address, q, mp->context);
1129 send_eid_table_map_pair (hash_pair_t * p,
1130 unix_shared_memory_queue_t * q, u32 context)
1132 vl_api_one_eid_table_map_details_t *rmp = NULL;
1134 rmp = vl_msg_api_alloc (sizeof (*rmp));
1135 memset (rmp, 0, sizeof (*rmp));
1136 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1138 rmp->vni = clib_host_to_net_u32 (p->key);
1139 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1140 rmp->context = context;
1141 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1145 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1147 unix_shared_memory_queue_t *q = NULL;
1148 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1150 uword *vni_table = 0;
1152 q = vl_api_client_index_to_input_queue (mp->client_index);
1160 vni_table = lcm->bd_id_by_vni;
1164 vni_table = lcm->table_id_by_vni;
1168 hash_foreach_pair (p, vni_table,
1170 send_eid_table_map_pair (p, q, mp->context);
1176 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1178 vl_api_one_eid_table_vni_details_t *rmp = 0;
1180 rmp = vl_msg_api_alloc (sizeof (*rmp));
1181 memset (rmp, 0, sizeof (*rmp));
1182 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1183 rmp->context = context;
1184 rmp->vni = clib_host_to_net_u32 (vni);
1185 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1189 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1191 lisp_adjacency_t *adj;
1192 vl_api_one_adjacency_t a;
1193 u32 i, n = vec_len (adjs);
1196 for (i = 0; i < n; i++)
1198 adj = vec_elt_at_index (adjs, i);
1199 memset (&a, 0, sizeof (a));
1201 switch (gid_address_type (&adj->reid))
1203 case GID_ADDR_IP_PREFIX:
1204 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1205 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1206 if (gid_address_ip_version (&adj->reid) == IP4)
1208 a.eid_type = 0; /* ipv4 type */
1209 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1210 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1214 a.eid_type = 1; /* ipv6 type */
1215 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1216 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1220 a.eid_type = 2; /* l2 mac type */
1221 mac_copy (a.reid, gid_address_mac (&adj->reid));
1222 mac_copy (a.leid, gid_address_mac (&adj->leid));
1225 a.eid_type = 3; /* NSH type */
1226 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid));
1227 nsh.si = gid_address_nsh_si (&adj->reid);
1228 clib_memcpy (a.reid, &nsh, sizeof (nsh));
1230 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid));
1231 nsh.si = gid_address_nsh_si (&adj->leid);
1232 clib_memcpy (a.leid, &nsh, sizeof (nsh));
1242 vl_api_show_one_rloc_probe_state_t_handler
1243 (vl_api_show_one_rloc_probe_state_t * mp)
1245 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1249 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1251 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1257 vl_api_show_one_map_register_state_t_handler
1258 (vl_api_show_one_map_register_state_t * mp)
1260 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1264 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1266 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1272 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1274 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1275 lisp_adjacency_t *adjs = 0;
1278 u32 vni = clib_net_to_host_u32 (mp->vni);
1280 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1281 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1284 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1286 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1287 one_adjacency_copy (rmp->adjacencies, adjs);
1295 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1299 unix_shared_memory_queue_t *q = 0;
1300 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1302 q = vl_api_client_index_to_input_queue (mp->client_index);
1309 hash_foreach_pair (p, lcm->table_id_by_vni,
1311 hash_set (vnis, p->key, 0);
1314 hash_foreach_pair (p, lcm->bd_id_by_vni,
1316 hash_set (vnis, p->key, 0);
1319 hash_foreach_pair (p, vnis,
1321 send_eid_table_vni (p->key, q, mp->context);
1329 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1331 vl_api_show_one_status_reply_t *rmp = NULL;
1335 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1337 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1338 rmp->feature_status = vnet_lisp_enable_disable_status ();
1344 vl_api_one_get_map_request_itr_rlocs_t_handler
1345 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1347 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1348 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1349 locator_set_t *loc_set = 0;
1353 if (~0 == lcm->mreq_itr_rlocs)
1355 tmp_str = format (0, " ");
1360 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1361 tmp_str = format (0, "%s", loc_set->name);
1365 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1367 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1368 ARRAY_LEN(rmp->locator_set_name) - 1);
1376 vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp)
1378 unix_shared_memory_queue_t *q = NULL;
1379 vl_api_show_one_nsh_mapping_reply_t *rmp = NULL;
1380 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1382 locator_set_t *ls = 0;
1387 q = vl_api_client_index_to_input_queue (mp->client_index);
1393 if (lcm->nsh_map_index == (u32) ~ 0)
1395 tmp_str = format (0, "N/A");
1399 m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index);
1400 if (~0 != m->locator_set_index)
1403 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1404 tmp_str = format (0, "%s", ls->name);
1409 tmp_str = format (0, "N/A");
1412 vec_add1 (tmp_str, 0);
1415 REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY,
1417 rmp->is_set = is_set;
1418 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1419 ARRAY_LEN(rmp->locator_set_name) - 1);
1425 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1427 unix_shared_memory_queue_t *q = NULL;
1428 vl_api_show_one_pitr_reply_t *rmp = NULL;
1429 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1431 locator_set_t *ls = 0;
1435 q = vl_api_client_index_to_input_queue (mp->client_index);
1441 u8 is_enabled = (lcm->flags & LISP_FLAG_PITR_MODE)
1442 && lcm->pitr_map_index != ~0;
1446 tmp_str = format (0, "N/A");
1450 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1451 if (~0 != m->locator_set_index)
1454 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1455 tmp_str = format (0, "%s", ls->name);
1459 tmp_str = format (0, "N/A");
1462 vec_add1 (tmp_str, 0);
1465 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1467 rmp->status = lcm->flags & LISP_FLAG_PITR_MODE;
1468 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1469 ARRAY_LEN(rmp->locator_set_name) - 1);
1475 vl_api_show_one_stats_enable_disable_t_handler
1476 (vl_api_show_one_stats_enable_disable_t * mp)
1478 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1479 vnet_api_error_t rv = 0;
1482 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1484 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1490 vl_api_one_stats_enable_disable_t_handler
1491 (vl_api_one_stats_enable_disable_t * mp)
1493 vl_api_one_enable_disable_reply_t *rmp = NULL;
1495 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1496 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1500 lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1503 switch (fid_addr_type (fid))
1505 case FID_ADDR_IP_PREF:
1506 *prefix_length = fid_addr_prefix_length (fid);
1507 if (fid_addr_ip_version (fid) == IP4)
1509 *api_eid_type = 0; /* ipv4 type */
1510 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1514 *api_eid_type = 1; /* ipv6 type */
1515 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1519 *api_eid_type = 2; /* l2 mac type */
1520 mac_copy (dst, fid_addr_mac (fid));
1528 vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
1530 vl_api_one_stats_flush_reply_t *rmp;
1533 rv = vnet_lisp_flush_stats ();
1534 REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
1538 vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1540 vl_api_one_stats_details_t *rmp;
1541 lisp_api_stats_t *stats, *stat;
1544 stats = vnet_lisp_get_stats ();
1545 vec_foreach (stat, stats)
1548 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1550 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1551 &rmp->deid_pref_len);
1552 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1553 &rmp->seid_pref_len);
1554 rmp->vni = clib_host_to_net_u32 (stat->vni);
1556 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1557 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1558 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1560 rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
1561 rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
1568 vl_api_one_add_del_l2_arp_entry_t_handler
1569 (vl_api_one_add_del_l2_arp_entry_t * mp)
1571 vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
1573 gid_address_t _arp, *arp = &_arp;
1574 memset (arp, 0, sizeof (*arp));
1576 gid_address_type (arp) = GID_ADDR_ARP;
1577 gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
1579 /* vpp keeps ip4 addresses in network byte order */
1580 ip_address_set (&gid_address_arp_ndp_ip (arp), &mp->ip4, IP4);
1582 rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mp->mac, mp->is_add);
1584 REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY);
1588 vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp)
1590 vl_api_one_add_del_ndp_entry_reply_t *rmp;
1592 gid_address_t _g, *g = &_g;
1593 memset (g, 0, sizeof (*g));
1595 gid_address_type (g) = GID_ADDR_NDP;
1596 gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd);
1597 ip_address_set (&gid_address_arp_ndp_ip (g), mp->ip6, IP6);
1599 rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mp->mac, mp->is_add);
1601 REPLY_MACRO (VL_API_ONE_ADD_DEL_NDP_ENTRY_REPLY);
1605 vl_api_one_ndp_bd_get_t_handler (vl_api_one_ndp_bd_get_t * mp)
1607 vl_api_one_ndp_bd_get_reply_t *rmp;
1612 u32 *bds = vnet_lisp_ndp_bds_get ();
1613 u32 size = hash_elts (bds) * sizeof (u32);
1616 REPLY_MACRO4 (VL_API_ONE_NDP_BD_GET_REPLY, size,
1618 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1619 hash_foreach_pair (p, bds,
1621 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1630 vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp)
1632 vl_api_one_l2_arp_bd_get_reply_t *rmp;
1637 u32 *bds = vnet_lisp_l2_arp_bds_get ();
1638 u32 size = hash_elts (bds) * sizeof (u32);
1641 REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size,
1643 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1644 hash_foreach_pair (p, bds,
1646 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1655 vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp)
1657 vl_api_one_l2_arp_entries_get_reply_t *rmp;
1658 lisp_api_l2_arp_entry_t *entries = 0, *e;
1662 u32 bd = clib_net_to_host_u32 (mp->bd);
1664 entries = vnet_lisp_l2_arp_entries_get_by_bd (bd);
1665 u32 size = vec_len (entries) * sizeof (vl_api_one_l2_arp_entry_t);
1668 REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size,
1670 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1671 vec_foreach (e, entries)
1673 mac_copy (rmp->entries[i].mac, e->mac);
1674 rmp->entries[i].ip4 = e->ip4;
1684 vl_api_one_map_register_fallback_threshold_t_handler
1685 (vl_api_one_map_register_fallback_threshold_t * mp)
1687 vl_api_one_map_register_fallback_threshold_reply_t *rmp;
1690 mp->value = clib_net_to_host_u32 (mp->value);
1691 rv = vnet_lisp_map_register_fallback_threshold_set (mp->value);
1692 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY);
1696 vl_api_show_one_map_register_fallback_threshold_t_handler
1697 (vl_api_show_one_map_register_fallback_threshold_t * mp)
1699 vl_api_show_one_map_register_fallback_threshold_reply_t *rmp;
1702 u32 value = vnet_lisp_map_register_fallback_threshold_get ();
1705 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY,
1707 rmp->value = clib_host_to_net_u32 (value);
1713 vl_api_one_set_transport_protocol_t_handler
1714 (vl_api_one_set_transport_protocol_t * mp)
1716 vl_api_one_set_transport_protocol_reply_t *rmp;
1719 rv = vnet_lisp_set_transport_protocol (mp->protocol);
1721 REPLY_MACRO (VL_API_ONE_SET_TRANSPORT_PROTOCOL_REPLY);
1725 vl_api_one_get_transport_protocol_t_handler
1726 (vl_api_one_get_transport_protocol_t * mp)
1728 vl_api_one_get_transport_protocol_reply_t *rmp;
1730 u8 proto = (u8) vnet_lisp_get_transport_protocol ();
1733 REPLY_MACRO2 (VL_API_ONE_GET_TRANSPORT_PROTOCOL_REPLY,
1735 rmp->protocol = proto;
1741 vl_api_one_ndp_entries_get_t_handler (vl_api_one_ndp_entries_get_t * mp)
1743 vl_api_one_ndp_entries_get_reply_t *rmp = 0;
1744 lisp_api_ndp_entry_t *entries = 0, *e;
1748 u32 bd = clib_net_to_host_u32 (mp->bd);
1750 entries = vnet_lisp_ndp_entries_get_by_bd (bd);
1751 u32 size = vec_len (entries) * sizeof (vl_api_one_ndp_entry_t);
1754 REPLY_MACRO4 (VL_API_ONE_NDP_ENTRIES_GET_REPLY, size,
1756 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1757 vec_foreach (e, entries)
1759 mac_copy (rmp->entries[i].mac, e->mac);
1760 clib_memcpy (rmp->entries[i].ip6, e->ip6, 16);
1770 vl_api_one_enable_disable_xtr_mode_t_handler
1771 (vl_api_one_enable_disable_xtr_mode_t * mp)
1773 vl_api_one_enable_disable_xtr_mode_reply_t *rmp = 0;
1774 int rv = vnet_lisp_enable_disable_xtr_mode (mp->is_en);
1776 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_XTR_MODE_REPLY);
1780 vl_api_one_show_xtr_mode_t_handler (vl_api_one_show_xtr_mode_t * mp)
1782 vl_api_one_show_xtr_mode_reply_t *rmp = 0;
1786 REPLY_MACRO2 (VL_API_ONE_SHOW_XTR_MODE_REPLY,
1788 rmp->is_en = vnet_lisp_get_xtr_mode ();
1794 vl_api_one_enable_disable_pitr_mode_t_handler
1795 (vl_api_one_enable_disable_pitr_mode_t * mp)
1797 vl_api_one_enable_disable_pitr_mode_reply_t *rmp = 0;
1798 int rv = vnet_lisp_enable_disable_pitr_mode (mp->is_en);
1800 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PITR_MODE_REPLY);
1804 vl_api_one_show_pitr_mode_t_handler (vl_api_one_show_pitr_mode_t * mp)
1806 vl_api_one_show_pitr_mode_reply_t *rmp = 0;
1810 REPLY_MACRO2 (VL_API_ONE_SHOW_PITR_MODE_REPLY,
1812 rmp->is_en = vnet_lisp_get_pitr_mode ();
1818 vl_api_one_enable_disable_petr_mode_t_handler
1819 (vl_api_one_enable_disable_petr_mode_t * mp)
1821 vl_api_one_enable_disable_petr_mode_reply_t *rmp = 0;
1822 int rv = vnet_lisp_enable_disable_petr_mode (mp->is_en);
1824 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PETR_MODE_REPLY);
1828 vl_api_one_show_petr_mode_t_handler (vl_api_one_show_petr_mode_t * mp)
1830 vl_api_one_show_petr_mode_reply_t *rmp = 0;
1834 REPLY_MACRO2 (VL_API_ONE_SHOW_PETR_MODE_REPLY,
1836 rmp->is_en = vnet_lisp_get_petr_mode ();
1843 * Add vpe's API message handlers to the table.
1844 * vlib has alread mapped shared memory and
1845 * added the client registration handlers.
1846 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1848 #define vl_msg_name_crc_list
1849 #include <vnet/vnet_all_api_h.h>
1850 #undef vl_msg_name_crc_list
1853 setup_message_id_table (api_main_t * am)
1855 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1856 foreach_vl_msg_name_crc_one;
1860 static clib_error_t *
1861 one_api_hookup (vlib_main_t * vm)
1863 api_main_t *am = &api_main;
1866 vl_msg_api_set_handlers(VL_API_##N, #n, \
1867 vl_api_##n##_t_handler, \
1869 vl_api_##n##_t_endian, \
1870 vl_api_##n##_t_print, \
1871 sizeof(vl_api_##n##_t), 1);
1872 foreach_vpe_api_msg;
1876 * Set up the (msg_name, crc, message-id) table
1878 setup_message_id_table (am);
1883 VLIB_API_INIT_FUNCTION (one_api_hookup);
1886 * fd.io coding-style-patch-verification: ON
1889 * eval: (c-set-style "gnu")