SNAT: Remove the oldest translation fix (VPP-568) 64/4464/2
authorMatus Fabian <matfabia@cisco.com>
Thu, 22 Dec 2016 07:58:46 +0000 (23:58 -0800)
committerDamjan Marion <dmarion.lists@gmail.com>
Thu, 22 Dec 2016 12:28:01 +0000 (12:28 +0000)
Fixed bug and add test.

Change-Id: Ibe70dfc81e6c264223050d316cf6a2a3a0e1524e
Signed-off-by: Matus Fabian <matfabia@cisco.com>
plugins/snat-plugin/snat/in2out.c
plugins/snat-plugin/snat/snat.c
test/test_snat.py
test/vpp_papi_provider.py

index d7b647e..c78fdd7 100644 (file)
@@ -203,7 +203,7 @@ static u32 slow_path (snat_main_t *sm, vlib_buffer_t *b0,
           /* Get the session */
           s = pool_elt_at_index (sm->per_thread_data[cpu_index].sessions,
                                  session_index);
-      } while (!snat_is_session_static (s));
+      } while (snat_is_session_static (s));
 
       /* Remove in2out, out2in keys */
       kv0.key = s->in2out.as_u64;
index ad350d6..b3b2097 100644 (file)
@@ -974,13 +974,13 @@ vl_api_snat_show_config_t_handler
 
   REPLY_MACRO2(VL_API_SNAT_SHOW_CONFIG_REPLY,
   ({
-    rmp->translation_buckets = htons (sm->translation_buckets);
-    rmp->translation_memory_size = htons (sm->translation_memory_size);
-    rmp->user_buckets = htons (sm->user_buckets);
-    rmp->user_memory_size = htons (sm->user_memory_size);
-    rmp->max_translations_per_user = htons (sm->max_translations_per_user);
-    rmp->outside_vrf_id = htons (sm->outside_vrf_id);
-    rmp->inside_vrf_id = htons (sm->inside_vrf_id);
+    rmp->translation_buckets = htonl (sm->translation_buckets);
+    rmp->translation_memory_size = htonl (sm->translation_memory_size);
+    rmp->user_buckets = htonl (sm->user_buckets);
+    rmp->user_memory_size = htonl (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;
index fdd81f0..8985c3e 100644 (file)
@@ -589,6 +589,33 @@ class TestSNAT(VppTestCase):
             self.logger.error(ppp("Unexpected or invalid packet:"), p)
             raise
 
+    def test_max_translations_per_user(self):
+        """ MAX translations per user - recycle the least recently used """
+
+        self.snat_add_address(self.snat_addr)
+        self.vapi.snat_interface_add_del_feature(self.pg0.sw_if_index)
+        self.vapi.snat_interface_add_del_feature(self.pg1.sw_if_index,
+                                                 is_inside=0)
+
+        # get maximum number of translations per user
+        snat_config = self.vapi.snat_show_config()
+
+        # send more than maximum number of translations per user packets
+        pkts_num = snat_config.max_translations_per_user + 5
+        pkts = []
+        for port in range(0, pkts_num):
+            p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
+                 IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4) /
+                 TCP(sport=1025 + port))
+            pkts.append(p)
+        self.pg0.add_stream(pkts)
+        self.pg_enable_capture(self.pg_interfaces)
+        self.pg_start()
+
+        # verify number of translated packet
+        capture = self.pg1.get_capture()
+        self.assertEqual(pkts_num, len(capture))
+
     def tearDown(self):
         super(TestSNAT, self).tearDown()
         if not self.vpp_dead:
index 7c90592..3279a27 100644 (file)
@@ -842,6 +842,12 @@ class VppPapiProvider(object):
         """
         return self.api(self.papi.snat_static_mapping_dump, {})
 
+    def snat_show_config(self):
+        """Show S-NAT config
+        :return: S-NAT config parameters
+        """
+        return self.api(self.papi.snat_show_config, {})
+
     def control_ping(self):
         self.api(self.papi.control_ping)