ipoe: fix wan service

Signed-off-by: Rodrigo Martins <rodrigo@martinsevieira.adv.br>
This commit is contained in:
Rodrigo Martins committed 2026-04-05 12:37:51 -03:00
1 parent 168b8d511d
commit dbd581eb99
1 file changed
+13 -10
+13 -10
View File
@@ -886,10 +886,10 @@ class FiberhomeManager {
} }
/** /**
* Configura IPoE em ONU FiberHome: deleta WAN services existentes e recria com VLAN 977 * Configura IPoE em ONU FiberHome: deleta WAN service na VLAN 1002 e recria com VLAN 977
* 1. Busca ONU registrada pelo serial * 1. Busca ONU registrada pelo serial
* 2. Consulta WAN services existentes (LST-ONUWANSERVICECFG) * 2. Consulta WAN services existentes (LST-ONUWANSERVICECFG)
* 3. Deleta cada WAN service (SET-WANSERVICE STATUS=2) * 3. Deleta WAN service na VLAN 1002 (SET-WANSERVICE STATUS=2)
* 4. Recria com VLAN 977 (SET-WANSERVICE STATUS=1) * 4. Recria com VLAN 977 (SET-WANSERVICE STATUS=1)
* 5. Reinicia ONU * 5. Reinicia ONU
* @param {string} serial - MAC/Serial da ONU * @param {string} serial - MAC/Serial da ONU
@@ -927,10 +927,14 @@ class FiberhomeManager {
this.logger.info(`WAN Services encontrados: ${wanServices.length}`, { wanServices }); this.logger.info(`WAN Services encontrados: ${wanServices.length}`, { wanServices });
} }
// 2. Deletar WAN services existentes // 2. Deletar WAN services na VLAN 1002 (PPPoE atual)
for (const ws of wanServices) { const VLAN_PPPOE = 1002;
const wanServicesParaDeletar = wanServices.filter(ws => ws.vlan === VLAN_PPPOE);
this.logger.info(`WAN Services na VLAN ${VLAN_PPPOE} para deletar: ${wanServicesParaDeletar.length}`, { wanServicesParaDeletar });
for (const ws of wanServicesParaDeletar) {
const delCmd = `SET-WANSERVICE::OLTID=${nameOlt},PONID=NA-NA-${ponId},ONUIDTYPE=MAC,ONUID=${serial}:${this.commandId++}::STATUS=2,MODE=${ws.mode},CONNTYPE=${ws.connType},VLAN=${ws.vlan},COS=${ws.cos},UPORT=${ws.uport};`; const delCmd = `SET-WANSERVICE::OLTID=${nameOlt},PONID=NA-NA-${ponId},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 }); this.logger.debug(`Deletando WAN Service VLAN ${ws.vlan} porta ${ws.uport}`, { comando: delCmd });
const delResult = await this.executarComandoTL1(delCmd); const delResult = await this.executarComandoTL1(delCmd);
if (!delResult.success) { if (!delResult.success) {
@@ -939,11 +943,10 @@ class FiberhomeManager {
await new Promise(resolve => setTimeout(resolve, 1000)); await new Promise(resolve => setTimeout(resolve, 1000));
} }
// 3. Recriar WAN services com VLAN 977 // 3. Recriar WAN services com VLAN 977 nas portas que tinham VLAN 1002
const numPortas = onuType === 'AN5506-02-B' ? 2 : 1; const numPortas = onuType === 'AN5506-02-B' ? 2 : 1;
// Usar as portas dos services existentes, ou fallback para 1..numPortas const portas = wanServicesParaDeletar.length > 0
const portas = wanServices.length > 0 ? wanServicesParaDeletar.map(ws => ws.uport)
? wanServices.map(ws => ws.uport)
: Array.from({ length: numPortas }, (_, i) => i + 1); : Array.from({ length: numPortas }, (_, i) => i + 1);
for (const porta of portas) { for (const porta of portas) {
@@ -977,7 +980,7 @@ class FiberhomeManager {
serial, serial,
vlan: VLAN_IPOE, vlan: VLAN_IPOE,
portasConfiguradas: portas, portasConfiguradas: portas,
wanServicesRemovidos: wanServices.length wanServicesRemovidos: wanServicesParaDeletar.length
} }
}; };