aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/nat/nat.api61
-rw-r--r--src/plugins/nat/nat_api.c52
-rw-r--r--src/plugins/nat/nat_test.c50
-rw-r--r--src/plugins/nat/test/test_nat.py43
4 files changed, 204 insertions, 2 deletions
diff --git a/src/plugins/nat/nat.api b/src/plugins/nat/nat.api
index 7e6f35968c5..8b263d4001d 100644
--- a/src/plugins/nat/nat.api
+++ b/src/plugins/nat/nat.api
@@ -60,11 +60,12 @@ define nat_control_ping_reply
*/
define nat_show_config
{
+ option deprecated;
u32 client_index;
u32 context;
};
-/** \brief Show NAT plugin startup config reply
+/** \brief DEPRECATED: Show NAT plugin startup config reply
@param context - sender context, to match reply w/ request
@param retval - return code for the request
@param static_mapping_only - if true dynamic translations disabled
@@ -108,6 +109,64 @@ define nat_show_config_reply
u64 nat64_st_memory_size;
};
+/** \brief Show NAT plugin startup config
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+*/
+define nat_show_config_2
+{
+ u32 client_index;
+ u32 context;
+};
+
+/** \brief Show NAT plugin startup config reply
+ @param context - sender context, to match reply w/ request
+ @param retval - return code for the request
+ @param static_mapping_only - if true dynamic translations disabled
+ @param static_mapping_connection_tracking - if true create session data
+ @param deterministic - if true deterministic mapping
+ @param endpoint_dependent - if true endpoint-dependent mode
+ @param out2in_dpo - if true out2in dpo mode
+ @param dslite_ce - if true DS-Lite is CE/B4 element, if false AFTR elemet
+ @param translation_buckets - number of translation hash buckets
+ @param translation_memory_size - translation hash memory size
+ @param user_buckets - number of user hash buckets
+ @param user_memory_size - user hash memory size
+ @param max_translations_per_user - maximum number of translations per user
+ @param outside_vrf_id - outside VRF id
+ @param inside_vrf_id - default inside VRF id
+ @param nat64_bib_buckets - number of NAT64 BIB hash buckets
+ @param nat64_bib_memory_size - memory size of NAT64 BIB hash
+ @param nat64_st_buckets - number of NAT64 session table hash buckets
+ @param nat64_st_memory_size - memory size of NAT64 session table hash
+ @param max_translations_per_thread - max translations per worker thread
+ @param max_users_per_thread - max users per worker thread
+*/
+define nat_show_config_2_reply
+{
+ u32 context;
+ i32 retval;
+ bool static_mapping_only;
+ bool static_mapping_connection_tracking;
+ bool deterministic;
+ bool endpoint_dependent;
+ bool out2in_dpo;
+ bool dslite_ce;
+ u32 translation_buckets;
+ u64 translation_memory_size;
+ u32 user_buckets;
+ u64 user_memory_size;
+ u32 max_translations_per_user;
+ u32 outside_vrf_id;
+ u32 inside_vrf_id;
+ u32 nat64_bib_buckets;
+ u64 nat64_bib_memory_size;
+ u32 nat64_st_buckets;
+ u64 nat64_st_memory_size;
+ u32 max_translations_per_thread;
+ u32 max_users_per_thread;
+};
+
enum nat_log_level : u8
{
NAT_LOG_NONE = 0x00,
diff --git a/src/plugins/nat/nat_api.c b/src/plugins/nat/nat_api.c
index 503143288f8..ad67375fb7a 100644
--- a/src/plugins/nat/nat_api.c
+++ b/src/plugins/nat/nat_api.c
@@ -104,7 +104,10 @@ vl_api_nat_show_config_t_handler (vl_api_nat_show_config_t * mp)
REPLY_MACRO2 (VL_API_NAT_SHOW_CONFIG_REPLY,
({
rmp->translation_buckets = htonl (sm->translation_buckets);
- rmp->translation_memory_size = clib_host_to_net_u64 (sm->translation_memory_size);
+ rmp->translation_memory_size = clib_host_to_net_u32 (
+ sm->translation_memory_size > 0xffffffffULL
+ ? 0xffffffffUL
+ : (u32)sm->translation_memory_size);
rmp->user_buckets = htonl (sm->user_buckets);
rmp->user_memory_size = clib_host_to_net_u64 (sm->user_memory_size);
rmp->max_translations_per_user = htonl (sm->max_translations_per_user);
@@ -136,6 +139,52 @@ vl_api_nat_show_config_t_print (vl_api_nat_show_config_t * mp, void *handle)
}
static void
+vl_api_nat_show_config_2_t_handler (vl_api_nat_show_config_2_t * mp)
+{
+ vl_api_nat_show_config_2_reply_t *rmp;
+ snat_main_t *sm = &snat_main;
+ //dslite_main_t *dm = &dslite_main;
+ nat64_main_t *n64m = &nat64_main;
+ int rv = 0;
+
+ /* *INDENT-OFF* */
+ REPLY_MACRO2 (VL_API_NAT_SHOW_CONFIG_2_REPLY,
+ ({
+ rmp->translation_buckets = htonl (sm->translation_buckets);
+ rmp->translation_memory_size = clib_host_to_net_u64 (sm->translation_memory_size);
+ rmp->user_buckets = htonl (sm->user_buckets);
+ rmp->user_memory_size = clib_host_to_net_u64 (sm->user_memory_size);
+ rmp->max_translations_per_user = htonl (sm->max_translations_per_user);
+ rmp->outside_vrf_id = htonl (sm->outside_vrf_id);
+ rmp->inside_vrf_id = htonl (sm->inside_vrf_id);
+ rmp->static_mapping_only = sm->static_mapping_only;
+ rmp->static_mapping_connection_tracking =
+ sm->static_mapping_connection_tracking;
+ rmp->deterministic = 0;
+ rmp->endpoint_dependent = sm->endpoint_dependent;
+ rmp->out2in_dpo = sm->out2in_dpo;
+ //rmp->dslite_ce = dm->is_ce;
+ rmp->nat64_bib_buckets = clib_net_to_host_u32(n64m->bib_buckets);
+ rmp->nat64_bib_memory_size = clib_net_to_host_u64(n64m->bib_memory_size);
+ rmp->nat64_st_buckets = clib_net_to_host_u32(n64m->st_buckets);
+ rmp->nat64_st_memory_size = clib_net_to_host_u64(n64m->st_memory_size);
+ rmp->max_translations_per_thread = clib_net_to_host_u32(sm->max_translations_per_thread);
+ rmp->max_users_per_thread = clib_net_to_host_u32(sm->max_users_per_thread);
+ }));
+ /* *INDENT-ON* */
+}
+
+static void *
+vl_api_nat_show_config_2_t_print (vl_api_nat_show_config_t * mp, void *handle)
+{
+ u8 *s;
+
+ s = format (0, "SCRIPT: nat_show_config_2 ");
+
+ FINISH;
+}
+
+static void
vl_api_nat_set_workers_t_handler (vl_api_nat_set_workers_t * mp)
{
snat_main_t *sm = &snat_main;
@@ -2592,6 +2641,7 @@ static void *vl_api_nat64_add_del_interface_addr_t_print
#define foreach_snat_plugin_api_msg \
_(NAT_CONTROL_PING, nat_control_ping) \
_(NAT_SHOW_CONFIG, nat_show_config) \
+_(NAT_SHOW_CONFIG_2, nat_show_config_2) \
_(NAT_SET_WORKERS, nat_set_workers) \
_(NAT_WORKER_DUMP, nat_worker_dump) \
_(NAT44_DEL_USER, nat44_del_user) \
diff --git a/src/plugins/nat/nat_test.c b/src/plugins/nat/nat_test.c
index 0cc34f0b3f1..228d5b58157 100644
--- a/src/plugins/nat/nat_test.c
+++ b/src/plugins/nat/nat_test.c
@@ -102,6 +102,7 @@ _(NAT44_ADD_DEL_STATIC_MAPPING_REPLY, \
_(NAT_CONTROL_PING_REPLY, nat_control_ping_reply) \
_(NAT44_STATIC_MAPPING_DETAILS, nat44_static_mapping_details) \
_(NAT_SHOW_CONFIG_REPLY, nat_show_config_reply) \
+_(NAT_SHOW_CONFIG_2_REPLY, nat_show_config_2_reply) \
_(NAT44_ADDRESS_DETAILS, nat44_address_details) \
_(NAT44_INTERFACE_DETAILS, nat44_interface_details) \
_(NAT_SET_WORKERS_REPLY, nat_set_workers_reply) \
@@ -467,6 +468,37 @@ static void vl_api_nat_show_config_reply_t_handler
vam->result_ready = 1;
}
+static void vl_api_nat_show_config_2_reply_t_handler
+ (vl_api_nat_show_config_2_reply_t *mp)
+{
+ snat_test_main_t * sm = &snat_test_main;
+ vat_main_t *vam = sm->vat_main;
+ i32 retval = ntohl (mp->retval);
+
+ if (retval >= 0)
+ {
+ fformat (vam->ofp, "translation hash buckets %d\n",
+ ntohl (mp->translation_buckets));
+ fformat (vam->ofp, "translation hash memory %d\n",
+ ntohl (mp->translation_memory_size));
+ fformat (vam->ofp, "user hash buckets %d\n", ntohl (mp->user_buckets));
+ fformat (vam->ofp, "user hash memory %d\n", ntohl (mp->user_memory_size));
+ fformat (vam->ofp, "max translations per user %d\n",
+ ntohl (mp->max_translations_per_user));
+ fformat (vam->ofp, "outside VRF id %d\n", ntohl (mp->outside_vrf_id));
+ fformat (vam->ofp, "inside VRF id %d\n", ntohl (mp->inside_vrf_id));
+ if (mp->static_mapping_only)
+ {
+ fformat (vam->ofp, "static mapping only");
+ if (mp->static_mapping_connection_tracking)
+ fformat (vam->ofp, " connection tracking");
+ fformat (vam->ofp, "\n");
+ }
+ }
+ vam->retval = retval;
+ vam->result_ready = 1;
+}
+
static int api_nat_show_config(vat_main_t * vam)
{
vl_api_nat_show_config_t * mp;
@@ -484,6 +516,23 @@ static int api_nat_show_config(vat_main_t * vam)
return ret;
}
+static int api_nat_show_config_2(vat_main_t * vam)
+{
+ vl_api_nat_show_config_2_t * mp;
+ int ret;
+
+ if (vam->json_output)
+ {
+ clib_warning ("JSON output not supported for nat_show_config_2");
+ return -99;
+ }
+
+ M(NAT_SHOW_CONFIG_2, mp);
+ S(mp);
+ W (ret);
+ return ret;
+}
+
static void vl_api_nat44_address_details_t_handler
(vl_api_nat44_address_details_t *mp)
{
@@ -904,6 +953,7 @@ _(nat44_add_del_static_mapping, "local_addr <ip>" \
_(nat_set_workers, "<wokrers_bitmap>") \
_(nat44_static_mapping_dump, "") \
_(nat_show_config, "") \
+_(nat_show_config_2, "") \
_(nat44_address_dump, "") \
_(nat44_interface_dump, "") \
_(nat_worker_dump, "") \
diff --git a/src/plugins/nat/test/test_nat.py b/src/plugins/nat/test/test_nat.py
index 6b673b0a143..a305b7aa9f4 100644
--- a/src/plugins/nat/test/test_nat.py
+++ b/src/plugins/nat/test/test_nat.py
@@ -1386,6 +1386,49 @@ class MethodHolder(VppTestCase):
self.assertEqual(data, p[Raw].load)
+class TestNATMisc(MethodHolder):
+ """ NAT misc Test Cases """
+
+ max_translations = 10240
+ max_users = 10240
+
+ @classmethod
+ def setUpConstants(cls):
+ super(TestNATMisc, cls).setUpConstants()
+ cls.vpp_cmdline.extend([
+ "nat", "{",
+ "max translations per thread %d" % cls.max_translations,
+ "max users per thread %d" % cls.max_users,
+ "}"
+ ])
+
+ @classmethod
+ def tearDownClass(cls):
+ super(TestNATMisc, cls).tearDownClass()
+
+ def test_show_config(self):
+ """ NAT config translation memory """
+
+ nat_config = self.vapi.nat_show_config()
+ mem = nat_config.translation_memory_size
+ self.assertTrue(mem > 0)
+ self.logger.info("max translation memory: %d" % mem)
+
+ def test_show_config_2(self):
+ """ NAT config2 translation memory """
+
+ nat_config = self.vapi.nat_show_config_2()
+ mem = nat_config.translation_memory_size
+ self.assertTrue(mem > 0)
+ self.logger.info("max translation memory: %d" % mem)
+
+ def test_show_max_translations(self):
+ """ API test - max translations per thread """
+ nat_config = self.vapi.nat_show_config_2()
+ self.assertEqual(self.max_translations,
+ nat_config.max_translations_per_thread)
+
+
class TestNAT44(MethodHolder):
""" NAT44 Test Cases """