2 *------------------------------------------------------------------
3 * Copyright (c) 2018 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
21 #include <vnet/interface.h>
22 #include <vnet/api_errno.h>
23 #include <vnet/ip/ip_types_api.h>
24 #include <vnet/ethernet/ethernet_types_api.h>
25 #include <vpp/app/version.h>
28 #include <gbp/gbp_learn.h>
29 #include <gbp/gbp_itf.h>
30 #include <gbp/gbp_vxlan.h>
31 #include <gbp/gbp_bridge_domain.h>
32 #include <gbp/gbp_route_domain.h>
34 #include <vlibapi/api.h>
35 #include <vlibmemory/api.h>
37 /* define message IDs */
38 #include <gbp/gbp_msg_enum.h>
40 #define vl_typedefs /* define message structures */
41 #include <gbp/gbp_all_api_h.h>
44 #define vl_endianfun /* define message structures */
45 #include <gbp/gbp_all_api_h.h>
48 /* instantiate all the print functions we know about */
49 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
51 #include <gbp/gbp_all_api_h.h>
54 /* Get the API version number */
55 #define vl_api_version(n,v) static u32 api_version=(v);
56 #include <gbp/gbp_all_api_h.h>
59 #include <vlibapi/api_helper_macros.h>
61 #define foreach_gbp_api_msg \
62 _(GBP_ENDPOINT_ADD, gbp_endpoint_add) \
63 _(GBP_ENDPOINT_DEL, gbp_endpoint_del) \
64 _(GBP_ENDPOINT_DUMP, gbp_endpoint_dump) \
65 _(GBP_SUBNET_ADD_DEL, gbp_subnet_add_del) \
66 _(GBP_SUBNET_DUMP, gbp_subnet_dump) \
67 _(GBP_ENDPOINT_GROUP_ADD, gbp_endpoint_group_add) \
68 _(GBP_ENDPOINT_GROUP_DEL, gbp_endpoint_group_del) \
69 _(GBP_ENDPOINT_GROUP_DUMP, gbp_endpoint_group_dump) \
70 _(GBP_BRIDGE_DOMAIN_ADD, gbp_bridge_domain_add) \
71 _(GBP_BRIDGE_DOMAIN_DEL, gbp_bridge_domain_del) \
72 _(GBP_BRIDGE_DOMAIN_DUMP, gbp_bridge_domain_dump) \
73 _(GBP_ROUTE_DOMAIN_ADD, gbp_route_domain_add) \
74 _(GBP_ROUTE_DOMAIN_DEL, gbp_route_domain_del) \
75 _(GBP_ROUTE_DOMAIN_DUMP, gbp_route_domain_dump) \
76 _(GBP_RECIRC_ADD_DEL, gbp_recirc_add_del) \
77 _(GBP_RECIRC_DUMP, gbp_recirc_dump) \
78 _(GBP_CONTRACT_ADD_DEL, gbp_contract_add_del) \
79 _(GBP_CONTRACT_DUMP, gbp_contract_dump) \
80 _(GBP_ENDPOINT_LEARN_SET_INACTIVE_THRESHOLD, gbp_endpoint_learn_set_inactive_threshold) \
81 _(GBP_VXLAN_TUNNEL_ADD, gbp_vxlan_tunnel_add) \
82 _(GBP_VXLAN_TUNNEL_DEL, gbp_vxlan_tunnel_del) \
83 _(GBP_VXLAN_TUNNEL_DUMP, gbp_vxlan_tunnel_dump)
87 static u16 msg_id_base;
89 #define GBP_MSG_BASE msg_id_base
91 static gbp_endpoint_flags_t
92 gbp_endpoint_flags_decode (vl_api_gbp_endpoint_flags_t v)
94 gbp_endpoint_flags_t f = GBP_ENDPOINT_FLAG_NONE;
99 f |= GBP_ENDPOINT_FLAG_BOUNCE;
101 f |= GBP_ENDPOINT_FLAG_REMOTE;
103 f |= GBP_ENDPOINT_FLAG_LEARNT;
108 static vl_api_gbp_endpoint_flags_t
109 gbp_endpoint_flags_encode (gbp_endpoint_flags_t f)
111 vl_api_gbp_endpoint_flags_t v = 0;
114 if (f & GBP_ENDPOINT_FLAG_BOUNCE)
116 if (f & GBP_ENDPOINT_FLAG_REMOTE)
118 if (f & GBP_ENDPOINT_FLAG_LEARNT)
127 vl_api_gbp_endpoint_add_t_handler (vl_api_gbp_endpoint_add_t * mp)
129 vl_api_gbp_endpoint_add_reply_t *rmp;
130 gbp_endpoint_flags_t gef;
131 u32 sw_if_index, handle;
136 VALIDATE_SW_IF_INDEX (&(mp->endpoint));
138 gef = gbp_endpoint_flags_decode (mp->endpoint.flags), ips = NULL;
139 sw_if_index = ntohl (mp->endpoint.sw_if_index);
141 if (mp->endpoint.n_ips)
143 vec_validate (ips, mp->endpoint.n_ips - 1);
145 vec_foreach_index (ii, ips)
147 ip_address_decode (&mp->endpoint.ips[ii], &ips[ii]);
150 mac_address_decode (&mp->endpoint.mac, &mac);
152 if (GBP_ENDPOINT_FLAG_REMOTE & gef)
154 ip46_address_t tun_src, tun_dst;
156 ip_address_decode (&mp->endpoint.tun.src, &tun_src);
157 ip_address_decode (&mp->endpoint.tun.dst, &tun_dst);
159 rv = gbp_endpoint_update (sw_if_index, ips, &mac,
160 ntohs (mp->endpoint.epg_id),
161 gef, &tun_src, &tun_dst, &handle);
165 rv = gbp_endpoint_update (sw_if_index, ips, &mac,
166 ntohs (mp->endpoint.epg_id),
167 gef, NULL, NULL, &handle);
169 BAD_SW_IF_INDEX_LABEL;
172 REPLY_MACRO2 (VL_API_GBP_ENDPOINT_ADD_REPLY + GBP_MSG_BASE,
174 rmp->handle = htonl (handle);
180 vl_api_gbp_endpoint_del_t_handler (vl_api_gbp_endpoint_del_t * mp)
182 vl_api_gbp_endpoint_del_reply_t *rmp;
185 gbp_endpoint_delete (ntohl (mp->handle));
187 REPLY_MACRO (VL_API_GBP_ENDPOINT_DEL_REPLY + GBP_MSG_BASE);
191 vl_api_gbp_endpoint_learn_set_inactive_threshold_t_handler
192 (vl_api_gbp_endpoint_learn_set_inactive_threshold_t * mp)
194 vl_api_gbp_endpoint_learn_set_inactive_threshold_reply_t *rmp;
197 gbp_learn_set_inactive_threshold (ntohl (mp->threshold));
199 REPLY_MACRO (VL_API_GBP_ENDPOINT_LEARN_SET_INACTIVE_THRESHOLD_REPLY +
203 typedef struct gbp_walk_ctx_t_
205 vl_api_registration_t *reg;
210 gbp_endpoint_send_details (index_t gei, void *args)
212 vl_api_gbp_endpoint_details_t *mp;
218 ge = gbp_endpoint_get (gei);
220 n_ips = vec_len (ge->ge_ips);
221 mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (*mp->endpoint.ips) * n_ips));
225 clib_memset (mp, 0, sizeof (*mp));
226 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_DETAILS + GBP_MSG_BASE);
227 mp->context = ctx->context;
229 if (gbp_endpoint_is_remote (ge))
231 mp->endpoint.sw_if_index = ntohl (ge->tun.ge_parent_sw_if_index);
232 ip_address_encode (&ge->tun.ge_src, IP46_TYPE_ANY,
233 &mp->endpoint.tun.src);
234 ip_address_encode (&ge->tun.ge_dst, IP46_TYPE_ANY,
235 &mp->endpoint.tun.dst);
239 mp->endpoint.sw_if_index = ntohl (ge->ge_sw_if_index);
241 mp->endpoint.epg_id = ntohs (ge->ge_epg_id);
242 mp->endpoint.n_ips = n_ips;
243 mp->endpoint.flags = gbp_endpoint_flags_encode (ge->ge_flags);
244 mp->handle = htonl (gei);
245 mp->age = vlib_time_now (vlib_get_main ()) - ge->ge_last_time;
246 mac_address_encode (&ge->ge_mac, &mp->endpoint.mac);
248 vec_foreach_index (ii, ge->ge_ips)
250 ip_address_encode (&ge->ge_ips[ii], IP46_TYPE_ANY, &mp->endpoint.ips[ii]);
253 vl_api_send_msg (ctx->reg, (u8 *) mp);
255 return (WALK_CONTINUE);
259 vl_api_gbp_endpoint_dump_t_handler (vl_api_gbp_endpoint_dump_t * mp)
261 vl_api_registration_t *reg;
263 reg = vl_api_client_index_to_registration (mp->client_index);
267 gbp_walk_ctx_t ctx = {
269 .context = mp->context,
272 gbp_endpoint_walk (gbp_endpoint_send_details, &ctx);
276 vl_api_gbp_endpoint_group_add_t_handler
277 (vl_api_gbp_endpoint_group_add_t * mp)
279 vl_api_gbp_endpoint_group_add_reply_t *rmp;
282 rv = gbp_endpoint_group_add_and_lock (ntohs (mp->epg.epg_id),
283 ntohl (mp->epg.bd_id),
284 ntohl (mp->epg.rd_id),
285 ntohl (mp->epg.uplink_sw_if_index));
287 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_ADD_REPLY + GBP_MSG_BASE);
291 vl_api_gbp_endpoint_group_del_t_handler
292 (vl_api_gbp_endpoint_group_del_t * mp)
294 vl_api_gbp_endpoint_group_del_reply_t *rmp;
297 rv = gbp_endpoint_group_delete (ntohs (mp->epg_id));
299 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_DEL_REPLY + GBP_MSG_BASE);
303 vl_api_gbp_bridge_domain_add_t_handler (vl_api_gbp_bridge_domain_add_t * mp)
305 vl_api_gbp_bridge_domain_add_reply_t *rmp;
308 rv = gbp_bridge_domain_add_and_lock (ntohl (mp->bd.bd_id),
309 ntohl (mp->bd.bvi_sw_if_index),
310 ntohl (mp->bd.uu_fwd_sw_if_index));
312 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
316 vl_api_gbp_bridge_domain_del_t_handler (vl_api_gbp_bridge_domain_del_t * mp)
318 vl_api_gbp_bridge_domain_del_reply_t *rmp;
321 rv = gbp_bridge_domain_delete (ntohl (mp->bd_id));
323 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
327 vl_api_gbp_route_domain_add_t_handler (vl_api_gbp_route_domain_add_t * mp)
329 vl_api_gbp_route_domain_add_reply_t *rmp;
332 rv = gbp_route_domain_add_and_lock (ntohl (mp->rd.rd_id),
333 ntohl (mp->rd.ip4_table_id),
334 ntohl (mp->rd.ip6_table_id),
335 ntohl (mp->rd.ip4_uu_sw_if_index),
336 ntohl (mp->rd.ip6_uu_sw_if_index));
338 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
342 vl_api_gbp_route_domain_del_t_handler (vl_api_gbp_route_domain_del_t * mp)
344 vl_api_gbp_route_domain_del_reply_t *rmp;
347 rv = gbp_route_domain_delete (ntohl (mp->rd_id));
349 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
353 gub_subnet_type_from_api (vl_api_gbp_subnet_type_t a, gbp_subnet_type_t * t)
355 a = clib_net_to_host_u32 (a);
359 case GBP_API_SUBNET_TRANSPORT:
360 *t = GBP_SUBNET_TRANSPORT;
362 case GBP_API_SUBNET_STITCHED_INTERNAL:
363 *t = GBP_SUBNET_STITCHED_INTERNAL;
365 case GBP_API_SUBNET_STITCHED_EXTERNAL:
366 *t = GBP_SUBNET_STITCHED_EXTERNAL;
374 vl_api_gbp_subnet_add_del_t_handler (vl_api_gbp_subnet_add_del_t * mp)
376 vl_api_gbp_subnet_add_del_reply_t *rmp;
377 gbp_subnet_type_t type;
381 ip_prefix_decode (&mp->subnet.prefix, &pfx);
383 rv = gub_subnet_type_from_api (mp->subnet.type, &type);
389 rv = gbp_subnet_add (ntohl (mp->subnet.rd_id),
391 ntohl (mp->subnet.sw_if_index),
392 ntohs (mp->subnet.epg_id));
394 rv = gbp_subnet_del (ntohl (mp->subnet.rd_id), &pfx);
397 REPLY_MACRO (VL_API_GBP_SUBNET_ADD_DEL_REPLY + GBP_MSG_BASE);
400 static vl_api_gbp_subnet_type_t
401 gub_subnet_type_to_api (gbp_subnet_type_t t)
403 vl_api_gbp_subnet_type_t a = 0;
407 case GBP_SUBNET_TRANSPORT:
408 a = GBP_API_SUBNET_TRANSPORT;
410 case GBP_SUBNET_STITCHED_INTERNAL:
411 a = GBP_API_SUBNET_STITCHED_INTERNAL;
413 case GBP_SUBNET_STITCHED_EXTERNAL:
414 a = GBP_API_SUBNET_STITCHED_EXTERNAL;
418 a = clib_host_to_net_u32 (a);
424 gbp_subnet_send_details (u32 rd_id,
425 const fib_prefix_t * pfx,
426 gbp_subnet_type_t type,
427 u32 sw_if_index, epg_id_t epg, void *args)
429 vl_api_gbp_subnet_details_t *mp;
433 mp = vl_msg_api_alloc (sizeof (*mp));
437 clib_memset (mp, 0, sizeof (*mp));
438 mp->_vl_msg_id = ntohs (VL_API_GBP_SUBNET_DETAILS + GBP_MSG_BASE);
439 mp->context = ctx->context;
441 mp->subnet.type = gub_subnet_type_to_api (type);
442 mp->subnet.sw_if_index = ntohl (sw_if_index);
443 mp->subnet.epg_id = ntohs (epg);
444 mp->subnet.rd_id = ntohl (rd_id);
445 ip_prefix_encode (pfx, &mp->subnet.prefix);
447 vl_api_send_msg (ctx->reg, (u8 *) mp);
449 return (WALK_CONTINUE);
453 vl_api_gbp_subnet_dump_t_handler (vl_api_gbp_subnet_dump_t * mp)
455 vl_api_registration_t *reg;
457 reg = vl_api_client_index_to_registration (mp->client_index);
461 gbp_walk_ctx_t ctx = {
463 .context = mp->context,
466 gbp_subnet_walk (gbp_subnet_send_details, &ctx);
470 gbp_endpoint_group_send_details (gbp_endpoint_group_t * gg, void *args)
472 vl_api_gbp_endpoint_group_details_t *mp;
476 mp = vl_msg_api_alloc (sizeof (*mp));
480 clib_memset (mp, 0, sizeof (*mp));
481 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_GROUP_DETAILS + GBP_MSG_BASE);
482 mp->context = ctx->context;
484 mp->epg.uplink_sw_if_index = ntohl (gg->gg_uplink_sw_if_index);
485 mp->epg.epg_id = ntohs (gg->gg_id);
486 mp->epg.bd_id = ntohl (gbp_endpoint_group_get_bd_id (gg));
487 mp->epg.rd_id = ntohl (gg->gg_rd);
489 vl_api_send_msg (ctx->reg, (u8 *) mp);
495 vl_api_gbp_endpoint_group_dump_t_handler (vl_api_gbp_endpoint_group_dump_t *
498 vl_api_registration_t *reg;
500 reg = vl_api_client_index_to_registration (mp->client_index);
504 gbp_walk_ctx_t ctx = {
506 .context = mp->context,
509 gbp_endpoint_group_walk (gbp_endpoint_group_send_details, &ctx);
513 gbp_bridge_domain_send_details (gbp_bridge_domain_t * gb, void *args)
515 vl_api_gbp_bridge_domain_details_t *mp;
519 mp = vl_msg_api_alloc (sizeof (*mp));
523 memset (mp, 0, sizeof (*mp));
524 mp->_vl_msg_id = ntohs (VL_API_GBP_BRIDGE_DOMAIN_DETAILS + GBP_MSG_BASE);
525 mp->context = ctx->context;
527 mp->bd.bd_id = ntohl (gb->gb_bd_id);
528 mp->bd.bvi_sw_if_index = ntohl (gb->gb_bvi_sw_if_index);
529 mp->bd.uu_fwd_sw_if_index = ntohl (gb->gb_uu_fwd_sw_if_index);
531 vl_api_send_msg (ctx->reg, (u8 *) mp);
537 vl_api_gbp_bridge_domain_dump_t_handler (vl_api_gbp_bridge_domain_dump_t * mp)
539 vl_api_registration_t *reg;
541 reg = vl_api_client_index_to_registration (mp->client_index);
545 gbp_walk_ctx_t ctx = {
547 .context = mp->context,
550 gbp_bridge_domain_walk (gbp_bridge_domain_send_details, &ctx);
554 gbp_route_domain_send_details (gbp_route_domain_t * grd, void *args)
556 vl_api_gbp_route_domain_details_t *mp;
560 mp = vl_msg_api_alloc (sizeof (*mp));
564 memset (mp, 0, sizeof (*mp));
565 mp->_vl_msg_id = ntohs (VL_API_GBP_ROUTE_DOMAIN_DETAILS + GBP_MSG_BASE);
566 mp->context = ctx->context;
568 mp->rd.rd_id = ntohl (grd->grd_id);
569 mp->rd.ip4_uu_sw_if_index =
570 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP4]);
571 mp->rd.ip6_uu_sw_if_index =
572 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP6]);
574 vl_api_send_msg (ctx->reg, (u8 *) mp);
580 vl_api_gbp_route_domain_dump_t_handler (vl_api_gbp_route_domain_dump_t * mp)
582 vl_api_registration_t *reg;
584 reg = vl_api_client_index_to_registration (mp->client_index);
588 gbp_walk_ctx_t ctx = {
590 .context = mp->context,
593 gbp_route_domain_walk (gbp_route_domain_send_details, &ctx);
597 vl_api_gbp_recirc_add_del_t_handler (vl_api_gbp_recirc_add_del_t * mp)
599 vl_api_gbp_recirc_add_del_reply_t *rmp;
603 sw_if_index = ntohl (mp->recirc.sw_if_index);
604 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
605 goto bad_sw_if_index;
608 gbp_recirc_add (sw_if_index,
609 ntohs (mp->recirc.epg_id), mp->recirc.is_ext);
611 gbp_recirc_delete (sw_if_index);
613 BAD_SW_IF_INDEX_LABEL;
615 REPLY_MACRO (VL_API_GBP_RECIRC_ADD_DEL_REPLY + GBP_MSG_BASE);
619 gbp_recirc_send_details (gbp_recirc_t * gr, void *args)
621 vl_api_gbp_recirc_details_t *mp;
625 mp = vl_msg_api_alloc (sizeof (*mp));
629 clib_memset (mp, 0, sizeof (*mp));
630 mp->_vl_msg_id = ntohs (VL_API_GBP_RECIRC_DETAILS + GBP_MSG_BASE);
631 mp->context = ctx->context;
633 mp->recirc.epg_id = ntohs (gr->gr_epg);
634 mp->recirc.sw_if_index = ntohl (gr->gr_sw_if_index);
635 mp->recirc.is_ext = ntohl (gr->gr_is_ext);
637 vl_api_send_msg (ctx->reg, (u8 *) mp);
643 vl_api_gbp_recirc_dump_t_handler (vl_api_gbp_recirc_dump_t * mp)
645 vl_api_registration_t *reg;
647 reg = vl_api_client_index_to_registration (mp->client_index);
651 gbp_walk_ctx_t ctx = {
653 .context = mp->context,
656 gbp_recirc_walk (gbp_recirc_send_details, &ctx);
660 vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp)
662 vl_api_gbp_contract_add_del_reply_t *rmp;
666 gbp_contract_update (ntohs (mp->contract.src_epg),
667 ntohs (mp->contract.dst_epg),
668 ntohl (mp->contract.acl_index));
670 gbp_contract_delete (ntohs (mp->contract.src_epg),
671 ntohs (mp->contract.dst_epg));
673 REPLY_MACRO (VL_API_GBP_CONTRACT_ADD_DEL_REPLY + GBP_MSG_BASE);
677 gbp_contract_send_details (gbp_contract_t * gbpc, void *args)
679 vl_api_gbp_contract_details_t *mp;
683 mp = vl_msg_api_alloc (sizeof (*mp));
687 clib_memset (mp, 0, sizeof (*mp));
688 mp->_vl_msg_id = ntohs (VL_API_GBP_CONTRACT_DETAILS + GBP_MSG_BASE);
689 mp->context = ctx->context;
691 mp->contract.src_epg = ntohs (gbpc->gc_key.gck_src);
692 mp->contract.dst_epg = ntohs (gbpc->gc_key.gck_dst);
693 mp->contract.acl_index = ntohl (gbpc->gc_value.gc_acl_index);
695 vl_api_send_msg (ctx->reg, (u8 *) mp);
701 vl_api_gbp_contract_dump_t_handler (vl_api_gbp_contract_dump_t * mp)
703 vl_api_registration_t *reg;
705 reg = vl_api_client_index_to_registration (mp->client_index);
709 gbp_walk_ctx_t ctx = {
711 .context = mp->context,
714 gbp_contract_walk (gbp_contract_send_details, &ctx);
718 gbp_vxlan_tunnel_mode_2_layer (vl_api_gbp_vxlan_tunnel_mode_t mode,
719 gbp_vxlan_tunnel_layer_t * l)
721 mode = clib_net_to_host_u32 (mode);
725 case GBP_VXLAN_TUNNEL_MODE_L2:
726 *l = GBP_VXLAN_TUN_L2;
728 case GBP_VXLAN_TUNNEL_MODE_L3:
729 *l = GBP_VXLAN_TUN_L3;
736 vl_api_gbp_vxlan_tunnel_add_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
738 vl_api_gbp_vxlan_tunnel_add_reply_t *rmp;
739 gbp_vxlan_tunnel_layer_t layer;
743 rv = gbp_vxlan_tunnel_mode_2_layer (mp->tunnel.mode, &layer);
748 rv = gbp_vxlan_tunnel_add (ntohl (mp->tunnel.vni),
750 ntohl (mp->tunnel.bd_rd_id), &sw_if_index);
754 REPLY_MACRO2 (VL_API_GBP_VXLAN_TUNNEL_ADD_REPLY + GBP_MSG_BASE,
756 rmp->sw_if_index = htonl (sw_if_index);
762 vl_api_gbp_vxlan_tunnel_del_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
764 vl_api_gbp_vxlan_tunnel_del_reply_t *rmp;
767 rv = gbp_vxlan_tunnel_del (ntohl (mp->tunnel.vni));
769 REPLY_MACRO (VL_API_GBP_VXLAN_TUNNEL_DEL_REPLY + GBP_MSG_BASE);
772 static vl_api_gbp_vxlan_tunnel_mode_t
773 gbp_vxlan_tunnel_layer_2_mode (gbp_vxlan_tunnel_layer_t layer)
775 vl_api_gbp_vxlan_tunnel_mode_t mode = GBP_VXLAN_TUNNEL_MODE_L2;
779 case GBP_VXLAN_TUN_L2:
780 mode = GBP_VXLAN_TUNNEL_MODE_L2;
782 case GBP_VXLAN_TUN_L3:
783 mode = GBP_VXLAN_TUNNEL_MODE_L3;
786 mode = clib_host_to_net_u32 (mode);
792 gbp_vxlan_tunnel_send_details (gbp_vxlan_tunnel_t * gt, void *args)
794 vl_api_gbp_vxlan_tunnel_details_t *mp;
798 mp = vl_msg_api_alloc (sizeof (*mp));
802 memset (mp, 0, sizeof (*mp));
803 mp->_vl_msg_id = htons (VL_API_GBP_VXLAN_TUNNEL_DETAILS + GBP_MSG_BASE);
804 mp->context = ctx->context;
806 mp->tunnel.vni = htonl (gt->gt_vni);
807 mp->tunnel.mode = gbp_vxlan_tunnel_layer_2_mode (gt->gt_layer);
808 mp->tunnel.bd_rd_id = htonl (gt->gt_bd_rd_id);
810 vl_api_send_msg (ctx->reg, (u8 *) mp);
816 vl_api_gbp_vxlan_tunnel_dump_t_handler (vl_api_gbp_vxlan_tunnel_dump_t * mp)
818 vl_api_registration_t *reg;
820 reg = vl_api_client_index_to_registration (mp->client_index);
824 gbp_walk_ctx_t ctx = {
826 .context = mp->context,
829 gbp_vxlan_walk (gbp_vxlan_tunnel_send_details, &ctx);
834 * Add vpe's API message handlers to the table.
835 * vlib has already mapped shared memory and
836 * added the client registration handlers.
837 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
839 #define vl_msg_name_crc_list
840 #include <gbp/gbp_all_api_h.h>
841 #undef vl_msg_name_crc_list
844 setup_message_id_table (api_main_t * am)
846 #define _(id,n,crc) \
847 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + GBP_MSG_BASE);
848 foreach_vl_msg_name_crc_gbp;
853 gbp_api_hookup (vlib_main_t * vm)
856 vl_msg_api_set_handlers(VL_API_##N + GBP_MSG_BASE, \
858 vl_api_##n##_t_handler, \
860 vl_api_##n##_t_endian, \
861 vl_api_##n##_t_print, \
862 sizeof(vl_api_##n##_t), 1);
867 static clib_error_t *
868 gbp_init (vlib_main_t * vm)
870 api_main_t *am = &api_main;
871 gbp_main_t *gbpm = &gbp_main;
872 u8 *name = format (0, "gbp_%08x%c", api_version, 0);
874 gbpm->gbp_acl_user_id = ~0;
876 /* Ask for a correctly-sized block of API message decode slots */
877 msg_id_base = vl_msg_api_get_msg_ids ((char *) name,
878 VL_MSG_FIRST_AVAILABLE);
881 /* Add our API messages to the global name_crc hash table */
882 setup_message_id_table (am);
888 VLIB_API_INIT_FUNCTION (gbp_init);
891 VLIB_PLUGIN_REGISTER () = {
892 .version = VPP_BUILD_VER,
893 .description = "Group Based Policy",
899 * fd.io coding-style-patch-verification: ON
902 * eval: (c-set-style "gnu")