From 886ea37702aea6df901aa50bb6791fcf50a77e2a Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 5 Nov 2024 17:33:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20iperf=E6=94=AF=E6=8C=81v2=E5=92=8Cv3?= =?UTF-8?q?=E7=9A=84=E5=91=BD=E4=BB=A4=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/tool/iperf/index.vue | 178 ++++++++++++++++++++++++++------- 1 file changed, 142 insertions(+), 36 deletions(-) diff --git a/src/views/tool/iperf/index.vue b/src/views/tool/iperf/index.vue index ef35bfa5..3119a83a 100644 --- a/src/views/tool/iperf/index.vue +++ b/src/views/tool/iperf/index.vue @@ -38,7 +38,8 @@ let state = reactive({ /**ws数据 */ data: { command: '', // 命令字符串 - client: true, // 服务端或客户端,默认服务端 + version: 'V3', // 服务版本,默认V3 + mode: 'client', // 服务端或客户端,默认服务端 // Server or Client port: 5201, // 服务端口 interval: 1, // 每次报告之间的时间间隔,单位为秒 @@ -50,11 +51,13 @@ let state = reactive({ time: 10, // 以秒为单位的传输时间(默认为 10 秒) reverse: false, // 以反向模式运行(服务器发送,客户端接收) window: '300k', // 设置窗口大小/套接字缓冲区大小 + parallel: 1, // 运行的并行客户端流数量 + bitrate: 0, // 以比特/秒为单位(0 表示无限制) }, }); /**连接发送 */ -async function fnIPerf3() { +async function fnIPerf() { const [neType, neId] = state.neType; if (!neType || !neId) { message.warning({ @@ -77,14 +80,15 @@ async function fnIPerf3() { }); return; } - if (state.initialized) { - fnResend(); - return; - } - + // 软件版本检查 state.params.neType = neType; state.params.neId = neId; - const resVersion = await iperfV({ neType, neId }); + const resVersion = await iperfV({ + neType, + neId, + version: state.data.version, + }); + if (resVersion.code !== RESULT_CODE_SUCCESS) { Modal.confirm({ title: t('common.tipTitle'), @@ -95,15 +99,20 @@ async function fnIPerf3() { } else { state.versionInfo = resVersion.data; } + // 初始化的直接重发 + if (state.initialized) { + fnResend(); + return; + } state.initialized = true; } -/**触发安装iperf3 */ +/**触发安装iperf */ function fnInstall() { const key = 'iperfI'; message.loading({ content: t('common.loading'), key }); const { neType, neId } = state.params; - iperfI({ neType, neId }).then(res => { + iperfI({ neType, neId, version: state.data.version }).then(res => { if (res.code === RESULT_CODE_SUCCESS) { message.success({ content: 'install success', @@ -140,7 +149,7 @@ function fnResend() { setTimeout(() => { const data = JSON.parse(JSON.stringify(state.data)); if (state.dataType === 'options') data.command = ''; - toolTerminal.value.send('iperf3', data); + toolTerminal.value.send('iperf', data); }, 1000); } @@ -149,6 +158,38 @@ function fnConnect() { fnResend(); } +/**终端消息处理*/ +function fnProcessMessage(data: string): string { + // 查找的开始输出标记 + const parts: string[] = data.split('\u001b[?2004l\r'); + if (parts.length > 0) { + if (parts[0].startsWith('^C') || parts[0].startsWith('\r')) { + return ''; + } + let text = parts[parts.length - 1]; + // 找到最后输出标记 + let lestIndex = text.lastIndexOf('\u001b[?2004h\u001b]0;'); + if (lestIndex !== -1) { + text = text.substring(0, lestIndex); + } + if (text === '' || text === '\r\n' || text.startsWith('^C')) { + return ''; + } + // 是否还有最后输出标记 + lestIndex = text.lastIndexOf('\u001b[?2004h'); + if (lestIndex !== -1) { + text = text.substring(0, lestIndex); + } + + // console.log({ parts, text }); + if (parts[0].startsWith('iperf')) { + return parts[0] + '\r\n' + text; + } + return text; + } + return data; +} + /**终端消息监听*/ function fnMessage(res: Record) { const { code, requestId, data } = res; @@ -162,6 +203,11 @@ function fnMessage(res: Record) { state.running = false; return; } + lestIndex = data.lastIndexOf('failed:'); + if (lestIndex !== -1) { + state.running = false; + return; + } lestIndex = data.lastIndexOf('iperf Done.'); if (lestIndex !== -1) { state.running = false; @@ -231,7 +277,7 @@ onBeforeUnmount(() => {});