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_msg_enum.h>
33 /* define message structures */
35 #include <ioam/lib-pot/pot_all_api_h.h>
38 /* declare message handlers for each api */
40 #define vl_endianfun /* define message structures */
41 #include <ioam/lib-pot/pot_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...)
47 #include <ioam/lib-pot/pot_all_api_h.h>
50 /* Get the API version number. */
51 #define vl_api_version(n,v) static u32 api_version=(v);
52 #include <ioam/lib-pot/pot_all_api_h.h>
57 /* API message ID base */
62 pot_test_main_t pot_test_main;
64 #define foreach_standard_reply_retval_handler \
65 _(pot_profile_add_reply) \
66 _(pot_profile_activate_reply) \
67 _(pot_profile_del_reply)
69 #define foreach_custom_reply_retval_handler \
70 _(pot_profile_show_config_details, \
71 errmsg(" ID:%d\n",mp->id); \
72 errmsg(" Validator:%d\n",mp->validator); \
73 errmsg(" secret_key:%Lx\n",clib_net_to_host_u64(mp->secret_key)); \
74 errmsg(" secret_share:%Lx\n",clib_net_to_host_u64(mp->secret_share)); \
75 errmsg(" prime:%Lx\n",clib_net_to_host_u64(mp->prime)); \
76 errmsg(" bitmask:%Lx\n",clib_net_to_host_u64(mp->bit_mask)); \
77 errmsg(" lpc:%Lx\n",clib_net_to_host_u64(mp->lpc)); \
78 errmsg(" public poly:%Lx\n",clib_net_to_host_u64(mp->polynomial_public)); \
82 static void vl_api_##n##_t_handler \
83 (vl_api_##n##_t * mp) \
85 vat_main_t * vam = pot_test_main.vat_main; \
86 i32 retval = ntohl(mp->retval); \
87 if (vam->async_mode) { \
88 vam->async_errors += (retval < 0); \
90 vam->retval = retval; \
91 vam->result_ready = 1; \
94 foreach_standard_reply_retval_handler;
98 static void vl_api_##n##_t_handler \
99 (vl_api_##n##_t * mp) \
101 vat_main_t * vam = pot_test_main.vat_main; \
102 i32 retval = ntohl(mp->retval); \
103 if (vam->async_mode) { \
104 vam->async_errors += (retval < 0); \
106 vam->retval = retval; \
107 vam->result_ready = 1; \
111 foreach_custom_reply_retval_handler;
115 * Table of message reply handlers, must include boilerplate handlers
118 #define foreach_vpe_api_reply_msg \
119 _(POT_PROFILE_ADD_REPLY, pot_profile_add_reply) \
120 _(POT_PROFILE_ACTIVATE_REPLY, pot_profile_activate_reply) \
121 _(POT_PROFILE_DEL_REPLY, pot_profile_del_reply) \
122 _(POT_PROFILE_SHOW_CONFIG_DETAILS, pot_profile_show_config_details)
124 static int api_pot_profile_add (vat_main_t *vam)
127 unformat_input_t *input = vam->input;
128 vl_api_pot_profile_add_t *mp;
131 u64 secret_share = 0;
134 u64 lpc = 0, poly2 = 0;
139 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
141 if (unformat(input, "name %s", &name))
143 else if(unformat(input, "id %d", &id))
145 else if (unformat(input, "validator-key 0x%Lx", &secret_key))
147 else if (unformat(input, "prime-number 0x%Lx", &prime))
149 else if (unformat(input, "secret-share 0x%Lx", &secret_share))
151 else if (unformat(input, "polynomial-public 0x%Lx", &poly2))
153 else if (unformat(input, "lpc 0x%Lx", &lpc))
155 else if (unformat(input, "bits-in-random %u", &bits))
166 errmsg ("name required\n");
171 M2(POT_PROFILE_ADD, mp, vec_len(name));
173 mp->list_name_len = vec_len(name);
174 clib_memcpy(mp->list_name, name, mp->list_name_len);
175 mp->secret_share = clib_host_to_net_u64(secret_share);
176 mp->polynomial_public = clib_host_to_net_u64(poly2);
177 mp->lpc = clib_host_to_net_u64(lpc);
178 mp->prime = clib_host_to_net_u64(prime);
181 mp->secret_key = clib_host_to_net_u64(secret_key);
200 static int api_pot_profile_activate (vat_main_t *vam)
203 unformat_input_t *input = vam->input;
204 vl_api_pot_profile_activate_t *mp;
210 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
212 if (unformat(input, "name %s", &name))
214 else if(unformat(input, "id %d", &id))
222 errmsg ("name required\n");
227 M2(POT_PROFILE_ACTIVATE, mp, vec_len(name));
229 mp->list_name_len = vec_len(name);
230 clib_memcpy(mp->list_name, name, mp->list_name_len);
243 static int api_pot_profile_del (vat_main_t *vam)
245 vl_api_pot_profile_del_t *mp;
248 M(POT_PROFILE_DEL, mp);
249 mp->list_name_len = 0;
255 static int api_pot_profile_show_config_dump (vat_main_t *vam)
257 unformat_input_t *input = vam->input;
258 vl_api_pot_profile_show_config_dump_t *mp;
262 while(unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
264 if(unformat(input,"id %d",&id));
268 M(POT_PROFILE_SHOW_CONFIG_DUMP, mp);
278 * List of messages that the api test plugin sends,
279 * and that the data plane plugin processes
281 #define foreach_vpe_api_msg \
282 _(pot_profile_add, "name <name> id [0-1] " \
283 "prime-number <0xu64> bits-in-random [0-64] " \
284 "secret-share <0xu64> lpc <0xu64> polynomial-public <0xu64> " \
285 "[validator-key <0xu64>] [validity <0xu64>]") \
286 _(pot_profile_activate, "name <name> id [0-1] ") \
287 _(pot_profile_del, "[id <nn>]") \
288 _(pot_profile_show_config_dump, "id [0-1]")
291 pot_vat_api_hookup (vat_main_t *vam)
293 pot_test_main_t * sm = &pot_test_main;
294 /* Hook up handlers for replies from the data plane plug-in */
296 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
298 vl_api_##n##_t_handler, \
300 vl_api_##n##_t_endian, \
301 vl_api_##n##_t_print, \
302 sizeof(vl_api_##n##_t), 1);
303 foreach_vpe_api_reply_msg;
306 /* API messages we can send */
307 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
312 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
319 pot_vat_plugin_register (vat_main_t *vam)
321 pot_test_main_t * sm = &pot_test_main;
326 name = format (0, "ioam_pot_%08x%c", api_version, 0);
327 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
330 if (sm->msg_id_base != (u16) ~0)
331 pot_vat_api_hookup (vam);
333 return clib_error_return (0, "ioam_pot plugin not loaded...");