X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FLoadBalancerUtil.py;h=77f641297339e6d0ff0206d0967b3242e0bd035a;hb=06e6da52159a865a3fd366d9aad09c31159f9e4b;hp=26bf965c3990891599317465adb7236f3c3f0ee3;hpb=18479deef4bc6fba143492f538cd4139c38e44ab;p=csit.git 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']))