2 * Copyright (c) 2016 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>
20 #include <l3xc/l3xc.h>
21 #include <vnet/mpls/mpls_types.h>
22 #include <vnet/fib/fib_path_list.h>
23 #include <vnet/fib/fib_api.h>
25 #include <vpp/app/version.h>
27 #include <vlibapi/api.h>
28 #include <vlibmemory/api.h>
30 /* define message IDs */
31 #include <vnet/format_fns.h>
32 #include <l3xc/l3xc.api_enum.h>
33 #include <l3xc/l3xc.api_types.h>
36 * Base message ID fot the plugin
38 static u32 l3xc_base_msg_id;
40 #include <vlibapi/api_helper_macros.h>
43 vl_api_l3xc_plugin_get_version_t_handler (vl_api_l3xc_plugin_get_version_t *
46 vl_api_l3xc_plugin_get_version_reply_t *rmp;
47 vl_api_registration_t *rp;
49 rp = vl_api_client_index_to_registration (mp->client_index);
53 rmp = vl_msg_api_alloc (sizeof (*rmp));
55 ntohs (VL_API_L3XC_PLUGIN_GET_VERSION_REPLY + l3xc_base_msg_id);
56 rmp->context = mp->context;
57 rmp->major = htonl (L3XC_PLUGIN_VERSION_MAJOR);
58 rmp->minor = htonl (L3XC_PLUGIN_VERSION_MINOR);
60 vl_api_send_msg (rp, (u8 *) rmp);
64 vl_api_l3xc_update_t_handler (vl_api_l3xc_update_t * mp)
66 vl_api_l3xc_update_reply_t *rmp;
67 fib_route_path_t *paths = NULL, *path;
71 VALIDATE_SW_IF_INDEX (&mp->l3xc);
73 if (0 == mp->l3xc.n_paths)
75 rv = VNET_API_ERROR_INVALID_VALUE;
79 vec_validate (paths, mp->l3xc.n_paths - 1);
81 for (pi = 0; pi < mp->l3xc.n_paths; pi++)
84 rv = fib_api_path_decode (&mp->l3xc.paths[pi], path);
92 rv = l3xc_update (ntohl (mp->l3xc.sw_if_index), mp->l3xc.is_ip6, paths);
97 BAD_SW_IF_INDEX_LABEL;
100 REPLY_MACRO2 (VL_API_L3XC_UPDATE_REPLY + l3xc_base_msg_id,
102 rmp->stats_index = 0;
108 vl_api_l3xc_del_t_handler (vl_api_l3xc_del_t * mp)
110 vl_api_l3xc_del_reply_t *rmp;
113 VALIDATE_SW_IF_INDEX (mp);
115 rv = l3xc_delete (ntohl (mp->sw_if_index), mp->is_ip6);
117 BAD_SW_IF_INDEX_LABEL;
119 REPLY_MACRO (VL_API_L3XC_DEL_REPLY + l3xc_base_msg_id);
122 typedef struct l3xc_dump_walk_ctx_t_
124 vl_api_registration_t *rp;
126 } l3xc_dump_walk_ctx_t;
129 l3xc_send_details (u32 l3xci, void *args)
131 fib_path_encode_ctx_t path_ctx = {
134 vl_api_l3xc_details_t *mp;
135 l3xc_dump_walk_ctx_t *ctx;
136 fib_route_path_t *rpath;
137 vl_api_fib_path_t *fp;
143 l3xc = l3xc_get (l3xci);
144 n_paths = fib_path_list_get_n_paths (l3xc->l3xc_pl);
145 msg_size = sizeof (*mp) + sizeof (mp->l3xc.paths[0]) * n_paths;
147 mp = vl_msg_api_alloc (msg_size);
148 clib_memset (mp, 0, msg_size);
149 mp->_vl_msg_id = ntohs (VL_API_L3XC_DETAILS + l3xc_base_msg_id);
151 /* fill in the message */
152 mp->context = ctx->context;
153 mp->l3xc.n_paths = n_paths;
154 mp->l3xc.sw_if_index = htonl (l3xc->l3xc_sw_if_index);
156 fib_path_list_walk_w_ext (l3xc->l3xc_pl, NULL, fib_path_encode, &path_ctx);
159 vec_foreach (rpath, path_ctx.rpaths)
161 fib_api_path_encode (rpath, fp);
165 vl_api_send_msg (ctx->rp, (u8 *) mp);
171 vl_api_l3xc_dump_t_handler (vl_api_l3xc_dump_t * mp)
173 vl_api_registration_t *rp;
176 rp = vl_api_client_index_to_registration (mp->client_index);
180 l3xc_dump_walk_ctx_t ctx = {
182 .context = mp->context,
185 sw_if_index = ntohl (mp->sw_if_index);
187 if (~0 == sw_if_index)
188 l3xc_walk (l3xc_send_details, &ctx);
191 fib_protocol_t fproto;
194 FOR_EACH_FIB_IP_PROTOCOL (fproto)
196 l3xci = l3xc_find (sw_if_index, fproto);
198 if (INDEX_INVALID != l3xci)
199 l3xc_send_details (l3xci, &ctx);
204 #include <l3xc/l3xc.api.c>
205 static clib_error_t *
206 l3xc_api_init (vlib_main_t * vm)
208 /* Ask for a correctly-sized block of API message decode slots */
209 l3xc_base_msg_id = setup_message_id_table ();
214 VLIB_INIT_FUNCTION (l3xc_api_init);
217 VLIB_PLUGIN_REGISTER () = {
218 .version = VPP_BUILD_VER,
219 .description = "L3 Cross-Connect (L3XC)",
224 * fd.io coding-style-patch-verification: ON
227 * eval: (c-set-style "gnu")