Repair SNAT's IPFIX and IF-add-del test functions.
[vpp.git] / src / plugins / snat / snat_test.c
1
2 /*
3  * snat.c - skeleton vpp-api-test plug-in 
4  *
5  * Copyright (c) <current-year> <your-organization>
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 #include <vat/vat.h>
19 #include <vlibapi/api.h>
20 #include <vlibmemory/api.h>
21 #include <vlibsocket/api.h>
22 #include <vppinfra/error.h>
23 #include <vnet/ip/ip.h>
24
25 #define __plugin_msg_base snat_test_main.msg_id_base
26 #include <vlibapi/vat_helper_macros.h>
27
28 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
29
30 /* Declare message IDs */
31 #include <snat/snat_msg_enum.h>
32
33 /* define message structures */
34 #define vl_typedefs
35 #include <snat/snat_all_api_h.h> 
36 #undef vl_typedefs
37
38 /* declare message handlers for each api */
39
40 #define vl_endianfun             /* define message structures */
41 #include <snat/snat_all_api_h.h> 
42 #undef vl_endianfun
43
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...)
46 #define vl_printfun
47 #include <snat/snat_all_api_h.h> 
48 #undef vl_printfun
49
50 /* Get the API version number. */
51 #define vl_api_version(n,v) static u32 api_version=(v);
52 #include <snat/snat_all_api_h.h>
53 #undef vl_api_version
54
55 typedef struct {
56     /* API message ID base */
57     u16 msg_id_base;
58     vat_main_t *vat_main;
59 } snat_test_main_t;
60
61 snat_test_main_t snat_test_main;
62
63 #define foreach_standard_reply_retval_handler   \
64 _(snat_add_address_range_reply)                 \
65 _(snat_interface_add_del_feature_reply)         \
66 _(snat_add_static_mapping_reply)                \
67 _(snat_set_workers_reply)                       \
68 _(snat_add_del_interface_addr_reply)            \
69 _(snat_ipfix_enable_disable_reply)
70
71 #define _(n)                                            \
72     static void vl_api_##n##_t_handler                  \
73     (vl_api_##n##_t * mp)                               \
74     {                                                   \
75         vat_main_t * vam = snat_test_main.vat_main;   \
76         i32 retval = ntohl(mp->retval);                 \
77         if (vam->async_mode) {                          \
78             vam->async_errors += (retval < 0);          \
79         } else {                                        \
80             vam->retval = retval;                       \
81             vam->result_ready = 1;                      \
82         }                                               \
83     }
84 foreach_standard_reply_retval_handler;
85 #undef _
86
87 /* 
88  * Table of message reply handlers, must include boilerplate handlers
89  * we just generated
90  */
91 #define foreach_vpe_api_reply_msg                               \
92 _(SNAT_ADD_ADDRESS_RANGE_REPLY, snat_add_address_range_reply)   \
93 _(SNAT_INTERFACE_ADD_DEL_FEATURE_REPLY,                         \
94   snat_interface_add_del_feature_reply)                         \
95 _(SNAT_ADD_STATIC_MAPPING_REPLY, snat_add_static_mapping_reply) \
96 _(SNAT_CONTROL_PING_REPLY, snat_control_ping_reply)             \
97 _(SNAT_STATIC_MAPPING_DETAILS, snat_static_mapping_details)     \
98 _(SNAT_SHOW_CONFIG_REPLY, snat_show_config_reply)               \
99 _(SNAT_ADDRESS_DETAILS, snat_address_details)                   \
100 _(SNAT_INTERFACE_DETAILS, snat_interface_details)               \
101 _(SNAT_SET_WORKERS_REPLY, snat_set_workers_reply)               \
102 _(SNAT_WORKER_DETAILS, snat_worker_details)                     \
103 _(SNAT_ADD_DEL_INTERFACE_ADDR_REPLY,                            \
104   snat_add_del_interface_addr_reply)                            \
105 _(SNAT_INTERFACE_ADDR_DETAILS, snat_interface_addr_details)     \
106 _(SNAT_IPFIX_ENABLE_DISABLE_REPLY,                              \
107   snat_ipfix_enable_disable_reply)
108
109 static int api_snat_add_address_range (vat_main_t * vam)
110 {
111   unformat_input_t * i = vam->input;
112   ip4_address_t start_addr, end_addr;
113   u32 start_host_order, end_host_order;
114   vl_api_snat_add_address_range_t * mp;
115   u8 is_add = 1;
116   int count;
117   int ret;
118
119   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
120     {
121       if (unformat (i, "%U - %U",
122                     unformat_ip4_address, &start_addr,
123                     unformat_ip4_address, &end_addr))
124         ;
125       else if (unformat (i, "%U", unformat_ip4_address, &start_addr))
126         end_addr = start_addr;
127       else if (unformat (i, "del"))
128         is_add = 0;
129       else
130         {
131           clib_warning("unknown input '%U'", format_unformat_error, i);
132           return -99;
133         }
134     }
135
136   start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
137   end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
138   
139   if (end_host_order < start_host_order)
140     {
141       errmsg ("end address less than start address\n");
142       return -99;
143     }
144
145   count = (end_host_order - start_host_order) + 1;
146
147   if (count > 1024)
148     {
149     errmsg ("%U - %U, %d addresses...\n",
150            format_ip4_address, &start_addr,
151            format_ip4_address, &end_addr,
152            count);
153     }
154   
155   M(SNAT_ADD_ADDRESS_RANGE, mp);
156
157   memcpy (mp->first_ip_address, &start_addr, 4);
158   memcpy (mp->last_ip_address, &end_addr, 4);
159   mp->is_ip4 = 1;
160   mp->is_add = is_add;
161
162   S(mp);
163   W (ret);
164   return ret;
165 }
166
167 static int api_snat_interface_add_del_feature (vat_main_t * vam)
168 {
169   unformat_input_t * i = vam->input;
170   vl_api_snat_interface_add_del_feature_t * mp;
171   u32 sw_if_index;
172   u8 sw_if_index_set = 0;
173   u8 is_inside = 1; 
174   u8 is_add = 1;
175   int ret;
176
177   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
178     {
179       if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
180         sw_if_index_set = 1;
181       else if (unformat (i, "sw_if_index %d", &sw_if_index))
182         sw_if_index_set = 1;
183       else if (unformat (i, "out"))
184         is_inside = 0;
185       else if (unformat (i, "in"))
186         is_inside = 1;
187       else if (unformat (i, "del"))
188         is_add = 0;
189       else
190         {
191           clib_warning("unknown input '%U'", format_unformat_error, i);
192           return -99;
193         }
194     }
195
196   if (sw_if_index_set == 0)
197     {
198       errmsg ("interface / sw_if_index required\n");
199       return -99;
200     }
201
202   M(SNAT_INTERFACE_ADD_DEL_FEATURE, mp);
203   mp->sw_if_index = ntohl(sw_if_index);
204   mp->is_add = is_add;
205   mp->is_inside = is_inside;
206   
207   S(mp);
208   W (ret);
209   return ret;
210 }
211
212 static int api_snat_add_static_mapping(vat_main_t * vam)
213 {
214   unformat_input_t * i = vam->input;
215   vl_api_snat_add_static_mapping_t * mp;
216   u8 external_addr_set = 0;
217   u8 local_addr_set = 0;
218   u8 is_add = 1;
219   u8 addr_only = 1;
220   ip4_address_t local_addr, external_addr;
221   u32 local_port = 0, external_port = 0, vrf_id = ~0;
222   u32 sw_if_index = ~0;
223   u8 sw_if_index_set = 0;
224   u32 proto = ~0;
225   u8 proto_set = 0;
226   int ret;
227
228   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
229     {
230       if (unformat (i, "local_addr %U", unformat_ip4_address, &local_addr))
231         local_addr_set = 1;
232       else if (unformat (i, "external_addr %U", unformat_ip4_address,
233                          &external_addr))
234         external_addr_set = 1;
235       else if (unformat (i, "local_port %u", &local_port))
236         addr_only = 0;
237       else if (unformat (i, "external_port %u", &external_port))
238         addr_only = 0;
239       else if (unformat (i, "external_if %U", unformat_sw_if_index, vam,
240                          &sw_if_index))
241         sw_if_index_set = 1;
242       else if (unformat (i, "external_sw_if_index %d", &sw_if_index))
243         sw_if_index_set = 1;
244       else if (unformat (i, "vrf %u", &vrf_id))
245         ;
246       else if (unformat (i, "protocol %u", &proto))
247         proto_set = 1;
248       else if (unformat (i, "del"))
249         is_add = 0;
250       else
251         {
252           clib_warning("unknown input '%U'", format_unformat_error, i);
253           return -99;
254         }
255     }
256
257   if (!addr_only && !proto_set)
258     {
259       errmsg ("protocol required\n");
260       return -99;
261     }
262
263   if (!local_addr_set)
264     {
265       errmsg ("local addr required\n");
266       return -99;
267     }
268   if (!external_addr_set && !sw_if_index_set)
269     {
270       errmsg ("external addr or interface required\n");
271       return -99;
272     }
273
274   M(SNAT_ADD_STATIC_MAPPING, mp);
275   mp->is_add = is_add;
276   mp->is_ip4 = 1;
277   mp->addr_only = addr_only;
278   mp->local_port = ntohs ((u16) local_port);
279   mp->external_port = ntohs ((u16) external_port);
280   mp->external_sw_if_index = ntohl (sw_if_index);
281   mp->vrf_id = ntohl (vrf_id);
282   mp->protocol = (u8) proto;
283   memcpy (mp->local_ip_address, &local_addr, 4);
284   memcpy (mp->external_ip_address, &external_addr, 4);
285
286   S(mp);
287   W (ret);
288   return ret;
289 }
290
291 static void vl_api_snat_control_ping_reply_t_handler
292   (vl_api_snat_control_ping_reply_t * mp)
293 {
294   vat_main_t *vam = &vat_main;
295   i32 retval = ntohl (mp->retval);
296   if (vam->async_mode)
297     {
298       vam->async_errors += (retval < 0);
299     }
300   else
301     {
302       vam->retval = retval;
303       vam->result_ready = 1;
304     }
305 }
306
307 static void vl_api_snat_static_mapping_details_t_handler
308   (vl_api_snat_static_mapping_details_t *mp)
309 {
310   snat_test_main_t * sm = &snat_test_main;
311   vat_main_t *vam = sm->vat_main;
312
313   if (mp->addr_only && mp->external_sw_if_index != ~0)
314       fformat (vam->ofp, "%15U%6s%15d%6s%11d%6d\n",
315                format_ip4_address, &mp->local_ip_address, "",
316                ntohl (mp->external_sw_if_index), "",
317                ntohl (mp->vrf_id),
318                mp->protocol);
319   else if (mp->addr_only && mp->external_sw_if_index == ~0)
320       fformat (vam->ofp, "%15U%6s%15U%6s%11d%6d\n",
321                format_ip4_address, &mp->local_ip_address, "",
322                format_ip4_address, &mp->external_ip_address, "",
323                ntohl (mp->vrf_id),
324                mp->protocol);
325   else if (!mp->addr_only && mp->external_sw_if_index != ~0)
326       fformat (vam->ofp, "%15U%6d%15d%6d%11d%6d\n",
327                format_ip4_address, &mp->local_ip_address,
328                ntohs (mp->local_port),
329                ntohl (mp->external_sw_if_index),
330                ntohs (mp->external_port),
331                ntohl (mp->vrf_id),
332                mp->protocol);
333   else
334       fformat (vam->ofp, "%15U%6d%15U%6d%11d%6d\n",
335                format_ip4_address, &mp->local_ip_address,
336                ntohs (mp->local_port),
337                format_ip4_address, &mp->external_ip_address,
338                ntohs (mp->external_port),
339                ntohl (mp->vrf_id),
340                mp->protocol);
341
342 }
343
344 static int api_snat_static_mapping_dump(vat_main_t * vam)
345 {
346   vl_api_snat_static_mapping_dump_t * mp;
347   vl_api_snat_control_ping_t *mp_ping;
348   int ret;
349
350   if (vam->json_output)
351     {
352       clib_warning ("JSON output not supported for snat_static_mapping_dump");
353       return -99;
354     }
355
356   fformat (vam->ofp, "%21s%21s\n", "local", "external");
357   fformat (vam->ofp, "%15s%6s%15s%6s%11s%6s\n", "address", "port",
358            "address/if_idx", "port", "vrf", "proto");
359
360   M(SNAT_STATIC_MAPPING_DUMP, mp);
361   S(mp);
362
363   /* Use a control ping for synchronization */
364   M(SNAT_CONTROL_PING, mp_ping);
365   S(mp_ping);
366
367   W (ret);
368   return ret;
369 }
370
371 static void vl_api_snat_show_config_reply_t_handler
372   (vl_api_snat_show_config_reply_t *mp)
373 {
374   snat_test_main_t * sm = &snat_test_main;
375   vat_main_t *vam = sm->vat_main;
376   i32 retval = ntohl (mp->retval);
377
378   if (retval >= 0)
379     {
380       fformat (vam->ofp, "translation hash buckets %d\n",
381                ntohl (mp->translation_buckets));
382       fformat (vam->ofp, "translation hash memory %d\n",
383                ntohl (mp->translation_memory_size));
384       fformat (vam->ofp, "user hash buckets %d\n", ntohl (mp->user_buckets));
385       fformat (vam->ofp, "user hash memory %d\n", ntohl (mp->user_memory_size));
386       fformat (vam->ofp, "max translations per user %d\n",
387                ntohl (mp->max_translations_per_user));
388       fformat (vam->ofp, "outside VRF id %d\n", ntohl (mp->outside_vrf_id));
389       fformat (vam->ofp, "inside VRF id %d\n", ntohl (mp->inside_vrf_id));
390       if (mp->static_mapping_only)
391         {
392           fformat (vam->ofp, "static mapping only");
393           if (mp->static_mapping_connection_tracking)
394             fformat (vam->ofp, " connection tracking");
395           fformat (vam->ofp, "\n");
396         }
397     }
398   vam->retval = retval;
399   vam->result_ready = 1;
400 }
401
402 static int api_snat_show_config(vat_main_t * vam)
403 {
404   vl_api_snat_show_config_t * mp;
405   int ret;
406
407   if (vam->json_output)
408     {
409       clib_warning ("JSON output not supported for snat_show_config");
410       return -99;
411     }
412
413   M(SNAT_SHOW_CONFIG, mp);
414   S(mp);
415   W (ret);
416   return ret;
417 }
418
419 static void vl_api_snat_address_details_t_handler
420   (vl_api_snat_address_details_t *mp)
421 {
422   snat_test_main_t * sm = &snat_test_main;
423   vat_main_t *vam = sm->vat_main;
424
425   fformat (vam->ofp, "%U\n", format_ip4_address, &mp->ip_address);
426 }
427
428 static int api_snat_address_dump(vat_main_t * vam)
429 {
430   vl_api_snat_address_dump_t * mp;
431   vl_api_snat_control_ping_t *mp_ping;
432   int ret;
433
434   if (vam->json_output)
435     {
436       clib_warning ("JSON output not supported for snat_address_dump");
437       return -99;
438     }
439
440   M(SNAT_ADDRESS_DUMP, mp);
441   S(mp);
442
443   /* Use a control ping for synchronization */
444   M(SNAT_CONTROL_PING, mp_ping);
445   S(mp_ping);
446
447   W (ret);
448   return ret;
449 }
450
451 static void vl_api_snat_interface_details_t_handler
452   (vl_api_snat_interface_details_t *mp)
453 {
454   snat_test_main_t * sm = &snat_test_main;
455   vat_main_t *vam = sm->vat_main;
456
457   fformat (vam->ofp, "sw_if_index %d %s\n", ntohl (mp->sw_if_index),
458            mp->is_inside ? "in" : "out");
459 }
460
461 static int api_snat_interface_dump(vat_main_t * vam)
462 {
463   vl_api_snat_interface_dump_t * mp;
464   vl_api_snat_control_ping_t *mp_ping;
465   int ret;
466
467   if (vam->json_output)
468     {
469       clib_warning ("JSON output not supported for snat_address_dump");
470       return -99;
471     }
472
473   M(SNAT_INTERFACE_DUMP, mp);
474   S(mp);
475
476   /* Use a control ping for synchronization */
477   M(SNAT_CONTROL_PING, mp_ping);
478   S(mp_ping);
479
480   W (ret);
481   return ret;
482 }
483
484 static int api_snat_set_workers (vat_main_t * vam)
485 {
486   unformat_input_t * i = vam->input;
487   vl_api_snat_set_workers_t * mp;
488   uword *bitmap;
489   int ret;
490
491   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
492     {
493       if (unformat (i, "%U", unformat_bitmap_list, &bitmap))
494         ;
495       else
496         {
497           clib_warning("unknown input '%U'", format_unformat_error, i);
498           return -99;
499         }
500     }
501
502   M(SNAT_SET_WORKERS, mp);
503   mp->worker_mask = clib_host_to_net_u64 (bitmap[0]);
504
505   S(mp);
506   W (ret);
507   return ret;
508 }
509
510 static void vl_api_snat_worker_details_t_handler
511   (vl_api_snat_worker_details_t *mp)
512 {
513   snat_test_main_t * sm = &snat_test_main;
514   vat_main_t *vam = sm->vat_main;
515
516   fformat (vam->ofp, "worker_index %d (%s at lcore %u)\n",
517            ntohl (mp->worker_index), mp->name, ntohl (mp->lcore_id));
518 }
519
520 static int api_snat_worker_dump(vat_main_t * vam)
521 {
522   vl_api_snat_worker_dump_t * mp;
523   vl_api_snat_control_ping_t *mp_ping;
524   int ret;
525
526   if (vam->json_output)
527     {
528       clib_warning ("JSON output not supported for snat_address_dump");
529       return -99;
530     }
531
532   M(SNAT_WORKER_DUMP, mp);
533   S(mp);
534
535   /* Use a control ping for synchronization */
536   M(SNAT_CONTROL_PING, mp_ping);
537   S(mp_ping);
538
539   W (ret);
540   return ret;
541 }
542
543 static int api_snat_add_del_interface_addr (vat_main_t * vam)
544 {
545   unformat_input_t * i = vam->input;
546   vl_api_snat_add_del_interface_addr_t * mp;
547   u32 sw_if_index;
548   u8 sw_if_index_set = 0;
549   u8 is_add = 1;
550   int ret;
551
552   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
553     {
554       if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
555         sw_if_index_set = 1;
556       else if (unformat (i, "sw_if_index %d", &sw_if_index))
557         sw_if_index_set = 1;
558       else if (unformat (i, "del"))
559         is_add = 0;
560       else
561         {
562           clib_warning("unknown input '%U'", format_unformat_error, i);
563           return -99;
564         }
565     }
566
567   if (sw_if_index_set == 0)
568     {
569       errmsg ("interface / sw_if_index required\n");
570       return -99;
571     }
572
573   M(SNAT_ADD_DEL_INTERFACE_ADDR, mp);
574   mp->sw_if_index = ntohl(sw_if_index);
575   mp->is_add = is_add;
576   
577   S(mp);
578   W (ret);
579   return ret;
580 }
581
582 static void vl_api_snat_interface_addr_details_t_handler
583   (vl_api_snat_interface_addr_details_t *mp)
584 {
585   snat_test_main_t * sm = &snat_test_main;
586   vat_main_t *vam = sm->vat_main;
587
588   fformat (vam->ofp, "sw_if_index %d\n", ntohl (mp->sw_if_index));
589 }
590
591 static int api_snat_interface_addr_dump(vat_main_t * vam)
592 {
593   vl_api_snat_interface_addr_dump_t * mp;
594   vl_api_snat_control_ping_t *mp_ping;
595   int ret;
596
597   if (vam->json_output)
598     {
599       clib_warning ("JSON output not supported for snat_address_dump");
600       return -99;
601     }
602
603   M(SNAT_INTERFACE_ADDR_DUMP, mp);
604   S(mp);
605
606   /* Use a control ping for synchronization */
607   M(SNAT_CONTROL_PING, mp_ping);
608   S(mp_ping);
609
610   W (ret);
611   return ret;
612 }
613
614 static int api_snat_ipfix_enable_disable (vat_main_t * vam)
615 {
616   unformat_input_t * i = vam->input;
617   vl_api_snat_ipfix_enable_disable_t * mp;
618   u32 domain_id = 0;
619   u32 src_port = 0;
620   u8 enable = 1;
621   int ret;
622
623   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
624     {
625       if (unformat (i, "domain %d", &domain_id))
626         ;
627       else if (unformat (i, "src_port %d", &src_port))
628         ;
629       else if (unformat (i, "disable"))
630         enable = 0;
631       else
632         {
633           clib_warning("unknown input '%U'", format_unformat_error, i);
634           return -99;
635         }
636     }
637
638   M(SNAT_IPFIX_ENABLE_DISABLE, mp);
639   mp->domain_id = htonl(domain_id);
640   mp->src_port = htons((u16) src_port);
641   mp->enable = enable;
642
643   S(mp);
644   W (ret);
645   return ret;
646 }
647
648 /* 
649  * List of messages that the api test plugin sends,
650  * and that the data plane plugin processes
651  */
652 #define foreach_vpe_api_msg                                      \
653 _(snat_add_address_range, "<start-addr> [- <end-addr] [del]")    \
654 _(snat_interface_add_del_feature,                                \
655   "<intfc> | sw_if_index <id> [in] [out] [del]")                 \
656 _(snat_add_static_mapping, "local_addr <ip> (external_addr <ip>" \
657   " | external_if <intfc> | external_sw_if_ndex <id>) "          \
658   "[local_port <n>] [external_port <n>] [vrf <table-id>] [del] " \
659   "protocol <n>")                                                \
660 _(snat_set_workers, "<wokrers_bitmap>")                          \
661 _(snat_static_mapping_dump, "")                                  \
662 _(snat_show_config, "")                                          \
663 _(snat_address_dump, "")                                         \
664 _(snat_interface_dump, "")                                       \
665 _(snat_worker_dump, "")                                          \
666 _(snat_add_del_interface_addr,                                   \
667   "<intfc> | sw_if_index <id> [del]")                            \
668 _(snat_interface_addr_dump, "")                                  \
669 _(snat_ipfix_enable_disable, "[domain <id>] [src_port <n>] "     \
670   "[disable]")
671
672 static void 
673 snat_vat_api_hookup (vat_main_t *vam)
674 {
675   snat_test_main_t * sm __attribute__((unused)) = &snat_test_main;
676   /* Hook up handlers for replies from the data plane plug-in */
677 #define _(N,n)                                                  \
678   vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base),       \
679                           #n,                                   \
680                           vl_api_##n##_t_handler,               \
681                           vl_noop_handler,                      \
682                           vl_api_##n##_t_endian,                \
683                           vl_api_##n##_t_print,                 \
684                           sizeof(vl_api_##n##_t), 1); 
685   foreach_vpe_api_reply_msg;
686 #undef _
687
688   /* API messages we can send */
689 #define _(n,h)                                          \
690   hash_set_mem (vam->function_by_name, #n, api_##n);    \
691   clib_warning ("vam %llx add '%s' handler %llx", vam, #n, api_##n);
692   foreach_vpe_api_msg;
693 #undef _    
694     
695   /* Help strings */
696 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
697   foreach_vpe_api_msg;
698 #undef _
699 }
700
701 clib_error_t * vat_plugin_register (vat_main_t *vam)
702 {
703   snat_test_main_t * sm = &snat_test_main;
704   u8 * name;
705
706   sm->vat_main = vam;
707
708   /* Ask the vpp engine for the first assigned message-id */
709   name = format (0, "snat_%08x%c", api_version, 0);
710   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
711
712   if (sm->msg_id_base != (u16) ~0)
713     snat_vat_api_hookup (vam);
714   
715   vec_free(name);
716   
717   return 0;
718 }