fiberhome: add remove onu option

Signed-off-by: Rodrigo Bertoldo de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
rodrigo committed 2026-02-10 20:15:40 -03:00
1 parent e5f8bcf546
commit 41a8d1b6c5
3 files changed
+333

No files matched your search

+173
View File
@@ -646,6 +646,179 @@ class FiberhomeManager {
}
}
/**
* Buscar ONU registrada no sistema
*/
async buscarOnuRegistrada(serial) {
try {
this.logger.debug('Buscando ONU registrada no sistema', { serial });
// 1. Descobrir nome da OLT
const lstDeviceCmd = `LST-DEVICE:::${this.commandId++}::;`;
const deviceResult = await this.executarComandoTL1(lstDeviceCmd);
if (!deviceResult.success) {
throw new Error('Falha ao listar dispositivos OLT');
}
console.log('📋 Resposta LST-DEVICE:', deviceResult.data);
// Extrair nome da OLT da resposta
const deviceLines = deviceResult.data.split('\n');
let nameOlt = null;
for (const line of deviceLines) {
if (line.includes('AN5516') || line.includes('AN5116')) {
const parts = line.split(/\s+/).filter(p => p.trim());
if (parts.length > 0) {
nameOlt = parts[0]; // Primeiro campo é o DEVNAME
break;
}
}
}
if (!nameOlt) {
throw new Error('Nome da OLT não encontrado');
}
console.log(`✅ Nome da OLT descoberto: ${nameOlt}`);
// 2. Listar todas as ONUs registradas
const lstOnuCmd = `LST-ONU::OLTID=${nameOlt}:${this.commandId++}::;`;
console.log(`📋 Listando ONUs registradas...`);
const onuResult = await this.executarComandoTL1(lstOnuCmd);
if (!onuResult.success) {
throw new Error('Falha ao listar ONUs registradas');
}
console.log('📋 ONUs registradas:', onuResult.data);
// 3. Procurar a ONU pelo MAC/Serial
const onuLines = onuResult.data.split('\n');
let onuInfo = null;
for (const line of onuLines) {
// Procurar linha que contenha o serial (case-insensitive)
if (line.toUpperCase().includes(serial.toUpperCase())) {
console.log(`🔍 Linha encontrada: ${line}`);
// Extrair informações da linha
// Formato esperado: campos separados por tabs ou espaços
const parts = line.split(/\s+/).filter(p => p.trim() && p !== '--');
console.log(`📋 Parts extraídos:`, parts);
if (parts.length >= 4) {
// Tentar extrair PONID que pode estar em vários formatos:
// - 1-1-12-14 (frameId-slotId-portId-onuId)
// - NA-NA-12-14
// - 12-14
for (const part of parts) {
// Regex mais flexível: aceita N-N-N-N ou NA-NA-N-N
const ponidMatch = part.match(/^(?:\d+|\w+)-(?:\d+|\w+)-(\d+)-(\d+)$/);
if (ponidMatch) {
console.log(`✅ PONID identificado: ${part}`);
onuInfo = {
nameOlt: nameOlt,
portAlias: part,
slot: ponidMatch[1],
porta: ponidMatch[2]
};
break;
}
}
}
if (onuInfo) {
console.log(`✅ ONU info completa:`, onuInfo);
break;
} else {
console.log(`❌ Não conseguiu extrair PONID da linha`);
}
}
}
if (!onuInfo) {
throw new Error('ONU não encontrada entre as ONUs registradas');
}
console.log(`✅ ONU encontrada:`, onuInfo);
return onuInfo;
} catch (error) {
this.logger.error('Erro ao buscar ONU registrada', { serial, error: error.message });
throw error;
}
}
/**
* Remover ONU Fiberhome via TL1
*/
async removerOnuFiberhome(serial) {
try {
this.logger.debug('Removendo ONU Fiberhome via TL1', { serial });
// Conectar ao UNM2000
const conectado = await this.conectarUNM2000();
if (!conectado) {
throw new Error('Não foi possível conectar ao UNM2000');
}
// Normalizar serial para maiúsculas
serial = serial.toUpperCase();
// Buscar a ONU registrada no sistema
this.logger.debug('Buscando ONU registrada', { serial });
const onuInfo = await this.buscarOnuRegistrada(serial);
if (!onuInfo) {
throw new Error('ONU não encontrada no sistema');
}
const { nameOlt, portAlias } = onuInfo;
this.logger.debug('ONU encontrada', { nameOlt, portAlias });
// Executar comando DEL-ONU
const delOnuCmd = `DEL-ONU::OLTID=${nameOlt},PONID=${portAlias}:${this.commandId++}::ONUIDTYPE=MAC,ONUID=${serial};`;
this.logger.debug('Executando comando DEL-ONU', { comando: delOnuCmd });
const delResult = await this.executarComandoTL1(delOnuCmd);
if (!delResult.success) {
throw new Error(`Falha ao remover ONU: ${delResult.error}`);
}
this.logger.info('ONU Fiberhome removida com sucesso', {
serial,
olt: nameOlt,
porta: portAlias
});
return {
success: true,
message: 'ONU removida com sucesso',
details: {
olt: nameOlt,
porta: portAlias,
serial: serial,
slot: onuInfo.slot,
ponPort: onuInfo.porta
}
};
} catch (error) {
this.logger.error('Erro ao remover ONU Fiberhome', {
serial, error: error.message
});
return {
success: false,
error: error.message
};
}
}
/**
* Desconectar TL1
*/