From 36532bda926f5255a323c9cac3144dd758a05667 Mon Sep 17 00:00:00 2001 From: Matus Fabian Date: Mon, 23 Jan 2017 23:42:28 -0800 Subject: SNAT: static mappings for dhcp addressed interfaces (VPP-590) updated API added test Change-Id: I3f6017ecf09b924cb320c1b5f323cd33f7a37447 Signed-off-by: Matus Fabian --- test/test_snat.py | 33 +++++++++++++++++++++++++++++++-- test/vpp_papi_provider.py | 5 ++++- 2 files changed, 35 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/test_snat.py b/test/test_snat.py index 09fdb108c0b..b6cc1c9a17f 100644 --- a/test/test_snat.py +++ b/test/test_snat.py @@ -269,6 +269,9 @@ class TestSNAT(VppTestCase): """ Clear SNAT configuration. """ + if self.pg7.has_ip4_config: + self.pg7.unconfig_ip4() + interfaces = self.vapi.snat_interface_addr_dump() for intf in interfaces: self.vapi.snat_add_interface_addr(intf.sw_if_index, is_add=0) @@ -297,8 +300,9 @@ class TestSNAT(VppTestCase): addr.ip_address, is_add=0) - def snat_add_static_mapping(self, local_ip, external_ip, local_port=0, - external_port=0, vrf_id=0, is_add=1): + def snat_add_static_mapping(self, local_ip, external_ip='0.0.0.0', + local_port=0, external_port=0, vrf_id=0, + is_add=1, external_sw_if_index=0xFFFFFFFF): """ Add/delete S-NAT static mapping @@ -308,6 +312,7 @@ class TestSNAT(VppTestCase): :param external_port: External port number (Optional) :param vrf_id: VRF ID (Default 0) :param is_add: 1 if add, 0 if delete (Default add) + :param external_sw_if_index: External interface instead of IP address """ addr_only = 1 if local_port and external_port: @@ -317,6 +322,7 @@ class TestSNAT(VppTestCase): self.vapi.snat_add_static_mapping( l_ip, e_ip, + external_sw_if_index, local_port, external_port, addr_only, @@ -762,12 +768,35 @@ class TestSNAT(VppTestCase): self.pg7.config_ip4() adresses = self.vapi.snat_address_dump() self.assertEqual(1, len(adresses)) + self.assertEqual(adresses[0].ip_address[0:4], self.pg7.local_ip4n) # remove interface address and check NAT address pool self.pg7.unconfig_ip4() adresses = self.vapi.snat_address_dump() self.assertEqual(0, len(adresses)) + def test_interface_addr_static_mapping(self): + """ Static mapping with addresses from interface """ + self.vapi.snat_add_interface_addr(self.pg7.sw_if_index) + self.snat_add_static_mapping('1.2.3.4', + external_sw_if_index=self.pg7.sw_if_index) + + # no static mappings + static_mappings = self.vapi.snat_static_mapping_dump() + self.assertEqual(0, len(static_mappings)) + + # configure interface address and check static mappings + self.pg7.config_ip4() + static_mappings = self.vapi.snat_static_mapping_dump() + self.assertEqual(1, len(static_mappings)) + self.assertEqual(static_mappings[0].external_ip_address[0:4], + self.pg7.local_ip4n) + + # remove interface address and check static mappings + self.pg7.unconfig_ip4() + static_mappings = self.vapi.snat_static_mapping_dump() + self.assertEqual(0, len(static_mappings)) + def test_ipfix_nat44_sess(self): """ S-NAT IPFIX logging NAT44 session created/delted """ self.snat_add_address(self.snat_addr) diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py index 96f3ddc5dae..901ea2744cb 100644 --- a/test/vpp_papi_provider.py +++ b/test/vpp_papi_provider.py @@ -843,7 +843,8 @@ class VppPapiProvider(object): def snat_add_static_mapping( self, local_ip, - external_ip, + external_ip=0, + external_sw_if_index=0xFFFFFFFF, local_port=0, external_port=0, addr_only=1, @@ -854,6 +855,7 @@ class VppPapiProvider(object): :param local_ip: Local IP address :param external_ip: External IP address + :param external_sw_if_index: External interface instead of IP address :param local_port: Local port number (Default value = 0) :param external_port: External port number (Default value = 0) :param addr_only: 1 if address only mapping, 0 if address and port @@ -870,6 +872,7 @@ class VppPapiProvider(object): 'external_ip_address': external_ip, 'local_port': local_port, 'external_port': external_port, + 'external_sw_if_index': external_sw_if_index, 'vrf_id': vrf_id}) def snat_add_address_range( -- cgit 1.2.3-korg