diff options
author | haiyanx1.zhang <haiyanx1.zhang@intel.com> | 2019-10-10 05:34:43 +0000 |
---|---|---|
committer | Peter Mikus <pmikus@cisco.com> | 2019-11-13 09:16:38 +0000 |
commit | 06e6da52159a865a3fd366d9aad09c31159f9e4b (patch) | |
tree | 78bf0658533580ca3fd8bbfce962ec3b34f4ee4d /resources/libraries/python/LoadBalancerUtil.py | |
parent | 1a4993354a24f9cf2d70d2b2b6b057852560b6e6 (diff) |
Add vpp loadbalancer l3dsr/nat4 mode test suites
Change-Id: I03603108fe7128fb4bde4abddb6a0959dd5b5c73
Signed-off-by: haiyanx1.zhang <haiyanx1.zhang@intel.com>
Diffstat (limited to 'resources/libraries/python/LoadBalancerUtil.py')
-rw-r--r-- | resources/libraries/python/LoadBalancerUtil.py | 33 |
1 files changed, 32 insertions, 1 deletions
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'])) |