def create_gre_tunnel_interface(node, source_ip, destination_ip): """Create GRE tunnel interface on node. :param node: VPP node to add tunnel interface. :param source_ip: Source of the GRE tunnel. :param destination_ip: Destination of the GRE tunnel. :type node: dict :type source_ip: str :type destination_ip: str :returns: Name and index of created GRE tunnel interface. :rtype: tuple :raises RuntimeError: If unable to create GRE tunnel interface. """ output = VatExecutor.cmd_from_template(node, "create_gre.vat", src=source_ip, dst=destination_ip) output = output[0] if output["retval"] == 0: sw_if_idx = output["sw_if_index"] vat_executor = VatExecutor() vat_executor.execute_script_json_out("dump_interfaces.vat", node) interface_dump_json = vat_executor.get_script_stdout() name = VatJsonUtil.get_interface_name_from_json( interface_dump_json, sw_if_idx) if_key = Topology.add_new_port(node, "gre_tunnel") Topology.update_interface_sw_if_index(node, if_key, sw_if_idx) Topology.update_interface_name(node, if_key, name) return name, sw_if_idx else: raise RuntimeError('Unable to create GRE tunnel on node {}.' .format(node))
def create_vxlan_interface(node, vni, source_ip, destination_ip): """Create VXLAN interface and return sw if index of created interface. Executes "vxlan_add_del_tunnel src {src} dst {dst} vni {vni}" VAT command on the node. :param node: Node where to create VXLAN interface. :param vni: VXLAN Network Identifier. :param source_ip: Source IP of a VXLAN Tunnel End Point. :param destination_ip: Destination IP of a VXLAN Tunnel End Point. :type node: dict :type vni: int :type source_ip: str :type destination_ip: str :returns: SW IF INDEX of created interface. :rtype: int :raises RuntimeError: if it is unable to create VxLAN interface on the node. """ output = VatExecutor.cmd_from_template(node, "vxlan_create.vat", src=source_ip, dst=destination_ip, vni=vni) output = output[0] if output["retval"] == 0: sw_if_idx = output["sw_if_index"] if_key = Topology.add_new_port(node, "vxlan_tunnel") Topology.update_interface_sw_if_index(node, if_key, sw_if_idx) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_idx) Topology.update_interface_name(node, if_key, ifc_name) return sw_if_idx else: raise RuntimeError("Unable to create VXLAN interface on node {0}" .format(node))
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 :returns: 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) sw_if_idx = resp[0]['sw_if_index'] if_key = Topology.add_new_port(node, 'tap') Topology.update_interface_sw_if_index(node, if_key, sw_if_idx) ifc_name = Tap.vpp_get_tap_interface_name(node, sw_if_idx) Topology.update_interface_name(node, if_key, ifc_name) if mac is None: mac = Tap.vpp_get_tap_interface_mac(node, sw_if_idx) Topology.update_interface_mac_address(node, if_key, mac) Topology.update_interface_tap_dev_name(node, if_key, tap_name) return sw_if_idx
def add_geneve_tunnel(node, local_address, remote_address, vni, multicast_if=None, encap_vrf=0, l3_mode=False, next_index=None): """Add GENEVE tunnel on the specified VPP node. :param node: Topology node. :param local_address: Local IP address. :param remote_address: Remote IP address. :param vni: Virtual network ID. :param multicast_if: Interface key of multicast interface; used only if remote is multicast. (Default value = None) :param encap_vrf: The FIB ID for sending unicast GENEVE encap packets or receiving multicast packets. (Default value = 0) :param l3_mode: Use geneve tunnel in L3 mode (ip routing) if Tue else in L2 mode (L2 switching). (Default value = False) :param next_index: The index of the next node. :type node: dict :type local_address: str :type remote_address: str :type vni: int :type multicast_if: str :type encap_vrf: int :type l3_mode: bool :type next_index: int :returns: SW interface index of created geneve tunnel. :rtype: int """ cmd = u"geneve_add_del_tunnel2" args = dict(is_add=True, local_address=IPAddress.create_ip_address_object( ip_address(local_address)), remote_address=IPAddress.create_ip_address_object( ip_address(remote_address)), mcast_sw_if_index=Topology.get_interface_sw_index( node, multicast_if) if multicast_if else Constants.BITWISE_NON_ZERO, encap_vrf_id=int(encap_vrf), decap_next_index=next_index if l3_mode else Constants.BITWISE_NON_ZERO, vni=int(vni), l3_mode=l3_mode) err_msg = f"Failed to configure GENEVE tunnel on host {node[u'host']}!" with PapiSocketExecutor(node) as papi_exec: sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg) if_key = Topology.add_new_port(node, u"geneve_tunnel") Topology.update_interface_sw_if_index(node, if_key, sw_if_index) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index) Topology.update_interface_mac_address(node, if_key, ifc_mac) return sw_if_index
def vpp_create_vhost_user_interface(node, socket): """Create Vhost-user interface on VPP node. :param node: Node to create Vhost-user interface on. :param socket: Vhost-user interface socket path. :type node: dict :type socket: str :returns: SW interface index. :rtype: int :raises RuntimeError: If Vhost-user interface creation failed. """ out = VatExecutor.cmd_from_template(node, 'create_vhost_user_if.vat', sock=socket) if out[0].get('retval') == 0: sw_if_idx = int(out[0].get('sw_if_index')) if_key = Topology.add_new_port(node, 'vhost') Topology.update_interface_sw_if_index(node, if_key, sw_if_idx) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_idx) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_idx) Topology.update_interface_mac_address(node, if_key, ifc_mac) Topology.update_interface_vhost_socket(node, if_key, socket) return sw_if_idx else: raise RuntimeError('Create Vhost-user interface failed on node ' '"{}"'.format(node['host']))
def vpp_create_vhost_user_interface(node, socket): """Create Vhost-user interface on VPP node. :param node: Node to create Vhost-user interface on. :param socket: Vhost-user interface socket path. :type node: dict :type socket: str :returns: SW interface index. :rtype: int """ cmd = 'create_vhost_user_if' err_msg = 'Failed to create Vhost-user interface on host {host}'.format( host=node['host']) args = dict(sock_filename=str(socket)) with PapiExecutor(node) as papi_exec: sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg) # Update the Topology: if_key = Topology.add_new_port(node, 'vhost') Topology.update_interface_sw_if_index(node, if_key, sw_if_index) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index) Topology.update_interface_mac_address(node, if_key, ifc_mac) Topology.update_interface_vhost_socket(node, if_key, socket) return sw_if_index
def add_bond_eth_interface(node, ifc_name=None, sw_if_idx=None): """Add BondEthernet interface to current topology. :param node: DUT node from topology. :param ifc_name: Name of the BondEthernet interface. :param sw_if_idx: SW interface index. :type node: dict :type ifc_name: str :type sw_if_idx: int """ if_key = Topology.add_new_port(node, 'eth_bond') vat_executor = VatExecutor() vat_executor.execute_script_json_out("dump_interfaces.vat", node) interface_dump_json = vat_executor.get_script_stdout() if ifc_name and sw_if_idx is None: sw_if_idx = VatJsonUtil.get_interface_sw_index_from_json( interface_dump_json, ifc_name) Topology.update_interface_sw_if_index(node, if_key, sw_if_idx) if sw_if_idx and ifc_name is None: ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_idx) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = VatJsonUtil.get_interface_mac_from_json( interface_dump_json, sw_if_idx) Topology.update_interface_mac_address(node, if_key, ifc_mac)
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; 0 means do not set. :param txq: Number of TX queues; 0 means do not set. :param role: Memif interface role [master=0|slave=1]. 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. """ role = getattr(MemifRole, role.upper()).value # Create socket Memif._memif_socket_filename_add_del(node, True, filename, sid) # Create memif sw_if_index = Memif._memif_create(node, mid, sid, rxq=rxq, txq=txq, role=role) # Update Topology if_key = Topology.add_new_port(node, 'memif') Topology.update_interface_sw_if_index(node, if_key, sw_if_index) ifc_name = Memif.vpp_get_memif_interface_name(node, sw_if_index) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = Memif.vpp_get_memif_interface_mac(node, sw_if_index) 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, str(role)) return sw_if_index
def add_tap_interface(node, tap_name, mac=None, num_rx_queues=1): """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. :param num_rx_queues: Number of RX queues. :type node: dict :type tap_name: str :type mac: str :type num_rx_queues: int :returns: Returns a interface index. :rtype: int """ cmd = u"tap_create_v2" args = dict(id=Constants.BITWISE_NON_ZERO, use_random_mac=bool(mac is None), mac_address=L2Util.mac_to_bin(mac) if mac else None, num_rx_queues=int(num_rx_queues), host_mtu_set=False, host_mac_addr_set=False, host_ip4_prefix_set=False, host_ip6_prefix_set=False, host_ip4_gw_set=False, host_ip6_gw_set=False, host_namespace_set=False, host_if_name_set=True, host_if_name=tap_name, host_bridge_set=False) err_msg = f"Failed to create tap interface {tap_name} " \ f"on host {node[u'host']}" with PapiSocketExecutor(node) as papi_exec: sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg) if_key = Topology.add_new_port(node, u"tap") Topology.update_interface_sw_if_index(node, if_key, sw_if_index) Topology.update_interface_name(node, if_key, tap_name) if mac is None: mac = Tap.vpp_get_tap_interface_mac(node, tap_name) Topology.update_interface_mac_address(node, if_key, mac) tap_dev_name = Tap.vpp_get_tap_dev_name(node, tap_name) Topology.update_interface_tap_dev_name(node, if_key, tap_dev_name) return sw_if_index
def vpp_create_vhost_user_interface(node, socket, is_server=False, virtio_feature_mask=None): """Create Vhost-user interface on VPP node. :param node: Node to create Vhost-user interface on. :param socket: Vhost-user interface socket path. :param is_server: Server side of connection. Default: False :param virtio_feature_mask: Mask of virtio features to be enabled. :type node: dict :type socket: str :type is_server: bool :type virtio_feature_mask: int :returns: SW interface index. :rtype: int """ cmd = u"create_vhost_user_if" err_msg = f"Failed to create Vhost-user interface " \ f"on host {node[u'host']}" if virtio_feature_mask is None: enable_gso = False else: enable_gso = VirtioFeatureMask.is_feature_enabled( virtio_feature_mask, VirtioFeaturesFlags.VIRTIO_NET_F_API_GSO) args = dict(is_server=bool(is_server), sock_filename=str(socket), enable_gso=bool(enable_gso)) with PapiSocketExecutor(node) as papi_exec: sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg) # Update the Topology: if_key = Topology.add_new_port(node, u"vhost") Topology.update_interface_sw_if_index(node, if_key, sw_if_index) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index) Topology.update_interface_mac_address(node, if_key, ifc_mac) Topology.update_interface_vhost_socket(node, if_key, socket) return sw_if_index
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 vpp_create_loopback(node): """Create loopback interface on VPP node. :param node: Node to create loopback interface on. :type node: dict :returns: SW interface index. :rtype: int :raises RuntimeError: If it is not possible to create loopback on the node. """ out = VatExecutor.cmd_from_template(node, "create_loopback.vat") if out[0].get('retval') == 0: sw_if_idx = out[0].get('sw_if_index') if_key = Topology.add_new_port(node, "loopback") Topology.update_interface_sw_if_index(node, if_key, sw_if_idx) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_idx) Topology.update_interface_name(node, if_key, ifc_name) return sw_if_idx else: raise RuntimeError('Create loopback failed on node "{}"' .format(node['host']))
def vpp_create_vhost_user_interface( node, socket, is_server=False, enable_gso=False): """Create Vhost-user interface on VPP node. :param node: Node to create Vhost-user interface on. :param socket: Vhost-user interface socket path. :param is_server: Server side of connection. Default: False :param enable_gso: Generic segmentation offloading. Default: False :type node: dict :type socket: str :type is_server: bool :type enable_gso: bool :returns: SW interface index. :rtype: int """ cmd = u"create_vhost_user_if" err_msg = f"Failed to create Vhost-user interface " \ f"on host {node[u'host']}" args = dict( is_server=bool(is_server), sock_filename=str(socket), enable_gso=bool(enable_gso) ) with PapiSocketExecutor(node) as papi_exec: sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg) # Update the Topology: if_key = Topology.add_new_port(node, u"vhost") Topology.update_interface_sw_if_index(node, if_key, sw_if_index) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index) Topology.update_interface_mac_address(node, if_key, ifc_mac) Topology.update_interface_vhost_socket(node, if_key, socket) return sw_if_index
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 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_put_vxlan_and_vlan_interfaces_up(node, vxlan_count, node_vlan_if): """ Update topology with VXLAN interfaces and VLAN sub-interfaces data and put interfaces up. :param node: VPP node. :param vxlan_count: Number of tunnel interfaces. :param node_vlan_if: VPP node interface key where VLAN sub-interfaces have been created. :type node: dict :type vxlan_count: int :type node_vlan_if: str """ if_data = InterfaceUtil.vpp_get_interface_data(node) if vxlan_count > 10: commands = list() for i in range(0, vxlan_count): vxlan_subif_key = Topology.add_new_port(node, u"vxlan_tunnel") vxlan_subif_name = f"vxlan_tunnel{i}" founds = dict(vxlan=False, vlan=False) vxlan_subif_idx = None vlan_subif_key = Topology.add_new_port(node, u"vlan_subif") vlan_subif_name = \ f"{Topology.get_interface_name(node, node_vlan_if)}.{i + 1}" vlan_idx = None for data in if_data: if_name = data[u"interface_name"] if not founds[u"vxlan"] and if_name == vxlan_subif_name: vxlan_subif_idx = data[u"sw_if_index"] founds[u"vxlan"] = True elif not founds[u"vlan"] and if_name == vlan_subif_name: vlan_idx = data[u"sw_if_index"] founds[u"vlan"] = True if founds[u"vxlan"] and founds[u"vlan"]: break Topology.update_interface_sw_if_index( node, vxlan_subif_key, vxlan_subif_idx) Topology.update_interface_name( node, vxlan_subif_key, vxlan_subif_name) commands.append( f"sw_interface_set_flags sw_if_index {vxlan_subif_idx} " f"admin-up link-up\n" ) Topology.update_interface_sw_if_index( node, vlan_subif_key, vlan_idx ) Topology.update_interface_name( node, vlan_subif_key, vlan_subif_name ) commands.append( f"sw_interface_set_flags sw_if_index {vlan_idx} admin-up " f"link-up\n" ) VatExecutor().write_and_execute_script( node, u"/tmp/put_subinterfaces_up.config", commands ) return cmd = u"sw_interface_set_flags" args1 = dict( sw_if_index=None, flags=InterfaceStatusFlags.IF_STATUS_API_FLAG_ADMIN_UP.value ) args2 = dict( sw_if_index=None, flags=InterfaceStatusFlags.IF_STATUS_API_FLAG_ADMIN_UP.value ) with PapiSocketExecutor(node) as papi_exec: for i in range(0, vxlan_count): vxlan_subif_key = Topology.add_new_port(node, u"vxlan_tunnel") vxlan_subif_name = f"vxlan_tunnel{i}" founds = dict(vxlan=False, vlan=False) vxlan_subif_idx = None vlan_subif_key = Topology.add_new_port(node, u"vlan_subif") vlan_subif_name = \ f"{Topology.get_interface_name(node, node_vlan_if)}.{i+1}" vlan_idx = None for data in if_data: if not founds[u"vxlan"] \ and data[u"interface_name"] == vxlan_subif_name: vxlan_subif_idx = data[u"sw_if_index"] founds[u"vxlan"] = True elif not founds[u"vlan"] \ and data[u"interface_name"] == vlan_subif_name: vlan_idx = data[u"sw_if_index"] founds[u"vlan"] = True if founds[u"vxlan"] and founds[u"vlan"]: break Topology.update_interface_sw_if_index( node, vxlan_subif_key, vxlan_subif_idx ) Topology.update_interface_name( node, vxlan_subif_key, vxlan_subif_name ) args1[u"sw_if_index"] = vxlan_subif_idx Topology.update_interface_sw_if_index( node, vlan_subif_key, vlan_idx ) Topology.update_interface_name( node, vlan_subif_key, vlan_subif_name ) args2[u"sw_if_index"] = vlan_idx history = bool(not 1 < i < vxlan_count - 1) papi_exec.add(cmd, history=history, **args1). \ add(cmd, history=history, **args2) papi_exec.add(cmd, **args1).add(cmd, **args2) papi_exec.get_replies()
def vpp_put_vxlan_and_vlan_interfaces_up(node, vxlan_count, node_vlan_if): """ Update topology with VXLAN interfaces and VLAN sub-interfaces data and put interfaces up. :param node: VPP node. :param vxlan_count: Number of tunnel interfaces. :param node_vlan_if: VPP node interface key where VLAN sub-interfaces have been created. :type node: dict :type vxlan_count: int :type node_vlan_if: str """ if_data = InterfaceUtil.vpp_get_interface_data(node) vlan_if_name = Topology.get_interface_name(node, node_vlan_if) if vxlan_count > 10: tmp_fn = '/tmp/put_subinterfaces_up.config' commands = list() for i in xrange(0, vxlan_count): vxlan_subif_key = Topology.add_new_port(node, 'vxlan_tunnel') vxlan_subif_name = 'vxlan_tunnel{nr}'.format(nr=i) vxlan_found = False vxlan_subif_idx = None vlan_subif_key = Topology.add_new_port(node, 'vlan_subif') vlan_subif_name = '{if_name}.{vlan}'.format( if_name=vlan_if_name, vlan=i + 1) vlan_found = False vlan_idx = None for data in if_data: if_name = data['interface_name'] if not vxlan_found and if_name == vxlan_subif_name: vxlan_subif_idx = data['sw_if_index'] vxlan_found = True elif not vlan_found and if_name == vlan_subif_name: vlan_idx = data['sw_if_index'] vlan_found = True if vxlan_found and vlan_found: break Topology.update_interface_sw_if_index(node, vxlan_subif_key, vxlan_subif_idx) Topology.update_interface_name(node, vxlan_subif_key, vxlan_subif_name) commands.append( 'sw_interface_set_flags sw_if_index {sw_idx} admin-up ' 'link-up\n'.format(sw_idx=vxlan_subif_idx)) Topology.update_interface_sw_if_index(node, vlan_subif_key, vlan_idx) Topology.update_interface_name(node, vlan_subif_key, vlan_subif_name) commands.append( 'sw_interface_set_flags sw_if_index {sw_idx} admin-up ' 'link-up\n'.format(sw_idx=vlan_idx)) VatExecutor().write_and_execute_script(node, tmp_fn, commands) return cmd = 'sw_interface_set_flags' args1 = dict(sw_if_index=None, admin_up_down=1) args2 = dict(sw_if_index=None, admin_up_down=1) err_msg = 'Failed to put VXLAN and VLAN interfaces up on host {host}'. \ format(host=node['host']) with PapiExecutor(node) as papi_exec: for i in xrange(0, vxlan_count): vxlan_subif_key = Topology.add_new_port(node, 'vxlan_tunnel') vxlan_subif_name = 'vxlan_tunnel{nr}'.format(nr=i) vxlan_found = False vxlan_subif_idx = None vlan_subif_key = Topology.add_new_port(node, 'vlan_subif') vlan_subif_name = '{if_name}.{vlan}'.format( if_name=vlan_if_name, vlan=i + 1) vlan_found = False vlan_idx = None for data in if_data: if not vxlan_found \ and data['interface_name'] == vxlan_subif_name: vxlan_subif_idx = data['sw_if_index'] vxlan_found = True elif not vlan_found \ and data['interface_name'] == vlan_subif_name: vlan_idx = data['sw_if_index'] vlan_found = True if vxlan_found and vlan_found: break Topology.update_interface_sw_if_index(node, vxlan_subif_key, vxlan_subif_idx) Topology.update_interface_name(node, vxlan_subif_key, vxlan_subif_name) args1['sw_if_index'] = vxlan_subif_idx Topology.update_interface_sw_if_index(node, vlan_subif_key, vlan_idx) Topology.update_interface_name(node, vlan_subif_key, vlan_subif_name) args2['sw_if_index'] = vlan_idx history = False if 1 < i < vxlan_count else True papi_exec.add(cmd, history=history, **args1). \ add(cmd, history=history, **args2) if i > 0 and i % (Constants.PAPI_MAX_API_BULK / 2) == 0: papi_exec.get_replies(err_msg) papi_exec.add(cmd, **args1).add(cmd, **args2) papi_exec.get_replies()