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>
24 #include <vlibsocket/api.h>
25 #include <vppinfra/error.h>
26 #include <vlibapi/vat_helper_macros.h>
28 /* Declare message IDs */
29 #include <ioam/lib-pot/pot_msg_enum.h>
31 /* define message structures */
33 #include <ioam/lib-pot/pot_all_api_h.h>
36 /* declare message handlers for each api */
38 #define vl_endianfun /* define message structures */
39 #include <ioam/lib-pot/pot_all_api_h.h>
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...)
45 #include <ioam/lib-pot/pot_all_api_h.h>
48 /* Get the API version number. */
49 #define vl_api_version(n,v) static u32 api_version=(v);
50 #include <ioam/lib-pot/pot_all_api_h.h>
55 /* API message ID base */
60 pot_test_main_t pot_test_main;
62 #define foreach_standard_reply_retval_handler \
63 _(pot_profile_add_reply) \
64 _(pot_profile_activate_reply) \
65 _(pot_profile_del_reply)
67 #define foreach_custom_reply_retval_handler \
68 _(pot_profile_show_config_details, \
69 errmsg(" ID:%d\n",mp->id); \
70 errmsg(" Validator:%d\n",mp->validator); \
71 errmsg(" secret_key:%Lx\n",clib_net_to_host_u64(mp->secret_key)); \
72 errmsg(" secret_share:%Lx\n",clib_net_to_host_u64(mp->secret_share)); \
73 errmsg(" prime:%Lx\n",clib_net_to_host_u64(mp->prime)); \
74 errmsg(" bitmask:%Lx\n",clib_net_to_host_u64(mp->bit_mask)); \
75 errmsg(" lpc:%Lx\n",clib_net_to_host_u64(mp->lpc)); \
76 errmsg(" public poly:%Lx\n",clib_net_to_host_u64(mp->polynomial_public)); \
80 static void vl_api_##n##_t_handler \
81 (vl_api_##n##_t * mp) \
83 vat_main_t * vam = pot_test_main.vat_main; \
84 i32 retval = ntohl(mp->retval); \
85 if (vam->async_mode) { \
86 vam->async_errors += (retval < 0); \
88 vam->retval = retval; \
89 vam->result_ready = 1; \
92 foreach_standard_reply_retval_handler;
96 static void vl_api_##n##_t_handler \
97 (vl_api_##n##_t * mp) \
99 vat_main_t * vam = pot_test_main.vat_main; \
100 i32 retval = ntohl(mp->retval); \
101 if (vam->async_mode) { \
102 vam->async_errors += (retval < 0); \
104 vam->retval = retval; \
105 vam->result_ready = 1; \
109 foreach_custom_reply_retval_handler;
113 * Table of message reply handlers, must include boilerplate handlers
116 #define foreach_vpe_api_reply_msg \
117 _(POT_PROFILE_ADD_REPLY, pot_profile_add_reply) \
118 _(POT_PROFILE_ACTIVATE_REPLY, pot_profile_activate_reply) \
119 _(POT_PROFILE_DEL_REPLY, pot_profile_del_reply) \
120 _(POT_PROFILE_SHOW_CONFIG_DETAILS, pot_profile_show_config_details)
122 static int api_pot_profile_add (vat_main_t *vam)
125 unformat_input_t *input = vam->input;
126 vl_api_pot_profile_add_t *mp;
129 u64 secret_share = 0;
132 u64 lpc = 0, poly2 = 0;
137 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
139 if (unformat(input, "name %s", &name))
141 else if(unformat(input, "id %d", &id))
143 else if (unformat(input, "validator-key 0x%Lx", &secret_key))
145 else if (unformat(input, "prime-number 0x%Lx", &prime))
147 else if (unformat(input, "secret-share 0x%Lx", &secret_share))
149 else if (unformat(input, "polynomial-public 0x%Lx", &poly2))
151 else if (unformat(input, "lpc 0x%Lx", &lpc))
153 else if (unformat(input, "bits-in-random %u", &bits))
164 errmsg ("name required\n");
169 M2(POT_PROFILE_ADD, pot_profile_add, vec_len(name));
171 mp->list_name_len = vec_len(name);
172 clib_memcpy(mp->list_name, name, mp->list_name_len);
173 mp->secret_share = clib_host_to_net_u64(secret_share);
174 mp->polynomial_public = clib_host_to_net_u64(poly2);
175 mp->lpc = clib_host_to_net_u64(lpc);
176 mp->prime = clib_host_to_net_u64(prime);
179 mp->secret_key = clib_host_to_net_u64(secret_key);
196 static int api_pot_profile_activate (vat_main_t *vam)
199 unformat_input_t *input = vam->input;
200 vl_api_pot_profile_activate_t *mp;
206 while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
208 if (unformat(input, "name %s", &name))
210 else if(unformat(input, "id %d", &id))
218 errmsg ("name required\n");
223 M2(POT_PROFILE_ACTIVATE, pot_profile_activate, vec_len(name));
225 mp->list_name_len = vec_len(name);
226 clib_memcpy(mp->list_name, name, mp->list_name_len);
237 static int api_pot_profile_del (vat_main_t *vam)
239 vl_api_pot_profile_del_t *mp;
242 M(POT_PROFILE_DEL, pot_profile_del);
243 mp->list_name_len = 0;
248 static int api_pot_profile_show_config_dump (vat_main_t *vam)
250 unformat_input_t *input = vam->input;
251 vl_api_pot_profile_show_config_dump_t *mp;
255 while(unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
257 if(unformat(input,"id %d",&id));
261 M(POT_PROFILE_SHOW_CONFIG_DUMP, pot_profile_show_config_dump);
270 * List of messages that the api test plugin sends,
271 * and that the data plane plugin processes
273 #define foreach_vpe_api_msg \
274 _(pot_profile_add, "name <name> id [0-1] " \
275 "prime-number <0xu64> bits-in-random [0-64] " \
276 "secret-share <0xu64> lpc <0xu64> polynomial-public <0xu64> " \
277 "[validator-key <0xu64>] [validity <0xu64>]") \
278 _(pot_profile_activate, "name <name> id [0-1] ") \
279 _(pot_profile_del, "[id <nn>]") \
280 _(pot_profile_show_config_dump, "id [0-1]")
283 pot_vat_api_hookup (vat_main_t *vam)
285 pot_test_main_t * sm = &pot_test_main;
286 /* Hook up handlers for replies from the data plane plug-in */
288 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
290 vl_api_##n##_t_handler, \
292 vl_api_##n##_t_endian, \
293 vl_api_##n##_t_print, \
294 sizeof(vl_api_##n##_t), 1);
295 foreach_vpe_api_reply_msg;
298 /* API messages we can send */
299 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
304 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
309 clib_error_t * vat_plugin_register (vat_main_t *vam)
311 pot_test_main_t * sm = &pot_test_main;
316 name = format (0, "ioam_pot_%08x%c", api_version, 0);
317 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
319 if (sm->msg_id_base != (u16) ~0)
320 pot_vat_api_hookup (vam);