3 * snat.c - skeleton vpp-api-test plug-in
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
25 #define __plugin_msg_base snat_test_main.msg_id_base
26 #include <vlibapi/vat_helper_macros.h>
28 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
30 /* Declare message IDs */
31 #include <snat/snat_msg_enum.h>
33 /* define message structures */
35 #include <snat/snat_all_api_h.h>
38 /* declare message handlers for each api */
40 #define vl_endianfun /* define message structures */
41 #include <snat/snat_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...)
47 #include <snat/snat_all_api_h.h>
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>
56 /* API message ID base */
61 snat_test_main_t snat_test_main;
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 _(snat_add_det_map_reply)
73 static void vl_api_##n##_t_handler \
74 (vl_api_##n##_t * mp) \
76 vat_main_t * vam = snat_test_main.vat_main; \
77 i32 retval = ntohl(mp->retval); \
78 if (vam->async_mode) { \
79 vam->async_errors += (retval < 0); \
81 vam->retval = retval; \
82 vam->result_ready = 1; \
85 foreach_standard_reply_retval_handler;
89 * Table of message reply handlers, must include boilerplate handlers
92 #define foreach_vpe_api_reply_msg \
93 _(SNAT_ADD_ADDRESS_RANGE_REPLY, snat_add_address_range_reply) \
94 _(SNAT_INTERFACE_ADD_DEL_FEATURE_REPLY, \
95 snat_interface_add_del_feature_reply) \
96 _(SNAT_ADD_STATIC_MAPPING_REPLY, snat_add_static_mapping_reply) \
97 _(SNAT_CONTROL_PING_REPLY, snat_control_ping_reply) \
98 _(SNAT_STATIC_MAPPING_DETAILS, snat_static_mapping_details) \
99 _(SNAT_SHOW_CONFIG_REPLY, snat_show_config_reply) \
100 _(SNAT_ADDRESS_DETAILS, snat_address_details) \
101 _(SNAT_INTERFACE_DETAILS, snat_interface_details) \
102 _(SNAT_SET_WORKERS_REPLY, snat_set_workers_reply) \
103 _(SNAT_WORKER_DETAILS, snat_worker_details) \
104 _(SNAT_ADD_DEL_INTERFACE_ADDR_REPLY, \
105 snat_add_del_interface_addr_reply) \
106 _(SNAT_INTERFACE_ADDR_DETAILS, snat_interface_addr_details) \
107 _(SNAT_IPFIX_ENABLE_DISABLE_REPLY, \
108 snat_ipfix_enable_disable_reply) \
109 _(SNAT_USER_DETAILS, snat_user_details) \
110 _(SNAT_USER_SESSION_DETAILS, snat_user_session_details) \
111 _(SNAT_ADD_DET_MAP_REPLY, snat_add_det_map_reply) \
112 _(SNAT_DET_FORWARD_REPLY, snat_det_forward_reply) \
113 _(SNAT_DET_REVERSE_REPLY, snat_det_reverse_reply) \
114 _(SNAT_DET_MAP_DETAILS, snat_det_map_details)
116 static int api_snat_add_address_range (vat_main_t * vam)
118 unformat_input_t * i = vam->input;
119 ip4_address_t start_addr, end_addr;
120 u32 start_host_order, end_host_order;
121 vl_api_snat_add_address_range_t * mp;
126 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
128 if (unformat (i, "%U - %U",
129 unformat_ip4_address, &start_addr,
130 unformat_ip4_address, &end_addr))
132 else if (unformat (i, "%U", unformat_ip4_address, &start_addr))
133 end_addr = start_addr;
134 else if (unformat (i, "del"))
138 clib_warning("unknown input '%U'", format_unformat_error, i);
143 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
144 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
146 if (end_host_order < start_host_order)
148 errmsg ("end address less than start address\n");
152 count = (end_host_order - start_host_order) + 1;
156 errmsg ("%U - %U, %d addresses...\n",
157 format_ip4_address, &start_addr,
158 format_ip4_address, &end_addr,
162 M(SNAT_ADD_ADDRESS_RANGE, mp);
164 memcpy (mp->first_ip_address, &start_addr, 4);
165 memcpy (mp->last_ip_address, &end_addr, 4);
174 static int api_snat_interface_add_del_feature (vat_main_t * vam)
176 unformat_input_t * i = vam->input;
177 vl_api_snat_interface_add_del_feature_t * mp;
179 u8 sw_if_index_set = 0;
184 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
186 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
188 else if (unformat (i, "sw_if_index %d", &sw_if_index))
190 else if (unformat (i, "out"))
192 else if (unformat (i, "in"))
194 else if (unformat (i, "del"))
198 clib_warning("unknown input '%U'", format_unformat_error, i);
203 if (sw_if_index_set == 0)
205 errmsg ("interface / sw_if_index required\n");
209 M(SNAT_INTERFACE_ADD_DEL_FEATURE, mp);
210 mp->sw_if_index = ntohl(sw_if_index);
212 mp->is_inside = is_inside;
219 static int api_snat_add_static_mapping(vat_main_t * vam)
221 unformat_input_t * i = vam->input;
222 vl_api_snat_add_static_mapping_t * mp;
223 u8 external_addr_set = 0;
224 u8 local_addr_set = 0;
227 ip4_address_t local_addr, external_addr;
228 u32 local_port = 0, external_port = 0, vrf_id = ~0;
229 u32 sw_if_index = ~0;
230 u8 sw_if_index_set = 0;
235 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
237 if (unformat (i, "local_addr %U", unformat_ip4_address, &local_addr))
239 else if (unformat (i, "external_addr %U", unformat_ip4_address,
241 external_addr_set = 1;
242 else if (unformat (i, "local_port %u", &local_port))
244 else if (unformat (i, "external_port %u", &external_port))
246 else if (unformat (i, "external_if %U", unformat_sw_if_index, vam,
249 else if (unformat (i, "external_sw_if_index %d", &sw_if_index))
251 else if (unformat (i, "vrf %u", &vrf_id))
253 else if (unformat (i, "protocol %u", &proto))
255 else if (unformat (i, "del"))
259 clib_warning("unknown input '%U'", format_unformat_error, i);
264 if (!addr_only && !proto_set)
266 errmsg ("protocol required\n");
272 errmsg ("local addr required\n");
275 if (!external_addr_set && !sw_if_index_set)
277 errmsg ("external addr or interface required\n");
281 M(SNAT_ADD_STATIC_MAPPING, mp);
284 mp->addr_only = addr_only;
285 mp->local_port = ntohs ((u16) local_port);
286 mp->external_port = ntohs ((u16) external_port);
287 mp->external_sw_if_index = ntohl (sw_if_index);
288 mp->vrf_id = ntohl (vrf_id);
289 mp->protocol = (u8) proto;
290 memcpy (mp->local_ip_address, &local_addr, 4);
291 memcpy (mp->external_ip_address, &external_addr, 4);
298 static void vl_api_snat_control_ping_reply_t_handler
299 (vl_api_snat_control_ping_reply_t * mp)
301 vat_main_t *vam = &vat_main;
302 i32 retval = ntohl (mp->retval);
305 vam->async_errors += (retval < 0);
309 vam->retval = retval;
310 vam->result_ready = 1;
314 static void vl_api_snat_static_mapping_details_t_handler
315 (vl_api_snat_static_mapping_details_t *mp)
317 snat_test_main_t * sm = &snat_test_main;
318 vat_main_t *vam = sm->vat_main;
320 if (mp->addr_only && mp->external_sw_if_index != ~0)
321 fformat (vam->ofp, "%15U%6s%15d%6s%11d%6d\n",
322 format_ip4_address, &mp->local_ip_address, "",
323 ntohl (mp->external_sw_if_index), "",
326 else if (mp->addr_only && mp->external_sw_if_index == ~0)
327 fformat (vam->ofp, "%15U%6s%15U%6s%11d%6d\n",
328 format_ip4_address, &mp->local_ip_address, "",
329 format_ip4_address, &mp->external_ip_address, "",
332 else if (!mp->addr_only && mp->external_sw_if_index != ~0)
333 fformat (vam->ofp, "%15U%6d%15d%6d%11d%6d\n",
334 format_ip4_address, &mp->local_ip_address,
335 ntohs (mp->local_port),
336 ntohl (mp->external_sw_if_index),
337 ntohs (mp->external_port),
341 fformat (vam->ofp, "%15U%6d%15U%6d%11d%6d\n",
342 format_ip4_address, &mp->local_ip_address,
343 ntohs (mp->local_port),
344 format_ip4_address, &mp->external_ip_address,
345 ntohs (mp->external_port),
351 static int api_snat_static_mapping_dump(vat_main_t * vam)
353 vl_api_snat_static_mapping_dump_t * mp;
354 vl_api_snat_control_ping_t *mp_ping;
357 if (vam->json_output)
359 clib_warning ("JSON output not supported for snat_static_mapping_dump");
363 fformat (vam->ofp, "%21s%21s\n", "local", "external");
364 fformat (vam->ofp, "%15s%6s%15s%6s%11s%6s\n", "address", "port",
365 "address/if_idx", "port", "vrf", "proto");
367 M(SNAT_STATIC_MAPPING_DUMP, mp);
370 /* Use a control ping for synchronization */
371 M(SNAT_CONTROL_PING, mp_ping);
378 static void vl_api_snat_show_config_reply_t_handler
379 (vl_api_snat_show_config_reply_t *mp)
381 snat_test_main_t * sm = &snat_test_main;
382 vat_main_t *vam = sm->vat_main;
383 i32 retval = ntohl (mp->retval);
387 fformat (vam->ofp, "translation hash buckets %d\n",
388 ntohl (mp->translation_buckets));
389 fformat (vam->ofp, "translation hash memory %d\n",
390 ntohl (mp->translation_memory_size));
391 fformat (vam->ofp, "user hash buckets %d\n", ntohl (mp->user_buckets));
392 fformat (vam->ofp, "user hash memory %d\n", ntohl (mp->user_memory_size));
393 fformat (vam->ofp, "max translations per user %d\n",
394 ntohl (mp->max_translations_per_user));
395 fformat (vam->ofp, "outside VRF id %d\n", ntohl (mp->outside_vrf_id));
396 fformat (vam->ofp, "inside VRF id %d\n", ntohl (mp->inside_vrf_id));
397 if (mp->static_mapping_only)
399 fformat (vam->ofp, "static mapping only");
400 if (mp->static_mapping_connection_tracking)
401 fformat (vam->ofp, " connection tracking");
402 fformat (vam->ofp, "\n");
405 vam->retval = retval;
406 vam->result_ready = 1;
409 static int api_snat_show_config(vat_main_t * vam)
411 vl_api_snat_show_config_t * mp;
414 if (vam->json_output)
416 clib_warning ("JSON output not supported for snat_show_config");
420 M(SNAT_SHOW_CONFIG, mp);
426 static void vl_api_snat_address_details_t_handler
427 (vl_api_snat_address_details_t *mp)
429 snat_test_main_t * sm = &snat_test_main;
430 vat_main_t *vam = sm->vat_main;
432 fformat (vam->ofp, "%U\n", format_ip4_address, &mp->ip_address);
435 static int api_snat_address_dump(vat_main_t * vam)
437 vl_api_snat_address_dump_t * mp;
438 vl_api_snat_control_ping_t *mp_ping;
441 if (vam->json_output)
443 clib_warning ("JSON output not supported for snat_address_dump");
447 M(SNAT_ADDRESS_DUMP, mp);
450 /* Use a control ping for synchronization */
451 M(SNAT_CONTROL_PING, mp_ping);
458 static void vl_api_snat_interface_details_t_handler
459 (vl_api_snat_interface_details_t *mp)
461 snat_test_main_t * sm = &snat_test_main;
462 vat_main_t *vam = sm->vat_main;
464 fformat (vam->ofp, "sw_if_index %d %s\n", ntohl (mp->sw_if_index),
465 mp->is_inside ? "in" : "out");
468 static int api_snat_interface_dump(vat_main_t * vam)
470 vl_api_snat_interface_dump_t * mp;
471 vl_api_snat_control_ping_t *mp_ping;
474 if (vam->json_output)
476 clib_warning ("JSON output not supported for snat_address_dump");
480 M(SNAT_INTERFACE_DUMP, mp);
483 /* Use a control ping for synchronization */
484 M(SNAT_CONTROL_PING, mp_ping);
491 static int api_snat_set_workers (vat_main_t * vam)
493 unformat_input_t * i = vam->input;
494 vl_api_snat_set_workers_t * mp;
498 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
500 if (unformat (i, "%U", unformat_bitmap_list, &bitmap))
504 clib_warning("unknown input '%U'", format_unformat_error, i);
509 M(SNAT_SET_WORKERS, mp);
510 mp->worker_mask = clib_host_to_net_u64 (bitmap[0]);
517 static void vl_api_snat_worker_details_t_handler
518 (vl_api_snat_worker_details_t *mp)
520 snat_test_main_t * sm = &snat_test_main;
521 vat_main_t *vam = sm->vat_main;
523 fformat (vam->ofp, "worker_index %d (%s at lcore %u)\n",
524 ntohl (mp->worker_index), mp->name, ntohl (mp->lcore_id));
527 static int api_snat_worker_dump(vat_main_t * vam)
529 vl_api_snat_worker_dump_t * mp;
530 vl_api_snat_control_ping_t *mp_ping;
533 if (vam->json_output)
535 clib_warning ("JSON output not supported for snat_address_dump");
539 M(SNAT_WORKER_DUMP, mp);
542 /* Use a control ping for synchronization */
543 M(SNAT_CONTROL_PING, mp_ping);
550 static int api_snat_add_del_interface_addr (vat_main_t * vam)
552 unformat_input_t * i = vam->input;
553 vl_api_snat_add_del_interface_addr_t * mp;
555 u8 sw_if_index_set = 0;
559 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
561 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
563 else if (unformat (i, "sw_if_index %d", &sw_if_index))
565 else if (unformat (i, "del"))
569 clib_warning("unknown input '%U'", format_unformat_error, i);
574 if (sw_if_index_set == 0)
576 errmsg ("interface / sw_if_index required\n");
580 M(SNAT_ADD_DEL_INTERFACE_ADDR, mp);
581 mp->sw_if_index = ntohl(sw_if_index);
589 static void vl_api_snat_interface_addr_details_t_handler
590 (vl_api_snat_interface_addr_details_t *mp)
592 snat_test_main_t * sm = &snat_test_main;
593 vat_main_t *vam = sm->vat_main;
595 fformat (vam->ofp, "sw_if_index %d\n", ntohl (mp->sw_if_index));
598 static int api_snat_interface_addr_dump(vat_main_t * vam)
600 vl_api_snat_interface_addr_dump_t * mp;
601 vl_api_snat_control_ping_t *mp_ping;
604 if (vam->json_output)
606 clib_warning ("JSON output not supported for snat_address_dump");
610 M(SNAT_INTERFACE_ADDR_DUMP, mp);
613 /* Use a control ping for synchronization */
614 M(SNAT_CONTROL_PING, mp_ping);
621 static int api_snat_ipfix_enable_disable (vat_main_t * vam)
623 unformat_input_t * i = vam->input;
624 vl_api_snat_ipfix_enable_disable_t * mp;
630 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
632 if (unformat (i, "domain %d", &domain_id))
634 else if (unformat (i, "src_port %d", &src_port))
636 else if (unformat (i, "disable"))
640 clib_warning("unknown input '%U'", format_unformat_error, i);
645 M(SNAT_IPFIX_ENABLE_DISABLE, mp);
646 mp->domain_id = htonl(domain_id);
647 mp->src_port = htons((u16) src_port);
655 static void vl_api_snat_user_session_details_t_handler
656 (vl_api_snat_user_session_details_t *mp)
658 snat_test_main_t * sm = &snat_test_main;
659 vat_main_t *vam = sm->vat_main;
661 fformat(vam->ofp, "%s session %U:%d to %U:%d protocol id %d "
662 "total packets %d total bytes %d\n",
663 mp->is_static ? "static" : "dynamic",
664 format_ip4_address, mp->inside_ip_address, ntohl(mp->inside_port),
665 format_ip4_address, mp->outside_ip_address, ntohl(mp->outside_port),
666 ntohl(mp->protocol), ntohl(mp->total_pkts), ntohl(mp->total_bytes));
669 static int api_snat_user_session_dump(vat_main_t * vam)
671 unformat_input_t* i = vam->input;
672 vl_api_snat_user_session_dump_t * mp;
673 vl_api_snat_control_ping_t *mp_ping;
678 if (vam->json_output)
680 clib_warning ("JSON output not supported for snat_address_dump");
684 if (unformat (i, "ip_address %U vrf_id %d",
685 unformat_ip4_address, &addr, &vrf_id))
689 clib_warning("unknown input '%U'", format_unformat_error, i);
693 M(SNAT_USER_SESSION_DUMP, mp);
696 /* Use a control ping for synchronization */
697 M(SNAT_CONTROL_PING, mp_ping);
698 memset(mp->ip_address, 0, 16);
699 clib_memcpy(mp->ip_address, &addr, 4);
700 mp->vrf_id = htonl(vrf_id);
708 static void vl_api_snat_user_details_t_handler
709 (vl_api_snat_user_details_t *mp)
711 snat_test_main_t * sm = &snat_test_main;
712 vat_main_t *vam = sm->vat_main;
714 fformat(vam->ofp, "user with ip %U with vrf_id %d "
715 "with %d sessions and %d static sessions\n",
716 format_ip4_address, mp->ip_address, ntohl(mp->vrf_id),
717 ntohl(mp->nsessions), ntohl(mp->nstaticsessions));
720 static int api_snat_user_dump(vat_main_t * vam)
722 vl_api_snat_user_dump_t * mp;
723 vl_api_snat_control_ping_t *mp_ping;
726 if (vam->json_output)
728 clib_warning ("JSON output not supported for snat_address_dump");
732 M(SNAT_USER_DUMP, mp);
735 /* Use a control ping for synchronization */
736 M(SNAT_CONTROL_PING, mp_ping);
743 static int api_snat_add_det_map (vat_main_t * vam)
745 unformat_input_t * i = vam->input;
746 vl_api_snat_add_det_map_t * mp;
747 ip4_address_t in_addr, out_addr;
748 u32 in_plen, out_plen;
752 if (unformat (i, "in %U/%d out %U/%d",
753 unformat_ip4_address, &in_addr, &in_plen,
754 unformat_ip4_address, &out_addr, &out_plen))
756 else if (unformat (i, "del"))
760 clib_warning("unknown input '%U'", format_unformat_error, i);
764 M(SNAT_ADD_DET_MAP, mp);
765 clib_memcpy(mp->in_addr, &in_addr, 4);
766 mp->in_plen = in_plen;
767 clib_memcpy(mp->out_addr, &out_addr, 4);
768 mp->out_plen = out_plen;
776 static void vl_api_snat_det_forward_reply_t_handler
777 (vl_api_snat_det_forward_reply_t *mp)
779 snat_test_main_t * sm = &snat_test_main;
780 vat_main_t *vam = sm->vat_main;
781 i32 retval = ntohl(mp->retval);
785 fformat (vam->ofp, "outside address %U", format_ip4_address, &mp->out_addr);
786 fformat (vam->ofp, " outside port range start %d", ntohs(mp->out_port_lo));
787 fformat (vam->ofp, " outside port range end %d\n", ntohs(mp->out_port_hi));
790 vam->retval = retval;
791 vam->result_ready = 1;
794 static int api_snat_det_forward (vat_main_t * vam)
796 unformat_input_t * i = vam->input;
797 vl_api_snat_det_forward_t * mp;
798 ip4_address_t in_addr;
801 if (unformat (i, "%U", unformat_ip4_address, &in_addr))
805 clib_warning("unknown input '%U'", format_unformat_error, i);
809 M(SNAT_DET_FORWARD, mp);
810 clib_memcpy(mp->in_addr, &in_addr, 4);
817 static void vl_api_snat_det_reverse_reply_t_handler
818 (vl_api_snat_det_reverse_reply_t *mp)
820 snat_test_main_t * sm = &snat_test_main;
821 vat_main_t *vam = sm->vat_main;
822 i32 retval = ntohl(mp->retval);
826 fformat (vam->ofp, "inside address %U\n", format_ip4_address, &mp->in_addr);
829 vam->retval = retval;
830 vam->result_ready = 1;
833 static int api_snat_det_reverse (vat_main_t * vam)
835 unformat_input_t * i = vam->input;
836 vl_api_snat_det_reverse_t * mp;
837 ip4_address_t out_addr;
841 if (unformat (i, "%U %d", unformat_ip4_address, &out_addr, &out_port))
845 clib_warning("unknown input '%U'", format_unformat_error, i);
849 M(SNAT_DET_REVERSE, mp);
850 clib_memcpy(mp->out_addr, &out_addr, 4);
851 mp->out_port = htons(out_port);
858 static void vl_api_snat_det_map_details_t_handler
859 (vl_api_snat_det_map_details_t *mp)
861 snat_test_main_t * sm = &snat_test_main;
862 vat_main_t *vam = sm->vat_main;
864 fformat (vam->ofp, "Deterministic S-NAT mapping in %U/%d out %U/%d "
865 "ports per host %d sharing ratio %d "
866 "number of sessions %d",
867 format_ip4_address, mp->in_addr, mp->in_plen,
868 format_ip4_address, mp->out_addr, mp->out_plen,
869 ntohs(mp->ports_per_host), ntohl(mp->sharing_ratio),
873 static int api_snat_det_map_dump(vat_main_t * vam)
875 vl_api_snat_det_map_dump_t * mp;
876 vl_api_snat_control_ping_t *mp_ping;
879 if (vam->json_output)
881 clib_warning ("JSON output not supported for snat_det_map_dump");
885 M(SNAT_DET_MAP_DUMP, mp);
888 /* Use a control ping for synchronization */
889 M(SNAT_CONTROL_PING, mp_ping);
897 * List of messages that the api test plugin sends,
898 * and that the data plane plugin processes
900 #define foreach_vpe_api_msg \
901 _(snat_add_address_range, "<start-addr> [- <end-addr] [del]") \
902 _(snat_interface_add_del_feature, \
903 "<intfc> | sw_if_index <id> [in] [out] [del]") \
904 _(snat_add_static_mapping, "local_addr <ip> (external_addr <ip>" \
905 " | external_if <intfc> | external_sw_if_ndex <id>) " \
906 "[local_port <n>] [external_port <n>] [vrf <table-id>] [del] " \
908 _(snat_set_workers, "<wokrers_bitmap>") \
909 _(snat_static_mapping_dump, "") \
910 _(snat_show_config, "") \
911 _(snat_address_dump, "") \
912 _(snat_interface_dump, "") \
913 _(snat_worker_dump, "") \
914 _(snat_add_del_interface_addr, \
915 "<intfc> | sw_if_index <id> [del]") \
916 _(snat_interface_addr_dump, "") \
917 _(snat_ipfix_enable_disable, "[domain <id>] [src_port <n>] " \
919 _(snat_user_dump, "") \
920 _(snat_user_session_dump, "ip_address <ip> vrf_id <table-id>") \
921 _(snat_add_det_map, "in <in_addr>/<in_plen> out " \
922 "<out_addr>/<out_plen> [del]") \
923 _(snat_det_forward, "<in_addr>") \
924 _(snat_det_reverse, "<out_addr> <out_port>") \
925 _(snat_det_map_dump, "")
928 snat_vat_api_hookup (vat_main_t *vam)
930 snat_test_main_t * sm __attribute__((unused)) = &snat_test_main;
931 /* Hook up handlers for replies from the data plane plug-in */
933 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
935 vl_api_##n##_t_handler, \
937 vl_api_##n##_t_endian, \
938 vl_api_##n##_t_print, \
939 sizeof(vl_api_##n##_t), 1);
940 foreach_vpe_api_reply_msg;
943 /* API messages we can send */
945 hash_set_mem (vam->function_by_name, #n, api_##n);
950 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
955 clib_error_t * vat_plugin_register (vat_main_t *vam)
957 snat_test_main_t * sm = &snat_test_main;
962 /* Ask the vpp engine for the first assigned message-id */
963 name = format (0, "snat_%08x%c", api_version, 0);
964 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
966 if (sm->msg_id_base != (u16) ~0)
967 snat_vat_api_hookup (vam);