2 * nat.c - skeleton vpp-api-test plug-in
4 * Copyright (c) <current-year> <your-organization>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
21 #include <vppinfra/error.h>
22 #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 <nat/nat_msg_enum.h>
33 /* define message structures */
35 #include <nat/nat_all_api_h.h>
38 /* declare message handlers for each api */
40 #define vl_endianfun /* define message structures */
41 #include <nat/nat_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...)
47 #include <nat/nat_all_api_h.h>
50 /* Get the API version number. */
51 #define vl_api_version(n,v) static u32 api_version=(v);
52 #include <nat/nat_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 _(nat44_add_del_address_range_reply) \
65 _(nat44_interface_add_del_feature_reply) \
66 _(nat44_interface_add_del_output_feature_reply) \
67 _(nat44_add_del_static_mapping_reply) \
68 _(nat_set_workers_reply) \
69 _(nat44_add_del_interface_addr_reply) \
70 _(nat_ipfix_enable_disable_reply) \
71 _(nat_set_timeouts_reply)
74 static void vl_api_##n##_t_handler \
75 (vl_api_##n##_t * mp) \
77 vat_main_t * vam = snat_test_main.vat_main; \
78 i32 retval = ntohl(mp->retval); \
79 if (vam->async_mode) { \
80 vam->async_errors += (retval < 0); \
82 vam->retval = retval; \
83 vam->result_ready = 1; \
86 foreach_standard_reply_retval_handler;
90 * Table of message reply handlers, must include boilerplate handlers
93 #define foreach_vpe_api_reply_msg \
94 _(NAT44_ADD_DEL_ADDRESS_RANGE_REPLY, \
95 nat44_add_del_address_range_reply) \
96 _(NAT44_INTERFACE_ADD_DEL_FEATURE_REPLY, \
97 nat44_interface_add_del_feature_reply) \
98 _(NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE_REPLY, \
99 nat44_interface_add_del_output_feature_reply) \
100 _(NAT44_ADD_DEL_STATIC_MAPPING_REPLY, \
101 nat44_add_del_static_mapping_reply) \
102 _(NAT_CONTROL_PING_REPLY, nat_control_ping_reply) \
103 _(NAT44_STATIC_MAPPING_DETAILS, nat44_static_mapping_details) \
104 _(NAT_SHOW_CONFIG_REPLY, nat_show_config_reply) \
105 _(NAT_SHOW_CONFIG_2_REPLY, nat_show_config_2_reply) \
106 _(NAT44_ADDRESS_DETAILS, nat44_address_details) \
107 _(NAT44_INTERFACE_DETAILS, nat44_interface_details) \
108 _(NAT_SET_WORKERS_REPLY, nat_set_workers_reply) \
109 _(NAT_WORKER_DETAILS, nat_worker_details) \
110 _(NAT44_ADD_DEL_INTERFACE_ADDR_REPLY, \
111 nat44_add_del_interface_addr_reply) \
112 _(NAT44_INTERFACE_ADDR_DETAILS, nat44_interface_addr_details) \
113 _(NAT_IPFIX_ENABLE_DISABLE_REPLY, \
114 nat_ipfix_enable_disable_reply) \
115 _(NAT44_USER_DETAILS, nat44_user_details) \
116 _(NAT44_USER_SESSION_DETAILS, nat44_user_session_details) \
117 _(NAT_SET_TIMEOUTS_REPLY, nat_set_timeouts_reply) \
118 _(NAT_GET_TIMEOUTS_REPLY, nat_get_timeouts_reply)
120 static int api_nat44_add_del_address_range (vat_main_t * vam)
122 unformat_input_t * i = vam->input;
123 ip4_address_t start_addr, end_addr;
124 u32 start_host_order, end_host_order;
125 vl_api_nat44_add_del_address_range_t * mp;
132 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
134 if (unformat (i, "%U - %U",
135 unformat_ip4_address, &start_addr,
136 unformat_ip4_address, &end_addr))
138 else if (unformat (i, "%U", unformat_ip4_address, &start_addr))
139 end_addr = start_addr;
140 else if (unformat (i, "twice-nat"))
142 else if (unformat (i, "vrf %u", &vrf_id))
144 else if (unformat (i, "del"))
148 clib_warning("unknown input '%U'", format_unformat_error, i);
153 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
154 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
156 if (end_host_order < start_host_order)
158 errmsg ("end address less than start address\n");
162 count = (end_host_order - start_host_order) + 1;
166 errmsg ("%U - %U, %d addresses...\n",
167 format_ip4_address, &start_addr,
168 format_ip4_address, &end_addr,
172 M(NAT44_ADD_DEL_ADDRESS_RANGE, mp);
174 memcpy (mp->first_ip_address, &start_addr, 4);
175 memcpy (mp->last_ip_address, &end_addr, 4);
178 mp->flags = (vl_api_nat_config_flags_t)NAT_API_IS_TWICE_NAT;
186 static int api_nat44_interface_add_del_feature (vat_main_t * vam)
188 unformat_input_t * i = vam->input;
189 vl_api_nat44_interface_add_del_feature_t * mp;
191 u8 sw_if_index_set = 0;
196 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
198 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
200 else if (unformat (i, "sw_if_index %d", &sw_if_index))
202 else if (unformat (i, "out"))
204 else if (unformat (i, "in"))
206 else if (unformat (i, "del"))
210 clib_warning("unknown input '%U'", format_unformat_error, i);
215 if (sw_if_index_set == 0)
217 errmsg ("interface / sw_if_index required\n");
221 M(NAT44_INTERFACE_ADD_DEL_FEATURE, mp);
222 mp->sw_if_index = ntohl(sw_if_index);
225 mp->flags |= NAT_API_IS_INSIDE;
232 static int api_nat44_interface_add_del_output_feature (vat_main_t * vam)
234 unformat_input_t * i = vam->input;
235 vl_api_nat44_interface_add_del_output_feature_t * mp;
237 u8 sw_if_index_set = 0;
242 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
244 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
246 else if (unformat (i, "sw_if_index %d", &sw_if_index))
248 else if (unformat (i, "out"))
250 else if (unformat (i, "in"))
252 else if (unformat (i, "del"))
256 clib_warning("unknown input '%U'", format_unformat_error, i);
261 if (sw_if_index_set == 0)
263 errmsg ("interface / sw_if_index required\n");
267 M(NAT44_INTERFACE_ADD_DEL_OUTPUT_FEATURE, mp);
268 mp->sw_if_index = ntohl(sw_if_index);
271 mp->flags |= NAT_API_IS_INSIDE;
278 static int api_nat44_add_del_static_mapping(vat_main_t * vam)
280 unformat_input_t * i = vam->input;
281 vl_api_nat44_add_del_static_mapping_t * mp;
282 u8 external_addr_set = 0;
283 u8 local_addr_set = 0;
286 ip4_address_t local_addr, external_addr;
287 u32 local_port = 0, external_port = 0, vrf_id = ~0;
288 u32 sw_if_index = ~0;
289 u8 sw_if_index_set = 0;
290 u32 proto = NAT_PROTOCOL_OTHER;
294 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
296 if (unformat (i, "local_addr %U", unformat_ip4_address, &local_addr))
298 else if (unformat (i, "external_addr %U", unformat_ip4_address,
300 external_addr_set = 1;
301 else if (unformat (i, "local_port %u", &local_port))
303 else if (unformat (i, "external_port %u", &external_port))
305 else if (unformat (i, "external_if %U", unformat_sw_if_index, vam,
308 else if (unformat (i, "external_sw_if_index %d", &sw_if_index))
310 else if (unformat (i, "vrf %u", &vrf_id))
312 else if (unformat (i, "protocol %u", &proto))
314 else if (unformat (i, "del"))
318 clib_warning("unknown input '%U'", format_unformat_error, i);
323 if (!addr_only && !proto_set)
325 errmsg ("protocol required\n");
331 errmsg ("local addr required\n");
334 if (!external_addr_set && !sw_if_index_set)
336 errmsg ("external addr or interface required\n");
340 M(NAT44_ADD_DEL_STATIC_MAPPING, mp);
344 mp->flags |= NAT_API_IS_ADDR_ONLY;
346 mp->local_port = ntohs ((u16) local_port);
347 mp->external_port = ntohs ((u16) external_port);
348 mp->external_sw_if_index = ntohl (sw_if_index);
349 mp->vrf_id = ntohl (vrf_id);
350 mp->protocol = (u8) proto;
351 memcpy (mp->local_ip_address, &local_addr, 4);
352 memcpy (mp->external_ip_address, &external_addr, 4);
359 static void vl_api_nat_control_ping_reply_t_handler
360 (vl_api_nat_control_ping_reply_t * mp)
362 vat_main_t *vam = &vat_main;
363 i32 retval = ntohl (mp->retval);
366 vam->async_errors += (retval < 0);
370 vam->retval = retval;
371 vam->result_ready = 1;
375 static void vl_api_nat44_static_mapping_details_t_handler
376 (vl_api_nat44_static_mapping_details_t *mp)
378 snat_test_main_t * sm = &snat_test_main;
379 vat_main_t *vam = sm->vat_main;
380 nat_config_flags_t flags = (nat_config_flags_t) mp->flags;
382 if (flags & NAT_API_IS_ADDR_ONLY && mp->external_sw_if_index != ~0)
383 fformat (vam->ofp, "%15U%6s%15d%6s%11d%6d\n",
384 format_ip4_address, &mp->local_ip_address, "",
385 ntohl (mp->external_sw_if_index), "",
388 else if (flags & NAT_API_IS_ADDR_ONLY && mp->external_sw_if_index == ~0)
389 fformat (vam->ofp, "%15U%6s%15U%6s%11d%6d\n",
390 format_ip4_address, &mp->local_ip_address, "",
391 format_ip4_address, &mp->external_ip_address, "",
394 else if (!(flags & NAT_API_IS_ADDR_ONLY) && mp->external_sw_if_index != ~0)
395 fformat (vam->ofp, "%15U%6d%15d%6d%11d%6d\n",
396 format_ip4_address, &mp->local_ip_address,
397 ntohs (mp->local_port),
398 ntohl (mp->external_sw_if_index),
399 ntohs (mp->external_port),
403 fformat (vam->ofp, "%15U%6d%15U%6d%11d%6d\n",
404 format_ip4_address, &mp->local_ip_address,
405 ntohs (mp->local_port),
406 format_ip4_address, &mp->external_ip_address,
407 ntohs (mp->external_port),
413 static int api_nat44_static_mapping_dump(vat_main_t * vam)
415 vl_api_nat44_static_mapping_dump_t * mp;
416 vl_api_nat_control_ping_t *mp_ping;
419 if (vam->json_output)
421 clib_warning ("JSON output not supported for nat44_static_mapping_dump");
425 fformat (vam->ofp, "%21s%21s\n", "local", "external");
426 fformat (vam->ofp, "%15s%6s%15s%6s%11s%6s\n", "address", "port",
427 "address/if_idx", "port", "vrf", "proto");
429 M(NAT44_STATIC_MAPPING_DUMP, mp);
432 /* Use a control ping for synchronization */
433 M(NAT_CONTROL_PING, mp_ping);
440 static void vl_api_nat_show_config_reply_t_handler
441 (vl_api_nat_show_config_reply_t *mp)
443 snat_test_main_t * sm = &snat_test_main;
444 vat_main_t *vam = sm->vat_main;
445 i32 retval = ntohl (mp->retval);
449 fformat (vam->ofp, "translation hash buckets %d\n",
450 ntohl (mp->translation_buckets));
451 fformat (vam->ofp, "translation hash memory %d\n",
452 ntohl (mp->translation_memory_size));
453 fformat (vam->ofp, "user hash buckets %d\n", ntohl (mp->user_buckets));
454 fformat (vam->ofp, "user hash memory %d\n", ntohl (mp->user_memory_size));
455 fformat (vam->ofp, "max translations per user %d\n",
456 ntohl (mp->max_translations_per_user));
457 fformat (vam->ofp, "outside VRF id %d\n", ntohl (mp->outside_vrf_id));
458 fformat (vam->ofp, "inside VRF id %d\n", ntohl (mp->inside_vrf_id));
459 if (mp->static_mapping_only)
461 fformat (vam->ofp, "static mapping only");
462 if (mp->static_mapping_connection_tracking)
463 fformat (vam->ofp, " connection tracking");
464 fformat (vam->ofp, "\n");
467 vam->retval = retval;
468 vam->result_ready = 1;
471 static void vl_api_nat_show_config_2_reply_t_handler
472 (vl_api_nat_show_config_2_reply_t *mp)
474 snat_test_main_t * sm = &snat_test_main;
475 vat_main_t *vam = sm->vat_main;
476 i32 retval = ntohl (mp->retval);
480 fformat (vam->ofp, "translation hash buckets %d\n",
481 ntohl (mp->translation_buckets));
482 fformat (vam->ofp, "translation hash memory %d\n",
483 ntohl (mp->translation_memory_size));
484 fformat (vam->ofp, "user hash buckets %d\n", ntohl (mp->user_buckets));
485 fformat (vam->ofp, "user hash memory %d\n", ntohl (mp->user_memory_size));
486 fformat (vam->ofp, "max translations per user %d\n",
487 ntohl (mp->max_translations_per_user));
488 fformat (vam->ofp, "outside VRF id %d\n", ntohl (mp->outside_vrf_id));
489 fformat (vam->ofp, "inside VRF id %d\n", ntohl (mp->inside_vrf_id));
490 if (mp->static_mapping_only)
492 fformat (vam->ofp, "static mapping only");
493 if (mp->static_mapping_connection_tracking)
494 fformat (vam->ofp, " connection tracking");
495 fformat (vam->ofp, "\n");
498 vam->retval = retval;
499 vam->result_ready = 1;
502 static int api_nat_show_config(vat_main_t * vam)
504 vl_api_nat_show_config_t * mp;
507 if (vam->json_output)
509 clib_warning ("JSON output not supported for nat_show_config");
513 M(NAT_SHOW_CONFIG, mp);
519 static int api_nat_show_config_2(vat_main_t * vam)
521 vl_api_nat_show_config_2_t * mp;
524 if (vam->json_output)
526 clib_warning ("JSON output not supported for nat_show_config_2");
530 M(NAT_SHOW_CONFIG_2, mp);
536 static void vl_api_nat44_address_details_t_handler
537 (vl_api_nat44_address_details_t *mp)
539 snat_test_main_t * sm = &snat_test_main;
540 vat_main_t *vam = sm->vat_main;
542 fformat (vam->ofp, "%U\n", format_ip4_address, &mp->ip_address);
545 static int api_nat44_address_dump(vat_main_t * vam)
547 vl_api_nat44_address_dump_t * mp;
548 vl_api_nat_control_ping_t *mp_ping;
551 if (vam->json_output)
553 clib_warning ("JSON output not supported for nat44_address_dump");
557 M(NAT44_ADDRESS_DUMP, mp);
560 /* Use a control ping for synchronization */
561 M(NAT_CONTROL_PING, mp_ping);
568 static void vl_api_nat44_interface_details_t_handler
569 (vl_api_nat44_interface_details_t *mp)
571 nat_config_flags_t flags = (nat_config_flags_t) mp->flags;
572 snat_test_main_t * sm = &snat_test_main;
573 vat_main_t *vam = sm->vat_main;
575 if ((flags & NAT_API_IS_INSIDE) && (flags & NAT_API_IS_OUTSIDE))
577 fformat (vam->ofp, "sw_if_index %d in & out\n", ntohl (mp->sw_if_index));
581 fformat (vam->ofp, "sw_if_index %d %s\n", ntohl (mp->sw_if_index),
582 flags & NAT_API_IS_INSIDE ? "in" : "out");
586 static int api_nat44_interface_dump(vat_main_t * vam)
588 vl_api_nat44_interface_dump_t * mp;
589 vl_api_nat_control_ping_t *mp_ping;
592 if (vam->json_output)
594 clib_warning ("JSON output not supported for nat44_address_dump");
598 M(NAT44_INTERFACE_DUMP, mp);
601 /* Use a control ping for synchronization */
602 M(NAT_CONTROL_PING, mp_ping);
609 static int api_nat_set_workers (vat_main_t * vam)
611 unformat_input_t * i = vam->input;
612 vl_api_nat_set_workers_t * mp;
616 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
618 if (unformat (i, "%U", unformat_bitmap_list, &bitmap))
622 clib_warning("unknown input '%U'", format_unformat_error, i);
627 M(NAT_SET_WORKERS, mp);
628 mp->worker_mask = clib_host_to_net_u64 (bitmap[0]);
635 static void vl_api_nat_worker_details_t_handler
636 (vl_api_nat_worker_details_t *mp)
638 snat_test_main_t * sm = &snat_test_main;
639 vat_main_t *vam = sm->vat_main;
641 fformat (vam->ofp, "worker_index %d (%s at lcore %u)\n",
642 ntohl (mp->worker_index), mp->name, ntohl (mp->lcore_id));
645 static int api_nat_worker_dump(vat_main_t * vam)
647 vl_api_nat_worker_dump_t * mp;
648 vl_api_nat_control_ping_t *mp_ping;
651 if (vam->json_output)
653 clib_warning ("JSON output not supported for nat_address_dump");
657 M(NAT_WORKER_DUMP, mp);
660 /* Use a control ping for synchronization */
661 M(NAT_CONTROL_PING, mp_ping);
668 static int api_nat44_add_del_interface_addr (vat_main_t * vam)
670 unformat_input_t * i = vam->input;
671 vl_api_nat44_add_del_interface_addr_t * mp;
673 u8 sw_if_index_set = 0;
678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
680 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
682 else if (unformat (i, "sw_if_index %d", &sw_if_index))
684 else if (unformat (i, "twice-nat"))
686 else if (unformat (i, "del"))
690 clib_warning("unknown input '%U'", format_unformat_error, i);
695 if (sw_if_index_set == 0)
697 errmsg ("interface / sw_if_index required\n");
701 M(NAT44_ADD_DEL_INTERFACE_ADDR, mp);
702 mp->sw_if_index = ntohl(sw_if_index);
704 mp->flags = (vl_api_nat_config_flags_t)NAT_API_IS_TWICE_NAT;
712 static void vl_api_nat44_interface_addr_details_t_handler
713 (vl_api_nat44_interface_addr_details_t *mp)
715 snat_test_main_t * sm = &snat_test_main;
716 vat_main_t *vam = sm->vat_main;
718 fformat (vam->ofp, "sw_if_index %d\n", ntohl (mp->sw_if_index));
721 static int api_nat44_interface_addr_dump(vat_main_t * vam)
723 vl_api_nat44_interface_addr_dump_t * mp;
724 vl_api_nat_control_ping_t *mp_ping;
727 if (vam->json_output)
729 clib_warning ("JSON output not supported for nat44_address_dump");
733 M(NAT44_INTERFACE_ADDR_DUMP, mp);
736 /* Use a control ping for synchronization */
737 M(NAT_CONTROL_PING, mp_ping);
744 static int api_nat_ipfix_enable_disable (vat_main_t * vam)
746 unformat_input_t * i = vam->input;
747 vl_api_nat_ipfix_enable_disable_t * mp;
753 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
755 if (unformat (i, "domain %d", &domain_id))
757 else if (unformat (i, "src_port %d", &src_port))
759 else if (unformat (i, "disable"))
763 clib_warning("unknown input '%U'", format_unformat_error, i);
768 M(NAT_IPFIX_ENABLE_DISABLE, mp);
769 mp->domain_id = htonl(domain_id);
770 mp->src_port = htons((u16) src_port);
778 static void vl_api_nat44_user_session_details_t_handler
779 (vl_api_nat44_user_session_details_t *mp)
781 snat_test_main_t * sm = &snat_test_main;
782 vat_main_t *vam = sm->vat_main;
784 fformat(vam->ofp, "%s session %U:%d to %U:%d protocol id %d "
785 "total packets %d total bytes %lld\n",
786 mp->flags & NAT_API_IS_STATIC ? "static" : "dynamic",
787 format_ip4_address, mp->inside_ip_address, ntohs(mp->inside_port),
788 format_ip4_address, mp->outside_ip_address, ntohs(mp->outside_port),
789 ntohs(mp->protocol), ntohl(mp->total_pkts),
790 clib_net_to_host_u64(mp->total_bytes));
793 static int api_nat44_user_session_dump(vat_main_t * vam)
795 unformat_input_t* i = vam->input;
796 vl_api_nat44_user_session_dump_t * mp;
797 vl_api_nat_control_ping_t *mp_ping;
802 if (vam->json_output)
804 clib_warning ("JSON output not supported for nat44_address_dump");
808 if (unformat (i, "ip_address %U vrf_id %d",
809 unformat_ip4_address, &addr, &vrf_id))
813 clib_warning("unknown input '%U'", format_unformat_error, i);
817 M(NAT44_USER_SESSION_DUMP, mp);
820 /* Use a control ping for synchronization */
821 M(NAT_CONTROL_PING, mp_ping);
822 clib_memset(mp->ip_address, 0, 16);
823 clib_memcpy(mp->ip_address, &addr, 4);
824 mp->vrf_id = htonl(vrf_id);
831 static void vl_api_nat44_user_details_t_handler
832 (vl_api_nat44_user_details_t *mp)
834 snat_test_main_t * sm = &snat_test_main;
835 vat_main_t *vam = sm->vat_main;
837 fformat(vam->ofp, "user with ip %U with vrf_id %d "
838 "with %d sessions and %d static sessions\n",
839 format_ip4_address, mp->ip_address, ntohl(mp->vrf_id),
840 ntohl(mp->nsessions), ntohl(mp->nstaticsessions));
843 static int api_nat44_user_dump(vat_main_t * vam)
845 vl_api_nat44_user_dump_t * mp;
846 vl_api_nat_control_ping_t *mp_ping;
849 if (vam->json_output)
851 clib_warning ("JSON output not supported for nat44_address_dump");
855 M(NAT44_USER_DUMP, mp);
858 /* Use a control ping for synchronization */
859 M(NAT_CONTROL_PING, mp_ping);
866 static int api_nat_set_timeouts (vat_main_t * vam)
868 unformat_input_t * i = vam->input;
869 vl_api_nat_set_timeouts_t * mp;
870 u32 udp = SNAT_UDP_TIMEOUT;
871 u32 tcp_established = SNAT_TCP_ESTABLISHED_TIMEOUT;
872 u32 tcp_transitory = SNAT_TCP_TRANSITORY_TIMEOUT;
873 u32 icmp = SNAT_ICMP_TIMEOUT;
876 if (unformat (i, "udp %d", &udp))
878 else if (unformat (i, "tcp_established %d", &tcp_established))
880 else if (unformat (i, "tcp_transitory %d", &tcp_transitory))
882 else if (unformat (i, "icmp %d", &icmp))
886 clib_warning("unknown input '%U'", format_unformat_error, i);
890 M(NAT_SET_TIMEOUTS, mp);
891 mp->udp = htonl(udp);
892 mp->tcp_established = htonl(tcp_established);
893 mp->tcp_transitory = htonl(tcp_transitory);
894 mp->icmp = htonl(icmp);
901 static void vl_api_nat_get_timeouts_reply_t_handler
902 (vl_api_nat_get_timeouts_reply_t *mp)
904 snat_test_main_t * sm = &snat_test_main;
905 vat_main_t *vam = sm->vat_main;
906 i32 retval = ntohl (mp->retval);
910 fformat (vam->ofp, "udp timeout: %dsec\n", ntohl (mp->udp));
911 fformat (vam->ofp, "tcp-established timeout: %dsec",
912 ntohl (mp->tcp_established));
913 fformat (vam->ofp, "tcp-transitory timeout: %dsec",
914 ntohl (mp->tcp_transitory));
915 fformat (vam->ofp, "icmp timeout: %dsec", ntohl (mp->icmp));
917 vam->retval = retval;
918 vam->result_ready = 1;
921 static int api_nat_get_timeouts(vat_main_t * vam)
923 vl_api_nat_get_timeouts_t * mp;
926 if (vam->json_output)
928 clib_warning ("JSON output not supported for nat_get_timeouts");
932 M(NAT_GET_TIMEOUTS, mp);
939 * List of messages that the api test plugin sends,
940 * and that the data plane plugin processes
942 #define foreach_vpe_api_msg \
943 _(nat44_add_del_address_range, \
944 "<start-addr> [- <end-addr>] [vrf <table-id>] [twice-nat] [del]") \
945 _(nat44_interface_add_del_feature, \
946 "<intfc> | sw_if_index <id> [in] [out] [del]") \
947 _(nat44_interface_add_del_output_feature, \
948 "<intfc> | sw_if_index <id> [in] [out] [del]") \
949 _(nat44_add_del_static_mapping, "local_addr <ip>" \
950 " (external_addr <ip> | external_if <intfc> |" \
951 " external_sw_if_ndex <id>) [local_port <n>]" \
952 " [external_port <n>] [vrf <table-id>] [del] protocol <n>") \
953 _(nat_set_workers, "<wokrers_bitmap>") \
954 _(nat44_static_mapping_dump, "") \
955 _(nat_show_config, "") \
956 _(nat_show_config_2, "") \
957 _(nat44_address_dump, "") \
958 _(nat44_interface_dump, "") \
959 _(nat_worker_dump, "") \
960 _(nat44_add_del_interface_addr, \
961 "<intfc> | sw_if_index <id> [twice-nat] [del]") \
962 _(nat44_interface_addr_dump, "") \
963 _(nat_ipfix_enable_disable, "[domain <id>] [src_port <n>] " \
965 _(nat44_user_dump, "") \
966 _(nat44_user_session_dump, "ip_address <ip> vrf_id <table-id>") \
967 _(nat_set_timeouts, "[udp <sec> | tcp_established <sec> | " \
968 "tcp_transitory <sec> | icmp <sec>]") \
969 _(nat_get_timeouts, "")
972 snat_vat_api_hookup (vat_main_t *vam)
974 snat_test_main_t * sm __attribute__((unused)) = &snat_test_main;
975 /* Hook up handlers for replies from the data plane plug-in */
977 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
979 vl_api_##n##_t_handler, \
981 vl_api_##n##_t_endian, \
982 vl_api_##n##_t_print, \
983 sizeof(vl_api_##n##_t), 1);
984 foreach_vpe_api_reply_msg;
987 /* API messages we can send */
989 hash_set_mem (vam->function_by_name, #n, api_##n);
994 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
999 clib_error_t * vat_plugin_register (vat_main_t *vam)
1001 snat_test_main_t * sm = &snat_test_main;
1006 /* Ask the vpp engine for the first assigned message-id */
1007 name = format (0, "nat_%08x%c", api_version, 0);
1008 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
1011 if (sm->msg_id_base != (u16) ~0)
1012 snat_vat_api_hookup (vam);
1014 return clib_error_return (0, "nat plugin not loaded...");