2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
21 #include <vnet/fib/fib_api.h>
22 #include <vnet/ip/ip_types_api.h>
24 #include <vpp/app/version.h>
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
29 /* define message IDs */
30 #include <vnet/format_fns.h>
31 #include <svs/svs.api_enum.h>
32 #include <svs/svs.api_types.h>
35 * Base message ID fot the plugin
37 static u32 svs_base_msg_id;
38 #include <vlibapi/api_helper_macros.h>
41 vl_api_svs_plugin_get_version_t_handler (vl_api_svs_plugin_get_version_t * mp)
43 vl_api_svs_plugin_get_version_reply_t *rmp;
44 int msg_size = sizeof (*rmp);
45 vl_api_registration_t *rp;
47 rp = vl_api_client_index_to_registration (mp->client_index);
51 rmp = vl_msg_api_alloc (msg_size);
52 clib_memset (rmp, 0, msg_size);
54 ntohs (VL_API_SVS_PLUGIN_GET_VERSION_REPLY + svs_base_msg_id);
55 rmp->context = mp->context;
56 rmp->major = htonl (SVS_PLUGIN_VERSION_MAJOR);
57 rmp->minor = htonl (SVS_PLUGIN_VERSION_MINOR);
59 vl_api_send_msg (rp, (u8 *) rmp);
63 vl_api_svs_table_add_del_t_handler (vl_api_svs_table_add_del_t * mp)
65 vl_api_svs_table_add_del_reply_t *rmp;
66 fib_protocol_t fproto;
69 fproto = fib_proto_from_api_address_family (mp->af);
73 rv = svs_table_add (fproto, ntohl (mp->table_id));
77 rv = svs_table_delete (fproto, ntohl (mp->table_id));
80 REPLY_MACRO (VL_API_SVS_TABLE_ADD_DEL_REPLY + svs_base_msg_id);
84 vl_api_svs_route_add_del_t_handler (vl_api_svs_route_add_del_t * mp)
86 vl_api_svs_route_add_del_reply_t *rmp;
90 ip_prefix_decode (&mp->prefix, &pfx);
94 rv = svs_route_add (ntohl (mp->table_id), &pfx,
95 ntohl (mp->source_table_id));
99 rv = svs_route_delete (ntohl (mp->table_id), &pfx);
102 REPLY_MACRO (VL_API_SVS_ROUTE_ADD_DEL_REPLY + svs_base_msg_id);
106 vl_api_svs_enable_disable_t_handler (vl_api_svs_enable_disable_t * mp)
108 vl_api_svs_enable_disable_reply_t *rmp;
109 fib_protocol_t fproto;
112 VALIDATE_SW_IF_INDEX (mp);
114 fproto = fib_proto_from_api_address_family (mp->af);
118 rv = svs_enable (fproto, ntohl (mp->table_id), ntohl (mp->sw_if_index));
123 svs_disable (fproto, ntohl (mp->table_id), ntohl (mp->sw_if_index));
126 BAD_SW_IF_INDEX_LABEL;
127 REPLY_MACRO (VL_API_SVS_ENABLE_DISABLE_REPLY + svs_base_msg_id);
130 typedef struct svs_dump_walk_ctx_t_
132 vl_api_registration_t *rp;
134 } svs_dump_walk_ctx_t;
138 svs_send_details (fib_protocol_t fproto,
139 u32 table_id, u32 sw_if_index, void *args)
141 vl_api_svs_details_t *mp;
142 svs_dump_walk_ctx_t *ctx;
146 mp = vl_msg_api_alloc (sizeof (*mp));
147 mp->_vl_msg_id = ntohs (VL_API_SVS_DETAILS + svs_base_msg_id);
149 mp->context = ctx->context;
150 mp->sw_if_index = htonl (sw_if_index);
151 mp->table_id = htonl (table_id);
152 mp->af = fib_proto_to_api_address_family (fproto);
154 vl_api_send_msg (ctx->rp, (u8 *) mp);
156 return (WALK_CONTINUE);
160 vl_api_svs_dump_t_handler (vl_api_svs_dump_t * mp)
162 vl_api_registration_t *rp;
164 rp = vl_api_client_index_to_registration (mp->client_index);
168 svs_dump_walk_ctx_t ctx = {
170 .context = mp->context,
173 svs_walk (svs_send_details, &ctx);
176 #include <svs/svs.api.c>
177 static clib_error_t *
178 svs_api_init (vlib_main_t * vm)
180 /* Ask for a correctly-sized block of API message decode slots */
181 svs_base_msg_id = setup_message_id_table ();
186 VLIB_INIT_FUNCTION (svs_api_init);
189 VLIB_PLUGIN_REGISTER () = {
190 .version = VPP_BUILD_VER,
191 .description = "Source Virtual Routing and Fowarding (VRF) Select",
196 * fd.io coding-style-patch-verification: ON
199 * eval: (c-set-style "gnu")