def cop_add_whitelist_entry(node, interface, ip_format, fib_id): """Add cop whitelisted entry. :param node: Node to add COP whitelist on. :param interface: Interface of the node where the COP is added. :param ip_format: IP format : ip4 or ip6 are valid formats. :param fib_id: Specify the fib table ID. :type node: dict :type interface: str :type ip_format: str :type fib_id: int """ if ip_format not in ('ip4', 'ip6'): raise ValueError("Ip not in correct format!") sw_if_index = Topology.get_interface_sw_index(node, interface) with VatTerminal(node) as vat: vat.vat_terminal_exec_cmd_from_template('cop_whitelist.vat', sw_if_index=sw_if_index, ip=ip_format, fib_id=fib_id)
def cop_interface_enable_or_disable(node, interface, state): """Enable or disable COP on the interface. :param node: Node to add COP whitelist on. :param interface: Interface of the node where the COP is added. :param state: disable/enable COP on the interface. :type node: dict :type interface: str :type state: str """ state = state.lower() if state in ('enable', 'disable'): if state == 'enable': state = '' sw_if_index = Topology.get_interface_sw_index(node, interface) with VatTerminal(node) as vat: vat.vat_terminal_exec_cmd_from_template( 'cop_interface.vat', sw_if_index=sw_if_index, state=state) else: raise ValueError("Possible values are 'enable' or 'disable'!")
def delete_tap_interface(node, if_index): """Delete tap interface. :param node: Node to delete tap on. :param if_index: Index of tap interface to be deleted. :type node: dict :type if_index: int :raises RuntimeError: Deletion was not successful. """ command = 'delete' args = 'sw_if_index {}'.format(if_index) with VatTerminal(node) as vat: resp = vat.vat_terminal_exec_cmd_from_template('tap.vat', tap_command=command, tap_arguments=args) if int(resp[0]['retval']) != 0: raise RuntimeError( 'Could not remove tap interface: {}'.format(resp)) if_key = Topology.get_interface_sw_index(node, if_index) Topology.remove_port(node, if_key)
def get_vhost_user_mac_by_sw_index(node, sw_if_index): """Get Vhost-user l2_address for the given interface from actual interface dump. :param node: VPP node to get interface data from. :param sw_if_index: Idx of the specific interface. :type node: dict :type sw_if_index: str :returns: l2_address of the given interface. :rtype: str """ with VatTerminal(node) as vat: if_data = vat.vat_terminal_exec_cmd_from_template( "interface_dump.vat") for iface in if_data[0]: if iface["sw_if_index"] == sw_if_index: return ':'.join("%02x" % (b) for b in iface["l2_address"][:6]) return None
def get_interface_vrf_table(node, interface): """Get vrf ID for the given interface. :param node: VPP node. :param interface: Name or sw_if_index of a specific interface. :type node: dict :type interface: str or int :returns: vrf ID of the specified interface. :rtype: int """ if isinstance(interface, basestring): sw_if_index = InterfaceUtil.get_sw_if_index(node, interface) else: sw_if_index = interface with VatTerminal(node) as vat: data = vat.vat_terminal_exec_cmd_from_template( "interface_vrf_dump.vat", sw_if_index=sw_if_index) return data[0]["vrf_id"]
def set_nat_workers(node, lcores): """Set NAT workers. :param node: DUT node. :param lcores: List of cores, format: range e.g. 1-5 or list of ranges e.g.: 1-5,18-22. :type node: dict :type lcores: str :returns: Response of the command. :rtype: str :raises RuntimeError: If setting of NAT workers fails. """ try: with VatTerminal(node, json_param=False) as vat: response = vat.vat_terminal_exec_cmd_from_template( 'nat/nat_set_workers.vat', lcores=lcores) return response except: raise RuntimeError("Setting of NAT workers failed!")
def add_fib_table(node, network, prefix_len, fib_id, place): """Create new FIB table according to ID. :param node: Node to add FIB on. :param network: IP address to add to the FIB table. :param prefix_len: IP address prefix length. :param fib_id: FIB table ID. :param place: Possible variants are local, drop. :type node: dict :type network: str :type prefix_len: int :type fib_id: int :type place: str """ with VatTerminal(node) as vat: vat.vat_terminal_exec_cmd_from_template('add_fib_table.vat', network=network, prefix_length=prefix_len, fib_number=fib_id, where=place)
def get_interface_classify_table(node, interface): """Get name of classify table for the given interface. :param node: VPP node to get data from. :param interface: Name or sw_if_index of a specific interface. :type node: dict :type interface: str or int :returns: Classify table name. :rtype: str """ if isinstance(interface, basestring): sw_if_index = InterfaceUtil.get_sw_if_index(node, interface) else: sw_if_index = interface with VatTerminal(node) as vat: data = vat.vat_terminal_exec_cmd_from_template( "classify_interface_table.vat", sw_if_index=sw_if_index) return data[0]
def set_ipfix_stream(node, domain=None, src_port=None): """Set an IPFIX export stream. Can be used to break up IPFIX reports into separate reporting domains. :param node: DUT node. :param domain: Desired index number of exporting domain. :param src_port: Source port to use when sending IPFIX packets. Default is the standard IPFIX port 4739. :type node: dict :type domain: int :type src_port: int """ domain = "domain {0}".format(domain) if domain else '' src_port = "src_port {0}".format(src_port) if src_port else '' with VatTerminal(node, json_param=False) as vat: vat.vat_terminal_exec_cmd_from_template("ipfix_stream_set.vat", domain=domain, src_port=src_port)
def get_classify_session_data(node, table_index, session_index=None): """Retrieve settings for all classify sessions in a table, or for a specific classify session. :param node: VPP node to retrieve classify data from. :param table_index: Index of a classify table. :param session_index: Index of a specific classify session. (Optional) :type node: dict :type table_index: int :type session_index: int :returns: List of classify session settings, or a dictionary of settings for a specific classify session. :rtype: list or dict """ with VatTerminal(node) as vat: data = vat.vat_terminal_exec_cmd_from_template( "classify_session_dump.vat", table_id=table_index) if session_index is not None: return data[0][session_index] return data[0]
def create_memif_interface(node, socket, mid, role='master'): """Create Memif interface on the given node. :param node: Given node to create Memif interface on. :param socket: Memif interface socket path. :param mid: Memif interface ID. :param role: Memif interface role [master|slave]. Default is master. :type node: dict :type socket: str :type mid: str :type role: str :returns: SW interface index. :rtype: int :raises ValueError: If command 'create memif' fails. """ with VatTerminal(node, json_param=False) as vat: vat.vat_terminal_exec_cmd_from_template( 'memif_create.vat', socket=socket, id=mid, role=role) if 'sw_if_index' in vat.vat_stdout: try: sw_if_idx = int(vat.vat_stdout.split()[4]) if_key = Topology.add_new_port(node, 'memif') Topology.update_interface_sw_if_index( node, if_key, sw_if_idx) ifc_name = Memif.vpp_get_memif_interface_name( node, sw_if_idx) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = Memif.vpp_get_memif_interface_mac(node, sw_if_idx) Topology.update_interface_mac_address(node, if_key, ifc_mac) Topology.update_interface_memif_socket(node, if_key, socket) Topology.update_interface_memif_id(node, if_key, mid) Topology.update_interface_memif_role(node, if_key, role) return sw_if_idx except KeyError: raise ValueError('Create Memif interface failed on node ' '{}'.format(node['host'])) else: raise ValueError('Create Memif interface failed on node ' '{}'.format(node['host']))
def l2_vlan_tag_rewrite(node, interface, tag_rewrite_method, push_dot1q=True, tag1_id=None, tag2_id=None): """Rewrite tags in ethernet frame. :param node: Node to rewrite tags. :param interface: Interface on which rewrite tags. :param tag_rewrite_method: Method of tag rewrite. :param push_dot1q: Optional parameter to disable to push dot1q tag instead of dot1ad. :param tag1_id: Optional tag1 ID for VLAN. :param tag2_id: Optional tag2 ID for VLAN. :type node: dict :type interface: str or int :type tag_rewrite_method: str :type push_dot1q: bool :type tag1_id: int :type tag2_id: int """ push_dot1q = 'push_dot1q 0' if not push_dot1q else '' tag1_id = 'tag1 {0}'.format(tag1_id) if tag1_id else '' tag2_id = 'tag2 {0}'.format(tag2_id) if tag2_id else '' if isinstance(interface, basestring): iface_key = Topology.get_interface_by_name(node, interface) sw_if_index = Topology.get_interface_sw_index(node, iface_key) else: sw_if_index = interface with VatTerminal(node) as vat: vat.vat_terminal_exec_cmd_from_template( "l2_vlan_tag_rewrite.vat", sw_if_index=sw_if_index, tag_rewrite_method=tag_rewrite_method, push_dot1q=push_dot1q, tag1_optional=tag1_id, tag2_optional=tag2_id)
def add_macip_acl(node, ip_ver="ipv4", action="permit", src_ip=None, src_mac=None, src_mac_mask=None): """Add a new MACIP ACL. :param node: VPP node to set MACIP ACL on. :param ip_ver: IP version. (Optional) :param action: ACL action. (Optional) :param src_ip: Source IP in format IP/plen. (Optional) :param src_mac: Source MAC address in format with colons. (Optional) :param src_mac_mask: Source MAC address mask in format with colons. 00:00:00:00:00:00 is a wildcard mask. (Optional) :type node: dict :type ip_ver: str :type action: str :type src_ip: str :type src_mac: str :type src_mac_mask: str :raises RuntimeError: If unable to add MACIP ACL. """ src_ip = 'ip {0}'.format(src_ip) if src_ip else '' src_mac = 'mac {0}'.format(src_mac) if src_mac else '' src_mac_mask = 'mask {0}'.format(src_mac_mask) if src_mac_mask else '' try: with VatTerminal(node, json_param=False) as vat: vat.vat_terminal_exec_cmd_from_template( "acl_plugin/macip_acl_add.vat", ip_ver=ip_ver, action=action, src_ip=src_ip, src_mac=src_mac, src_mac_mask=src_mac_mask) except RuntimeError: raise RuntimeError("Adding of MACIP ACL failed on node {0}".format( node['host']))
def vpp_get_tap_interface_name(node, sw_if_idx): """Get VPP tap interface name from hardware interfaces dump. :param node: DUT node. :param sw_if_idx: DUT node. :type node: dict :type sw_if_idx: int :returns: VPP tap interface name. :rtype: str """ with VatTerminal(node, json_param=False) as vat: response = vat.vat_terminal_exec_cmd_from_template( 'show_hardware_detail.vat') for line in str(response[0]).splitlines(): if line.startswith('tap-'): line_split = line.split() if line_split[1] == sw_if_idx: return line_split[0] return None
def vpp_del_if_ipv6_addr(node, interface, addr, prefix): """Delete IPv6 address on VPP. :param node: VPP node. :param interface: Node interface. :param addr: IPv6 address. :param prefix: IPv6 address prefix. :type node: dict :type interface: str :type addr: str :type prefix: str """ sw_if_index = Topology.get_interface_sw_index(node, interface) with VatTerminal(node) as vat: vat.vat_terminal_exec_cmd_from_template('del_ip_address.vat', sw_if_index=sw_if_index, address=addr, prefix_length=prefix) vat.vat_terminal_exec_cmd_from_template('set_if_state.vat', sw_if_index=sw_if_index, state='admin-down')
def show_snat_deterministic_forward(node, ip_addr): """Show forward IP address and port(s). :param node: DUT node. :param ip_addr: IP address. :type node: dict :type ip_addr: str :returns: Response of the command. :rtype: str :raises RuntimeError: If command 'exec snat deterministic forward' fails. """ try: with VatTerminal(node, json_param=False) as vat: response = vat.vat_terminal_exec_cmd_from_template( 'snat/snat_deterministic_forward.vat', ip=ip_addr) return response except: raise RuntimeError("Command 'exec snat deterministic forward {ip}'" " failed!".format(ip=ip_addr))
def tap_dump(node, name=None): """Get all TAP interface data from the given node, or data about a specific TAP interface. :param node: VPP node to get data from. :param name: Optional name of a specific TAP interface. :type node: dict :type name: str :returns: Dictionary of information about a specific TAP interface, or a List of dictionaries containing all TAP data for the given node. :rtype: dict or list """ with VatTerminal(node) as vat: response = vat.vat_terminal_exec_cmd_from_template("tap_dump.vat") if name is None: return response[0] else: for item in response[0]: if name == item['dev_name']: return item return {}
def add_tap_interface(node, tap_name, mac=None): """Add tap interface with name and optionally with MAC. :param node: Node to add tap on. :param tap_name: Tap interface name for linux tap. :param mac: Optional MAC address for VPP tap. :type node: dict :type tap_name: str :type mac: str :return: Returns a interface index. :rtype: int """ command = 'connect' if mac is not None: args = 'tapname {} mac {}'.format(tap_name, mac) else: args = 'tapname {}'.format(tap_name) with VatTerminal(node) as vat: resp = vat.vat_terminal_exec_cmd_from_template('tap.vat', tap_command=command, tap_arguments=args) return resp[0]['sw_if_index']
def add_ip_neighbor(node, interface, ip_address, mac_address): """Add IP neighbor. :param node: VPP node to add ip neighbor. :param interface: Interface name or sw_if_index. :param ip_address: IP address. :param mac_address: MAC address. :type node: dict :type interface: str or int :type ip_address: str :type mac_address: str """ if isinstance(interface, basestring): sw_if_index = Topology.get_interface_sw_index(node, interface) else: sw_if_index = interface with VatTerminal(node) as vat: vat.vat_terminal_exec_cmd_from_template("add_ip_neighbor.vat", sw_if_index=sw_if_index, ip_address=ip_address, mac_address=mac_address)
def get_l2_fib_table_vat(node, bd_index): """Retrieves the L2 FIB table using VAT. :param node: VPP node. :param bd_index: Index of the bridge domain. :type node: dict :type bd_index: int :returns: L2 FIB table. :rtype: list """ bd_data = L2Util.vpp_get_bridge_domain_data(node) bd_id = bd_data[bd_index-1]["bd_id"] try: with VatTerminal(node) as vat: table = vat.vat_terminal_exec_cmd_from_template( "l2_fib_table_dump.vat", bd_id=bd_id) return table[0] except ValueError: return []
def create_vlan_subinterface(node, interface, vlan): """Create VLAN subinterface on node. :param node: Node to add VLAN subinterface on. :param interface: Interface name on which create VLAN subinterface. :param vlan: VLAN ID of the subinterface to be created. :type node: dict :type interface: str :type vlan: int :returns: Name and index of created subinterface. :rtype: tuple :raises RuntimeError: if it is unable to create VLAN subinterface on the node. """ iface_key = Topology.get_interface_by_name(node, interface) sw_if_index = Topology.get_interface_sw_index(node, iface_key) output = VatExecutor.cmd_from_template(node, "create_vlan_subif.vat", sw_if_index=sw_if_index, vlan=vlan) if output[0]["retval"] == 0: sw_subif_idx = output[0]["sw_if_index"] logger.trace( 'VLAN subinterface with sw_if_index {} and VLAN ID {} ' 'created on node {}'.format(sw_subif_idx, vlan, node['host'])) if_key = Topology.add_new_port(node, "vlan_subif") Topology.update_interface_sw_if_index(node, if_key, sw_subif_idx) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_subif_idx) Topology.update_interface_name(node, if_key, ifc_name) else: raise RuntimeError( 'Unable to create VLAN subinterface on node {}'.format( node['host'])) with VatTerminal(node, False) as vat: vat.vat_terminal_exec_cmd('exec show interfaces') return '{}.{}'.format(interface, vlan), sw_subif_idx
def vpp_configures_classify_session_generic(node, session_type, table_index, skip_n, match_n, match, match2=''): """Configuration of classify session. :param node: VPP node to setup classify session. :param session_type: Session type - hit-next, l2-hit-next, acl-hit-next or policer-hit-next, and their respective parameters. :param table_index: Classify table index. :param skip_n: Number of skip vectors based on mask. :param match_n: Number of match vectors based on mask. :param match: Match value - l2, l3, l4 or hex, and their respective parameters. :param match2: Additional match values, to avoid using overly long variables in RobotFramework. :type node: dict :type session_type: str :type table_index: int :type skip_n: int :type match_n: int :type match: str :type match2: str """ match = ' '.join((match, match2)) with VatTerminal(node) as vat: vat.vat_terminal_exec_cmd_from_template( "classify_add_session_generic.vat", type=session_type, table_index=table_index, skip_n=skip_n, match_n=match_n, match=match, )
def vpp_enable_input_acl_interface(node, interface, ip_version, table_index): """Enable input acl on interface. :param node: VPP node to setup interface for input acl. :param interface: Interface to setup input acl. :param ip_version: Version of IP protocol. :param table_index: Classify table index. :type node: dict :type interface: str or int :type ip_version: str :type table_index: int """ if isinstance(interface, basestring): sw_if_index = Topology.get_interface_sw_index(node, interface) else: sw_if_index = interface with VatTerminal(node) as vat: vat.vat_terminal_exec_cmd_from_template("input_acl_int.vat", sw_if_index=sw_if_index, ip_version=ip_version, table_index=table_index)
def add_macip_acl_multi_entries(node, rules=None): """Add a new MACIP ACL. :param node: VPP node to set MACIP ACL on. :param rules: Required MACIP rules. (Optional) :type node: dict :type rules: str :raises RuntimeError: If unable to add MACIP ACL. """ rules = '{0}'.format(rules) if rules else '' try: with VatTerminal(node, json_param=False) as vat: vat.vat_terminal_exec_cmd_from_template( "acl_plugin/macip_acl_add.vat", ip_ver=rules, action='', src_ip='', src_mac='', src_mac_mask='') except RuntimeError: raise RuntimeError("Adding of MACIP ACL failed on node {0}".format( node['host']))
def vpp_get_interface_ip_addresses(node, interface, ip_version): """Get list of IP addresses from an interface on a VPP node. :param node: VPP node to get data from. :param interface: Name of an interface on the VPP node. :param ip_version: IP protocol version (ipv4 or ipv6). :type node: dict :type interface: str :type ip_version: str :returns: List of dictionaries, each containing IP address, subnet prefix length and also the subnet mask for ipv4 addresses. Note: A single interface may have multiple IP addresses assigned. :rtype: list """ try: sw_if_index = Topology.convert_interface_reference( node, interface, "sw_if_index") except RuntimeError: if isinstance(interface, basestring): sw_if_index = InterfaceUtil.get_sw_if_index(node, interface) else: raise with VatTerminal(node) as vat: response = vat.vat_terminal_exec_cmd_from_template( "ip_address_dump.vat", ip_version=ip_version, sw_if_index=sw_if_index) data = response[0] if ip_version == "ipv4": for item in data: item["netmask"] = convert_ipv4_netmask_prefix( item["prefix_length"]) return data
def vpp_get_bridge_domain_data(node, bd_id=None): """Get all bridge domain data from a VPP node. If a domain ID number is provided, return only data for the matching bridge domain. :param node: VPP node to get bridge domain data from. :param bd_id: Numeric ID of a specific bridge domain. :type node: dict :type bd_id: int :returns: List of dictionaries containing data for each bridge domain, or a single dictionary for the specified bridge domain. :rtype: list or dict """ with VatTerminal(node) as vat: response = vat.vat_terminal_exec_cmd_from_template("l2_bd_dump.vat") data = response[0] if bd_id is not None: for bridge_domain in data: if bridge_domain["bd_id"] == bd_id: return bridge_domain return data
def configure_sr_policy(node, bsid, sid_list, mode='encap'): """Create SRv6 policy on the given node. :param node: Given node to create SRv6 policy on. :param bsid: BindingSID - local SID IPv6 address. :param sid_list: SID list. :param mode: Encapsulation / insertion mode. :type node: dict :type bsid: str :type sid_list: list :type mode: str """ sid_conf = 'next ' + ' next '.join(sid_list) with VatTerminal(node, json_param=False) as vat: vat.vat_terminal_exec_cmd_from_template('srv6/sr_policy_add.vat', bsid=bsid, sid_conf=sid_conf, mode=mode) if "exec error: Misc" in vat.vat_stdout: raise RuntimeError( 'Create SRv6 policy for BindingSID {0} failed on' ' node {1}'.format(bsid, node['host']))
def create_subinterface(node, interface, sub_id, outer_vlan_id=None, inner_vlan_id=None, type_subif=None): """Create sub-interface on node. It is possible to set required sub-interface type and VLAN tag(s). :param node: Node to add sub-interface. :param interface: Interface name on which create sub-interface. :param sub_id: ID of the sub-interface to be created. :param outer_vlan_id: Optional outer VLAN ID. :param inner_vlan_id: Optional inner VLAN ID. :param type_subif: Optional type of sub-interface. Values supported by VPP: [no_tags] [one_tag] [two_tags] [dot1ad] [exact_match] [default_sub] :type node: dict :type interface: str or int :type sub_id: int :type outer_vlan_id: int :type inner_vlan_id: int :type type_subif: str :returns: Name and index of created sub-interface. :rtype: tuple :raises RuntimeError: If it is not possible to create sub-interface. """ outer_vlan_id = 'outer_vlan_id {0}'.format(outer_vlan_id)\ if outer_vlan_id else '' inner_vlan_id = 'inner_vlan_id {0}'.format(inner_vlan_id)\ if inner_vlan_id else '' if type_subif is None: type_subif = '' if isinstance(interface, basestring): iface_key = Topology.get_interface_by_name(node, interface) sw_if_index = Topology.get_interface_sw_index(node, iface_key) else: sw_if_index = interface output = VatExecutor.cmd_from_template(node, "create_sub_interface.vat", sw_if_index=sw_if_index, sub_id=sub_id, outer_vlan_id=outer_vlan_id, inner_vlan_id=inner_vlan_id, type_subif=type_subif) if output[0]["retval"] == 0: sw_subif_idx = output[0]["sw_if_index"] logger.trace('Created subinterface with index {}' .format(sw_subif_idx)) if_key = Topology.add_new_port(node, "subinterface") Topology.update_interface_sw_if_index(node, if_key, sw_subif_idx) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_subif_idx) Topology.update_interface_name(node, if_key, ifc_name) else: raise RuntimeError('Unable to create sub-interface on node {}' .format(node['host'])) with VatTerminal(node, json_param=False) as vat: vat.vat_terminal_exec_cmd('exec show interfaces') name = '{}.{}'.format(interface, sub_id) return name, sw_subif_idx
def create_memif_interface(node, filename, mid, sid, rxq=1, txq=1, role='slave'): """Create Memif interface on the given node. :param node: Given node to create Memif interface on. :param filename: Memif interface socket filename. :param mid: Memif interface ID. :param sid: Socket ID. :param rxq: Number of RX queues. :param txq: Number of TX queues. :param role: Memif interface role [master|slave]. Default is master. :type node: dict :type filename: str :type mid: str :type sid: str :type rxq: int :type txq: int :type role: str :returns: SW interface index. :rtype: int :raises ValueError: If command 'create memif' fails. """ with VatTerminal(node, json_param=False) as vat: vat.vat_terminal_exec_cmd_from_template( 'memif_socket_filename_add_del.vat', add_del='add', id=sid, filename='/tmp/' + filename) vat.vat_terminal_exec_cmd_from_template('memif_create.vat', id=mid, socket=sid, rxq=rxq, txq=txq, role=role) if 'sw_if_index' in vat.vat_stdout: try: sw_if_idx = int(vat.vat_stdout.split()[4]) if_key = Topology.add_new_port(node, 'memif') Topology.update_interface_sw_if_index( node, if_key, sw_if_idx) ifc_name = Memif.vpp_get_memif_interface_name( node, sw_if_idx) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = Memif.vpp_get_memif_interface_mac( node, sw_if_idx) Topology.update_interface_mac_address( node, if_key, ifc_mac) Topology.update_interface_memif_socket( node, if_key, '/tmp/' + filename) Topology.update_interface_memif_id(node, if_key, mid) Topology.update_interface_memif_role(node, if_key, role) return sw_if_idx except KeyError: raise ValueError('Create Memif interface failed on node ' '{}'.format(node['host'])) else: raise ValueError('Create Memif interface failed on node ' '{}'.format(node['host']))
def vpp_route_add(node, network, prefix_len, gateway=None, interface=None, use_sw_index=True, resolve_attempts=10, count=1, vrf=None, lookup_vrf=None, multipath=False, weight=None): """Add route to the VPP node. :param node: Node to add route on. :param network: Route destination network address. :param prefix_len: Route destination network prefix length. :param gateway: Route gateway address. :param interface: Route interface. :param vrf: VRF table ID (Optional). :param use_sw_index: Use sw_if_index in VAT command. :param resolve_attempts: Resolve attempts IP route add parameter. :param count: number of IP addresses to add starting from network IP with same prefix (increment is 1). If None, then is not used. :param lookup_vrf: VRF table ID for lookup. :param multipath: Enable multipath routing. :param weight: Weight value for unequal cost multipath routing. :type node: dict :type network: str :type prefix_len: int :type gateway: str :type interface: str :type use_sw_index: bool :type resolve_attempts: int :type count: int :type vrf: int :type lookup_vrf: int :type multipath: bool :type weight: int """ if use_sw_index: int_cmd = ('sw_if_index {}'.format( Topology.get_interface_sw_index(node, interface))) else: int_cmd = interface rap = 'resolve-attempts {}'.format(resolve_attempts) \ if resolve_attempts else '' via = 'via {}'.format(gateway) if gateway else '' cnt = 'count {}'.format(count) \ if count else '' vrf = 'vrf {}'.format(vrf) if vrf else '' lookup_vrf = 'lookup-in-vrf {}'.format( lookup_vrf) if lookup_vrf else '' multipath = 'multipath' if multipath else '' weight = 'weight {}'.format(weight) if weight else '' with VatTerminal(node, json_param=False) as vat: vat.vat_terminal_exec_cmd_from_template('add_route.vat', network=network, prefix_length=prefix_len, via=via, vrf=vrf, interface=int_cmd, resolve_attempts=rap, count=cnt, lookup_vrf=lookup_vrf, multipath=multipath, weight=weight)