Line data Source code
1 : /*
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:
6 : *
7 : * http://www.apache.org/licenses/LICENSE-2.0
8 : *
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.
14 : */
15 : /*
16 : *------------------------------------------------------------------
17 : * pot_test.c - test harness for pot plugin
18 : *------------------------------------------------------------------
19 : */
20 :
21 : #include <vat/vat.h>
22 : #include <vlibapi/api.h>
23 : #include <vlibmemory/api.h>
24 :
25 : #include <vppinfra/error.h>
26 :
27 : #define __plugin_msg_base pot_test_main.msg_id_base
28 : #include <vlibapi/vat_helper_macros.h>
29 :
30 : /* Declare message IDs */
31 : #include <ioam/lib-pot/pot.api_enum.h>
32 : #include <ioam/lib-pot/pot.api_types.h>
33 :
34 : typedef struct {
35 : /* API message ID base */
36 : u16 msg_id_base;
37 : vat_main_t *vat_main;
38 : } pot_test_main_t;
39 :
40 : pot_test_main_t pot_test_main;
41 :
42 0 : static int api_pot_profile_add (vat_main_t *vam)
43 : {
44 : #define MAX_BITS 64
45 0 : unformat_input_t *input = vam->input;
46 : vl_api_pot_profile_add_t *mp;
47 0 : u8 *name = NULL;
48 0 : u64 prime = 0;
49 0 : u64 secret_share = 0;
50 0 : u64 secret_key = 0;
51 0 : u32 bits = MAX_BITS;
52 0 : u64 lpc = 0, poly2 = 0;
53 0 : u8 id = 0;
54 0 : int rv = 0;
55 : int ret;
56 :
57 0 : while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
58 : {
59 0 : if (unformat(input, "name %s", &name))
60 : ;
61 0 : else if(unformat(input, "id %d", &id))
62 : ;
63 0 : else if (unformat(input, "validator-key 0x%Lx", &secret_key))
64 : ;
65 0 : else if (unformat(input, "prime-number 0x%Lx", &prime))
66 : ;
67 0 : else if (unformat(input, "secret-share 0x%Lx", &secret_share))
68 : ;
69 0 : else if (unformat(input, "polynomial-public 0x%Lx", &poly2))
70 : ;
71 0 : else if (unformat(input, "lpc 0x%Lx", &lpc))
72 : ;
73 0 : else if (unformat(input, "bits-in-random %u", &bits))
74 : {
75 0 : if (bits > MAX_BITS)
76 0 : bits = MAX_BITS;
77 : }
78 : else
79 0 : break;
80 : }
81 :
82 0 : if (!name)
83 : {
84 0 : errmsg ("name required\n");
85 0 : rv = -99;
86 0 : goto OUT;
87 : }
88 :
89 0 : M2(POT_PROFILE_ADD, mp, sizeof(vl_api_string_t) + vec_len(name));
90 :
91 0 : vl_api_vec_to_api_string(name, &mp->list_name);
92 0 : mp->secret_share = clib_host_to_net_u64(secret_share);
93 0 : mp->polynomial_public = clib_host_to_net_u64(poly2);
94 0 : mp->lpc = clib_host_to_net_u64(lpc);
95 0 : mp->prime = clib_host_to_net_u64(prime);
96 0 : if (secret_key != 0)
97 : {
98 0 : mp->secret_key = clib_host_to_net_u64(secret_key);
99 0 : mp->validator = 1;
100 : }
101 : else
102 : {
103 0 : mp->validator = 0;
104 : }
105 0 : mp->id = id;
106 0 : mp->max_bits = bits;
107 :
108 0 : S(mp);
109 0 : W (ret);
110 0 : return ret;
111 :
112 0 : OUT:
113 0 : vec_free(name);
114 0 : return(rv);
115 : }
116 :
117 0 : static int api_pot_profile_activate (vat_main_t *vam)
118 : {
119 : #define MAX_BITS 64
120 0 : unformat_input_t *input = vam->input;
121 : vl_api_pot_profile_activate_t *mp;
122 0 : u8 *name = NULL;
123 0 : u8 id = 0;
124 0 : int rv = 0;
125 : int ret;
126 :
127 0 : while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
128 : {
129 0 : if (unformat(input, "name %s", &name))
130 : ;
131 0 : else if(unformat(input, "id %d", &id))
132 : ;
133 : else
134 0 : break;
135 : }
136 :
137 0 : if (!name)
138 : {
139 0 : errmsg ("name required\n");
140 0 : rv = -99;
141 0 : goto OUT;
142 : }
143 :
144 0 : M2(POT_PROFILE_ACTIVATE, mp, sizeof(vl_api_string_t) + vec_len(name));
145 0 : vl_api_vec_to_api_string(name, &mp->list_name);
146 0 : mp->id = id;
147 :
148 0 : S(mp);
149 0 : W (ret);
150 0 : return ret;
151 :
152 0 : OUT:
153 0 : vec_free(name);
154 0 : return(rv);
155 : }
156 :
157 :
158 0 : static int api_pot_profile_del (vat_main_t *vam)
159 : {
160 : vl_api_pot_profile_del_t *mp;
161 : int ret;
162 :
163 0 : M(POT_PROFILE_DEL, mp);
164 0 : S(mp);
165 0 : W (ret);
166 0 : return ret;
167 : }
168 :
169 0 : static int api_pot_profile_show_config_dump (vat_main_t *vam)
170 : {
171 0 : unformat_input_t *input = vam->input;
172 : vl_api_pot_profile_show_config_dump_t *mp;
173 0 : u8 id = 0;
174 : int ret;
175 :
176 0 : while(unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
177 : {
178 0 : if(unformat(input,"id %d",&id));
179 : else
180 0 : break;
181 : }
182 0 : M(POT_PROFILE_SHOW_CONFIG_DUMP, mp);
183 :
184 0 : mp->id = id;
185 :
186 0 : S(mp);
187 0 : W (ret);
188 0 : return ret;
189 : }
190 0 : static int vl_api_pot_profile_show_config_details_t_handler (vat_main_t *vam)
191 : {
192 0 : return -1;
193 : }
194 :
195 : /* Override generated plugin register symbol */
196 : #define vat_plugin_register pot_vat_plugin_register
197 : #include <ioam/lib-pot/pot.api_test.c>
|