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()