- if node['type'] == NodeType.DUT:
- cmd = 'lb_add_del_as'
- err_msg = 'Failed to add lb as on host {host}'.format(
- host=node['host'])
-
- vip_addr = kwargs.pop('vip_addr', '0.0.0.0')
- protocol = kwargs.pop('protocol', 255)
- port = kwargs.pop('port', 0)
- as_addr = kwargs.pop('as_addr', '0.0.0.0')
- is_del = kwargs.pop('is_del', 0)
- is_flush = kwargs.pop('is_flush', 0)
-
- vip_addr = ip_address(unicode(vip_addr)).packed
- as_addr = ip_address(unicode(as_addr)).packed
-
- args = dict(pfx={'len': 128,
- 'address': {'un': {'ip4': vip_addr}, 'af': 0}},
- protocol=protocol,
- port=port,
- as_address={'un': {'ip4': as_addr}, 'af': 0},
- is_del=is_del,
- is_flush=is_flush)
+ if node[u"type"] == NodeType.DUT:
+ cmd = u"lb_add_del_as"
+ err_msg = f"Failed to add lb as on host {node[u'host']}"
+
+ vip_addr = kwargs.pop(u"vip_addr", "0.0.0.0")
+ protocol = kwargs.pop(u"protocol", 255)
+ port = kwargs.pop(u"port", 0)
+ as_addr = kwargs.pop(u"as_addr", u"0.0.0.0")
+ is_del = kwargs.pop(u"is_del", 0)
+ is_flush = kwargs.pop(u"is_flush", 0)
+
+ vip_addr = ip_address(vip_addr).packed
+ as_addr = ip_address(as_addr).packed
+
+ args = dict(
+ pfx={
+ u"len": 128,
+ u"address": {u"un": {u"ip": vip_addr}, u"af": 0}
+ },
+ protocol=protocol,
+ port=port,
+ as_address={u"un": {u"ip": as_addr}, u"af": 0},
+ is_del=is_del,
+ is_flush=is_flush
+ )
+
+ with PapiSocketExecutor(node) as papi_exec:
+ papi_exec.add(cmd, **args).get_reply(err_msg)
+ else:
+ raise ValueError(
+ f"Node {node[u'host']} has unknown NodeType: '{node[u'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[u"type"] == NodeType.DUT:
+ cmd = u"lb_add_del_intf_nat4"
+ err_msg = f"Failed to add interface nat4 on host {node[u'host']}"
+
+ is_add = kwargs.pop(u"is_add", True)
+ interface = kwargs.pop(u"interface", 0)
+ sw_if_index = Topology.get_interface_sw_index(node, interface)
+ args = dict(
+ is_add=is_add,
+ sw_if_index=sw_if_index
+ )