IKEv2 to plugin
[vpp.git] / src / plugins / ikev2 / ikev2_test.c
1 /*
2  *------------------------------------------------------------------
3  * api_format.c
4  *
5  * Copyright (c) 2014-2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #include <vat/vat.h>
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 #include <vppinfra/error.h>
24 #include <plugins/ikev2/ikev2.h>
25
26 #define __plugin_msg_base ikev2_test_main.msg_id_base
27 #include <vlibapi/vat_helper_macros.h>
28
29 /* Declare message IDs */
30 #include <ikev2/ikev2_msg_enum.h>
31
32 #define vl_typedefs             /* define message structures */
33 #include <ikev2/ikev2.api.h>
34 #undef vl_typedefs
35
36 /* declare message handlers for each api */
37
38 #define vl_endianfun            /* define message structures */
39 #include <ikev2/ikev2.api.h>
40 #undef vl_endianfun
41
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...)
44 #define vl_printfun
45 #include <ikev2/ikev2.api.h>
46 #undef vl_printfun
47
48 /* Get the API version number. */
49 #define vl_api_version(n,v) static u32 api_version=(v);
50 #include <ikev2/ikev2.api.h>
51 #undef vl_api_version
52
53 typedef struct
54 {
55   /* API message ID base */
56   u16 msg_id_base;
57   vat_main_t *vat_main;
58 } ikev2_test_main_t;
59
60 ikev2_test_main_t ikev2_test_main;
61
62 uword
63 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
64 {
65   u32 *r = va_arg (*args, u32 *);
66
67   if (0);
68 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
69   foreach_ikev2_auth_method
70 #undef _
71     else
72     return 0;
73   return 1;
74 }
75
76 uword
77 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
78 {
79   u32 *r = va_arg (*args, u32 *);
80
81   if (0);
82 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
83   foreach_ikev2_id_type
84 #undef _
85     else
86     return 0;
87   return 1;
88 }
89
90 /*
91  * Generate boilerplate reply handlers, which
92  * dig the return value out of the xxx_reply_t API message,
93  * stick it into vam->retval, and set vam->result_ready
94  *
95  * Could also do this by pointing N message decode slots at
96  * a single function, but that could break in subtle ways.
97  */
98
99 #define foreach_standard_reply_retval_handler           \
100 _(ikev2_profile_add_del_reply)                          \
101 _(ikev2_profile_set_auth_reply)                         \
102 _(ikev2_profile_set_id_reply)                           \
103 _(ikev2_profile_set_ts_reply)                           \
104 _(ikev2_set_local_key_reply)                            \
105 _(ikev2_set_responder_reply)                            \
106 _(ikev2_set_ike_transforms_reply)                       \
107 _(ikev2_set_esp_transforms_reply)                       \
108 _(ikev2_set_sa_lifetime_reply)                          \
109 _(ikev2_initiate_sa_init_reply)                         \
110 _(ikev2_initiate_del_ike_sa_reply)                      \
111 _(ikev2_initiate_del_child_sa_reply)                    \
112 _(ikev2_initiate_rekey_child_sa_reply)
113
114 #define _(n)                                            \
115     static void vl_api_##n##_t_handler                  \
116     (vl_api_##n##_t * mp)                               \
117     {                                                   \
118         vat_main_t * vam = ikev2_test_main.vat_main;    \
119         i32 retval = ntohl(mp->retval);                 \
120         if (vam->async_mode) {                          \
121             vam->async_errors += (retval < 0);          \
122         } else {                                        \
123             vam->retval = retval;                       \
124             vam->result_ready = 1;                      \
125         }                                               \
126     }
127 foreach_standard_reply_retval_handler;
128 #undef _
129
130 /*
131  * Table of message reply handlers, must include boilerplate handlers
132  * we just generated
133  */
134
135 #define foreach_vpe_api_reply_msg                                       \
136 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply)             \
137 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply)           \
138 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply)               \
139 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply)               \
140 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply)                 \
141 _(IKEV2_SET_RESPONDER_REPLY, ikev2_set_responder_reply)                 \
142 _(IKEV2_SET_IKE_TRANSFORMS_REPLY, ikev2_set_ike_transforms_reply)       \
143 _(IKEV2_SET_ESP_TRANSFORMS_REPLY, ikev2_set_esp_transforms_reply)       \
144 _(IKEV2_SET_SA_LIFETIME_REPLY, ikev2_set_sa_lifetime_reply)             \
145 _(IKEV2_INITIATE_SA_INIT_REPLY, ikev2_initiate_sa_init_reply)           \
146 _(IKEV2_INITIATE_DEL_IKE_SA_REPLY, ikev2_initiate_del_ike_sa_reply)     \
147 _(IKEV2_INITIATE_DEL_CHILD_SA_REPLY, ikev2_initiate_del_child_sa_reply) \
148 _(IKEV2_INITIATE_REKEY_CHILD_SA_REPLY, ikev2_initiate_rekey_child_sa_reply)
149
150
151 static int
152 api_ikev2_profile_add_del (vat_main_t * vam)
153 {
154   unformat_input_t *i = vam->input;
155   vl_api_ikev2_profile_add_del_t *mp;
156   u8 is_add = 1;
157   u8 *name = 0;
158   int ret;
159
160   const char *valid_chars = "a-zA-Z0-9_";
161
162   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
163     {
164       if (unformat (i, "del"))
165         is_add = 0;
166       else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
167         vec_add1 (name, 0);
168       else
169         {
170           errmsg ("parse error '%U'", format_unformat_error, i);
171           return -99;
172         }
173     }
174
175   if (!vec_len (name))
176     {
177       errmsg ("profile name must be specified");
178       return -99;
179     }
180
181   if (vec_len (name) > 64)
182     {
183       errmsg ("profile name too long");
184       return -99;
185     }
186
187   M (IKEV2_PROFILE_ADD_DEL, mp);
188
189   clib_memcpy (mp->name, name, vec_len (name));
190   mp->is_add = is_add;
191   vec_free (name);
192
193   S (mp);
194   W (ret);
195   return ret;
196 }
197
198 static int
199 api_ikev2_profile_set_auth (vat_main_t * vam)
200 {
201   unformat_input_t *i = vam->input;
202   vl_api_ikev2_profile_set_auth_t *mp;
203   u8 *name = 0;
204   u8 *data = 0;
205   u32 auth_method = 0;
206   u8 is_hex = 0;
207   int ret;
208
209   const char *valid_chars = "a-zA-Z0-9_";
210
211   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
212     {
213       if (unformat (i, "name %U", unformat_token, valid_chars, &name))
214         vec_add1 (name, 0);
215       else if (unformat (i, "auth_method %U",
216                          unformat_ikev2_auth_method, &auth_method))
217         ;
218       else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
219         is_hex = 1;
220       else if (unformat (i, "auth_data %v", &data))
221         ;
222       else
223         {
224           errmsg ("parse error '%U'", format_unformat_error, i);
225           return -99;
226         }
227     }
228
229   if (!vec_len (name))
230     {
231       errmsg ("profile name must be specified");
232       return -99;
233     }
234
235   if (vec_len (name) > 64)
236     {
237       errmsg ("profile name too long");
238       return -99;
239     }
240
241   if (!vec_len (data))
242     {
243       errmsg ("auth_data must be specified");
244       return -99;
245     }
246
247   if (!auth_method)
248     {
249       errmsg ("auth_method must be specified");
250       return -99;
251     }
252
253   M (IKEV2_PROFILE_SET_AUTH, mp);
254
255   mp->is_hex = is_hex;
256   mp->auth_method = (u8) auth_method;
257   mp->data_len = vec_len (data);
258   clib_memcpy (mp->name, name, vec_len (name));
259   clib_memcpy (mp->data, data, vec_len (data));
260   vec_free (name);
261   vec_free (data);
262
263   S (mp);
264   W (ret);
265   return ret;
266 }
267
268 static int
269 api_ikev2_profile_set_id (vat_main_t * vam)
270 {
271   unformat_input_t *i = vam->input;
272   vl_api_ikev2_profile_set_id_t *mp;
273   u8 *name = 0;
274   u8 *data = 0;
275   u8 is_local = 0;
276   u32 id_type = 0;
277   ip4_address_t ip4;
278   int ret;
279
280   const char *valid_chars = "a-zA-Z0-9_";
281
282   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
283     {
284       if (unformat (i, "name %U", unformat_token, valid_chars, &name))
285         vec_add1 (name, 0);
286       else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
287         ;
288       else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
289         {
290           data = vec_new (u8, 4);
291           clib_memcpy (data, ip4.as_u8, 4);
292         }
293       else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
294         ;
295       else if (unformat (i, "id_data %v", &data))
296         ;
297       else if (unformat (i, "local"))
298         is_local = 1;
299       else if (unformat (i, "remote"))
300         is_local = 0;
301       else
302         {
303           errmsg ("parse error '%U'", format_unformat_error, i);
304           return -99;
305         }
306     }
307
308   if (!vec_len (name))
309     {
310       errmsg ("profile name must be specified");
311       return -99;
312     }
313
314   if (vec_len (name) > 64)
315     {
316       errmsg ("profile name too long");
317       return -99;
318     }
319
320   if (!vec_len (data))
321     {
322       errmsg ("id_data must be specified");
323       return -99;
324     }
325
326   if (!id_type)
327     {
328       errmsg ("id_type must be specified");
329       return -99;
330     }
331
332   M (IKEV2_PROFILE_SET_ID, mp);
333
334   mp->is_local = is_local;
335   mp->id_type = (u8) id_type;
336   mp->data_len = vec_len (data);
337   clib_memcpy (mp->name, name, vec_len (name));
338   clib_memcpy (mp->data, data, vec_len (data));
339   vec_free (name);
340   vec_free (data);
341
342   S (mp);
343   W (ret);
344   return ret;
345 }
346
347 static int
348 api_ikev2_profile_set_ts (vat_main_t * vam)
349 {
350   unformat_input_t *i = vam->input;
351   vl_api_ikev2_profile_set_ts_t *mp;
352   u8 *name = 0;
353   u8 is_local = 0;
354   u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
355   ip4_address_t start_addr, end_addr;
356
357   const char *valid_chars = "a-zA-Z0-9_";
358   int ret;
359
360   start_addr.as_u32 = 0;
361   end_addr.as_u32 = (u32) ~ 0;
362
363   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
364     {
365       if (unformat (i, "name %U", unformat_token, valid_chars, &name))
366         vec_add1 (name, 0);
367       else if (unformat (i, "protocol %d", &proto))
368         ;
369       else if (unformat (i, "start_port %d", &start_port))
370         ;
371       else if (unformat (i, "end_port %d", &end_port))
372         ;
373       else
374         if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
375         ;
376       else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
377         ;
378       else if (unformat (i, "local"))
379         is_local = 1;
380       else if (unformat (i, "remote"))
381         is_local = 0;
382       else
383         {
384           errmsg ("parse error '%U'", format_unformat_error, i);
385           return -99;
386         }
387     }
388
389   if (!vec_len (name))
390     {
391       errmsg ("profile name must be specified");
392       return -99;
393     }
394
395   if (vec_len (name) > 64)
396     {
397       errmsg ("profile name too long");
398       return -99;
399     }
400
401   M (IKEV2_PROFILE_SET_TS, mp);
402
403   mp->is_local = is_local;
404   mp->proto = (u8) proto;
405   mp->start_port = (u16) start_port;
406   mp->end_port = (u16) end_port;
407   mp->start_addr = start_addr.as_u32;
408   mp->end_addr = end_addr.as_u32;
409   clib_memcpy (mp->name, name, vec_len (name));
410   vec_free (name);
411
412   S (mp);
413   W (ret);
414   return ret;
415 }
416
417 static int
418 api_ikev2_set_local_key (vat_main_t * vam)
419 {
420   unformat_input_t *i = vam->input;
421   vl_api_ikev2_set_local_key_t *mp;
422   u8 *file = 0;
423   int ret;
424
425   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
426     {
427       if (unformat (i, "file %v", &file))
428         vec_add1 (file, 0);
429       else
430         {
431           errmsg ("parse error '%U'", format_unformat_error, i);
432           return -99;
433         }
434     }
435
436   if (!vec_len (file))
437     {
438       errmsg ("RSA key file must be specified");
439       return -99;
440     }
441
442   if (vec_len (file) > 256)
443     {
444       errmsg ("file name too long");
445       return -99;
446     }
447
448   M (IKEV2_SET_LOCAL_KEY, mp);
449
450   clib_memcpy (mp->key_file, file, vec_len (file));
451   vec_free (file);
452
453   S (mp);
454   W (ret);
455   return ret;
456 }
457
458 static int
459 api_ikev2_set_responder (vat_main_t * vam)
460 {
461   unformat_input_t *i = vam->input;
462   vl_api_ikev2_set_responder_t *mp;
463   int ret;
464   u8 *name = 0;
465   u32 sw_if_index = ~0;
466   ip4_address_t address;
467
468   const char *valid_chars = "a-zA-Z0-9_";
469
470   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
471     {
472       if (unformat
473           (i, "%U interface %d address %U", unformat_token, valid_chars,
474            &name, &sw_if_index, unformat_ip4_address, &address))
475         vec_add1 (name, 0);
476       else
477         {
478           errmsg ("parse error '%U'", format_unformat_error, i);
479           return -99;
480         }
481     }
482
483   if (!vec_len (name))
484     {
485       errmsg ("profile name must be specified");
486       return -99;
487     }
488
489   if (vec_len (name) > 64)
490     {
491       errmsg ("profile name too long");
492       return -99;
493     }
494
495   M (IKEV2_SET_RESPONDER, mp);
496
497   clib_memcpy (mp->name, name, vec_len (name));
498   vec_free (name);
499
500   mp->sw_if_index = sw_if_index;
501   clib_memcpy (mp->address, &address, sizeof (address));
502
503   S (mp);
504   W (ret);
505   return ret;
506 }
507
508 static int
509 api_ikev2_set_ike_transforms (vat_main_t * vam)
510 {
511   unformat_input_t *i = vam->input;
512   vl_api_ikev2_set_ike_transforms_t *mp;
513   int ret;
514   u8 *name = 0;
515   u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
516
517   const char *valid_chars = "a-zA-Z0-9_";
518
519   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
520     {
521       if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
522                     &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
523         vec_add1 (name, 0);
524       else
525         {
526           errmsg ("parse error '%U'", format_unformat_error, i);
527           return -99;
528         }
529     }
530
531   if (!vec_len (name))
532     {
533       errmsg ("profile name must be specified");
534       return -99;
535     }
536
537   if (vec_len (name) > 64)
538     {
539       errmsg ("profile name too long");
540       return -99;
541     }
542
543   M (IKEV2_SET_IKE_TRANSFORMS, mp);
544
545   clib_memcpy (mp->name, name, vec_len (name));
546   vec_free (name);
547   mp->crypto_alg = crypto_alg;
548   mp->crypto_key_size = crypto_key_size;
549   mp->integ_alg = integ_alg;
550   mp->dh_group = dh_group;
551
552   S (mp);
553   W (ret);
554   return ret;
555 }
556
557
558 static int
559 api_ikev2_set_esp_transforms (vat_main_t * vam)
560 {
561   unformat_input_t *i = vam->input;
562   vl_api_ikev2_set_esp_transforms_t *mp;
563   int ret;
564   u8 *name = 0;
565   u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
566
567   const char *valid_chars = "a-zA-Z0-9_";
568
569   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
570     {
571       if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
572                     &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
573         vec_add1 (name, 0);
574       else
575         {
576           errmsg ("parse error '%U'", format_unformat_error, i);
577           return -99;
578         }
579     }
580
581   if (!vec_len (name))
582     {
583       errmsg ("profile name must be specified");
584       return -99;
585     }
586
587   if (vec_len (name) > 64)
588     {
589       errmsg ("profile name too long");
590       return -99;
591     }
592
593   M (IKEV2_SET_ESP_TRANSFORMS, mp);
594
595   clib_memcpy (mp->name, name, vec_len (name));
596   vec_free (name);
597   mp->crypto_alg = crypto_alg;
598   mp->crypto_key_size = crypto_key_size;
599   mp->integ_alg = integ_alg;
600   mp->dh_group = dh_group;
601
602   S (mp);
603   W (ret);
604   return ret;
605 }
606
607 static int
608 api_ikev2_set_sa_lifetime (vat_main_t * vam)
609 {
610   unformat_input_t *i = vam->input;
611   vl_api_ikev2_set_sa_lifetime_t *mp;
612   int ret;
613   u8 *name = 0;
614   u64 lifetime, lifetime_maxdata;
615   u32 lifetime_jitter, handover;
616
617   const char *valid_chars = "a-zA-Z0-9_";
618
619   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
620     {
621       if (unformat (i, "%U %lu %u %u %lu", unformat_token, valid_chars, &name,
622                     &lifetime, &lifetime_jitter, &handover,
623                     &lifetime_maxdata))
624         vec_add1 (name, 0);
625       else
626         {
627           errmsg ("parse error '%U'", format_unformat_error, i);
628           return -99;
629         }
630     }
631
632   if (!vec_len (name))
633     {
634       errmsg ("profile name must be specified");
635       return -99;
636     }
637
638   if (vec_len (name) > 64)
639     {
640       errmsg ("profile name too long");
641       return -99;
642     }
643
644   M (IKEV2_SET_SA_LIFETIME, mp);
645
646   clib_memcpy (mp->name, name, vec_len (name));
647   vec_free (name);
648   mp->lifetime = lifetime;
649   mp->lifetime_jitter = lifetime_jitter;
650   mp->handover = handover;
651   mp->lifetime_maxdata = lifetime_maxdata;
652
653   S (mp);
654   W (ret);
655   return ret;
656 }
657
658 static int
659 api_ikev2_initiate_sa_init (vat_main_t * vam)
660 {
661   unformat_input_t *i = vam->input;
662   vl_api_ikev2_initiate_sa_init_t *mp;
663   int ret;
664   u8 *name = 0;
665
666   const char *valid_chars = "a-zA-Z0-9_";
667
668   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
669     {
670       if (unformat (i, "%U", unformat_token, valid_chars, &name))
671         vec_add1 (name, 0);
672       else
673         {
674           errmsg ("parse error '%U'", format_unformat_error, i);
675           return -99;
676         }
677     }
678
679   if (!vec_len (name))
680     {
681       errmsg ("profile name must be specified");
682       return -99;
683     }
684
685   if (vec_len (name) > 64)
686     {
687       errmsg ("profile name too long");
688       return -99;
689     }
690
691   M (IKEV2_INITIATE_SA_INIT, mp);
692
693   clib_memcpy (mp->name, name, vec_len (name));
694   vec_free (name);
695
696   S (mp);
697   W (ret);
698   return ret;
699 }
700
701 static int
702 api_ikev2_initiate_del_ike_sa (vat_main_t * vam)
703 {
704   unformat_input_t *i = vam->input;
705   vl_api_ikev2_initiate_del_ike_sa_t *mp;
706   int ret;
707   u64 ispi;
708
709
710   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
711     {
712       if (unformat (i, "%lx", &ispi))
713         ;
714       else
715         {
716           errmsg ("parse error '%U'", format_unformat_error, i);
717           return -99;
718         }
719     }
720
721   M (IKEV2_INITIATE_DEL_IKE_SA, mp);
722
723   mp->ispi = ispi;
724
725   S (mp);
726   W (ret);
727   return ret;
728 }
729
730 static int
731 api_ikev2_initiate_del_child_sa (vat_main_t * vam)
732 {
733   unformat_input_t *i = vam->input;
734   vl_api_ikev2_initiate_del_child_sa_t *mp;
735   int ret;
736   u32 ispi;
737
738
739   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
740     {
741       if (unformat (i, "%x", &ispi))
742         ;
743       else
744         {
745           errmsg ("parse error '%U'", format_unformat_error, i);
746           return -99;
747         }
748     }
749
750   M (IKEV2_INITIATE_DEL_CHILD_SA, mp);
751
752   mp->ispi = ispi;
753
754   S (mp);
755   W (ret);
756   return ret;
757 }
758
759 static int
760 api_ikev2_initiate_rekey_child_sa (vat_main_t * vam)
761 {
762   unformat_input_t *i = vam->input;
763   vl_api_ikev2_initiate_rekey_child_sa_t *mp;
764   int ret;
765   u32 ispi;
766
767
768   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
769     {
770       if (unformat (i, "%x", &ispi))
771         ;
772       else
773         {
774           errmsg ("parse error '%U'", format_unformat_error, i);
775           return -99;
776         }
777     }
778
779   M (IKEV2_INITIATE_REKEY_CHILD_SA, mp);
780
781   mp->ispi = ispi;
782
783   S (mp);
784   W (ret);
785   return ret;
786 }
787
788
789 /* List of API message constructors, CLI names map to api_xxx */
790 #define foreach_vpe_api_msg                                             \
791 _(ikev2_profile_add_del, "name <profile_name> [del]")                   \
792 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n"  \
793   "(auth_data 0x<data> | auth_data <data>)")                            \
794 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n"          \
795   "(id_data 0x<data> | id_data <data>) (local|remote)")                 \
796 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n"        \
797   "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
798   "(local|remote)")                                                     \
799 _(ikev2_set_local_key, "file <absolute_file_path>")                     \
800 _(ikev2_set_responder, "<profile_name> interface <interface> address <addr>") \
801 _(ikev2_set_ike_transforms, "<profile_name> <crypto alg> <key size> <integrity alg> <DH group>") \
802 _(ikev2_set_esp_transforms, "<profile_name> <crypto alg> <key size> <integrity alg> <DH group>") \
803 _(ikev2_set_sa_lifetime, "<profile_name> <seconds> <jitter> <handover> <max bytes>") \
804 _(ikev2_initiate_sa_init, "<profile_name>")                             \
805 _(ikev2_initiate_del_ike_sa, "<ispi>")                                  \
806 _(ikev2_initiate_del_child_sa, "<ispi>")                                \
807 _(ikev2_initiate_rekey_child_sa, "<ispi>")
808
809 static void
810 ikev2_vat_api_hookup (vat_main_t * vam)
811 {
812   ikev2_test_main_t *sm = &ikev2_test_main;
813   /* Hook up handlers for replies from the data plane plug-in */
814 #define _(N,n)                                                  \
815     vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base),     \
816                            #n,                                  \
817                            vl_api_##n##_t_handler,              \
818                            vl_noop_handler,                     \
819                            vl_api_##n##_t_endian,               \
820                            vl_api_##n##_t_print,                \
821                            sizeof(vl_api_##n##_t), 1);
822   foreach_vpe_api_reply_msg;
823 #undef _
824
825   /* API messages we can send */
826 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
827   foreach_vpe_api_msg;
828 #undef _
829
830   /* Help strings */
831 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
832   foreach_vpe_api_msg;
833 #undef _
834 }
835
836 clib_error_t *
837 vat_plugin_register (vat_main_t * vam)
838 {
839   ikev2_test_main_t *sm = &ikev2_test_main;
840   u8 *name;
841
842   sm->vat_main = vam;
843
844   name = format (0, "ikev2_%08x%c", api_version, 0);
845   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
846
847   if (sm->msg_id_base != (u16) ~ 0)
848     ikev2_vat_api_hookup (vam);
849
850   vec_free (name);
851
852   return 0;
853 }
854
855 /*
856  * fd.io coding-style-patch-verification: ON
857  *
858  * Local Variables:
859  * eval: (c-set-style "gnu")
860  * End:
861  */