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.
16 *------------------------------------------------------------------
17 * pot_test.c - test harness for pot plugin
18 *------------------------------------------------------------------
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
25 #include <vppinfra/error.h>
27 #define __plugin_msg_base pot_test_main.msg_id_base
28 #include <vlibapi/vat_helper_macros.h>
30 /* Declare message IDs */
31 #include <ioam/lib-pot/pot.api_enum.h>
32 #include <ioam/lib-pot/pot.api_types.h>
34 #define vl_endianfun /* define message structures */
36 #define vl_api_version(n,v) static u32 api_version=(v);
37 #define vl_print(handle, ...)
38 #include <ioam/lib-pot/pot.api.h>
44 /* API message ID base */
49 pot_test_main_t pot_test_main;
51 #define foreach_standard_reply_retval_handler \
52 _(pot_profile_add_reply) \
53 _(pot_profile_activate_reply) \
54 _(pot_profile_del_reply)
56 #define foreach_custom_reply_retval_handler \
57 _(pot_profile_show_config_details, \
58 errmsg(" ID:%d\n",mp->id); \
59 errmsg(" Validator:%d\n",mp->validator); \
60 errmsg(" secret_key:%Lx\n",clib_net_to_host_u64(mp->secret_key)); \
61 errmsg(" secret_share:%Lx\n",clib_net_to_host_u64(mp->secret_share)); \
62 errmsg(" prime:%Lx\n",clib_net_to_host_u64(mp->prime)); \
63 errmsg(" bitmask:%Lx\n",clib_net_to_host_u64(mp->bit_mask)); \
64 errmsg(" lpc:%Lx\n",clib_net_to_host_u64(mp->lpc)); \
65 errmsg(" public poly:%Lx\n",clib_net_to_host_u64(mp->polynomial_public)); \
69 static void vl_api_##n##_t_handler \
70 (vl_api_##n##_t * mp) \
72 vat_main_t * vam = pot_test_main.vat_main; \
73 i32 retval = ntohl(mp->retval); \
74 if (vam->async_mode) { \
75 vam->async_errors += (retval < 0); \
77 vam->retval = retval; \
78 vam->result_ready = 1; \
81 foreach_standard_reply_retval_handler;
85 static void vl_api_##n##_t_handler \
86 (vl_api_##n##_t * mp) \
88 vat_main_t * vam = pot_test_main.vat_main; \
89 i32 retval = ntohl(mp->retval); \
90 if (vam->async_mode) { \
91 vam->async_errors += (retval < 0); \
93 vam->retval = retval; \
94 vam->result_ready = 1; \
98 foreach_custom_reply_retval_handler;
102 * Table of message reply handlers, must include boilerplate handlers
105 #define foreach_vpe_api_reply_msg \
106 _(POT_PROFILE_ADD_REPLY, pot_profile_add_reply) \
107 _(POT_PROFILE_ACTIVATE_REPLY, pot_profile_activate_reply) \
108 _(POT_PROFILE_DEL_REPLY, pot_profile_del_reply) \
109 _(POT_PROFILE_SHOW_CONFIG_DETAILS, pot_profile_show_config_details)
111 static int api_pot_profile_add (vat_main_t *vam)
114 unformat_input_t *input = vam->input;
115 vl_api_pot_profile_add_t *mp;
118 u64 secret_share = 0;
121 u64 lpc = 0, poly2 = 0;
126 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
128 if (unformat(input, "name %s", &name))
130 else if(unformat(input, "id %d", &id))
132 else if (unformat(input, "validator-key 0x%Lx", &secret_key))
134 else if (unformat(input, "prime-number 0x%Lx", &prime))
136 else if (unformat(input, "secret-share 0x%Lx", &secret_share))
138 else if (unformat(input, "polynomial-public 0x%Lx", &poly2))
140 else if (unformat(input, "lpc 0x%Lx", &lpc))
142 else if (unformat(input, "bits-in-random %u", &bits))
153 errmsg ("name required\n");
158 M2(POT_PROFILE_ADD, mp, vec_len(name));
160 mp->list_name_len = vec_len(name);
161 clib_memcpy(mp->list_name, name, mp->list_name_len);
162 mp->secret_share = clib_host_to_net_u64(secret_share);
163 mp->polynomial_public = clib_host_to_net_u64(poly2);
164 mp->lpc = clib_host_to_net_u64(lpc);
165 mp->prime = clib_host_to_net_u64(prime);
168 mp->secret_key = clib_host_to_net_u64(secret_key);
187 static int api_pot_profile_activate (vat_main_t *vam)
190 unformat_input_t *input = vam->input;
191 vl_api_pot_profile_activate_t *mp;
197 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
199 if (unformat(input, "name %s", &name))
201 else if(unformat(input, "id %d", &id))
209 errmsg ("name required\n");
214 M2(POT_PROFILE_ACTIVATE, mp, vec_len(name));
216 mp->list_name_len = vec_len(name);
217 clib_memcpy(mp->list_name, name, mp->list_name_len);
230 static int api_pot_profile_del (vat_main_t *vam)
232 vl_api_pot_profile_del_t *mp;
235 M(POT_PROFILE_DEL, mp);
236 mp->list_name_len = 0;
242 static int api_pot_profile_show_config_dump (vat_main_t *vam)
244 unformat_input_t *input = vam->input;
245 vl_api_pot_profile_show_config_dump_t *mp;
249 while(unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
251 if(unformat(input,"id %d",&id));
255 M(POT_PROFILE_SHOW_CONFIG_DUMP, mp);
265 * List of messages that the api test plugin sends,
266 * and that the data plane plugin processes
268 #define foreach_vpe_api_msg \
269 _(pot_profile_add, "name <name> id [0-1] " \
270 "prime-number <0xu64> bits-in-random [0-64] " \
271 "secret-share <0xu64> lpc <0xu64> polynomial-public <0xu64> " \
272 "[validator-key <0xu64>] [validity <0xu64>]") \
273 _(pot_profile_activate, "name <name> id [0-1] ") \
274 _(pot_profile_del, "[id <nn>]") \
275 _(pot_profile_show_config_dump, "id [0-1]")
278 pot_vat_api_hookup (vat_main_t *vam)
280 pot_test_main_t * sm = &pot_test_main;
281 /* Hook up handlers for replies from the data plane plug-in */
283 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
285 vl_api_##n##_t_handler, \
287 vl_api_##n##_t_endian, \
288 vl_api_##n##_t_print, \
289 sizeof(vl_api_##n##_t), 1);
290 foreach_vpe_api_reply_msg;
293 /* API messages we can send */
294 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
299 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
306 pot_vat_plugin_register (vat_main_t *vam)
308 pot_test_main_t * sm = &pot_test_main;
313 name = format (0, "ioam_pot_%08x%c", api_version, 0);
314 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
317 if (sm->msg_id_base != (u16) ~0)
318 pot_vat_api_hookup (vam);
320 return clib_error_return (0, "ioam_pot plugin not loaded...");