From 066f034b903bda6e938bec1b12f01edef65ee9c4 Mon Sep 17 00:00:00 2001 From: Matus Fabian Date: Fri, 10 Feb 2017 03:48:01 -0800 Subject: CGN: Deterministic NAT (VPP-623) Inside user is statically mapped to a set of outside ports. Support endpoint dependent mapping to deal with overloading of the outside ports. Change-Id: I8014438744597a976f8ae459283e8b91f63b7f72 Signed-off-by: Matus Fabian --- test/test_snat.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++ test/vpp_papi_provider.py | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) (limited to 'test') diff --git a/test/test_snat.py b/test/test_snat.py index f5e6e1398f0..78919a026ed 100644 --- a/test/test_snat.py +++ b/test/test_snat.py @@ -1276,5 +1276,57 @@ class TestSNAT(VppTestCase): self.clear_snat() +class TestDeterministicNAT(VppTestCase): + """ Deterministic NAT Test Cases """ + + @classmethod + def setUpConstants(cls): + super(TestDeterministicNAT, cls).setUpConstants() + cls.vpp_cmdline.extend(["snat", "{", "deterministic", "}"]) + + @classmethod + def setUpClass(cls): + super(TestDeterministicNAT, cls).setUpClass() + + try: + cls.create_pg_interfaces(range(2)) + cls.interfaces = list(cls.pg_interfaces) + + for i in cls.interfaces: + i.admin_up() + i.config_ip4() + i.resolve_arp() + + except Exception: + super(TestDeterministicNAT, cls).tearDownClass() + raise + + def test_deterministic_mode(self): + """ S-NAT run deterministic mode """ + in_addr = '172.16.255.0' + out_addr = '172.17.255.50' + in_addr_t = '172.16.255.20' + in_addr_n = socket.inet_aton(in_addr) + out_addr_n = socket.inet_aton(out_addr) + in_addr_t_n = socket.inet_aton(in_addr_t) + in_plen = 24 + out_plen = 32 + + snat_config = self.vapi.snat_show_config() + self.assertEqual(1, snat_config.deterministic) + + self.vapi.snat_add_det_map(in_addr_n, in_plen, out_addr_n, out_plen) + + rep1 = self.vapi.snat_det_forward(in_addr_t_n) + self.assertEqual(rep1.out_addr[:4], out_addr_n) + rep2 = self.vapi.snat_det_reverse(out_addr_n, rep1.out_port_hi) + self.assertEqual(rep2.in_addr[:4], in_addr_t_n) + + def tearDown(self): + super(TestDeterministicNAT, self).tearDown() + if not self.vpp_dead: + self.logger.info(self.vapi.cli("show snat detail")) + + if __name__ == '__main__': unittest.main(testRunner=VppTestRunner) diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py index c7e875f0481..b9c4d0c1be6 100644 --- a/test/vpp_papi_provider.py +++ b/test/vpp_papi_provider.py @@ -1123,6 +1123,54 @@ class VppPapiProvider(object): """ return self.api(self.papi.snat_user_dump, {}) + def snat_add_det_map( + self, + in_addr, + in_plen, + out_addr, + out_plen, + is_add=1): + """Add/delete S-NAT deterministic mapping + + :param is_add - 1 if add, 0 if delete + :param in_addr - inside IP address + :param in_plen - inside IP address prefix length + :param out_addr - outside IP address + :param out_plen - outside IP address prefix length + """ + return self.api( + self.papi.snat_add_det_map, + {'is_add': is_add, + 'in_addr': in_addr, + 'in_plen': in_plen, + 'out_addr': out_addr, + 'out_plen': out_plen}) + + def snat_det_forward( + self, + in_addr): + """Get outside address and port range from inside address + + :param in_addr - inside IP address + """ + return self.api( + self.papi.snat_det_forward, + {'in_addr': in_addr}) + + def snat_det_reverse( + self, + out_addr, + out_port): + """Get inside address from outside address and port + + :param out_addr - outside IP address + :param out_port - outside port + """ + return self.api( + self.papi.snat_det_reverse, + {'out_addr': out_addr, + 'out_port': out_port}) + def control_ping(self): self.api(self.papi.control_ping) -- cgit 1.2.3-korg