summaryrefslogtreecommitdiffstats
path: root/test/vpp_papi_provider.py
diff options
context:
space:
mode:
authorOle Trøan <otroan@employees.org>2019-04-23 12:38:35 +0000
committerOle Trøan <otroan@employees.org>2019-04-23 15:08:45 +0000
commit89fec713f84b8f567c52743c9c514ac29297fbda (patch)
tree52c25aa7bd1a23f03f8a176b669b33724f57d09c /test/vpp_papi_provider.py
parentb8591ac91318984a2706c6388ff836f1a9ef0a16 (diff)
Revert "NAT: VPP-1531 api cleanup & update"
This reverts commit bed1421b9f1b3643d93384084972337b596aec73. /vpp/master3/src/plugins/nat/nat_api.c: In function ‘send_nat_worker_details’: /vpp/master3/src/vppinfra/clib.h:62:33: error: division ‘sizeof (u8 * {aka unsigned char *}) / sizeof (u8 {aka unsigned char})’ does not compute the number of array elements [-Werror=sizeof-pointer-div] #define ARRAY_LEN(x) (sizeof (x)/sizeof (x[0])) ^ /vpp/master3/src/plugins/nat/nat_api.c:205:43: note: in expansion of macro ‘ARRAY_LEN’ rmp = vl_msg_api_alloc (sizeof (*rmp) + ARRAY_LEN (w->name) - 1); ^~~~~~~~~ Change-Id: Ie82672c145fb2f6580827f95e535435307bc7a23 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'test/vpp_papi_provider.py')
-rw-r--r--test/vpp_papi_provider.py239
1 files changed, 183 insertions, 56 deletions
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index bda1aea425c..62fc0aa42b3 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -122,22 +122,23 @@ defaultmapping = {
'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
'nat44_add_del_address_range': {'is_add': 1, 'vrf_id': 4294967295, },
'nat44_add_del_identity_mapping': {'ip': b'0', 'sw_if_index': 4294967295,
- 'is_add': 1, },
+ 'addr_only': 1, 'is_add': 1, },
'nat44_add_del_interface_addr': {'is_add': 1, },
'nat44_add_del_lb_static_mapping': {'is_add': 1, },
'nat44_add_del_static_mapping': {'external_sw_if_index': 4294967295,
- 'is_add': 1, },
- 'nat44_interface_add_del_feature': {'is_add': 1, },
- 'nat44_interface_add_del_output_feature': {'is_add': 1, },
+ 'addr_only': 1, 'is_add': 1, },
+ 'nat44_del_session': {'is_in': 1, },
+ 'nat44_interface_add_del_feature': {'is_inside': 1, 'is_add': 1, },
+ 'nat44_interface_add_del_output_feature': {'is_inside': 1, 'is_add': 1, },
'nat44_lb_static_mapping_add_del_local': {'is_add': 1, },
- 'nat64_add_del_interface': {'is_add': 1, },
+ 'nat64_add_del_interface': {'is_inside': 1, 'is_add': 1, },
'nat64_add_del_interface_addr': {'is_add': 1, },
'nat64_add_del_pool_addr_range': {'vrf_id': 4294967295, 'is_add': 1, },
'nat64_add_del_prefix': {'is_add': 1, },
'nat64_add_del_static_bib': {'is_add': 1, },
'nat64_bib_dump': {'protocol': 255, },
'nat64_st_dump': {'protocol': 255, },
- 'nat66_add_del_interface': {'is_add': 1, },
+ 'nat66_add_del_interface': {'is_inside': 1, 'is_add': 1, },
'nat66_add_del_static_mapping': {'is_add': 1, },
'nat_det_add_del_map': {'is_add': 1, },
'nat_ha_resync': {'want_resync_event': 1, },
@@ -754,35 +755,35 @@ class VppPapiProvider(object):
def nat44_interface_add_del_feature(
self,
sw_if_index,
- is_add=1,
- flags=0):
+ is_inside=1,
+ is_add=1):
"""Enable/disable NAT44 feature on the interface
:param sw_if_index: Software index of the interface
+ :param is_inside: 1 if inside, 0 if outside (Default value = 1)
:param is_add: 1 if add, 0 if delete (Default value = 1)
- :param flags: NAT_IS_INSIDE if inside else outside
"""
return self.api(
self.papi.nat44_interface_add_del_feature,
{'is_add': is_add,
- 'flags': flags,
+ 'is_inside': is_inside,
'sw_if_index': sw_if_index})
def nat44_interface_add_del_output_feature(
self,
sw_if_index,
- is_add=1,
- flags=0):
+ is_inside=1,
+ is_add=1):
"""Enable/disable NAT44 output feature on the interface
:param sw_if_index: Software index of the interface
+ :param is_inside: 1 if inside, 0 if outside (Default value = 1)
:param is_add: 1 if add, 0 if delete (Default value = 1)
- :param flags: NAT_IS_INSIDE if inside else outside
"""
return self.api(
self.papi.nat44_interface_add_del_output_feature,
{'is_add': is_add,
- 'flags': flags,
+ 'is_inside': is_inside,
'sw_if_index': sw_if_index})
def nat44_add_del_static_mapping(
@@ -792,11 +793,14 @@ class VppPapiProvider(object):
external_sw_if_index=0xFFFFFFFF,
local_port=0,
external_port=0,
+ addr_only=1,
vrf_id=0,
protocol=0,
- is_add=1,
- flags=0,
- tag=""):
+ twice_nat=0,
+ self_twice_nat=0,
+ out2in_only=0,
+ tag="",
+ is_add=1):
"""Add/delete NAT44 static mapping
:param local_ip: Local IP address
@@ -804,23 +808,31 @@ class VppPapiProvider(object):
: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
:param vrf_id: VRF ID
:param protocol: IP protocol (Default value = 0)
- :param flags: NAT configuration flags
- :param is_add: 1 if add, 0 if delete (Default value = 1)
+ :param twice_nat: 1 if translate external host address and port
+ :param self_twice_nat: 1 if translate external host address and port
+ whenever external host address equals
+ local address of internal host
+ :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(
self.papi.nat44_add_del_static_mapping,
{'is_add': is_add,
- 'flags': flags,
+ 'addr_only': addr_only,
'local_ip_address': local_ip,
'external_ip_address': external_ip,
- 'protocol': protocol,
'local_port': local_port,
'external_port': external_port,
'external_sw_if_index': external_sw_if_index,
'vrf_id': vrf_id,
+ 'protocol': protocol,
+ 'twice_nat': twice_nat,
+ 'self_twice_nat': self_twice_nat,
+ 'out2in_only': out2in_only,
'tag': tag})
def nat44_add_del_identity_mapping(
@@ -828,7 +840,7 @@ class VppPapiProvider(object):
ip=b'0',
sw_if_index=0xFFFFFFFF,
port=0,
- flags=0,
+ addr_only=1,
vrf_id=0,
protocol=0,
tag='',
@@ -838,7 +850,7 @@ class VppPapiProvider(object):
:param ip: IP address (Default value = 0)
:param sw_if_index: Interface instead of IP address
:param port: Port number (Default value = 0)
- :param flags: NAT configuration flags (NAT_IS_ADDR_ONLY)
+ :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
@@ -847,13 +859,13 @@ class VppPapiProvider(object):
return self.api(
self.papi.nat44_add_del_identity_mapping,
{'is_add': is_add,
- 'flags': flags,
+ 'addr_only': addr_only,
'ip_address': ip,
- 'protocol': protocol,
'port': port,
'sw_if_index': sw_if_index,
'vrf_id': vrf_id,
- 'tag': tag})
+ 'tag': tag,
+ 'protocol': protocol})
def nat44_add_del_address_range(
self,
@@ -861,69 +873,73 @@ class VppPapiProvider(object):
last_ip_address,
is_add=1,
vrf_id=0xFFFFFFFF,
- flags=0):
+ twice_nat=0):
"""Add/del NAT44 address range
:param first_ip_address: First IP address
:param last_ip_address: Last IP address
:param vrf_id: VRF id for the address range
+ :param twice_nat: twice NAT address for extenral hosts
:param is_add: 1 if add, 0 if delete (Default value = 1)
- :param flags: NAT configuration flags (NAT_IS_TWICE_NAT)
"""
return self.api(
self.papi.nat44_add_del_address_range,
{'first_ip_address': first_ip_address,
'last_ip_address': last_ip_address,
'vrf_id': vrf_id,
- 'is_add': is_add,
- 'flags': flags})
+ 'twice_nat': twice_nat,
+ 'is_add': is_add})
def nat44_add_del_interface_addr(
self,
sw_if_index,
- flags=0,
+ twice_nat=0,
is_add=1):
"""Add/del NAT44 address from interface
:param sw_if_index: Software index of the interface
- :param flags: NAT configuration flags (NAT_IS_TWICE_NAT)
+ :param twice_nat: twice NAT address for external hosts
:param is_add: 1 if add, 0 if delete (Default value = 1)
"""
return self.api(
self.papi.nat44_add_del_interface_addr,
{'is_add': is_add,
'sw_if_index': sw_if_index,
- 'flags': flags})
+ 'twice_nat': twice_nat})
def nat44_add_del_lb_static_mapping(
self,
external_addr,
external_port,
protocol,
+ twice_nat=0,
+ self_twice_nat=0,
+ out2in_only=0,
tag='',
affinity=0,
local_num=0,
locals=[],
- flags=0,
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 affinity: if 0 disabled, otherwise client IP affinity timeout
- :param flags: NAT configuration flags (NAT_IS_TWICE_NAT)
:param is_add - 1 if add, 0 if delete
"""
return self.api(
self.papi.nat44_add_del_lb_static_mapping,
{'is_add': is_add,
- 'flags': flags,
'external_addr': external_addr,
'external_port': external_port,
'protocol': protocol,
+ 'twice_nat': twice_nat,
+ 'self_twice_nat': self_twice_nat,
+ 'out2in_only': out2in_only,
+ 'tag': tag,
'affinity': affinity,
'local_num': local_num,
- 'locals': locals,
- 'tag': tag})
+ 'locals': locals})
def nat44_lb_static_mapping_add_del_local(
self,
@@ -964,7 +980,7 @@ class VppPapiProvider(object):
port,
protocol,
vrf_id=0,
- flags=0,
+ is_in=1,
ext_host_address=None,
ext_host_port=0):
"""Delete NAT44 session
@@ -973,19 +989,29 @@ class VppPapiProvider(object):
:param por: port number
:param protocol: IP protocol number
:param vrf_id: VRF ID
- :param flags: NAT configuration flags (NAT_IS_INSIDE)
+ :param is_in: 1 if inside network address and port pair, 0 if outside
:param ext_host_address: external host IPv4 address
:param ext_host_port: external host port
"""
- return self.api(
- self.papi.nat44_del_session,
- {'address': addr,
- 'protocol': protocol,
- 'port': port,
- 'vrf_id': vrf_id,
- 'flags': flags,
- 'ext_host_address': ext_host_address,
- 'ext_host_port': ext_host_port})
+ if ext_host_address is None:
+ return self.api(
+ self.papi.nat44_del_session,
+ {'address': addr,
+ 'port': port,
+ 'protocol': protocol,
+ 'vrf_id': vrf_id,
+ 'is_in': is_in})
+ else:
+ return self.api(
+ self.papi.nat44_del_session,
+ {'address': addr,
+ 'port': port,
+ 'protocol': protocol,
+ 'vrf_id': vrf_id,
+ 'is_in': is_in,
+ 'ext_host_valid': 1,
+ 'ext_host_address': ext_host_address,
+ 'ext_host_port': ext_host_port})
def nat44_forwarding_enable_disable(
self,
@@ -998,6 +1024,56 @@ class VppPapiProvider(object):
self.papi.nat44_forwarding_enable_disable,
{'enable': enable})
+ def nat_det_add_del_map(
+ self,
+ in_addr,
+ in_plen,
+ out_addr,
+ out_plen,
+ is_add=1):
+ """Add/delete deterministic NAT 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.nat_det_add_del_map,
+ {'is_add': is_add,
+ 'is_nat44': 1,
+ 'in_addr': in_addr,
+ 'in_plen': in_plen,
+ 'out_addr': out_addr,
+ 'out_plen': out_plen})
+
+ def nat_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.nat_det_forward,
+ {'in_addr': in_addr,
+ 'is_nat44': 1})
+
+ def nat_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.nat_det_reverse,
+ {'out_addr': out_addr,
+ 'out_port': out_port})
+
def nat_det_map_dump(self):
"""Dump deterministic NAT mappings
@@ -1015,6 +1091,56 @@ class VppPapiProvider(object):
self.papi.nat_set_mss_clamping,
{'enable': enable, 'mss_value': mss_value})
+ def nat_det_close_session_in(
+ self,
+ in_addr,
+ in_port,
+ ext_addr,
+ ext_port):
+ """Close deterministic NAT session using inside address and port
+
+ :param in_addr - inside IP address
+ :param in_port - inside port
+ :param ext_addr - external host IP address
+ :param ext_port - external host port
+ """
+ return self.api(
+ self.papi.nat_det_close_session_in,
+ {'in_addr': in_addr,
+ 'in_port': in_port,
+ 'ext_addr': ext_addr,
+ 'ext_port': ext_port,
+ 'is_nat44': 1})
+
+ def nat_det_session_dump(
+ self,
+ user_addr):
+ """Dump deterministic NAT sessions belonging to a user
+
+ :param user_addr - inside IP address of the user
+ :return: Dictionary of deterministic NAT sessions
+ """
+ return self.api(
+ self.papi.nat_det_session_dump,
+ {'is_nat44': 1,
+ 'user_addr': user_addr})
+
+ def nat64_add_del_interface(
+ self,
+ sw_if_index,
+ is_inside=1,
+ is_add=1):
+ """Enable/disable NAT64 feature on the interface
+ :param sw_if_index: Index of the interface
+ :param is_inside: 1 if inside, 0 if outside (Default value = 1)
+ :param is_add: 1 if add, 0 if delete (Default value = 1)
+ """
+ return self.api(
+ self.papi.nat64_add_del_interface,
+ {'sw_if_index': sw_if_index,
+ 'is_inside': is_inside,
+ 'is_add': is_add})
+
def nat64_add_del_static_bib(
self,
in_ip,
@@ -1060,16 +1186,18 @@ class VppPapiProvider(object):
"""
return self.api(self.papi.nat64_st_dump, {'proto': protocol})
- def nat64_add_del_prefix(self, prefix, vrf_id=0, is_add=1):
+ def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
"""Add/del NAT64 prefix
:param prefix: NAT64 prefix
+ :param plen: NAT64 prefix length
:param vrf_id: VRF id of tenant (Default 0)
:param is_add: 1 if add, 0 if delete (Default value = 1)
"""
return self.api(
self.papi.nat64_add_del_prefix,
{'prefix': prefix,
+ 'prefix_len': plen,
'vrf_id': vrf_id,
'is_add': is_add})
@@ -1110,19 +1238,18 @@ class VppPapiProvider(object):
def nat66_add_del_interface(
self,
sw_if_index,
- flags=0,
+ is_inside=1,
is_add=1):
"""Enable/disable NAT66 feature on the interface
-
:param sw_if_index: Index of the interface
- :param flags: NAT configuration flags (NAT_IS_INSIDE)
+ :param is_inside: 1 if inside, 0 if outside (Default value = 1)
:param is_add: 1 if add, 0 if delete (Default value = 1)
"""
return self.api(
self.papi.nat66_add_del_interface,
- {'is_add': is_add,
- 'flags': flags,
- 'sw_if_index': sw_if_index})
+ {'sw_if_index': sw_if_index,
+ 'is_inside': is_inside,
+ 'is_add': is_add})
def nat66_add_del_static_mapping(
self,