From 06e6da52159a865a3fd366d9aad09c31159f9e4b Mon Sep 17 00:00:00 2001 From: "haiyanx1.zhang" Date: Thu, 10 Oct 2019 05:34:43 +0000 Subject: Add vpp loadbalancer l3dsr/nat4 mode test suites Change-Id: I03603108fe7128fb4bde4abddb6a0959dd5b5c73 Signed-off-by: haiyanx1.zhang --- resources/libraries/python/LoadBalancerUtil.py | 33 +++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'resources/libraries/python/LoadBalancerUtil.py') diff --git a/resources/libraries/python/LoadBalancerUtil.py b/resources/libraries/python/LoadBalancerUtil.py index 26bf965c39..77f6412973 100644 --- a/resources/libraries/python/LoadBalancerUtil.py +++ b/resources/libraries/python/LoadBalancerUtil.py @@ -15,7 +15,7 @@ from socket import htonl from ipaddress import ip_address -from resources.libraries.python.topology import NodeType +from resources.libraries.python.topology import NodeType, Topology from resources.libraries.python.PapiExecutor import PapiSocketExecutor class LoadBalancerUtil(object): @@ -174,3 +174,34 @@ class LoadBalancerUtil(object): else: raise ValueError('Node {host} has unknown NodeType: "{type}"' .format(host=node['host'], type=node['type'])) + + @staticmethod + def vpp_lb_add_del_intf_nat4(node, **kwargs): + """Enable/disable NAT4 feature on the interface. + + :param node: Node where the interface is. + :param kwargs: Optional key-value arguments: + + is_add: true if add, false if delete. (bool) + interface: software index of the interface. (int) + + :type node: dict + :type kwargs: dict + :returns: Nothing. + :raises ValueError: If the node has an unknown node type. + """ + if node['type'] == NodeType.DUT: + cmd = 'lb_add_del_intf_nat4' + err_msg = 'Failed to add interface nat4 on host {host}'.format( + host=node['host']) + + is_add = kwargs.pop('is_add', True) + interface = kwargs.pop('interface', 0) + sw_if_index = Topology.get_interface_sw_index(node, interface) + args = dict(is_add=is_add, sw_if_index=sw_if_index) + + with PapiSocketExecutor(node) as papi_exec: + papi_exec.add(cmd, **args).get_reply(err_msg) + else: + raise ValueError('Node {host} has unknown NodeType: "{type}"' + .format(host=node['host'], type=node['type'])) -- cgit 1.2.3-korg