summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2017-01-12 04:24:35 -0800
committerDamjan Marion <dmarion.lists@gmail.com>2017-01-13 08:54:07 +0000
commit8bf68e858a30a9c04329668d2b5dd67e9ad6f5af (patch)
tree4ae28e50d40b96646c3fbc71d083b25442aede36 /test
parent97f6edc1f5f94fbd5591a85cd710230bd310daa5 (diff)
SNAT: add API and test for NAT pool address from interface
Change-Id: I2a868f736fae8d37b438c604a9284653ea415541 Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_snat.py26
-rw-r--r--test/vpp_papi_provider.py18
2 files changed, 43 insertions, 1 deletions
diff --git a/test/test_snat.py b/test/test_snat.py
index d23becf5ce9..653496e2880 100644
--- a/test/test_snat.py
+++ b/test/test_snat.py
@@ -26,7 +26,7 @@ class TestSNAT(VppTestCase):
cls.icmp_id_out = 6305
cls.snat_addr = '10.0.0.3'
- cls.create_pg_interfaces(range(7))
+ cls.create_pg_interfaces(range(8))
cls.interfaces = list(cls.pg_interfaces[0:4])
for i in cls.interfaces:
@@ -48,6 +48,8 @@ class TestSNAT(VppTestCase):
i.admin_up()
i.resolve_arp()
+ cls.pg7.admin_up()
+
except Exception:
super(TestSNAT, cls).tearDownClass()
raise
@@ -178,6 +180,10 @@ class TestSNAT(VppTestCase):
"""
Clear SNAT configuration.
"""
+ interfaces = self.vapi.snat_interface_addr_dump()
+ for intf in interfaces:
+ self.vapi.snat_add_interface_addr(intf.sw_if_index, is_add=0)
+
interfaces = self.vapi.snat_interface_dump()
for intf in interfaces:
self.vapi.snat_interface_add_del_feature(intf.sw_if_index,
@@ -623,6 +629,24 @@ class TestSNAT(VppTestCase):
# verify number of translated packet
self.pg1.get_capture(pkts_num)
+ def test_interface_addr(self):
+ """ Acquire SNAT addresses from interface """
+ self.vapi.snat_add_interface_addr(self.pg7.sw_if_index)
+
+ # no address in NAT pool
+ adresses = self.vapi.snat_address_dump()
+ self.assertEqual(0, len(adresses))
+
+ # configure interface address and check NAT address pool
+ self.pg7.config_ip4()
+ adresses = self.vapi.snat_address_dump()
+ self.assertEqual(1, len(adresses))
+
+ # remove interface address and check NAT address pool
+ self.pg7.unconfig_ip4()
+ adresses = self.vapi.snat_address_dump()
+ self.assertEqual(0, len(adresses))
+
def tearDown(self):
super(TestSNAT, self).tearDown()
if not self.vpp_dead:
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index b78e861347f..73d3b564001 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -916,6 +916,24 @@ class VppPapiProvider(object):
"""
return self.api(self.papi.snat_show_config, {})
+ def snat_add_interface_addr(
+ self,
+ sw_if_index,
+ is_add=1):
+ """Add/del S-NAT address from interface
+
+ :param sw_if_index: Software index of the interface
+ :param is_add: 1 if add, 0 if delete (Default value = 1)
+ """
+ return self.api(self.papi.snat_add_del_interface_addr,
+ {'is_add': is_add, 'sw_if_index': sw_if_index})
+
+ def snat_interface_addr_dump(self):
+ """Dump S-NAT addresses interfaces
+ :return: Dictionary of S-NAT addresses interfaces
+ """
+ return self.api(self.papi.snat_interface_addr_dump, {})
+
def control_ping(self):
self.api(self.papi.control_ping)