diff options
author | Matus Fabian <matfabia@cisco.com> | 2018-01-25 21:59:16 -0800 |
---|---|---|
committer | Matus Fabian <matfabia@cisco.com> | 2018-01-25 22:00:31 -0800 |
commit | 5f22499e8836066a268dcb3f4d16cfcd0244b2a2 (patch) | |
tree | e971d52c6c339e6b1df930adad9fa3ff3ff037e7 /test | |
parent | 1f9600e50f3317e8a9abd5ac38734010ca08e246 (diff) |
NAT44: add opaque string tag to static mapping APIs (VPP-1147)
Change-Id: I620e2081285ca8ac5c2da8efc12fe6f540ea4fd1
Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/test_nat.py | 22 | ||||
-rw-r--r-- | test/vpp_papi_provider.py | 11 |
2 files changed, 29 insertions, 4 deletions
diff --git a/test/test_nat.py b/test/test_nat.py index 46a6d42c0c5..f0614da2f3c 100644 --- a/test/test_nat.py +++ b/test/test_nat.py @@ -1030,6 +1030,7 @@ class TestNAT44(MethodHolder): protocol=sm.protocol, twice_nat=sm.twice_nat, out2in_only=sm.out2in_only, + tag=sm.tag, is_add=0) lb_static_mappings = self.vapi.nat44_lb_static_mapping_dump() @@ -1041,6 +1042,7 @@ class TestNAT44(MethodHolder): vrf_id=lb_sm.vrf_id, twice_nat=lb_sm.twice_nat, out2in_only=lb_sm.out2in_only, + tag=lb_sm.tag, is_add=0, local_num=0, locals=[]) @@ -1069,7 +1071,7 @@ class TestNAT44(MethodHolder): def nat44_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, - proto=0, twice_nat=0, out2in_only=0): + proto=0, twice_nat=0, out2in_only=0, tag=""): """ Add/delete NAT44 static mapping @@ -1083,6 +1085,7 @@ class TestNAT44(MethodHolder): :param proto: IP protocol (Mandatory if port specified) :param twice_nat: 1 if translate external host address and port :param out2in_only: if 1 rule is matching only out2in direction + :param tag: Opaque string tag """ addr_only = 1 if local_port and external_port: @@ -1100,6 +1103,7 @@ class TestNAT44(MethodHolder): proto, twice_nat, out2in_only, + tag, is_add) def nat44_add_address(self, ip, is_add=1, vrf_id=0xFFFFFFFF, twice_nat=0): @@ -1376,6 +1380,9 @@ class TestNAT44(MethodHolder): self.vapi.nat44_interface_add_del_feature(self.pg0.sw_if_index) self.vapi.nat44_interface_add_del_feature(self.pg1.sw_if_index, is_inside=0) + sm = self.vapi.nat44_static_mapping_dump() + self.assertEqual(len(sm), 1) + self.assertEqual((sm[0].tag).split('\0', 1)[0], '') # in2out pkts = self.create_stream_in(self.pg0, self.pg1) @@ -1400,11 +1407,15 @@ class TestNAT44(MethodHolder): self.tcp_port_out = 6303 self.udp_port_out = 6304 self.icmp_id_out = 6305 + tag = "testTAG" - self.nat44_add_static_mapping(self.pg0.remote_ip4, nat_ip) + self.nat44_add_static_mapping(self.pg0.remote_ip4, nat_ip, tag=tag) self.vapi.nat44_interface_add_del_feature(self.pg0.sw_if_index) self.vapi.nat44_interface_add_del_feature(self.pg1.sw_if_index, is_inside=0) + sm = self.vapi.nat44_static_mapping_dump() + self.assertEqual(len(sm), 1) + self.assertEqual((sm[0].tag).split('\0', 1)[0], tag) # out2in pkts = self.create_stream_out(self.pg1, nat_ip) @@ -2338,16 +2349,20 @@ class TestNAT44(MethodHolder): def test_interface_addr_static_mapping(self): """ Static mapping with addresses from interface """ + tag = "testTAG" + self.vapi.nat44_add_interface_addr(self.pg7.sw_if_index) self.nat44_add_static_mapping( '1.2.3.4', - external_sw_if_index=self.pg7.sw_if_index) + external_sw_if_index=self.pg7.sw_if_index, + tag=tag) # static mappings with external interface static_mappings = self.vapi.nat44_static_mapping_dump() self.assertEqual(1, len(static_mappings)) self.assertEqual(self.pg7.sw_if_index, static_mappings[0].external_sw_if_index) + self.assertEqual((static_mappings[0].tag).split('\0', 1)[0], tag) # configure interface address and check static mappings self.pg7.config_ip4() @@ -2356,6 +2371,7 @@ class TestNAT44(MethodHolder): self.assertEqual(static_mappings[0].external_ip_address[0:4], self.pg7.local_ip4n) self.assertEqual(0xFFFFFFFF, static_mappings[0].external_sw_if_index) + self.assertEqual((static_mappings[0].tag).split('\0', 1)[0], tag) # remove interface address and check static mappings self.pg7.unconfig_ip4() diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py index db0f8e61aed..b791444fdcd 100644 --- a/test/vpp_papi_provider.py +++ b/test/vpp_papi_provider.py @@ -1236,6 +1236,7 @@ class VppPapiProvider(object): protocol=0, twice_nat=0, out2in_only=0, + tag="", is_add=1): """Add/delete NAT44 static mapping @@ -1249,6 +1250,7 @@ class VppPapiProvider(object): :param protocol: IP protocol (Default value = 0) :param twice_nat: 1 if translate external host address and port :param out2in_only: if 1 rule is matching only out2in direction + :param tag: Opaque string tag :param is_add: 1 if add, 0 if delete (Default value = 1) """ return self.api( @@ -1263,7 +1265,8 @@ class VppPapiProvider(object): 'vrf_id': vrf_id, 'protocol': protocol, 'twice_nat': twice_nat, - 'out2in_only': out2in_only}) + 'out2in_only': out2in_only, + 'tag': tag}) def nat44_add_del_identity_mapping( self, @@ -1273,6 +1276,7 @@ class VppPapiProvider(object): addr_only=1, vrf_id=0, protocol=0, + tag='', is_add=1): """Add/delete NAT44 identity mapping @@ -1282,6 +1286,7 @@ class VppPapiProvider(object): :param addr_only: 1 if address only mapping, 0 if address and port :param vrf_id: VRF ID :param protocol: IP protocol (Default value = 0) + :param tag: Opaque string tag :param is_add: 1 if add, 0 if delete (Default value = 1) """ return self.api( @@ -1292,6 +1297,7 @@ class VppPapiProvider(object): 'port': port, 'sw_if_index': sw_if_index, 'vrf_id': vrf_id, + 'tag': tag, 'protocol': protocol}) def nat44_add_del_address_range( @@ -1424,12 +1430,14 @@ class VppPapiProvider(object): vrf_id=0, twice_nat=0, out2in_only=0, + tag='', local_num=0, locals=[], is_add=1): """Add/delete NAT44 load balancing static mapping :param twice_nat: 1 if translate external host address and port + :param tag: Opaque string tag :param is_add - 1 if add, 0 if delete """ return self.api( @@ -1441,6 +1449,7 @@ class VppPapiProvider(object): 'vrf_id': vrf_id, 'twice_nat': twice_nat, 'out2in_only': out2in_only, + 'tag': tag, 'local_num': local_num, 'locals': locals}) |