ipoe: fluxo adicionado fix
Signed-off-by: Rodrigo Martins <rodrigo@martinsevieira.adv.br>
This commit is contained in:
1 parent
ef6f94067b
commit
a976a9fa58
1 file changed
+95
-15
@@ -886,8 +886,12 @@ class FiberhomeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configura IPoE em ONU FiberHome: SET-WANSERVICE com VLAN 977
|
* Configura IPoE em ONU FiberHome: deleta WAN services existentes e recria com VLAN 977
|
||||||
* Busca a ONU registrada pela serial e reconfigura as portas WAN
|
* 1. Busca ONU registrada pelo serial
|
||||||
|
* 2. Consulta WAN services existentes (LST-ONUWANSERVICECFG)
|
||||||
|
* 3. Deleta cada WAN service (SET-WANSERVICE STATUS=2)
|
||||||
|
* 4. Recria com VLAN 977 (SET-WANSERVICE STATUS=1)
|
||||||
|
* 5. Reinicia ONU
|
||||||
* @param {string} serial - MAC/Serial da ONU
|
* @param {string} serial - MAC/Serial da ONU
|
||||||
* @param {string} onuType - Tipo da ONU (para determinar número de portas)
|
* @param {string} onuType - Tipo da ONU (para determinar número de portas)
|
||||||
* @returns {Promise} - Promise com resultado
|
* @returns {Promise} - Promise com resultado
|
||||||
@@ -902,30 +906,56 @@ class FiberhomeManager {
|
|||||||
throw new Error('Não foi possível conectar ao UNM2000');
|
throw new Error('Não foi possível conectar ao UNM2000');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buscar ONU registrada pelo serial (retorna o objeto diretamente ou lança exceção)
|
// Buscar ONU registrada pelo serial
|
||||||
const onuInfo = await this.buscarOnuRegistrada(serial);
|
const onuInfo = await this.buscarOnuRegistrada(serial);
|
||||||
|
|
||||||
const nameOlt = onuInfo.nameOlt || this.config.olt.name;
|
const nameOlt = onuInfo.nameOlt || this.config.olt.name;
|
||||||
const portAlias = onuInfo.portAlias;
|
const portAlias = onuInfo.portAlias;
|
||||||
|
|
||||||
this.logger.info('ONU encontrada, reconfigurando WAN Service', { nameOlt, portAlias, serial, vlan: VLAN_IPOE });
|
this.logger.info('ONU encontrada, consultando WAN Services existentes', { nameOlt, portAlias, serial });
|
||||||
|
|
||||||
// SET-WANSERVICE com VLAN 977
|
// 1. Consultar WAN services existentes
|
||||||
const numPortas = onuType === 'AN5506-02-B' ? 2 : 1;
|
const lstCmd = `LST-ONUWANSERVICECFG::OLTID=${nameOlt},PONID=NA-NA-${portAlias},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::;`;
|
||||||
|
this.logger.debug('Consultando WAN Services', { comando: lstCmd });
|
||||||
|
const lstResult = await this.executarComandoTL1(lstCmd);
|
||||||
|
|
||||||
for (let porta = 1; porta <= numPortas; porta++) {
|
let wanServices = [];
|
||||||
const setWanCmd = `SET-WANSERVICE::OLTID=${nameOlt},PONID=NA-NA-${portAlias},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::STATUS=1,MODE=2,CONNTYPE=1,VLAN=${VLAN_IPOE},COS=0,QOS=2,UPORT=${porta};`;
|
if (lstResult.success && lstResult.data) {
|
||||||
this.logger.debug(`Configurando WAN Service IPoE porta ${porta}`, { comando: setWanCmd });
|
wanServices = this._parseWanServices(lstResult.data);
|
||||||
|
this.logger.info(`WAN Services encontrados: ${wanServices.length}`, { wanServices });
|
||||||
const resultado = await this.executarComandoTL1(setWanCmd);
|
|
||||||
if (!resultado.success) {
|
|
||||||
this.logger.warn(`Aviso ao configurar WAN porta ${porta}: ${resultado.error}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. Deletar WAN services existentes
|
||||||
|
for (const ws of wanServices) {
|
||||||
|
const delCmd = `SET-WANSERVICE::OLTID=${nameOlt},PONID=NA-NA-${portAlias},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::STATUS=2,MODE=${ws.mode},CONNTYPE=${ws.connType},VLAN=${ws.vlan},COS=${ws.cos},UPORT=${ws.uport};`;
|
||||||
|
this.logger.debug(`Deletando WAN Service porta ${ws.uport}`, { comando: delCmd });
|
||||||
|
|
||||||
|
const delResult = await this.executarComandoTL1(delCmd);
|
||||||
|
if (!delResult.success) {
|
||||||
|
this.logger.warn(`Aviso ao deletar WAN porta ${ws.uport}: ${delResult.error}`);
|
||||||
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reiniciar ONU para aplicar
|
// 3. Recriar WAN services com VLAN 977
|
||||||
|
const numPortas = onuType === 'AN5506-02-B' ? 2 : 1;
|
||||||
|
// Usar as portas dos services existentes, ou fallback para 1..numPortas
|
||||||
|
const portas = wanServices.length > 0
|
||||||
|
? wanServices.map(ws => ws.uport)
|
||||||
|
: Array.from({ length: numPortas }, (_, i) => i + 1);
|
||||||
|
|
||||||
|
for (const porta of portas) {
|
||||||
|
const addCmd = `SET-WANSERVICE::OLTID=${nameOlt},PONID=NA-NA-${portAlias},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::STATUS=1,MODE=2,CONNTYPE=1,VLAN=${VLAN_IPOE},COS=0,QOS=2,UPORT=${porta};`;
|
||||||
|
this.logger.debug(`Criando WAN Service IPoE porta ${porta}`, { comando: addCmd });
|
||||||
|
|
||||||
|
const addResult = await this.executarComandoTL1(addCmd);
|
||||||
|
if (!addResult.success) {
|
||||||
|
this.logger.warn(`Aviso ao criar WAN porta ${porta}: ${addResult.error}`);
|
||||||
|
}
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Reiniciar ONU para aplicar
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
const resetCmd = `RESET-ONU::OLTID=${nameOlt},PONID=NA-NA-${portAlias},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::;`;
|
const resetCmd = `RESET-ONU::OLTID=${nameOlt},PONID=NA-NA-${portAlias},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::;`;
|
||||||
this.logger.debug('Reiniciando ONU após IPoE', { comando: resetCmd });
|
this.logger.debug('Reiniciando ONU após IPoE', { comando: resetCmd });
|
||||||
@@ -944,7 +974,8 @@ class FiberhomeManager {
|
|||||||
porta: portAlias,
|
porta: portAlias,
|
||||||
serial,
|
serial,
|
||||||
vlan: VLAN_IPOE,
|
vlan: VLAN_IPOE,
|
||||||
portas: numPortas
|
portasConfiguradas: portas,
|
||||||
|
wanServicesRemovidos: wanServices.length
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -956,6 +987,55 @@ class FiberhomeManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parseia a resposta do LST-ONUWANSERVICECFG para extrair WAN services
|
||||||
|
* Formato: SVCNAME CONNMODE CONNTYPE VLANID VLANCOS ... BINDPORTNO (tab-separated)
|
||||||
|
*/
|
||||||
|
_parseWanServices(data) {
|
||||||
|
const services = [];
|
||||||
|
const lines = data.split('\n');
|
||||||
|
|
||||||
|
// Encontrar a linha de cabeçalho e as linhas de dados
|
||||||
|
let headerFound = false;
|
||||||
|
let dashFound = false;
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
const trimmed = line.trim();
|
||||||
|
|
||||||
|
if (trimmed.startsWith('SVCNAME')) {
|
||||||
|
headerFound = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (headerFound && trimmed.startsWith('---')) {
|
||||||
|
if (!dashFound) {
|
||||||
|
dashFound = true; // primeiro traço (após header)
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break; // segundo traço = fim dos dados
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dashFound && trimmed.length > 0 && !trimmed.startsWith('---')) {
|
||||||
|
// Linha de dados: campos separados por tab ou espaços
|
||||||
|
const parts = trimmed.split(/\t+|\s{2,}/).filter(p => p.trim());
|
||||||
|
// Formato: SVCNAME(0) CONNMODE(1) CONNTYPE(2) VLANID(3) VLANCOS(4) ... BINDPORTNO(18)
|
||||||
|
if (parts.length >= 5) {
|
||||||
|
const mode = parseInt(parts[1]) || 2;
|
||||||
|
const connType = parseInt(parts[2]) || 1;
|
||||||
|
const vlan = parseInt(parts[3]) || 0;
|
||||||
|
const cos = parseInt(parts[4]) || 0;
|
||||||
|
// BINDPORTNO é o último campo
|
||||||
|
const uport = parseInt(parts[parts.length - 1]) || 1;
|
||||||
|
|
||||||
|
services.push({ mode, connType, vlan, cos, uport, name: parts[0] });
|
||||||
|
console.log(`📋 [IPoE FH] WAN Service parseado: mode=${mode}, connType=${connType}, vlan=${vlan}, cos=${cos}, uport=${uport}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = FiberhomeManager;
|
module.exports = FiberhomeManager;
|
||||||
Reference in new issue
Block a user