blob: 28924091fd326136ee040c59491e1fbe176d467f [file] [log] [blame]
Filip Tehlar694396d2017-02-17 14:29:11 +01001/*
2 *------------------------------------------------------------------
3 * one_api.c - Overlay Network Engine API
4 *
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:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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 *------------------------------------------------------------------
18 */
19
20#include <vnet/vnet.h>
21#include <vlibmemory/api.h>
22
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>
27
28#include <vnet/vnet_msg_enum.h>
29
Filip Tehlar974cdc62017-02-22 18:09:49 +010030#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
Filip Tehlar694396d2017-02-17 14:29:11 +010034
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
39
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
44
45#define vl_typedefs /* define message structures */
46#include <vnet/vnet_all_api_h.h>
47#undef vl_typedefs
48
49#define vl_endianfun /* define message structures */
50#include <vnet/vnet_all_api_h.h>
51#undef vl_endianfun
52
53/* instantiate all the print functions we know about */
54#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
55#define vl_printfun
56#include <vnet/vnet_all_api_h.h>
57#undef vl_printfun
58
59#include <vlibapi/api_helper_macros.h>
60
Filip Tehlar4868ff62017-03-09 16:48:39 +010061#define REPLY_DETAILS(t, body) \
62do { \
63 unix_shared_memory_queue_t * q; \
64 rv = vl_msg_api_pd_handler (mp, rv); \
65 q = vl_api_client_index_to_input_queue (mp->client_index); \
66 if (!q) \
67 return; \
68 \
69 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
70 rmp->_vl_msg_id = ntohs((t)); \
71 rmp->context = mp->context; \
72 do {body;} while (0); \
73 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
74} while(0);
75
Filip Tehlar694396d2017-02-17 14:29:11 +010076#define foreach_vpe_api_msg \
77_(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
78_(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
79_(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
80_(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
81_(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
82_(ONE_ENABLE_DISABLE, one_enable_disable) \
83_(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
84_(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
85_(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
86_(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
87_(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
88_(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
89_(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
90_(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
91_(ONE_LOCATOR_DUMP, one_locator_dump) \
92_(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
93_(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
94_(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
95_(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
96_(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
97_(ONE_ADJACENCIES_GET, one_adjacencies_get) \
98_(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
99_(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
100_(SHOW_ONE_STATUS, show_one_status) \
101_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
102 one_add_del_map_request_itr_rlocs) \
103_(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
104_(SHOW_ONE_PITR, show_one_pitr) \
105_(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
106_(ONE_USE_PETR, one_use_petr) \
107_(SHOW_ONE_USE_PETR, show_one_use_petr) \
Filip Tehlar7eaf0e52017-03-08 08:46:51 +0100108_(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
109_(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
110_(ONE_STATS_DUMP, one_stats_dump) \
111
Filip Tehlar694396d2017-02-17 14:29:11 +0100112
113static locator_t *
Filip Tehlar974cdc62017-02-22 18:09:49 +0100114unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
Filip Tehlar694396d2017-02-17 14:29:11 +0100115{
116 u32 i;
117 locator_t *locs = 0, loc;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100118 vl_api_one_remote_locator_t *r;
Filip Tehlar694396d2017-02-17 14:29:11 +0100119
120 for (i = 0; i < rloc_num; i++)
121 {
122 /* remote locators */
123 r = &rmt_locs[i];
124 memset (&loc, 0, sizeof (loc));
125 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
126
127 loc.priority = r->priority;
128 loc.weight = r->weight;
129
130 vec_add1 (locs, loc);
131 }
132 return locs;
133}
134
135static void
136vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
137 mp)
138{
139 vl_api_one_add_del_locator_set_reply_t *rmp;
140 int rv = 0;
141 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
142 locator_t locator;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100143 vl_api_one_local_locator_t *ls_loc;
Filip Tehlar694396d2017-02-17 14:29:11 +0100144 u32 ls_index = ~0, locator_num;
145 u8 *locator_name = NULL;
146 int i;
147
148 memset (a, 0, sizeof (a[0]));
149
150 locator_name = format (0, "%s", mp->locator_set_name);
151
152 a->name = locator_name;
153 a->is_add = mp->is_add;
154 a->local = 1;
155 locator_num = clib_net_to_host_u32 (mp->locator_num);
156
157 memset (&locator, 0, sizeof (locator));
158 for (i = 0; i < locator_num; i++)
159 {
160 ls_loc = &mp->locators[i];
161 VALIDATE_SW_IF_INDEX (ls_loc);
162
163 locator.sw_if_index = htonl (ls_loc->sw_if_index);
164 locator.priority = ls_loc->priority;
165 locator.weight = ls_loc->weight;
166 locator.local = 1;
167 vec_add1 (a->locators, locator);
168 }
169
170 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
171
172 BAD_SW_IF_INDEX_LABEL;
173
174 vec_free (locator_name);
175 vec_free (a->locators);
176
177 /* *INDENT-OFF* */
178 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
179 ({
180 rmp->ls_index = clib_host_to_net_u32 (ls_index);
181 }));
182 /* *INDENT-ON* */
183}
184
185static void
186vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
187{
188 vl_api_one_add_del_locator_reply_t *rmp;
189 int rv = 0;
190 locator_t locator, *locators = NULL;
191 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
192 u32 ls_index = ~0;
193 u8 *locator_name = NULL;
194
195 memset (&locator, 0, sizeof (locator));
196 memset (a, 0, sizeof (a[0]));
197
198 locator.sw_if_index = ntohl (mp->sw_if_index);
199 locator.priority = mp->priority;
200 locator.weight = mp->weight;
201 locator.local = 1;
202 vec_add1 (locators, locator);
203
204 locator_name = format (0, "%s", mp->locator_set_name);
205
206 a->name = locator_name;
207 a->locators = locators;
208 a->is_add = mp->is_add;
209 a->local = 1;
210
211 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
212
213 vec_free (locators);
214 vec_free (locator_name);
215
216 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
217}
218
219static int
220unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
221 u8 len)
222{
223 switch (type)
224 {
225 case 0: /* ipv4 */
226 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
227 gid_address_ip_set (dst, src, IP4);
228 gid_address_ippref_len (dst) = len;
229 ip_prefix_normalize (&gid_address_ippref (dst));
230 break;
231 case 1: /* ipv6 */
232 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
233 gid_address_ip_set (dst, src, IP6);
234 gid_address_ippref_len (dst) = len;
235 ip_prefix_normalize (&gid_address_ippref (dst));
236 break;
237 case 2: /* l2 mac */
238 gid_address_type (dst) = GID_ADDR_MAC;
239 clib_memcpy (&gid_address_mac (dst), src, 6);
240 break;
241 default:
242 /* unknown type */
243 return VNET_API_ERROR_INVALID_VALUE;
244 }
245
246 gid_address_vni (dst) = vni;
247
248 return 0;
249}
250
251static void
252vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
253{
254 vl_api_one_add_del_local_eid_reply_t *rmp;
255 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
256 int rv = 0;
257 gid_address_t _eid, *eid = &_eid;
258 uword *p = NULL;
259 u32 locator_set_index = ~0, map_index = ~0;
260 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
261 u8 *name = NULL, *key = NULL;
262 memset (a, 0, sizeof (a[0]));
263 memset (eid, 0, sizeof (eid[0]));
264
265 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
266 mp->eid_type, mp->eid, mp->prefix_len);
267 if (rv)
268 goto out;
269
270 name = format (0, "%s", mp->locator_set_name);
271 p = hash_get_mem (lcm->locator_set_index_by_name, name);
272 if (!p)
273 {
274 rv = VNET_API_ERROR_INVALID_VALUE;
275 goto out;
276 }
277 locator_set_index = p[0];
278
279 if (*mp->key)
280 key = format (0, "%s", mp->key);
281
282 /* XXX treat batch configuration */
283 a->is_add = mp->is_add;
284 gid_address_copy (&a->eid, eid);
285 a->locator_set_index = locator_set_index;
286 a->local = 1;
287 a->key = key;
288 a->key_id = clib_net_to_host_u16 (mp->key_id);
289
290 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
291
292out:
293 vec_free (name);
294 vec_free (key);
295 gid_address_free (&a->eid);
296
297 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
298}
299
300static void
301 vl_api_one_eid_table_add_del_map_t_handler
302 (vl_api_one_eid_table_add_del_map_t * mp)
303{
304 vl_api_one_eid_table_add_del_map_reply_t *rmp;
305 int rv = 0;
306 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
307 clib_net_to_host_u32 (mp->dp_table),
308 mp->is_l2, mp->is_add);
309REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
310
311static void
312vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
313{
314 vl_api_one_add_del_map_server_reply_t *rmp;
315 int rv = 0;
316 ip_address_t addr;
317
318 memset (&addr, 0, sizeof (addr));
319
320 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
321 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
322
323 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
324}
325
326static void
327vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
328 * mp)
329{
330 vl_api_one_add_del_map_resolver_reply_t *rmp;
331 int rv = 0;
332 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
333
334 memset (a, 0, sizeof (a[0]));
335
336 a->is_add = mp->is_add;
337 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
338
339 rv = vnet_lisp_add_del_map_resolver (a);
340
341 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
342}
343
344static void
345 vl_api_one_map_register_enable_disable_t_handler
346 (vl_api_one_map_register_enable_disable_t * mp)
347{
348 vl_api_one_map_register_enable_disable_reply_t *rmp;
349 int rv = 0;
350
351 vnet_lisp_map_register_enable_disable (mp->is_enabled);
352 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
353}
354
355static void
356 vl_api_one_rloc_probe_enable_disable_t_handler
357 (vl_api_one_rloc_probe_enable_disable_t * mp)
358{
359 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
360 int rv = 0;
361
362 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
363 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
364}
365
366static void
367vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
368{
369 vl_api_one_enable_disable_reply_t *rmp;
370 int rv = 0;
371
372 vnet_lisp_enable_disable (mp->is_en);
373 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
374}
375
376static void
377 vl_api_show_one_map_request_mode_t_handler
378 (vl_api_show_one_map_request_mode_t * mp)
379{
380 int rv = 0;
381 vl_api_show_one_map_request_mode_reply_t *rmp;
382
383 /* *INDENT-OFF* */
384 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
385 ({
386 rmp->mode = vnet_lisp_get_map_request_mode ();
387 }));
388 /* *INDENT-ON* */
389}
390
391static void
392vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
393{
394 vl_api_one_map_request_mode_reply_t *rmp;
395 int rv = 0;
396
397 rv = vnet_lisp_set_map_request_mode (mp->mode);
398
399 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
400}
401
402static void
403vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
404 * mp)
405{
406 vl_api_one_pitr_set_locator_set_reply_t *rmp;
407 int rv = 0;
408 u8 *ls_name = 0;
409
410 ls_name = format (0, "%s", mp->ls_name);
411 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
412 vec_free (ls_name);
413
414 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
415}
416
417static void
418vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
419{
420 vl_api_one_use_petr_reply_t *rmp;
421 int rv = 0;
422 ip_address_t addr;
423
424 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
425 rv = vnet_lisp_use_petr (&addr, mp->is_add);
426
427 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
428}
429
430static void
431vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
432{
433 unix_shared_memory_queue_t *q = NULL;
434 vl_api_show_one_use_petr_reply_t *rmp = NULL;
435 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
436 mapping_t *m;
437 locator_set_t *ls = 0;
438 int rv = 0;
439 locator_t *loc = 0;
440 u8 status = 0;
441 gid_address_t addr;
442
443 q = vl_api_client_index_to_input_queue (mp->client_index);
444 if (q == 0)
445 {
446 return;
447 }
448
449 memset (&addr, 0, sizeof (addr));
450 status = lcm->flags & LISP_FLAG_USE_PETR;
451 if (status)
452 {
453 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
454 if (~0 != m->locator_set_index)
455 {
456 ls =
457 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
458 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
459 gid_address_copy (&addr, &loc->address);
460 }
461 }
462
463 /* *INDENT-OFF* */
464 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
465 {
Filip Tehlar67a99f82017-03-10 13:18:02 +0100466 rmp->status = status;
467 ip_address_t *ip = &gid_address_ip (&addr);
468 switch (ip_addr_version (ip))
469 {
470 case IP4:
471 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
472 sizeof (ip_addr_v4 (ip)));
473 break;
474
475 case IP6:
476 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
477 sizeof (ip_addr_v6 (ip)));
478 break;
479
480 default:
481 ASSERT (0);
482 }
483 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
Filip Tehlar694396d2017-02-17 14:29:11 +0100484 });
485 /* *INDENT-ON* */
486}
487
488static void
489 vl_api_one_add_del_map_request_itr_rlocs_t_handler
490 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
491{
492 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
493 int rv = 0;
494 u8 *locator_set_name = NULL;
495 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
496
497 locator_set_name = format (0, "%s", mp->locator_set_name);
498
499 a->is_add = mp->is_add;
500 a->locator_set_name = locator_set_name;
501
502 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
503
504 vec_free (locator_set_name);
505
506 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
507}
508
509static void
510 vl_api_one_add_del_remote_mapping_t_handler
511 (vl_api_one_add_del_remote_mapping_t * mp)
512{
513 locator_t *rlocs = 0;
514 vl_api_one_add_del_remote_mapping_reply_t *rmp;
515 int rv = 0;
516 gid_address_t _eid, *eid = &_eid;
517 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
518
519 memset (eid, 0, sizeof (eid[0]));
520
521 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
522 mp->eid_type, mp->eid, mp->eid_len);
523 if (rv)
524 goto send_reply;
525
526 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
527
528 if (!mp->is_add)
529 {
530 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
531 gid_address_copy (&a->reid, eid);
532 a->is_add = 0;
533 rv = vnet_lisp_add_del_adjacency (a);
534 if (rv)
535 {
536 goto out;
537 }
538 }
539
540 /* NOTE: for now this works as a static remote mapping, i.e.,
541 * not authoritative and ttl infinite. */
542 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
543 mp->is_add, 1 /* is_static */ , 0);
544
545 if (mp->del_all)
546 vnet_lisp_clear_all_remote_adjacencies ();
547
548out:
549 vec_free (rlocs);
550send_reply:
551 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
552}
553
554static void
555vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
556{
557 vl_api_one_add_del_adjacency_reply_t *rmp;
558 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
559
560 int rv = 0;
561 memset (a, 0, sizeof (a[0]));
562
563 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
564 mp->eid_type, mp->leid, mp->leid_len);
565 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
566 mp->eid_type, mp->reid, mp->reid_len);
567
568 if (rv)
569 goto send_reply;
570
571 a->is_add = mp->is_add;
572 rv = vnet_lisp_add_del_adjacency (a);
573
574send_reply:
575 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
576}
577
578static void
579send_one_locator_details (lisp_cp_main_t * lcm,
580 locator_t * loc,
581 unix_shared_memory_queue_t * q, u32 context)
582{
583 vl_api_one_locator_details_t *rmp;
584
585 rmp = vl_msg_api_alloc (sizeof (*rmp));
586 memset (rmp, 0, sizeof (*rmp));
587 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
588 rmp->context = context;
589
590 rmp->local = loc->local;
591 if (loc->local)
592 {
593 rmp->sw_if_index = ntohl (loc->sw_if_index);
594 }
595 else
596 {
597 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
598 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
599 }
600 rmp->priority = loc->priority;
601 rmp->weight = loc->weight;
602
603 vl_msg_api_send_shmem (q, (u8 *) & rmp);
604}
605
606static void
607vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
608{
609 u8 *ls_name = 0;
610 unix_shared_memory_queue_t *q = 0;
611 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
612 locator_set_t *lsit = 0;
613 locator_t *loc = 0;
614 u32 ls_index = ~0, *locit = 0;
615 uword *p = 0;
616
617 q = vl_api_client_index_to_input_queue (mp->client_index);
618 if (q == 0)
619 {
620 return;
621 }
622
623 if (mp->is_index_set)
624 ls_index = htonl (mp->ls_index);
625 else
626 {
627 /* make sure we get a proper C-string */
628 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
629 ls_name = format (0, "%s", mp->ls_name);
630 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
631 if (!p)
632 goto out;
633 ls_index = p[0];
634 }
635
636 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
637 return;
638
639 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
640
641 vec_foreach (locit, lsit->locator_indices)
642 {
643 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
644 send_one_locator_details (lcm, loc, q, mp->context);
645 };
646out:
647 vec_free (ls_name);
648}
649
650static void
651send_one_locator_set_details (lisp_cp_main_t * lcm,
652 locator_set_t * lsit,
653 unix_shared_memory_queue_t * q,
654 u32 context, u32 ls_index)
655{
656 vl_api_one_locator_set_details_t *rmp;
657 u8 *str = 0;
658
659 rmp = vl_msg_api_alloc (sizeof (*rmp));
660 memset (rmp, 0, sizeof (*rmp));
661 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
662 rmp->context = context;
663
664 rmp->ls_index = htonl (ls_index);
665 if (lsit->local)
666 {
667 ASSERT (lsit->name != NULL);
668 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
669 vec_len (lsit->name));
670 }
671 else
672 {
673 str = format (0, "<remote-%d>", ls_index);
674 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
675 vec_free (str);
676 }
677
678 vl_msg_api_send_shmem (q, (u8 *) & rmp);
679}
680
681static void
682vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
683{
684 unix_shared_memory_queue_t *q = NULL;
685 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
686 locator_set_t *lsit = NULL;
687 u8 filter;
688
689 q = vl_api_client_index_to_input_queue (mp->client_index);
690 if (q == 0)
691 {
692 return;
693 }
694
695 filter = mp->filter;
696 /* *INDENT-OFF* */
697 pool_foreach (lsit, lcm->locator_set_pool,
698 ({
699 if (filter && !((1 == filter && lsit->local) ||
700 (2 == filter && !lsit->local)))
701 {
702 continue;
703 }
704 send_one_locator_set_details (lcm, lsit, q, mp->context,
705 lsit - lcm->locator_set_pool);
706 }));
707 /* *INDENT-ON* */
708}
709
710static void
711one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
712{
713 ASSERT (prefix_length);
714 ip_prefix_t *ippref = &fid_addr_ippref (src);
715
716 switch (fid_addr_type (src))
717 {
718 case FID_ADDR_IP_PREF:
719 if (ip_prefix_version (ippref) == IP4)
720 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
721 else
722 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
723 prefix_length[0] = ip_prefix_len (ippref);
724 break;
725
726 case FID_ADDR_MAC:
727 prefix_length[0] = 0;
728 clib_memcpy (dst, fid_addr_mac (src), 6);
729 break;
730
731 default:
732 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
733 break;
734 }
735}
736
737static u8
738fid_type_to_api_type (fid_address_t * fid)
739{
740 ip_prefix_t *ippref;
741
742 switch (fid_addr_type (fid))
743 {
744 case FID_ADDR_IP_PREF:
745 ippref = &fid_addr_ippref (fid);
746 if (ip_prefix_version (ippref) == IP4)
747 return 0;
748 else if (ip_prefix_version (ippref) == IP6)
749 return 1;
750 else
751 return ~0;
752
753 case FID_ADDR_MAC:
754 return 2;
755 case FID_ADDR_NSH:
756 return 3;
757 }
758
759 return ~0;
760}
761
762static void
763send_one_eid_table_details (mapping_t * mapit,
764 unix_shared_memory_queue_t * q,
765 u32 context, u8 filter)
766{
767 fid_address_t *fid;
768 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
769 locator_set_t *ls = 0;
770 vl_api_one_eid_table_details_t *rmp = NULL;
771 gid_address_t *gid = NULL;
772 u8 *mac = 0;
773 ip_prefix_t *ip_prefix = NULL;
774
Filip Tehlar1e8d01f2017-03-30 15:17:01 +0200775 if (mapit->pitr_set)
776 return;
777
Filip Tehlar694396d2017-02-17 14:29:11 +0100778 switch (filter)
779 {
780 case 0: /* all mappings */
781 break;
782
783 case 1: /* local only */
784 if (!mapit->local)
785 return;
786 break;
787 case 2: /* remote only */
788 if (mapit->local)
789 return;
790 break;
791 default:
792 clib_warning ("Filter error, unknown filter: %d", filter);
793 return;
794 }
795
796 gid = &mapit->eid;
797 ip_prefix = &gid_address_ippref (gid);
798 mac = gid_address_mac (gid);
799
800 rmp = vl_msg_api_alloc (sizeof (*rmp));
801 memset (rmp, 0, sizeof (*rmp));
802 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
803
804 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
805 if (vec_len (ls->locator_indices) == 0)
806 rmp->locator_set_index = ~0;
807 else
808 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
809
810 rmp->is_local = mapit->local;
811 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
812 rmp->action = mapit->action;
813 rmp->authoritative = mapit->authoritative;
814
815 switch (gid_address_type (gid))
816 {
817 case GID_ADDR_SRC_DST:
818 rmp->is_src_dst = 1;
819 fid = &gid_address_sd_src (gid);
820 rmp->eid_type = fid_type_to_api_type (fid);
821 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
822 &rmp->seid_prefix_len);
823 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
824 &rmp->eid_prefix_len);
825 break;
826 case GID_ADDR_IP_PREFIX:
827 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
828 if (ip_prefix_version (ip_prefix) == IP4)
829 {
830 rmp->eid_type = 0; /* ipv4 type */
831 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
832 sizeof (ip_prefix_v4 (ip_prefix)));
833 }
834 else
835 {
836 rmp->eid_type = 1; /* ipv6 type */
837 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
838 sizeof (ip_prefix_v6 (ip_prefix)));
839 }
840 break;
841 case GID_ADDR_MAC:
842 rmp->eid_type = 2; /* l2 mac type */
843 clib_memcpy (rmp->eid, mac, 6);
844 break;
845 default:
846 ASSERT (0);
847 }
848 rmp->context = context;
849 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
850 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
851 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
852 vl_msg_api_send_shmem (q, (u8 *) & rmp);
853}
854
855static void
856vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
857{
858 u32 mi;
859 unix_shared_memory_queue_t *q = NULL;
860 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
861 mapping_t *mapit = NULL;
862 gid_address_t _eid, *eid = &_eid;
863
864 q = vl_api_client_index_to_input_queue (mp->client_index);
865 if (q == 0)
866 {
867 return;
868 }
869
870 if (mp->eid_set)
871 {
872 memset (eid, 0, sizeof (*eid));
873
874 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
875 mp->eid_type, mp->eid, mp->prefix_length);
876
877 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
878 if ((u32) ~ 0 == mi)
879 return;
880
881 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
882 send_one_eid_table_details (mapit, q, mp->context,
883 0 /* ignore filter */ );
884 }
885 else
886 {
887 /* *INDENT-OFF* */
888 pool_foreach (mapit, lcm->mapping_pool,
889 ({
890 send_one_eid_table_details(mapit, q, mp->context,
891 mp->filter);
892 }));
893 /* *INDENT-ON* */
894 }
895}
896
897static void
898send_one_map_server_details (ip_address_t * ip,
899 unix_shared_memory_queue_t * q, u32 context)
900{
901 vl_api_one_map_server_details_t *rmp = NULL;
902
903 rmp = vl_msg_api_alloc (sizeof (*rmp));
904 memset (rmp, 0, sizeof (*rmp));
905 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
906
907 switch (ip_addr_version (ip))
908 {
909 case IP4:
910 rmp->is_ipv6 = 0;
911 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
912 sizeof (ip_addr_v4 (ip)));
913 break;
914
915 case IP6:
916 rmp->is_ipv6 = 1;
917 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
918 sizeof (ip_addr_v6 (ip)));
919 break;
920
921 default:
922 ASSERT (0);
923 }
924 rmp->context = context;
925
926 vl_msg_api_send_shmem (q, (u8 *) & rmp);
927}
928
929static void
930vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
931{
932 unix_shared_memory_queue_t *q = NULL;
933 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
934 lisp_msmr_t *mr;
935
936 q = vl_api_client_index_to_input_queue (mp->client_index);
937 if (q == 0)
938 {
939 return;
940 }
941
942 vec_foreach (mr, lcm->map_servers)
943 {
944 send_one_map_server_details (&mr->address, q, mp->context);
945 }
946}
947
948static void
949send_one_map_resolver_details (ip_address_t * ip,
950 unix_shared_memory_queue_t * q, u32 context)
951{
952 vl_api_one_map_resolver_details_t *rmp = NULL;
953
954 rmp = vl_msg_api_alloc (sizeof (*rmp));
955 memset (rmp, 0, sizeof (*rmp));
956 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
957
958 switch (ip_addr_version (ip))
959 {
960 case IP4:
961 rmp->is_ipv6 = 0;
962 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
963 sizeof (ip_addr_v4 (ip)));
964 break;
965
966 case IP6:
967 rmp->is_ipv6 = 1;
968 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
969 sizeof (ip_addr_v6 (ip)));
970 break;
971
972 default:
973 ASSERT (0);
974 }
975 rmp->context = context;
976
977 vl_msg_api_send_shmem (q, (u8 *) & rmp);
978}
979
980static void
981vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
982{
983 unix_shared_memory_queue_t *q = NULL;
984 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
985 lisp_msmr_t *mr;
986
987 q = vl_api_client_index_to_input_queue (mp->client_index);
988 if (q == 0)
989 {
990 return;
991 }
992
993 vec_foreach (mr, lcm->map_resolvers)
994 {
995 send_one_map_resolver_details (&mr->address, q, mp->context);
996 }
997}
998
999static void
1000send_eid_table_map_pair (hash_pair_t * p,
1001 unix_shared_memory_queue_t * q, u32 context)
1002{
1003 vl_api_one_eid_table_map_details_t *rmp = NULL;
1004
1005 rmp = vl_msg_api_alloc (sizeof (*rmp));
1006 memset (rmp, 0, sizeof (*rmp));
1007 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1008
1009 rmp->vni = clib_host_to_net_u32 (p->key);
1010 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1011 rmp->context = context;
1012 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1013}
1014
1015static void
1016vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1017{
1018 unix_shared_memory_queue_t *q = NULL;
1019 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1020 hash_pair_t *p;
1021 uword *vni_table = 0;
1022
1023 q = vl_api_client_index_to_input_queue (mp->client_index);
1024 if (q == 0)
1025 {
1026 return;
1027 }
1028
1029 if (mp->is_l2)
1030 {
1031 vni_table = lcm->bd_id_by_vni;
1032 }
1033 else
1034 {
1035 vni_table = lcm->table_id_by_vni;
1036 }
1037
1038 /* *INDENT-OFF* */
1039 hash_foreach_pair (p, vni_table,
1040 ({
1041 send_eid_table_map_pair (p, q, mp->context);
1042 }));
1043 /* *INDENT-ON* */
1044}
1045
1046static void
1047send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1048{
1049 vl_api_one_eid_table_vni_details_t *rmp = 0;
1050
1051 rmp = vl_msg_api_alloc (sizeof (*rmp));
1052 memset (rmp, 0, sizeof (*rmp));
1053 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1054 rmp->context = context;
1055 rmp->vni = clib_host_to_net_u32 (vni);
1056 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1057}
1058
1059static void
1060one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1061{
1062 lisp_adjacency_t *adj;
1063 vl_api_one_adjacency_t a;
1064 u32 i, n = vec_len (adjs);
1065
1066 for (i = 0; i < n; i++)
1067 {
1068 adj = vec_elt_at_index (adjs, i);
1069 memset (&a, 0, sizeof (a));
1070
1071 switch (gid_address_type (&adj->reid))
1072 {
1073 case GID_ADDR_IP_PREFIX:
1074 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1075 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1076 if (gid_address_ip_version (&adj->reid) == IP4)
1077 {
1078 a.eid_type = 0; /* ipv4 type */
1079 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1080 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1081 }
1082 else
1083 {
1084 a.eid_type = 1; /* ipv6 type */
1085 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1086 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1087 }
1088 break;
1089 case GID_ADDR_MAC:
1090 a.eid_type = 2; /* l2 mac type */
1091 mac_copy (a.reid, gid_address_mac (&adj->reid));
1092 mac_copy (a.leid, gid_address_mac (&adj->leid));
1093 break;
1094 default:
1095 ASSERT (0);
1096 }
1097 dst[i] = a;
1098 }
1099}
1100
1101static void
1102 vl_api_show_one_rloc_probe_state_t_handler
1103 (vl_api_show_one_rloc_probe_state_t * mp)
1104{
1105 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1106 int rv = 0;
1107
1108 /* *INDENT-OFF* */
1109 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1110 {
1111 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1112 });
1113 /* *INDENT-ON* */
1114}
1115
1116static void
1117 vl_api_show_one_map_register_state_t_handler
1118 (vl_api_show_one_map_register_state_t * mp)
1119{
1120 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1121 int rv = 0;
1122
1123 /* *INDENT-OFF* */
1124 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1125 {
1126 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1127 });
1128 /* *INDENT-ON* */
1129}
1130
1131static void
1132vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1133{
1134 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1135 lisp_adjacency_t *adjs = 0;
1136 int rv = 0;
1137 u32 size = ~0;
1138 u32 vni = clib_net_to_host_u32 (mp->vni);
1139
1140 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1141 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1142
1143 /* *INDENT-OFF* */
1144 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1145 {
1146 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1147 one_adjacency_copy (rmp->adjacencies, adjs);
1148 });
1149 /* *INDENT-ON* */
1150
1151 vec_free (adjs);
1152}
1153
1154static void
1155vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1156{
1157 hash_pair_t *p;
1158 u32 *vnis = 0;
1159 unix_shared_memory_queue_t *q = 0;
1160 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1161
1162 q = vl_api_client_index_to_input_queue (mp->client_index);
1163 if (q == 0)
1164 {
1165 return;
1166 }
1167
1168 /* *INDENT-OFF* */
1169 hash_foreach_pair (p, lcm->table_id_by_vni,
1170 ({
1171 hash_set (vnis, p->key, 0);
1172 }));
1173
1174 hash_foreach_pair (p, lcm->bd_id_by_vni,
1175 ({
1176 hash_set (vnis, p->key, 0);
1177 }));
1178
1179 hash_foreach_pair (p, vnis,
1180 ({
1181 send_eid_table_vni (p->key, q, mp->context);
1182 }));
1183 /* *INDENT-ON* */
1184
1185 hash_free (vnis);
1186}
1187
1188static void
1189vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1190{
1191 unix_shared_memory_queue_t *q = NULL;
1192 vl_api_show_one_status_reply_t *rmp = NULL;
1193 int rv = 0;
1194
1195 q = vl_api_client_index_to_input_queue (mp->client_index);
1196 if (q == 0)
1197 {
1198 return;
1199 }
1200
1201 /* *INDENT-OFF* */
1202 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1203 ({
1204 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1205 rmp->feature_status = vnet_lisp_enable_disable_status ();
1206 }));
1207 /* *INDENT-ON* */
1208}
1209
1210static void
1211 vl_api_one_get_map_request_itr_rlocs_t_handler
1212 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1213{
1214 unix_shared_memory_queue_t *q = NULL;
1215 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1216 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1217 locator_set_t *loc_set = 0;
1218 u8 *tmp_str = 0;
1219 int rv = 0;
1220
1221 q = vl_api_client_index_to_input_queue (mp->client_index);
1222 if (q == 0)
1223 {
1224 return;
1225 }
1226
1227 if (~0 == lcm->mreq_itr_rlocs)
1228 {
1229 tmp_str = format (0, " ");
1230 }
1231 else
1232 {
1233 loc_set =
1234 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1235 tmp_str = format (0, "%s", loc_set->name);
1236 }
1237
1238 /* *INDENT-OFF* */
1239 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1240 ({
1241 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1242 ARRAY_LEN(rmp->locator_set_name) - 1);
1243 }));
1244 /* *INDENT-ON* */
1245
1246 vec_free (tmp_str);
1247}
1248
1249static void
1250vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1251{
1252 unix_shared_memory_queue_t *q = NULL;
1253 vl_api_show_one_pitr_reply_t *rmp = NULL;
1254 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1255 mapping_t *m;
1256 locator_set_t *ls = 0;
1257 u8 *tmp_str = 0;
1258 int rv = 0;
1259
1260 q = vl_api_client_index_to_input_queue (mp->client_index);
1261 if (q == 0)
1262 {
1263 return;
1264 }
1265
1266 if (!lcm->lisp_pitr)
1267 {
1268 tmp_str = format (0, "N/A");
1269 }
1270 else
1271 {
1272 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1273 if (~0 != m->locator_set_index)
1274 {
1275 ls =
1276 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1277 tmp_str = format (0, "%s", ls->name);
1278 }
1279 else
1280 {
1281 tmp_str = format (0, "N/A");
1282 }
1283 }
1284 vec_add1 (tmp_str, 0);
1285
1286 /* *INDENT-OFF* */
1287 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1288 ({
1289 rmp->status = lcm->lisp_pitr;
1290 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1291 ARRAY_LEN(rmp->locator_set_name) - 1);
1292 }));
1293 /* *INDENT-ON* */
1294}
1295
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001296static void
1297 vl_api_show_one_stats_enable_disable_t_handler
1298 (vl_api_show_one_stats_enable_disable_t * mp)
1299{
1300 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1301 vnet_api_error_t rv = 0;
1302
1303 /* *INDENT-OFF* */
1304 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1305 ({
1306 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1307 }));
1308 /* *INDENT-ON* */
1309}
1310
1311static void
1312 vl_api_one_stats_enable_disable_t_handler
1313 (vl_api_one_stats_enable_disable_t * mp)
1314{
1315 vl_api_one_enable_disable_reply_t *rmp = NULL;
1316
1317 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1318 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1319}
1320
1321static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01001322lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1323 u8 * prefix_length)
1324{
1325 switch (fid_addr_type (fid))
1326 {
1327 case FID_ADDR_IP_PREF:
1328 *prefix_length = fid_addr_prefix_length (fid);
1329 if (fid_addr_ip_version (fid) == IP4)
1330 {
1331 *api_eid_type = 0; /* ipv4 type */
1332 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1333 }
1334 else
1335 {
1336 *api_eid_type = 1; /* ipv6 type */
1337 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1338 }
1339 break;
1340 case FID_ADDR_MAC:
1341 *api_eid_type = 2; /* l2 mac type */
1342 mac_copy (dst, fid_addr_mac (fid));
1343 break;
1344 default:
1345 ASSERT (0);
1346 }
1347}
1348
1349static void
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001350vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1351{
Filip Tehlar4868ff62017-03-09 16:48:39 +01001352 vl_api_one_stats_details_t *rmp;
1353 lisp_api_stats_t *stats, *stat;
1354 u8 rv = 0;
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001355
Filip Tehlar4868ff62017-03-09 16:48:39 +01001356 stats = vnet_lisp_get_stats ();
1357 vec_foreach (stat, stats)
1358 {
1359 /* *INDENT-OFF* */
1360 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1361 ({
1362 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1363 &rmp->deid_pref_len);
1364 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1365 &rmp->seid_pref_len);
1366 rmp->vni = clib_host_to_net_u32 (stat->vni);
1367
1368 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1369 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1370 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1371
1372 rmp->pkt_count = clib_host_to_net_u32 (stat->stats.pkt_count);
1373 rmp->bytes = clib_host_to_net_u32 (stat->stats.bytes);
1374 }));
1375 /* *INDENT-ON* */
1376 }
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001377}
1378
Filip Tehlar694396d2017-02-17 14:29:11 +01001379/*
1380 * one_api_hookup
1381 * Add vpe's API message handlers to the table.
1382 * vlib has alread mapped shared memory and
1383 * added the client registration handlers.
1384 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1385 */
1386#define vl_msg_name_crc_list
1387#include <vnet/vnet_all_api_h.h>
1388#undef vl_msg_name_crc_list
1389
1390static void
1391setup_message_id_table (api_main_t * am)
1392{
1393#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
Filip Tehlar974cdc62017-02-22 18:09:49 +01001394 foreach_vl_msg_name_crc_one;
Filip Tehlar694396d2017-02-17 14:29:11 +01001395#undef _
1396}
1397
1398static clib_error_t *
1399one_api_hookup (vlib_main_t * vm)
1400{
1401 api_main_t *am = &api_main;
1402
1403#define _(N,n) \
1404 vl_msg_api_set_handlers(VL_API_##N, #n, \
1405 vl_api_##n##_t_handler, \
1406 vl_noop_handler, \
1407 vl_api_##n##_t_endian, \
1408 vl_api_##n##_t_print, \
1409 sizeof(vl_api_##n##_t), 1);
1410 foreach_vpe_api_msg;
1411#undef _
1412
1413 /*
1414 * Set up the (msg_name, crc, message-id) table
1415 */
1416 setup_message_id_table (am);
1417
1418 return 0;
1419}
1420
1421VLIB_API_INIT_FUNCTION (one_api_hookup);
1422
1423/*
1424 * fd.io coding-style-patch-verification: ON
1425 *
1426 * Local Variables:
1427 * eval: (c-set-style "gnu")
1428 * End:
1429 */